diff --git a/JGE/include/JFileSystem.h b/JGE/include/JFileSystem.h index c882c61e0..1b85889ab 100644 --- a/JGE/include/JFileSystem.h +++ b/JGE/include/JFileSystem.h @@ -132,6 +132,8 @@ public: //Returns true if strdirname exists somewhere in the fileSystem, and is a directory bool DirExists(const string& strDirname); + bool MakeDir(const string & dir); + static void init( const string & userPath, const string & systemPath = ""); diff --git a/JGE/src/JFileSystem.cpp b/JGE/src/JFileSystem.cpp index 92812bf38..8dbcc722a 100644 --- a/JGE/src/JFileSystem.cpp +++ b/JGE/src/JFileSystem.cpp @@ -19,6 +19,11 @@ The content that users should not be touching. #ifdef WIN32 #pragma warning(disable : 4786) +#include +#define MAKEDIR(name) _mkdir(name) +#else +#include +#define MAKEDIR(name) mkdir(name, 0777) #endif #include "../include/JGE.h" @@ -149,6 +154,8 @@ JFileSystem::JFileSystem(const string & _userPath, const string & _systemPath) } mUserFSPath = userPath; + MAKEDIR(userPath.c_str()); + mSystemFSPath = systemPath; mUserFS = new filesystem(userPath.c_str()); @@ -184,6 +191,13 @@ bool JFileSystem::FileExists(const string& strFilename) return result; } +bool JFileSystem::MakeDir(const string & dir) +{ + string fullDir = mUserFSPath + dir; + MAKEDIR(fullDir.c_str()); + return true; +} + JFileSystem::~JFileSystem() { clearZipCache(); diff --git a/projects/mtg/include/GameOptions.h b/projects/mtg/include/GameOptions.h index 2b4d7a9d1..39c7cac6d 100644 --- a/projects/mtg/include/GameOptions.h +++ b/projects/mtg/include/GameOptions.h @@ -425,6 +425,7 @@ private: GameApp* theGame; SimplePad* keypad; StyleManager* styleMan; + void createProfileFolders(); }; extern GameSettings options; diff --git a/projects/mtg/include/utils.h b/projects/mtg/include/utils.h index 9a5863442..a1fc5bf54 100644 --- a/projects/mtg/include/utils.h +++ b/projects/mtg/include/utils.h @@ -86,13 +86,13 @@ void dumpStack(); u32 ramAvailableLineareMax(void); u32 ramAvailable(void); +/* #ifdef WIN32 #include -#define MAKEDIR(name) _mkdir(name) #else #include -#define MAKEDIR(name) mkdir(name, 0777) #endif +*/ bool fileExists(const char * filename); bool FileExists(const string & filename); diff --git a/projects/mtg/src/GameApp.cpp b/projects/mtg/src/GameApp.cpp index cf821965e..e1842895e 100644 --- a/projects/mtg/src/GameApp.cpp +++ b/projects/mtg/src/GameApp.cpp @@ -102,14 +102,10 @@ void GameApp::Create() // Create User Folders (for write access) if they don't exist { const char* folders[] = { "ai", "ai/baka", "ai/baka/stats", "campaigns", "graphics", "lang", "packs", "player", "player/stats", "profiles", "rules", "sets", "settings", "sound", "sound/sfx", "themes", "test"}; - string userRoot = JFileSystem::GetInstance()->GetUserRoot(); - MAKEDIR(userRoot.c_str()); for (size_t i = 0; i < sizeof(folders)/sizeof(folders[0]); ++i) { - string current(folders[i]); - string folder = userRoot + current; - MAKEDIR(folder.c_str()); + JFileSystem::GetInstance()->MakeDir(string(folders[i])); } } diff --git a/projects/mtg/src/GameOptions.cpp b/projects/mtg/src/GameOptions.cpp index c35a7cbf4..a423f67fa 100644 --- a/projects/mtg/src/GameOptions.cpp +++ b/projects/mtg/src/GameOptions.cpp @@ -633,24 +633,26 @@ GameOption* GameSettings::get(int optionID) return &invalid_option; } +void GameSettings::createProfileFolders() +{ + if (!profileOptions) + return; + + string temp = profileFile("", "", false); + JFileSystem::GetInstance()->MakeDir(temp); + temp += "/stats"; + JFileSystem::GetInstance()->MakeDir(temp); + temp = profileFile(PLAYER_SETTINGS, "", false); + + profileOptions->save(); +} + int GameSettings::save() { if (globalOptions) globalOptions->save(); - if (profileOptions) - { - //Create a temp directory - // Erwan 2011/08/14: what does this really do? temp is never used. - /* - string temp = profileFile("", "", false); - MAKEDIR(temp.c_str()); - temp += "/stats"; - MAKEDIR(temp.c_str()); - temp = profileFile(PLAYER_SETTINGS, "", false); - */ - profileOptions->save(); - } + createProfileFolders(); checkProfile(); @@ -714,7 +716,7 @@ void GameSettings::checkProfile() if (!profileOptions) { profileOptions = NEW GameOptions(profileFile(PLAYER_SETTINGS, "", false)); - //Backwards compatability hack for unlocked modes. + //Backwards compatibility hack for unlocked modes. for (int x = Options::BEGIN_AWARDS; x < Options::LAST_NAMED; x++) { GameOptionAward * goa = dynamic_cast (globalOptions->get(x)); @@ -736,20 +738,8 @@ void GameSettings::checkProfile() { //If we had any default settings, we'd set them here. - - //Make the proper directories - if (profileOptions) - { - //Force our directories to exist. - /* - string temp = profileFile("", "", false); - MAKEDIR(temp.c_str()); - temp += "/stats"; - MAKEDIR(temp.c_str()); - temp = profileFile(PLAYER_SETTINGS, "", false); - */ - profileOptions->save(); - } + //Create proper directories + createProfileFolders(); } //Find the set for which we have the most variety