1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2024-11-15 14:09:06 +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
parent 7de589e275
commit ab752e1156
5 changed files with 47 additions and 27 deletions

View file

@ -62,7 +62,7 @@ static void Linux_CopyTree(const char *src, const char *dst)
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);
if (dirp == NULL)
return;
@ -156,8 +156,6 @@ Vector savesz;
DSQ::DSQ(const std::string& fileSystem, const std::string& extraDataDir)
: Core(fileSystem, extraDataDir, LR_MAX, APPNAME, PARTICLE_AMOUNT_DEFAULT, "Aquaria")
{
// 2048
//createDirectory(getSaveDirectory());
dsq = this;
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());
#endif
std::string p1 = getUserDataFolder();
std::string p2 = getUserDataFolder() + "/save";
#if defined(BBGE_BUILD_UNIX)
mkdir(p1.c_str(), S_IRWXU);
mkdir(p2.c_str(), S_IRWXU);
#elif defined(BBGE_BUILD_WINDOWS)
CreateDirectoryA(p2.c_str(), NULL);
#endif
createDir(getUserDataFolder());
createDir(getUserDataFolder() + "/save");
createDir(getUserDataFolder() + "/_mods");
addStateInstance(game = new Game);
addStateInstance(new GameOver);
@ -2670,6 +2663,8 @@ void DSQ::clearMenu(float t)
void DSQ::screenMessage(const std::string &msg)
{
debugLog(msg);
DebugFont *b = new DebugFont();
b->position = Vector(16,300);
b->setFontSize(10);

View file

@ -22,16 +22,6 @@ using Network::NE_UPDATE;
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>.zip
static std::string _PathToModName(const std::string& path)

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