From d9f435d1b714bbd89fe6bb5c0935e327062ea015 Mon Sep 17 00:00:00 2001 From: Charlie Fenton Date: Wed, 9 Aug 2023 05:37:48 -0700 Subject: [PATCH 1/3] Fix Mac crash bug introduced by commit e0ffbf106d --- clientgui/BOINCGUIApp.cpp | 14 ++++++++++++-- clientgui/DlgOptions.cpp | 4 ++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/clientgui/BOINCGUIApp.cpp b/clientgui/BOINCGUIApp.cpp index 7eb463fe525..408925c3203 100644 --- a/clientgui/BOINCGUIApp.cpp +++ b/clientgui/BOINCGUIApp.cpp @@ -205,10 +205,17 @@ bool CBOINCGUIApp::OnInit() { #endif m_pConfig->Read(wxT("DisableAutoStart"), &m_iBOINCMGRDisableAutoStart, 0L); m_pConfig->Read(wxT("LanguageISO"), &m_strISOLanguageCode, wxT("")); - bool bUseDefaultLocaleDefault = +#ifdef __WXMAC__ // wxWidgets System language detection does not work on Mac + m_bUseDefaultLocale = false; +#else + bool bUseDefaultLocaleDefault = false; + const wxLanguageInfo *defaultLanguageInfo = wxLocale::GetLanguageInfo(wxLANGUAGE_DEFAULT); + if (defaultLanguageInfo != NULL) { // Migration: assume a selected language code that matches the system default means "auto select" - m_strISOLanguageCode == wxLocale::GetLanguageInfo(wxLANGUAGE_DEFAULT)->CanonicalName; + bUseDefaultLocaleDefault = m_strISOLanguageCode == defaultLanguageInfo->CanonicalName;; + } m_pConfig->Read(wxT("UseDefaultLocale"), &m_bUseDefaultLocale, bUseDefaultLocaleDefault); +#endif m_pConfig->Read(wxT("GUISelection"), &m_iGUISelected, BOINC_SIMPLEGUI); m_pConfig->Read(wxT("EventLogOpen"), &bOpenEventLog); m_pConfig->Read(wxT("RunDaemon"), &m_bRunDaemon, 1L); @@ -946,7 +953,9 @@ void CBOINCGUIApp::InitSupportedLanguages() { wxLayoutDirection uiLayoutDirection = pLIui ? pLIui->LayoutDirection : wxLayout_Default; GUI_SUPPORTED_LANG newItem; +#ifndef __WXMAC__ // wxWidgets System language detection does not work on Mac // CDlgOptions depends on "Auto" being the first item in the list + // if newItem.Language = wxLANGUAGE_DEFAULT; wxString strAutoEnglish = wxT("(Automatic Detection)"); wxString strAutoTranslated = wxGetTranslation(strAutoEnglish); @@ -964,6 +973,7 @@ void CBOINCGUIApp::InitSupportedLanguages() { newItem.Label += LRM + strAutoEnglish + LRM; } m_astrLanguages.push_back(newItem); +#endif // Add known locales to the list for (int langID = wxLANGUAGE_UNKNOWN+1; langID < wxLANGUAGE_USER_DEFINED; ++langID) { diff --git a/clientgui/DlgOptions.cpp b/clientgui/DlgOptions.cpp index 275b18470ea..22bbe9b7d05 100644 --- a/clientgui/DlgOptions.cpp +++ b/clientgui/DlgOptions.cpp @@ -618,13 +618,13 @@ bool CDlgOptions::ReadSettings() { wxString strBuffer = wxEmptyString; wxArrayString astrDialupConnections; - wxASSERT(pDoc); wxASSERT(pFrame); wxASSERT(wxDynamicCast(pDoc, CMainDocument)); wxASSERT(wxDynamicCast(pFrame, CBOINCBaseFrame)); - +// wxWidgets System language detection does not work on Mac +// so we always set UseDefaultLocale() to false on Mac // General Tab if (wxGetApp().UseDefaultLocale()) { // CBOINCGUIApp::InitSupportedLanguages() ensures "Auto" is the first item in the list From c3bb61258291b2919d4ce787273998adb54d1e1a Mon Sep 17 00:00:00 2001 From: Charlie Fenton Date: Wed, 9 Aug 2023 05:49:51 -0700 Subject: [PATCH 2/3] Mac: fix compiler warnings introduced by commit 59eb2c20ea --- clientgui/DlgEventLog.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/clientgui/DlgEventLog.cpp b/clientgui/DlgEventLog.cpp index 00c13a6f396..7c9f38e6956 100644 --- a/clientgui/DlgEventLog.cpp +++ b/clientgui/DlgEventLog.cpp @@ -1086,7 +1086,7 @@ void CDlgEventLog::FindErrorMessages(bool isFiltered) { MESSAGE* message; wxInt32 i = 0; if (isFiltered) { - for (i; i < m_iFilteredDocCount; i++) { + for (i=0; i < m_iFilteredDocCount; i++) { message = wxGetApp().GetDocument()->message(GetFilteredMessageIndex(i)); if (message) { if (message->priority == MSG_USER_ALERT) { @@ -1096,7 +1096,7 @@ void CDlgEventLog::FindErrorMessages(bool isFiltered) { } } else { - for (i; i < m_iTotalDocCount; i++) { + for (i=0; i < m_iTotalDocCount; i++) { message = wxGetApp().GetDocument()->message(i); if (message) { if (message->priority == MSG_USER_ALERT) { @@ -1130,7 +1130,7 @@ void CDlgEventLog::FindProjectMessages(bool isFiltered) { MESSAGE* message; wxInt32 i = 0; if (isFiltered) { - for (i; i < m_iFilteredDocCount; i++) { + for (i=0; i < m_iFilteredDocCount; i++) { message = wxGetApp().GetDocument()->message(GetFilteredMessageIndex(i)); if (message) { if (message->project.empty() || message->project == s_strFilteredProjectName) { @@ -1140,7 +1140,7 @@ void CDlgEventLog::FindProjectMessages(bool isFiltered) { } } else { - for (i; i < m_iTotalDocCount; i++) { + for (i=0; i < m_iTotalDocCount; i++) { message = wxGetApp().GetDocument()->message(i); if (message) { if (message->project.empty() || message->project == s_strFilteredProjectName) { From be950db6db4a9093ce3a1eb8a154e920f5fb2268 Mon Sep 17 00:00:00 2001 From: Charlie Fenton Date: Thu, 10 Aug 2023 05:00:05 -0700 Subject: [PATCH 3/3] Fix Mac crash bug introduced by commit e0ffbf106d --- clientgui/BOINCGUIApp.cpp | 14 +++++++++----- clientgui/DlgOptions.cpp | 13 ++++++++----- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/clientgui/BOINCGUIApp.cpp b/clientgui/BOINCGUIApp.cpp index 408925c3203..df9aa21bade 100644 --- a/clientgui/BOINCGUIApp.cpp +++ b/clientgui/BOINCGUIApp.cpp @@ -205,17 +205,22 @@ bool CBOINCGUIApp::OnInit() { #endif m_pConfig->Read(wxT("DisableAutoStart"), &m_iBOINCMGRDisableAutoStart, 0L); m_pConfig->Read(wxT("LanguageISO"), &m_strISOLanguageCode, wxT("")); -#ifdef __WXMAC__ // wxWidgets System language detection does not work on Mac m_bUseDefaultLocale = false; -#else bool bUseDefaultLocaleDefault = false; +#ifdef __WXMAC__ // wxLocale::GetLanguageInfo(wxLANGUAGE_DEFAULT) does not work on Mac + wxLocale *defaultLocale = new wxLocale; + defaultLocale->Init(wxLANGUAGE_DEFAULT); + wxString defaultLanguageCode = defaultLocale->GetCanonicalName(); + bUseDefaultLocaleDefault = m_strISOLanguageCode == defaultLanguageCode; + delete defaultLocale; +#else const wxLanguageInfo *defaultLanguageInfo = wxLocale::GetLanguageInfo(wxLANGUAGE_DEFAULT); if (defaultLanguageInfo != NULL) { // Migration: assume a selected language code that matches the system default means "auto select" bUseDefaultLocaleDefault = m_strISOLanguageCode == defaultLanguageInfo->CanonicalName;; } - m_pConfig->Read(wxT("UseDefaultLocale"), &m_bUseDefaultLocale, bUseDefaultLocaleDefault); #endif + m_pConfig->Read(wxT("UseDefaultLocale"), &m_bUseDefaultLocale, bUseDefaultLocaleDefault); m_pConfig->Read(wxT("GUISelection"), &m_iGUISelected, BOINC_SIMPLEGUI); m_pConfig->Read(wxT("EventLogOpen"), &bOpenEventLog); m_pConfig->Read(wxT("RunDaemon"), &m_bRunDaemon, 1L); @@ -953,7 +958,6 @@ void CBOINCGUIApp::InitSupportedLanguages() { wxLayoutDirection uiLayoutDirection = pLIui ? pLIui->LayoutDirection : wxLayout_Default; GUI_SUPPORTED_LANG newItem; -#ifndef __WXMAC__ // wxWidgets System language detection does not work on Mac // CDlgOptions depends on "Auto" being the first item in the list // if newItem.Language = wxLANGUAGE_DEFAULT; @@ -973,11 +977,11 @@ void CBOINCGUIApp::InitSupportedLanguages() { newItem.Label += LRM + strAutoEnglish + LRM; } m_astrLanguages.push_back(newItem); -#endif // Add known locales to the list for (int langID = wxLANGUAGE_UNKNOWN+1; langID < wxLANGUAGE_USER_DEFINED; ++langID) { const wxLanguageInfo* pLI = wxLocale::GetLanguageInfo(langID); + if (pLI == NULL) continue; wxString lang_region = pLI->CanonicalName.BeforeFirst('@'); wxString lang = lang_region.BeforeFirst('_'); wxString script = pLI->CanonicalName.AfterFirst('@'); diff --git a/clientgui/DlgOptions.cpp b/clientgui/DlgOptions.cpp index 22bbe9b7d05..9ec4810d052 100644 --- a/clientgui/DlgOptions.cpp +++ b/clientgui/DlgOptions.cpp @@ -623,8 +623,6 @@ bool CDlgOptions::ReadSettings() { wxASSERT(wxDynamicCast(pDoc, CMainDocument)); wxASSERT(wxDynamicCast(pFrame, CBOINCBaseFrame)); -// wxWidgets System language detection does not work on Mac -// so we always set UseDefaultLocale() to false on Mac // General Tab if (wxGetApp().UseDefaultLocale()) { // CBOINCGUIApp::InitSupportedLanguages() ensures "Auto" is the first item in the list @@ -734,7 +732,7 @@ bool CDlgOptions::SaveSettings() { CSkinAdvanced* pSkinAdvanced = wxGetApp().GetSkinManager()->GetAdvanced(); long lBuffer = 0; wxString strBuffer = wxEmptyString; - + const wxLanguageInfo *newLanguageInfo = NULL; wxASSERT(pDoc); wxASSERT(pFrame); @@ -750,14 +748,19 @@ bool CDlgOptions::SaveSettings() { int selLangIdx = m_LanguageSelectionCtrl->GetSelection(); if (selLangIdx == 0) { // CBOINCGUIApp::InitSupportedLanguages() ensures "Auto" is the first item in the list - newLangCode = wxLocale::GetLanguageInfo(wxLANGUAGE_DEFAULT)->CanonicalName; + newLanguageInfo = wxLocale::GetLanguageInfo(wxLANGUAGE_DEFAULT); + // wxLocale::GetLanguageInfo(wxLANGUAGE_DEFAULT) may return NULL on Macintosh + newLangCode = wxEmptyString; } else if (selLangIdx > 0) { const std::vector& langs = wxGetApp().GetSupportedLanguages(); if (selLangIdx < langs.size()) { const GUI_SUPPORTED_LANG& selLang = langs[selLangIdx]; - newLangCode = wxLocale::GetLanguageInfo(selLang.Language)->CanonicalName; + newLanguageInfo = wxLocale::GetLanguageInfo(selLang.Language); } } + if (newLanguageInfo) { + newLangCode = newLanguageInfo->CanonicalName; + } if (newLangCode != oldLangCode) { wxString strDialogTitle; wxString strDialogMessage;