Fix for issue 734 (creating profile on a fresh install is completely broken.)

This commit is contained in:
wagic.the.homebrew
2011-09-17 08:42:13 +00:00
parent a6c458d0cb
commit c96d2fea55
6 changed files with 38 additions and 35 deletions

View File

@@ -132,6 +132,8 @@ public:
//Returns true if strdirname exists somewhere in the fileSystem, and is a directory //Returns true if strdirname exists somewhere in the fileSystem, and is a directory
bool DirExists(const string& strDirname); bool DirExists(const string& strDirname);
bool MakeDir(const string & dir);
static void init( const string & userPath, const string & systemPath = ""); static void init( const string & userPath, const string & systemPath = "");

View File

@@ -19,6 +19,11 @@ The content that users should not be touching.
#ifdef WIN32 #ifdef WIN32
#pragma warning(disable : 4786) #pragma warning(disable : 4786)
#include <direct.h>
#define MAKEDIR(name) _mkdir(name)
#else
#include <sys/stat.h>
#define MAKEDIR(name) mkdir(name, 0777)
#endif #endif
#include "../include/JGE.h" #include "../include/JGE.h"
@@ -149,6 +154,8 @@ JFileSystem::JFileSystem(const string & _userPath, const string & _systemPath)
} }
mUserFSPath = userPath; mUserFSPath = userPath;
MAKEDIR(userPath.c_str());
mSystemFSPath = systemPath; mSystemFSPath = systemPath;
mUserFS = new filesystem(userPath.c_str()); mUserFS = new filesystem(userPath.c_str());
@@ -184,6 +191,13 @@ bool JFileSystem::FileExists(const string& strFilename)
return result; return result;
} }
bool JFileSystem::MakeDir(const string & dir)
{
string fullDir = mUserFSPath + dir;
MAKEDIR(fullDir.c_str());
return true;
}
JFileSystem::~JFileSystem() JFileSystem::~JFileSystem()
{ {
clearZipCache(); clearZipCache();

View File

@@ -425,6 +425,7 @@ private:
GameApp* theGame; GameApp* theGame;
SimplePad* keypad; SimplePad* keypad;
StyleManager* styleMan; StyleManager* styleMan;
void createProfileFolders();
}; };
extern GameSettings options; extern GameSettings options;

View File

@@ -86,13 +86,13 @@ void dumpStack();
u32 ramAvailableLineareMax(void); u32 ramAvailableLineareMax(void);
u32 ramAvailable(void); u32 ramAvailable(void);
/*
#ifdef WIN32 #ifdef WIN32
#include <direct.h> #include <direct.h>
#define MAKEDIR(name) _mkdir(name)
#else #else
#include <sys/stat.h> #include <sys/stat.h>
#define MAKEDIR(name) mkdir(name, 0777)
#endif #endif
*/
bool fileExists(const char * filename); bool fileExists(const char * filename);
bool FileExists(const string & filename); bool FileExists(const string & filename);

View File

@@ -102,14 +102,10 @@ void GameApp::Create()
// Create User Folders (for write access) if they don't exist // 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"}; 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) for (size_t i = 0; i < sizeof(folders)/sizeof(folders[0]); ++i)
{ {
string current(folders[i]); JFileSystem::GetInstance()->MakeDir(string(folders[i]));
string folder = userRoot + current;
MAKEDIR(folder.c_str());
} }
} }

View File

@@ -633,24 +633,26 @@ GameOption* GameSettings::get(int optionID)
return &invalid_option; 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() int GameSettings::save()
{ {
if (globalOptions) if (globalOptions)
globalOptions->save(); globalOptions->save();
if (profileOptions) createProfileFolders();
{
//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();
}
checkProfile(); checkProfile();
@@ -714,7 +716,7 @@ void GameSettings::checkProfile()
if (!profileOptions) if (!profileOptions)
{ {
profileOptions = NEW GameOptions(profileFile(PLAYER_SETTINGS, "", false)); 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++) for (int x = Options::BEGIN_AWARDS; x < Options::LAST_NAMED; x++)
{ {
GameOptionAward * goa = dynamic_cast<GameOptionAward *> (globalOptions->get(x)); GameOptionAward * goa = dynamic_cast<GameOptionAward *> (globalOptions->get(x));
@@ -736,20 +738,8 @@ void GameSettings::checkProfile()
{ {
//If we had any default settings, we'd set them here. //If we had any default settings, we'd set them here.
//Create proper directories
//Make the proper directories createProfileFolders();
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();
}
} }
//Find the set for which we have the most variety //Find the set for which we have the most variety