From 40b8bc8c3da282b0e2f722022ff6ce9aae86c993 Mon Sep 17 00:00:00 2001 From: "sgehani%netscape.com" Date: Wed, 11 Oct 2000 05:40:51 +0000 Subject: [PATCH] Testing the fix for bugscape 2470 on the trunk per PDT. Make the Unix installer support fallbacks when loading the string bundle. b=2470 r=dbragg a=erik git-svn-id: svn://10.0.0.236/trunk@80902 18797224-902f-48f8-a5cc-f745e15eee43 --- .../src2/{installer.prop => installer.ini} | 0 .../wizard/unix/src2/nsINIParser.cpp | 34 +++++++++++++++++++ .../xpinstall/wizard/unix/src2/nsINIParser.h | 18 ++++++++++ .../wizard/unix/src2/nsXIContext.cpp | 12 ++++++- .../xpinstall/wizard/unix/src2/nsXIContext.h | 2 +- .../wizard/unix/src2/nsXInstaller.cpp | 15 +++++--- .../xpinstall/wizard/unix/src2/nsXInstaller.h | 2 +- 7 files changed, 76 insertions(+), 7 deletions(-) rename mozilla/xpinstall/wizard/unix/src2/{installer.prop => installer.ini} (100%) diff --git a/mozilla/xpinstall/wizard/unix/src2/installer.prop b/mozilla/xpinstall/wizard/unix/src2/installer.ini similarity index 100% rename from mozilla/xpinstall/wizard/unix/src2/installer.prop rename to mozilla/xpinstall/wizard/unix/src2/installer.ini diff --git a/mozilla/xpinstall/wizard/unix/src2/nsINIParser.cpp b/mozilla/xpinstall/wizard/unix/src2/nsINIParser.cpp index 0cef92dd02b..e188c01dfb5 100644 --- a/mozilla/xpinstall/wizard/unix/src2/nsINIParser.cpp +++ b/mozilla/xpinstall/wizard/unix/src2/nsINIParser.cpp @@ -138,6 +138,40 @@ nsINIParser::GetError() return mError; } +char * +nsINIParser::ResolveName(char *aINIRoot) +{ + char *resolved = NULL; + char *locale = NULL; + struct stat st_exists; + + /* param check */ + if (!aINIRoot) + return NULL; + + locale = setlocale(LC_CTYPE, NULL); + if (!locale) + return NULL; + + /* resolved string: ".ini.\0" */ + resolved = (char *) malloc(strlen(aINIRoot) + 5 + strlen(locale) + 1); + if (!resolved) + return NULL; + + /* locale specific ini file name */ + sprintf(resolved, "%s.ini.%s", aINIRoot, locale); + if (0 == stat(resolved, &st_exists)) + return resolved; + + /* fallback to general ini file name */ + sprintf(resolved, "%s.ini", aINIRoot); + if (0 == stat(resolved, &st_exists)) + return resolved; + + /* neither existed so error returned */ + return NULL; +} + int nsINIParser::FindSection(char *aSection, char **aOutSecPtr) { diff --git a/mozilla/xpinstall/wizard/unix/src2/nsINIParser.h b/mozilla/xpinstall/wizard/unix/src2/nsINIParser.h index 01e77d93fb2..ac1cd4ae95c 100644 --- a/mozilla/xpinstall/wizard/unix/src2/nsINIParser.h +++ b/mozilla/xpinstall/wizard/unix/src2/nsINIParser.h @@ -28,6 +28,8 @@ #include #include #include +#include +#include class nsINIParser { @@ -90,6 +92,22 @@ public: */ int GetError(); + /** + * ResolveName + * + * Given a "root" name we append the runtime locale of the + * current system to the .ini. If such a file exists we + * return this as the name else simply return .ini. + * + * NOTE: Returned string is allocated and caller is responsible + * ---- for its deallocation. + * + * @param aINIRoot the "root" of the INI file name + * @return resolved the resolved INI file name + * (NULL if neither exist) + */ + static char *ResolveName(char *aINIRoot); + /*--------------------------------------------------------------------* * Errors *--------------------------------------------------------------------*/ diff --git a/mozilla/xpinstall/wizard/unix/src2/nsXIContext.cpp b/mozilla/xpinstall/wizard/unix/src2/nsXIContext.cpp index 7843fa9a9e6..51fedb3addf 100644 --- a/mozilla/xpinstall/wizard/unix/src2/nsXIContext.cpp +++ b/mozilla/xpinstall/wizard/unix/src2/nsXIContext.cpp @@ -123,13 +123,22 @@ int nsXIContext::LoadResources() { int err = OK; - nsINIParser *parser = new nsINIParser(RES_FILE); + nsINIParser *parser = NULL; + char *resfile = NULL; kvpair *currkv = NULL; char currkey[MAX_KEY_SIZE]; int len, i; + resfile = nsINIParser::ResolveName(RES_FILE); + if (!resfile) + return E_INVALID_PTR; + + parser = new nsINIParser(resfile); if (!parser) + { + XI_IF_FREE(resfile); return E_MEM; + } char *strkeys[] = { @@ -203,6 +212,7 @@ BAIL: { fprintf(stderr, "FATAL ERROR: Failed to load resources!"); } + XI_IF_FREE(resfile); XI_IF_DELETE(parser); return err; } diff --git a/mozilla/xpinstall/wizard/unix/src2/nsXIContext.h b/mozilla/xpinstall/wizard/unix/src2/nsXIContext.h index c3dcca18852..224af1da730 100644 --- a/mozilla/xpinstall/wizard/unix/src2/nsXIContext.h +++ b/mozilla/xpinstall/wizard/unix/src2/nsXIContext.h @@ -33,7 +33,7 @@ #include "nsXIOptions.h" #include "nsINIParser.h" -#define RES_FILE "installer.prop" +#define RES_FILE "installer" #define RES_SECT "String Resources" class nsXInstaller; diff --git a/mozilla/xpinstall/wizard/unix/src2/nsXInstaller.cpp b/mozilla/xpinstall/wizard/unix/src2/nsXInstaller.cpp index 309b04cfbaa..d843b0b7670 100644 --- a/mozilla/xpinstall/wizard/unix/src2/nsXInstaller.cpp +++ b/mozilla/xpinstall/wizard/unix/src2/nsXInstaller.cpp @@ -44,15 +44,23 @@ nsXInstaller::ParseConfig() { int err = OK; nsINIParser *parser = NULL; + char *cfg = NULL; XI_ERR_BAIL(InitContext()); err = gCtx->LoadResources(); if (err != OK) return err; - parser = new nsINIParser( CONFIG_INI ); + cfg = nsINIParser::ResolveName(CONFIG); + if (!cfg) + return E_INVALID_PTR; + + parser = new nsINIParser(cfg); if (!parser) - return E_MEM; + { + err = E_MEM; + goto BAIL; + } err = parser->GetError(); if (err != nsINIParser::OK) @@ -65,9 +73,8 @@ nsXInstaller::ParseConfig() XI_ERR_BAIL(gCtx->sdlg->Parse(parser)); XI_ERR_BAIL(gCtx->idlg->Parse(parser)); - return OK; - BAIL: + XI_IF_FREE(cfg); return err; } diff --git a/mozilla/xpinstall/wizard/unix/src2/nsXInstaller.h b/mozilla/xpinstall/wizard/unix/src2/nsXInstaller.h index 254e5d69fb8..be835023dd0 100644 --- a/mozilla/xpinstall/wizard/unix/src2/nsXInstaller.h +++ b/mozilla/xpinstall/wizard/unix/src2/nsXInstaller.h @@ -60,7 +60,7 @@ int ErrorHandler(int aErr); void ErrDlgOK(GtkWidget *aWidget, gpointer aData); int IsErrFatal(int aErr); -#define CONFIG_INI "config.ini" +#define CONFIG "config" #if defined(DUMP) #undef DUMP