diff --git a/source/fileop.cpp b/source/fileop.cpp index 5e3f776..da04a88 100644 --- a/source/fileop.cpp +++ b/source/fileop.cpp @@ -698,6 +698,20 @@ ParseDirectory(bool waitParse, bool filter) 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 () * Clear and allocate the savebuffer diff --git a/source/fileop.h b/source/fileop.h index 716f204..9ff49d3 100644 --- a/source/fileop.h +++ b/source/fileop.h @@ -34,6 +34,7 @@ void CreateAppPath(char * origpath); bool GetFileSize(int i); void FindAndSelectLastLoadedFile(); int ParseDirectory(bool waitParse = false, bool filter = true); +bool CreateDirectory(char * path); void AllocSaveBuffer(); void FreeSaveBuffer(); size_t LoadFile(char * rbuffer, char *filepath, size_t length, bool silent); diff --git a/source/preferences.cpp b/source/preferences.cpp index d6eb018..714a0a5 100644 --- a/source/preferences.cpp +++ b/source/preferences.cpp @@ -633,7 +633,6 @@ DefaultSettings () GCSettings.SaveMethod = DEVICE_AUTO; // Auto, SD, USB, Network (SMB) sprintf (GCSettings.LoadFolder, "%s/roms", APPFOLDER); // Path to game 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.BorderFolder, "%s/borders", APPFOLDER); sprintf (GCSettings.CoverFolder, "%s/covers", APPFOLDER); // Path to cover files @@ -839,6 +838,17 @@ bool LoadPrefs() if(prefFound) 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(); return prefFound; }