From 1082968752ae1cb1ca7388b5465ba8d7f1f4e5a4 Mon Sep 17 00:00:00 2001 From: "sgehani%netscape.com" Date: Fri, 8 Oct 1999 09:00:13 +0000 Subject: [PATCH] Failover implemented for i18n strings in XPInstall if the string bundle service is not available, fails, or if the .properties resource file is not avilable. Fixes install wizard logging. Completion of fix for bug 8140. [r=ssu] --- xpinstall/src/nsInstall.cpp | 26 ++++++++++-- xpinstall/src/nsInstallResources.cpp | 61 +++++++++++----------------- xpinstall/src/nsInstallResources.h | 51 +++++++++++++++++++---- xpinstall/src/nsXPInstallManager.cpp | 34 ++++++++++++---- 4 files changed, 115 insertions(+), 57 deletions(-) diff --git a/xpinstall/src/nsInstall.cpp b/xpinstall/src/nsInstall.cpp index 23aac5c5086..2e8816061ca 100644 --- a/xpinstall/src/nsInstall.cpp +++ b/xpinstall/src/nsInstall.cpp @@ -53,6 +53,7 @@ #include "nsInstallExecute.h" #include "nsInstallPatch.h" #include "nsInstallUninstall.h" +#include "nsInstallResources.h" #ifdef NECKO #include "nsNeckoUtil.h" #endif @@ -2239,8 +2240,10 @@ nsInstall::ExtractFileFromJar(const nsString& aJarfile, nsFileSpec* aSuggestedNa if ( nsAppleSingleDecoder::IsAppleSingleFile(&extractedSpec) ) { nsAppleSingleDecoder *asd = new nsAppleSingleDecoder(&extractedSpec, &finalSpec); - - OSErr decodeErr = asd->Decode(); + OSErr decodeErr = fnfErr; + + if (asd) + decodeErr = asd->Decode(); if (decodeErr != noErr) { @@ -2287,6 +2290,7 @@ char* nsInstall::GetResourcedString(const nsString& aResName) { nsString rscdStr = ""; + PRBool bStrBdlSuccess = PR_FALSE; if (mStringBundle) { @@ -2294,9 +2298,25 @@ nsInstall::GetResourcedString(const nsString& aResName) PRUnichar *ucRscdStr = nsnull; nsresult rv = mStringBundle->GetStringFromName(ucResName, &ucRscdStr); if (NS_SUCCEEDED(rv)) + { + bStrBdlSuccess = PR_TRUE; rscdStr = ucRscdStr; + } } - + + /* + ** We don't have a string bundle, the necessary libs, or something went wrong + ** so we failover to hardcoded english strings so we log something rather + ** than nothing due to failure above: always the case for the Install Wizards. + */ + if (!bStrBdlSuccess) + { + char *cResName = aResName.ToNewCString(); + rscdStr = nsInstallResources::GetDefaultVal(cResName); + if (cResName) + Recycle(cResName); + } + return rscdStr.ToNewCString(); } diff --git a/xpinstall/src/nsInstallResources.cpp b/xpinstall/src/nsInstallResources.cpp index 71f627d0962..27ede9d7e11 100644 --- a/xpinstall/src/nsInstallResources.cpp +++ b/xpinstall/src/nsInstallResources.cpp @@ -21,47 +21,32 @@ * Contributors: * Daniel Veditz * Douglas Turner + * Samir Gehani */ +#include +#include "nscore.h" #include "nsInstallResources.h" -char* nsInstallResources::GetInstallFileString(void) -{ - return "Installing: %s"; -} - -char* nsInstallResources::GetReplaceFileString(void) -{ - return "Replacing %s"; -} - -char* nsInstallResources::GetDeleteFileString(void) -{ - return "Deleting file: %s"; -} - -char* nsInstallResources::GetDeleteComponentString(void) -{ - return "Deleting component: %s"; -} - -char* nsInstallResources::GetExecuteString(void) -{ - return "Executing: %s"; -} - -char* nsInstallResources::GetExecuteWithArgsString(void) -{ - return "Executing: %s with argument: %s"; -} - -char* nsInstallResources::GetPatchFileString(void) -{ - return "Patching: %s"; -} - -char* nsInstallResources::GetUninstallString(void) -{ - return "Uninstalling: %s"; +char* +nsInstallResources::GetDefaultVal(const char* aResName) +{ + char *currResName = XPIResTable[0].resName; + char *currResVal = nsnull; + PRInt32 idx, len = 0; + + for (idx = 0; 0 != strcmp(currResName, NS_XPI_EOT); idx++) + { + currResName = XPIResTable[idx].resName; + len = strlen(currResName); + + if (0 == strncmp(currResName, aResName, len)) + { + currResVal = XPIResTable[idx].defaultString; + break; + } + } + + return currResVal; } diff --git a/xpinstall/src/nsInstallResources.h b/xpinstall/src/nsInstallResources.h index 64dc11ba2ab..7ccf9555fb9 100644 --- a/xpinstall/src/nsInstallResources.h +++ b/xpinstall/src/nsInstallResources.h @@ -21,24 +21,57 @@ * Contributors: * Daniel Veditz * Douglas Turner + * Samir Gehani */ #ifndef __NS_INSTALLRESOURCES_H__ #define __NS_INSTALLRESOURCES_H__ +#define NS_XPI_EOT "___END_OF_TABLE___" + +typedef struct _nsXPIResourceTableItem +{ + char *resName; + char *defaultString; +} nsXPIResourceTableItem; + +static nsXPIResourceTableItem XPIResTable[] = +{ + /*---------------------------------------------------------------------* + * Install Actions + *---------------------------------------------------------------------*/ + { "InstallFile", "Installing: %s" }, + { "ReplaceFile", "Replacing: %s" }, + { "DeleteFile", "Deleting file: %s" }, + { "DeleteComponent", "Deleting component: %s" }, + { "Execute", "Executing: %s" }, + { "ExecuteWithArgs", "Executing: %s with argument: %s" }, + { "Patch", "Patching: %s" }, + { "Uninstall", "Uninstalling: %s" }, + + // XXX FileOp*() action strings + // XXX WinReg and WinProfile action strings + + /*---------------------------------------------------------------------* + * Dialog Messages + *---------------------------------------------------------------------*/ + { "ShouldWeInstallMsg", "Attempting to download and install software. Do you feel lucky punk?" }, + { "FinishingInstallMsg", "Finishing install... please wait." }, + + /*---------------------------------------------------------------------* + * Miscellaneous + *---------------------------------------------------------------------*/ + { "ERROR", "ERROR" }, + + { NS_XPI_EOT, "" } +}; + class nsInstallResources { public: - - static char* GetInstallFileString(void); - static char* GetReplaceFileString(void); - static char* GetDeleteFileString(void); - static char* GetDeleteComponentString(void); - static char* GetExecuteString(void); - static char* GetExecuteWithArgsString(void); - static char* GetPatchFileString(void); - static char* GetUninstallString(void); + + static char* GetDefaultVal(const char* aResName); }; diff --git a/xpinstall/src/nsXPInstallManager.cpp b/xpinstall/src/nsXPInstallManager.cpp index 04bad6ea08e..ab6c0545521 100644 --- a/xpinstall/src/nsXPInstallManager.cpp +++ b/xpinstall/src/nsXPInstallManager.cpp @@ -42,6 +42,7 @@ #include "nsXPITriggerInfo.h" #include "nsXPInstallManager.h" #include "nsInstallProgressDialog.h" +#include "nsInstallResources.h" #include "nsSpecialSystemDirectory.h" #include "nsFileStream.h" #include "nsProxyObjectManager.h" @@ -152,16 +153,35 @@ nsXPInstallManager::InitManager(nsXPITriggerInfo* aTriggers) if ( NS_SUCCEEDED(rv) ) { nsCOMPtr prompt( do_QueryInterface(wbwin, &rv) ); - if ( NS_SUCCEEDED(rv) && prompt && mStringBundle ) + if ( NS_SUCCEEDED(rv) && prompt ) { + PRBool bStrBdlSuccess = PR_FALSE; nsString rsrcName = "ShouldWeInstallMsg"; - const PRUnichar* ucRsrcName = rsrcName.GetUnicode(); - PRUnichar* ucRsrcVal = nsnull; - rv = mStringBundle->GetStringFromName(ucRsrcName, &ucRsrcVal); - if (NS_SUCCEEDED(rv) && ucRsrcVal) + + if (mStringBundle) { - prompt->Confirm( ucRsrcVal, &OKtoInstall); - nsCRT::free(ucRsrcVal); + const PRUnichar* ucRsrcName = rsrcName.GetUnicode(); + PRUnichar* ucRsrcVal = nsnull; + rv = mStringBundle->GetStringFromName(ucRsrcName, &ucRsrcVal); + if (NS_SUCCEEDED(rv) && ucRsrcVal) + { + prompt->Confirm( ucRsrcVal, &OKtoInstall); + nsCRT::free(ucRsrcVal); + bStrBdlSuccess = PR_TRUE; + } + } + + /* failover to default english strings */ + if (!bStrBdlSuccess) + { + char *cResName = rsrcName.ToNewCString(); + nsString resVal = nsInstallResources::GetDefaultVal(cResName); + + if (!resVal.IsEmpty()) + prompt->Confirm( resVal.GetUnicode(), &OKtoInstall ); + + if (cResName) + Recycle(cResName); } } }