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