added a check for data and user data paths being the same

This commit is contained in:
Mark Vejvoda 2013-11-06 00:31:36 +00:00
parent e689ac8bff
commit 70421d1b3d
7 changed files with 70 additions and 39 deletions

View File

@ -104,6 +104,7 @@ using namespace Shared;
namespace Glest { namespace Game {
static string tempDataLocation = getUserHome();
static string mg_app_name = "";
static string mailStringSupport = "";
static bool sdl_quitCalled = false;
@ -578,7 +579,7 @@ void stackdumper(unsigned int type, EXCEPTION_POINTERS *ep, bool fatalExit) {
mainProgram->showMessage(msg.c_str());
}
message(msg.c_str(),GlobalStaticFlags::getIsNonGraphicalModeEnabled());
message(msg.c_str(),GlobalStaticFlags::getIsNonGraphicalModeEnabled(),tempDataLocation);
}
#endif
@ -594,7 +595,7 @@ void stackdumper(unsigned int type, EXCEPTION_POINTERS *ep, bool fatalExit) {
mainProgram->showMessage(msg.c_str());
}
message(msg.c_str(),GlobalStaticFlags::getIsNonGraphicalModeEnabled());
message(msg.c_str(),GlobalStaticFlags::getIsNonGraphicalModeEnabled(),tempDataLocation);
}
void ExceptionHandler::logError(const char *msg, bool confirmToConsole) {
@ -763,7 +764,7 @@ void stackdumper(unsigned int type, EXCEPTION_POINTERS *ep, bool fatalExit) {
#endif
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
message(err,GlobalStaticFlags::getIsNonGraphicalModeEnabled());
message(err,GlobalStaticFlags::getIsNonGraphicalModeEnabled(),tempDataLocation);
}
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
@ -819,7 +820,7 @@ void stackdumper(unsigned int type, EXCEPTION_POINTERS *ep, bool fatalExit) {
}
else {
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] msg [%s] exitApp = %d\n",__FILE__,__FUNCTION__,__LINE__,msg,exitApp);
message(msg,GlobalStaticFlags::getIsNonGraphicalModeEnabled());
message(msg,GlobalStaticFlags::getIsNonGraphicalModeEnabled(),tempDataLocation);
}
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] msg [%s] exitApp = %d\n",__FILE__,__FUNCTION__,__LINE__,msg,exitApp);
@ -3883,6 +3884,13 @@ int glestMain(int argc, char** argv) {
endPathWithSlash(userData);
}
string data_path_check = getGameReadWritePath(GameConstants::path_data_CacheLookupKey);
string userDataPath_check = getGameCustomCoreDataPath(data_path_check, "");
if(data_path_check == userDataPath_check) {
printf("****WARNING**** your game data path and user data path are the same.\nThis will likely create problems: %s\n",data_path_check.c_str());
throw megaglest_runtime_error("Regular and User data paths cannot have the same value [" + userDataPath_check + "]");
}
if(userData != "") {
if(isdir(userData.c_str()) == false) {
createDirectoryPaths(userData);
@ -3901,11 +3909,13 @@ int glestMain(int argc, char** argv) {
}
string tempDataPath = userData + "temp/";
tempDataLocation = tempDataPath;
if(isdir(tempDataPath.c_str()) == true) {
removeFolder(tempDataPath);
}
createDirectoryPaths(tempDataPath);
if(hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_USE_PORTS]) == true) {
int foundParamIndIndex = -1;
hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_USE_PORTS]) + string("="),&foundParamIndIndex);
@ -5480,7 +5490,7 @@ int glestMain(int argc, char** argv) {
program->getRendererInitOk() == false) {
//printf("#2 MAIN ERROR \n");
message(e.what(),GlobalStaticFlags::getIsNonGraphicalModeEnabled());
message(e.what(),GlobalStaticFlags::getIsNonGraphicalModeEnabled(),tempDataLocation);
}
}
@ -5634,7 +5644,7 @@ static bool MinidumpCallback(const google_breakpad::MinidumpDescriptor& descript
char szBuf[8096];
snprintf(szBuf,8096,"An unhandled error was detected.\n\nA crash dump file has been created in the folder:\n%s\nCrash dump filename is: %s",descriptor.directory().c_str(),descriptor.path());
//MessageBox(NULL, szBuf, "Unhandled error", MB_OK|MB_SYSTEMMODAL);
message(szBuf,GlobalStaticFlags::getIsNonGraphicalModeEnabled());
message(szBuf,GlobalStaticFlags::getIsNonGraphicalModeEnabled(),tempDataLocation);
}
return succeeded;

View File

