- bugfix for custom data path macro usage to avoid compiler errors

This commit is contained in:
Mark Vejvoda 2012-01-24 07:39:16 +00:00
parent 84f06d3cbd
commit ff4c327261
6 changed files with 56 additions and 78 deletions

View File

@ -147,7 +147,7 @@ Config::Config(std::pair<ConfigType,ConfigType> type, std::pair<string,string> f
#if defined(CUSTOM_DATA_INSTALL_PATH) #if defined(CUSTOM_DATA_INSTALL_PATH)
if(foundPath == false) { if(foundPath == false) {
foundPath = tryCustomPath(cfgType, fileName, TOSTRING(CUSTOM_DATA_INSTALL_PATH)); foundPath = tryCustomPath(cfgType, fileName, formatPath(TOSTRING(CUSTOM_DATA_INSTALL_PATH)));
} }
#endif #endif

View File

@ -2181,26 +2181,8 @@ void CheckForDuplicateData() {
string duplicateWarnings=""; string duplicateWarnings="";
{ {
// vector<string> maps;
vector<string> results; vector<string> results;
/*
vector<string> 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 = ""; string scenarioDir = "";
vector<string> pathList = config.getPathListForType(ptMaps,scenarioDir); vector<string> pathList = config.getPathListForType(ptMaps,scenarioDir);
vector<string> invalidMapList; vector<string> invalidMapList;
@ -2459,7 +2441,7 @@ int glestMain(int argc, char** argv) {
#if defined(CUSTOM_DATA_INSTALL_PATH) #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 #endif
const int knownArgCount = sizeof(GAME_ARGS) / sizeof(GAME_ARGS[0]); const int knownArgCount = sizeof(GAME_ARGS) / sizeof(GAME_ARGS[0]);
@ -2945,13 +2927,13 @@ int glestMain(int argc, char** argv) {
else { else {
#ifdef _WIN32 #ifdef _WIN32
int localeBufferSize = GetLocaleInfo(LOCALE_SYSTEM_DEFAULT, LOCALE_SISO639LANGNAME, NULL, 0); int localeBufferSize = GetLocaleInfo(LOCALE_SYSTEM_DEFAULT, LOCALE_SISO639LANGNAME, NULL, 0);
wchar_t *sysLocale = new wchar_t[localeBufferSize]; wchar_t *sysLocale = new wchar_t[localeBufferSize];
GetLocaleInfo(LOCALE_SYSTEM_DEFAULT, LOCALE_SISO639LANGNAME, sysLocale,localeBufferSize); GetLocaleInfo(LOCALE_SYSTEM_DEFAULT, LOCALE_SISO639LANGNAME, sysLocale,localeBufferSize);
//String langValue(sysLocale); //String langValue(sysLocale);
//const char *lang_locale = langValue.c_str(); //const char *lang_locale = langValue.c_str();
char langValue[1024]=""; char langValue[1024]="";
wcstombs(langValue,sysLocale, 1023); wcstombs(langValue,sysLocale, 1023);
const char *lang_locale = &langValue[0]; const char *lang_locale = &langValue[0];
#else #else
@ -3543,9 +3525,9 @@ int glestMain(int argc, char** argv) {
cinfd[0].events = POLLIN; cinfd[0].events = POLLIN;
#else #else
h = GetStdHandle(STD_INPUT_HANDLE); h = GetStdHandle(STD_INPUT_HANDLE);
//DWORD dwMode; //DWORD dwMode;
//GetConsoleMode(h, &dwMode); //GetConsoleMode(h, &dwMode);
//SetConsoleMode(h, dwMode & ~ENABLE_MOUSE_INPUT); //SetConsoleMode(h, dwMode & ~ENABLE_MOUSE_INPUT);
FlushConsoleInputBuffer(h); FlushConsoleInputBuffer(h);
#endif #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 // 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. // console command), in which case we'll still be waiting for the stdin EOL and hang.
DWORD saveMode; DWORD saveMode;
GetConsoleMode(h, &saveMode); GetConsoleMode(h, &saveMode);
DWORD dwMode = saveMode; DWORD dwMode = saveMode;
dwMode &= ~ENABLE_MOUSE_INPUT; dwMode &= ~ENABLE_MOUSE_INPUT;
dwMode &= ~ENABLE_WINDOW_INPUT; dwMode &= ~ENABLE_WINDOW_INPUT;
SetConsoleMode(h, dwMode); SetConsoleMode(h, dwMode);
bool gotData = (WaitForSingleObject(h, 0) == WAIT_OBJECT_0); bool gotData = (WaitForSingleObject(h, 0) == WAIT_OBJECT_0);
@ -3588,18 +3570,18 @@ int glestMain(int argc, char** argv) {
bool skip = true; bool skip = true;
#ifdef WIN32 #ifdef WIN32
DWORD nNumberOfCharsToRead = 1024; DWORD nNumberOfCharsToRead = 1024;
DWORD nRead = 0; DWORD nRead = 0;
INPUT_RECORD irInRec[1025]; INPUT_RECORD irInRec[1025];
PeekConsoleInput(h,&irInRec[0],nNumberOfCharsToRead,&nRead); PeekConsoleInput(h,&irInRec[0],nNumberOfCharsToRead,&nRead);
for(int i = 0; i < nRead; ++i) { for(int i = 0; i < nRead; ++i) {
INPUT_RECORD &inr = irInRec[i]; INPUT_RECORD &inr = irInRec[i];
//printf("inr.EventType = %d\n",inr.EventType); //printf("inr.EventType = %d\n",inr.EventType);
if(inr.EventType == KEY_EVENT) { if(inr.EventType == KEY_EVENT) {
if(inr.Event.KeyEvent.bKeyDown) { if(inr.Event.KeyEvent.bKeyDown) {
char cHoldKey = inr.Event.KeyEvent.uChar.AsciiChar; char cHoldKey = inr.Event.KeyEvent.uChar.AsciiChar;
if(cHoldKey == '\r') { if(cHoldKey == '\r') {
skip = false; skip = false;
break; break;

View File

@ -211,6 +211,7 @@ bool EndsWith(const string &str, const string& key);
void endPathWithSlash(string &path, bool requireOSSlash=false); void endPathWithSlash(string &path, bool requireOSSlash=false);
void trimPathWithStartingSlash(string &path); void trimPathWithStartingSlash(string &path);
void updatePathClimbingParts(string &path); void updatePathClimbingParts(string &path);
void formatPath(string &path);
string replaceAll(string& context, const string& from, const string& to); string replaceAll(string& context, const string& from, const string& to);
bool removeFile(string file); bool removeFile(string file);

View File

@ -500,6 +500,11 @@ void endPathWithSlash(string &path,bool requireOSSlash) {
} }
} }
void formatPath(string &path) {
replaceAll(path, "\"", "");
replaceAll(path, "//", "/");
}
void trimPathWithStartingSlash(string &path) { void trimPathWithStartingSlash(string &path) {
if(StartsWith(path, "/") == true || StartsWith(path, "\\") == true) { if(StartsWith(path, "/") == true || StartsWith(path, "\\") == true) {
path.erase(path.begin(),path.begin()+1); path.erase(path.begin(),path.begin()+1);

View File

@ -77,11 +77,11 @@ void PlatformContextGl::init(int colorBits, int depthBits, int stencilBits,bool
#ifndef WIN32 #ifndef WIN32
string mg_icon_file = ""; string mg_icon_file = "";
#if defined(CUSTOM_DATA_INSTALL_PATH_VALUE) #if defined(CUSTOM_DATA_INSTALL_PATH_VALUE)
if(fileExists(CUSTOM_DATA_INSTALL_PATH_VALUE + "megaglest.png")) { if(fileExists(formatPath(TOSTRING(CUSTOM_DATA_INSTALL_PATH_VALUE)) + "megaglest.png")) {
mg_icon_file = 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")) { else if(fileExists(formatPath(TOSTRING(CUSTOM_DATA_INSTALL_PATH_VALUE)) + "megaglest.bmp")) {
mg_icon_file = CUSTOM_DATA_INSTALL_PATH_VALUE + "megaglest.bmp"; mg_icon_file = formatPath(TOSTRING(CUSTOM_DATA_INSTALL_PATH_VALUE)) + "megaglest.bmp";
} }
#endif #endif
@ -202,15 +202,15 @@ void PlatformContextGl::init(int colorBits, int depthBits, int stencilBits,bool
SDL_WM_GrabInput(SDL_GRAB_OFF); SDL_WM_GrabInput(SDL_GRAB_OFF);
GLuint err = glewInit(); GLuint err = glewInit();
if (GLEW_OK != err) { if (GLEW_OK != err) {
fprintf(stderr, "Error [main]: glewInit failed: %s\n", glewGetErrorString(err)); fprintf(stderr, "Error [main]: glewInit failed: %s\n", glewGetErrorString(err));
//return 1; //return 1;
throw std::runtime_error((char *)glewGetErrorString(err)); throw std::runtime_error((char *)glewGetErrorString(err));
} }
//fprintf(stdout, "Status: Using GLEW %s\n", glewGetString(GLEW_VERSION)); //fprintf(stdout, "Status: Using GLEW %s\n", glewGetString(GLEW_VERSION));
int bufferSize = (resW * resH * BaseColorPickEntity::COLOR_COMPONENTS); int bufferSize = (resW * resH * BaseColorPickEntity::COLOR_COMPONENTS);
BaseColorPickEntity::init(bufferSize); BaseColorPickEntity::init(bufferSize);
} }
} }

View File

@ -190,11 +190,11 @@ std::map<string,string> Properties::getTagReplacementValues(std::map<string,stri
//const wchar_t *wBuf = &szPath[0]; //const wchar_t *wBuf = &szPath[0];
//size_t size = MAX_PATH + 1; //size_t size = MAX_PATH + 1;
//char pMBBuffer[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[] //wcstombs_s(&size, &pMBBuffer[0], (size_t)size, wBuf, (size_t)size);// Convert to char* from TCHAR[]
//string appPath=""; //string appPath="";
//appPath.assign(&pMBBuffer[0]); // Now assign the char* to the string, and there you have it!!! :) //appPath.assign(&pMBBuffer[0]); // Now assign the char* to the string, and there you have it!!! :)
std::string appPath = utf8_encode(szPath); std::string appPath = utf8_encode(szPath);
//string appPath = szPath; //string appPath = szPath;
mapTagReplacementValues["$APPDATA"] = appPath; mapTagReplacementValues["$APPDATA"] = appPath;
@ -215,20 +215,15 @@ std::map<string,string> Properties::getTagReplacementValues(std::map<string,stri
mapTagReplacementValues["{APPLICATIONPATH}"] = Properties::applicationPath; mapTagReplacementValues["{APPLICATIONPATH}"] = Properties::applicationPath;
#if defined(CUSTOM_DATA_INSTALL_PATH) #if defined(CUSTOM_DATA_INSTALL_PATH)
mapTagReplacementValues["$APPLICATIONDATAPATH"] = TOSTRING(CUSTOM_DATA_INSTALL_PATH); mapTagReplacementValues["$APPLICATIONDATAPATH"] = formatPath(TOSTRING(CUSTOM_DATA_INSTALL_PATH));
mapTagReplacementValues["%%APPLICATIONDATAPATH%%"] = TOSTRING(CUSTOM_DATA_INSTALL_PATH); mapTagReplacementValues["%%APPLICATIONDATAPATH%%"] = formatPath(TOSTRING(CUSTOM_DATA_INSTALL_PATH));
mapTagReplacementValues["{APPLICATIONDATAPATH}"] = TOSTRING(CUSTOM_DATA_INSTALL_PATH); mapTagReplacementValues["{APPLICATIONDATAPATH}"] = formatPath(TOSTRING(CUSTOM_DATA_INSTALL_PATH));
//mapTagReplacementValues["$COMMONDATAPATH", string(CUSTOM_DATA_INSTALL_PATH) + "/commondata/");
//mapTagReplacementValues["%%COMMONDATAPATH%%", string(CUSTOM_DATA_INSTALL_PATH) + "/commondata/");
#else #else
mapTagReplacementValues["$APPLICATIONDATAPATH"] = Properties::applicationPath; mapTagReplacementValues["$APPLICATIONDATAPATH"] = Properties::applicationPath;
mapTagReplacementValues["%%APPLICATIONDATAPATH%%"] = Properties::applicationPath; mapTagReplacementValues["%%APPLICATIONDATAPATH%%"] = Properties::applicationPath;
mapTagReplacementValues["{APPLICATIONDATAPATH}"] = Properties::applicationPath; mapTagReplacementValues["{APPLICATIONDATAPATH}"] = Properties::applicationPath;
//mapTagReplacementValues["$COMMONDATAPATH", Properties::applicationPath + "/commondata/");
//mapTagReplacementValues["%%COMMONDATAPATH%%", Properties::applicationPath + "/commondata/");
#endif #endif
mapTagReplacementValues["$GAMEVERSION"] = Properties::gameVersion; mapTagReplacementValues["$GAMEVERSION"] = Properties::gameVersion;
@ -278,17 +273,17 @@ bool Properties::applyTagsToValue(string &value, std::map<string,string> *mapTag
// For win32 we allow use of the appdata variable since that is the recommended // For win32 we allow use of the appdata variable since that is the recommended
// place for application data in windows platform // place for application data in windows platform
#ifdef WIN32 #ifdef WIN32
TCHAR szPath[MAX_PATH]; TCHAR szPath[MAX_PATH];
// Get path for each computer, non-user specific and non-roaming data. // Get path for each computer, non-user specific and non-roaming data.
if ( SUCCEEDED( SHGetFolderPath( NULL, CSIDL_APPDATA, if ( SUCCEEDED( SHGetFolderPath( NULL, CSIDL_APPDATA,
NULL, 0, szPath))) { NULL, 0, szPath))) {
//const wchar_t *wBuf = &szPath[0]; //const wchar_t *wBuf = &szPath[0];
//size_t size = MAX_PATH + 1; //size_t size = MAX_PATH + 1;
//char pMBBuffer[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[] //wcstombs_s(&size, &pMBBuffer[0], (size_t)size, wBuf, (size_t)size);// Convert to char* from TCHAR[]
//string appPath=""; //string appPath="";
//appPath.assign(&pMBBuffer[0]); // Now assign the char* to the string, and there you have it!!! :) //appPath.assign(&pMBBuffer[0]); // Now assign the char* to the string, and there you have it!!! :)
std::string appPath = utf8_encode(szPath); std::string appPath = utf8_encode(szPath);
//string appPath = szPath; //string appPath = szPath;
replaceAll(value, "$APPDATA", appPath); replaceAll(value, "$APPDATA", appPath);
@ -308,20 +303,15 @@ bool Properties::applyTagsToValue(string &value, std::map<string,string> *mapTag
replaceAll(value, "{APPLICATIONPATH}", Properties::applicationPath); replaceAll(value, "{APPLICATIONPATH}", Properties::applicationPath);
#if defined(CUSTOM_DATA_INSTALL_PATH) #if defined(CUSTOM_DATA_INSTALL_PATH)
replaceAll(value, "$APPLICATIONDATAPATH", TOSTRING(CUSTOM_DATA_INSTALL_PATH)); replaceAll(value, "$APPLICATIONDATAPATH", formatPath(TOSTRING(CUSTOM_DATA_INSTALL_PATH)));
replaceAll(value, "%%APPLICATIONDATAPATH%%", TOSTRING(CUSTOM_DATA_INSTALL_PATH)); replaceAll(value, "%%APPLICATIONDATAPATH%%", formatPath(TOSTRING(CUSTOM_DATA_INSTALL_PATH)));
replaceAll(value, "{APPLICATIONDATAPATH}", TOSTRING(CUSTOM_DATA_INSTALL_PATH)); replaceAll(value, "{APPLICATIONDATAPATH}", formatPath(TOSTRING(CUSTOM_DATA_INSTALL_PATH)));
//replaceAll(value, "$COMMONDATAPATH", string(CUSTOM_DATA_INSTALL_PATH) + "/commondata/");
//replaceAll(value, "%%COMMONDATAPATH%%", string(CUSTOM_DATA_INSTALL_PATH) + "/commondata/");
#else #else
replaceAll(value, "$APPLICATIONDATAPATH", Properties::applicationPath); replaceAll(value, "$APPLICATIONDATAPATH", Properties::applicationPath);
replaceAll(value, "%%APPLICATIONDATAPATH%%", Properties::applicationPath); 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 #endif
replaceAll(value, "$GAMEVERSION", Properties::gameVersion); replaceAll(value, "$GAMEVERSION", Properties::gameVersion);