mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-28 03:18:41 +00:00
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
This commit is contained in:
parent
a2321444a1
commit
3792b5a155
@ -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: "<root>.ini.<locale>\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)
|
||||
{
|
||||
|
@ -28,6 +28,8 @@
|
||||
#include <stdio.h>
|
||||
#include <malloc.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <locale.h>
|
||||
|
||||
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 <root>.ini. If such a file exists we
|
||||
* return this as the name else simply return <root>.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
|
||||
*--------------------------------------------------------------------*/
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user