コード例 #1
0
ファイル: dbprefs.cpp プロジェクト: amiel/jugglemaster
UInt16 OpenPrefsDatabase(void) {
  JMPalmPrefs = DmOpenDatabaseByTypeCreator(JMPalmPrefsType, JMPalmAppID,
					    dmModeReadWrite);

  // the database doesn't exist
  if (!JMPalmPrefs) {
    MemHandle foo;
    UInt16 position = 1;

    if (DmCreateDatabase(0, JMPalmPrefsName,
			 JMPalmAppID, JMPalmPrefsType, false))
      return true;
    
    JMPalmPrefs = DmOpenDatabaseByTypeCreator(JMPalmPrefsType, JMPalmAppID,
					      dmModeReadWrite);
		 		 
    ResetHeader();
    
    // create dummy record
    foo = DmNewRecord(JMPalmPrefs, &position, sizeof(headerdata));
    DmReleaseRecord(JMPalmPrefs, position, true);
    WriteHeader();

    // Do some special handling for the first run of the application
    HandleFirstRun();
  }

  return false;
}
コード例 #2
0
void buildAll() {
	Err err;
	LocalID olddb;	

	olddb = DmFindDatabase(0, "Glbs::" BUILD_NAME);
	if (olddb) {
		DmDeleteDatabase(0,olddb);
		FrmCustomAlert(1000,"delete old " BUILD_NAME " DB",0,0);
	}
	err = DmCreateDatabase (0, "Glbs::" BUILD_NAME, 'ScVM', 'GLBS', false);
	olddb = DmFindDatabase(0, "Glbs::" BUILD_NAME);
	dbP[BUILD_RES] = DmOpenDatabase(0, olddb, dmModeReadWrite);

#if defined(BUILD_COMMON)
	addNewGui();

#elif defined(BUILD_SCUMM)
	addDimuseTables();
	// temp removed
	// TODO ::scummvm use sizeof(OLD256_MIDI_HACK) so i need to fix it
	// directly in the code or call MemHandleSize but it may slow down
	// code execution
	addAkos();
	addDimuseCodecs();
	addCodec47();
	addGfx();
	addDialogs();
	addCharset();
	addCostume();
	addPlayerV2();
	addScummTables();

#elif defined(BUILD_SIMON)
	addSimon();
	Simon_addCharset();

#elif defined(BUILD_SKY)
	Sky_addHufftext();

#elif defined(BUILD_QUEEN)
	Queen_addTalk();
	Queen_addRestables();
	Queen_addGraphics();
	Queen_addDisplay();
	Queen_addMusicdata();

#elif defined(BUILD_SWORD1)
	Sword1_addStaticres();
#endif

	DmCloseDatabase(dbP[BUILD_RES]);
}
コード例 #3
0
ファイル: DataMgr.cpp プロジェクト: oldhu/smstw
TDataMgr::TDataMgr(const char* dbName, UInt32 creator) :
    m_db(NULL)
{
    LocalID dbId = DmFindDatabase(0, dbName);
    if (dbId == 0) {
        Err err = DmCreateDatabase(0, dbName, creator, 'DATA', false);
        if (err == errNone) {
            dbId = DmFindDatabase(0, dbName);
        }
    }

    if (dbId != 0) {
        m_db = DmOpenDatabase(0, dbId, dmModeReadWrite);
    }

    ErrFatalDisplayIf(m_db == NULL, "cannot open db");
}
コード例 #4
0
ファイル: storage_util.c プロジェクト: sjlombardo/strip-palm
Err getDatabase (DmOpenRef * DBptr, UInt32 type, UInt32 creator, UInt32 mode,
    UInt16 card, char *name, Boolean * created) {
    Err errors;
    *created = false;

    errors = getDatabaseByTypeCreatorName (DBptr, type, creator, mode, name); 

    /* if the database does not exist, make a new one. */
    if (errors) {
        errors = DmCreateDatabase (card, name, creator, type, false);
        if (errors) return errors;
        *created = true;
    	errors = getDatabaseByTypeCreatorName (DBptr, type, creator, mode, name); 
        if (!*DBptr || errors) return DmGetLastErr ();
    }

    return 0; 
}
コード例 #5
0
ファイル: bookmarks.c プロジェクト: kjk/noah-palm
/* Open one of the bookmark databases. If sortType is bkmSortByName
   use bookmarks sorted by name, if bkmSortByTime use bookmarks
   sorted by the bookmarking time */
