diff --git a/source/glest_game/global/config.cpp b/source/glest_game/global/config.cpp index 9f436b11..c4082f24 100644 --- a/source/glest_game/global/config.cpp +++ b/source/glest_game/global/config.cpp @@ -147,7 +147,7 @@ Config::Config(std::pair type, std::pair f #if defined(CUSTOM_DATA_INSTALL_PATH) if(foundPath == false) { - foundPath = tryCustomPath(cfgType, fileName, TOSTRING(CUSTOM_DATA_INSTALL_PATH)); + foundPath = tryCustomPath(cfgType, fileName, formatPath(TOSTRING(CUSTOM_DATA_INSTALL_PATH))); } #endif diff --git a/source/glest_game/main/main.cpp b/source/glest_game/main/main.cpp index a22265ed..44617cec 100644 --- a/source/glest_game/main/main.cpp +++ b/source/glest_game/main/main.cpp @@ -2181,26 +2181,8 @@ void CheckForDuplicateData() { string duplicateWarnings=""; { -// vector maps; vector results; -/* - vector mapPaths = config.getPathListForType(ptMaps); - - findAll(mapPaths, "*.gbm", results, false, false, true); - copy(results.begin(), results.end(), std::back_inserter(maps)); - - results.clear(); - findAll(mapPaths, "*.mgm", results, false, false, true); - copy(results.begin(), results.end(), std::back_inserter(maps)); - - results.clear(); - std::sort(maps.begin(),maps.end()); - - if(maps.empty()) { - throw runtime_error("No maps were found!"); - } -*/ string scenarioDir = ""; vector pathList = config.getPathListForType(ptMaps,scenarioDir); vector invalidMapList; @@ -2459,7 +2441,7 @@ int glestMain(int argc, char** argv) { #if defined(CUSTOM_DATA_INSTALL_PATH) - if(SystemFlags::VERBOSE_MODE_ENABLED) printf("\n\nCUSTOM_DATA_INSTALL_PATH = [%s]\n\n",TOSTRING(CUSTOM_DATA_INSTALL_PATH)); + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("\n\nCUSTOM_DATA_INSTALL_PATH = [%s]\n\n",formatPath(TOSTRING(CUSTOM_DATA_INSTALL_PATH)).c_str()); #endif const int knownArgCount = sizeof(GAME_ARGS) / sizeof(GAME_ARGS[0]); @@ -2945,13 +2927,13 @@ int glestMain(int argc, char** argv) { else { #ifdef _WIN32 - int localeBufferSize = GetLocaleInfo(LOCALE_SYSTEM_DEFAULT, LOCALE_SISO639LANGNAME, NULL, 0); - wchar_t *sysLocale = new wchar_t[localeBufferSize]; + int localeBufferSize = GetLocaleInfo(LOCALE_SYSTEM_DEFAULT, LOCALE_SISO639LANGNAME, NULL, 0); + wchar_t *sysLocale = new wchar_t[localeBufferSize]; GetLocaleInfo(LOCALE_SYSTEM_DEFAULT, LOCALE_SISO639LANGNAME, sysLocale,localeBufferSize); //String langValue(sysLocale); //const char *lang_locale = langValue.c_str(); - char langValue[1024]=""; + char langValue[1024]=""; wcstombs(langValue,sysLocale, 1023); const char *lang_locale = &langValue[0]; #else @@ -3543,9 +3525,9 @@ int glestMain(int argc, char** argv) { cinfd[0].events = POLLIN; #else h = GetStdHandle(STD_INPUT_HANDLE); - //DWORD dwMode; - //GetConsoleMode(h, &dwMode); - //SetConsoleMode(h, dwMode & ~ENABLE_MOUSE_INPUT); + //DWORD dwMode; + //GetConsoleMode(h, &dwMode); + //SetConsoleMode(h, dwMode & ~ENABLE_MOUSE_INPUT); FlushConsoleInputBuffer(h); #endif } @@ -3573,11 +3555,11 @@ int glestMain(int argc, char** argv) { // without pressing enter, and then try to end the server another way (say a remote // console command), in which case we'll still be waiting for the stdin EOL and hang. - DWORD saveMode; - GetConsoleMode(h, &saveMode); - DWORD dwMode = saveMode; - dwMode &= ~ENABLE_MOUSE_INPUT; - dwMode &= ~ENABLE_WINDOW_INPUT; + DWORD saveMode; + GetConsoleMode(h, &saveMode); + DWORD dwMode = saveMode; + dwMode &= ~ENABLE_MOUSE_INPUT; + dwMode &= ~ENABLE_WINDOW_INPUT; SetConsoleMode(h, dwMode); bool gotData = (WaitForSingleObject(h, 0) == WAIT_OBJECT_0); @@ -3588,18 +3570,18 @@ int glestMain(int argc, char** argv) { bool skip = true; #ifdef WIN32 - DWORD nNumberOfCharsToRead = 1024; - DWORD nRead = 0; + DWORD nNumberOfCharsToRead = 1024; + DWORD nRead = 0; INPUT_RECORD irInRec[1025]; PeekConsoleInput(h,&irInRec[0],nNumberOfCharsToRead,&nRead); - for(int i = 0; i < nRead; ++i) { - INPUT_RECORD &inr = irInRec[i]; - - //printf("inr.EventType = %d\n",inr.EventType); - if(inr.EventType == KEY_EVENT) { - if(inr.Event.KeyEvent.bKeyDown) { - char cHoldKey = inr.Event.KeyEvent.uChar.AsciiChar; + for(int i = 0; i < nRead; ++i) { + INPUT_RECORD &inr = irInRec[i]; + + //printf("inr.EventType = %d\n",inr.EventType); + if(inr.EventType == KEY_EVENT) { + if(inr.Event.KeyEvent.bKeyDown) { + char cHoldKey = inr.Event.KeyEvent.uChar.AsciiChar; if(cHoldKey == '\r') { skip = false; break; diff --git a/source/shared_lib/include/platform/common/platform_common.h b/source/shared_lib/include/platform/common/platform_common.h index c4e0ad9d..026333ab 100644 --- a/source/shared_lib/include/platform/common/platform_common.h +++ b/source/shared_lib/include/platform/common/platform_common.h @@ -211,6 +211,7 @@ bool EndsWith(const string &str, const string& key); void endPathWithSlash(string &path, bool requireOSSlash=false); void trimPathWithStartingSlash(string &path); void updatePathClimbingParts(string &path); +void formatPath(string &path); string replaceAll(string& context, const string& from, const string& to); bool removeFile(string file); diff --git a/source/shared_lib/sources/platform/common/platform_common.cpp b/source/shared_lib/sources/platform/common/platform_common.cpp index 3f23c880..47bef261 100644 --- a/source/shared_lib/sources/platform/common/platform_common.cpp +++ b/source/shared_lib/sources/platform/common/platform_common.cpp @@ -500,6 +500,11 @@ void endPathWithSlash(string &path,bool requireOSSlash) { } } +void formatPath(string &path) { + replaceAll(path, "\"", ""); + replaceAll(path, "//", "/"); +} + void trimPathWithStartingSlash(string &path) { if(StartsWith(path, "/") == true || StartsWith(path, "\\") == true) { path.erase(path.begin(),path.begin()+1); diff --git a/source/shared_lib/sources/platform/sdl/gl_wrap.cpp b/source/shared_lib/sources/platform/sdl/gl_wrap.cpp index 3a3fd6bb..01ae28e7 100644 --- a/source/shared_lib/sources/platform/sdl/gl_wrap.cpp +++ b/source/shared_lib/sources/platform/sdl/gl_wrap.cpp @@ -77,11 +77,11 @@ void PlatformContextGl::init(int colorBits, int depthBits, int stencilBits,bool #ifndef WIN32 string mg_icon_file = ""; #if defined(CUSTOM_DATA_INSTALL_PATH_VALUE) - if(fileExists(CUSTOM_DATA_INSTALL_PATH_VALUE + "megaglest.png")) { - mg_icon_file = CUSTOM_DATA_INSTALL_PATH_VALUE + "megaglest.png"; + if(fileExists(formatPath(TOSTRING(CUSTOM_DATA_INSTALL_PATH_VALUE)) + "megaglest.png")) { + mg_icon_file = formatPath(TOSTRING(CUSTOM_DATA_INSTALL_PATH_VALUE)) + "megaglest.png"; } - else if(fileExists(CUSTOM_DATA_INSTALL_PATH_VALUE + "megaglest.bmp")) { - mg_icon_file = CUSTOM_DATA_INSTALL_PATH_VALUE + "megaglest.bmp"; + else if(fileExists(formatPath(TOSTRING(CUSTOM_DATA_INSTALL_PATH_VALUE)) + "megaglest.bmp")) { + mg_icon_file = formatPath(TOSTRING(CUSTOM_DATA_INSTALL_PATH_VALUE)) + "megaglest.bmp"; } #endif @@ -202,15 +202,15 @@ void PlatformContextGl::init(int colorBits, int depthBits, int stencilBits,bool SDL_WM_GrabInput(SDL_GRAB_OFF); GLuint err = glewInit(); - if (GLEW_OK != err) { - fprintf(stderr, "Error [main]: glewInit failed: %s\n", glewGetErrorString(err)); - //return 1; - throw std::runtime_error((char *)glewGetErrorString(err)); + if (GLEW_OK != err) { + fprintf(stderr, "Error [main]: glewInit failed: %s\n", glewGetErrorString(err)); + //return 1; + throw std::runtime_error((char *)glewGetErrorString(err)); } //fprintf(stdout, "Status: Using GLEW %s\n", glewGetString(GLEW_VERSION)); int bufferSize = (resW * resH * BaseColorPickEntity::COLOR_COMPONENTS); - BaseColorPickEntity::init(bufferSize); + BaseColorPickEntity::init(bufferSize); } } diff --git a/source/shared_lib/sources/util/properties.cpp b/source/shared_lib/sources/util/properties.cpp index cd05523a..662ed988 100644 --- a/source/shared_lib/sources/util/properties.cpp +++ b/source/shared_lib/sources/util/properties.cpp @@ -190,11 +190,11 @@ std::map Properties::getTagReplacementValues(std::map Properties::getTagReplacementValues(std::map *mapTag // For win32 we allow use of the appdata variable since that is the recommended // place for application data in windows platform #ifdef WIN32 - TCHAR szPath[MAX_PATH]; - // Get path for each computer, non-user specific and non-roaming data. - if ( SUCCEEDED( SHGetFolderPath( NULL, CSIDL_APPDATA, + TCHAR szPath[MAX_PATH]; + // Get path for each computer, non-user specific and non-roaming data. + if ( SUCCEEDED( SHGetFolderPath( NULL, CSIDL_APPDATA, NULL, 0, szPath))) { //const wchar_t *wBuf = &szPath[0]; //size_t size = MAX_PATH + 1; - //char pMBBuffer[MAX_PATH + 1]=""; - //wcstombs_s(&size, &pMBBuffer[0], (size_t)size, wBuf, (size_t)size);// Convert to char* from TCHAR[] - //string appPath=""; - //appPath.assign(&pMBBuffer[0]); // Now assign the char* to the string, and there you have it!!! :) - std::string appPath = utf8_encode(szPath); + //char pMBBuffer[MAX_PATH + 1]=""; + //wcstombs_s(&size, &pMBBuffer[0], (size_t)size, wBuf, (size_t)size);// Convert to char* from TCHAR[] + //string appPath=""; + //appPath.assign(&pMBBuffer[0]); // Now assign the char* to the string, and there you have it!!! :) + std::string appPath = utf8_encode(szPath); //string appPath = szPath; replaceAll(value, "$APPDATA", appPath); @@ -308,20 +303,15 @@ bool Properties::applyTagsToValue(string &value, std::map *mapTag replaceAll(value, "{APPLICATIONPATH}", Properties::applicationPath); #if defined(CUSTOM_DATA_INSTALL_PATH) - replaceAll(value, "$APPLICATIONDATAPATH", TOSTRING(CUSTOM_DATA_INSTALL_PATH)); - replaceAll(value, "%%APPLICATIONDATAPATH%%", TOSTRING(CUSTOM_DATA_INSTALL_PATH)); - replaceAll(value, "{APPLICATIONDATAPATH}", TOSTRING(CUSTOM_DATA_INSTALL_PATH)); - - //replaceAll(value, "$COMMONDATAPATH", string(CUSTOM_DATA_INSTALL_PATH) + "/commondata/"); - //replaceAll(value, "%%COMMONDATAPATH%%", string(CUSTOM_DATA_INSTALL_PATH) + "/commondata/"); + replaceAll(value, "$APPLICATIONDATAPATH", formatPath(TOSTRING(CUSTOM_DATA_INSTALL_PATH))); + replaceAll(value, "%%APPLICATIONDATAPATH%%", formatPath(TOSTRING(CUSTOM_DATA_INSTALL_PATH))); + replaceAll(value, "{APPLICATIONDATAPATH}", formatPath(TOSTRING(CUSTOM_DATA_INSTALL_PATH))); #else replaceAll(value, "$APPLICATIONDATAPATH", Properties::applicationPath); replaceAll(value, "%%APPLICATIONDATAPATH%%", Properties::applicationPath); replaceAll(value, "{APPLICATIONDATAPATH}", Properties::applicationPath); - //replaceAll(value, "$COMMONDATAPATH", Properties::applicationPath + "/commondata/"); - //replaceAll(value, "%%COMMONDATAPATH%%", Properties::applicationPath + "/commondata/"); #endif replaceAll(value, "$GAMEVERSION", Properties::gameVersion);