automatically create screenshots dir if it doesn't exist

This commit is contained in:
Daryl Borth 2018-08-02 11:27:34 -06:00
parent 70ce1b8239
commit cd7248af31
3 changed files with 22 additions and 2 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

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

@ -580,8 +580,6 @@ bool LoadPrefs()
sprintf(filepath[1], "cardb:/%s", APPFOLDER);
#endif
printf("in load prefs\n");
for(int i=0; i<numDevices; i++)
{
prefFound = LoadPrefsFromMethod(filepath[i]);
@ -595,6 +593,13 @@ bool LoadPrefs()
if(prefFound)
FixInvalidSettings();
// attempt to create screenshots directory if it doesn't exist
if(GCSettings.LoadMethod != DEVICE_AUTO) {
char dirPath[MAXPATHLEN];
sprintf(dirPath, "%s%s", pathPrefix[GCSettings.LoadMethod], GCSettings.ScreenshotsFolder);
CreateDirectory(dirPath);
}
ResetText();
return prefFound;
}