@ -251,6 +251,8 @@ bool isKeyDown(int virtualKey);
//bool isKeyDown(SDLKey key);
string getCommandLine();
string getUserHome();
#define SPACES " "
inline string trim_at_delim (const string & s, const string &t) {

View File

@ -59,7 +59,7 @@ public:
// =====================================================
// Misc
// =====================================================
void message(string message,bool isNonGraphicalModeEnabled);
void message(string message,bool isNonGraphicalModeEnabled, string writepath);
void exceptionMessage(const exception &excp);
string getCommandLine();
@ -102,7 +102,7 @@ std::string utf8_encode(const std::wstring &wstr);
std::wstring utf8_decode(const std::string &str);
std::string getRegKey(const std::string& location, const std::string& name);
void message(string message, bool isNonGraphicalModeEnabled);
void message(string message, bool isNonGraphicalModeEnabled,string writepath);
void exceptionMessage(const exception &excp);
string getCommandLine();
void init_win32();

View File

@ -65,12 +65,20 @@
#include "platform_util.h"
#include "utf8.h"
#include "byte_order.h"
#include "leak_dumper.h"
#if _BSD_SOURCE || _SVID_SOURCE || _XOPEN_SOURCE >= 500 || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED
#include <unistd.h>
#include <sys/types.h>
#include <pwd.h>
#endif
#ifdef __APPLE__
#include <mach-o/dyld.h>
#endif
#include "leak_dumper.h"
using namespace Shared::Platform;
using namespace Shared::Util;
using namespace std;
@ -2389,5 +2397,19 @@ void ValueCheckerVault::checkItemInVault(const void *ptr,int value) const {
}
string getUserHome() {
string home_folder = "";
const char *homedir = getenv("HOME");
if (!homedir) {
#if _BSD_SOURCE || _SVID_SOURCE || _XOPEN_SOURCE >= 500 || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED
struct passwd *pw = getpwuid(getuid());
homedir = pw->pw_dir;
#else
homedir = "";
#endif
}
home_folder = homedir;
return home_folder;
}
}}//end namespace

View File

@ -44,7 +44,14 @@ const char * getDialogCommand() {
}
*/
FILE *file = popen("which gdialog","r");
FILE *file = popen("which zenity","r");
//printf("File #1 [%p]\n",file);
if (file != NULL) {
pclose(file);
return "zenity";
}
file = popen("which gdialog","r");
//printf("File #1 [%p]\n",file);
if (file != NULL) {
pclose(file);
@ -60,14 +67,25 @@ const char * getDialogCommand() {
return NULL;
}
bool showMessage(std::string warning) {
bool showMessage(std::string warning,string writepath) {
bool guiMessage = false;
const char * dialogCommand = getDialogCommand();
if (dialogCommand) {
std::string command = dialogCommand;
command += " --title \"Error\" --msgbox \"`printf \"" + warning.erase(4096,std::string::npos) + "\"`\"";
//printf("\n\n\nzenity command [%s]\n\n\n",command.c_str());
string text_file = writepath + "/mg_dialog_text.txt";
{
FILE *fp = fopen(text_file.c_str(),"wt");
if (fp != NULL) {
fputs(warning.c_str(),fp);
fclose(fp);
}
}
//command += " --title \"Error\" --msgbox \"`printf \"" + warning + "\"`\"";
command += " --title \"Error\" --text-info --filename=" + text_file;
printf("\n\n\nzenity command [%s]\n\n\n",command.c_str());
FILE *fp = popen(command.c_str(),"r");
if (fp != 0)
@ -78,7 +96,7 @@ bool showMessage(std::string warning) {
return guiMessage;
}
void message(string message, bool isNonGraphicalModeEnabled) {
void message(string message, bool isNonGraphicalModeEnabled,string writepath) {
std::cerr << "\n\n\n";
std::cerr << "******************************************************\n";
std::cerr << " " << message << "\n";
@ -86,7 +104,7 @@ void message(string message, bool isNonGraphicalModeEnabled) {
std::cerr << "\n\n\n";
if(isNonGraphicalModeEnabled == false) {
showMessage(message);
showMessage(message,writepath);
}
}

View File

@ -341,7 +341,7 @@ megaglest_runtime_error::megaglest_runtime_error(const string& __arg,bool noStac
// assert(dispChangeErr==DISP_CHANGE_SUCCESSFUL);
//}
void message(string message, bool isNonGraphicalModeEnabled) {
void message(string message, bool isNonGraphicalModeEnabled,string writepath) {
std::cerr << "******************************************************\n";
std::cerr << " " << message << "\n";
std::cerr << "******************************************************\n";

View File

@ -28,12 +28,6 @@
#endif
#if _BSD_SOURCE || _SVID_SOURCE || _XOPEN_SOURCE >= 500 || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED
#include <unistd.h>
#include <sys/types.h>
#include <pwd.h>
#endif
#include "utf8.h"
#include "font.h"
#include "string_utils.h"
@ -177,21 +171,6 @@ void Properties::load(const string &path, bool clearCurrentProperties) {
#endif
}
string getUserHomeFromGLIBC() {
string home_folder = "";
const char *homedir = getenv("HOME");
if (!homedir) {
#if _BSD_SOURCE || _SVID_SOURCE || _XOPEN_SOURCE >= 500 || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED
struct passwd *pw = getpwuid(getuid());
homedir = pw->pw_dir;
#else
homedir = "";
#endif
}
home_folder = homedir;
return home_folder;
}
std::map<string,string> Properties::getTagReplacementValues(std::map<string,string> *mapExtraTagReplacementValues) {
std::map<string,string> mapTagReplacementValues;
@ -202,7 +181,7 @@ std::map<string,string> Properties::getTagReplacementValues(std::map<string,stri
#ifdef WIN32
const char *homeDir = getenv("USERPROFILE");
#else
string home = getUserHomeFromGLIBC();
string home = getUserHome();
const char *homeDir = home.c_str();
#endif
@ -304,7 +283,7 @@ bool Properties::applyTagsToValue(string &value, const std::map<string,string> *
#ifdef WIN32
const char *homeDir = getenv("USERPROFILE");
#else
string home = getUserHomeFromGLIBC();
string home = getUserHome();
const char *homeDir = home.c_str();
#endif