Skip to content
This repository has been archived by the owner on Jan 13, 2020. It is now read-only.

Commit

Permalink
Merge pull request #7 from hi-ban/master
Browse files Browse the repository at this point in the history
Added rom browser saving the last selected rom.
  • Loading branch information
Nebuleon committed Jan 27, 2014
2 parents b3b329a + b37c010 commit 2c27d4e
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions menu/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,40 @@ s32 DeleteMenuOptions(const char *path, const char *filename,
return SAL_OK;
}

s32 LoadLastSelectedRomPos() // Try to get the last selected rom position from a config file
{
char lastselfile[SAL_MAX_PATH];
s32 savedval = ROM_SELECTOR_DEFAULT_FOCUS;
strcpy(lastselfile, sal_DirectoryGetHome());
sal_DirectoryCombine(lastselfile, "lastselected.opt");
FILE * pFile;
pFile = fopen (lastselfile,"r+");
if (pFile != NULL) {
fscanf (pFile, "%i", &savedval);
fclose (pFile);
}
return savedval;
}

void SaveLastSelectedRomPos(s32 pospointer) // Save the last selected rom position in a config file
{
char lastselfile[SAL_MAX_PATH];
strcpy(lastselfile, sal_DirectoryGetHome());
sal_DirectoryCombine(lastselfile, "lastselected.opt");
FILE * pFile;
pFile = fopen (lastselfile,"w+");
fprintf (pFile, "%i", pospointer);
fclose (pFile);
}

void DelLastSelectedRomPos() // Remove the last selected rom position config file
{
char lastselfile[SAL_MAX_PATH];
strcpy(lastselfile, sal_DirectoryGetHome());
sal_DirectoryCombine(lastselfile, "lastselected.opt");
remove (lastselfile);
}

void MenuPause()
{
sal_InputWaitForPress();
Expand Down Expand Up @@ -408,6 +442,8 @@ s32 FileSelect()
return 0;
}
}

focus = LoadLastSelectedRomPos(); //try to load a saved position in the romlist

smooth=focus<<8;
sal_InputIgnore();
Expand Down Expand Up @@ -471,6 +507,7 @@ s32 FileSelect()
switch(focus)
{
case ROM_SELECTOR_SAVE_DEFAULT_DIR: //Save default directory
DelLastSelectedRomPos(); //delete any previously saved position in the romlist
SaveMenuOptions(mSystemDir, DEFAULT_ROM_DIR_FILENAME, DEFAULT_ROM_DIR_EXT, mRomDir, strlen(mRomDir), 1);
break;

Expand Down Expand Up @@ -519,6 +556,7 @@ s32 FileSelect()
else
{
// user has selected a rom, so load it
SaveLastSelectedRomPos(focus); // save the current position in the romlist
strcpy(mRomName, mRomDir);
sal_DirectoryCombine(mRomName,mRomList[focus].filename);
mQuickSavePresent=0; // reset any quick saves
Expand Down

0 comments on commit 2c27d4e

Please sign in to comment.