diff --git a/mk/windoze/glest_game.vcproj b/mk/windoze/glest_game.vcproj index b662a898a..9fc01be87 100644 --- a/mk/windoze/glest_game.vcproj +++ b/mk/windoze/glest_game.vcproj @@ -46,7 +46,7 @@ WholeProgramOptimization="false" AdditionalIncludeDirectories="../../source/shared_lib/include/graphics;../../source/shared_lib/include/graphics/gl;../../source/shared_lib/include/platform;../../source/shared_lib/include/platform/win32;../../source/shared_lib/include/sound;../../source/shared_lib/include/sound/ds8;../../source/shared_lib/include/util;../../source/shared_lib/include/lua;../../source/shared_lib/include/xml;../../source/shared_lib/include/tinyxml;../../source/glest_game/ai;../../source/glest_game/facilities;../../source/glest_game/game;../../source/glest_game/global;../../source/glest_game/graphics;../../source/glest_game/gui;../../source/glest_game/main;../../source/glest_game/menu;../../source/glest_game/network;../../source/glest_game/sound;../../source/glest_game/type_instances;../../source/glest_game/types;../../source/glest_game/world;../../source/win32_deps/include;"../../source/win32_deps/xerces-c-3.0.1/src";"../../source/win32_deps/SDL-1.2.x/include";../../source/shared_lib/include/platform/sdl;../../source/shared_lib/include/sound/openal;"../../source/win32_deps/openal-soft-1.12.854/include";../../source/shared_lib/include/platform/posix;../../source/shared_lib/include/streflop;../../source/shared_lib/include/platform/common;"../../source/win32_deps/curl-7.21.3/include";../../source/shared_lib/include/map;$(NOINHERIT);../../source/win32_deps/libircclient/include" AdditionalUsingDirectories="" - PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;XML_LIBRARY;USE_PCH=1;_CRT_SECURE_NO_WARNINGS;USE_STREFLOP;STREFLOP_SSE;LIBM_COMPILING_FLT32;CURL_STATICLIB" + PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;XML_LIBRARY;USE_PCH=1;_CRT_SECURE_NO_WARNINGS;USE_STREFLOP;STREFLOP_SSE;LIBM_COMPILING_FLT32;CURL_STATICLIB; UNICODE" StringPooling="true" MinimalRebuild="true" BasicRuntimeChecks="3" @@ -139,7 +139,7 @@ WholeProgramOptimization="false" AdditionalIncludeDirectories="../../source/shared_lib/include/graphics;../../source/shared_lib/include/graphics/gl;../../source/shared_lib/include/platform;../../source/shared_lib/include/platform/win32;../../source/shared_lib/include/sound;../../source/shared_lib/include/sound/ds8;../../source/shared_lib/include/util;../../source/shared_lib/include/lua;../../source/shared_lib/include/xml;../../source/shared_lib/include/tinyxml;../../source/glest_game/ai;../../source/glest_game/facilities;../../source/glest_game/game;../../source/glest_game/global;../../source/glest_game/graphics;../../source/glest_game/gui;../../source/glest_game/main;../../source/glest_game/menu;../../source/glest_game/network;../../source/glest_game/sound;../../source/glest_game/type_instances;../../source/glest_game/types;../../source/glest_game/world;../../source/win32_deps/include;"../../source/win32_deps/xerces-c-3.0.1/src";"../../source/win32_deps/SDL-1.2.x/include";../../source/shared_lib/include/platform/sdl;../../source/shared_lib/include/sound/openal;"../../source/win32_deps/openal-soft-1.12.854/include";../../source/shared_lib/include/platform/posix;../../source/shared_lib/include/streflop;../../source/shared_lib/include/platform/common;"../../source/win32_deps/curl-7.21.3/include";../../source/shared_lib/include/map;$(NOINHERIT);../../source/win32_deps/libircclient/include" AdditionalUsingDirectories="" - PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;XML_LIBRARY;USE_PCH=1;_CRT_SECURE_NO_WARNINGS;USE_STREFLOP;STREFLOP_SSE;LIBM_COMPILING_FLT32;CURL_STATICLIB" + PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;XML_LIBRARY;USE_PCH=1;_CRT_SECURE_NO_WARNINGS;USE_STREFLOP;STREFLOP_SSE;LIBM_COMPILING_FLT32;CURL_STATICLIB;UNICODE" StringPooling="true" ExceptionHandling="2" RuntimeLibrary="0" diff --git a/mk/windoze/shared_lib.vcproj b/mk/windoze/shared_lib.vcproj index 7d4a53283..ff9c7abd1 100644 --- a/mk/windoze/shared_lib.vcproj +++ b/mk/windoze/shared_lib.vcproj @@ -41,7 +41,7 @@ Name="VCCLCompilerTool" Optimization="0" AdditionalIncludeDirectories="../../source/shared_lib/include;../../source/shared_lib/include/graphics;../../source/shared_lib/include/graphics/gl;../../source/shared_lib/include/platform;../../source/shared_lib/include/platform/win32;../../source/shared_lib/include/sound;../../source/shared_lib/include/sound/ds8;../../source/shared_lib/include/util;../../source/shared_lib/include/lua;../../source/shared_lib/include/xml;../../source/win32_deps/include;"../../source/win32_deps/xerces-c-3.0.1/src";"../../source/win32_deps/xerces-c-3.0.1/src/xercesc/xinclude";../../source/win32_deps/lpng141;"../../source/win32_deps/jpeg-8a";"../../source/win32_deps/SDL-1.2.x/include";../../source/shared_lib/include/platform/sdl;"../../source/win32_deps/openal-soft-1.12.854/include";../../source/shared_lib/include/sound/openal;../../source/shared_lib/include/platform/posix;../../source/shared_lib/include/streflop;../../source/shared_lib/include/streflop/libm_flt32_source;../../source/shared_lib/include/platform/common;"../../source/win32_deps/curl-7.21.3/include";../../source/shared_lib/include/map;../../source/shared_lib/include/platform/miniupnpc;../../source/shared_lib/include/libircclient/include;../../source/shared_lib/include/feathery_ftp" - PreprocessorDefinitions="WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;USE_PCH=1;USE_STREFLOP;STREFLOP_SSE;STREFLOP_RANDOM_GEN_SIZE=32;LIBM_COMPILING_FLT32;CURL_STATICLIB" + PreprocessorDefinitions="WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;USE_PCH=1;USE_STREFLOP;STREFLOP_SSE;STREFLOP_RANDOM_GEN_SIZE=32;LIBM_COMPILING_FLT32;CURL_STATICLIB;UNICODE" StringPooling="true" MinimalRebuild="true" BasicRuntimeChecks="3" @@ -121,7 +121,7 @@ FavorSizeOrSpeed="1" WholeProgramOptimization="false" AdditionalIncludeDirectories="../../source/shared_lib/include;../../source/shared_lib/include/graphics;../../source/shared_lib/include/graphics/gl;../../source/shared_lib/include/platform;../../source/shared_lib/include/platform/win32;../../source/shared_lib/include/sound;../../source/shared_lib/include/sound/ds8;../../source/shared_lib/include/util;../../source/shared_lib/include/lua;../../source/shared_lib/include/xml;../../source/win32_deps/include;"../../source/win32_deps/xerces-c-3.0.1/src";"../../source/win32_deps/xerces-c-3.0.1/src/xercesc/xinclude";../../source/win32_deps/lpng141;"../../source/win32_deps/jpeg-8a";"../../source/win32_deps/SDL-1.2.x/include";../../source/shared_lib/include/platform/sdl;"../../source/win32_deps/openal-soft-1.12.854/include";../../source/shared_lib/include/sound/openal;../../source/shared_lib/include/platform/posix;../../source/shared_lib/include/streflop;../../source/shared_lib/include/streflop/libm_flt32_source;../../source/shared_lib/include/platform/common;"../../source/win32_deps/curl-7.21.3/include";../../source/shared_lib/include/map;../../source/shared_lib/include/platform/miniupnpc;../../source/shared_lib/include/libircclient/include;../../source/shared_lib/include/feathery_ftp;$(NOINHERIT)" - PreprocessorDefinitions="WIN32;NDEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;USE_PCH=1;USE_STREFLOP;STREFLOP_SSE;STREFLOP_RANDOM_GEN_SIZE=32;LIBM_COMPILING_FLT32;CURL_STATICLIB" + PreprocessorDefinitions="WIN32;NDEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;USE_PCH=1;USE_STREFLOP;STREFLOP_SSE;STREFLOP_RANDOM_GEN_SIZE=32;LIBM_COMPILING_FLT32;CURL_STATICLIB;UNICODE" StringPooling="true" ExceptionHandling="2" RuntimeLibrary="0" @@ -687,7 +687,7 @@ > +#include //#include #ifndef WIN32 @@ -360,30 +361,30 @@ MainWindow::MainWindow( std::pair > unitToLoad, // For windows register g3d file extension to launch this app #if defined(WIN32) && !defined(__MINGW32__) // example from: http://stackoverflow.com/questions/1387769/create-registry-entry-to-associate-file-extension-with-application-in-c - //[HKEY_CURRENT_USER\Software\Classes\blergcorp.blergapp.v1\shell\open\command] - //@="c:\path\to\app.exe \"%1\"" - //[HKEY_CURRENT_USER\Software\Classes\.blerg] + //[HKEY_CURRENT_USER\Software\Classes\blergcorp.blergapp.v1\shell\open\command] + //@="c:\path\to\app.exe \"%1\"" + //[HKEY_CURRENT_USER\Software\Classes\.blerg] //@="blergcorp.blergapp.v1" //Open the registry key. - string subKey = "Software\\Classes\\megaglest.g3d\\shell\\open\\command"; + string subKey = "Software\\Classes\\megaglest.g3d\\shell\\open\\command"; HKEY keyHandle; - DWORD dwDisposition; - RegCreateKeyEx(HKEY_CURRENT_USER,subKey.c_str(),0, NULL, 0, KEY_ALL_ACCESS, NULL, &keyHandle, &dwDisposition); - //Set the value. - string launchApp = appPath + " \"%1\""; - DWORD len = launchApp.length() + 1; - RegSetValueEx(keyHandle, NULL, 0, REG_SZ, (PBYTE)launchApp.c_str(), len); - RegCloseKey(keyHandle); - - subKey = "Software\\Classes\\.g3d"; - RegCreateKeyEx(HKEY_CURRENT_USER,subKey.c_str(),0, NULL, 0, KEY_ALL_ACCESS, NULL, &keyHandle, &dwDisposition); - //Set the value. - launchApp = "megaglest.g3d"; - len = launchApp.length() + 1; - RegSetValueEx(keyHandle, NULL, 0, REG_SZ, (PBYTE)launchApp.c_str(), len); - RegCloseKey(keyHandle); - + DWORD dwDisposition; + RegCreateKeyEx(HKEY_CURRENT_USER,subKey.c_str(),0, NULL, 0, KEY_ALL_ACCESS, NULL, &keyHandle, &dwDisposition); + //Set the value. + string launchApp = appPath + " \"%1\""; + DWORD len = launchApp.length() + 1; + RegSetValueEx(keyHandle, NULL, 0, REG_SZ, (PBYTE)launchApp.c_str(), len); + RegCloseKey(keyHandle); + + subKey = "Software\\Classes\\.g3d"; + RegCreateKeyEx(HKEY_CURRENT_USER,subKey.c_str(),0, NULL, 0, KEY_ALL_ACCESS, NULL, &keyHandle, &dwDisposition); + //Set the value. + launchApp = "megaglest.g3d"; + len = launchApp.length() + 1; + RegSetValueEx(keyHandle, NULL, 0, REG_SZ, (PBYTE)launchApp.c_str(), len); + RegCloseKey(keyHandle); + #endif } @@ -799,7 +800,11 @@ void MainWindow::saveScreenshot() { if(autoSaveScreenshotIndex >= 0) { string saveAsFilename = autoScreenShotParams[autoSaveScreenshotIndex]; saveAsFilename.erase(0,7); +#ifdef WIN32 + FILE*f = _wfopen(utf8_decode(saveAsFilename).c_str(), L"rb"); +#else FILE *f= fopen(saveAsFilename.c_str(), "rb"); +#endif if(f == NULL) { renderer->saveScreen(saveAsFilename.c_str()); } @@ -829,7 +834,11 @@ void MainWindow::saveScreenshot() { for(int i=0; i < 5000; ++i) { path = screenShotsPath; path += string("screen") + intToStr(i) + string(".") + fileFormat; +#ifdef WIN32 + FILE*f= _wfopen(utf8_decode(path).c_str(), L"rb"); +#else FILE *f= fopen(path.c_str(), "rb"); +#endif if(f == NULL) { renderer->saveScreen(path); break; @@ -2128,9 +2137,9 @@ bool App::OnInit() { //#endif // printf("appPath [%s]\n",argv[0]); - wxString exe_path = wxStandardPaths::Get().GetExecutablePath(); - //wxString path_separator = wxFileName::GetPathSeparator(); - //exe_path = exe_path.BeforeLast(path_separator[0]); + wxString exe_path = wxStandardPaths::Get().GetExecutablePath(); + //wxString path_separator = wxFileName::GetPathSeparator(); + //exe_path = exe_path.BeforeLast(path_separator[0]); //exe_path += path_separator; #if defined(__MINGW32__) diff --git a/source/glest_game/ai/ai_interface.cpp b/source/glest_game/ai/ai_interface.cpp index 8d4d5e4e9..bd04856fa 100644 --- a/source/glest_game/ai/ai_interface.cpp +++ b/source/glest_game/ai/ai_interface.cpp @@ -52,7 +52,11 @@ AiInterface::AiInterface(Game &game, int factionIndex, int teamIndex, int useSta //clear log file if(logLevel>0){ +#ifdef WIN32 + FILE *f= _wfopen(utf8_decode(getLogFilename()).c_str(), L"wt"); +#else FILE *f= fopen(getLogFilename().c_str(), "wt"); +#endif if(f==NULL){ throw runtime_error("Can't open file: "+getLogFilename()); } @@ -80,7 +84,11 @@ void AiInterface::printLog(int logLevel, const string &s){ string logString= "(" + intToStr(factionIndex) + ") " + s; //print log to file +#ifdef WIN32 + FILE *f= _wfopen(utf8_decode(getLogFilename()).c_str(), L"at"); +#else FILE *f= fopen(getLogFilename().c_str(), "at"); +#endif if(f==NULL){ throw runtime_error("Can't open file: "+getLogFilename()); } diff --git a/source/glest_game/facilities/logger.cpp b/source/glest_game/facilities/logger.cpp index 3cd50e4ad..98251b773 100644 --- a/source/glest_game/facilities/logger.cpp +++ b/source/glest_game/facilities/logger.cpp @@ -19,6 +19,7 @@ #include "graphics_interface.h" #include "game_constants.h" #include "game_util.h" +#include "platform_util.h" #include "leak_dumper.h" using namespace std; @@ -63,7 +64,11 @@ Logger & Logger::getInstance() { } void Logger::add(const string str, bool renderScreen, const string statusText) { +#ifdef WIN32 + FILE *f= _wfopen(utf8_decode(fileName).c_str(), L"at+"); +#else FILE *f = fopen(fileName.c_str(), "at+"); +#endif if(f != NULL){ fprintf(f, "%s\n", str.c_str()); fclose(f); @@ -79,7 +84,11 @@ void Logger::add(const string str, bool renderScreen, const string statusText) void Logger::clear() { string s = "Log file\n"; +#ifdef WIN32 + FILE *f= _wfopen(utf8_decode(fileName).c_str(), L"wt+"); +#else FILE *f= fopen(fileName.c_str(), "wt+"); +#endif if(f == NULL){ throw runtime_error("Error opening log file" + fileName); } diff --git a/source/glest_game/global/config.cpp b/source/glest_game/global/config.cpp index c8dc260cc..2fad23955 100644 --- a/source/glest_game/global/config.cpp +++ b/source/glest_game/global/config.cpp @@ -194,10 +194,17 @@ Config::Config(std::pair type, std::pair f if(fileName.second != "" && fileExists(fileName.second) == false) { if(SystemFlags::VERBOSE_MODE_ENABLED) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] attempting to auto-create cfgFile.second = [%s]\n",__FILE__,__FUNCTION__,__LINE__,fileName.second.c_str()); +#ifdef WIN32 + FILE *fp = _wfopen(utf8_decode(fileName.second).c_str(), L"w"); + std::ofstream userFile(fp); +#else std::ofstream userFile; userFile.open(fileName.second.c_str(), ios_base::out | ios_base::trunc); +#endif userFile.close(); - +#ifdef WIN32 + fclose(fp); +#endif fileLoaded.second = true; properties.second.load(fileName.second); } diff --git a/source/glest_game/graphics/renderer.cpp b/source/glest_game/graphics/renderer.cpp index 16bc97dfd..d91ee0702 100644 --- a/source/glest_game/graphics/renderer.cpp +++ b/source/glest_game/graphics/renderer.cpp @@ -2488,6 +2488,12 @@ void Renderer::renderWater() { SurfaceCell *tc0= map->getSurfaceCell(i, j); SurfaceCell *tc1= map->getSurfaceCell(i, j+1); + if(tc0 == NULL) { + throw runtime_error("tc0 == NULL"); + } + if(tc1 == NULL) { + throw runtime_error("tc1 == NULL"); + } int thisTeamIndex= world->getThisTeamIndex(); @@ -4458,6 +4464,8 @@ void Renderer::init2dList() { //this list sets the state for the 2d rendering list2d= glGenLists(1); + assertGl(); + glNewList(list2d, GL_COMPILE); //projection diff --git a/source/glest_game/main/main.cpp b/source/glest_game/main/main.cpp index 718bb5fba..284ec5fd1 100644 Binary files a/source/glest_game/main/main.cpp and b/source/glest_game/main/main.cpp differ diff --git a/source/glest_game/menu/menu_state_about.cpp b/source/glest_game/menu/menu_state_about.cpp index 4b4a1a446..a13116812 100644 --- a/source/glest_game/menu/menu_state_about.cpp +++ b/source/glest_game/menu/menu_state_about.cpp @@ -104,7 +104,12 @@ string MenuStateAbout::loadAdditionalCredits(){ string result= ""; const string dir= data_path + "data/core/menu/credits.txt"; if(fileExists(dir) == true) { +#ifdef WIN32 + FILE *fp = _wfopen(utf8_decode(dir).c_str(), L"r"); + ifstream file(fp); +#else ifstream file(dir.c_str()); +#endif std::string buffer; while(!file.eof()){ getline(file, buffer); @@ -112,6 +117,9 @@ string MenuStateAbout::loadAdditionalCredits(){ } std::cout << buffer << std::endl; file.close(); +#ifdef WIN32 + fclose(fp); +#endif } return result; } diff --git a/source/glest_game/menu/menu_state_connected_game.cpp b/source/glest_game/menu/menu_state_connected_game.cpp index 82bc3397f..b577c9c06 100644 --- a/source/glest_game/menu/menu_state_connected_game.cpp +++ b/source/glest_game/menu/menu_state_connected_game.cpp @@ -2244,7 +2244,11 @@ bool MenuStateConnectedGame::loadMapInfo(string file, MapInfo *mapInfo, bool loa lastMissingMap = file; +#ifdef WIN32 + FILE *f= _wfopen(utf8_decode(file).c_str(), L"rb"); +#else FILE *f= fopen(file.c_str(), "rb"); +#endif if(f==NULL) { if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); throw runtime_error("[2]Can't open file"); diff --git a/source/glest_game/menu/menu_state_custom_game.cpp b/source/glest_game/menu/menu_state_custom_game.cpp index 21f7109e9..6a738de18 100644 --- a/source/glest_game/menu/menu_state_custom_game.cpp +++ b/source/glest_game/menu/menu_state_custom_game.cpp @@ -2373,8 +2373,13 @@ void MenuStateCustomGame::saveGameSettingsToFile(std::string fileName) { GameSettings gameSettings; loadGameSettings(&gameSettings); +#ifdef WIN32 + FILE *fp = _wfopen(utf8_decode(fileName).c_str(), L"w"); + std::ofstream saveGameFile(fp); +#else std::ofstream saveGameFile; saveGameFile.open(fileName.c_str(), ios_base::out | ios_base::trunc); +#endif //int factionCount= 0; //ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface(); @@ -2416,6 +2421,9 @@ void MenuStateCustomGame::saveGameSettingsToFile(std::string fileName) { saveGameFile << "FactionPlayerNameForIndex" << slotIndex << "=" << gameSettings.getNetworkPlayerName(i) << std::endl; } +#ifdef WIN32 + fclose(fp); +#endif if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); } @@ -2635,7 +2643,11 @@ void MenuStateCustomGame::loadMapInfo(string file, MapInfo *mapInfo, bool loadMa Lang &lang= Lang::getInstance(); try{ +#ifdef WIN32 + FILE *f= _wfopen(utf8_decode(file).c_str(), L"rb"); +#else FILE *f= fopen(file.c_str(), "rb"); +#endif if(f==NULL) throw runtime_error("Can't open file"); diff --git a/source/glest_game/menu/menu_state_mods.cpp b/source/glest_game/menu/menu_state_mods.cpp index aa5cc5c59..e70aa702f 100644 --- a/source/glest_game/menu/menu_state_mods.cpp +++ b/source/glest_game/menu/menu_state_mods.cpp @@ -670,7 +670,11 @@ MapInfo MenuStateMods::loadMapInfo(string file) { MapInfo mapInfo; //memset(&mapInfo,0,sizeof(mapInfo)); try{ +#ifdef WIN32 + FILE *f= _wfopen(utf8_decode(file).c_str(), L"rb"); +#else FILE *f= fopen(file.c_str(), "rb"); +#endif if(f != NULL) { MapFileHeader header; @@ -1843,7 +1847,8 @@ void MenuStateMods::render() { if(keyMapScrollBar.getElementCount() != 0) { for(int i = keyMapScrollBar.getVisibleStart(); i <= keyMapScrollBar.getVisibleEnd(); ++i) { - bool alreadyHasMap = (std::find(mapFiles.begin(),mapFiles.end(),keyMapButtons[i]->getText()) != mapFiles.end()); + string mapNameToRender = keyMapButtons[i]->getText(); + bool alreadyHasMap = (std::find(mapFiles.begin(),mapFiles.end(),mapNameToRender) != mapFiles.end()); if(keyMapButtons[i]->getText() == selectedMapName) { bool lightedOverride = true; renderer.renderButton(keyMapButtons[i],&WHITE,&lightedOverride); diff --git a/source/glest_game/world/map.cpp b/source/glest_game/world/map.cpp index 3e9039b81..82881a463 100644 --- a/source/glest_game/world/map.cpp +++ b/source/glest_game/world/map.cpp @@ -202,7 +202,11 @@ Vec2i Map::getStartLocation(int locationIndex) const { Checksum Map::load(const string &path, TechTree *techTree, Tileset *tileset) { Checksum mapChecksum; try{ +#ifdef WIN32 + FILE *f= _wfopen(utf8_decode(path).c_str(), L"rb"); +#else FILE *f = fopen(path.c_str(), "rb"); +#endif if(f != NULL) { mapChecksum.addFile(path); checksumValue.addFile(path); diff --git a/source/glest_game/world/world.cpp b/source/glest_game/world/world.cpp index 6d13e4a2a..e3a0f7ef1 100644 --- a/source/glest_game/world/world.cpp +++ b/source/glest_game/world/world.cpp @@ -1677,9 +1677,13 @@ std::string World::DumpWorldToLog(bool consoleBasicInfoOnly) const { } else { +#ifdef WIN32 + FILE *fp = _wfopen(utf8_decode(debugWorldLogFile).c_str(), L"w"); + std::ofstream logFile(fp); +#else std::ofstream logFile; logFile.open(debugWorldLogFile.c_str(), ios_base::out | ios_base::trunc); - +#endif logFile << "World debug information:" << std::endl; logFile << "========================" << std::endl; @@ -1704,6 +1708,9 @@ std::string World::DumpWorldToLog(bool consoleBasicInfoOnly) const { } logFile.close(); +#ifdef WIN32 + fclose(fp); +#endif } return debugWorldLogFile; } diff --git a/source/shared_lib/include/graphics/FileReader.h b/source/shared_lib/include/graphics/FileReader.h index 12baf3871..13fe5957c 100644 --- a/source/shared_lib/include/graphics/FileReader.h +++ b/source/shared_lib/include/graphics/FileReader.h @@ -141,7 +141,12 @@ public: template static inline T* readFromFileReaders(vector const *>* readers, const string& filepath) { //try to assign file +#ifdef WIN32 + FILE *fp = _wfopen(utf8_decode(filepath).c_str(), L"rb"); + ifstream file(fp); +#else ifstream file(filepath.c_str(), ios::in | ios::binary); +#endif if (!file.is_open()) { //An error occured; TODO: Which one - throw an exception, print error message? throw runtime_error("Could not open file " + filepath); } @@ -155,18 +160,39 @@ static inline T* readFromFileReaders(vector const *>* readers, con continue; } if (ret != NULL) { + file.close(); +#ifdef WIN32 + fclose(fp); +#endif return ret; } } + file.close(); +#ifdef WIN32 + fclose(fp); +#endif + return NULL; } template static inline T* readFromFileReaders(vector const *>* readers, const string& filepath, T* object) { //try to assign file - ifstream file(filepath.c_str(), ios::in | ios::binary); +#ifdef WIN32 + wstring wstr = utf8_decode(filepath); + FILE *fp = _wfopen(wstr.c_str(), L"rb"); + int fileErrno = errno; + ifstream file(fp); +#else + ifstream file(friendly_path.c_str(), ios::in | ios::binary); +#endif if (!file.is_open()) { //An error occured; TODO: Which one - throw an exception, print error message? - throw runtime_error("Could not open file [" + filepath + "]"); +#ifdef WIN32 + DWORD error = GetLastError(); + throw runtime_error("Could not open file, result: " + intToStr(error) + " - " + intToStr(fileErrno) + " [" + filepath + "]"); +#else + throw runtime_error("Could not open file [" + friendly_path + "]"); +#endif } for (typename vector const *>::const_iterator i = readers->begin(); i != readers->end(); ++i) { T* ret = NULL; @@ -178,9 +204,17 @@ static inline T* readFromFileReaders(vector const *>* readers, con continue; } if (ret != NULL) { + file.close(); +#ifdef WIN32 + fclose(fp); +#endif return ret; } } + file.close(); +#ifdef WIN32 + fclose(fp); +#endif return NULL; } @@ -292,11 +326,22 @@ bool FileReader::canRead(ifstream& file) const { */ template T* FileReader::read(const string& filepath) const { +#ifdef WIN32 + FILE *fp = _wfopen(utf8_decode(filepath).c_str(), L"rb"); + ifstream file(fp); +#else ifstream file(filepath.c_str(), ios::in | ios::binary); +#endif if (!file.is_open()) { //An error occured; TODO: Which one - throw an exception, print error message? throw runtime_error("Could not open file " + filepath); } - return read(file,filepath); + T* ret = read(file,filepath); + file.close(); +#ifdef WIN32 + fclose(fp); +#endif + + return ret; } /**Reads a file @@ -306,11 +351,22 @@ T* FileReader::read(const string& filepath) const { */ template T* FileReader::read(const string& filepath, T* object) const { +#ifdef WIN32 + FILE *fp = _wfopen(utf8_decode(filepath).c_str(), L"rb"); + ifstream file(fp); +#else ifstream file(filepath.c_str(), ios::in | ios::binary); +#endif if (!file.is_open()) { //An error occured; TODO: Which one - throw an exception, print error message? throw runtime_error("Could not open file " + filepath); } - return read(file,filepath,object); + T* ret = read(file,filepath,object); + file.close(); +#ifdef WIN32 + fclose(fp); +#endif + + return ret; } diff --git a/source/shared_lib/include/platform/win32/platform_util.h b/source/shared_lib/include/platform/win32/platform_util.h index 9c1b21673..4d420e93e 100644 --- a/source/shared_lib/include/platform/win32/platform_util.h +++ b/source/shared_lib/include/platform/win32/platform_util.h @@ -28,6 +28,10 @@ namespace Shared{ namespace Platform{ // class PlatformExceptionHandler // ===================================================== +LPWSTR Ansi2WideString(LPCSTR lpaszString); +std::string utf8_encode(const std::wstring &wstr); +std::wstring utf8_decode(const std::string &str); + LONG WINAPI UnhandledExceptionFilter2(struct _EXCEPTION_POINTERS *ExceptionInfo); class PlatformExceptionHandler{ diff --git a/source/shared_lib/sources/graphics/gl/font_gl.cpp b/source/shared_lib/sources/graphics/gl/font_gl.cpp index e54bc58e3..77cd08e1f 100644 --- a/source/shared_lib/sources/graphics/gl/font_gl.cpp +++ b/source/shared_lib/sources/graphics/gl/font_gl.cpp @@ -30,6 +30,8 @@ void Font2DGl::init(){ if(!inited){ handle= glGenLists(charCount); + assertGl(); + createGlFontBitmaps(handle, type, size, width, charCount, metrics); inited= true; } diff --git a/source/shared_lib/sources/graphics/model.cpp b/source/shared_lib/sources/graphics/model.cpp index 4d58e74d6..efa462bb3 100644 --- a/source/shared_lib/sources/graphics/model.cpp +++ b/source/shared_lib/sources/graphics/model.cpp @@ -20,6 +20,7 @@ #include "util.h" #include "platform_common.h" #include "opengl.h" +#include "platform_util.h" #include "leak_dumper.h" using namespace Shared::Platform; @@ -27,6 +28,7 @@ using namespace Shared::PlatformCommon; using namespace Shared::Graphics::Gl; using namespace std; +using namespace Shared::Util; namespace Shared{ namespace Graphics{ @@ -801,7 +803,11 @@ void Model::loadG3d(const string &path, bool deletePixMapAfterLoad, string sourceLoader) { try{ +#ifdef WIN32 + FILE *f= _wfopen(utf8_decode(path).c_str(), L"rb"); +#else FILE *f=fopen(path.c_str(),"rb"); +#endif if (f == NULL) { printf("In [%s::%s] cannot load file = [%s]\n",__FILE__,__FUNCTION__,path.c_str()); throw runtime_error("Error opening g3d model file [" + path + "]"); @@ -887,7 +893,12 @@ void Model::loadG3d(const string &path, bool deletePixMapAfterLoad, void Model::saveG3d(const string &path, string convertTextureToFormat, bool keepsmallest) { string tempModelFilename = path + "cvt"; + +#ifdef WIN32 + FILE *f= _wfopen(utf8_decode(tempModelFilename).c_str(), L"wb"); +#else FILE *f= fopen(tempModelFilename.c_str(), "wb"); +#endif if(f == NULL) { throw runtime_error("Cant open file for writting: [" + tempModelFilename + "]"); } diff --git a/source/shared_lib/sources/graphics/pixmap.cpp b/source/shared_lib/sources/graphics/pixmap.cpp index 6b360ae75..033ec5db6 100644 --- a/source/shared_lib/sources/graphics/pixmap.cpp +++ b/source/shared_lib/sources/graphics/pixmap.cpp @@ -101,7 +101,11 @@ PixmapIoTga::~PixmapIoTga() { } void PixmapIoTga::openRead(const string &path) { +#ifdef WIN32 + file= _wfopen(utf8_decode(path).c_str(), L"rb"); +#else file= fopen(path.c_str(),"rb"); +#endif if (file == NULL) { throw runtime_error("Can't open TGA file: "+ path); } @@ -181,7 +185,11 @@ void PixmapIoTga::openWrite(const string &path, int w, int h, int components) { this->h= h; this->components= components; +#ifdef WIN32 + file= _wfopen(utf8_decode(path).c_str(), L"wb"); +#else file= fopen(path.c_str(),"wb"); +#endif if (file == NULL) { throw runtime_error("Can't open TGA file: "+ path); } @@ -229,7 +237,11 @@ PixmapIoBmp::~PixmapIoBmp() { } void PixmapIoBmp::openRead(const string &path){ +#ifdef WIN32 + file= _wfopen(utf8_decode(path).c_str(), L"rb"); +#else file= fopen(path.c_str(),"rb"); +#endif if (file==NULL){ throw runtime_error("Can't open BMP file: "+ path); } @@ -288,7 +300,11 @@ void PixmapIoBmp::openWrite(const string &path, int w, int h, int components) { this->h= h; this->components= components; +#ifdef WIN32 + file= _wfopen(utf8_decode(path).c_str(), L"wb"); +#else file= fopen(path.c_str(),"wb"); +#endif if (file == NULL) { throw runtime_error("Can't open BMP file for writing: "+ path); } @@ -413,7 +429,11 @@ void PixmapIoPng::openWrite(const string &path, int w, int h, int components) { this->h= h; this->components= components; +#ifdef WIN32 + file= _wfopen(utf8_decode(path).c_str(), L"wb"); +#else file= fopen(path.c_str(),"wb"); +#endif if (file == NULL) { throw runtime_error("Can't open PNG file for writing: "+ path); } @@ -602,7 +622,11 @@ void PixmapIoJpg::openWrite(const string &path, int w, int h, int components) { this->h= h; this->components= components; +#ifdef WIN32 + file= _wfopen(utf8_decode(path).c_str(), L"wb"); +#else file= fopen(path.c_str(),"wb"); +#endif if (file == NULL) { throw runtime_error("Can't open JPG file for writing: "+ path); } diff --git a/source/shared_lib/sources/map/map_preview.cpp b/source/shared_lib/sources/map/map_preview.cpp index 68dbcc8b9..82c1d10c5 100644 --- a/source/shared_lib/sources/map/map_preview.cpp +++ b/source/shared_lib/sources/map/map_preview.cpp @@ -15,6 +15,7 @@ #include "math_wrapper.h" #include #include +#include "platform_util.h" using namespace Shared::Util; using namespace std; @@ -682,7 +683,11 @@ void MapPreview::switchSurfaces(MapSurfaceType surf1, MapSurfaceType surf2) { void MapPreview::loadFromFile(const string &path) { +#ifdef WIN32 + FILE* f1= _wfopen(utf8_decode(path).c_str(), L"rb"); +#else FILE *f1 = fopen(path.c_str(), "rb"); +#endif if (f1 != NULL) { //read header @@ -751,8 +756,11 @@ void MapPreview::loadFromFile(const string &path) { void MapPreview::saveToFile(const string &path) { - +#ifdef WIN32 + FILE* f1= _wfopen(utf8_decode(path).c_str(), L"wb"); +#else FILE *f1 = fopen(path.c_str(), "wb"); +#endif if (f1 != NULL) { //write header diff --git a/source/shared_lib/sources/platform/common/platform_common.cpp b/source/shared_lib/sources/platform/common/platform_common.cpp index 08a338650..c4bcd65d1 100644 --- a/source/shared_lib/sources/platform/common/platform_common.cpp +++ b/source/shared_lib/sources/platform/common/platform_common.cpp @@ -56,6 +56,7 @@ #include #include "randomgen.h" #include +#include "platform_util.h" #include "leak_dumper.h" using namespace Shared::Platform; @@ -290,7 +291,7 @@ void findAll(const vector &paths, const string &fileFilter, vector 0) { for(unsigned int folder_index = 0; folder_index < current_results.size(); folder_index++) { - string ¤t_file = current_results[folder_index]; + string current_file = current_results[folder_index]; if(keepDuplicates == true || std::find(results.begin(),results.end(),current_file) == results.end()) { results.push_back(current_file); } @@ -319,16 +320,14 @@ void findAll(const string &path, vector &results, bool cutExtension, boo glob_t globbuf; int res = glob(mypath.c_str(), 0, 0, &globbuf); - if(res < 0 && errorOnNotFound == true) - { + if(res < 0 && errorOnNotFound == true) { if(errorOnNotFound) { std::stringstream msg; msg << "#1 Couldn't scan directory '" << mypath << "': " << strerror(errno); throw runtime_error(msg.str()); } } - else - { + else { for(int i = 0; i < globbuf.gl_pathc; ++i) { const char* p = globbuf.gl_pathv[i]; const char* begin = p; @@ -370,8 +369,13 @@ bool isdir(const char *path) } #endif +#ifdef WIN32 + struct _stat64i32 stats; + int result = _wstat(utf8_decode(friendly_path).c_str(), &stats); +#else struct stat stats; int result = stat(friendly_path.c_str(), &stats); +#endif bool ret = (result == 0); if(ret == true) { ret = S_ISDIR(stats.st_mode); // #define S_ISDIR(mode) ((mode) & _S_IFDIR) @@ -423,7 +427,8 @@ void removeFolder(const string path) { //printf("~~~~~ REMOVE FOLDER [%s] in [%s]\n",item.c_str(),path.c_str()); #ifdef WIN32 - int result = _rmdir(item.c_str()); + //int result = _rmdir(item.c_str()); + int result = _wrmdir(utf8_decode(item).c_str()); #else int result = rmdir(item.c_str()); #endif @@ -437,7 +442,8 @@ void removeFolder(const string path) { } #ifdef WIN32 - int result = _rmdir(path.c_str()); + //int result = _rmdir(path.c_str()); + int result = _wrmdir(utf8_decode(path).c_str()); #else int result = rmdir(path.c_str()); #endif @@ -555,7 +561,11 @@ pair hasCachedFileCRCValue(string crcCacheFile, int32 &value) { //bool result = false; pair result = make_pair(false,0); if(fileExists(crcCacheFile) == true) { +#ifdef WIN32 + FILE *fp = _wfopen(utf8_decode(crcCacheFile).c_str(), L"r"); +#else FILE *fp = fopen(crcCacheFile.c_str(),"r"); +#endif if(fp != NULL) { time_t refreshDate = 0; int32 crcValue = 0; @@ -589,7 +599,11 @@ pair hasCachedFileCRCValue(string crcCacheFile, int32 &value) { } void writeCachedFileCRCValue(string crcCacheFile, int32 &crcValue) { +#ifdef WIN32 + FILE *fp = _wfopen(utf8_decode(crcCacheFile).c_str(), L"w"); +#else FILE *fp = fopen(crcCacheFile.c_str(),"w"); +#endif if(fp != NULL) { //RandomGen random; //int offset = random.randRange(5, 15); @@ -1258,7 +1272,8 @@ void createDirectoryPaths(string Path) { if ('/' == *path) { if(isdir(DirName) == false) { #ifdef WIN32 - int result = _mkdir(DirName); + int result = _wmkdir(utf8_decode(DirName).c_str()); + //int result = _mkdir(DirName); #elif defined(__GNUC__) int result = mkdir(DirName, S_IRWXU | S_IRWXO | S_IRWXG); #else @@ -1271,12 +1286,14 @@ void createDirectoryPaths(string Path) { *dirName = '\0'; } #ifdef WIN32 - _mkdir(DirName); + //int result = _mkdir(DirName); + int result = _wmkdir(utf8_decode(DirName).c_str()); #elif defined(__GNUC__) - mkdir(DirName, S_IRWXU | S_IRWXO | S_IRWXG); + int result = mkdir(DirName, S_IRWXU | S_IRWXO | S_IRWXG); #else #error "Your compiler needs to support mkdir!" #endif + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] DirName [%s] result = %d, errno = %d\n",__FILE__,__FUNCTION__,__LINE__,DirName,result,errno); } void getFullscreenVideoInfo(int &colorBits,int &screenWidth,int &screenHeight,bool isFullscreen) { @@ -1653,7 +1670,7 @@ bool executeShellCommand(string cmd, int expectedResult) { if(SystemFlags::VERBOSE_MODE_ENABLED) printf("About to run [%s]", cmd.c_str()); #ifdef WIN32 - FILE *file = _popen(cmd.c_str(),"r"); + FILE *file = _wpopen(utf8_decode(cmd).c_str(),L"r"); #else FILE *file = popen(cmd.c_str(),"r"); #endif @@ -1699,8 +1716,13 @@ bool renameFile(string oldFile, string newFile) { } off_t getFileSize(string filename) { +#ifdef WIN32 + struct _stat64i32 stbuf; + if(_wstat(utf8_decode(filename).c_str(), &stbuf) != -1) { +#else struct stat stbuf; if(stat(filename.c_str(), &stbuf) != -1) { +#endif return stbuf.st_size; } return 0; @@ -1710,7 +1732,7 @@ string executable_path(string exeName, bool includeExeNameInPath) { string value = ""; #ifdef _WIN32 char path[MAX_PATH]=""; - if( GetModuleFileName(NULL,path,MAX_PATH) == 0 ) { + if( GetModuleFileNameA(NULL,path,MAX_PATH) == 0 ) { if(includeExeNameInPath == true) { value = exeName; } @@ -1802,8 +1824,13 @@ bool searchAndReplaceTextInFile(string fileName, string findText, string replace size_t find_len = findText.length(); string tempfileName = fileName + "_tmp"; +#ifdef WIN32 + fp1 = _wfopen(utf8_decode(fileName).c_str(), L"r"); + fp2 = _wfopen(utf8_decode(tempfileName).c_str(), L"w"); +#else fp1 = fopen(fileName.c_str(),"r"); fp2 = fopen(tempfileName.c_str(),"w"); +#endif while(fgets(buffer,MAX_LEN_SINGLE_LINE + 2,fp1)) { buff_ptr = buffer; @@ -1839,8 +1866,15 @@ bool searchAndReplaceTextInFile(string fileName, string findText, string replace void copyFileTo(string fromFileName, string toFileName) { //Open an input and output stream in binary mode +#ifdef WIN32 + FILE *fp1 = _wfopen(utf8_decode(fromFileName).c_str(), L"rb"); + ifstream in(fp1); + FILE *fp2 = _wfopen(utf8_decode(toFileName).c_str(), L"wb"); + ofstream out(fp2); +#else ifstream in(fromFileName.c_str(),ios::binary); ofstream out(toFileName.c_str(),ios::binary); +#endif if(in.is_open() && out.is_open()) { while(in.eof() == false) { @@ -1851,6 +1885,11 @@ void copyFileTo(string fromFileName, string toFileName) { //Close both files in.close(); out.close(); + +#ifdef WIN32 + fclose(fp1); + fclose(fp2); +#endif } // ===================================== diff --git a/source/shared_lib/sources/platform/posix/ircclient.cpp b/source/shared_lib/sources/platform/posix/ircclient.cpp index 00beae37a..5ae898171 100644 --- a/source/shared_lib/sources/platform/posix/ircclient.cpp +++ b/source/shared_lib/sources/platform/posix/ircclient.cpp @@ -43,12 +43,12 @@ void addlog (const char * fmt, ...) { if(SystemFlags::VERBOSE_MODE_ENABLED) printf ("===> IRC: %s\n", buf); - if(SystemFlags::VERBOSE_MODE_ENABLED == true) { - if ( (fp = fopen ("irctest.log", "ab")) != 0 ) { - fprintf (fp, "%s\n", buf); - fclose (fp); - } - } + //if(SystemFlags::VERBOSE_MODE_ENABLED == true) { + // if ( (fp = fopen ("irctest.log", "ab")) != 0 ) { + // fprintf (fp, "%s\n", buf); + // fclose (fp); + // } + //} } void dump_event (irc_session_t * session, const char * event, const char * origin, const char ** params, unsigned int count) { diff --git a/source/shared_lib/sources/platform/posix/miniftpclient.cpp b/source/shared_lib/sources/platform/posix/miniftpclient.cpp index 711c0e4cc..d392ebab3 100644 --- a/source/shared_lib/sources/platform/posix/miniftpclient.cpp +++ b/source/shared_lib/sources/platform/posix/miniftpclient.cpp @@ -19,6 +19,7 @@ #include #include #include "conversion.h" +#include "platform_util.h" using namespace Shared::Util; using namespace Shared::PlatformCommon; @@ -85,7 +86,11 @@ static size_t my_fwrite(void *buffer, size_t size, size_t nmemb, void *stream) { if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"===> FTP Client thread opening file for writing [%s]\n",fullFilePath.c_str()); /* open file for writing */ +#ifdef WIN32 + out->stream= _wfopen(utf8_decode(fullFilePath).c_str(), L"wb"); +#else out->stream = fopen(fullFilePath.c_str(), "wb"); +#endif if(out->stream == NULL) { if(SystemFlags::VERBOSE_MODE_ENABLED) printf ("===> FTP Client thread FAILED to open file for writing [%s]\n",fullFilePath.c_str()); if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"===> FTP Client thread FAILED to open file for writing [%s]\n",fullFilePath.c_str()); @@ -1164,7 +1169,11 @@ pair FTPClientThread::getFileFromServer(FTP_Clien ftpfile.stream = NULL; } +#ifdef WIN32 + FILE *fp = _wfopen(utf8_decode(destFileSaveAs).c_str(), L"rt"); +#else FILE *fp = fopen(destFileSaveAs.c_str(), "rt"); +#endif if(fp != NULL) { char szBuf[4096]=""; while(feof(fp) == false) { diff --git a/source/shared_lib/sources/platform/win32/gl_wrap_billy.cpp b/source/shared_lib/sources/platform/win32/gl_wrap_billy.cpp index 9c4bdde42..1cc6b6f51 100644 --- a/source/shared_lib/sources/platform/win32/gl_wrap_billy.cpp +++ b/source/shared_lib/sources/platform/win32/gl_wrap_billy.cpp @@ -19,13 +19,14 @@ #include "window.h" #include //#include +#include "platform_util.h" #include "leak_dumper.h" using namespace Shared::Graphics::Gl; using namespace Shared::Util; namespace Shared{ namespace Platform{ - + // ====================================== @@ -43,11 +44,15 @@ namespace Shared{ namespace Platform{ void createGlFontBitmaps(uint32 &base, const string &type, int size, int width, int charCount, FontMetrics &metrics) { + //return; + // -adecw-screen-medium-r-normal--18-180-75-75-m-160-gb2312.1980-1 this is a Chinese font std::string useRealFontName = type; if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] trying to load useRealFontName [%s], size = %d, width = %d\n",__FILE__,__FUNCTION__,__LINE__,useRealFontName.c_str(),size,width); + DWORD dwErrorGL = 0; + HDC hDC = 0; static std::vector systemFontList; if(systemFontList.size() == 0) { LOGFONT lf; @@ -56,7 +61,16 @@ namespace Shared{ namespace Platform{ lf.lfCharSet = (BYTE)charSet; lf.lfFaceName[0]='\0'; - HDC hDC = wglGetCurrentDC(); + //HGLRC hdRC =wglGetCurrentContext(); + //DWORD dwErrorGL = GetLastError(); + //assertGl(); + + hDC = wglGetCurrentDC(); + dwErrorGL = GetLastError(); + assertGl(); + //hDC = CreateCompatibleDC(0); + //dwErrorGL = GetLastError(); + ::EnumFontFamiliesEx(hDC, &lf, (FONTENUMPROC) EnumFontFamExProc, @@ -79,17 +93,39 @@ namespace Shared{ namespace Platform{ } } } - + + LPWSTR wstr = Ansi2WideString(useRealFontName.c_str()); HFONT font= CreateFont( size, 0, 0, 0, width, FALSE, FALSE, FALSE, charSet, OUT_TT_ONLY_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, - DEFAULT_PITCH| (useRealFontName.c_str() ? FF_DONTCARE:FF_SWISS), useRealFontName.c_str()); - + DEFAULT_PITCH| (useRealFontName.c_str() ? FF_DONTCARE:FF_SWISS), wstr); + delete [] wstr; assert(font!=NULL); HDC dc= wglGetCurrentDC(); + dwErrorGL = GetLastError(); + assertGl(); + SelectObject(dc, font); - BOOL err= wglUseFontBitmaps(dc, 0, charCount, base); + dwErrorGL = GetLastError(); + assertGl(); + + BOOL err= 0; + err= wglUseFontBitmaps(dc, 0, charCount, base); + dwErrorGL = GetLastError(); + +/* + for(int glBugRetry = 0; glBugRetry <= 10; glBugRetry++) { + err= wglUseFontBitmaps(dc, 0, charCount, base); + dwErrorGL = GetLastError(); + //assertGl(); + GLenum error = glGetError(); + if(error == 0) { + break; + } + } +*/ + assertGl(); if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] wglUseFontBitmaps returned = %d, charCount = %d, base = %d\n",__FILE__,__FUNCTION__,__LINE__,err,charCount,base); @@ -131,6 +167,10 @@ namespace Shared{ namespace Platform{ DeleteObject(font); + //if(hDC != 0) { + // DeleteDC(hDC); + //} + assert(err); } diff --git a/source/shared_lib/sources/platform/win32/glob.c b/source/shared_lib/sources/platform/win32/glob.cpp similarity index 93% rename from source/shared_lib/sources/platform/win32/glob.c rename to source/shared_lib/sources/platform/win32/glob.cpp index 5e95d3a23..291baff1c 100644 --- a/source/shared_lib/sources/platform/win32/glob.c +++ b/source/shared_lib/sources/platform/win32/glob.cpp @@ -47,21 +47,23 @@ #include #define NOMINMAX #include +#include "platform_util.h" #define NUM_ELEMENTS(ar) (sizeof(ar) / sizeof(ar[0])) +using namespace Shared::Util; /* ///////////////////////////////////////////////////////////////////////// * Helper functions */ static char const *strrpbrk(char const *string, char const *strCharSet) { - char *part = NULL; + char const *part = NULL; char const *pch; for(pch = strCharSet; *pch; ++pch) { - char *p = strrchr(string, *pch); + const char *p = strrchr(string, *pch); if(NULL != p) { @@ -102,7 +104,7 @@ int glob( char const *pattern int result; char szRelative[1 + _MAX_PATH]; char const *file_part; - WIN32_FIND_DATAA find_data; + WIN32_FIND_DATAW find_data; HANDLE hFind; char *buffer; char szPattern2[1 + _MAX_PATH]; @@ -167,7 +169,8 @@ int glob( char const *pattern bMagic0 = (leafMost == strpbrk(leafMost, "?*")); - hFind = FindFirstFileA(effectivePattern, &find_data); + std::wstring wstr = utf8_decode(effectivePattern); + hFind = FindFirstFileW(wstr.c_str(), &find_data); buffer = NULL; pglob->gl_pathc = 0; @@ -234,8 +237,8 @@ int glob( char const *pattern GLOB_NODOTSDIRS == (flags & GLOB_NODOTSDIRS)) { /* Pattern must begin with '.' to match either dots directory */ - if( 0 == lstrcmpA(".", find_data.cFileName) || - 0 == lstrcmpA("..", find_data.cFileName)) + if( 0 == lstrcmpW(L".", find_data.cFileName) || + 0 == lstrcmpW(L"..", find_data.cFileName)) { continue; } @@ -246,7 +249,7 @@ int glob( char const *pattern #if 0 if(find_data.cFileName[0] >= 'A' && find_data.cFileName[0] <= 'M') #endif /* 0 */ - (void)lstrcatA(find_data.cFileName, "/"); + (void)lstrcatW(find_data.cFileName, L"/"); } } else @@ -261,7 +264,9 @@ int glob( char const *pattern } } - cch = lstrlenA(find_data.cFileName); + //cch = lstrlenW(find_data.cFileName); + string sFileName = utf8_encode(find_data.cFileName); + cch = sFileName.length(); if(NULL != file_part) { cch += (int)(file_part - effectivePattern); @@ -291,12 +296,13 @@ int glob( char const *pattern } (void)lstrcpynA(buffer + cbCurr, szRelative, 1 + (int)(file_part - effectivePattern)); - (void)lstrcatA(buffer + cbCurr, find_data.cFileName); + (void)lstrcatA(buffer + cbCurr, sFileName.c_str()); cbCurr += cch + 1; ++cMatches; } - while(FindNextFile(hFind, &find_data) && cMatches != maxMatches); + //while(FindNextFileA(hFind, &find_data) && cMatches != maxMatches); + while(FindNextFileW(hFind, &find_data) && cMatches != maxMatches); (void)FindClose(hFind); diff --git a/source/shared_lib/sources/platform/win32/platform_util.cpp b/source/shared_lib/sources/platform/win32/platform_util.cpp index db489670e..a4e4aadd0 100644 --- a/source/shared_lib/sources/platform/win32/platform_util.cpp +++ b/source/shared_lib/sources/platform/win32/platform_util.cpp @@ -33,18 +33,63 @@ namespace Shared { namespace Platform { PlatformExceptionHandler *PlatformExceptionHandler::thisPointer= NULL; +// Constructs object and convert lpaszString to Unicode +LPWSTR Ansi2WideString(LPCSTR lpaszString) { + LPWSTR lpwszString(NULL); + int nLen = ::lstrlenA(lpaszString) + 1; + lpwszString = new WCHAR[nLen]; + if (lpwszString == NULL) { + return lpwszString; + } + + memset(lpwszString, 0, nLen * sizeof(WCHAR)); + + if (::MultiByteToWideChar(CP_ACP, 0, lpaszString, nLen, lpwszString, nLen) == 0) { + // Conversation failed + return lpwszString; + } + + return lpwszString; +} + +// Convert a wide Unicode string to an UTF8 string +std::string utf8_encode(const std::wstring &wstr) { + int size_needed = WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), NULL, 0, NULL, NULL); + std::string strTo( size_needed, 0 ); + WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), &strTo[0], size_needed, NULL, NULL); + replaceAll(strTo, "/", "\\"); + replaceAll(strTo, "\\\\", "\\"); + updatePathClimbingParts(strTo); + return strTo; +} + +// Convert an UTF8 string to a wide Unicode String +std::wstring utf8_decode(const std::string &str) { + string friendly_path = str; + replaceAll(friendly_path, "/", "\\"); + replaceAll(friendly_path, "\\\\", "\\"); + updatePathClimbingParts(friendly_path); + int size_needed = MultiByteToWideChar(CP_UTF8, 0, &friendly_path[0], (int)friendly_path.size(), NULL, 0); + std::wstring wstrTo( size_needed, 0 ); + MultiByteToWideChar(CP_UTF8, 0, &friendly_path[0], (int)friendly_path.size(), &wstrTo[0], size_needed); + return wstrTo; +} + + LONG WINAPI PlatformExceptionHandler::handler(LPEXCEPTION_POINTERS pointers){ //printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + LPWSTR wstr = Ansi2WideString(thisPointer->dumpFileName.c_str()); HANDLE hFile = CreateFile( - thisPointer->dumpFileName.c_str(), + wstr, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); + delete [] wstr; //printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); @@ -158,11 +203,16 @@ void message(string message){ std::cerr << " " << message << "\n"; std::cerr << "******************************************************\n"; - MessageBox(NULL, message.c_str(), "Message", MB_OK); + LPWSTR wstr = Ansi2WideString(message.c_str()); + MessageBox(NULL, wstr, L"Message", MB_OK); + delete [] wstr; } bool ask(string message){ - return MessageBox(NULL, message.c_str(), "Confirmation", MB_YESNO)==IDYES; + LPWSTR wstr = Ansi2WideString(message.c_str()); + bool result = MessageBox(NULL, wstr, L"Confirmation", MB_YESNO)==IDYES; + delete [] wstr; + return result; } void exceptionMessage(const exception &excp){ @@ -175,7 +225,11 @@ void exceptionMessage(const exception &excp){ title= "Error: Unhandled Exception"; printf("Error detected with text: %s\n",message.c_str()); - MessageBox(NULL, message.c_str(), title.c_str(), MB_ICONSTOP | MB_OK | MB_TASKMODAL); + LPWSTR wstr = Ansi2WideString(message.c_str()); + LPWSTR wstr1 = Ansi2WideString(title.c_str()); + MessageBox(NULL, wstr, wstr1, MB_ICONSTOP | MB_OK | MB_TASKMODAL); + delete [] wstr; + delete [] wstr1; } //int getScreenW(){ @@ -192,7 +246,7 @@ HICON icon; void init_win32() { HINSTANCE handle = ::GetModuleHandle(NULL); - icon = ::LoadIcon(handle, "IDI_ICON1"); + icon = ::LoadIcon(handle, L"IDI_ICON1"); SDL_SysWMinfo wminfo; SDL_VERSION(&wminfo.version) diff --git a/source/shared_lib/sources/sound/sound_file_loader.cpp b/source/shared_lib/sources/sound/sound_file_loader.cpp index 0ff6a56c1..6038ccb6e 100644 --- a/source/shared_lib/sources/sound/sound_file_loader.cpp +++ b/source/shared_lib/sources/sound/sound_file_loader.cpp @@ -16,6 +16,7 @@ #include "sound.h" #include "util.h" +#include "platform_util.h" #include "leak_dumper.h" using namespace Shared::Platform; @@ -144,7 +145,11 @@ void WavSoundFileLoader::restart(){ void OggSoundFileLoader::open(const string &path, SoundInfo *soundInfo){ fileName = path; +#ifdef WIN32 + f = _wfopen(utf8_decode(path).c_str(), L"rb"); +#else f= fopen(path.c_str(), "rb"); +#endif if(f==NULL){ throw runtime_error("Can't open ogg file: "+path); } @@ -189,12 +194,13 @@ uint32 OggSoundFileLoader::read(int8 *samples, uint32 size){ return totalBytesRead; } -void OggSoundFileLoader::close(){ - if(vf!=NULL){ +void OggSoundFileLoader::close() { + if(vf != NULL) { ov_clear(vf); delete vf; vf= 0; } + fclose(f); } void OggSoundFileLoader::restart(){ diff --git a/source/shared_lib/sources/util/checksum.cpp b/source/shared_lib/sources/util/checksum.cpp index ab8ba63d4..2345fbde6 100644 --- a/source/shared_lib/sources/util/checksum.cpp +++ b/source/shared_lib/sources/util/checksum.cpp @@ -24,10 +24,12 @@ #include "util.h" #include "platform_common.h" #include "conversion.h" +#include "platform_util.h" #include "leak_dumper.h" using namespace std; using namespace Shared::PlatformCommon; +using namespace Shared::Util; namespace Shared{ namespace Util{ @@ -131,7 +133,11 @@ bool Checksum::addFileToSum(const string &path) { */ bool fileExists = false; +#ifdef WIN32 + FILE* file= _wfopen(utf8_decode(path).c_str(), L"rb"); +#else FILE* file= fopen(path.c_str(), "rb"); +#endif if(file != NULL) { fileExists = true; addString(lastFile(path)); diff --git a/source/shared_lib/sources/util/leak_dumper.cpp b/source/shared_lib/sources/util/leak_dumper.cpp index a689eaa23..a7e552aaa 100644 --- a/source/shared_lib/sources/util/leak_dumper.cpp +++ b/source/shared_lib/sources/util/leak_dumper.cpp @@ -91,7 +91,11 @@ void AllocRegistry::reset(){ } void AllocRegistry::dump(const char *path){ +#ifdef WIN32 + FILE* f= = _wfopen(utf8_decode(path).c_str(), L"wt"); +#else FILE *f= fopen(path, "wt"); +#endif int leakCount=0; size_t leakBytes=0; diff --git a/source/shared_lib/sources/util/profiler.cpp b/source/shared_lib/sources/util/profiler.cpp index d1d526b82..4cced37b4 100644 --- a/source/shared_lib/sources/util/profiler.cpp +++ b/source/shared_lib/sources/util/profiler.cpp @@ -83,7 +83,11 @@ Profiler::~Profiler(){ } profileLog = userData + profileLog; } +#ifdef WIN32 + FILE* f= = _wfopen(utf8_decode(profileLog).c_str(), L"w"); +#else FILE *f= fopen(profileLog.c_str(), "w"); +#endif if(f==NULL) throw runtime_error("Can not open file: " + profileLog); diff --git a/source/shared_lib/sources/util/properties.cpp b/source/shared_lib/sources/util/properties.cpp index ecf531983..5ed1828b4 100644 --- a/source/shared_lib/sources/util/properties.cpp +++ b/source/shared_lib/sources/util/properties.cpp @@ -18,6 +18,7 @@ #include "conversion.h" #include "util.h" #include "platform_common.h" +#include "platform_util.h" #ifdef WIN32 #include @@ -28,6 +29,7 @@ using namespace std; using namespace Shared::PlatformCommon; +using namespace Shared::Platform; namespace Shared{ namespace Util{ @@ -39,14 +41,19 @@ string Properties::applicationPath = ""; void Properties::load(const string &path, bool clearCurrentProperties) { - ifstream fileStream; char lineBuffer[maxLine]=""; string line, key, value; size_t pos=0; - this->path= path; +#ifdef WIN32 + FILE *fp = _wfopen(utf8_decode(path).c_str(), L"r"); + ifstream fileStream(fp); +#else + ifstream fileStream; fileStream.open(path.c_str(), ios_base::in); +#endif + if(fileStream.fail()){ if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] path = [%s]\n",__FILE__,__FUNCTION__,__LINE__,path.c_str()); throw runtime_error("Can't open propertyMap file: " + path); @@ -102,6 +109,9 @@ void Properties::load(const string &path, bool clearCurrentProperties) { } fileStream.close(); +#ifdef WIN32 + fclose(fp); +#endif } std::map Properties::getTagReplacementValues(std::map *mapExtraTagReplacementValues) { @@ -127,11 +137,20 @@ 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]=""; + 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))) { - string appPath = 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); + + //string appPath = szPath; replaceAll(value, "$APPDATA", appPath); replaceAll(value, "%%APPDATA%%", appPath); } @@ -241,10 +268,13 @@ bool Properties::applyTagsToValue(string &value, std::map *mapTag } void Properties::save(const string &path){ +#ifdef WIN32 + FILE *fp = _wfopen(utf8_decode(path).c_str(), L"w"); + ofstream fileStream(fp); +#else ofstream fileStream; - fileStream.open(path.c_str(), ios_base::out | ios_base::trunc); - +#endif fileStream << "; === propertyMap File === \n"; fileStream << '\n'; @@ -253,6 +283,9 @@ void Properties::save(const string &path){ } fileStream.close(); +#ifdef WIN32 + fclose(fp); +#endif } void Properties::clear(){ diff --git a/source/shared_lib/sources/util/util.cpp b/source/shared_lib/sources/util/util.cpp index a6865fe1b..9000dccb2 100644 --- a/source/shared_lib/sources/util/util.cpp +++ b/source/shared_lib/sources/util/util.cpp @@ -29,12 +29,13 @@ #include "platform_common.h" #include "conversion.h" #include "simple_threads.h" - +#include "platform_util.h" #include "leak_dumper.h" using namespace std; using namespace Shared::Platform; using namespace Shared::PlatformCommon; +using namespace Shared::Util; namespace Shared{ namespace Util{ @@ -508,8 +509,12 @@ void SystemFlags::logDebugEntry(DebugType type, string debugEntry, time_t debugT } if(currentDebugLog.fileStream == NULL) { +#ifdef WIN32 + currentDebugLog.fileStream = new std::ofstream(_wfopen(utf8_decode(debugLog).c_str(), L"w")); +#else currentDebugLog.fileStream = new std::ofstream(); currentDebugLog.fileStream->open(debugLog.c_str(), ios_base::out | ios_base::trunc); +#endif currentDebugLog.fileStreamOwner = true; currentDebugLog.mutex = new Mutex(); } @@ -583,8 +588,8 @@ string lastDir(const string &s) { pos= i 0 && @@ -610,43 +615,47 @@ string cutLastFile(const string &s){ size_t j= s.find_last_of('\\'); size_t pos; - if(i==string::npos){ + if(i == string::npos) { pos= j; } - else if(j==string::npos){ + else if(j == string::npos) { pos= i; } else{ - pos= i