Fix for issue 734 (creating profile on a fresh install is completely broken.)
This commit is contained in:
@@ -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 = "");
|
||||
|
||||
|
||||
|
||||
@@ -19,6 +19,11 @@ The content that users should not be touching.
|
||||
|
||||
#ifdef WIN32
|
||||
#pragma warning(disable : 4786)
|
||||
#include <direct.h>
|
||||
#define MAKEDIR(name) _mkdir(name)
|
||||
#else
|
||||
#include <sys/stat.h>
|
||||
#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();
|
||||
|
||||
@@ -425,6 +425,7 @@ private:
|
||||
GameApp* theGame;
|
||||
SimplePad* keypad;
|
||||
StyleManager* styleMan;
|
||||
void createProfileFolders();
|
||||
};
|
||||
|
||||
extern GameSettings options;
|
||||
|
||||
@@ -86,13 +86,13 @@ void dumpStack();
|
||||
u32 ramAvailableLineareMax(void);
|
||||
u32 ramAvailable(void);
|
||||
|
||||
/*
|
||||
#ifdef WIN32
|
||||
#include <direct.h>
|
||||
#define MAKEDIR(name) _mkdir(name)
|
||||
#else
|
||||
#include <sys/stat.h>
|
||||
#define MAKEDIR(name) mkdir(name, 0777)
|
||||
#endif
|
||||
*/
|
||||
|
||||
bool fileExists(const char * filename);
|
||||
bool FileExists(const string & filename);
|
||||
|
||||
@@ -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]));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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<GameOptionAward *> (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
|
||||
|
||||
Reference in New Issue
Block a user