From 20c3da5d88602dedd91bfe87f2e865d9d4b6d0ff Mon Sep 17 00:00:00 2001 From: "sgehani%netscape.com" Date: Thu, 14 Sep 2000 05:15:46 +0000 Subject: [PATCH] Make linux installer localizable. [nsbeta3+ b=2288; r=dbragg;dveditz] --- xpinstall/wizard/unix/src2/Makefile.in | 3 +- xpinstall/wizard/unix/src2/XIDefines.h | 32 ---- xpinstall/wizard/unix/src2/XIErrors.h | 14 +- xpinstall/wizard/unix/src2/config.ini | 2 +- .../src2/{XIErrors.cpp => installer.prop} | 0 .../wizard/unix/src2/nsComponentsDlg.cpp | 4 +- xpinstall/wizard/unix/src2/nsFTPConn.cpp | 120 +++++++++++--- xpinstall/wizard/unix/src2/nsFTPConn.h | 154 ------------------ xpinstall/wizard/unix/src2/nsInstallDlg.cpp | 18 +- xpinstall/wizard/unix/src2/nsLicenseDlg.cpp | 6 +- xpinstall/wizard/unix/src2/nsSetupTypeDlg.cpp | 22 +-- xpinstall/wizard/unix/src2/nsWelcomeDlg.cpp | 6 +- xpinstall/wizard/unix/src2/nsXIContext.cpp | 146 +++++++++++++++++ xpinstall/wizard/unix/src2/nsXIContext.h | 18 ++ xpinstall/wizard/unix/src2/nsXInstaller.cpp | 73 ++++++++- xpinstall/wizard/unix/src2/nsXInstaller.h | 4 +- 16 files changed, 370 insertions(+), 252 deletions(-) rename xpinstall/wizard/unix/src2/{XIErrors.cpp => installer.prop} (100%) diff --git a/xpinstall/wizard/unix/src2/Makefile.in b/xpinstall/wizard/unix/src2/Makefile.in index 8d183105813..c99c3503fb3 100644 --- a/xpinstall/wizard/unix/src2/Makefile.in +++ b/xpinstall/wizard/unix/src2/Makefile.in @@ -31,7 +31,7 @@ include $(DEPTH)/config/autoconf.mk PROGRAM = mozilla-installer-bin CPPSRCS = \ - XIErrors.cpp \ + nsINIParser.cpp \ nsFTPConn.cpp \ nsXInstallerDlg.cpp \ nsComponent.cpp \ @@ -48,7 +48,6 @@ CPPSRCS = \ nsXIContext.cpp \ nsXInstaller.cpp \ nsXIEngine.cpp \ - nsINIParser.cpp \ $(NULL) LIBS = \ diff --git a/xpinstall/wizard/unix/src2/XIDefines.h b/xpinstall/wizard/unix/src2/XIDefines.h index 992c69fd106..792acaece70 100644 --- a/xpinstall/wizard/unix/src2/XIDefines.h +++ b/xpinstall/wizard/unix/src2/XIDefines.h @@ -28,38 +28,6 @@ #include "XIErrors.h" #include -/*--------------------------------------------------------------------* - * Default Strings - *--------------------------------------------------------------------*/ -#define NEXT "Next >" -#define BACK "< Back" -#define CANCEL "Cancel" -#define ACCEPT "Accept" -#define DECLINE "Decline" -#define INSTALL "Install" -#define DEFAULT_TITLE "Mozilla Installer" -#define DEST_DIR "Destination Directory" -#define BROWSE "Change..." -#define SELECT_DIR "Select a directory" -#define DOESNT_EXIST "Directory %s doesn't exist. Create it?\n" -#define YES_LABEL "Yes" -#define NO_LABEL "No" -#define OK_LABEL "OK" -#define DELETE_LABEL "Delete" -#define CANCEL_LABEL "Cancel" -#define ERROR "Error [%d]: %s\n" -#define FATAL_ERROR "Fatal error [%d]: %s\n" -#define WARNING "Warning [%d]: %s\n" -#define DESCRIPTION "Description" -#define DOWNLOADING "Downloading %s [%d/%d]" -#define DLRATE " at %d K/sec..." -#define PREPARING "Preparing %s..." -#define EXTRACTING "Extracting %s..." -#define INSTALLING_XPI "Installing %s..." -#define PROCESSING_FILE "Processing file %d of %d..." -#define EXTRACTING_FILES "Extracting files..." -#define COMPLETED "Installation has completed." - /*--------------------------------------------------------------------* * Limits diff --git a/xpinstall/wizard/unix/src2/XIErrors.h b/xpinstall/wizard/unix/src2/XIErrors.h index ae13823df0a..a1d312cb4a3 100644 --- a/xpinstall/wizard/unix/src2/XIErrors.h +++ b/xpinstall/wizard/unix/src2/XIErrors.h @@ -57,18 +57,12 @@ E_FORK_FAILED = -617, /* failed to fork a process */ E_LIB_OPEN = -618, /* couldn't open stub lib */ E_LIB_SYM = -619, /* couldn't get symbol in lib */ - E_XPI_FAIL = -420, /* a xpistub call failed */ - E_INSTALL = -421, /* a .xpi failed to install */ + E_XPI_FAIL = -620, /* a xpistub call failed */ + E_INSTALL = -621, /* a .xpi failed to install */ E_CP_FAIL = -622, /* copy of a xpi failed */ E_NO_DEST = -623, /* destination dir doesn't exist */ - E_MKDIR_FAIL = -424, /* can't make destination dir */ - E_OLD_INST = -425 /* old instllation exists */ + E_MKDIR_FAIL = -624, /* can't make destination dir */ + E_OLD_INST = -625 /* old instllation exists */ }; -#define FATAL_ERR_THRESHOLD -500 /* errs below this cause app quit */ -#define GENERAL_ERR_THRESHOLD -1 /* errs below this cause dlg to come up*/ - -int ErrorHandler(int aErr); -void ErrDlgOK(GtkWidget *aWidget, gpointer aData); - #endif /* _XI_ERRORS_H_ */ diff --git a/xpinstall/wizard/unix/src2/config.ini b/xpinstall/wizard/unix/src2/config.ini index 788de1be9e6..09037cd7829 100644 --- a/xpinstall/wizard/unix/src2/config.ini +++ b/xpinstall/wizard/unix/src2/config.ini @@ -10,7 +10,7 @@ Title=Le Mozilla Installer ;------------------------------------------------------------------------- Show Dialog=TRUE Title=Mozilla Installer -Readme File=README +Readme File= ;------------------------------------------------------------------------- diff --git a/xpinstall/wizard/unix/src2/XIErrors.cpp b/xpinstall/wizard/unix/src2/installer.prop similarity index 100% rename from xpinstall/wizard/unix/src2/XIErrors.cpp rename to xpinstall/wizard/unix/src2/installer.prop diff --git a/xpinstall/wizard/unix/src2/nsComponentsDlg.cpp b/xpinstall/wizard/unix/src2/nsComponentsDlg.cpp index 511cd0a433e..9639c855cdd 100644 --- a/xpinstall/wizard/unix/src2/nsComponentsDlg.cpp +++ b/xpinstall/wizard/unix/src2/nsComponentsDlg.cpp @@ -357,7 +357,7 @@ nsComponentsDlg::Show(int aDirection) static_cast(GTK_EXPAND | GTK_FILL), static_cast(GTK_EXPAND | GTK_FILL), 20, 20); - frame = gtk_frame_new(DESCRIPTION); + frame = gtk_frame_new(gCtx->Res("DESCRIPTION")); gtk_table_attach_defaults(GTK_TABLE(descLongTable), frame, 0, 1, 0, 1); gtk_widget_show(frame); @@ -390,7 +390,7 @@ nsComponentsDlg::Show(int aDirection) if (aDirection == nsXInstallerDlg::BACKWARD_MOVE) // from install dlg { gtk_container_remove(GTK_CONTAINER(gCtx->next), gCtx->installLabel); - gCtx->nextLabel = gtk_label_new(NEXT); + gCtx->nextLabel = gtk_label_new(gCtx->Res("NEXT")); gtk_container_add(GTK_CONTAINER(gCtx->next), gCtx->nextLabel); gtk_widget_show(gCtx->nextLabel); gtk_widget_show(gCtx->next); diff --git a/xpinstall/wizard/unix/src2/nsFTPConn.cpp b/xpinstall/wizard/unix/src2/nsFTPConn.cpp index cca70a5d799..30fc94de709 100644 --- a/xpinstall/wizard/unix/src2/nsFTPConn.cpp +++ b/xpinstall/wizard/unix/src2/nsFTPConn.cpp @@ -41,7 +41,8 @@ nsFTPConn::nsFTPConn(char *aHost) : mState(CLOSED), mCntlFd(-1), mDataFd(-1), - mEOFFound(FALSE) + mEOFFound(FALSE), + mPassive(FALSE) { } @@ -109,8 +110,6 @@ nsFTPConn::Get(char *aSrvPath, char *aLoclPath, int aType, int aOvWrite, int err = OK, connfd = 0, wrote = 0, totBytesRd = 0; char cmd[CMD_BUF_SIZE], resp[RESP_BUF_SIZE]; int fileSize = 0, respBufSize = RESP_BUF_SIZE; - socklen_t clilen; - struct sockaddr cliaddr; FILE *loclfd = NULL; if (!aSrvPath || !aLoclPath) @@ -125,9 +124,8 @@ nsFTPConn::Get(char *aSrvPath, char *aLoclPath, int aType, int aOvWrite, mState = GETTING; - // XXX rename to RawDataInit() /* initialize data connection */ - ERR_CHECK(RawListen(mHost, DATA_PORT, &mDataFd)); + ERR_CHECK(RawDataInit(mHost, DATA_PORT, &mDataFd)); /* issue SIZE command on control connection */ sprintf(cmd, "SIZE %s\r\n", aSrvPath); @@ -143,15 +141,8 @@ nsFTPConn::Get(char *aSrvPath, char *aLoclPath, int aType, int aOvWrite, sprintf(cmd, "RETR %s\r\n", aSrvPath); ERR_CHECK(IssueCmd(cmd, resp, RESP_BUF_SIZE, mCntlFd)); - // XXX move this to RawDataConnect() /* get file contents on data connection */ - clilen = sizeof(cliaddr); - connfd = accept(mDataFd, (struct sockaddr *) &cliaddr, &clilen); - if (connfd < 0) - { - err = E_ACCEPT; - goto BAIL; - } + ERR_CHECK(RawDataConnect(mDataFd, &connfd)); /* initialize locl file */ if (!(loclfd = fopen(aLoclPath, aType==BINARY ? "wb" : "w")) || @@ -193,7 +184,8 @@ BAIL: /* kill data connection if it exists */ if (mDataFd > 0) { - RawClose(mDataFd); + if (!mPassive) /* for passive mDataFd==connfd so don't close twice! */ + RawClose(mDataFd); mDataFd = -1; } if (connfd > 0) @@ -206,6 +198,7 @@ BAIL: } mState = OPEN; + mPassive = FALSE; return err; } @@ -307,6 +300,9 @@ BAIL: return err; } +/*---------------------------------------------------------------------------* + * "Raw" transport primitives (port below here) + *---------------------------------------------------------------------------*/ int nsFTPConn::RawConnect(char *aHost, int aPort, int *aFd) { @@ -346,23 +342,41 @@ nsFTPConn::RawConnect(char *aHost, int aPort, int *aFd) } int -nsFTPConn::RawListen(char *aHost, int aPort, int *aFd) +nsFTPConn::RawDataInit(char *aHost, int aPort, int *aFd) { int err = OK; struct sockaddr_in servaddr; socklen_t salen; int listenfd = 0; char cmd[CMD_BUF_SIZE], resp[RESP_BUF_SIZE]; - + char *srvhost = NULL; + int srvport = 0; + /* param check */ if (!aHost || !aFd) return E_PARAM; - // XXX TODO: handle PASV mode - // XXX * issue PASV command - // XXX * if passive command returns an error use active mode - // XXX * else connect to supplied port + /* issue PASV command */ + sprintf(cmd, "PASV\r\n"); + err = IssueCmd(cmd, resp, RESP_BUF_SIZE, mCntlFd); + if (err != OK) + { + err = OK; + goto ACTIVE; /* failover to active mode */ + } + + mPassive = TRUE; + ERR_CHECK(RawParseAddr(resp, &srvhost, &srvport)); + ERR_CHECK(RawConnect(srvhost, srvport, &mDataFd)); + + if (srvhost) + free(srvhost); + srvhost = NULL; + + return err; + +ACTIVE: /* init data socket making it listen */ listenfd = socket(AF_INET, SOCK_STREAM, 0); @@ -394,6 +408,35 @@ nsFTPConn::RawListen(char *aHost, int aPort, int *aFd) *aFd = listenfd; BAIL: + if (mPassive && err != OK) + mPassive = FALSE; + + return err; +} + +int +nsFTPConn::RawDataConnect(int aDataFd, int *aConnFd) +{ + int err = OK; + struct sockaddr cliaddr; + socklen_t clilen; + int connfd = 0; + + if (!aConnFd) + return E_PARAM; + + if (mPassive) + { + *aConnFd = aDataFd; + return OK; + } + + clilen = sizeof(cliaddr); + connfd = accept(aDataFd, (struct sockaddr *) &cliaddr, &clilen); + if (connfd < 0) + err = E_ACCEPT; + + *aConnFd = connfd; return err; } @@ -541,6 +584,43 @@ nsFTPConn::RawRecv(unsigned char *aBuf, int *aBufSize, int aFd) return err; } +int +nsFTPConn::RawParseAddr(char *aBuf, char **aHost, int *aPort) +{ + int err = OK; + char *c; + int addr[6]; + + /* param check */ + if (!aBuf || !aHost || !aPort) + return E_PARAM; + + c = aBuf + strlen("227 "); /* pass by return code */ + while (!isdigit((int)(*c))) + { + if (*c == '\0') + return E_INVALID_ADDR; + c++; + } + + if (sscanf(c, "%d,%d,%d,%d,%d,%d", + &addr[0], &addr[1], &addr[2], &addr[3], &addr[4], &addr[5]) != 6) + return E_INVALID_ADDR; + + *aHost = (char *)malloc(strlen("XXX.XXX.XXX.XXX")); + sprintf(*aHost, "%d.%d.%d.%d", addr[0], addr[1], addr[2], addr[3]); + + *aPort = ((addr[4] & 0xFF) << 8) | (addr[5] & 0xFF); + +#ifdef DEBUG + printf("%s %d: PASV response: %d,%d,%d,%d,%d,%d\n", __FILE__, __LINE__, + addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]); + printf("%s %d: Host = %s\tPort = %d\n", __FILE__, __LINE__, *aHost, *aPort); +#endif + + return err; +} + #define KILOBYTE 1024 float nsFTPConn::CalcRate(struct timeval *aPre, struct timeval *aPost, int aBytes) diff --git a/xpinstall/wizard/unix/src2/nsFTPConn.h b/xpinstall/wizard/unix/src2/nsFTPConn.h index cecee95f02d..e69de29bb2d 100644 --- a/xpinstall/wizard/unix/src2/nsFTPConn.h +++ b/xpinstall/wizard/unix/src2/nsFTPConn.h @@ -1,154 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* - * The contents of this file are subject to the Netscape Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is Mozilla Communicator client code, - * released March 31, 1998. - * - * The Initial Developer of the Original Code is Netscape Communications - * Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - * Samir Gehani - */ - -#ifndef _NS_FTPCONN_H_ -#define _NS_FTPCONN_H_ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define CNTL_PORT 21 -#define DATA_PORT 20 - -typedef int (*FTPGetCB)(int aBytesRd, int aTotal); - -class nsFTPConn -{ -public: - nsFTPConn(char *aHost); - ~nsFTPConn(); - - /* ftp type */ - enum - { - ASCII = 0, - BINARY - }; - - /* connection state */ - enum - { - OPEN = 0, - GETTING, - CLOSED - }; - - int Open(); - int Open(char *aHost); - int Get(char *aSrvPath, char *aLoclPath, int aType, int aOvWrite, - FTPGetCB aCBFunc); - int Close(); - - static float - CalcRate(struct timeval *aPre, struct timeval *aPost, int aBytes); - -/*--------------------------------------------------------------------* - * Errors - *--------------------------------------------------------------------*/ - enum - { - OK = 0, - E_MEM = -801, /* out of memory */ - E_PARAM = -802, /* parameter null or incorrect */ - E_ALREADY_OPEN = -803, /* connection already established */ - E_NOT_OPEN = -804, /* connection not established, can't use */ - E_SOCK_OPEN = -805, /* socket already open */ - E_SOCK_CLOSE = -806, /* socket closed, can't use */ - E_CMD_ERR = -807, /* ftp command error */ - E_CMD_FAIL = -808, /* ftp command failed */ - E_CMD_UNEXPECTED = -809, /* ftp command unexpected response */ - E_WRITE = -810, /* write to socket/fd failed */ - E_READ = -811, /* read on socket/fd failed */ - E_SMALL_BUF = -812, /* buffer too small, provide bigger one */ - E_INVALID_HOST = -813, /* failed to resolve hostname */ - E_CANT_OVWRITE = -814, /* cannot overwrite existing file */ - E_BIND = -815, /* bind() failed during cxn init */ - E_LISTEN = -816, /* listen() failed during cxn init */ - E_ACCEPT = -817, /* accept() failed */ - E_GETSOCKNAME = -818, /* getsockname() failed */ - E_READ_MORE = 819, /* more to read from this socket */ - E_LOCL_INIT = -820, /* local file open/init failed */ - E_TIMEOUT = -821 /* select() timed out */ - }; - -private: - int IssueCmd(char *aCmd, char *aResp, int aRespSize, int aFd); - -/*--------------------------------------------------------------------* - * Platform-specific Impls - *--------------------------------------------------------------------*/ - int RawConnect(char *aHost, int aPort, int *aFd); /* cli init */ - int RawListen(char *aHost, int aPort, int *aFd); /* srv init */ - int RawClose(int aFd); - int RawSend(unsigned char *aBuf, int *aBufSize, int aFd); - int RawRecv(unsigned char *aBuf, int *aBufSize, int aFd); - - char *mHost; - int mState; - int mCntlFd; - int mDataFd; - int mEOFFound; -}; - -#ifndef NULL -#define NULL (void*)0L -#endif - -#ifndef TRUE -#define TRUE 1 -#endif - -#ifndef FALSE -#define FALSE 0 -#endif - -#ifndef DUMP -#ifdef DEBUG -#define DUMP(_msg) printf("%s %d: %s\n", __FILE__, __LINE__, _msg); -#else -#define DUMP(_msg) -#endif /* DEBUG */ -#endif /* DUMP */ - -#ifndef ERR_CHECK -#define ERR_CHECK(_func) \ -do { \ - err = _func; \ - if (err != OK) \ - goto BAIL; \ -} while(0); - -#endif - -#endif /* _NS_FTPCONN_H_ */ - diff --git a/xpinstall/wizard/unix/src2/nsInstallDlg.cpp b/xpinstall/wizard/unix/src2/nsInstallDlg.cpp index 67abea0faf6..32c19d40620 100644 --- a/xpinstall/wizard/unix/src2/nsInstallDlg.cpp +++ b/xpinstall/wizard/unix/src2/nsInstallDlg.cpp @@ -250,7 +250,7 @@ nsInstallDlg::Show(int aDirection) // always change title of next button to "Install" gtk_container_remove(GTK_CONTAINER(gCtx->next), gCtx->nextLabel); - gCtx->installLabel = gtk_label_new(INSTALL); + gCtx->installLabel = gtk_label_new(gCtx->Res("INSTALL")); gtk_container_add(GTK_CONTAINER(gCtx->next), gCtx->installLabel); gtk_widget_show(gCtx->installLabel); gtk_widget_show(gCtx->next); @@ -359,7 +359,7 @@ nsInstallDlg::XPIProgressCB(const char *aMsg, int aVal, int aMax) gtk_progress_bar_update(GTK_PROGRESS_BAR(sMinorProgBar), percent); gtk_widget_show(sMinorProgBar); - sprintf(msg, PROCESSING_FILE, aVal, aMax); + sprintf(msg, gCtx->Res("PROCESSING_FILE"), aVal, aMax); } else { @@ -413,15 +413,15 @@ nsInstallDlg::MajorProgressCB(char *aName, int aNum, int aTotal, int aActivity) { case ACT_DOWNLOAD: if (!bDownload) - sprintf(msg, PREPARING, aName); + sprintf(msg, gCtx->Res("PREPARING"), aName); break; case ACT_EXTRACT: - sprintf(msg, EXTRACTING, aName); + sprintf(msg, gCtx->Res("EXTRACTING"), aName); break; case ACT_INSTALL: - sprintf(msg, INSTALLING_XPI, aName); + sprintf(msg, gCtx->Res("INSTALLING_XPI"), aName); break; default: @@ -460,7 +460,7 @@ nsInstallDlg::SetDownloadComp(char *aName, int aNum, int aTotal) char label[64]; // major label format e.g., "Downloading Navigator [4/12] at 635 K/sec..." - sprintf(label, DOWNLOADING, aName, aNum, aTotal); + sprintf(label, gCtx->Res("DOWNLOADING"), aName, aNum, aTotal); gtk_label_set_text(GTK_LABEL(sMajorLabel), label); gettimeofday(&sDLStartTime, NULL); @@ -486,7 +486,7 @@ nsInstallDlg::DownloadCB(int aBytesRd, int aTotal) percent = (gfloat)aBytesRd/(gfloat)aTotal; // only update rate in major label line - sprintf(label, DLRATE, rate); + sprintf(label, gCtx->Res("DLRATE"), rate); gtk_label_set_text(GTK_LABEL(sRateLabel), label); gtk_progress_bar_update(GTK_PROGRESS_BAR(sMajorProgBar), percent); @@ -510,8 +510,8 @@ nsInstallDlg::ShowCompleteDlg() // throw up completion notification completeDlg = gtk_dialog_new(); - label = gtk_label_new(COMPLETED); - okButton = gtk_button_new_with_label(OK_LABEL); + label = gtk_label_new(gCtx->Res("COMPLETED")); + okButton = gtk_button_new_with_label(gCtx->Res("OK_LABEL")); packer = gtk_packer_new(); gtk_packer_set_default_border_width(GTK_PACKER(packer), 20); diff --git a/xpinstall/wizard/unix/src2/nsLicenseDlg.cpp b/xpinstall/wizard/unix/src2/nsLicenseDlg.cpp index 0e6c2cd7efb..be026b2149a 100644 --- a/xpinstall/wizard/unix/src2/nsLicenseDlg.cpp +++ b/xpinstall/wizard/unix/src2/nsLicenseDlg.cpp @@ -148,7 +148,7 @@ nsLicenseDlg::Show(int aDirection) licenseContents = GetLicenseContents(); if (!licenseContents) { - err = E_EMPTY_LICENSE; + err = ErrorHandler(E_EMPTY_LICENSE); goto BAIL; } @@ -196,8 +196,8 @@ nsLicenseDlg::Show(int aDirection) // always change the button titles to Accept/Decline gtk_container_remove(GTK_CONTAINER(gCtx->next), gCtx->nextLabel); gtk_container_remove(GTK_CONTAINER(gCtx->back), gCtx->backLabel); - gCtx->acceptLabel = gtk_label_new(ACCEPT); - gCtx->declineLabel = gtk_label_new(DECLINE); + gCtx->acceptLabel = gtk_label_new(gCtx->Res("ACCEPT")); + gCtx->declineLabel = gtk_label_new(gCtx->Res("DECLINE")); gtk_container_add(GTK_CONTAINER(gCtx->next), gCtx->acceptLabel); gtk_container_add(GTK_CONTAINER(gCtx->back), gCtx->declineLabel); gtk_widget_show(gCtx->acceptLabel); diff --git a/xpinstall/wizard/unix/src2/nsSetupTypeDlg.cpp b/xpinstall/wizard/unix/src2/nsSetupTypeDlg.cpp index d707477780b..5f73f6115dc 100644 --- a/xpinstall/wizard/unix/src2/nsSetupTypeDlg.cpp +++ b/xpinstall/wizard/unix/src2/nsSetupTypeDlg.cpp @@ -394,7 +394,7 @@ nsSetupTypeDlg::Show(int aDirection) static_cast(GTK_EXPAND | GTK_FILL), static_cast(GTK_EXPAND | GTK_FILL), 20, 20); - frame = gtk_frame_new(DEST_DIR); + frame = gtk_frame_new(gCtx->Res("DEST_DIR")); gtk_table_attach_defaults(GTK_TABLE(destTable), frame, 0, 2, 0, 1); gtk_widget_show(frame); @@ -408,7 +408,7 @@ nsSetupTypeDlg::Show(int aDirection) gtk_widget_show(sFolder); gtk_table_attach_defaults(GTK_TABLE(destTable), sFolder, 0, 1, 0, 1); - sBrowseBtn = gtk_button_new_with_label(BROWSE); + sBrowseBtn = gtk_button_new_with_label(gCtx->Res("BROWSE")); gtk_widget_show(sBrowseBtn); gtk_table_attach(GTK_TABLE(destTable), sBrowseBtn, 1, 2, 0, 1, static_cast(GTK_EXPAND | GTK_FILL), @@ -436,8 +436,8 @@ nsSetupTypeDlg::Show(int aDirection) // change the button titles back to Back/Next gtk_container_remove(GTK_CONTAINER(gCtx->next), gCtx->acceptLabel); gtk_container_remove(GTK_CONTAINER(gCtx->back), gCtx->declineLabel); - gCtx->nextLabel = gtk_label_new(NEXT); - gCtx->backLabel = gtk_label_new(BACK); + gCtx->nextLabel = gtk_label_new(gCtx->Res("NEXT")); + gCtx->backLabel = gtk_label_new(gCtx->Res("BACK")); gtk_widget_show(gCtx->nextLabel); gtk_widget_show(gCtx->backLabel); gtk_container_add(GTK_CONTAINER(gCtx->next), gCtx->nextLabel); @@ -452,7 +452,7 @@ nsSetupTypeDlg::Show(int aDirection) { DUMP("Back from Install to Setup Type"); gtk_container_remove(GTK_CONTAINER(gCtx->next), gCtx->installLabel); - gCtx->nextLabel = gtk_label_new(NEXT); + gCtx->nextLabel = gtk_label_new(gCtx->Res("NEXT")); gtk_container_add(GTK_CONTAINER(gCtx->next), gCtx->nextLabel); gtk_widget_show(gCtx->nextLabel); gtk_widget_show(gCtx->next); @@ -615,7 +615,7 @@ nsSetupTypeDlg::SelectFolder(GtkWidget *aWidget, gpointer aData) GtkWidget *fileSel = NULL; char *selDir = gCtx->opt->mDestination; - fileSel = gtk_file_selection_new(SELECT_DIR); + fileSel = gtk_file_selection_new(gCtx->Res("SELECT_DIR")); gtk_file_selection_set_filename(GTK_FILE_SELECTION(fileSel), selDir); gtk_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(fileSel)->ok_button), "clicked", (GtkSignalFunc) SelectFolderOK, fileSel); @@ -682,12 +682,12 @@ nsSetupTypeDlg::VerifyDestination() return OK; // destination doesn't exist so ask user if we should create it - sprintf(message, DOESNT_EXIST, gCtx->opt->mDestination); + sprintf(message, gCtx->Res("DOESNT_EXIST"), gCtx->opt->mDestination); sCreateDestDlg = gtk_dialog_new(); label = gtk_label_new(message); - yesButton = gtk_button_new_with_label(YES_LABEL); - noButton = gtk_button_new_with_label(NO_LABEL); + yesButton = gtk_button_new_with_label(gCtx->Res("YES_LABEL")); + noButton = gtk_button_new_with_label(gCtx->Res("NO_LABEL")); gtk_container_add(GTK_CONTAINER(GTK_DIALOG(sCreateDestDlg)->action_area), yesButton); @@ -772,8 +772,8 @@ nsSetupTypeDlg::DeleteOldInst() // throw up delete dialog sDelInstDlg = gtk_dialog_new(); - deleteBtn = gtk_button_new_with_label(DELETE_LABEL); - cancelBtn = gtk_button_new_with_label(CANCEL_LABEL); + deleteBtn = gtk_button_new_with_label(gCtx->Res("DELETE_LABEL")); + cancelBtn = gtk_button_new_with_label(gCtx->Res("CANCEL_LABEL")); gtk_container_add(GTK_CONTAINER(GTK_DIALOG(sDelInstDlg)->action_area), deleteBtn); diff --git a/xpinstall/wizard/unix/src2/nsWelcomeDlg.cpp b/xpinstall/wizard/unix/src2/nsWelcomeDlg.cpp index 57bb687ccc3..f8d668ddaaf 100644 --- a/xpinstall/wizard/unix/src2/nsWelcomeDlg.cpp +++ b/xpinstall/wizard/unix/src2/nsWelcomeDlg.cpp @@ -133,7 +133,7 @@ nsWelcomeDlg::Show(int aDirection) readmeContents = GetReadmeContents(); if (!readmeContents) { - err = E_EMPTY_README; + err = ErrorHandler(E_EMPTY_README); goto BAIL; } @@ -181,8 +181,8 @@ nsWelcomeDlg::Show(int aDirection) // change the button titles back to Back/Next gtk_container_remove(GTK_CONTAINER(gCtx->next), gCtx->acceptLabel); gtk_container_remove(GTK_CONTAINER(gCtx->back), gCtx->declineLabel); - gCtx->nextLabel = gtk_label_new(NEXT); - gCtx->backLabel = gtk_label_new(BACK); + gCtx->nextLabel = gtk_label_new(gCtx->Res("NEXT")); + gCtx->backLabel = gtk_label_new(gCtx->Res("BACK")); gtk_container_add(GTK_CONTAINER(gCtx->next), gCtx->nextLabel); gtk_container_add(GTK_CONTAINER(gCtx->back), gCtx->backLabel); gtk_widget_show(gCtx->nextLabel); diff --git a/xpinstall/wizard/unix/src2/nsXIContext.cpp b/xpinstall/wizard/unix/src2/nsXIContext.cpp index 9186a8b2673..7843fa9a9e6 100644 --- a/xpinstall/wizard/unix/src2/nsXIContext.cpp +++ b/xpinstall/wizard/unix/src2/nsXIContext.cpp @@ -24,6 +24,8 @@ #include "nsXIContext.h" +#define __EOT__ "EndOfTable" + nsXIContext::nsXIContext() { me = NULL; @@ -53,12 +55,16 @@ nsXIContext::nsXIContext() nextID = 0; bMoving = FALSE; bDone = FALSE; + + reslist = NULL; } nsXIContext::~nsXIContext() { // NOTE: don't try to delete "me" cause I control thee + ReleaseResources(); + XI_IF_DELETE(ldlg); XI_IF_DELETE(wdlg); XI_IF_DELETE(sdlg); @@ -109,3 +115,143 @@ nsXIContext::itoa(int n) return s; } + +#define MAX_KEY_SIZE 64 +#define FIRST_ERR -601 +#define LAST_ERR -625 +int +nsXIContext::LoadResources() +{ + int err = OK; + nsINIParser *parser = new nsINIParser(RES_FILE); + kvpair *currkv = NULL; + char currkey[MAX_KEY_SIZE]; + int len, i; + + if (!parser) + return E_MEM; + + char *strkeys[] = + { + "NEXT", + "BACK", + "CANCEL", + "ACCEPT", + "DECLINE", + "INSTALL", + "DEFAULT_TITLE", + "DEST_DIR", + "BROWSE", + "SELECT_DIR", + "DOESNT_EXIST", + "YES_LABEL", + "NO_LABEL", + "OK_LABEL", + "DELETE_LABEL", + "CANCEL_LABEL", + "ERROR", + "FATAL_ERROR", + "DESCRIPTION", + "DOWNLOADING", + "DLRATE", + "PREPARING", + "EXTRACTING", + "INSTALLING_XPI", + "PROCESSING_FILE", + "COMPLETED", + + __EOT__ + }; + + /* read in UI strings */ + currkv = (kvpair *) malloc(sizeof(kvpair)); + reslist = currkv; + for (i = 0; strcmp(strkeys[i], __EOT__) != 0; i++) + { + err = parser->GetStringAlloc(RES_SECT, strkeys[i], + &(currkv->val), &len); + if (err != OK) + goto BAIL; + + currkv->key = strdup(strkeys[i]); + currkv->next = (kvpair *) malloc(sizeof(kvpair)); + currkv = currkv->next; + + if (i > 1024) /* inf loop prevention paranoia */ + break; + } + currkv->next = NULL; /* seal off list */ + + /* read in err strings */ + for (i = FIRST_ERR; i >= LAST_ERR; i--) + { + sprintf(currkey, "%d", i); + err = parser->GetStringAlloc(RES_SECT, currkey, &(currkv->val), &len); + if (err != OK) + goto BAIL; + + currkv->key = strdup(currkey); + if (i == LAST_ERR) + break; + currkv->next = (kvpair *) malloc(sizeof(kvpair)); + currkv = currkv->next; + } + currkv->next = NULL; /* seal off list */ + +BAIL: + if (err != OK) + { + fprintf(stderr, "FATAL ERROR: Failed to load resources!"); + } + XI_IF_DELETE(parser); + return err; +} + +int +nsXIContext::ReleaseResources() +{ + int err = OK; + kvpair *currkv = NULL, *delkv = NULL; + + /* empty list -- should never really happen */ + if (!reslist) + return E_PARAM; + + currkv = reslist; + while (currkv) + { + XI_IF_FREE(currkv->key); + XI_IF_FREE(currkv->val); + delkv = currkv; + currkv = currkv->next; + XI_IF_FREE(delkv); + } + + return err; +} + +char * +nsXIContext::Res(char *aKey) +{ + char *val = NULL; + kvpair *currkv = NULL; + + /* param check */ + if (!aKey || !reslist) + return NULL; + + /* search through linked list */ + currkv = reslist; + while (currkv) + { + if (strcmp(aKey, currkv->key) == 0) + { + val = currkv->val; + break; + } + currkv = currkv->next; + } + + return val; +} + diff --git a/xpinstall/wizard/unix/src2/nsXIContext.h b/xpinstall/wizard/unix/src2/nsXIContext.h index 55cbc7d35c7..c3dcca18852 100644 --- a/xpinstall/wizard/unix/src2/nsXIContext.h +++ b/xpinstall/wizard/unix/src2/nsXIContext.h @@ -31,9 +31,21 @@ #include "nsComponentsDlg.h" #include "nsInstallDlg.h" #include "nsXIOptions.h" +#include "nsINIParser.h" + +#define RES_FILE "installer.prop" +#define RES_SECT "String Resources" class nsXInstaller; +typedef struct _kvpair +{ + char *key; + char *val; + + struct _kvpair *next; +} kvpair; + class nsXIContext { public: @@ -81,6 +93,12 @@ public: * Utilities *-------------------------------------------------------------------*/ char *itoa(int n); + int LoadResources(); /* load string resources */ + int ReleaseResources(); /* release alloc'd resource strings */ + char *Res(char *aKey); /* get string resource for key; NULL==err */ + +private: + kvpair *reslist; /* string resource linked list */ }; #endif /* _NS_XICONTEXT_H_ */ diff --git a/xpinstall/wizard/unix/src2/nsXInstaller.cpp b/xpinstall/wizard/unix/src2/nsXInstaller.cpp index 660311424af..ca8c66851ae 100644 --- a/xpinstall/wizard/unix/src2/nsXInstaller.cpp +++ b/xpinstall/wizard/unix/src2/nsXInstaller.cpp @@ -46,6 +46,9 @@ nsXInstaller::ParseConfig() nsINIParser *parser = NULL; XI_ERR_BAIL(InitContext()); + err = gCtx->LoadResources(); + if (err != OK) + return err; parser = new nsINIParser( CONFIG_INI ); if (!parser) @@ -126,7 +129,8 @@ nsXInstaller::RunWizard(int argc, char **argv) if (mTitle) gtk_window_set_title(GTK_WINDOW(gCtx->window), mTitle); else - gtk_window_set_title(GTK_WINDOW(gCtx->window), DEFAULT_TITLE); + gtk_window_set_title(GTK_WINDOW(gCtx->window), + gCtx->Res("DEFAULT_TITLE")); gtk_widget_show(gCtx->window); // create and display the logo and cancel button @@ -209,7 +213,7 @@ nsXInstaller::DrawCancelButton(GtkWidget *aLogoVBox) int err = OK; GtkWidget *hbox; - gCtx->cancel = gtk_button_new_with_label(CANCEL); + gCtx->cancel = gtk_button_new_with_label(gCtx->Res("CANCEL")); hbox = gtk_hbox_new(FALSE, 10); gtk_box_pack_start(GTK_BOX(hbox), gCtx->cancel, TRUE, TRUE, 15); gtk_box_pack_end(GTK_BOX(aLogoVBox), hbox, FALSE, TRUE, 10); @@ -234,8 +238,8 @@ nsXInstaller::DrawNavButtons() gCtx->next = gtk_button_new(); gCtx->back = gtk_button_new(); - gCtx->nextLabel = gtk_label_new(NEXT); - gCtx->backLabel = gtk_label_new(BACK); + gCtx->nextLabel = gtk_label_new(gCtx->Res("NEXT")); + gCtx->backLabel = gtk_label_new(gCtx->Res("BACK")); XI_VERIFY(gCtx->next); XI_VERIFY(gCtx->back); gtk_widget_show(gCtx->next); @@ -326,3 +330,64 @@ main(int argc, char **argv) _exit(err); } +/*------------------------------------------------------------------* + * Default Error Handler + *------------------------------------------------------------------*/ +int +ErrorHandler(int aErr) +{ + GtkWidget *okButton, *label, *dialog; + char msg[256]; + char errStr[16]; + + sprintf(errStr, "%d", aErr); + if (!IsErrFatal(aErr)) + sprintf(msg, gCtx->Res("ERROR"), aErr, gCtx->Res(errStr)); + else + sprintf(msg, gCtx->Res("FATAL_ERROR"), aErr, gCtx->Res(errStr)); + + dialog = gtk_dialog_new(); + okButton = gtk_button_new_with_label(gCtx->Res("OK_LABEL")); + label = gtk_label_new(msg); + + gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->action_area), + okButton); + gtk_signal_connect(GTK_OBJECT(okButton), "clicked", + GTK_SIGNAL_FUNC(ErrDlgOK), (void*)aErr); + + gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), label); + + gtk_widget_show_all(dialog); + + return aErr; +} + +void +ErrDlgOK(GtkWidget *aWidget, gpointer aData) +{ + int err = (int) aData; + + gtk_widget_destroy(aWidget); + if (IsErrFatal(err)) + exit(err); +} + +int +IsErrFatal(int aErr) +{ + int bFatal = TRUE; + + /* non-fatal errors */ + switch (aErr) + { + case -620: + case -621: + case -624: + case -625: + bFatal = FALSE; + default: + break; + } + + return bFatal; +} diff --git a/xpinstall/wizard/unix/src2/nsXInstaller.h b/xpinstall/wizard/unix/src2/nsXInstaller.h index 56063b11ace..254e5d69fb8 100644 --- a/xpinstall/wizard/unix/src2/nsXInstaller.h +++ b/xpinstall/wizard/unix/src2/nsXInstaller.h @@ -56,7 +56,9 @@ private: }; int main(int argc, char **argv); - +int ErrorHandler(int aErr); +void ErrDlgOK(GtkWidget *aWidget, gpointer aData); +int IsErrFatal(int aErr); #define CONFIG_INI "config.ini"