mirror of
https://github.com/AquariaOSE/Aquaria.git
synced 2025-07-03 06:24:32 +00:00
show better errors when we fail to start up
This commit is contained in:
parent
af6c6a31aa
commit
f01db61292
8 changed files with 73 additions and 12 deletions
|
@ -23,6 +23,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
#include <assert.h>
|
||||
#include "OSFunctions.h"
|
||||
|
||||
#if SDL_VERSION_ATLEAST(2,0,0)
|
||||
#include "SDL_filesystem.h"
|
||||
#endif
|
||||
|
||||
#ifdef BBGE_BUILD_VFS
|
||||
# include "ttvfs.h"
|
||||
# ifndef VFS_IGNORE_CASE
|
||||
|
@ -253,10 +257,29 @@ bool exists(const std::string &f, bool makeFatal, bool skipVFS)
|
|||
|
||||
|
||||
|
||||
std::string getPathInfoStr()
|
||||
{
|
||||
std::ostringstream os;
|
||||
os << "Working dir (expecting game data there):\n" << getWorkingDir() << "\n";
|
||||
if(core)
|
||||
{
|
||||
os << "Preferences folder:\n" << core->getPreferencesFolder() << "\n";
|
||||
os << "User data folder:\n" << core->getUserDataFolder() << "\n";
|
||||
os << "Debug log path:\n" << core->getDebugLogPath() << "\n";
|
||||
}
|
||||
#if SDL_VERSION_ATLEAST(2,0,1)
|
||||
char *base = SDL_GetBasePath();
|
||||
os << "SDL_GetBasePath():\n" << base << "\n";
|
||||
SDL_free(base);
|
||||
#endif
|
||||
return os.str();
|
||||
}
|
||||
|
||||
void exit_error(const std::string &message)
|
||||
{
|
||||
fprintf(stderr, "FATAL: %s\n", message.c_str());
|
||||
errorLog(message);
|
||||
std::string out = message + "\n\n++ Path info for debugging aid: ++\n" + getPathInfoStr();
|
||||
fprintf(stderr, "FATAL: %s\n", out.c_str());
|
||||
errorLog(out);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
|
|
@ -154,7 +154,7 @@ bool isTouchingLine(Vector lineStart, Vector lineEnd, Vector point, int radius=1
|
|||
|
||||
void drawCircle(float radius, int steps=1);
|
||||
|
||||
|
||||
std::string getPathInfoStr();
|
||||
void exit_error(const std::string &message);
|
||||
|
||||
unsigned hash(const std::string &string);
|
||||
|
|
|
@ -412,7 +412,7 @@ void Core::initPlatform(const std::string &filesystem)
|
|||
if (!CFURLGetFileSystemRepresentation(resourcesURL, TRUE, (UInt8 *)path, PATH_MAX))
|
||||
{
|
||||
// error!
|
||||
debugLog("CFURLGetFileSystemRepresentation");
|
||||
errorLog("Core::initPlatform: CFURLGetFileSystemRepresentation error");
|
||||
}
|
||||
CFRelease(resourcesURL);
|
||||
debugLog(path);
|
||||
|
@ -423,13 +423,13 @@ void Core::initPlatform(const std::string &filesystem)
|
|||
if (chdir(filesystem.c_str()) == 0)
|
||||
return;
|
||||
else
|
||||
debugLog("Failed to chdir to filesystem path " + filesystem);
|
||||
errorLog("Core::initPlatform: Failed to chdir to filesystem path " + filesystem);
|
||||
}
|
||||
#ifdef BBGE_DATA_PREFIX
|
||||
if (chdir(BBGE_DATA_PREFIX) == 0 && chdir(appName.c_str()) == 0)
|
||||
return;
|
||||
else
|
||||
debugLog("Failed to chdir to filesystem path " BBGE_DATA_PREFIX + appName);
|
||||
errorLog("Core::initPlatform: Failed to chdir to filesystem path " BBGE_DATA_PREFIX + appName);
|
||||
#endif
|
||||
char path[PATH_MAX];
|
||||
// always a symlink to this process's binary, on modern Linux systems.
|
||||
|
@ -437,7 +437,7 @@ void Core::initPlatform(const std::string &filesystem)
|
|||
if ( (rc == -1) || (rc >= (ssize_t) sizeof (path)) )
|
||||
{
|
||||
// error!
|
||||
debugLog("readlink");
|
||||
errorLog("Core::initPlatform: readlink error");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -448,7 +448,7 @@ void Core::initPlatform(const std::string &filesystem)
|
|||
*ptr = '\0';
|
||||
debugLog(path);
|
||||
if (chdir(path) != 0)
|
||||
debugLog("Failed to chdir to executable path" + std::string(path));
|
||||
errorLog("Core::initPlatform: Failed to chdir to executable path" + std::string(path));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -457,7 +457,7 @@ void Core::initPlatform(const std::string &filesystem)
|
|||
{
|
||||
if(_chdir(filesystem.c_str()) != 0)
|
||||
{
|
||||
debugLog("chdir failed: " + filesystem);
|
||||
errorLog("chdir failed: " + filesystem);
|
||||
}
|
||||
}
|
||||
// FIXME: filesystem not handled
|
||||
|
@ -479,6 +479,11 @@ std::string Core::getUserDataFolder()
|
|||
return userDataFolder;
|
||||
}
|
||||
|
||||
std::string Core::getDebugLogPath()
|
||||
{
|
||||
return debugLogPath;
|
||||
}
|
||||
|
||||
Core::~Core()
|
||||
{
|
||||
clearActionButtons();
|
||||
|
|
|
@ -216,6 +216,7 @@ public:
|
|||
|
||||
std::string getPreferencesFolder();
|
||||
std::string getUserDataFolder();
|
||||
std::string getDebugLogPath();
|
||||
|
||||
void resetCamera();
|
||||
|
||||
|
|
|
@ -469,3 +469,14 @@ std::string getSystemLocale()
|
|||
|
||||
return localeStr;
|
||||
}
|
||||
|
||||
std::string getWorkingDir()
|
||||
{
|
||||
char buf[1024*2] = {0};
|
||||
#ifdef _WIN32
|
||||
GetCurrentDirectoryA(sizeof(buf), buf);
|
||||
#else
|
||||
getcwd(buf, sizeof(buf))
|
||||
#endif
|
||||
return buf;
|
||||
}
|
||||
|
|
|
@ -13,5 +13,6 @@ bool createDir(const std::string& d);
|
|||
void triggerBreakpoint();
|
||||
void openURL(const std::string &url);
|
||||
std::string getSystemLocale();
|
||||
std::string getWorkingDir();
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue