From adb7ec4a6aa66f3d02148793f895611af0ce527f Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Mon, 23 May 2011 19:50:17 +0000 Subject: [PATCH] - bugfixes from windows unicode work to compile in Linux --- source/configurator/configuration.cpp | 74 +++++++++++-------- source/configurator/main.cpp | 7 +- source/g3d_viewer/main.cpp | 63 +++++++++++----- source/glest_game/main/main.cpp | 15 ++++ source/glest_map_editor/main.cpp | 32 ++++++-- source/shared_lib/sources/map/map_preview.cpp | 4 + source/shared_lib/sources/util/properties.cpp | 1 + source/shared_lib/sources/util/util.cpp | 4 + 8 files changed, 140 insertions(+), 60 deletions(-) diff --git a/source/configurator/configuration.cpp b/source/configurator/configuration.cpp index 8b307100..5a2136e9 100644 --- a/source/configurator/configuration.cpp +++ b/source/configurator/configuration.cpp @@ -235,13 +235,15 @@ void IntField::createControl(wxWindow *parent, wxSizer *sizer){ void IntField::updateValue(){ //#if defined(__MINGW32__) - const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(wxFNCONV(textCtrl->GetValue())); - value = tmp_buf; +#ifdef WIN32 + const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(wxFNCONV(textCtrl->GetValue())); + value = tmp_buf; - #ifdef WIN32 - std::auto_ptr wstr(Ansi2WideString(value.c_str())); - value = utf8_encode(wstr.get()); - #endif + std::auto_ptr wstr(Ansi2WideString(value.c_str())); + value = utf8_encode(wstr.get()); +#else + value= (const char*)wxFNCONV(textCtrl->GetValue()); +#endif //#else //value= (const char*)wxFNCONV(textCtrl->GetValue()); @@ -274,12 +276,15 @@ void FloatField::createControl(wxWindow *parent, wxSizer *sizer){ void FloatField::updateValue(){ //#if defined(__MINGW32__) - const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(wxFNCONV(textCtrl->GetValue())); - value = tmp_buf; - #ifdef WIN32 - std::auto_ptr wstr(Ansi2WideString(value.c_str())); - value = utf8_encode(wstr.get()); - #endif +#ifdef WIN32 + const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(wxFNCONV(textCtrl->GetValue())); + value = tmp_buf; + + std::auto_ptr wstr(Ansi2WideString(value.c_str())); + value = utf8_encode(wstr.get()); +#else + value= (const char*)wxFNCONV(textCtrl->GetValue()); +#endif //#else // value= (const char*)wxFNCONV(textCtrl->GetValue()); @@ -313,12 +318,15 @@ void StringField::createControl(wxWindow *parent, wxSizer *sizer){ void StringField::updateValue(){ //#if defined(__MINGW32__) - const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(wxFNCONV(textCtrl->GetValue())); - value = tmp_buf; - #ifdef WIN32 - std::auto_ptr wstr(Ansi2WideString(value.c_str())); - value = utf8_encode(wstr.get()); - #endif +#ifdef WIN32 + const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(wxFNCONV(textCtrl->GetValue())); + value = tmp_buf; + + std::auto_ptr wstr(Ansi2WideString(value.c_str())); + value = utf8_encode(wstr.get()); +#else + value= (const char*)wxFNCONV(textCtrl->GetValue()); +#endif //#else // value= (const char*)wxFNCONV(textCtrl->GetValue()); @@ -348,13 +356,16 @@ void EnumField::createControl(wxWindow *parent, wxSizer *sizer){ void EnumField::updateValue(){ //#if defined(__MINGW32__) - const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(wxFNCONV(comboBox->GetValue())); - value = tmp_buf; - #ifdef WIN32 - std::auto_ptr wstr(Ansi2WideString(value.c_str())); - value = utf8_encode(wstr.get()); - #endif +#ifdef WIN32 + const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(wxFNCONV(comboBox->GetValue())); + value = tmp_buf; + + std::auto_ptr wstr(Ansi2WideString(value.c_str())); + value = utf8_encode(wstr.get()); +#else + value= (const char*)wxFNCONV(comboBox->GetValue()); +#endif //#else // value= (const char*)wxFNCONV(comboBox->GetValue()); @@ -428,13 +439,16 @@ void FloatRangeField::createControl(wxWindow *parent, wxSizer *sizer){ void FloatRangeField::updateValue(){ //#if defined(__MINGW32__) - const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(wxFNCONV(textCtrl->GetValue())); - value = tmp_buf; - #ifdef WIN32 - std::auto_ptr wstr(Ansi2WideString(value.c_str())); - value = utf8_encode(wstr.get()); - #endif +#ifdef WIN32 + const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(wxFNCONV(textCtrl->GetValue())); + value = tmp_buf; + + std::auto_ptr wstr(Ansi2WideString(value.c_str())); + value = utf8_encode(wstr.get()); +#else + value= (const char*)wxFNCONV(textCtrl->GetValue()); +#endif //#else // value= (const char*)wxFNCONV(textCtrl->GetValue()); diff --git a/source/configurator/main.cpp b/source/configurator/main.cpp index 7a7ce972..3ea18a1c 100644 --- a/source/configurator/main.cpp +++ b/source/configurator/main.cpp @@ -213,12 +213,15 @@ bool App::OnInit(){ string appPath = ""; wxString exe_path = wxStandardPaths::Get().GetExecutablePath(); +#ifdef WIN32 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 +#else + appPath = wxFNCONV(exe_path); +#endif //#if defined(__MINGW32__) // const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(wxFNCONV(exe_path)); diff --git a/source/g3d_viewer/main.cpp b/source/g3d_viewer/main.cpp index d5ca0916..71a2b611 100644 --- a/source/g3d_viewer/main.cpp +++ b/source/g3d_viewer/main.cpp @@ -14,6 +14,10 @@ #include "game_constants.h" #include #include +#ifndef WIN32 +#include +#endif + //#include #ifndef WIN32 @@ -670,12 +674,16 @@ void MainWindow::onMenuFileLoad(wxCommandEvent &event){ if(fileDialog->ShowModal()==wxID_OK){ modelPathList.clear(); + string file = ""; +#ifdef WIN32 const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(fileDialog->GetPath()); - string file = tmp_buf; - #ifdef WIN32 + file = tmp_buf; + std::auto_ptr wstr(Ansi2WideString(file.c_str())); file = utf8_encode(wstr.get()); - #endif +#else + file = (const char*)wxFNCONV(fileDialog->GetPath().c_str()); +#endif //loadModel((const char*)wxFNCONV(fileDialog->GetPath().c_str())); loadModel(file); @@ -702,12 +710,15 @@ void MainWindow::onMenuFileLoadParticleXML(wxCommandEvent &event){ if(fileDialog->ShowModal()==wxID_OK){ //string path = (const char*)wxFNCONV(fileDialog->GetPath().c_str()); + string file = ""; +#ifdef WIN32 const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(fileDialog->GetPath()); - string file = tmp_buf; - #ifdef WIN32 + file = tmp_buf; std::auto_ptr wstr(Ansi2WideString(file.c_str())); file = utf8_encode(wstr.get()); - #endif +#else + file = (const char*)wxFNCONV(fileDialog->GetPath().c_str()); +#endif loadParticle(file); } @@ -733,12 +744,15 @@ void MainWindow::onMenuFileLoadProjectileParticleXML(wxCommandEvent &event){ if(fileDialog->ShowModal()==wxID_OK){ //string path = (const char*)wxFNCONV(fileDialog->GetPath().c_str()); + string file = ""; +#ifdef WIN32 const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(fileDialog->GetPath()); - string file = tmp_buf; - #ifdef WIN32 + file = tmp_buf; std::auto_ptr wstr(Ansi2WideString(file.c_str())); file = utf8_encode(wstr.get()); - #endif +#else + file = (const char*)wxFNCONV(fileDialog->GetPath().c_str()); +#endif loadProjectileParticle(file); } @@ -764,12 +778,16 @@ void MainWindow::onMenuFileLoadSplashParticleXML(wxCommandEvent &event){ if(fileDialog->ShowModal()==wxID_OK){ //string path = (const char*)wxFNCONV(fileDialog->GetPath().c_str()); + string file = ""; +#ifdef WIN32 const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(fileDialog->GetPath()); - string file = tmp_buf; - #ifdef WIN32 + file = tmp_buf; + std::auto_ptr wstr(Ansi2WideString(file.c_str())); file = utf8_encode(wstr.get()); - #endif +#else + file = (const char*)wxFNCONV(fileDialog->GetPath().c_str()); +#endif loadSplashParticle(file); } @@ -2190,12 +2208,14 @@ bool App::OnInit() { if(argc == 2 && argv[1][0] != '-') { //#if defined(__MINGW32__) +#ifdef WIN32 const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(wxFNCONV(argv[1])); modelPath = tmp_buf; - #ifdef WIN32 std::auto_ptr wstr(Ansi2WideString(modelPath.c_str())); modelPath = utf8_encode(wstr.get()); - #endif +#else + modelPath = wxFNCONV(argv[1]); +#endif //#else // modelPath = wxFNCONV(argv[1]); @@ -2219,12 +2239,15 @@ bool App::OnInit() { //exe_path += path_separator; //#if defined(__MINGW32__) - 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 +#ifdef WIN32 + const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(wxFNCONV(exe_path)); + appPath = tmp_buf; + + std::auto_ptr wstr(Ansi2WideString(appPath.c_str())); + appPath = utf8_encode(wstr.get()); +#else + appPath = wxFNCONV(exe_path); +#endif //#else // appPath = wxFNCONV(exe_path); diff --git a/source/glest_game/main/main.cpp b/source/glest_game/main/main.cpp index 8d132e6d..8a922701 100644 --- a/source/glest_game/main/main.cpp +++ b/source/glest_game/main/main.cpp @@ -2531,6 +2531,21 @@ int glestMain(int argc, char** argv) { lang.loadStrings(language); + if( lang.hasString("FONT_CHARCOUNT") && + lang.hasString("FONT_TYPENAME") && + lang.hasString("FONT_CHARSET")) { + // 256 for English + // 30000 for Chinese + Font::charCount = strToInt(lang.get("FONT_CHARCOUNT")); + Font::fontTypeName = lang.get("FONT_TYPENAME"); + // Example values: + // DEFAULT_CHARSET (English) = 1 + // GB2312_CHARSET (Chinese) = 134 + Shared::Platform::charSet = strToInt(lang.get("FONT_CHARSET")); + } + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] Font::charCount = %d, Font::fontTypeName [%s] Shared::Platform::charSet = %d\n",__FILE__,__FUNCTION__,__LINE__,Font::charCount,Font::fontTypeName.c_str(),Shared::Platform::charSet); + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Using Font::charCount = %d, Font::fontTypeName [%s] Shared::Platform::charSet = %d\n",Font::charCount,Font::fontTypeName.c_str(),Shared::Platform::charSet); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); if(hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_SHOW_MAP_CRC]) == true) { diff --git a/source/glest_map_editor/main.cpp b/source/glest_map_editor/main.cpp index 35046013..dae1d3e0 100644 --- a/source/glest_map_editor/main.cpp +++ b/source/glest_map_editor/main.cpp @@ -18,6 +18,9 @@ #include #include"platform_util.h" #include +#ifndef WIN32 +#include +#endif using namespace Shared::Util; using namespace Shared::PlatformCommon; @@ -580,11 +583,14 @@ void MainWindow::onMenuFileLoad(wxCommandEvent &event) { 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) { +#ifdef WIN32 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()); +#else + currentFile = fileDialog->GetPath().ToAscii(); #endif program->loadMap(currentFile); @@ -645,11 +651,14 @@ void MainWindow::onMenuFileSaveAs(wxCommandEvent &event) { fd.SetWildcard(wxT("Glest Map (*.gbm)|*.gbm|MegaGlest Map (*.mgm)|*.mgm")); if (fd.ShowModal() == wxID_OK) { +#ifdef WIN32 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()); + + std::auto_ptr wstr(Ansi2WideString(currentFile.c_str())); + currentFile = utf8_encode(wstr.get()); +#else + currentFile = fd.GetPath().ToAscii(); #endif fileDialog->SetPath(fd.GetPath()); @@ -1402,8 +1411,12 @@ 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) { +#ifdef WIN32 const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(wxFNCONV(texts[i]->GetValue())); values[i].second = tmp_buf; +#else + values[i].second = texts[i]->GetValue().ToAscii(); +#endif } return true; } @@ -1452,12 +1465,15 @@ bool App::OnInit() { string appPath = ""; //#if defined(__MINGW32__) - 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()); + const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(wxFNCONV(exe_path)); + appPath = tmp_buf; + + std::auto_ptr wstr(Ansi2WideString(appPath.c_str())); + appPath = utf8_encode(wstr.get()); +#else + appPath = wxFNCONV(exe_path); #endif //#else diff --git a/source/shared_lib/sources/map/map_preview.cpp b/source/shared_lib/sources/map/map_preview.cpp index 1bacaddb..657611f6 100644 --- a/source/shared_lib/sources/map/map_preview.cpp +++ b/source/shared_lib/sources/map/map_preview.cpp @@ -18,6 +18,10 @@ #include "platform_util.h" #include "conversion.h" +#ifndef WIN32 +#include +#endif + using namespace Shared::Util; using namespace std; diff --git a/source/shared_lib/sources/util/properties.cpp b/source/shared_lib/sources/util/properties.cpp index 5ed1828b..124dbd00 100644 --- a/source/shared_lib/sources/util/properties.cpp +++ b/source/shared_lib/sources/util/properties.cpp @@ -65,6 +65,7 @@ void Properties::load(const string &path, bool clearCurrentProperties) { while(!fileStream.eof()){ fileStream.getline(lineBuffer, maxLine); lineBuffer[maxLine-1]='\0'; + //printf("\n[%s]\n",lineBuffer); //process line if it it not a comment if(lineBuffer[0]!=';'){ diff --git a/source/shared_lib/sources/util/util.cpp b/source/shared_lib/sources/util/util.cpp index dcedec03..eb756c57 100644 --- a/source/shared_lib/sources/util/util.cpp +++ b/source/shared_lib/sources/util/util.cpp @@ -30,6 +30,10 @@ #include "conversion.h" #include "simple_threads.h" #include "platform_util.h" +#ifndef WIN32 +#include +#endif + #include "leak_dumper.h" using namespace std;