- 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(foundPath == false) {
foundPath = tryCustomPath(cfgType, fileName, TOSTRING(CUSTOM_DATA_INSTALL_PATH));
foundPath = tryCustomPath(cfgType, fileName, formatPath(TOSTRING(CUSTOM_DATA_INSTALL_PATH)));
}
#endif

View File

@ -2181,26 +2181,8 @@ void CheckForDuplicateData() {
string duplicateWarnings="";
{
// vector<string> maps;
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 = "";
vector<string> pathList = config.getPathListForType(ptMaps,scenarioDir);
vector<string> 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;

View File

@ -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);

View File

@ -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);

View File

@ -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);
}
}

View File

@ -190,11 +190,11 @@ std::map<string,string> Properties::getTagReplacementValues(std::map<string,stri
//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;
mapTagReplacementValues["$APPDATA"] = appPath;
@ -215,20 +215,15 @@ std::map<string,string> Properties::getTagReplacementValues(std::map<string,stri
mapTagReplacementValues["{APPLICATIONPATH}"] = Properties::applicationPath;
#if defined(CUSTOM_DATA_INSTALL_PATH)
mapTagReplacementValues["$APPLICATIONDATAPATH"] = TOSTRING(CUSTOM_DATA_INSTALL_PATH);
mapTagReplacementValues["%%APPLICATIONDATAPATH%%"] = TOSTRING(CUSTOM_DATA_INSTALL_PATH);
mapTagReplacementValues["{APPLICATIONDATAPATH}"] = TOSTRING(CUSTOM_DATA_INSTALL_PATH);
//mapTagReplacementValues["$COMMONDATAPATH", string(CUSTOM_DATA_INSTALL_PATH) + "/commondata/");
//mapTagReplacementValues["%%COMMONDATAPATH%%", string(CUSTOM_DATA_INSTALL_PATH) + "/commondata/");
mapTagReplacementValues["$APPLICATIONDATAPATH"] = formatPath(TOSTRING(CUSTOM_DATA_INSTALL_PATH));
mapTagReplacementValues["%%APPLICATIONDATAPATH%%"] = formatPath(TOSTRING(CUSTOM_DATA_INSTALL_PATH));
mapTagReplacementValues["{APPLICATIONDATAPATH}"] = formatPath(TOSTRING(CUSTOM_DATA_INSTALL_PATH));
#else
mapTagReplacementValues["$APPLICATIONDATAPATH"] = Properties::applicationPath;
mapTagReplacementValues["%%APPLICATIONDATAPATH%%"] = Properties::applicationPath;
mapTagReplacementValues["{APPLICATIONDATAPATH}"] = Properties::applicationPath;
//mapTagReplacementValues["$COMMONDATAPATH", Properties::applicationPath + "/commondata/");
//mapTagReplacementValues["%%COMMONDATAPATH%%", Properties::applicationPath + "/commondata/");
#endif
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
// 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<string,string> *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);