diff --git a/source/configurator/main.cpp b/source/configurator/main.cpp index 3ea18a1c..0855d92c 100644 --- a/source/configurator/main.cpp +++ b/source/configurator/main.cpp @@ -251,6 +251,9 @@ int App::MainLoop(){ } int App::OnExit(){ + SystemFlags::Close(); + SystemFlags::SHUTDOWN_PROGRAM_MODE=true; + return 0; } diff --git a/source/glest_map_editor/main.cpp b/source/glest_map_editor/main.cpp index 93510959..02284118 100644 --- a/source/glest_map_editor/main.cpp +++ b/source/glest_map_editor/main.cpp @@ -391,7 +391,12 @@ void MainWindow::init(string fname) { //program = new Program(glCanvas->GetClientSize().x, glCanvas->GetClientSize().y); fileName = "New (unsaved) Map"; - if (!fname.empty() && fileExists(fname)) { + + //printf("Does file exist, fname [%s]\n",fname.c_str()); + + if (fname.empty() == false && fileExists(fname)) { + //printf("YES file exist, fname [%s]\n",fname.c_str()); + //program->loadMap(fname); currentFile = fname; fileName = cutLastExt(extractFileFromDirectoryPath(fname.c_str())); @@ -400,6 +405,11 @@ void MainWindow::init(string fname) { SetTitle(ToUnicode(currentFile + " - " + winHeader)); //setDirty(false); //setExtension(); + + if(startupSettingsInited == false) { + startupSettingsInited = true; + setupStartupSettings(); + } } void MainWindow::onClose(wxCloseEvent &event) { @@ -415,7 +425,12 @@ void MainWindow::setupStartupSettings() { program = new Program(glCanvas->GetClientSize().x, glCanvas->GetClientSize().y); fileName = "New (unsaved) Map"; + + //printf("#0 file load [%s]\n",currentFile.c_str()); + if (!currentFile.empty() && fileExists(currentFile)) { + //printf("#0 exists file load [%s]\n",currentFile.c_str()); + program->loadMap(currentFile); //currentFile = fname; fileName = cutLastExt(extractFileFromDirectoryPath(currentFile.c_str())); @@ -452,14 +467,19 @@ void MainWindow::setExtension() { if (currentFile.empty() || program == NULL) { return; } + string extnsn = ext(currentFile); + + //printf("#A currentFile [%s] extnsn [%s]\n",currentFile.c_str(),extnsn.c_str()); + if (extnsn == "gbm" || extnsn == "mgm") { currentFile = cutLastExt(currentFile); } if (Program::getMap()->getMaxFactions() <= 4) { SetStatusText(wxT(".gbm"), siFILE_TYPE); currentFile += ".gbm"; - } else { + } + else { SetStatusText(wxT(".mgm"), siFILE_TYPE); currentFile += ".mgm"; } @@ -549,11 +569,6 @@ void MainWindow::onPaint(wxPaintEvent &event) { glCanvas->setCurrentGLContext(); #endif - if(startupSettingsInited == false) { - startupSettingsInited = true; - setupStartupSettings(); - } - if(lastPaintEvent.getMillis() < 30) { sleep(1); return; @@ -591,9 +606,14 @@ void MainWindow::onMenuFileLoad(wxCommandEvent &event) { std::auto_ptr wstr(Ansi2WideString(currentFile.c_str())); currentFile = utf8_encode(wstr.get()); #else - currentFile = fileDialog->GetPath().ToAscii(); + //currentFile = fileDialog->GetPath().ToAscii(); + + const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(fileDialog->GetPath()); + currentFile = tmp_buf; #endif + //printf("#1 file load [%s]\n",currentFile.c_str()); + program->loadMap(currentFile); fileName = cutLastExt(extractFileFromDirectoryPath(currentFile.c_str())); setDirty(false); @@ -618,9 +638,12 @@ void MainWindow::onMenuFileSave(wxCommandEvent &event) { if (currentFile.empty()) { wxCommandEvent ev; onMenuFileSaveAs(ev); - } else { + } + else { setExtension(); + //printf("#1 save load [%s]\n",currentFile.c_str()); + program->saveMap(currentFile); setDirty(false); } @@ -659,11 +682,16 @@ void MainWindow::onMenuFileSaveAs(wxCommandEvent &event) { std::auto_ptr wstr(Ansi2WideString(currentFile.c_str())); currentFile = utf8_encode(wstr.get()); #else - currentFile = fd.GetPath().ToAscii(); + //currentFile = fd.GetPath().ToAscii(); + const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(fd.GetPath()); + currentFile = tmp_buf; #endif fileDialog->SetPath(fd.GetPath()); setExtension(); + + //printf("#2 file save [%s]\n",currentFile.c_str()); + program->saveMap(currentFile); fileName = cutLastExt(extractFileFromDirectoryPath(currentFile.c_str())); setDirty(false); @@ -1440,6 +1468,7 @@ bool SimpleDialog::show(const string &title, bool wide) { bool App::OnInit() { SystemFlags::VERBOSE_MODE_ENABLED = true; + SystemFlags::ENABLE_THREADED_LOGGING = false; string fileparam; if(argc==2){ @@ -1520,6 +1549,9 @@ int App::MainLoop() { } int App::OnExit() { + SystemFlags::Close(); + SystemFlags::SHUTDOWN_PROGRAM_MODE=true; + return 0; } diff --git a/source/shared_lib/sources/util/util.cpp b/source/shared_lib/sources/util/util.cpp index eb756c57..3f08c4ae 100644 --- a/source/shared_lib/sources/util/util.cpp +++ b/source/shared_lib/sources/util/util.cpp @@ -654,8 +654,8 @@ string ext(const string &s) { i=s.find_last_of('.')+1; - if (i == string::npos) { - throw runtime_error(string(__FILE__) + " line: " + intToStr(__LINE__) + " i==string::npos for [" + s + "]"); + if (i != string::npos) { + //throw runtime_error(string(__FILE__) + " line: " + intToStr(__LINE__) + " i==string::npos for [" + s + "]"); //} return (s.substr(i, s.size()-i)); }