automatically create preview image dirs if they don't exist

This commit is contained in:
Daryl Borth 2018-08-02 11:28:16 -06:00
parent f4d6743273
commit 50413d4e53
3 changed files with 26 additions and 1 deletions

View File

@ -698,6 +698,20 @@ ParseDirectory(bool waitParse, bool filter)
return browser.numEntries; return browser.numEntries;
} }
bool CreateDirectory(char * path)
{
DIR *dir = opendir(path);
if (!dir) {
if(mkdir(path, 0777) != 0) {
return false;
}
}
else {
closedir(dir);
}
return true;
}
/**************************************************************************** /****************************************************************************
* AllocSaveBuffer () * AllocSaveBuffer ()
* Clear and allocate the savebuffer * Clear and allocate the savebuffer

View File

@ -34,6 +34,7 @@ void CreateAppPath(char * origpath);
bool GetFileSize(int i); bool GetFileSize(int i);
void FindAndSelectLastLoadedFile(); void FindAndSelectLastLoadedFile();
int ParseDirectory(bool waitParse = false, bool filter = true); int ParseDirectory(bool waitParse = false, bool filter = true);
bool CreateDirectory(char * path);
void AllocSaveBuffer(); void AllocSaveBuffer();
void FreeSaveBuffer(); void FreeSaveBuffer();
size_t LoadFile(char * rbuffer, char *filepath, size_t length, bool silent); size_t LoadFile(char * rbuffer, char *filepath, size_t length, bool silent);

View File

@ -633,7 +633,6 @@ DefaultSettings ()
GCSettings.SaveMethod = DEVICE_AUTO; // Auto, SD, USB, Network (SMB) GCSettings.SaveMethod = DEVICE_AUTO; // Auto, SD, USB, Network (SMB)
sprintf (GCSettings.LoadFolder, "%s/roms", APPFOLDER); // Path to game files sprintf (GCSettings.LoadFolder, "%s/roms", APPFOLDER); // Path to game files
sprintf (GCSettings.SaveFolder, "%s/saves", APPFOLDER); // Path to save files sprintf (GCSettings.SaveFolder, "%s/saves", APPFOLDER); // Path to save files
//sprintf (GCSettings.CheatFolder, "%s/cheats", APPFOLDER); // Path to cheat files
sprintf (GCSettings.ScreenshotsFolder, "%s/screenshots", APPFOLDER); sprintf (GCSettings.ScreenshotsFolder, "%s/screenshots", APPFOLDER);
sprintf (GCSettings.BorderFolder, "%s/borders", APPFOLDER); sprintf (GCSettings.BorderFolder, "%s/borders", APPFOLDER);
sprintf (GCSettings.CoverFolder, "%s/covers", APPFOLDER); // Path to cover files sprintf (GCSettings.CoverFolder, "%s/covers", APPFOLDER); // Path to cover files
@ -839,6 +838,17 @@ bool LoadPrefs()
if(prefFound) if(prefFound)
FixInvalidSettings(); FixInvalidSettings();
// attempt to create directories if they don't exist
if(GCSettings.LoadMethod != DEVICE_AUTO) {
char dirPath[MAXPATHLEN];
sprintf(dirPath, "%s%s", pathPrefix[GCSettings.LoadMethod], GCSettings.ScreenshotsFolder);
CreateDirectory(dirPath);
sprintf(dirPath, "%s%s", pathPrefix[GCSettings.LoadMethod], GCSettings.CoverFolder);
CreateDirectory(dirPath);
sprintf(dirPath, "%s%s", pathPrefix[GCSettings.LoadMethod], GCSettings.ArtworkFolder);
CreateDirectory(dirPath);
}
ResetText(); ResetText();
return prefFound; return prefFound;
} }