From eaa5e0936d94e7d0bb2e6066a87d485e7613414c Mon Sep 17 00:00:00 2001 From: Oliver Tappe Date: Sat, 14 Apr 2012 17:58:58 +0200 Subject: [PATCH] Fix #8452 (app's crashing for non-existent system catalog) * make the system catalog a BCatalog instead of a BCatalogAddOn*, such that using a non-existing system catalog won't crash but simply return the untranslated string instead * rename MutableLocaleRoster::GetSystemCatalog() to LoadSystemCatalog() and adjust it to use BCatalog::SetTo() in order to replace the data used by the given catalog * adjust all users of gSystemCatalog accordingly --- headers/private/locale/MutableLocaleRoster.h | 4 ++-- headers/private/locale/SystemCatalog.h | 2 +- src/kits/interface/ColorControl.cpp | 6 +++--- src/kits/interface/Dragger.cpp | 2 +- src/kits/interface/Menu.cpp | 2 +- src/kits/interface/PrintJob.cpp | 2 +- src/kits/interface/TextView.cpp | 2 +- src/kits/interface/ZombieReplicantView.cpp | 2 +- src/kits/locale/InitLocaleKit.cpp | 5 +++-- src/kits/locale/MutableLocaleRoster.cpp | 16 ++++++++-------- src/kits/shared/AboutMenuItem.cpp | 2 +- src/kits/shared/AboutWindow.cpp | 8 ++++---- src/kits/shared/StringForSize.cpp | 10 +++++----- 13 files changed, 32 insertions(+), 31 deletions(-) diff --git a/headers/private/locale/MutableLocaleRoster.h b/headers/private/locale/MutableLocaleRoster.h index 1027fce68e..44dec1223f 100644 --- a/headers/private/locale/MutableLocaleRoster.h +++ b/headers/private/locale/MutableLocaleRoster.h @@ -46,7 +46,7 @@ public: // contain the language-name(s) status_t SetFilesystemTranslationPreferred(bool preferred); - status_t GetSystemCatalog(BCatalogAddOn** catalog) const; + status_t LoadSystemCatalog(BCatalog* catalog) const; BCatalogAddOn* LoadCatalog(const entry_ref& catalogOwner, const char* language = NULL, @@ -109,7 +109,7 @@ struct RosterData { BLocale fDefaultLocale; BTimeZone fDefaultTimeZone; - + bool fIsFilesystemTranslationPreferred; bool fAreResourcesLoaded; diff --git a/headers/private/locale/SystemCatalog.h b/headers/private/locale/SystemCatalog.h index ef0708e944..b70fd4d101 100644 --- a/headers/private/locale/SystemCatalog.h +++ b/headers/private/locale/SystemCatalog.h @@ -10,7 +10,7 @@ namespace BPrivate { -extern BCatalogAddOn* gSystemCatalog; +extern BCatalog gSystemCatalog; } // namespace BPrivate diff --git a/src/kits/interface/ColorControl.cpp b/src/kits/interface/ColorControl.cpp index 47bf460817..919c5bedf4 100644 --- a/src/kits/interface/ColorControl.cpp +++ b/src/kits/interface/ColorControl.cpp @@ -90,9 +90,9 @@ BColorControl::_InitData(color_control_layout layout, float size, const char* red = B_TRANSLATE_MARK("Red:"); const char* green = B_TRANSLATE_MARK("Green:"); const char* blue = B_TRANSLATE_MARK("Blue:"); - red = gSystemCatalog->GetString(red, "ColorControl"); - green = gSystemCatalog->GetString(green, "ColorControl"); - blue = gSystemCatalog->GetString(blue, "ColorControl"); + red = gSystemCatalog.GetString(red, "ColorControl"); + green = gSystemCatalog.GetString(green, "ColorControl"); + blue = gSystemCatalog.GetString(blue, "ColorControl"); if (archive) { fRedText = (BTextControl*)FindView("_red"); diff --git a/src/kits/interface/Dragger.cpp b/src/kits/interface/Dragger.cpp index 374b312cee..fa5020230a 100644 --- a/src/kits/interface/Dragger.cpp +++ b/src/kits/interface/Dragger.cpp @@ -43,7 +43,7 @@ using BPrivate::gSystemCatalog; #undef B_TRANSLATE #define B_TRANSLATE(str) \ - gSystemCatalog->GetString(B_TRANSLATE_MARK(str), "Dragger") + gSystemCatalog.GetString(B_TRANSLATE_MARK(str), "Dragger") const uint32 kMsgDragStarted = 'Drgs'; diff --git a/src/kits/interface/Menu.cpp b/src/kits/interface/Menu.cpp index 9055ce77f8..d5760decca 100644 --- a/src/kits/interface/Menu.cpp +++ b/src/kits/interface/Menu.cpp @@ -52,7 +52,7 @@ using BPrivate::gSystemCatalog; #undef B_TRANSLATE #define B_TRANSLATE(str) \ - gSystemCatalog->GetString(B_TRANSLATE_MARK(str), "Menu") + gSystemCatalog.GetString(B_TRANSLATE_MARK(str), "Menu") using std::nothrow; diff --git a/src/kits/interface/PrintJob.cpp b/src/kits/interface/PrintJob.cpp index 6a884f97d2..59c9543096 100644 --- a/src/kits/interface/PrintJob.cpp +++ b/src/kits/interface/PrintJob.cpp @@ -42,7 +42,7 @@ using BPrivate::gSystemCatalog; #undef B_TRANSLATE #define B_TRANSLATE(str) \ - gSystemCatalog->GetString(B_TRANSLATE_MARK(str), "PrintJob") + gSystemCatalog.GetString(B_TRANSLATE_MARK(str), "PrintJob") /*! Summary of spool file: diff --git a/src/kits/interface/TextView.cpp b/src/kits/interface/TextView.cpp index b933443509..9d14a84a04 100644 --- a/src/kits/interface/TextView.cpp +++ b/src/kits/interface/TextView.cpp @@ -65,7 +65,7 @@ using BPrivate::gSystemCatalog; #define TRANSLATE(str) \ - gSystemCatalog->GetString(B_TRANSLATE_MARK(str), "TextView") + gSystemCatalog.GetString(B_TRANSLATE_MARK(str), "TextView") #undef TRACE #undef CALLED diff --git a/src/kits/interface/ZombieReplicantView.cpp b/src/kits/interface/ZombieReplicantView.cpp index de908447f0..4269009f8c 100644 --- a/src/kits/interface/ZombieReplicantView.cpp +++ b/src/kits/interface/ZombieReplicantView.cpp @@ -26,7 +26,7 @@ using BPrivate::gSystemCatalog; #undef B_TRANSLATE #define B_TRANSLATE(str) \ - gSystemCatalog->GetString(B_TRANSLATE_MARK(str), "ZombieReplicantView") + gSystemCatalog.GetString(B_TRANSLATE_MARK(str), "ZombieReplicantView") _BZombieReplicantView_::_BZombieReplicantView_(BRect frame, status_t error) diff --git a/src/kits/locale/InitLocaleKit.cpp b/src/kits/locale/InitLocaleKit.cpp index ac246844f8..3092092f4c 100644 --- a/src/kits/locale/InitLocaleKit.cpp +++ b/src/kits/locale/InitLocaleKit.cpp @@ -17,7 +17,7 @@ namespace BPrivate { -BCatalogAddOn* gSystemCatalog; +BCatalog gSystemCatalog; } @@ -129,5 +129,6 @@ __initialize_locale_kit() { SetupCatalogBasics(); - MutableLocaleRoster::Default()->GetSystemCatalog(&BPrivate::gSystemCatalog); + MutableLocaleRoster::Default()->LoadSystemCatalog( + &BPrivate::gSystemCatalog); } diff --git a/src/kits/locale/MutableLocaleRoster.cpp b/src/kits/locale/MutableLocaleRoster.cpp index aa189b6a2c..e2b3ca0353 100644 --- a/src/kits/locale/MutableLocaleRoster.cpp +++ b/src/kits/locale/MutableLocaleRoster.cpp @@ -775,7 +775,7 @@ MutableLocaleRoster::SetFilesystemTranslationPreferred(bool preferred) status_t -MutableLocaleRoster::GetSystemCatalog(BCatalogAddOn** catalog) const +MutableLocaleRoster::LoadSystemCatalog(BCatalog* catalog) const { if (!catalog) return B_BAD_VALUE; @@ -799,13 +799,13 @@ MutableLocaleRoster::GetSystemCatalog(BCatalogAddOn** catalog) const return B_ERROR; } - // load the catalog for libbe and return it to the app + // load the catalog for libbe into the given catalog entry_ref ref; - BEntry(info.name).GetRef(&ref); + status_t status = BEntry(info.name).GetRef(&ref); + if (status != B_OK) + return status; - *catalog = LoadCatalog(ref); - - return B_OK; + return catalog->SetTo(ref); } @@ -859,8 +859,8 @@ MutableLocaleRoster::CreateCatalog(const char* type, const char* signature, * NULL is returned if no matching catalog could be found. */ BCatalogAddOn* -MutableLocaleRoster::LoadCatalog(const entry_ref& catalogOwner, const char* language, - int32 fingerprint) const +MutableLocaleRoster::LoadCatalog(const entry_ref& catalogOwner, + const char* language, int32 fingerprint) const { BAutolock lock(RosterData::Default()->fLock); if (!lock.IsLocked()) diff --git a/src/kits/shared/AboutMenuItem.cpp b/src/kits/shared/AboutMenuItem.cpp index 3b4f45fbd9..bfda1b9550 100644 --- a/src/kits/shared/AboutMenuItem.cpp +++ b/src/kits/shared/AboutMenuItem.cpp @@ -31,7 +31,7 @@ BAboutMenuItem::BAboutMenuItem() name = B_TRANSLATE_NOCOLLECT_SYSTEM_NAME(info.ref.name); const char* string = B_TRANSLATE_MARK("About %app%"); - string = gSystemCatalog->GetString(string, "AboutMenuItem"); + string = gSystemCatalog.GetString(string, "AboutMenuItem"); BString label = string; if (name != NULL) diff --git a/src/kits/shared/AboutWindow.cpp b/src/kits/shared/AboutWindow.cpp index 6c84a0f4be..ed0c53f16d 100644 --- a/src/kits/shared/AboutWindow.cpp +++ b/src/kits/shared/AboutWindow.cpp @@ -32,8 +32,8 @@ BAboutWindow::BAboutWindow(const char *appName, int32 firstCopyrightYear, const char* copyright = B_TRANSLATE_MARK("Copyright " B_UTF8_COPYRIGHT " %years% Haiku, Inc."); const char* writtenBy = B_TRANSLATE_MARK("Written by:"); - copyright = gSystemCatalog->GetString(copyright, "AboutWindow"); - writtenBy = gSystemCatalog->GetString(writtenBy, "AboutWindow"); + copyright = gSystemCatalog.GetString(copyright, "AboutWindow"); + writtenBy = gSystemCatalog.GetString(writtenBy, "AboutWindow"); // Get current year time_t tp; @@ -77,8 +77,8 @@ BAboutWindow::Show() { const char* aboutTitle = B_TRANSLATE_MARK("About" B_UTF8_ELLIPSIS); const char* closeLabel = B_TRANSLATE_MARK("Close"); - aboutTitle = gSystemCatalog->GetString(aboutTitle, "AboutWindow"); - closeLabel = gSystemCatalog->GetString(closeLabel, "AboutWindow"); + aboutTitle = gSystemCatalog.GetString(aboutTitle, "AboutWindow"); + closeLabel = gSystemCatalog.GetString(closeLabel, "AboutWindow"); BAlert *alert = new BAlert(aboutTitle, fText->String(), closeLabel); BTextView *view = alert->TextView(); diff --git a/src/kits/shared/StringForSize.cpp b/src/kits/shared/StringForSize.cpp index 2517203df1..40a89a7910 100644 --- a/src/kits/shared/StringForSize.cpp +++ b/src/kits/shared/StringForSize.cpp @@ -25,33 +25,33 @@ string_for_size(double size, char* string, size_t stringSize) double kib = size / 1024.0; if (kib < 1.0) { const char* trKey = B_TRANSLATE_MARK("%d bytes"); - snprintf(string, stringSize, gSystemCatalog->GetString(trKey, + snprintf(string, stringSize, gSystemCatalog.GetString(trKey, B_TRANSLATE_CONTEXT), (int)size); return string; } double mib = kib / 1024.0; if (mib < 1.0) { const char* trKey = B_TRANSLATE_MARK("%3.2f KiB"); - snprintf(string, stringSize, gSystemCatalog->GetString(trKey, + snprintf(string, stringSize, gSystemCatalog.GetString(trKey, B_TRANSLATE_CONTEXT), kib); return string; } double gib = mib / 1024.0; if (gib < 1.0) { const char* trKey = B_TRANSLATE_MARK("%3.2f MiB"); - snprintf(string, stringSize, gSystemCatalog->GetString(trKey, + snprintf(string, stringSize, gSystemCatalog.GetString(trKey, B_TRANSLATE_CONTEXT), mib); return string; } double tib = gib / 1024.0; if (tib < 1.0) { const char* trKey = B_TRANSLATE_MARK("%3.2f GiB"); - snprintf(string, stringSize, gSystemCatalog->GetString(trKey, + snprintf(string, stringSize, gSystemCatalog.GetString(trKey, B_TRANSLATE_CONTEXT), gib); return string; } const char* trKey = B_TRANSLATE_MARK("%.2f TiB"); - snprintf(string, stringSize, gSystemCatalog->GetString(trKey, + snprintf(string, stringSize, gSystemCatalog.GetString(trKey, B_TRANSLATE_CONTEXT), tib); return string; }