1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2025-10-05 22:02:38 +00:00

replace CreateDirA() and mkdir() scattered everywhere by createDir() with some more error checking.

This commit is contained in:
fgenesis 2013-11-14 20:07:39 +01:00
commit ab752e1156
5 changed files with 47 additions and 27 deletions

View file

@ -1170,6 +1170,38 @@ void triggerBreakpoint()
#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"

View file

@ -302,5 +302,7 @@ std::string spacesToUnderscores(const std::string &str);
void triggerBreakpoint();
bool createDir(const std::string& d);
#endif

View file

@ -899,7 +899,7 @@ Core::Core(const std::string &filesystem, const std::string& extraDataDir, int n
envr = "."; // oh well.
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.
#ifdef BBGE_BUILD_MACOSX
@ -909,11 +909,12 @@ Core::Core(const std::string &filesystem, const std::string& extraDataDir, int n
#endif
userDataFolder = home + "/" + prefix + userDataSubFolder;
mkdir(userDataFolder.c_str(), 0700);
createDir(userDataFolder);
debugLogPath = userDataFolder + "/";
mkdir((userDataFolder + "/screenshots").c_str(), 0700);
createDir(userDataFolder + "/screenshots");
std::string prefpath(getPreferencesFolder());
mkdir(prefpath.c_str(), 0700);
createDir(prefpath);
#else
debugLogPath = "";
userDataFolder = ".";
@ -929,7 +930,7 @@ Core::Core(const std::string &filesystem, const std::string& extraDataDir, int n
// not sure about this right now -- FG
/*else
{
puts("Working directory is not writeable...");
puts("Working directory is not writable...");
char pathbuf[MAX_PATH];
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] = '/';
debugLogPath = userDataFolder + "/";
puts(("Using \"" + userDataFolder + "\" as user directory.").c_str());
CreateDirectoryA(userDataFolder.c_str(), NULL);
createDir(userDataFolder);
checkWritable(userDataFolder, true, true);
}
else