static Err OpenBookmarksDB(AppContext* appContext, BookmarkSortType sortType)
{
    Err      err;
    char *   dbName;
 
    if ( sortType == appContext->currBookmarkDbType )
    {
        // it's already open
        Assert( appContext->bookmarksDb );
        return errNone;
    }

    switch( sortType )
    {
        case bkmSortByName:
            dbName = BOOKMARKS_DB_BY_NAME;
            break;
        case bkmSortByTime:
            dbName = BOOKMARKS_DB_BY_TIME;
            break;
        default:
            Assert(false);
            break;
    }

    CloseBookmarksDB(appContext);

    appContext->bookmarksDb = OpenDbByNameTypeCreator(dbName, BOOKMARKS_DB_TYPE, APP_CREATOR);

    if (!appContext->bookmarksDb)
    {
        err = DmCreateDatabase(0, dbName, APP_CREATOR,  BOOKMARKS_DB_TYPE, false);
        if ( errNone != err)
            return err;

        appContext->bookmarksDb = OpenDbByNameTypeCreator(dbName, BOOKMARKS_DB_TYPE, APP_CREATOR);
        if (!appContext->bookmarksDb)
            return dmErrCantOpen;
    }
    Assert(appContext->bookmarksDb);

    appContext->currBookmarkDbType = sortType;
    return errNone;
}
コード例 #6
0
ファイル: editor_form.c プロジェクト: asashnov/palmano
/* DESCRIPTION:  Get the application's database.  Open the database if it
 * exists, create it if neccessary.
 *
 * PARAMETERS:   *dbPP - pointer to a database ref (DmOpenRef) to be set
 *					  mode - how to open the database (dmModeReadWrite)
 *
 * RETURNED:     Err - zero if no error, else the error
 */
