From a81ead8928b6e0b880a7d889d8312e140f42dd39 Mon Sep 17 00:00:00 2001 From: Daniel Wilhelm Date: Fri, 18 Apr 2014 16:52:08 +0200 Subject: 1.9 --- library/misc.cpp | 18 ++++++++++-------- library/misc.h | 4 ++++ library/multithreading.cpp | 14 +++++++++++--- library/multithreading.h | 1 + 4 files changed, 26 insertions(+), 11 deletions(-) (limited to 'library') diff --git a/library/misc.cpp b/library/misc.cpp index 7d798ec0..71bbe608 100644 --- a/library/misc.cpp +++ b/library/misc.cpp @@ -4,6 +4,8 @@ #include "resources.h" #include "globalFunctions.h" +const string CustomLocale::FfsLanguageDat = "language.dat"; + void exchangeEscapeChars(wxString& data) { data.Replace(wxT("\\\\"), wxT("\\")); @@ -23,14 +25,14 @@ CustomLocale::CustomLocale() : CustomLocale::~CustomLocale() { //write language to file - ofstream output("lang.dat"); + ofstream output(FfsLanguageDat.c_str()); if (output) { globalFunctions::writeInt(output, currentLanguage); output.close(); } else - wxMessageBox(wxString(_("Could not write to ")) + wxT("\"") + wxT("lang.dat") + wxT("\""), _("An exception occured!"), wxOK | wxICON_ERROR); + wxMessageBox(wxString(_("Could not write to ")) + wxT("\"") + wxString::From8BitData(FfsLanguageDat.c_str()) + wxT("\""), _("An exception occured!"), wxOK | wxICON_ERROR); } @@ -39,7 +41,7 @@ void CustomLocale::loadLanguageFromCfg() //retrieve language from config file: int language = wxLANGUAGE_ENGLISH; //try to load language setting from file - ifstream input("lang.dat"); + ifstream input(FfsLanguageDat.c_str()); if (input) { language = globalFunctions::readInt(input); @@ -86,15 +88,15 @@ void CustomLocale::loadLanguageFile(int language) //Delimiter: //---------- - //Linux: 0xa - //Mac: 0xd - //Win: 0xd 0xa <- language files are in Windows format + //Linux: 0xa \n + //Mac: 0xd \r + //Win: 0xd 0xa \r\n <- language files are in Windows format while (langFile.getline(temp, bufferSize, 0xd)) //specify delimiter explicitely { langFile.get(); //discard the 0xa character - //wxString formattedString = wxString::FromUTF8(temp); - wxString formattedString = wxString::From8BitData(temp); + wxString formattedString = wxString::FromUTF8(temp); + //wxString formattedString = wxString::From8BitData(temp); exchangeEscapeChars(formattedString); diff --git a/library/misc.h b/library/misc.h index a8db4088..68a5db68 100644 --- a/library/misc.h +++ b/library/misc.h @@ -36,7 +36,9 @@ public: ~CustomLocale(); void loadLanguageFromCfg(); + void loadLanguageFile(int language); + int getLanguage() { return currentLanguage; @@ -44,6 +46,8 @@ public: const wxChar* GetString(const wxChar* szOrigString, const wxChar* szDomain = NULL) const; + static const string FfsLanguageDat; + private: Translation translationDB; int currentLanguage; diff --git a/library/multithreading.cpp b/library/multithreading.cpp index c8826b11..19f83b94 100644 --- a/library/multithreading.cpp +++ b/library/multithreading.cpp @@ -68,7 +68,8 @@ public: threadHandler->longRunner(); threadHandler->readyToReceiveResult.Lock(); - threadHandler->receivingResult.Signal(); + threadHandler->receivingResult.Signal(); // kind of a double notice that work is completed + threadHandler->workDone = true; // workaround for wxCondition bug (wxWidgets v2.8.9, signal might geht lost) threadHandler->readyToReceiveResult.Unlock(); } @@ -90,7 +91,8 @@ private: UpdateWhileExecuting::UpdateWhileExecuting() : readyToReceiveResult(), - receivingResult(readyToReceiveResult) + receivingResult(readyToReceiveResult), + workDone(false) { //mutex needs to be initially locked for condition receivingResult to work properly readyToReceiveResult.Lock(); @@ -124,7 +126,6 @@ UpdateWhileExecuting::~UpdateWhileExecuting() theWorkerThread->beginProcessing.Signal(); theWorkerThread->readyToBeginProcessing.Unlock(); - //theWorkerThread deletes itself! } @@ -134,6 +135,8 @@ void UpdateWhileExecuting::waitUntilReady() readyToReceiveResult.Unlock(); //avoid possible deadlock, when thread might be waiting to send the signal (if abort was pressed) theWorkerThread->readyToBeginProcessing.Lock(); + + workDone = false; //no mutex needed here (worker thread that changes this variable is in waiting state) } // /|\ \|/ must be called directly after each other @@ -145,6 +148,11 @@ void UpdateWhileExecuting::execute(StatusUpdater* statusUpdater) theWorkerThread->readyToBeginProcessing.Unlock(); while (receivingResult.WaitTimeout(UI_UPDATE_INTERVAL) == wxCOND_TIMEOUT) + { statusUpdater->triggerUI_Refresh(true); //ATTENTION: Exception "AbortThisProcess" may be thrown here!!! + + if (workDone == true) //workaround for a bug in wxWidgets v2.8.9 class wxCondition: signals might get lost + break; //no mutex for workDone needed here: it is changed only when maintread is in WaitTimeout() + } } diff --git a/library/multithreading.h b/library/multithreading.h index f2b5211c..feecce5f 100644 --- a/library/multithreading.h +++ b/library/multithreading.h @@ -62,6 +62,7 @@ private: wxMutex readyToReceiveResult; wxCondition receivingResult; + bool workDone; //workaround for a bug in wxWidgets v2.8.9 class wxCondition: signals might get lost }; #endif // MULTITHREADING_H_INCLUDED -- cgit