automatically create preview image dirs if they don't exist

This commit is contained in:
Daryl Borth 2018-08-02 11:28:00 -06:00
parent b66d66e82e
commit 6788d15aae
3 changed files with 28 additions and 1 deletions

View File

@ -699,6 +699,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

View File

@ -37,6 +37,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);

View File

@ -651,8 +651,9 @@ bool LoadPrefs()
prefLoaded = true; // attempted to load preferences
if(prefFound)
if(prefFound) {
FixInvalidSettings();
}
// rename snes9x to snes9xgx
if(GCSettings.LoadMethod == DEVICE_SD)
@ -690,6 +691,17 @@ bool LoadPrefs()
if(strcmp(GCSettings.ArtworkFolder, "snes9x/artworks") == 0)
sprintf(GCSettings.ArtworkFolder, "snes9xgx/artworks");
// 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;
}