static Err getPalmanoDatabase (DmOpenRef *dbPP, UInt16 mode)
{
  Err error = 0;
  DmOpenRef dbP;

  *dbPP = NULL;
  
  // Find the application's data file.  If it doesn't exist create it.
  dbP = DmOpenDatabaseByTypeCreator (sysFileTMidi, pmnoCreatorDB, mode);

  if (!dbP) {
    debugPrintf("getPalmanoDatabase(): Can't open database, code %d\n",
		DmGetLastErr());
    error = DmCreateDatabase (0, "palmano", pmnoCreatorDB, sysFileTMidi, false);

    if (error) {
      debugPrintf("getPalmanoDatabase(): DmCreateDatabase exit code %d\n", error);
      ErrAlert(error);
      return error;
    }
    else
      debugPrintf("getPalmanoDatabase(): create DB ok\n");

    dbP = DmOpenDatabaseByTypeCreator(sysFileTMidi, pmnoCreatorDB, mode);
    if (!dbP) {
      debugPrintf("getPalmanoDatabase(): Can't open database after create, code %d\n",
		  DmGetLastErr());
      ErrAlert(DmGetLastErr());      
      return DmGetLastErr();
    } else
      debugPrintf("getPalmanoDatabase(): second open DB ok\n");


    // Set the backup bit.  This is to aid syncs with non Palm software.
    //    ToDoSetDBBackupBit(dbP);
		
  } else
    debugPrintf("getPalmanoDatabase(): open DB ok\n");


  *dbPP = dbP;
  return 0;
}
コード例 #7
0
ファイル: doclist.c プロジェクト: TimofonicJunkRoom/plucker-1
/* Create database for list of documents */
static void CreateDocList( void )
    /* THROWS */
{
    UInt16  cardNo;
    Err     err;
    LocalID dbID;
    UInt16  version;

    /* list is always put on first card in RAM */
    cardNo  = 0;
    err     = errNone;

    err = DmCreateDatabase( cardNo, PlkrDocListName, ViewerAppID,
            PlkrDocListType, false );
    THROW_IF( err != errNone, memErrNotEnoughSpace );

    dbID    = DmFindDatabase( cardNo, PlkrDocListName );
    version = PlkrDocListVersion;
    err     = DmSetDatabaseInfo( cardNo, dbID, NULL, NULL, &version, 
                NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL );

    plkrDocList = DmOpenDatabaseByTypeCreator( PlkrDocListType, ViewerAppID,
                    dmModeReadWrite );

    ErrTry {
        InitPlkrAppInfo( plkrDocList );
    }
    ErrCatch( UNUSED_PARAM( err ) ) {
        LocalID dbID;

        DmOpenDatabaseInfo( plkrDocList, &dbID, NULL, NULL, &cardNo, NULL );
        CloseDatabase( plkrDocList );
        DmDeleteDatabase( cardNo, dbID );
        MSG( "Couldn't initialize Plkr document list [ appInfo ]\n" );
        ErrThrow( memErrNotEnoughSpace );
    } ErrEndCatch
}
コード例 #8
0
ファイル: PrefsStore.cpp プロジェクト: kjk/ars-framework
// Save preferences previously set via ErrSet*() calls to a database.
// If something goes wrong, returns an error
// Possible errors:
//   memErrNotEnoughSpace - not enough memory to allocate needed structures
//   errors from Dm*() calls
Err PrefsStoreWriter::ErrSavePreferences()
{
    Err     err = errNone;
    long    blobSize;
    void *  prefsBlob = SerializeItems(_items, _itemsCount, &blobSize);
    if ( NULL == prefsBlob ) 
        return memErrNotEnoughSpace;

    DmOpenRef db = DmOpenDatabaseByTypeCreator(_dbType, _dbCreator, dmModeReadWrite);
    if (!db)
    {
        err = DmCreateDatabase(0, _dbName, _dbCreator, _dbType, false);
        if ( err)
            return err;

        db = DmOpenDatabaseByTypeCreator(_dbType, _dbCreator, dmModeReadWrite);
        if (!db)
            return DmGetLastErr();
    }

    // set backup bit on the database. code adapted from DataStore.cpp
    // DataStore::open()
    if (errNone == err)
    {
        LocalID localId;
        UInt16 cardNo;
        UInt16 attribs;
        err = DmOpenDatabaseInfo(db, &localId, NULL, NULL, &cardNo, NULL);
        if (errNone != err)
            goto Continue;
        err = DmDatabaseInfo(cardNo, localId, NULL, &attribs, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
        if (errNone != err)
            goto Continue;
        if (0 != attribs & dmHdrAttrBackup)
            goto Continue;
        attribs |= dmHdrAttrBackup;
        err = DmSetDatabaseInfo(cardNo, localId, NULL, &attribs, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
Continue:
        err = errNone;
    }

    UInt16    recNo = 0;
    UInt16    recsCount = DmNumRecords(db);
    MemHandle recHandle;
    Boolean   fRecordBusy = false;
    Boolean   fRecFound = false;
    void *    recData;
    long      recSize;
    while (recNo < recsCount)
    {
        recHandle = DmGetRecord(db, recNo);
        fRecordBusy = true;
        recData = MemHandleLock(recHandle);
        recSize = MemHandleSize(recHandle);
        if (IsValidPrefRecord(recData))
        {
            fRecFound = true;
            break;
        }
        MemPtrUnlock(recData);
        DmReleaseRecord(db, recNo, true);
        fRecordBusy = false;
        ++recNo;
    }

    if (fRecFound && blobSize>recSize)
    {
        /* need to resize the record */
        MemPtrUnlock(recData);
        DmReleaseRecord(db,recNo,true);
        fRecordBusy = false;
        recHandle = DmResizeRecord(db, recNo, blobSize);
        if ( NULL == recHandle )
            return DmGetLastErr();
        recData = MemHandleLock(recHandle);
        Assert( MemHandleSize(recHandle) == blobSize );        
    }

    if (!fRecFound)
    {
        recNo = 0;
        recHandle = DmNewRecord(db, &recNo, blobSize);
        if (!recHandle)
        {
            err = DmGetLastErr();
            goto CloseDbExit;
        }
        recData = MemHandleLock(recHandle);
        fRecordBusy = true;
    }

    err = DmWrite(recData, 0, prefsBlob, blobSize);
    MemPtrUnlock(recData);
    if (fRecordBusy)
        DmReleaseRecord(db, recNo, true);
CloseDbExit:
    // if had error before - preserve that error
    // otherwise return error code from DmCloseDatabase()
    if (err)
        DmCloseDatabase(db);
    else
        err = DmCloseDatabase(db);
    new_free( prefsBlob );
    return err;
}