/* Retrieve search patterns */ static void ReadSearchPatterns( void ) { patternsSize = 0; if ( PrefGetAppPreferences( (UInt32) ViewerAppID, (UInt16) ViewerPrefSearchStringID, NULL, &patternsSize, true ) != noPreferenceFound ) { Char* entry; Int16 i; Int16 len; SafeMemPtrFree( patterns ); patterns = SafeMemPtrNew( patternsSize ); PrefGetAppPreferences( (UInt32) ViewerAppID, (UInt16) ViewerPrefSearchStringID, patterns, &patternsSize, true ); /* do a sanity check */ entry = patterns; for ( i = 0 ; i < pref.searchEntries ; i++ ) { len = StrLen( entry ); if ( MAX_PATTERN_LEN < len || patterns + patternsSize < entry + len + 1 ) { /* error in search patterns! */ SafeMemPtrFree( patterns ); pref.searchEntries = 0; break; } entry += len + 1; } } }
void TestPrefsDataReadOld( void ) { OldPreferences oldPref; Int16 version; UInt16 prefSize; /* Add known old preference structure */ MemSet( &oldPref, sizeof( OldPreferences ), 0 ); oldPref.rotate = true; oldPref.controlMode = MODE2; oldPref.useDateTime = true; PrefSetAppPreferences( (UInt32) ViewerAppID, (UInt16) ViewerOldPrefID, (Int16) ViewerVersion, &oldPref, sizeof( OldPreferences ), true ); /* When the old preference structure is found it should be converted to the new format and then the old structure should be removed */ ReadPrefs(); ASSERT( Prefs()->rotate ); ASSERT( Prefs()->controlMode == MODE2 ); ASSERT( Prefs()->useDateTime ); /* Check that the old preference structure is removed */ prefSize = 0; version = PrefGetAppPreferences( (UInt32) ViewerAppID, (UInt16) ViewerOldPrefID, NULL, &prefSize, true); ASSERT( version == noPreferenceFound ); }
/******************************************************************************** * Function: StartApplication * Description: This is the first function that gets called and it is * responsible for initializing databases and other global variables, checking * to see whether private records will be shown and calculating the auto-off time * for the current system. * ******************************************************************************/ static Err StartApplication (void) { UInt16 mode = dmModeReadWrite; Err errors = 0; Boolean created; StripPrefType prefs; UInt16 prefsSize, prefsVersion; // set current form to be the password opener currentForm = PasswordForm; // check about private records hideSecretRecords = PrefGetPreference (prefHidePrivateRecordsV33); if (!hideSecretRecords) mode |= dmModeShowSecret; /* handle program prefrences */ prefsSize = sizeof (StripPrefType); prefsVersion = PrefGetAppPreferences (StripCreator, StripPrefID, &prefs, &prefsSize, true); if (prefsVersion == noPreferenceFound) { FrmCustomAlert (GenericError, "This version of StripCS is only able to convert 0.5 databases. If you're using an earlier version you must run the StripCS_0.5.prc file that came with this distro first. If you aren't upgrading, just run Strip.prc!", NULL, NULL); return -1; } else if (prefsVersion == StripVersionNumber) { FrmCustomAlert (GenericError, "It looks like you have already converted your databases with StripCS. You may now use the latest version of Strip.", NULL, NULL); return -1; } // open or create databases. errors = getDatabase (&SystemDB, systemDBTypeOld, StripCreator, mode, 0, systemDBName, &created); errors = getDatabase (&AccountDB, accountDBTypeOld, StripCreator, mode, 0, accountDBName, &created); errors = getDatabase (&PasswordDB, passwordDBTypeOld, StripCreator, mode, 0, passwordDBName, &created); // if the password database does not exist, or there are no records in it note that // this is the first run, so the user will be prompted to enter a new password. if (created ||(DmNumRecordsInCategory (PasswordDB, dmAllCategories) == 0)) { firstRun = true; } // set up the timer stuff. start by setting auto off time to 0. the function returns the old // auto off time. If the oldAutoOffTime is 0 then the system will never shut down. this is not // the behavior that we want, so we reset the autoOffTime to 300. if the oldAutoOffTime is not // 0 then we set it back immediatly. Note that in the StopApplication function we // set the autoOffTime back to what it was before this program started no matter what. return 0; }
int load_preferences(void) {UInt16 prefs_size=0;int version,n;char*p,*_; version=PrefGetAppPreferences(CREATOR,prefs_id,0,&prefs_size,0); if(version!=prefs_version)return try_db_name(); if(prefs_size<db_name_size+1)return try_db_name(); p=MemPtrNew(prefs_size);if(!p)return try_db_name();_=p; version=PrefGetAppPreferences(CREATOR,prefs_id,p,&prefs_size,0); if(version!=prefs_version){MemPtrFree(p);return try_db_name();} n=db_name_size;MemMove(db_name,_,n);_+=n;prefs_size-=n;db_name[n]=0; if(try_db_name())return!0; if(prefs_size>1) {n=StrLen(_)+1;lookup=MemPtrNew(n); if(lookup)MemMove(lookup,_,n);prefs_size-=n;_+=n; }if(prefs_size>0) {char aux_flags=*_;set_list_mode(2*!!(aux_flags&(1<<list_mode_bit))); prefs_size-=1;_+=1; }MemPtrFree(p);return 0; }static int
int PrefsDataSuiteSetUp( void ) { Int16 version; UInt16 prefSize; /* Store original preference structure */ prefSize = 0; version = PrefGetAppPreferences( (UInt32) ViewerAppID, (UInt16) ViewerPrefID, NULL, &prefSize, true); if ( version != noPreferenceFound && prefSize == sizeof( Preferences ) ) { PrefGetAppPreferences( (UInt32) ViewerAppID, (UInt16) ViewerPrefID, &originalPref, &prefSize, true); hasStoredPrefs = true; } else { hasStoredPrefs = false; } return 0; }
// Function tries to load a Game game_p gameLoad(engine_p engine) { game_p game = NULL; UInt16 size = 0; int version = 0; version = PrefGetAppPreferences( CREATOR, SAVED_GAME, NULL, &size, 1); if (VERSION == version && 0 < size) { board_p board = NULL; void* data = bufferAllocate(size, NULL); PrefGetAppPreferences(CREATOR, SAVED_GAME, data, &size, 1); // ignore if game can't be loaded TRY { board = boardRetain( boardLoad(data, size)); } CATCH {} END; if (NULL == board) return NULL; else board = boardAutorelease(board); switch (boardState(board)) { case State_Victory: case State_Defeat: break; default: game = gameNew(engine, board); break; } }
static Err FlickrVerifyUserCredentials(bool& res, FlickrPrefs& prefs) { Err err = errNone; UInt16 size = sizeof(FlickrPrefs); Int16 ver = PrefGetAppPreferences(FlickrCreatorID, flickrPrefsResourceID, &prefs, &size, true); if (noPreferenceFound == ver) { res = false; return errNone; } res = ((0 != StrLen(prefs.email)) && (0 != StrLen(prefs.password))); return err; }
void TestPrefsDataWrite( void ) { Preferences testPref; Int16 version; UInt16 prefSize; /* Write known preference structure */ MemSet( Prefs(), sizeof( Preferences ), 0 ); Prefs()->controlMode = MODE2; WritePrefs(); /* Check that the correct preference structure was stored */ prefSize = 0; version = PrefGetAppPreferences( (UInt32) ViewerAppID, (UInt16) ViewerPrefID, NULL, &prefSize, true); if ( version != noPreferenceFound && prefSize == sizeof( Preferences ) ) { PrefGetAppPreferences( (UInt32) ViewerAppID, (UInt16) ViewerPrefID, &testPref, &prefSize, true); } ASSERT( testPref.controlMode == MODE2 ); }
/*********************************************************************** * * FUNCTION: AppStart * * DESCRIPTION: Get the current application's preferences. * * PARAMETERS: nothing * * RETURNED: Err value 0 if nothing went wrong * * REVISION HISTORY: * * ***********************************************************************/ static Err AppStart(void) { StarterPreferenceType prefs; UInt16 prefsSize; // Read the saved preferences / saved-state information. prefsSize = sizeof(StarterPreferenceType); if (PrefGetAppPreferences(appFileCreator, appPrefID, &prefs, &prefsSize, true) != noPreferenceFound) { } return errNone; }
static Err FlickrDisableUploadCompletedForm() { FlickrPrefs* prefs = new FlickrPrefs(); if (NULL == prefs) return exgMemError; MemSet(prefs, sizeof(*prefs), 0); Err err = errNone; UInt16 size = sizeof(*prefs); Int16 ver = PrefGetAppPreferences(FlickrCreatorID, flickrPrefsResourceID, prefs, &size, true); prefs->dontShowUploadCompletedForm = true; FlickrSavePrefs(*prefs); Finish: delete prefs; return err; }
void LoadCubes() { Word x,size; Char msg[MaxName+1]; size = sizeof(stor); x = PrefGetAppPreferences( CREATOR, 0, &stor, &size, true); if( (x == noPreferenceFound) || (stor.version != storVersion) ) { ResetCubes(); // Clear player names and scores. for (x = 0; x < MaxPlayers; x++) { StrPrintF( msg, "Wimpy %d", x+1 ); StrCopy( stor.player[x].name, msg ); stor.player[x].score = 0; } } }
/* Get preferences, open (or create) app database */ static UInt16 StartApplication(void) { UInt16 prefsize,i; /* Fetch application preferences */ prefsize = sizeof(stopWatchPreferenceType); i = PrefGetAppPreferences('StWt', 0, &stopWatchPrefs, &prefsize, true); /* If no prefs were found, reset all values. */ if (noPreferenceFound == i) { //DEBUGBOX("no prefs",""); stopWatchPrefs.timestamp = 0; stopWatchPrefs.vol=10; stopWatchPrefs.sound=btnSound2; stopWatchPrefs.visual=btnVisualNum; stopWatchPrefs.disableAutoOff = 1; } FrmGotoForm(MainForm); return 0; }
static void FlickrClearUserCredentials() { FlickrPrefs* prefs = new FlickrPrefs(); if (NULL == prefs) return; MemSet(prefs, sizeof(*prefs), 0); UInt16 size = sizeof(*prefs); Int16 ver = PrefGetAppPreferences(FlickrCreatorID, flickrPrefsResourceID, prefs, &size, true); if (noPreferenceFound == ver) { delete prefs; return; } MemSet(prefs->password, prefs->maxPasswordLength + 1, 0); FlickrSavePrefs(*prefs); delete prefs; }
/*********************************************************************** * * FUNCTION: ReserveAlarmInternals * * DESCRIPTION: Returns the internal struct which stores pending alarms, * etc. for use by AlarmTrigger and DBDisplayAlarm, et al. * THIS MAY BE CALLED AT INTERRUPT LEVEL (inInterrupt == true)! * IF SO, DONT USE GLOBALS!! * * PARAMETERS: inInterrupt If true, use FeatureMgr to retrieve * application globals. * * RETURNED: Pointer to the internal struct * * REVISION HISTORY: * Name Date Description * ---- ---- ----------- * rbb 4/29/99 Initial Revision * ***********************************************************************/ void ReserveAlarmInternals ( PendingAlarmQueueType* outAlarmInternalsP ) { UInt16 prefsSize = sizeof (PendingAlarmQueueType); Int16 prefsVersion; prefsVersion = PrefGetAppPreferences (sysFileCDatebook, datebookUnsavedPrefID, outAlarmInternalsP, &prefsSize, false); if (prefsVersion == noPreferenceFound) { MemSet (outAlarmInternalsP, sizeof (PendingAlarmQueueType), 0); outAlarmInternalsP->snoozeAnchorTime = apptNoAlarm; PrefSetAppPreferences (sysFileCDatebook, datebookUnsavedPrefID, datebookUnsavedPrefsVersionNum, outAlarmInternalsP, sizeof (PendingAlarmQueueType), false); } }
/* Retrieve preferences from the Preferences database */ void ReadPrefs( void ) { Int16 version; Int16 oldVersion; UInt16 prefSize; UInt16 oldPrefSize; ASSERT( ViewerPrefID != ViewerPrefSearchStringID ); /* if not a test version remove preferences with ID 0 */ if ( ViewerPrefID != 0 ) RemovePref( 0 ); MemSet( &pref, sizeof( Preferences ), 0 ); /* if no preference found or the found preference has a "bad" size and there is no preference using an old (incompatible) format, then initialize a new preference structure */ prefSize = 0; version = PrefGetAppPreferences( (UInt32) ViewerAppID, (UInt16) ViewerPrefID, NULL, &prefSize, true); if ( version == noPreferenceFound || sizeof( Preferences ) < prefSize ) { MSG( _( "Version = %d, prefSize = %u\n", version, prefSize ) ); oldPrefSize = 0; oldVersion = PrefGetAppPreferences( (UInt32) ViewerAppID, (UInt16) ViewerOldPrefID, NULL, &oldPrefSize, true); if ( oldVersion == noPreferenceFound ) { MSG( "No old preferences found\n" ); pref.column.date = SHOW; pref.column.size = SHOW; pref.column.type = SHOW; pref.strikethrough = false; pref.defaultStrikethrough = false; pref.multipleSelect = true; pref.hardKeys = false; pref.arrowKeys = false; pref.searchFlags = 0; pref.toolbar = TOOLBAR_TOP; pref.lastForm = frmLibrary; pref.scrollbar = SCROLLBAR_RIGHT; pref.controlMode = MODE1; pref.screenDepth = 0; pref.searchEntries = 0; pref.categories = dmAllCategoriesAdvanced; pref.cardNo = 0; pref.toolbarButton = 0; pref.filterMode = FILTER_OR; pref.fontModeMain = FONT_DEFAULT; pref.underlineMode = false; pref.defaultUnderlineMode = false; pref.sortType = SORT_NAME; pref.sortOrder = SORTORDER_ASC; pref.autoscrollEnabled = false; pref.autoscrollInterval = 0; pref.autoscrollLastScrollTime = 0; pref.autoscrollJump = 1; pref.autoscrollMode = AUTOSCROLL_PIXELS; pref.autoscrollDir = AUTOSCROLL_DOWN; pref.autoscrollStayOn = false; pref.location = RAM; pref.gestures = true; pref.gestMode[ GESTURES_UP ] = SELECT_GO_TO_TOP; pref.gestMode[ GESTURES_RIGHT ] = SELECT_GO_FORWARD; pref.gestMode[ GESTURES_DOWN ] = SELECT_GO_TO_BOTTOM; pref.gestMode[ GESTURES_LEFT ] = SELECT_GO_BACK; pref.gestMode[ GESTURES_TAP ] = SELECT_GO_HOME; pref.syncPolicy = SYNC_AUTOMATIC; pref.fontModeLibrary = FONT_DEFAULT; pref.categoryStyle = CATEGORY_ADVANCED; pref.hardcopyAction = HARDCOPY_DIALOG; pref.hardcopyRange = HARDCOPY_INVIEW; pref.hardcopyLink = HARDCOPY_ATBOTTOM; pref.lineSpacing = -MINIMAL_LINE_SPACING; pref.paragraphSpacing = DEFAULT_PARAGRAPH_SPACING; pref.searchMode = SEARCH_IN_ONE_PAGE; pref.enableSoftHyphens = true; pref.defaultEnableSoftHyphens = true; pref.indicateOpened = false; pref.individualDocumentLayout = false; pref.individualDocumentFonts = false; pref.individualDocumentColor = false; pref.individualDocumentLookup = false; pref.forceDefaultColors = false; pref.defaultForceDefaultColors = false; pref.savedToolbar = TOOLBAR_TOP; pref.savedScrollbar = SCROLLBAR_RIGHT; pref.savedSilkscreen = DIA_STATE_MIN; pref.pageControlsLink = false; pref.defaultPageControlsLink = false; pref.forceAlign = FORCE_ALIGN_NONE; pref.defaultForceAlign = FORCE_ALIGN_NONE; pref.joinUpAllRecords = false; pref.rotate = ROTATE_ZERO; pref.defaultRotate = ROTATE_ZERO; pref.defaultLineSpacing = pref.lineSpacing; pref.defaultParagraphSpacing = pref.paragraphSpacing; pref.defaultFontModeMain = pref.fontModeMain; pref.selectedWordAction = SELECT_WORD_SEARCH_FORM; pref.defaultSelectedWordAction = SELECT_WORD_SEARCH_FORM; pref.selectWordTap = SELECT_WORD_TAP_NONE; pref.defaultSelectWordTap = SELECT_WORD_TAP_NONE; pref.useDateTime = false; pref.searchXlit = 0; pref.rtl = false; pref.defaultRTL = false; pref.enableMargins = true; pref.defaultEnableMargins = true; pref.noAnnotationsInBookmarkList = false; pref.alwaysDeleteAnnotations = false; StrCopy( pref.docName, "" ); StrCopy( pref.mainUserFontName, "" ); StrCopy( pref.libraryUserFontName, "" ); StrCopy( pref.defaultMainUserFontName, pref.mainUserFontName ); MemSet( &pref.select, sizeof( pref.select ), SELECT_NONE ); MemSet( &pref.hwMode, sizeof( pref.hwMode ), SELECT_NONE ); pref.arrowKeys = true; pref.arrowMode[ UP_ARROW ] = SELECT_FULL_PAGE_UP; pref.arrowMode[ DOWN_ARROW ] = SELECT_FULL_PAGE_DOWN; pref.arrowMode[ LEFT_ARROW ] = SELECT_GO_BACK; pref.arrowMode[ RIGHT_ARROW ] = SELECT_GO_FORWARD; pref.arrowMode[ SELECT_ARROW ] = SELECT_GO_HOME; MemSet( &pref.jogMode, sizeof( pref.jogMode ), SELECT_NONE ); if ( JogdialType() != noJogdial ) { pref.jogEnabled = true; pref.jogMode[ JOGEVENTS_UP ] = SELECT_HALF_PAGE_UP; pref.jogMode[ JOGEVENTS_DOWN ] = SELECT_HALF_PAGE_DOWN; pref.jogMode[ JOGEVENTS_PUSH ] = SELECT_GO_FORWARD; pref.jogMode[ JOGEVENTS_PUSHUP ] = SELECT_FULL_PAGE_UP; pref.jogMode[ JOGEVENTS_PUSHDOWN ] = SELECT_FULL_PAGE_DOWN; pref.jogMode[ JOGEVENTS_BACK ] = SELECT_GO_BACK; } RemovePref( ViewerPrefSearchStringID ); RemovePref( ViewerPrefID ); } else { /* we found a preference structure using an old (incompatible) format; convert it to the new format */ OldPreferences old; MemSet( &old, sizeof( OldPreferences ), 0 ); oldVersion = PrefGetAppPreferences( (UInt32) ViewerAppID, (UInt16) ViewerOldPrefID, &old, &oldPrefSize, true); MSG( _( "Old version = %d, oldPrefSize = %u\n", oldVersion, oldPrefSize ) ); /* if we found an older version of the old preference format we add default values for the new items */ if ( oldVersion < 2 ) { old.column.type = SHOW; old.fontModeLibrary = FONT_DEFAULT; old.categoryStyle = CATEGORY_ADVANCED; old.hardcopyAction = HARDCOPY_DIALOG; old.hardcopyRange = HARDCOPY_INVIEW; old.hardcopyLink = HARDCOPY_ATBOTTOM; old.searchMode = SEARCH_IN_ONE_PAGE; old.enableSoftHyphens = true; old.lineSpacing = -MINIMAL_LINE_SPACING; old.paragraphSpacing = DEFAULT_PARAGRAPH_SPACING; MemSet( &old.jogMode, sizeof( old.jogMode ), SELECT_NONE ); if ( JogdialType() != noJogdial ) { old.jogEnabled = true; old.jogMode[ JOGEVENTS_UP ] = SELECT_HALF_PAGE_UP; old.jogMode[ JOGEVENTS_DOWN ] = SELECT_HALF_PAGE_DOWN; old.jogMode[ JOGEVENTS_PUSH ] = SELECT_GO_FORWARD; old.jogMode[ JOGEVENTS_PUSHUP ] = SELECT_FULL_PAGE_UP; old.jogMode[ JOGEVENTS_PUSHDOWN ] = SELECT_FULL_PAGE_DOWN; old.jogMode[ JOGEVENTS_BACK ] = SELECT_GO_BACK; } } if ( version < 3 ) { old.indicateOpened = false; old.individualDocumentFonts = false; old.forceDefaultColors = false; old.savedToolbar = TOOLBAR_TOP; old.savedScrollbar = SCROLLBAR_RIGHT; old.savedSilkscreen = DIA_STATE_MIN; old.pageControlsLink = false; old.forceAlign = FORCE_ALIGN_NONE; old.joinUpAllRecords = false; old.rotate = ROTATE_ZERO; old.defaultRotate = ROTATE_ZERO; old.defaultLineSpacing = old.lineSpacing; old.defaultParagraphSpacing = old.paragraphSpacing; old.defaultFontModeMain = old.fontModeMain; old.selectedWordAction = SELECT_WORD_SEARCH_FORM; old.selectWordTap = SELECT_WORD_TAP_NONE; old.useDateTime = false; old.searchXlit = 0; StrCopy( old.mainUserFontName, "" ); StrCopy( old.libraryUserFontName, "" ); StrCopy( old.defaultMainUserFontName, old.mainUserFontName ); } pref.column = old.column; pref.strikethrough = old.strikethrough; pref.multipleSelect = old.multipleSelect; pref.searchFlags = old.searchFlags; pref.toolbar = old.toolbar; pref.lastForm = old.lastForm; pref.scrollbar = old.scrollbar; pref.controlMode = old.controlMode; pref.screenDepth = old.screenDepth; pref.searchEntries = old.searchEntries; pref.categories = old.categories; pref.cardNo = old.cardNo; pref.toolbarButton = old.toolbarButton; pref.filterMode = old.filterMode; pref.fontModeMain = old.fontModeMain; pref.underlineMode = old.underlineMode; pref.sortType = old.sortType; pref.sortOrder = old.sortOrder; pref.autoscrollEnabled = old.autoscrollEnabled; pref.autoscrollInterval = old.autoscrollInterval; pref.autoscrollLastScrollTime = old.autoscrollLastScrollTime; pref.autoscrollJump = old.autoscrollJump; pref.autoscrollMode = old.autoscrollMode; pref.autoscrollDir = old.autoscrollDir; pref.autoscrollStayOn = old.autoscrollStayOn; pref.location = old.location; pref.syncPolicy = old.syncPolicy; pref.fontModeLibrary = old.fontModeLibrary; pref.categoryStyle = old.categoryStyle; pref.hardcopyAction = old.hardcopyAction; pref.hardcopyRange = old.hardcopyRange; pref.hardcopyLink = old.hardcopyLink; pref.searchMode = old.searchMode; pref.enableSoftHyphens = old.enableSoftHyphens; pref.lineSpacing = old.lineSpacing; pref.paragraphSpacing = old.paragraphSpacing; pref.indicateOpened = old.indicateOpened; pref.individualDocumentFonts = old.individualDocumentFonts; pref.forceDefaultColors = old.forceDefaultColors; pref.savedToolbar = old.savedToolbar; pref.savedScrollbar = old.savedScrollbar; pref.savedSilkscreen = old.savedSilkscreen; pref.pageControlsLink = old.pageControlsLink; pref.forceAlign = old.forceAlign; pref.joinUpAllRecords = old.joinUpAllRecords; pref.rotate = old.rotate; pref.defaultRotate = old.defaultRotate; pref.defaultLineSpacing = old.defaultLineSpacing; pref.defaultParagraphSpacing = old.defaultParagraphSpacing; pref.defaultFontModeMain = old.defaultFontModeMain; pref.selectedWordAction = old.selectedWordAction; pref.selectWordTap = old.selectWordTap; pref.useDateTime = old.useDateTime; pref.searchXlit = old.searchXlit; pref.hardKeys = old.hardKeys; pref.arrowKeys = old.arrowKeys; pref.gestures = old.gestures; pref.arrowKeys = old.arrowKeys; pref.jogEnabled = old.jogEnabled; StrCopy( pref.docName, old.docName ); StrCopy( pref.mainUserFontName, old.mainUserFontName ); StrCopy( pref.libraryUserFontName, old.libraryUserFontName ); StrCopy( pref.defaultMainUserFontName, old.defaultMainUserFontName ); if ( sizeof( pref.select ) == sizeof( old.select ) ) { MemMove( &pref.select, &old.select, sizeof( pref.select ) ); } else { MemSet( &pref.select, sizeof( pref.select ), SELECT_NONE ); } if ( sizeof( pref.jogMode ) == sizeof( old.jogMode ) ) { MemMove( &pref.jogMode, &old.select, sizeof( pref.jogMode ) ); } else { MemSet( &pref.jogMode, sizeof( pref.jogMode ), SELECT_NONE ); } if ( sizeof( pref.hwMode ) == sizeof( old.hwMode ) ) { MemMove( &pref.hwMode, &old.select, sizeof( pref.hwMode ) ); } else { MemSet( &pref.hwMode, sizeof( pref.hwMode ), SELECT_NONE ); } if ( sizeof( pref.gestMode ) == sizeof( old.gestMode ) ) { MemMove( &pref.gestMode, &old.select, sizeof( pref.gestMode ) ); } else { MemSet( &pref.gestMode, sizeof( pref.gestMode ), SELECT_NONE ); } if ( sizeof( pref.arrowMode ) == sizeof( old.arrowMode ) ) { MemMove( &pref.arrowMode, &old.select, sizeof( pref.arrowMode ) ); } else { MemSet( &pref.arrowMode, sizeof( pref.arrowMode ), SELECT_NONE ); } /* items not included in old format */ pref.rtl = false; pref.defaultRTL = false; pref.defaultUnderlineMode = false; pref.defaultEnableSoftHyphens = true; pref.defaultPageControlsLink = false; pref.defaultForceAlign = FORCE_ALIGN_NONE; pref.defaultStrikethrough = false; pref.defaultForceDefaultColors = false; pref.defaultSelectWordTap = SELECT_WORD_TAP_NONE; pref.defaultSelectedWordAction = SELECT_WORD_SEARCH_FORM; pref.individualDocumentLayout = false; pref.individualDocumentColor = false; pref.individualDocumentLookup = false; pref.enableMargins = true; pref.defaultEnableMargins = true; pref.noAnnotationsInBookmarkList = false; pref.alwaysDeleteAnnotations = false; RemovePref( ViewerOldPrefID ); } } else { version = PrefGetAppPreferences( (UInt32) ViewerAppID, (UInt16) ViewerPrefID, &pref, &prefSize, true); MSG( _( "Version = %d\n", version ) ); } }
/*************************************************************************** * Function: cryptSwitch * Description: handles changing the system password based upon the * password change screen. Basically checks that current password is correct, * checks that the new password was entered correctly, then re-encrypts the * databases based upon the new password. * ************************************************************************/ static void cryptSwitch (int v) { // total number of records to re-write UInt16 totalAItems = DmNumRecordsInCategory (AccountDB, dmAllCategories); UInt16 totalSItems = DmNumRecordsInCategory (SystemDB, dmAllCategories); MemPtr pac = NULL, scratch = NULL, scratch2 = NULL; UInt16 i = 0, senc = 0, aenc = 0; MemHandle rH; char s[5], a[5]; StripPrefType prefs; UInt16 prefsSize, prefsVersion; FormType *preF = FrmGetActiveForm (); FormType *f = FrmInitForm (pleaseWait); FrmDrawForm (f); // re-encrypt the password if ((rH = DmGetRecord (PasswordDB, 0))) { if ((scratch = MemPtrNew (getSCSize(sizeof(md_hash))))) { PackPassword (scratch, &NewSysPass); writeRecord (scratch, rH); MemPtrFree (scratch); } DmReleaseRecord (PasswordDB, 0, true); } // loop through the systems and re-encrypt for (i = 0; i < totalSItems; i++) { System_old sys; if ((rH = DmGetRecord (SystemDB, i))) { pac = MemHandleLock (rH); if ((scratch = MemPtrNew (MemPtrSize (pac)))) { // decrypt the system with old password switch (v) { case 0: UnpackSystem_old (&sys, pac, scratch, SysPass, MemHandleSize (rH), true, 1); scratch2 = MemPtrNew (getSystemSize((System *)&sys, true)); break; case 1: UnpackSystem_old (&sys, pac, scratch, SysPass, MemHandleSize (rH), true, 2); scratch2 = MemPtrNew (getSystemSize ((System *)&sys,true) ); break; case 2: UnpackSystem_old (&sys, pac, scratch, SysPass, MemHandleSize (rH), true, 0); scratch2 = MemPtrNew (getSystemSize ((System *)&sys, true )); break; } if (scratch2) { PackSystem(scratch2, *((System *) &sys), &NewSysPass, true); MemHandleUnlock (rH); writeRecord (scratch2, rH); senc++; MemPtrFree (scratch2); } MemPtrFree (scratch); } DmReleaseRecord (SystemDB, i, true); } } // loop through the accounts and re-encrypt for (i = 0; i < totalAItems; i++) { Account_old ac; Account ac_new; if ((rH = DmGetRecord (AccountDB, i))) { pac = MemHandleLock (rH); if ((scratch = MemPtrNew (MemPtrSize (pac)))) { // decrypt the system with old password switch (v) { case 0: UnpackAccount_old(&ac, pac, scratch, SysPass, MemHandleSize (rH), true, true, 1); ChangeAccountFormat(i, &ac, &ac_new); scratch2 = MemPtrNew (getAccountSize(&ac_new, true)); break; case 1: UnpackAccount_old (&ac, pac, scratch, SysPass, MemHandleSize (rH), true, true, 2); ChangeAccountFormat(i, &ac, &ac_new); scratch2 = MemPtrNew (getAccountSize(&ac_new, true)); break; case 2: UnpackAccount_old(&ac, pac, scratch, SysPass, MemHandleSize (rH), true, true, 0); ChangeAccountFormat(i, &ac, &ac_new); scratch2 = MemPtrNew (getAccountSize(&ac_new,true)); break; } if (scratch2) { PackAccount(scratch2, ac_new, &NewSysPass, true); MemHandleUnlock (rH); writeRecord (scratch2, rH); aenc++; MemPtrFree (scratch2); } MemPtrFree (scratch); } DmReleaseRecord (AccountDB, i, true); } } FrmEraseForm (f); FrmDeleteForm (f); FrmSetActiveForm (preF); // close databases. DmCloseDatabase (SystemDB); DmCloseDatabase (AccountDB); DmCloseDatabase (PasswordDB); { UInt16 cardNo; UInt32 type; LocalID dbID; DmSearchStateType search; type = systemDBType; DmGetNextDatabaseByTypeCreator(true, &search, systemDBTypeOld, StripCreator, true, &cardNo, &dbID); DmSetDatabaseInfo(cardNo, dbID, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &type, NULL); type = accountDBType; DmGetNextDatabaseByTypeCreator(true, &search, accountDBTypeOld, StripCreator, true, &cardNo, &dbID); DmSetDatabaseInfo(cardNo, dbID, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &type, NULL); type = passwordDBType; DmGetNextDatabaseByTypeCreator(true, &search, passwordDBTypeOld, StripCreator, true, &cardNo, &dbID); DmSetDatabaseInfo(cardNo, dbID, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &type, NULL); } prefsSize = sizeof (StripPrefType); prefsVersion = PrefGetAppPreferences (StripCreator, StripPrefID, &prefs, &prefsSize, true); if (prefsVersion != StripVersionNumber) { prefs.smart_beaming = false; PrefSetAppPreferences (StripCreator, StripPrefID, StripVersionNumber, &prefs, sizeof (StripPrefType), true); prefsVersion = PrefGetAppPreferences (StripCreator, StripPrefID, &prefs, &prefsSize, true); } StrIToA (s, senc); StrIToA (a, aenc); FrmCustomAlert (infoDialog, s, a, NULL); StopApplication (); SysReset (); }
Err AppStart(void) { UInt16 dataSize, checkSize = 0; Err error; #ifndef _DEBUG_ENGINE // delete old databases ModDelete(); #endif // allocate global variables space dataSize = sizeof(GlobalsDataType); gVars = (GlobalsDataType *)MemPtrNew(dataSize); MemSet(gVars, dataSize, 0); gVars->indicator.on = 255; gVars->indicator.off = 0; gVars->HRrefNum = sysInvalidRefNum; gVars->VFS.volRefNum = vfsInvalidVolRef; gVars->slkRefNum = sysInvalidRefNum; gVars->options = kOptNone; // set memory required by the differents engines AppStartSetMemory(); StuffsGetFeatures(); // allocate prefs space dataSize = sizeof(GlobalsPreferenceType); gPrefs = (GlobalsPreferenceType *)MemPtrNew(dataSize); MemSet(gPrefs, dataSize, 0); // Read the saved preferences / saved-state information. if (PrefGetAppPreferences(appFileCreator, appPrefID, NULL, &checkSize, true) == noPreferenceFound || checkSize != dataSize) { // reset all elements MemSet(gPrefs, dataSize, 0); gPrefs->card.volRefNum = vfsInvalidVolRef; gPrefs->card.cacheSize = 4096; gPrefs->card.useCache = true; gPrefs->card.showLED = true; gPrefs->autoOff = true; gPrefs->vibrator = RumbleExists(); gPrefs->debug = false; gPrefs->exitLauncher = true; gPrefs->stdPalette = OPTIONS_TST(kOptDeviceOS5); gPrefs->stylusClick = true; } else { PrefGetAppPreferences(appFileCreator, appPrefID, gPrefs, &dataSize, true); } if (!OPTIONS_TST(kOptDeviceARM)) { error = AppStartCheckMathLib(); if (error) return (error); } error = AppStartCheckHRmode(); if (error) return (error); bDirectMode = (AppStartLoadSkin() != errNone); // if volref previously defined, check if it's a valid one if (gPrefs->card.volRefNum != vfsInvalidVolRef) { VolumeInfoType volInfo; Err err = VFSVolumeInfo(gPrefs->card.volRefNum, &volInfo); if (err) gPrefs->card.volRefNum = parseCards(); } else gPrefs->card.volRefNum = parseCards(); if (gPrefs->card.volRefNum != vfsInvalidVolRef) CardSlotCreateDirs(); // open games database error = GamOpenDatabase(); if (error) return (error); GamImportDatabase(); AppStartCheckScreenSize(); AppStartCheckNotify(); // not fatal error if not avalaible return error; }
// ExgLibControl Err FlickrControl(UInt16 libRefNum, UInt16 op, void *valueP, UInt16 *valueLenP) { DMSG("FlickrControl() enter, op: ");DNUM(op);DMSG("; *valueLenP: ");DNUM(*valueLenP);DENDL FlickrDbOpen dbOpen; FlickrGlobalsPtr globals(libRefNum); switch (op) { case exgLibCtlGetTitle: { DMSG("FlickrControl(): exgLibCtlGetTitle\n"); if (NULL == valueLenP) return exgErrBadParam; UInt16 len = StrLen(FlickrTitle); if (0 == *valueLenP || NULL == valueP) { *valueLenP = len; return errNone; } if (*valueLenP - 1 < len) { StrNCopy((char*)valueP, FlickrTitle, *valueLenP - 1); ((char*)valueP)[*valueLenP - 1] = chrNull; } else { StrCopy((char*)valueP, FlickrTitle); *valueLenP = len + 1; } return errNone; } case exgLibCtlGetVersion: { DMSG("FlickrControl(): exgLibCtlGetVersion\n"); if (NULL == valueP || NULL == valueLenP || *valueLenP < 2) return exgErrBadParam; UInt16* ver = (UInt16*)valueP; *ver = exgLibAPIVersion; *valueLenP = 2; return errNone; } case exgLibCtlGetPreview: DMSG("FlickrControl(): exgLibCtlGetPreview\n"); return exgErrNotSupported; case flickrCtlLibraryVersion: { DMSG("FlickrControl(): flickrCtlLibraryVersion\n"); if (NULL == valueP || NULL == valueLenP || *valueLenP < 2) return exgErrBadParam; UInt16* ver = (UInt16*)valueP; *ver = FlickrVersion; *valueLenP = 2; return errNone; } case flickrCtlInitializePrefs: { DMSG("FlickrControl(): flickrCtlInitializePrefs\n"); FlickrPrefs* prefs = new FlickrPrefs; if (NULL == prefs) return memErrNotEnoughSpace; MemSet(prefs, sizeof(*prefs), 0); UInt16 size = sizeof(*prefs); Int16 ver = PrefGetAppPreferences(FlickrCreatorID, flickrPrefsResourceID, prefs, &size, true); if (noPreferenceFound != ver) goto Finish; PrvPrepareDescriptionText(*prefs); PrvPrepareTags(*prefs); FlickrSavePrefs(*prefs); Finish: delete prefs; return errNone; } } return exgErrNotSupported; }