diff --git a/mk/windoze/g3d_viewer.vcproj b/mk/windoze/g3d_viewer.vcproj
index bf9f3754c..880758139 100644
--- a/mk/windoze/g3d_viewer.vcproj
+++ b/mk/windoze/g3d_viewer.vcproj
@@ -41,7 +41,7 @@
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=""..\..\source\win32_deps\wxWidgets-2.8.10\lib\vc_lib\mswd";"..\..\source\win32_deps\wxWidgets-2.8.10\include\msvc";..\..\source\shared_lib\include\util;..\..\source\shared_lib\include\platform\win32;..\..\source\shared_lib\include\graphics\gl;..\..\source\win32_deps\include;..\..\source\shared_lib\include\graphics;"..\..\source\win32_deps\wxWidgets-2.8.10\include";..\..\source\shared_lib\include\platform\sdl;../../source/shared_lib/include/streflop;../../source/shared_lib/include/platform/common;"../../source/win32_deps/SDL-1.2.x/include";"../../source/win32_deps/curl-7.21.3/include";..\..\source\glest_game\graphics;..\..\source\shared_lib\include\xml;"../../source/win32_deps/xerces-c-3.0.1/src";..\..\source\glest_game\global;..\..\source\glest_game\sound;..\..\source\shared_lib\include\sound;..\..\source\glest_game\game;../../source/shared_lib/include/map;../../source/win32_deps/lpng141;..\..\source\glest_game\facilities"
- PreprocessorDefinitions="WIN32;_WINDOWS;CURL_STATICLIB"
+ PreprocessorDefinitions="WIN32;_WINDOWS;CURL_STATICLIB;UNICODE"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
@@ -64,7 +64,7 @@
/>
cWX2MB(wxFNCONV(textCtrl->GetValue()));
value = tmp_buf;
-#else
- value= (const char*)wxFNCONV(textCtrl->GetValue());
-#endif
+
+ #ifdef WIN32
+ std::auto_ptr wstr(Ansi2WideString(value.c_str()));
+ value = utf8_encode(wstr.get());
+ #endif
+
+//#else
+ //value= (const char*)wxFNCONV(textCtrl->GetValue());
+//#endif
}
void IntField::updateControl(){
@@ -265,12 +273,17 @@ void FloatField::createControl(wxWindow *parent, wxSizer *sizer){
void FloatField::updateValue(){
-#if defined(__MINGW32__)
+//#if defined(__MINGW32__)
const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(wxFNCONV(textCtrl->GetValue()));
value = tmp_buf;
-#else
- value= (const char*)wxFNCONV(textCtrl->GetValue());
-#endif
+ #ifdef WIN32
+ std::auto_ptr wstr(Ansi2WideString(value.c_str()));
+ value = utf8_encode(wstr.get());
+ #endif
+
+//#else
+// value= (const char*)wxFNCONV(textCtrl->GetValue());
+//#endif
}
void FloatField::updateControl(){
@@ -299,12 +312,17 @@ void StringField::createControl(wxWindow *parent, wxSizer *sizer){
void StringField::updateValue(){
-#if defined(__MINGW32__)
+//#if defined(__MINGW32__)
const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(wxFNCONV(textCtrl->GetValue()));
value = tmp_buf;
-#else
- value= (const char*)wxFNCONV(textCtrl->GetValue());
-#endif
+ #ifdef WIN32
+ std::auto_ptr wstr(Ansi2WideString(value.c_str()));
+ value = utf8_encode(wstr.get());
+ #endif
+
+//#else
+// value= (const char*)wxFNCONV(textCtrl->GetValue());
+//#endif
}
void StringField::updateControl(){
@@ -329,12 +347,18 @@ void EnumField::createControl(wxWindow *parent, wxSizer *sizer){
}
void EnumField::updateValue(){
-#if defined(__MINGW32__)
+//#if defined(__MINGW32__)
const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(wxFNCONV(comboBox->GetValue()));
value = tmp_buf;
-#else
- value= (const char*)wxFNCONV(comboBox->GetValue());
-#endif
+
+ #ifdef WIN32
+ std::auto_ptr wstr(Ansi2WideString(value.c_str()));
+ value = utf8_encode(wstr.get());
+ #endif
+
+//#else
+// value= (const char*)wxFNCONV(comboBox->GetValue());
+//#endif
}
@@ -403,12 +427,18 @@ void FloatRangeField::createControl(wxWindow *parent, wxSizer *sizer){
}
void FloatRangeField::updateValue(){
-#if defined(__MINGW32__)
+//#if defined(__MINGW32__)
const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(wxFNCONV(textCtrl->GetValue()));
value = tmp_buf;
-#else
- value= (const char*)wxFNCONV(textCtrl->GetValue());
-#endif
+
+ #ifdef WIN32
+ std::auto_ptr wstr(Ansi2WideString(value.c_str()));
+ value = utf8_encode(wstr.get());
+ #endif
+
+//#else
+// value= (const char*)wxFNCONV(textCtrl->GetValue());
+//#endif
}
void FloatRangeField::updateControl(){
diff --git a/source/configurator/main.cpp b/source/configurator/main.cpp
index 7a7809156..7a7ce9722 100644
--- a/source/configurator/main.cpp
+++ b/source/configurator/main.cpp
@@ -12,6 +12,7 @@
#include "game_constants.h"
#include "util.h"
#include
+#include
using namespace std;
using namespace Shared::PlatformCommon;
@@ -212,12 +213,19 @@ bool App::OnInit(){
string appPath = "";
wxString exe_path = wxStandardPaths::Get().GetExecutablePath();
- #if defined(__MINGW32__)
- const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(wxFNCONV(exe_path));
- appPath = tmp_buf;
- #else
- appPath = wxFNCONV(exe_path);
- #endif
+ const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(wxFNCONV(exe_path));
+ appPath = tmp_buf;
+ #ifdef WIN32
+ std::auto_ptr wstr(Ansi2WideString(appPath.c_str()));
+ appPath = utf8_encode(wstr.get());
+ #endif
+
+ //#if defined(__MINGW32__)
+ // const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(wxFNCONV(exe_path));
+ // appPath = tmp_buf;
+ //#else
+ // appPath = wxFNCONV(exe_path);
+ //#endif
mainWindow= new MainWindow(appPath);
mainWindow->Show();
diff --git a/source/g3d_viewer/main.cpp b/source/g3d_viewer/main.cpp
index 1ed66c551..d5ca0916f 100644
--- a/source/g3d_viewer/main.cpp
+++ b/source/g3d_viewer/main.cpp
@@ -327,7 +327,7 @@ MainWindow::MainWindow( std::pair > unitToLoad,
#if defined(__MINGW32__)
wxIcon icon(ToUnicode("IDI_ICON1"));
#else
- wxIcon icon("IDI_ICON1");
+ wxIcon icon(L"IDI_ICON1");
#endif
#else
@@ -367,20 +367,22 @@ MainWindow::MainWindow( std::pair > unitToLoad,
//@="blergcorp.blergapp.v1"
//Open the registry key.
- string subKey = "Software\\Classes\\megaglest.g3d\\shell\\open\\command";
+ wstring subKey = L"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\"";
+ std::auto_ptr wstr(Ansi2WideString(appPath.c_str()));
+
+ wstring launchApp = wstring(wstr.get()) + L" \"%1\"";
DWORD len = launchApp.length() + 1;
RegSetValueEx(keyHandle, NULL, 0, REG_SZ, (PBYTE)launchApp.c_str(), len);
RegCloseKey(keyHandle);
- subKey = "Software\\Classes\\.g3d";
+ subKey = L"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";
+ launchApp = L"megaglest.g3d";
len = launchApp.length() + 1;
RegSetValueEx(keyHandle, NULL, 0, REG_SZ, (PBYTE)launchApp.c_str(), len);
RegCloseKey(keyHandle);
@@ -668,7 +670,15 @@ void MainWindow::onMenuFileLoad(wxCommandEvent &event){
if(fileDialog->ShowModal()==wxID_OK){
modelPathList.clear();
- loadModel((const char*)wxFNCONV(fileDialog->GetPath().c_str()));
+ const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(fileDialog->GetPath());
+ string file = tmp_buf;
+ #ifdef WIN32
+ std::auto_ptr wstr(Ansi2WideString(file.c_str()));
+ file = utf8_encode(wstr.get());
+ #endif
+
+ //loadModel((const char*)wxFNCONV(fileDialog->GetPath().c_str()));
+ loadModel(file);
}
isControlKeyPressed = false;
}
@@ -691,8 +701,15 @@ void MainWindow::onMenuFileLoadParticleXML(wxCommandEvent &event){
}
if(fileDialog->ShowModal()==wxID_OK){
- string path = (const char*)wxFNCONV(fileDialog->GetPath().c_str());
- loadParticle(path);
+ //string path = (const char*)wxFNCONV(fileDialog->GetPath().c_str());
+ const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(fileDialog->GetPath());
+ string file = tmp_buf;
+ #ifdef WIN32
+ std::auto_ptr wstr(Ansi2WideString(file.c_str()));
+ file = utf8_encode(wstr.get());
+ #endif
+
+ loadParticle(file);
}
isControlKeyPressed = false;
}
@@ -715,8 +732,15 @@ void MainWindow::onMenuFileLoadProjectileParticleXML(wxCommandEvent &event){
}
if(fileDialog->ShowModal()==wxID_OK){
- string path = (const char*)wxFNCONV(fileDialog->GetPath().c_str());
- loadProjectileParticle(path);
+ //string path = (const char*)wxFNCONV(fileDialog->GetPath().c_str());
+ const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(fileDialog->GetPath());
+ string file = tmp_buf;
+ #ifdef WIN32
+ std::auto_ptr wstr(Ansi2WideString(file.c_str()));
+ file = utf8_encode(wstr.get());
+ #endif
+
+ loadProjectileParticle(file);
}
isControlKeyPressed = false;
}
@@ -739,8 +763,15 @@ void MainWindow::onMenuFileLoadSplashParticleXML(wxCommandEvent &event){
}
if(fileDialog->ShowModal()==wxID_OK){
- string path = (const char*)wxFNCONV(fileDialog->GetPath().c_str());
- loadSplashParticle(path);
+ //string path = (const char*)wxFNCONV(fileDialog->GetPath().c_str());
+ const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(fileDialog->GetPath());
+ string file = tmp_buf;
+ #ifdef WIN32
+ std::auto_ptr wstr(Ansi2WideString(file.c_str()));
+ file = utf8_encode(wstr.get());
+ #endif
+
+ loadSplashParticle(file);
}
isControlKeyPressed = false;
}
@@ -809,7 +840,9 @@ void MainWindow::saveScreenshot() {
renderer->saveScreen(saveAsFilename.c_str());
}
else {
- fclose(f);
+ if(f) {
+ fclose(f);
+ }
}
}
else {
@@ -844,7 +877,9 @@ void MainWindow::saveScreenshot() {
break;
}
else {
- fclose(f);
+ if(f) {
+ fclose(f);
+ }
}
}
}
@@ -1856,6 +1891,14 @@ bool App::OnInit() {
autoScreenShotParams.clear();
Tokenize(optionsValue,autoScreenShotParams,",");
+
+ #ifdef WIN32
+ for(unsigned int i = 0; i < autoScreenShotParams.size(); ++i) {
+ std::auto_ptr wstr(Ansi2WideString(autoScreenShotParams[i].c_str()));
+ autoScreenShotParams[i] = utf8_encode(wstr.get());
+ }
+ #endif
+
}
}
@@ -1880,8 +1923,19 @@ bool App::OnInit() {
if(delimitedList.size() >= 2) {
unitToLoad.first = delimitedList[0];
+ #ifdef WIN32
+ std::auto_ptr wstr(Ansi2WideString(unitToLoad.first.c_str()));
+ unitToLoad.first = utf8_encode(wstr.get());
+ #endif
+
for(unsigned int i = 1; i < delimitedList.size(); ++i) {
- unitToLoad.second.push_back(delimitedList[i]);
+ string value = delimitedList[i];
+ #ifdef WIN32
+ std::auto_ptr wstr(Ansi2WideString(value.c_str()));
+ value = utf8_encode(wstr.get());
+ #endif
+
+ unitToLoad.second.push_back(value);
}
}
else {
@@ -1915,6 +1969,11 @@ bool App::OnInit() {
if(paramPartTokens.size() >= 2 && paramPartTokens[1].length() > 0) {
string customPathValue = paramPartTokens[1];
modelPath = customPathValue;
+ #ifdef WIN32
+ std::auto_ptr wstr(Ansi2WideString(modelPath.c_str()));
+ modelPath = utf8_encode(wstr.get());
+ #endif
+
}
else {
printf("\nInvalid path specified on commandline [%s] value [%s]\n\n",(const char *)wxConvCurrent->cWX2MB(argv[foundParamIndIndex]),(paramPartTokens.size() >= 2 ? paramPartTokens[1].c_str() : NULL));
@@ -1940,6 +1999,10 @@ bool App::OnInit() {
if(paramPartTokens.size() >= 2 && paramPartTokens[1].length() > 0) {
string customPathValue = paramPartTokens[1];
particlePath = customPathValue;
+ #ifdef WIN32
+ std::auto_ptr wstr(Ansi2WideString(particlePath.c_str()));
+ particlePath = utf8_encode(wstr.get());
+ #endif
}
else {
printf("\nInvalid path specified on commandline [%s] value [%s]\n\n",(const char *)wxConvCurrent->cWX2MB(argv[foundParamIndIndex]),(paramPartTokens.size() >= 2 ? paramPartTokens[1].c_str() : NULL));
@@ -1964,6 +2027,10 @@ bool App::OnInit() {
if(paramPartTokens.size() >= 2 && paramPartTokens[1].length() > 0) {
string customPathValue = paramPartTokens[1];
projectileParticlePath = customPathValue;
+ #ifdef WIN32
+ std::auto_ptr wstr(Ansi2WideString(projectileParticlePath.c_str()));
+ projectileParticlePath = utf8_encode(wstr.get());
+ #endif
}
else {
printf("\nInvalid path specified on commandline [%s] value [%s]\n\n",(const char *)wxConvCurrent->cWX2MB(argv[foundParamIndIndex]),(paramPartTokens.size() >= 2 ? paramPartTokens[1].c_str() : NULL));
@@ -1988,6 +2055,10 @@ bool App::OnInit() {
if(paramPartTokens.size() >= 2 && paramPartTokens[1].length() > 0) {
string customPathValue = paramPartTokens[1];
splashParticlePath = customPathValue;
+ #ifdef WIN32
+ std::auto_ptr wstr(Ansi2WideString(splashParticlePath.c_str()));
+ splashParticlePath = utf8_encode(wstr.get());
+ #endif
}
else {
printf("\nInvalid path specified on commandline [%s] value [%s]\n\n",(const char *)wxConvCurrent->cWX2MB(argv[foundParamIndIndex]),(paramPartTokens.size() >= 2 ? paramPartTokens[1].c_str() : NULL));
@@ -2118,12 +2189,17 @@ bool App::OnInit() {
if(argc == 2 && argv[1][0] != '-') {
-#if defined(__MINGW32__)
+//#if defined(__MINGW32__)
const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(wxFNCONV(argv[1]));
modelPath = tmp_buf;
-#else
- modelPath = wxFNCONV(argv[1]);
-#endif
+ #ifdef WIN32
+ std::auto_ptr wstr(Ansi2WideString(modelPath.c_str()));
+ modelPath = utf8_encode(wstr.get());
+ #endif
+
+//#else
+// modelPath = wxFNCONV(argv[1]);
+//#endif
}
@@ -2142,12 +2218,17 @@ bool App::OnInit() {
//exe_path = exe_path.BeforeLast(path_separator[0]);
//exe_path += path_separator;
-#if defined(__MINGW32__)
+//#if defined(__MINGW32__)
const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(wxFNCONV(exe_path));
appPath = tmp_buf;
-#else
- appPath = wxFNCONV(exe_path);
-#endif
+ #ifdef WIN32
+ std::auto_ptr wstr(Ansi2WideString(appPath.c_str()));
+ appPath = utf8_encode(wstr.get());
+ #endif
+
+//#else
+// appPath = wxFNCONV(exe_path);
+//#endif
// printf("#2 appPath [%s]\n",appPath.c_str());
diff --git a/source/glest_game/global/config.cpp b/source/glest_game/global/config.cpp
index 2fad23955..a0f3fbb08 100644
--- a/source/glest_game/global/config.cpp
+++ b/source/glest_game/global/config.cpp
@@ -195,7 +195,8 @@ Config::Config(std::pair type, std::pair f
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");
+ wstring wstr = utf8_decode(fileName.second);
+ FILE *fp = _wfopen(wstr.c_str(), L"w");
std::ofstream userFile(fp);
#else
std::ofstream userFile;
@@ -203,7 +204,9 @@ Config::Config(std::pair type, std::pair f
#endif
userFile.close();
#ifdef WIN32
- fclose(fp);
+ if(fp) {
+ fclose(fp);
+ }
#endif
fileLoaded.second = true;
properties.second.load(fileName.second);
diff --git a/source/glest_game/world/world.cpp b/source/glest_game/world/world.cpp
index e3a0f7ef1..4dfd1c9fd 100644
--- a/source/glest_game/world/world.cpp
+++ b/source/glest_game/world/world.cpp
@@ -1709,7 +1709,9 @@ std::string World::DumpWorldToLog(bool consoleBasicInfoOnly) const {
logFile.close();
#ifdef WIN32
- fclose(fp);
+ if(fp) {
+ fclose(fp);
+ }
#endif
}
return debugWorldLogFile;
diff --git a/source/glest_map_editor/main.cpp b/source/glest_map_editor/main.cpp
index 73e941e3a..35046013f 100644
--- a/source/glest_map_editor/main.cpp
+++ b/source/glest_map_editor/main.cpp
@@ -16,6 +16,7 @@
#include "platform_common.h"
#include "config.h"
#include
+#include"platform_util.h"
#include
using namespace Shared::Util;
@@ -349,11 +350,11 @@ void MainWindow::init(string fname) {
wxInitAllImageHandlers();
#ifdef WIN32
//std::cout << "B" << std::endl;
- #if defined(__MINGW32__)
+// #if defined(__MINGW32__)
wxIcon icon(ToUnicode("IDI_ICON1"));
- #else
- wxIcon icon("IDI_ICON1");
- #endif
+// #else
+// wxIcon icon("IDI_ICON1");
+// #endif
#else
//std::cout << "B" << std::endl;
@@ -575,16 +576,31 @@ void MainWindow::onMenuFileLoad(wxCommandEvent &event) {
return;
}
- fileDialog->SetMessage(wxT("Select Glestmap to load"));
- fileDialog->SetWildcard(wxT("Glest&Mega Map (*.gbm *.mgm)|*.gbm;*.mgm|Glest Map (*.gbm)|*.gbm|Mega Map (*.mgm)|*.mgm"));
- if (fileDialog->ShowModal() == wxID_OK) {
- currentFile = fileDialog->GetPath().ToAscii();
- program->loadMap(currentFile);
- fileName = cutLastExt(extractFileFromDirectoryPath(currentFile.c_str()));
- setDirty(false);
- setExtension();
- SetTitle(ToUnicode(winHeader + "; " + currentFile));
+ try {
+ fileDialog->SetMessage(wxT("Select Glestmap to load"));
+ fileDialog->SetWildcard(wxT("Glest&Mega Map (*.gbm *.mgm)|*.gbm;*.mgm|Glest Map (*.gbm)|*.gbm|Mega Map (*.mgm)|*.mgm"));
+ if (fileDialog->ShowModal() == wxID_OK) {
+ const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(wxFNCONV(fileDialog->GetPath()));
+ currentFile = tmp_buf;
+#ifdef WIN32
+ std::auto_ptr wstr(Ansi2WideString(currentFile.c_str()));
+ currentFile = utf8_encode(wstr.get());
+#endif
+
+ program->loadMap(currentFile);
+ fileName = cutLastExt(extractFileFromDirectoryPath(currentFile.c_str()));
+ setDirty(false);
+ setExtension();
+ SetTitle(ToUnicode(winHeader + "; " + currentFile));
+ }
}
+ catch (const string &e) {
+ MsgDialog(this, ToUnicode(e), wxT("Exception"), wxOK | wxICON_ERROR).ShowModal();
+ }
+ catch (const exception &e) {
+ MsgDialog(this, ToUnicode(e.what()), wxT("Exception"), wxOK | wxICON_ERROR).ShowModal();
+ }
+
}
void MainWindow::onMenuFileSave(wxCommandEvent &event) {
@@ -597,6 +613,7 @@ void MainWindow::onMenuFileSave(wxCommandEvent &event) {
onMenuFileSaveAs(ev);
} else {
setExtension();
+
program->saveMap(currentFile);
setDirty(false);
}
@@ -628,7 +645,13 @@ void MainWindow::onMenuFileSaveAs(wxCommandEvent &event) {
fd.SetWildcard(wxT("Glest Map (*.gbm)|*.gbm|MegaGlest Map (*.mgm)|*.mgm"));
if (fd.ShowModal() == wxID_OK) {
- currentFile = fd.GetPath().ToAscii();
+ const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(wxFNCONV(fd.GetPath()));
+ currentFile = tmp_buf;
+#ifdef WIN32
+ std::auto_ptr wstr(Ansi2WideString(currentFile.c_str()));
+ currentFile = utf8_encode(wstr.get());
+#endif
+
fileDialog->SetPath(fd.GetPath());
setExtension();
program->saveMap(currentFile);
@@ -1379,7 +1402,8 @@ bool SimpleDialog::show(const string &title, bool wide) {
if(m_returnCode==wxID_CANCEL) return false; // don't change values if canceled
for (unsigned int i = 0; i < texts.size(); ++i) {
- values[i].second = texts[i]->GetValue().ToAscii();
+ const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(wxFNCONV(texts[i]->GetValue()));
+ values[i].second = tmp_buf;
}
return true;
}
@@ -1407,12 +1431,18 @@ bool App::OnInit() {
exit (0);
}
-#if defined(__MINGW32__)
- const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(wxFNCONV(argv[1]));
+//#if defined(__MINGW32__)
+ const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(argv[1]);
fileparam = tmp_buf;
-#else
- fileparam = wxFNCONV(argv[1]);
+
+#ifdef WIN32
+ std::auto_ptr wstr(Ansi2WideString(fileparam.c_str()));
+ fileparam = utf8_encode(wstr.get());
#endif
+
+//#else
+// fileparam = wxFNCONV(argv[1]);
+//#endif
}
wxString exe_path = wxStandardPaths::Get().GetExecutablePath();
@@ -1421,13 +1451,20 @@ bool App::OnInit() {
//exe_path += path_separator;
string appPath = "";
-#if defined(__MINGW32__)
+//#if defined(__MINGW32__)
const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(wxFNCONV(exe_path));
appPath = tmp_buf;
-#else
- appPath = wxFNCONV(exe_path);
+
+#ifdef WIN32
+ std::auto_ptr wstr(Ansi2WideString(appPath.c_str()));
+ appPath = utf8_encode(wstr.get());
#endif
+//#else
+// const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(wxFNCONV(exe_path));
+// appPath = tmp_buf;
+//#endif
+
mainWindow = new MainWindow(appPath);
mainWindow->Show();
mainWindow->init(fileparam);
diff --git a/source/glest_map_editor/program.cpp b/source/glest_map_editor/program.cpp
index 59eaada38..14ffc2833 100644
--- a/source/glest_map_editor/program.cpp
+++ b/source/glest_map_editor/program.cpp
@@ -11,10 +11,10 @@
#include "program.h"
-
#include "util.h"
-
#include
+#include "platform_util.h"
+
using namespace Shared::Util;
namespace MapEditor {
@@ -612,11 +612,25 @@ void Program::setMapAdvanced(int altFactor, int waterLevel, int cliffLevel , int
void Program::loadMap(const string &path) {
undoStack.clear();
redoStack.clear();
- map->loadFromFile(path);
+
+ std::string encodedPath = path;
+//#ifdef WIN32
+// std::auto_ptr wstr(Ansi2WideString(path.c_str()));
+// encodedPath = utf8_encode(wstr.get());
+//#endif
+ map->loadFromFile(encodedPath);
}
void Program::saveMap(const string &path) {
- if(map) map->saveToFile(path);
+ if(map) {
+ std::string encodedPath = path;
+//#ifdef WIN32
+// std::auto_ptr wstr(Ansi2WideString(path.c_str()));
+// encodedPath = utf8_encode(wstr.get());
+//#endif
+
+ map->saveToFile(encodedPath);
+ }
}
}// end namespace
diff --git a/source/shared_lib/include/platform/win32/platform_util.h b/source/shared_lib/include/platform/win32/platform_util.h
index 4d420e93e..299a10e2b 100644
--- a/source/shared_lib/include/platform/win32/platform_util.h
+++ b/source/shared_lib/include/platform/win32/platform_util.h
@@ -24,14 +24,14 @@ using std::exception;
namespace Shared{ namespace Platform{
+LPWSTR Ansi2WideString(LPCSTR lpaszString);
+std::string utf8_encode(const std::wstring wstr);
+std::wstring utf8_decode(const std::string str);
+
// =====================================================
// 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/map/map_preview.cpp b/source/shared_lib/sources/map/map_preview.cpp
index 82c1d10c5..1bacaddb4 100644
--- a/source/shared_lib/sources/map/map_preview.cpp
+++ b/source/shared_lib/sources/map/map_preview.cpp
@@ -16,6 +16,7 @@
#include
#include
#include "platform_util.h"
+#include "conversion.h"
using namespace Shared::Util;
using namespace std;
@@ -683,11 +684,15 @@ void MapPreview::switchSurfaces(MapSurfaceType surf1, MapSurfaceType surf2) {
void MapPreview::loadFromFile(const string &path) {
+ // "Could not open file, result: 3 - 2 No such file or directory [C:\Documents and Settings\人間五\Application Data\megaglest\maps\clearings_in_the_woods.gbm]
+
#ifdef WIN32
- FILE* f1= _wfopen(utf8_decode(path).c_str(), L"rb");
+ wstring wstr = utf8_decode(path);
+ FILE* f1= _wfopen(wstr.c_str(), L"rb");
#else
FILE *f1 = fopen(path.c_str(), "rb");
#endif
+ int fileErrno = errno;
if (f1 != NULL) {
//read header
@@ -750,7 +755,13 @@ void MapPreview::loadFromFile(const string &path) {
mapFileLoaded = path;
}
else {
+#ifdef WIN32
+ DWORD error = GetLastError();
+ string strError = "Could not open file, result: " + intToStr(error) + " - " + intToStr(fileErrno) + " " + strerror(fileErrno) + " [" + path + "]";
+ throw strError;
+#else
throw runtime_error("error opening map file: " + path);
+#endif
}
}
diff --git a/source/shared_lib/sources/platform/common/platform_common.cpp b/source/shared_lib/sources/platform/common/platform_common.cpp
index c4bcd65d1..1a015685f 100644
--- a/source/shared_lib/sources/platform/common/platform_common.cpp
+++ b/source/shared_lib/sources/platform/common/platform_common.cpp
@@ -1832,6 +1832,13 @@ bool searchAndReplaceTextInFile(string fileName, string findText, string replace
fp2 = fopen(tempfileName.c_str(),"w");
#endif
+ if(fp1 == NULL) {
+ throw runtime_error("cannot open input file [" + fileName + "]");
+ }
+ if(fp2 == NULL) {
+ throw runtime_error("cannot open output file [" + tempfileName + "]");
+ }
+
while(fgets(buffer,MAX_LEN_SINGLE_LINE + 2,fp1)) {
buff_ptr = buffer;
if(findText != "") {
@@ -1881,14 +1888,24 @@ void copyFileTo(string fromFileName, string toFileName) {
out.put(in.get());
}
}
+ else if(in.is_open() == false) {
+ throw runtime_error("cannot open input file [" + fromFileName + "]");
+ }
+ else if(out.is_open() == false) {
+ throw runtime_error("cannot open input file [" + toFileName + "]");
+ }
//Close both files
in.close();
out.close();
#ifdef WIN32
- fclose(fp1);
- fclose(fp2);
+ if(fp1) {
+ fclose(fp1);
+ }
+ if(fp2) {
+ fclose(fp2);
+ }
#endif
}
diff --git a/source/shared_lib/sources/platform/posix/ircclient.cpp b/source/shared_lib/sources/platform/posix/ircclient.cpp
index 5ae898171..30e15811e 100644
--- a/source/shared_lib/sources/platform/posix/ircclient.cpp
+++ b/source/shared_lib/sources/platform/posix/ircclient.cpp
@@ -29,7 +29,7 @@ namespace Shared { namespace PlatformCommon {
const int IRC_SERVER_PORT = 6667;
void addlog (const char * fmt, ...) {
- FILE * fp;
+ //FILE * fp;
char buf[1024];
va_list va_alist;
diff --git a/source/shared_lib/sources/platform/win32/platform_util.cpp b/source/shared_lib/sources/platform/win32/platform_util.cpp
index a4e4aadd0..78f86cfc7 100644
--- a/source/shared_lib/sources/platform/win32/platform_util.cpp
+++ b/source/shared_lib/sources/platform/win32/platform_util.cpp
@@ -53,7 +53,7 @@ LPWSTR Ansi2WideString(LPCSTR lpaszString) {
}
// Convert a wide Unicode string to an UTF8 string
-std::string utf8_encode(const std::wstring &wstr) {
+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);
@@ -64,7 +64,7 @@ std::string utf8_encode(const std::wstring &wstr) {
}
// Convert an UTF8 string to a wide Unicode String
-std::wstring utf8_decode(const std::string &str) {
+std::wstring utf8_decode(const std::string str) {
string friendly_path = str;
replaceAll(friendly_path, "/", "\\");
replaceAll(friendly_path, "\\\\", "\\");
diff --git a/source/shared_lib/sources/util/util.cpp b/source/shared_lib/sources/util/util.cpp
index 9000dccb2..dcedec032 100644
--- a/source/shared_lib/sources/util/util.cpp
+++ b/source/shared_lib/sources/util/util.cpp
@@ -650,7 +650,7 @@ string ext(const string &s) {
i=s.find_last_of('.')+1;
- if (i != string::npos) {
+ if (i == string::npos) {
throw runtime_error(string(__FILE__) + " line: " + intToStr(__LINE__) + " i==string::npos for [" + s + "]");
//}
return (s.substr(i, s.size()-i));
@@ -723,16 +723,24 @@ int round(float f){
// ==================== misc ====================
-bool fileExists(const string &path){
+bool fileExists(const string &path) {
#ifdef WIN32
- FILE* file= _wfopen(utf8_decode(path).c_str(), L"rb");
+ wstring wstr = utf8_decode(path);
+ FILE* file= _wfopen(wstr.c_str(), L"rb");
#else
FILE* file= fopen(path.c_str(), "rb");
#endif
- if(file!=NULL){
+ if(file != NULL) {
fclose(file);
return true;
}
+ else {
+ int fileErrno = errno;
+#ifdef WIN32
+ DWORD error = GetLastError();
+ string strError = "Could not open file, result: " + intToStr(error) + " - " + intToStr(fileErrno) + " " + strerror(fileErrno) + " [" + path + "]";
+#endif
+ }
return false;
}
diff --git a/source/shared_lib/sources/xml/xml_parser.cpp b/source/shared_lib/sources/xml/xml_parser.cpp
index 33bbd4377..19511ef03 100644
--- a/source/shared_lib/sources/xml/xml_parser.cpp
+++ b/source/shared_lib/sources/xml/xml_parser.cpp
@@ -22,6 +22,7 @@
#include "types.h"
#include "properties.h"
#include "platform_common.h"
+#include "platform_util.h"
#include "leak_dumper.h"
@@ -106,8 +107,12 @@ XmlNode *XmlIo::load(const string &path, std::map mapTagReplaceme
config->setParameter(XMLUni::fgDOMValidate, true);
#endif
XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument *document= parser->parseURI(path.c_str());
-
- if(document==NULL){
+#ifdef WIN32
+ if(document == NULL) {
+ document= parser->parseURI(utf8_decode(path).c_str());
+ }
+#endif
+ if(document == NULL) {
throw runtime_error("Can not parse URL: " + path);
}