mirror of
https://github.com/AquariaOSE/Aquaria.git
synced 2025-06-08 09:31:58 +00:00
replace CreateDirA() and mkdir() scattered everywhere by createDir() with some more error checking.
This commit is contained in:
parent
7de589e275
commit
ab752e1156
5 changed files with 47 additions and 27 deletions
|
@ -62,7 +62,7 @@ static void Linux_CopyTree(const char *src, const char *dst)
|
||||||
|
|
||||||
if (S_ISDIR(statbuf.st_mode))
|
if (S_ISDIR(statbuf.st_mode))
|
||||||
{
|
{
|
||||||
mkdir(dst, 0700); // don't care if this fails.
|
createDir(dst); // don't care if this fails.
|
||||||
DIR *dirp = opendir(src);
|
DIR *dirp = opendir(src);
|
||||||
if (dirp == NULL)
|
if (dirp == NULL)
|
||||||
return;
|
return;
|
||||||
|
@ -156,8 +156,6 @@ Vector savesz;
|
||||||
DSQ::DSQ(const std::string& fileSystem, const std::string& extraDataDir)
|
DSQ::DSQ(const std::string& fileSystem, const std::string& extraDataDir)
|
||||||
: Core(fileSystem, extraDataDir, LR_MAX, APPNAME, PARTICLE_AMOUNT_DEFAULT, "Aquaria")
|
: Core(fileSystem, extraDataDir, LR_MAX, APPNAME, PARTICLE_AMOUNT_DEFAULT, "Aquaria")
|
||||||
{
|
{
|
||||||
// 2048
|
|
||||||
//createDirectory(getSaveDirectory());
|
|
||||||
dsq = this;
|
dsq = this;
|
||||||
|
|
||||||
cutscene_bg = 0;
|
cutscene_bg = 0;
|
||||||
|
@ -947,14 +945,9 @@ This build is not yet final, and as such there are a couple things lacking. They
|
||||||
Linux_CopyTree(core->adjustFilenameCase("_mods").c_str(), core->adjustFilenameCase(fn).c_str());
|
Linux_CopyTree(core->adjustFilenameCase("_mods").c_str(), core->adjustFilenameCase(fn).c_str());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
std::string p1 = getUserDataFolder();
|
createDir(getUserDataFolder());
|
||||||
std::string p2 = getUserDataFolder() + "/save";
|
createDir(getUserDataFolder() + "/save");
|
||||||
#if defined(BBGE_BUILD_UNIX)
|
createDir(getUserDataFolder() + "/_mods");
|
||||||
mkdir(p1.c_str(), S_IRWXU);
|
|
||||||
mkdir(p2.c_str(), S_IRWXU);
|
|
||||||
#elif defined(BBGE_BUILD_WINDOWS)
|
|
||||||
CreateDirectoryA(p2.c_str(), NULL);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
addStateInstance(game = new Game);
|
addStateInstance(game = new Game);
|
||||||
addStateInstance(new GameOver);
|
addStateInstance(new GameOver);
|
||||||
|
@ -2670,6 +2663,8 @@ void DSQ::clearMenu(float t)
|
||||||
|
|
||||||
void DSQ::screenMessage(const std::string &msg)
|
void DSQ::screenMessage(const std::string &msg)
|
||||||
{
|
{
|
||||||
|
debugLog(msg);
|
||||||
|
|
||||||
DebugFont *b = new DebugFont();
|
DebugFont *b = new DebugFont();
|
||||||
b->position = Vector(16,300);
|
b->position = Vector(16,300);
|
||||||
b->setFontSize(10);
|
b->setFontSize(10);
|
||||||
|
|
|
@ -22,16 +22,6 @@ using Network::NE_UPDATE;
|
||||||
ModDL moddl;
|
ModDL moddl;
|
||||||
|
|
||||||
|
|
||||||
// TODO: move this to Base.cpp and replace other similar occurrances
|
|
||||||
static void createDir(const char *d)
|
|
||||||
{
|
|
||||||
#if defined(BBGE_BUILD_UNIX)
|
|
||||||
mkdir(d, S_IRWXU);
|
|
||||||
#elif defined(BBGE_BUILD_WINDOWS)
|
|
||||||
CreateDirectoryA(d, NULL);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
// .../_mods/<MODNAME>
|
// .../_mods/<MODNAME>
|
||||||
// .../_mods/<MODNAME>.zip
|
// .../_mods/<MODNAME>.zip
|
||||||
static std::string _PathToModName(const std::string& path)
|
static std::string _PathToModName(const std::string& path)
|
||||||
|
|
|
@ -1170,6 +1170,38 @@ void triggerBreakpoint()
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool createDir(const std::string& d)
|
||||||
|
{
|
||||||
|
bool success = false;
|
||||||
|
int err = 0;
|
||||||
|
#if defined(BBGE_BUILD_UNIX)
|
||||||
|
if (!mkdir(d.c_str(), S_IRWXU))
|
||||||
|
success = true;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
err = errno;
|
||||||
|
if (err == EEXIST)
|
||||||
|
success = true;
|
||||||
|
}
|
||||||
|
#elif defined(BBGE_BUILD_WINDOWS)
|
||||||
|
if (CreateDirectoryA(d.c_str(), NULL))
|
||||||
|
success = true;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
err = GetLastError();
|
||||||
|
if(err == ERROR_ALREADY_EXISTS)
|
||||||
|
success = true;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
if (!success)
|
||||||
|
{
|
||||||
|
std::ostringstream os;
|
||||||
|
os << "Failed to create directory: [" << d << "], error code: " << err;
|
||||||
|
debugLog(os.str());
|
||||||
|
}
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#include "DeflateCompressor.h"
|
#include "DeflateCompressor.h"
|
||||||
|
|
||||||
|
|
|
@ -302,5 +302,7 @@ std::string spacesToUnderscores(const std::string &str);
|
||||||
|
|
||||||
void triggerBreakpoint();
|
void triggerBreakpoint();
|
||||||
|
|
||||||
|
bool createDir(const std::string& d);
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -899,7 +899,7 @@ Core::Core(const std::string &filesystem, const std::string& extraDataDir, int n
|
||||||
envr = "."; // oh well.
|
envr = "."; // oh well.
|
||||||
const std::string home(envr);
|
const std::string home(envr);
|
||||||
|
|
||||||
mkdir(home.c_str(), 0700); // just in case.
|
createDir(home); // just in case.
|
||||||
|
|
||||||
// "/home/icculus/.Aquaria" or something. Spaces are okay.
|
// "/home/icculus/.Aquaria" or something. Spaces are okay.
|
||||||
#ifdef BBGE_BUILD_MACOSX
|
#ifdef BBGE_BUILD_MACOSX
|
||||||
|
@ -909,11 +909,12 @@ Core::Core(const std::string &filesystem, const std::string& extraDataDir, int n
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
userDataFolder = home + "/" + prefix + userDataSubFolder;
|
userDataFolder = home + "/" + prefix + userDataSubFolder;
|
||||||
mkdir(userDataFolder.c_str(), 0700);
|
createDir(userDataFolder);
|
||||||
debugLogPath = userDataFolder + "/";
|
debugLogPath = userDataFolder + "/";
|
||||||
mkdir((userDataFolder + "/screenshots").c_str(), 0700);
|
createDir(userDataFolder + "/screenshots");
|
||||||
std::string prefpath(getPreferencesFolder());
|
std::string prefpath(getPreferencesFolder());
|
||||||
mkdir(prefpath.c_str(), 0700);
|
createDir(prefpath);
|
||||||
|
|
||||||
#else
|
#else
|
||||||
debugLogPath = "";
|
debugLogPath = "";
|
||||||
userDataFolder = ".";
|
userDataFolder = ".";
|
||||||
|
@ -929,7 +930,7 @@ Core::Core(const std::string &filesystem, const std::string& extraDataDir, int n
|
||||||
// not sure about this right now -- FG
|
// not sure about this right now -- FG
|
||||||
/*else
|
/*else
|
||||||
{
|
{
|
||||||
puts("Working directory is not writeable...");
|
puts("Working directory is not writable...");
|
||||||
char pathbuf[MAX_PATH];
|
char pathbuf[MAX_PATH];
|
||||||
if(SHGetSpecialFolderPathA(NULL, &pathbuf[0], CSIDL_APPDATA, 0))
|
if(SHGetSpecialFolderPathA(NULL, &pathbuf[0], CSIDL_APPDATA, 0))
|
||||||
{
|
{
|
||||||
|
@ -941,7 +942,7 @@ Core::Core(const std::string &filesystem, const std::string& extraDataDir, int n
|
||||||
userDataFolder[i] = '/';
|
userDataFolder[i] = '/';
|
||||||
debugLogPath = userDataFolder + "/";
|
debugLogPath = userDataFolder + "/";
|
||||||
puts(("Using \"" + userDataFolder + "\" as user directory.").c_str());
|
puts(("Using \"" + userDataFolder + "\" as user directory.").c_str());
|
||||||
CreateDirectoryA(userDataFolder.c_str(), NULL);
|
createDir(userDataFolder);
|
||||||
checkWritable(userDataFolder, true, true);
|
checkWritable(userDataFolder, true, true);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
Loading…
Add table
Reference in a new issue