(*) Hook in libxpnet's pause/resume support and add a disk space warning.

(*) Also, fix the download location for resumption.
(*) Implement a new and improved download UI with a unified prog bar.

b  = 77980
r  = suu
sr = mscott
This commit is contained in:
sgehani%netscape.com 2001-05-03 02:17:27 +00:00
Родитель 882fe0046f
Коммит f67be14c0f
22 изменённых файлов: 1241 добавлений и 175 удалений

Просмотреть файл

@ -83,7 +83,8 @@
#define Cd "C%d" #define Cd "C%d"
#define ARCHIVE "Archive" #define ARCHIVE "Archive"
#define URLd "URL%d" #define URLd "URL%d"
#define SIZE "Install Size" #define INSTALL_SIZE "Install Size"
#define ARCHIVE_SIZE "Archive Size"
#define DEPENDENCYd "Dependency%d" #define DEPENDENCYd "Dependency%d"
#define DEPENDEEd "Dependee%d" #define DEPENDEEd "Dependee%d"
#define ATTRIBUTES "Attributes" #define ATTRIBUTES "Attributes"

Просмотреть файл

@ -63,7 +63,8 @@
E_NO_DEST = -623, /* destination dir doesn't exist */ E_NO_DEST = -623, /* destination dir doesn't exist */
E_MKDIR_FAIL = -624, /* can't make destination dir */ E_MKDIR_FAIL = -624, /* can't make destination dir */
E_OLD_INST = -625, /* old instllation exists */ E_OLD_INST = -625, /* old instllation exists */
E_NO_PERMS = -626 /* don't have rwx perms on selected dir */ E_NO_PERMS = -626, /* don't have rwx perms on selected dir */
E_NO_DISK_SPACE = -627 /* not eough disk space to install */
}; };
#endif /* _XI_ERRORS_H_ */ #endif /* _XI_ERRORS_H_ */

Просмотреть файл

@ -71,6 +71,7 @@ Description Short=XPInstall Engine
Description Long=Installer technology Description Long=Installer technology
Archive=xpcom.xpi Archive=xpcom.xpi
Install Size=1000 Install Size=1000
Archive Size=837900
Attributes=SELECTED|INVISIBLE Attributes=SELECTED|INVISIBLE
URL0=ftp://127.0.0.1/pub/xpi/ URL0=ftp://127.0.0.1/pub/xpi/
URL1=ftp://orb.mcom.com/pub/xpi/ URL1=ftp://orb.mcom.com/pub/xpi/
@ -80,6 +81,7 @@ Description Short=Navigator
Description Long=Web browser software Description Long=Web browser software
Archive=browser.xpi Archive=browser.xpi
Install Size=2000 Install Size=2000
Archive Size=200
Attributes=SELECTED Attributes=SELECTED
URL0=ftp://127.0.0.1/pub/xpi/ URL0=ftp://127.0.0.1/pub/xpi/
URL1=ftp://orb.mcom.com/pub/xpi/ URL1=ftp://orb.mcom.com/pub/xpi/
@ -91,6 +93,7 @@ Description Short=Mail & News
Description Long=Email and Newsgroup software Description Long=Email and Newsgroup software
Archive=mail.xpi Archive=mail.xpi
Install Size=1500 Install Size=1500
Archive Size=150
Attributes=SELECTED Attributes=SELECTED
URL0=ftp://127.0.0.1/pub/xpi/ URL0=ftp://127.0.0.1/pub/xpi/
URL1=ftp://orb.mcom.com/pub/xpi/ URL1=ftp://orb.mcom.com/pub/xpi/
@ -100,6 +103,7 @@ Description Short=Java
Description Long=Java runtime environment Description Long=Java runtime environment
Archive=java.xpi Archive=java.xpi
Install Size=1500 Install Size=1500
Archive Size=150
Attributes= Attributes=
URL0=ftp://127.0.0.1/pub/xpi/ URL0=ftp://127.0.0.1/pub/xpi/
URL1=ftp://orb.mcom.com/pub/xpi/ URL1=ftp://orb.mcom.com/pub/xpi/
@ -109,6 +113,7 @@ Description Short=Browser-UI
Description Long=Browser User Interface Description Long=Browser User Interface
Archive=browser-ui.xpi Archive=browser-ui.xpi
Install Size=2000 Install Size=2000
Archive Size=200
Attributes= Attributes=
URL0=ftp://127.0.0.1/pub/xpi/ URL0=ftp://127.0.0.1/pub/xpi/
URL1=ftp://orb.mcom.com/pub/xpi/ URL1=ftp://orb.mcom.com/pub/xpi/
@ -127,4 +132,4 @@ XPInstall Engine=xpcom.xpi
[LegacyCheck0] [LegacyCheck0]
;------------------------------------------------------------------------- ;-------------------------------------------------------------------------
Filename=mozilla-bin Filename=mozilla-bin
Message=An older installation of Mozilla was detected. Please choose to delete the directory contents of your current Mozilla installation by hitting the 'Delete' button. Alternatively, please hit the 'Cancel' button and choose a different destination directory. Message=An older installation of Mozilla was detected. Please choose to delete the directory contents of your current Mozilla installation by pressing the 'Delete' button. Alternatively, please press the 'Cancel' button and choose a different destination directory.

Просмотреть файл

@ -11,6 +11,8 @@ CANCEL=Cancel
ACCEPT=Accept ACCEPT=Accept
DECLINE=Decline DECLINE=Decline
INSTALL=Install INSTALL=Install
PAUSE=Pause
RESUME=Resume
DEFAULT_TITLE=Mozilla Installer DEFAULT_TITLE=Mozilla Installer
DEST_DIR=Destination Directory DEST_DIR=Destination Directory
BROWSE=Change... BROWSE=Change...
@ -24,8 +26,6 @@ CANCEL_LABEL=Cancel
ERROR=Error [%d]: %s ERROR=Error [%d]: %s
FATAL_ERROR=Fatal error [%d]: %s FATAL_ERROR=Fatal error [%d]: %s
DESCRIPTION=Description DESCRIPTION=Description
DOWNLOADING=Downloading %s [%d/%d]
DLRATE= at %d K/sec...
PREPARING=Preparing %s... PREPARING=Preparing %s...
EXTRACTING=Extracting %s... EXTRACTING=Extracting %s...
INSTALLING_XPI=Installing %s... INSTALLING_XPI=Installing %s...
@ -40,6 +40,16 @@ PS_LABEL1=Proxy Port [required]:
PS_LABEL2=Proxy Username [optional]: PS_LABEL2=Proxy Username [optional]:
PS_LABEL3=Proxy Password [optional]: PS_LABEL3=Proxy Password [optional]:
ERROR_TITLE=Error! ERROR_TITLE=Error!
DS_AVAIL=Disk Space Available = %ld KB
DS_REQD=Disk Space Required = %ld KB
NO_DISK_SPACE=Please select a directory on a disk with enough space to install or free some disk space on the selected disk.
CXN_DROPPED=A network connection failure occured. Please check your network connection and press the 'Resume' button. Alternatively, press the 'Cancel' button to quit the installer.
DOWNLOADING=Downloading:
FROM=From:
TO=To:
STATUS=Status:
DL_STATUS_STR=%d KB of %d KB (at %d KB/sec)
UNKNOWN=Unknown
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------
; Error strings ; Error strings

Просмотреть файл

@ -45,6 +45,6 @@ export PATH
MOZILLA_FIVE_HOME=. MOZILLA_FIVE_HOME=.
export MOZILLA_FIVE_HOME export MOZILLA_FIVE_HOME
./mozilla-installer-bin --sync ./mozilla-installer-bin --sync $@
rm -rf /tmp/.tmp.xi.* rm -rf /tmp/.tmp.xi.*

Просмотреть файл

@ -23,18 +23,22 @@
*/ */
#include "nsComponent.h" #include "nsComponent.h"
#include <sys/stat.h>
nsComponent::nsComponent() : nsComponent::nsComponent() :
mDescShort(NULL), mDescShort(NULL),
mDescLong(NULL), mDescLong(NULL),
mArchive(NULL), mArchive(NULL),
mSize(0), mInstallSize(0),
mArchiveSize(0),
mNextDependeeIdx(0),
mAttributes(NO_ATTR), mAttributes(NO_ATTR),
mNext(NULL), mNext(NULL),
mIndex(-1), mIndex(-1),
mRefCount(0), mRefCount(0),
mDepRefCount(0), mDepRefCount(0),
mNextDependeeIdx(0) mResPos(0),
mDownloaded(FALSE)
{ {
int i; int i;
@ -129,22 +133,57 @@ nsComponent::GetArchive()
} }
int int
nsComponent::SetSize(int aSize) nsComponent::SetInstallSize(int aInstallSize)
{ {
mSize = aSize; mInstallSize = aInstallSize;
return OK; return OK;
} }
int int
nsComponent::GetSize() nsComponent::GetInstallSize()
{ {
if (mSize >= 0) if (mInstallSize >= 0)
return mSize; return mInstallSize;
return 0; return 0;
} }
int
nsComponent::SetArchiveSize(int aArchiveSize)
{
mArchiveSize = aArchiveSize;
return OK;
}
int
nsComponent::GetArchiveSize()
{
if (mArchiveSize >= 0)
return mArchiveSize;
return 0;
}
int
nsComponent::GetCurrentSize()
{
// assumes cwd is the same as the installer binary location
char path[MAXPATHLEN];
struct stat stbuf;
if (!mArchive)
return 0;
sprintf(path, "./xpi/%s", mArchive);
if (0 != stat(path, &stbuf))
return 0;
return (stbuf.st_size/1024); // return size in KB
}
int int
nsComponent::SetURL(char *aURL, int aIndex) nsComponent::SetURL(char *aURL, int aIndex)
{ {
@ -395,3 +434,34 @@ nsComponent::DepGetRefCount()
{ {
return mDepRefCount; return mDepRefCount;
} }
int
nsComponent::SetResumePos(int aResPos)
{
mResPos = aResPos;
return OK;
}
int
nsComponent::GetResumePos()
{
if (mResPos > 0)
return mResPos;
return 0;
}
int
nsComponent::SetDownloaded()
{
mDownloaded = TRUE;
return OK;
}
int
nsComponent::IsDownloaded()
{
return mDownloaded;
}

Просмотреть файл

@ -48,8 +48,11 @@ public:
char * GetDescLong(); char * GetDescLong();
int SetArchive(char *aAcrhive); int SetArchive(char *aAcrhive);
char * GetArchive(); char * GetArchive();
int SetSize(int aSize); int SetInstallSize(int aInstallSize);
int GetSize(); int GetInstallSize();
int SetArchiveSize(int aArchiveSize);
int GetArchiveSize();
int GetCurrentSize();
int SetURL(char *aURL, int aIndex); int SetURL(char *aURL, int aIndex);
char * GetURL(int aIndex); char * GetURL(int aIndex);
int AddDependee(char *aDependee); int AddDependee(char *aDependee);
@ -77,6 +80,10 @@ public:
int DepAddRef(); int DepAddRef();
int DepRelease(); int DepRelease();
int DepGetRefCount(); int DepGetRefCount();
int SetResumePos(int aResPos);
int GetResumePos();
int SetDownloaded();
int IsDownloaded();
/*---------------------------------------------------------------* /*---------------------------------------------------------------*
* Attributes * Attributes
@ -93,7 +100,8 @@ private:
char *mDescShort; char *mDescShort;
char *mDescLong; char *mDescLong;
char *mArchive; char *mArchive;
int mSize; int mInstallSize;
int mArchiveSize;
char *mURL[MAX_URLS]; char *mURL[MAX_URLS];
char *mDependees[MAX_COMPONENTS]; char *mDependees[MAX_COMPONENTS];
int mNextDependeeIdx; int mNextDependeeIdx;
@ -102,6 +110,8 @@ private:
int mIndex; int mIndex;
int mRefCount; int mRefCount;
int mDepRefCount; int mDepRefCount;
int mResPos;
int mDownloaded;
}; };
#endif /* _NS_COMPONENT_H_ */ #endif /* _NS_COMPONENT_H_ */

Просмотреть файл

@ -75,6 +75,9 @@ nsComponentsDlg::Next(GtkWidget *aWidget, gpointer aData)
return; return;
} }
if (OK != nsSetupTypeDlg::VerifyDiskSpace())
return;
// hide this notebook page // hide this notebook page
gCtx->cdlg->Hide(nsXInstallerDlg::FORWARD_MOVE); gCtx->cdlg->Hide(nsXInstallerDlg::FORWARD_MOVE);
@ -100,7 +103,8 @@ nsComponentsDlg::Parse(nsINIParser *aParser)
char *currDescShort = NULL; char *currDescShort = NULL;
char *currDescLong = NULL; char *currDescLong = NULL;
char *currArchive = NULL; char *currArchive = NULL;
char *currSizeStr = NULL; char *currInstallSizeStr = NULL;
char *currArchiveSizeStr = NULL;
char *currAttrStr = NULL; char *currAttrStr = NULL;
char *currURL = NULL; char *currURL = NULL;
char *currDepName = NULL; char *currDepName = NULL;
@ -139,7 +143,8 @@ nsComponentsDlg::Parse(nsINIParser *aParser)
currDescShort = NULL; currDescShort = NULL;
currDescLong = NULL; currDescLong = NULL;
currArchive = NULL; currArchive = NULL;
currSizeStr = NULL; currInstallSizeStr = NULL;
currArchiveSizeStr = NULL;
currAttrStr = NULL; currAttrStr = NULL;
sprintf(currSec, COMPONENTd, i); sprintf(currSec, COMPONENTd, i);
@ -157,8 +162,10 @@ nsComponentsDlg::Parse(nsINIParser *aParser)
&currDescLong, &bufsize)); &currDescLong, &bufsize));
XI_ERR_BAIL(aParser->GetStringAlloc(currSec, ARCHIVE, XI_ERR_BAIL(aParser->GetStringAlloc(currSec, ARCHIVE,
&currArchive, &bufsize)); &currArchive, &bufsize));
XI_ERR_BAIL(aParser->GetStringAlloc(currSec, SIZE, XI_ERR_BAIL(aParser->GetStringAlloc(currSec, INSTALL_SIZE,
&currSizeStr, &bufsize)); &currInstallSizeStr, &bufsize));
XI_ERR_BAIL(aParser->GetStringAlloc(currSec, ARCHIVE_SIZE,
&currArchiveSizeStr, &bufsize));
err = aParser->GetStringAlloc(currSec, ATTRIBUTES, err = aParser->GetStringAlloc(currSec, ATTRIBUTES,
&currAttrStr, &bufsize); &currAttrStr, &bufsize);
if (err != OK && err != nsINIParser::E_NO_KEY) goto BAIL; else err = OK; if (err != OK && err != nsINIParser::E_NO_KEY) goto BAIL; else err = OK;
@ -169,7 +176,8 @@ nsComponentsDlg::Parse(nsINIParser *aParser)
currComp->SetDescShort(currDescShort); currComp->SetDescShort(currDescShort);
currComp->SetDescLong(currDescLong); currComp->SetDescLong(currDescLong);
currComp->SetArchive(currArchive); currComp->SetArchive(currArchive);
currComp->SetSize(atoi(currSizeStr)); currComp->SetInstallSize(atoi(currInstallSizeStr));
currComp->SetArchiveSize(atoi(currArchiveSizeStr));
if (NULL != strstr(currAttrStr, SELECTED_ATTR)) if (NULL != strstr(currAttrStr, SELECTED_ATTR))
{ {
currComp->SetSelected(); currComp->SetSelected();

Просмотреть файл

@ -23,15 +23,34 @@
*/ */
#include "nsSocket.h" #include "nsSocket.h"
#include "nsHTTPConn.h"
#include "nsInstallDlg.h" #include "nsInstallDlg.h"
#include "nsXInstaller.h" #include "nsXInstaller.h"
#include "nsXIEngine.h" #include "nsXIEngine.h"
#include <signal.h> #include <signal.h>
#include <gtk/gtk.h>
#define NUM_PS_ENTRIES 4 #define NUM_PS_ENTRIES 4
typedef struct _DLProgress
{
// progress widgets
GtkWidget *vbox;
GtkWidget *compName;
GtkWidget *URL;
GtkWidget *localPath;
GtkWidget *status;
GtkWidget *progBar;
// progress info
int downloadedBytes;
int totalKB;
}
DLProgress;
static char *sXPInstallEngine; static char *sXPInstallEngine;
static nsRunApp *sRunAppList = NULL; static nsRunApp *sRunAppList = NULL;
static DLProgress sDLProgress;
static GtkWidget *sDLTable = NULL; static GtkWidget *sDLTable = NULL;
static GtkWidget *sMsg0Label; static GtkWidget *sMsg0Label;
@ -44,6 +63,10 @@ static GtkWidget *sPSTextEntry[NUM_PS_ENTRIES];
static int bDownload = FALSE; static int bDownload = FALSE;
static struct timeval sDLStartTime; static struct timeval sDLStartTime;
static int bDLPause = FALSE;
static int bDLCancel = FALSE;
static int bComplete = FALSE;
static int bInstallClicked = FALSE;
nsInstallDlg::nsInstallDlg() : nsInstallDlg::nsInstallDlg() :
mMsg0(NULL) mMsg0(NULL)
@ -87,21 +110,19 @@ nsInstallDlg::Next(GtkWidget *aWidget, gpointer aData)
DUMP("Next"); DUMP("Next");
int bCus; int bCus;
nsComponentList *comps = NULL; nsComponentList *comps = NULL;
GtkWidget *pauseLabel, *resumeLabel;
if (aData != gCtx->idlg) return; if (aData != gCtx->idlg) return;
if (gCtx->bMoving) if (gCtx->bMoving)
{ {
gCtx->bMoving = FALSE; gCtx->bMoving = FALSE;
DUMP("Moving done!");
return; return;
} }
bCus = (gCtx->opt->mSetupType == (gCtx->sdlg->GetNumSetupTypes() - 1)); bCus = (gCtx->opt->mSetupType == (gCtx->sdlg->GetNumSetupTypes() - 1));
comps = gCtx->sdlg->GetSelectedSetupType()->GetComponents(); comps = gCtx->sdlg->GetSelectedSetupType()->GetComponents();
// hide the cancel button
if (gCtx->cancel)
gtk_widget_hide(gCtx->cancel);
// initialize progress bar cleanly // initialize progress bar cleanly
int totalComps = 0; int totalComps = 0;
if (nsXIEngine::ExistAllXPIs(bCus, comps, &totalComps)) if (nsXIEngine::ExistAllXPIs(bCus, comps, &totalComps))
@ -112,23 +133,59 @@ nsInstallDlg::Next(GtkWidget *aWidget, gpointer aData)
gtk_progress_set_activity_mode(GTK_PROGRESS(sMajorProgBar), FALSE); gtk_progress_set_activity_mode(GTK_PROGRESS(sMajorProgBar), FALSE);
gtk_progress_bar_update(GTK_PROGRESS_BAR(sMajorProgBar), (gfloat) 0); gtk_progress_bar_update(GTK_PROGRESS_BAR(sMajorProgBar), (gfloat) 0);
gtk_label_set_text(GTK_LABEL(sMajorLabel), ""); gtk_label_set_text(GTK_LABEL(sMajorLabel), "");
if (bDownload)
{
InitDLProgress();
pauseLabel = gtk_label_new(gCtx->Res("PAUSE"));
resumeLabel = gtk_label_new(gCtx->Res("RESUME"));
gtk_container_remove(GTK_CONTAINER(gCtx->back), gCtx->backLabel);
gtk_container_remove(GTK_CONTAINER(gCtx->next), gCtx->installLabel);
gtk_container_add(GTK_CONTAINER(gCtx->back), pauseLabel);
gtk_container_add(GTK_CONTAINER(gCtx->next), resumeLabel);
gtk_widget_show(pauseLabel);
gtk_widget_show(resumeLabel);
gtk_signal_disconnect(GTK_OBJECT(gCtx->back), gCtx->backID);
gtk_signal_disconnect(GTK_OBJECT(gCtx->next), gCtx->nextID);
gtk_signal_disconnect(GTK_OBJECT(gCtx->cancel), gCtx->cancelID);
// disable resume button
gtk_widget_set_sensitive(gCtx->next, FALSE);
XI_GTK_UPDATE_UI();
// hook up buttons with callbacks
gCtx->backID = gtk_signal_connect(GTK_OBJECT(gCtx->back), "clicked",
GTK_SIGNAL_FUNC(DLPause), NULL);
gCtx->nextID = gtk_signal_connect(GTK_OBJECT(gCtx->next), "clicked",
GTK_SIGNAL_FUNC(DLResume), NULL);
gCtx->cancelID = gtk_signal_connect(GTK_OBJECT(gCtx->cancel), "clicked",
GTK_SIGNAL_FUNC(DLCancel), NULL);
}
else
{
gtk_widget_show(sMajorLabel); gtk_widget_show(sMajorLabel);
gtk_widget_show(sMajorProgBar); gtk_widget_show(sMajorProgBar);
gtk_widget_hide(gCtx->back); gtk_widget_hide(gCtx->back);
gtk_widget_hide(gCtx->next); gtk_widget_hide(gCtx->next);
gtk_widget_hide(gCtx->cancel);
}
gtk_widget_hide(sMsg0Label); gtk_widget_hide(sMsg0Label);
if (bDownload && sDLTable) if (bDownload && sDLTable)
gtk_widget_hide(sDLTable); gtk_widget_hide(sDLTable);
XI_GTK_UPDATE_UI(); XI_GTK_UPDATE_UI();
WorkDammitWork((void*) NULL); bInstallClicked = TRUE;
WorkDammitWork();
// run all specified applications after installation if (bDLCancel) // set only when download was cancelled
if (sRunAppList)
{ {
RunApps(); // mode auto has no call to gtk_main()
FreeRunAppList(); if (gCtx->opt->mMode != nsXIOptions::MODE_AUTO)
gtk_main_quit();
} }
gCtx->bMoving = TRUE; gCtx->bMoving = TRUE;
@ -423,6 +480,28 @@ nsInstallDlg::Hide(int aDirection)
return OK; return OK;
} }
int
nsInstallDlg::ShowTable()
{
if (!mTable)
return E_PARAM;
gtk_widget_show(mTable);
return OK;
}
int
nsInstallDlg::HideTable()
{
if (!mTable)
return E_PARAM;
gtk_widget_hide(mTable);
return OK;
}
int int
nsInstallDlg::SetMsg0(char *aMsg) nsInstallDlg::SetMsg0(char *aMsg)
{ {
@ -443,8 +522,8 @@ nsInstallDlg::GetMsg0()
return NULL; return NULL;
} }
void * int
nsInstallDlg::WorkDammitWork(void *arg) nsInstallDlg::WorkDammitWork()
{ {
DUMP("WorkDammitWork"); DUMP("WorkDammitWork");
@ -455,7 +534,7 @@ nsInstallDlg::WorkDammitWork(void *arg)
if (!engine) if (!engine)
{ {
ErrorHandler(E_MEM); ErrorHandler(E_MEM);
return NULL; return E_MEM;
} }
// get the component list for the current setup type // get the component list for the current setup type
@ -466,14 +545,34 @@ nsInstallDlg::WorkDammitWork(void *arg)
if (!comps) if (!comps)
{ {
ErrorHandler(E_NO_COMPONENTS); ErrorHandler(E_NO_COMPONENTS);
return NULL; return E_NO_COMPONENTS;
} }
if (!sXPInstallEngine) return NULL; if (!sXPInstallEngine) return E_PARAM;
xpiengine = comps->GetCompByArchive(sXPInstallEngine); xpiengine = comps->GetCompByArchive(sXPInstallEngine);
// 1> download // 1> download
XI_ERR_BAIL(engine->Download(bCus, comps)); err = engine->Download(bCus, comps);
if (err == E_DL_DROP_CXN)
{
ShowCxnDroppedDlg();
return err;
}
else if (err == E_DL_PAUSE || err == E_DL_CANCEL)
{
DUMP("Pause or Cancel pressed");
goto BAIL;
}
else if (err != OK)
{
DUMP("dammit... hopped into the wrong hole!");
ErrorHandler(err);
goto BAIL;
}
// prepare install UI
InitInstallProgress();
HideNavButtons();
// 2> extract engine // 2> extract engine
XI_ERR_BAIL(engine->Extract(xpiengine)); XI_ERR_BAIL(engine->Extract(xpiengine));
@ -481,19 +580,26 @@ nsInstallDlg::WorkDammitWork(void *arg)
// 3> install .xpis // 3> install .xpis
XI_ERR_BAIL(engine->Install(bCus, comps, gCtx->opt->mDestination)); XI_ERR_BAIL(engine->Install(bCus, comps, gCtx->opt->mDestination));
// save xpis if user requested so // delete xpis if user didn't request saving them
if (bDownload && gCtx->opt->mSaveModules) if (bDownload && !gCtx->opt->mSaveModules)
{ {
engine->SaveXPIs(); engine->DeleteXPIs(bCus, comps);
} }
ShowCompleteDlg(); ShowCompleteDlg();
// run all specified applications after installation
if (sRunAppList)
{
RunApps();
FreeRunAppList();
}
BAIL: BAIL:
// destroy installer engine thread object // destroy installer engine thread object
XI_IF_DELETE(engine); XI_IF_DELETE(engine);
return NULL; return err;
} }
void void
@ -617,14 +723,41 @@ nsInstallDlg::MajorProgressCB(char *aName, int aNum, int aTotal, int aActivity)
XI_GTK_UPDATE_UI(); XI_GTK_UPDATE_UI();
} }
void const int kCharsInDLLabel = 50;
nsInstallDlg::SetDownloadComp(char *aName, int aNum, int aTotal)
{
char label[64];
// major label format e.g., "Downloading Navigator [4/12] at 635 K/sec..." void
sprintf(label, gCtx->Res("DOWNLOADING"), aName, aNum, aTotal); nsInstallDlg::SetDownloadComp(nsComponent *aComp, int aURLIndex,
gtk_label_set_text(GTK_LABEL(sMajorLabel), label); int aNum, int aTotal)
{
static char xpiDir[MAXPATHLEN];
static int bHaveXPIDir = FALSE;
char label[MAXPATHLEN];
char localPath[MAXPATHLEN];
if (!aComp)
return;
if (!bHaveXPIDir)
{
getcwd(xpiDir, MAXPATHLEN);
strcat(xpiDir, "/xpi");
bHaveXPIDir = TRUE;
}
// update comp name
sprintf(label, "%s [%d/%d]", aComp->GetDescShort(), aNum, aTotal);
gtk_label_set_text(GTK_LABEL(sDLProgress.compName), label);
// update from URL
label[0] = 0;
CompressToFit(aComp->GetURL(aURLIndex), label, kCharsInDLLabel);
gtk_label_set_text(GTK_LABEL(sDLProgress.URL), label);
// to local path
label[0] = 0;
sprintf(localPath, "%s/%s", xpiDir, aComp->GetArchive());
CompressToFit(localPath, label, kCharsInDLLabel);
gtk_label_set_text(GTK_LABEL(sDLProgress.localPath), label);
gettimeofday(&sDLStartTime, NULL); gettimeofday(&sDLStartTime, NULL);
} }
@ -639,6 +772,27 @@ nsInstallDlg::DownloadCB(int aBytesRd, int aTotal)
gfloat percent = 0; gfloat percent = 0;
static int timesCalled = 0; static int timesCalled = 0;
static int activityCount = 0; static int activityCount = 0;
int dlKB;
static int lastTotal = 0;
static int lastBytesRd = 0;
// new component being downloaded
if (lastTotal != aTotal)
{
lastBytesRd = 0; // reset
lastTotal = aTotal;
}
if ((aBytesRd - lastBytesRd) > 0)
{
sDLProgress.downloadedBytes += aBytesRd - lastBytesRd;
lastBytesRd = aBytesRd;
}
if (bDLPause || bDLCancel)
{
return nsHTTPConn::E_USER_CANCEL;
}
if (++timesCalled < SHOW_EVERY_N_KB) if (++timesCalled < SHOW_EVERY_N_KB)
return 0; return 0;
@ -648,23 +802,36 @@ nsInstallDlg::DownloadCB(int aBytesRd, int aTotal)
gettimeofday(&now, NULL); gettimeofday(&now, NULL);
rate = (int) nsSocket::CalcRate(&sDLStartTime, &now, aBytesRd); rate = (int) nsSocket::CalcRate(&sDLStartTime, &now, aBytesRd);
// update the status -- bytes thus far, rate, percent in prog bar
dlKB = sDLProgress.downloadedBytes/1024;
sprintf(label, gCtx->Res("DL_STATUS_STR"), dlKB, sDLProgress.totalKB, rate);
gtk_label_set_text(GTK_LABEL(sDLProgress.status), label);
/*
// only update rate in major label line // only update rate in major label line
XXX remove this: DLRATE no longer exists
sprintf(label, gCtx->Res("DLRATE"), rate); sprintf(label, gCtx->Res("DLRATE"), rate);
gtk_label_set_text(GTK_LABEL(sRateLabel), label); gtk_label_set_text(GTK_LABEL(sRateLabel), label);
*/
if (aTotal <= 0) if (sDLProgress.totalKB <= 0)
{ {
// show some activity // show some activity
if (activityCount >= 5) activityCount = 0; if (activityCount >= 5) activityCount = 0;
percent = (gfloat)( (gfloat)activityCount++/ (gfloat)5 ); percent = (gfloat)( (gfloat)activityCount++/ (gfloat)5 );
gtk_progress_set_activity_mode(GTK_PROGRESS(sMajorProgBar), TRUE); gtk_progress_set_activity_mode(GTK_PROGRESS(sDLProgress.progBar), TRUE);
gtk_progress_bar_update(GTK_PROGRESS_BAR(sMajorProgBar), percent); gtk_progress_bar_update(GTK_PROGRESS_BAR(sDLProgress.progBar), percent);
} }
else else
{ {
percent = (gfloat)aBytesRd/(gfloat)aTotal; percent = (gfloat)dlKB/(gfloat)sDLProgress.totalKB;
gtk_progress_set_activity_mode(GTK_PROGRESS(sMajorProgBar), FALSE); #ifdef DEBUG
gtk_progress_bar_update(GTK_PROGRESS_BAR(sMajorProgBar), percent); printf("DLProgress: %d of %d (%f percent) at %d KB/sec\n", dlKB,
sDLProgress.totalKB, percent, rate);
#endif
gtk_progress_set_activity_mode(GTK_PROGRESS(sDLProgress.progBar),
FALSE);
gtk_progress_bar_update(GTK_PROGRESS_BAR(sDLProgress.progBar), percent);
} }
XI_GTK_UPDATE_UI(); XI_GTK_UPDATE_UI();
@ -704,7 +871,13 @@ nsInstallDlg::ShowCompleteDlg()
gtk_signal_connect(GTK_OBJECT(okButton), "clicked", gtk_signal_connect(GTK_OBJECT(okButton), "clicked",
GTK_SIGNAL_FUNC(CompleteOK), completeDlg); GTK_SIGNAL_FUNC(CompleteOK), completeDlg);
gtk_widget_show_all(completeDlg); gtk_widget_show_all(completeDlg);
while (!bComplete)
{
XI_GTK_UPDATE_UI(); XI_GTK_UPDATE_UI();
}
gtk_main_quit();
} }
void void
@ -715,7 +888,7 @@ nsInstallDlg::CompleteOK(GtkWidget *aWidget, gpointer aData)
if (dlg) if (dlg)
gtk_widget_destroy(dlg); gtk_widget_destroy(dlg);
gtk_main_quit(); bComplete = TRUE;
} }
void void
@ -874,3 +1047,310 @@ nsInstallDlg::PSDlgCancel(GtkWidget *aWidget, gpointer aData)
if (dlg) if (dlg)
gtk_widget_destroy(dlg); gtk_widget_destroy(dlg);
} }
void
nsInstallDlg::DLPause(GtkWidget *aWidget, gpointer aData)
{
DUMP("DLPause");
// set pause for download callback to return to libxpnet
bDLPause = TRUE;
// disbale pause button
gtk_widget_set_sensitive(gCtx->back, FALSE);
// enable resume button
gtk_widget_set_sensitive(gCtx->next, TRUE);
}
void
nsInstallDlg::DLResume(GtkWidget *aWidget, gpointer aData)
{
DUMP("DLResume");
if (!bDLPause)
{
DUMP("Not paused");
return;
}
if (bInstallClicked)
{
DUMP("Lingering signal from when Install clicked");
bInstallClicked = FALSE;
return;
}
DUMP("Unsetting bDLPause");
bDLPause = FALSE;
// disable resume button
gtk_widget_set_sensitive(gCtx->next, FALSE);
// enable pause button
gtk_widget_set_sensitive(gCtx->back, TRUE);
WorkDammitWork();
return;
}
void
nsInstallDlg::DLCancel(GtkWidget *aWidget, gpointer aData)
{
DUMP("DLCancel");
// show cancellation confirm dialog
// XXX TO DO
// set cancel for download callback to return to libxpnet
bDLCancel = TRUE;
#ifdef DEBUG
printf("%s %d: bDLPause: %d\tbDLCancel: %d\n", __FILE__, __LINE__,
bDLPause, bDLCancel);
#endif
// already paused then take explicit action to quit
if (bDLPause)
{
// mode auto has no call to gtk_main()
if (gCtx->opt->mMode != nsXIOptions::MODE_AUTO)
gtk_main_quit();
}
}
int
nsInstallDlg::CancelOrPause()
{
int err;
if (bDLPause)
{
err = E_DL_PAUSE;
}
else if (bDLCancel)
{
err = E_DL_CANCEL;
}
return err;
}
int
nsInstallDlg::ShowCxnDroppedDlg()
{
GtkWidget *cxnDroppedDlg, *label, *okButton, *packer;
// throw up dialog informing user to press resume
// or to cancel out
cxnDroppedDlg = gtk_dialog_new();
label = gtk_label_new(gCtx->Res("CXN_DROPPED"));
okButton = gtk_button_new_with_label(gCtx->Res("OK_LABEL"));
packer = gtk_packer_new();
if (cxnDroppedDlg && label && okButton && packer)
{
gtk_packer_set_default_border_width(GTK_PACKER(packer), 20);
gtk_packer_add_defaults(GTK_PACKER(packer), label, GTK_SIDE_BOTTOM,
GTK_ANCHOR_CENTER, GTK_FILL_X);
gtk_window_set_modal(GTK_WINDOW(cxnDroppedDlg), TRUE);
gtk_window_set_title(GTK_WINDOW(cxnDroppedDlg), gCtx->opt->mTitle);
gtk_window_set_position(GTK_WINDOW(cxnDroppedDlg), GTK_WIN_POS_CENTER);
gtk_container_add(GTK_CONTAINER(GTK_DIALOG(cxnDroppedDlg)->vbox),
packer);
gtk_container_add(GTK_CONTAINER(GTK_DIALOG(cxnDroppedDlg)->action_area),
okButton);
gtk_signal_connect(GTK_OBJECT(okButton), "clicked",
GTK_SIGNAL_FUNC(CxnDroppedOK), cxnDroppedDlg);
gtk_widget_show_all(cxnDroppedDlg);
}
XI_GTK_UPDATE_UI();
return OK;
}
void
nsInstallDlg::CxnDroppedOK(GtkWidget *aWidget, gpointer aData)
{
GtkWidget *cxnDroppedDlg = (GtkWidget *) aData;
if (cxnDroppedDlg)
gtk_widget_destroy(cxnDroppedDlg);
return;
}
void
nsInstallDlg::HideNavButtons()
{
gtk_signal_disconnect(GTK_OBJECT(gCtx->back), gCtx->backID);
gtk_signal_disconnect(GTK_OBJECT(gCtx->next), gCtx->nextID);
gtk_signal_disconnect(GTK_OBJECT(gCtx->cancel), gCtx->cancelID);
gtk_widget_hide(gCtx->back);
gtk_widget_hide(gCtx->next);
gtk_widget_hide(gCtx->cancel);
}
void
nsInstallDlg::InitDLProgress()
{
GtkWidget *titles[4];
GtkWidget *hbox;
GtkWidget *table;
gCtx->idlg->HideTable();
sDLProgress.vbox = gtk_vbox_new(FALSE, 10);
gtk_notebook_append_page(GTK_NOTEBOOK(gCtx->notebook),
sDLProgress.vbox, NULL);
gtk_widget_show(sDLProgress.vbox);
table = gtk_table_new(5, 2, FALSE);
gtk_box_pack_start(GTK_BOX(sDLProgress.vbox), table, FALSE,
FALSE, 0);
gtk_widget_show(table);
// setup static title progress labels in table left column
titles[0] = gtk_label_new(gCtx->Res("DOWNLOADING"));
titles[1] = gtk_label_new(gCtx->Res("FROM"));
titles[2] = gtk_label_new(gCtx->Res("TO"));
titles[3] = gtk_label_new(gCtx->Res("STATUS"));
// setup dynamic progress labels in right column
sDLProgress.compName = gtk_label_new(gCtx->Res("UNKNOWN"));
sDLProgress.URL = gtk_label_new(gCtx->Res("UNKNOWN"));
sDLProgress.localPath = gtk_label_new(gCtx->Res("UNKNOWN"));
sDLProgress.status = gtk_label_new(gCtx->Res("UNKNOWN"));
// pack and show titles
for (int i = 0; i < 4; ++i)
{
hbox = gtk_hbox_new(FALSE, 10);
gtk_box_pack_end(GTK_BOX(hbox), titles[i], FALSE, FALSE, 0);
gtk_table_attach(GTK_TABLE(table), hbox,
0, 1, i, i + 1, GTK_FILL, GTK_FILL, 5, 5);
gtk_widget_show(titles[i]);
gtk_widget_show(hbox);
}
// pack and show dynamic labels
hbox = gtk_hbox_new(FALSE, 10);
gtk_box_pack_start(GTK_BOX(hbox), sDLProgress.compName, FALSE, FALSE, 0);
gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 0, 1,
GTK_FILL, GTK_FILL, 5, 5);
gtk_widget_show(sDLProgress.compName);
gtk_widget_show(hbox);
hbox = gtk_hbox_new(FALSE, 10);
gtk_box_pack_start(GTK_BOX(hbox), sDLProgress.URL, FALSE, FALSE, 0);
gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 1, 2,
GTK_FILL, GTK_FILL, 5, 5);
gtk_widget_show(sDLProgress.URL);
gtk_widget_show(hbox);
hbox = gtk_hbox_new(FALSE, 10);
gtk_box_pack_start(GTK_BOX(hbox), sDLProgress.localPath, FALSE,
FALSE, 0);
gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 2, 3,
GTK_FILL, GTK_FILL, 5, 5);
gtk_widget_show(sDLProgress.localPath);
gtk_widget_show(hbox);
hbox = gtk_hbox_new(FALSE, 10);
gtk_box_pack_start(GTK_BOX(hbox), sDLProgress.status, FALSE,
FALSE, 0);
gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 3, 4,
GTK_FILL, GTK_FILL, 5, 5);
gtk_widget_show(sDLProgress.status);
gtk_widget_show(hbox);
// init and show prog bar
sDLProgress.progBar = gtk_progress_bar_new();
// set to non-activity mode and initialize
gtk_progress_set_activity_mode(GTK_PROGRESS(sDLProgress.progBar), FALSE);
gtk_progress_bar_update(GTK_PROGRESS_BAR(sDLProgress.progBar), (gfloat) 0);
// compute total download size
sDLProgress.downloadedBytes = 0;
sDLProgress.totalKB = TotalDLSize();
// show prog bar
hbox = gtk_hbox_new(TRUE, 10);
gtk_box_pack_start(GTK_BOX(hbox), sDLProgress.progBar, FALSE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(sDLProgress.vbox), hbox, FALSE, FALSE, 0);
gtk_widget_show(sDLProgress.progBar);
gtk_widget_show(hbox);
XI_GTK_UPDATE_UI();
}
void
nsInstallDlg::InitInstallProgress()
{
gtk_widget_hide(sDLProgress.vbox);
gCtx->idlg->ShowTable();
}
int
nsInstallDlg::TotalDLSize()
{
int total = 0; // in KB
int bCustom;
nsComponentList *comps;
nsComponent *currComp;
int archiveSize, currentSize;
bCustom = (gCtx->opt->mSetupType == (gCtx->sdlg->GetNumSetupTypes() - 1));
comps = gCtx->sdlg->GetSelectedSetupType()->GetComponents();
currComp = comps->GetHead();
// loop through all components
while (currComp)
{
if ((bCustom && currComp->IsSelected()) || (!bCustom))
{
// if still have to download
if (!currComp->IsDownloaded())
{
// find archive size - amount downloaded already
archiveSize = currComp->GetArchiveSize();
currentSize = currComp->GetCurrentSize();
#ifdef DEBUG
printf("%s ar sz = %d cu sz = %d\n", currComp->GetArchive(),
archiveSize, currentSize);
#endif
total += (archiveSize - currentSize);
}
}
currComp = currComp->GetNext();
}
return total;
}
void
nsInstallDlg::CompressToFit(char *aOrigStr, char *aOutStr, int aOutStrLen)
{
int origStrLen;
int halfOutStrLen;
char *lastPart; // last aOrigStr part start
if (!aOrigStr || !aOutStr || aOutStrLen <= 0)
return;
origStrLen = strlen(aOrigStr);
halfOutStrLen = (aOutStrLen/2) - 2; // minus 2 since ellipsis is 3 chars
lastPart = aOrigStr + origStrLen - halfOutStrLen;
strncpy(aOutStr, aOrigStr, halfOutStrLen);
*(aOutStr + halfOutStrLen) = 0;
strcat(aOutStr, "...");
strncat(aOutStr, lastPart, strlen(lastPart));
*(aOutStr + aOutStrLen + 1) = 0;
}

Просмотреть файл

@ -29,7 +29,7 @@
#include "XIErrors.h" #include "XIErrors.h"
#include "nsRunApp.h" #include "nsRunApp.h"
#include <sys/time.h> class nsComponent;
class nsInstallDlg : public nsXInstallerDlg class nsInstallDlg : public nsXInstallerDlg
{ {
@ -47,13 +47,17 @@ public:
int Show(int aDirection); int Show(int aDirection);
int Hide(int aDirection); int Hide(int aDirection);
int ShowTable();
int HideTable();
static void XPIProgressCB(const char *aMsg, int aVal, int aMax); static void XPIProgressCB(const char *aMsg, int aVal, int aMax);
static void MajorProgressCB(char *aName, int aNum, int aTotal, static void MajorProgressCB(char *aName, int aNum, int aTotal,
int aActivity); int aActivity);
static int DownloadCB(int aBytesRd, int aTotal); static int DownloadCB(int aBytesRd, int aTotal);
static void SetDownloadComp(char *aName, int aNum, int aTotal); static void SetDownloadComp(nsComponent *aComp, int aURLIndex,
int aNum, int aTotal);
static void ClearRateLabel(); static void ClearRateLabel();
static int CancelOrPause();
enum enum
{ {
@ -62,6 +66,13 @@ public:
ACT_INSTALL ACT_INSTALL
}; };
enum
{
E_DL_PAUSE = -1101,
E_DL_CANCEL = -1102,
E_DL_DROP_CXN = -1103
};
/*------------------------------------------------------------------* /*------------------------------------------------------------------*
* INI Properties * INI Properties
*------------------------------------------------------------------*/ *------------------------------------------------------------------*/
@ -69,7 +80,7 @@ public:
char *GetMsg0(); char *GetMsg0();
private: private:
static void *WorkDammitWork(void *arg); // install start static int WorkDammitWork(void); // install start
static void SaveModulesToggled(GtkWidget *aWidget, gpointer aData); static void SaveModulesToggled(GtkWidget *aWidget, gpointer aData);
static void ShowProxySettings(GtkWidget *aWidget, gpointer aData); static void ShowProxySettings(GtkWidget *aWidget, gpointer aData);
static void PSDlgOK (GtkWidget *aWidget, gpointer aData); static void PSDlgOK (GtkWidget *aWidget, gpointer aData);
@ -79,6 +90,17 @@ private:
static void RunApps(); static void RunApps();
static void FreeRunAppList(); static void FreeRunAppList();
int AppendRunApp(nsRunApp *aNewRunApp); int AppendRunApp(nsRunApp *aNewRunApp);
static void DLPause(GtkWidget *aWidget, gpointer aData);
static void DLResume(GtkWidget *aWidget, gpointer aData);
static void DLCancel(GtkWidget *aWidget, gpointer aData);
static int ShowCxnDroppedDlg();
static void CxnDroppedOK(GtkWidget *aWidget, gpointer aData);
static void HideNavButtons();
static void InitDLProgress();
static void InitInstallProgress();
static int TotalDLSize();
static void CompressToFit(char *aOrigStr, char *aOutStr,
int aOutStrLen);
char *mMsg0; char *mMsg0;
}; };

Просмотреть файл

@ -25,6 +25,24 @@
#include "nsSetupTypeDlg.h" #include "nsSetupTypeDlg.h"
#include "nsXInstaller.h" #include "nsXInstaller.h"
// need these for statfs
#ifdef HAVE_SYS_STATVFS_H
#include <sys/statvfs.h>
#endif
#ifdef HAVE_SYS_STATFS_H
#include <sys/statfs.h>
#endif
#ifdef HAVE_STATVFS
#define STATFS statvfs
#else
#define STATFS statfs
#endif
static GtkWidget *sBrowseBtn; static GtkWidget *sBrowseBtn;
static gint sBrowseBtnID; static gint sBrowseBtnID;
static GtkWidget *sFolder; static GtkWidget *sFolder;
@ -97,6 +115,13 @@ nsSetupTypeDlg::Next(GtkWidget *aWidget, gpointer aData)
if (OK != nsSetupTypeDlg::DeleteOldInst()) if (OK != nsSetupTypeDlg::DeleteOldInst())
return; return;
// if not custom setup type verify disk space
if (gCtx->opt->mSetupType != (gCtx->sdlg->GetNumSetupTypes() - 1))
{
if (OK != nsSetupTypeDlg::VerifyDiskSpace())
return;
}
// hide this notebook page // hide this notebook page
gCtx->sdlg->Hide(nsXInstallerDlg::FORWARD_MOVE); gCtx->sdlg->Hide(nsXInstallerDlg::FORWARD_MOVE);
@ -936,3 +961,144 @@ nsSetupTypeDlg::ConstructPath(char *aDest, char *aTrunk, char *aLeaf)
return err; return err;
} }
int
nsSetupTypeDlg::VerifyDiskSpace(void)
{
int err = OK;
int dsAvail, dsReqd;
char dsAvailStr[128], dsReqdStr[128];
char message[512];
GtkWidget *noDSDlg, *label, *okButton, *packer;
// find disk space available at destination
dsAvail = DSAvailable();
if (dsAvail < 0)
return OK; // optimistic when statfs failed
// or we don't have statfs
// get disk space required
dsReqd = DSRequired();
if (dsReqd > dsAvail)
{
// throw up not enough ds dlg
sprintf(dsAvailStr, gCtx->Res("DS_AVAIL"), dsAvail);
sprintf(dsReqdStr, gCtx->Res("DS_REQD"), dsReqd);
sprintf(message, "%s\n%s\n\n%s", dsAvailStr, dsReqdStr,
gCtx->Res("NO_DISK_SPACE"));
noDSDlg = gtk_dialog_new();
label = gtk_label_new(message);
okButton = gtk_button_new_with_label(gCtx->Res("OK_LABEL"));
packer = gtk_packer_new();
if (noDSDlg && label && okButton && packer)
{
gtk_window_set_title(GTK_WINDOW(noDSDlg), gCtx->opt->mTitle);
gtk_window_set_position(GTK_WINDOW(noDSDlg),
GTK_WIN_POS_CENTER);
gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
gtk_packer_set_default_border_width(GTK_PACKER(packer), 20);
gtk_packer_add_defaults(GTK_PACKER(packer), label, GTK_SIDE_BOTTOM,
GTK_ANCHOR_CENTER, GTK_FILL_X);
gtk_box_pack_start(GTK_BOX(
GTK_DIALOG(noDSDlg)->action_area), okButton,
FALSE, FALSE, 10);
gtk_signal_connect(GTK_OBJECT(okButton), "clicked",
GTK_SIGNAL_FUNC(NoDiskSpaceOK), noDSDlg);
gtk_box_pack_start(GTK_BOX(
GTK_DIALOG(noDSDlg)->vbox), packer, FALSE, FALSE, 10);
gtk_widget_show_all(noDSDlg);
}
err = E_NO_DISK_SPACE;
}
return err;
}
int
nsSetupTypeDlg::DSAvailable(void)
{
// returns disk space available in kilobytes
int dsAvail = -1;
#if defined(HAVE_SYS_STATVFS_H) || defined(HAVE_SYS_STATFS_H)
struct STATFS buf;
int rv;
if (gCtx->opt->mDestination)
{
rv = STATFS(gCtx->opt->mDestination, &buf);
if (rv == 0)
{
if (buf.f_bsize > 1024 && (buf.f_bsize%1024 == 0))
{
// normally the block size is >= 1024 and a multiple
// so we can shave off the last three digits before
// finding the product of the block size and num blocks
// which is important for large disks
dsAvail = (buf.f_bsize/1024) * (buf.f_bavail);
}
else
{
// attempt to stuff into a 32 bit int even though
// we convert from bytes -> kilobytes later
// (may fail to compute on very large disks whose
// block size is not a multiple of 1024 -- highly
// improbable)
dsAvail = (buf.f_bsize * buf.f_bavail)/1024;
}
}
}
#endif // HAVE_SYS_STATVFS_H -or- HAVE_SYS_STATFS_H
return dsAvail;
}
int
nsSetupTypeDlg::DSRequired(void)
{
// returns disk space required in kilobytes
int dsReqd = 0;
nsComponentList *comps;
int bCus;
// find setup type's component list
bCus = (gCtx->opt->mSetupType == (gCtx->sdlg->GetNumSetupTypes() - 1));
comps = gCtx->sdlg->GetSelectedSetupType()->GetComponents();
// loop through all components
nsComponent *currComp = comps->GetHead();
while (currComp)
{
if ( (bCus == TRUE && currComp->IsSelected()) || (bCus == FALSE) )
{
// add to disk space required
dsReqd += currComp->GetInstallSize();
dsReqd += currComp->GetArchiveSize();
}
currComp = currComp->GetNext();
}
return dsReqd;
}
void
nsSetupTypeDlg::NoDiskSpaceOK(GtkWidget *aWidget, gpointer aData)
{
GtkWidget *noDSDlg = (GtkWidget *) aData;
if (!noDSDlg)
return;
gtk_widget_destroy(noDSDlg);
}

Просмотреть файл

@ -61,6 +61,10 @@ public:
static void DeleteInstDelete(GtkWidget *aWidget, gpointer aData); static void DeleteInstDelete(GtkWidget *aWidget, gpointer aData);
static void DeleteInstCancel(GtkWidget *aWidget, gpointer aData); static void DeleteInstCancel(GtkWidget *aWidget, gpointer aData);
static int ConstructPath(char *aDest, char *aTrunk, char *aLeaf); static int ConstructPath(char *aDest, char *aTrunk, char *aLeaf);
static int VerifyDiskSpace();
static int DSAvailable();
static int DSRequired();
static void NoDiskSpaceOK(GtkWidget *aWidget, gpointer aData);
/*---------------------------------------------------------------------* /*---------------------------------------------------------------------*
* INI Properties * INI Properties

Просмотреть файл

@ -53,6 +53,7 @@ nsXIContext::nsXIContext()
backID = 0; backID = 0;
nextID = 0; nextID = 0;
cancelID = 0;
bMoving = FALSE; bMoving = FALSE;
bDone = FALSE; bDone = FALSE;
@ -148,6 +149,8 @@ nsXIContext::LoadResources()
"ACCEPT", "ACCEPT",
"DECLINE", "DECLINE",
"INSTALL", "INSTALL",
"PAUSE",
"RESUME",
"DEFAULT_TITLE", "DEFAULT_TITLE",
"DEST_DIR", "DEST_DIR",
"BROWSE", "BROWSE",
@ -161,8 +164,6 @@ nsXIContext::LoadResources()
"ERROR", "ERROR",
"FATAL_ERROR", "FATAL_ERROR",
"DESCRIPTION", "DESCRIPTION",
"DOWNLOADING",
"DLRATE",
"PREPARING", "PREPARING",
"EXTRACTING", "EXTRACTING",
"INSTALLING_XPI", "INSTALLING_XPI",
@ -177,6 +178,16 @@ nsXIContext::LoadResources()
"PS_LABEL2", "PS_LABEL2",
"PS_LABEL3", "PS_LABEL3",
"ERROR_TITLE", "ERROR_TITLE",
"DS_AVAIL",
"DS_REQD",
"NO_DISK_SPACE",
"CXN_DROPPED",
"DOWNLOADING",
"FROM",
"TO",
"STATUS",
"DL_STATUS_STR",
"UNKNOWN",
__EOT__ __EOT__
}; };

Просмотреть файл

@ -84,6 +84,7 @@ public:
int backID; /* signal handler id for back btn */ int backID; /* signal handler id for back btn */
int nextID; /* signal handler id for next btn */ int nextID; /* signal handler id for next btn */
int cancelID; /* signal handler id for cancel btn */
int bMoving; /* when moving between dlgs signals are int bMoving; /* when moving between dlgs signals are
emitted twice; this notes the state */ emitted twice; this notes the state */
int bDone; /* engine thread sets boolean when done int bDone; /* engine thread sets boolean when done

Просмотреть файл

@ -26,10 +26,13 @@
#include "nsHTTPConn.h" #include "nsHTTPConn.h"
#include "nsXIEngine.h" #include "nsXIEngine.h"
#include <errno.h>
#define CORE_LIB_COUNT 11 #define CORE_LIB_COUNT 11
const char kHTTPProto[8] = "http://"; const char kHTTPProto[] = "http://";
const char kFTPProto[7] = "ftp://"; const char kFTPProto[] = "ftp://";
const char kDLMarkerPath[] = "./xpi/.current_download";
nsXIEngine::nsXIEngine() : nsXIEngine::nsXIEngine() :
mTmp(NULL), mTmp(NULL),
@ -58,7 +61,7 @@ nsXIEngine::Download(int aCustom, nsComponentList *aComps)
return E_PARAM; return E_PARAM;
int err = OK; int err = OK;
nsComponent *currComp = aComps->GetHead(); nsComponent *currComp = aComps->GetHead(), *markedComp = NULL;
char *currURL = NULL; char *currURL = NULL;
char *currHost = NULL; char *currHost = NULL;
char *currPath = NULL; char *currPath = NULL;
@ -68,28 +71,60 @@ nsXIEngine::Download(int aCustom, nsComponentList *aComps)
char *qualURL = NULL; char *qualURL = NULL;
int i; int i;
int currPort; int currPort;
struct stat stbuf;
int resPos = 0;
int fileSize = 0;
int currCompNum = 1, markedCompNum = 0;
int numToDL = 0; // num xpis to download
mTmp = NULL; err = GetDLMarkedComp(aComps, aCustom, &markedComp, &markedCompNum);
err = MakeUniqueTmpDir(); if (err == OK && markedComp)
if (!mTmp || err != OK) {
return E_DIR_CREATE; currComp = markedComp;
currCompNum = markedCompNum;
// if all .xpis exist in the ./xpi dir (blob/CD) we don't need to download sprintf(localPath, "%s/%s", XPI_DIR, currComp->GetArchive());
currComp->SetResumePos(GetFileSize(localPath));
}
else
{
// if all .xpis exist in the ./xpi dir (blob/CD)
// we don't need to download
if (ExistAllXPIs(aCustom, aComps, &mTotalComps)) if (ExistAllXPIs(aCustom, aComps, &mTotalComps))
return CopyToTmp(aCustom, aComps); return OK;
}
// check if ./xpi dir exists else create it
if (0 != stat(XPI_DIR, &stbuf))
{
if (0 != mkdir(XPI_DIR, 0755))
return E_MKDIR_FAIL;
}
numToDL = TotalToDownload(aCustom, aComps);
int currCompNum = 1;
while (currComp) while (currComp)
{ {
if ( (aCustom == TRUE && currComp->IsSelected()) || (aCustom == FALSE) ) if ( (aCustom == TRUE && currComp->IsSelected()) || (aCustom == FALSE) )
{ {
// in case we are resuming inter- or intra-installer session
if (currComp->IsDownloaded())
{
currComp = currComp->GetNext();
continue;
}
SetDLMarker(currComp->GetArchive());
for (i = 0; i < MAX_URLS; i++) for (i = 0; i < MAX_URLS; i++)
{ {
currURL = currComp->GetURL(i); currURL = currComp->GetURL(i);
if (!currURL) break; if (!currURL) break;
nsInstallDlg::SetDownloadComp(currComp->GetDescShort(), nsInstallDlg::SetDownloadComp(currComp, i,
currCompNum, mTotalComps); currCompNum, numToDL);
// restore resume position
resPos = currComp->GetResumePos();
// has a proxy server been specified? // has a proxy server been specified?
if (gCtx->opt->mProxyHost && gCtx->opt->mProxyPort) if (gCtx->opt->mProxyHost && gCtx->opt->mProxyPort)
@ -129,18 +164,16 @@ nsXIEngine::Download(int aCustom, nsComponentList *aComps)
err = conn->Open(); err = conn->Open();
if (err == nsHTTPConn::OK) if (err == nsHTTPConn::OK)
{ {
sprintf(localPath, "%s/%s", mTmp, sprintf(localPath, "%s/%s", XPI_DIR,
currComp->GetArchive()); currComp->GetArchive());
err = conn->Get(nsInstallDlg::DownloadCB, localPath); err = conn->Get(nsInstallDlg::DownloadCB, localPath,
resPos);
conn->Close(); conn->Close();
} }
XI_IF_FREE(proxyURL); XI_IF_FREE(proxyURL);
XI_IF_FREE(qualURL); XI_IF_FREE(qualURL);
XI_IF_DELETE(conn); XI_IF_DELETE(conn);
if (err != nsHTTPConn::OK)
continue; // failover
} }
// is this an HTTP URL? // is this an HTTP URL?
@ -166,17 +199,15 @@ nsXIEngine::Download(int aCustom, nsComponentList *aComps)
err = conn->Open(); err = conn->Open();
if (err == nsHTTPConn::OK) if (err == nsHTTPConn::OK)
{ {
sprintf(localPath, "%s/%s", mTmp, sprintf(localPath, "%s/%s", XPI_DIR,
currComp->GetArchive()); currComp->GetArchive());
err = conn->Get(nsInstallDlg::DownloadCB, localPath); err = conn->Get(nsInstallDlg::DownloadCB, localPath,
resPos);
conn->Close(); conn->Close();
} }
XI_IF_FREE(qualURL); XI_IF_FREE(qualURL);
XI_IF_DELETE(conn); XI_IF_DELETE(conn);
if (err != nsHTTPConn::OK)
continue; // failover
} }
// or is this an FTP URL? // or is this an FTP URL?
@ -207,10 +238,10 @@ nsXIEngine::Download(int aCustom, nsComponentList *aComps)
err = conn->Open(); err = conn->Open();
if (err == nsFTPConn::OK) if (err == nsFTPConn::OK)
{ {
sprintf(localPath, "%s/%s", mTmp, sprintf(localPath, "%s/%s", XPI_DIR,
currComp->GetArchive()); currComp->GetArchive());
err = conn->Get(srvPath, localPath, nsFTPConn::BINARY, err = conn->Get(srvPath, localPath, nsFTPConn::BINARY,
1, nsInstallDlg::DownloadCB); resPos, 1, nsInstallDlg::DownloadCB);
conn->Close(); conn->Close();
} }
@ -218,9 +249,6 @@ nsXIEngine::Download(int aCustom, nsComponentList *aComps)
XI_IF_FREE(currPath); XI_IF_FREE(currPath);
XI_IF_FREE(srvPath); XI_IF_FREE(srvPath);
XI_IF_DELETE(conn); XI_IF_DELETE(conn);
if (err != nsFTPConn::OK)
continue; // failover
} }
// else error: malformed URL // else error: malformed URL
@ -229,10 +257,43 @@ nsXIEngine::Download(int aCustom, nsComponentList *aComps)
err = nsHTTPConn::E_MALFORMED_URL; err = nsHTTPConn::E_MALFORMED_URL;
} }
if (err == nsHTTPConn::E_USER_CANCEL)
err = nsInstallDlg::CancelOrPause();
// user hit pause and subsequently resumed
if (err == nsInstallDlg::E_DL_PAUSE)
{
currComp->SetResumePos(GetFileSize(localPath));
return err;
}
// user cancelled during download
else if (err == nsInstallDlg::E_DL_CANCEL)
return err;
// user didn't cancel or pause: some other dl error occured
else if (err != OK)
{
fileSize = GetFileSize(localPath);
if (fileSize > 0)
{
// assume dropped connection if file size > 0
currComp->SetResumePos(fileSize);
return nsInstallDlg::E_DL_DROP_CXN;
}
else
{
// failover
continue;
}
}
nsInstallDlg::ClearRateLabel(); // clean after ourselves nsInstallDlg::ClearRateLabel(); // clean after ourselves
if (err == OK) if (err == OK)
{ {
currComp->SetDownloaded();
currCompNum++; currCompNum++;
break; // no need to failover break; // no need to failover
} }
@ -242,17 +303,29 @@ nsXIEngine::Download(int aCustom, nsComponentList *aComps)
currComp = currComp->GetNext(); currComp = currComp->GetNext();
} }
// download complete: remove marker
DelDLMarker();
return OK; return OK;
} }
int int
nsXIEngine::Extract(nsComponent *aXPIEngine) nsXIEngine::Extract(nsComponent *aXPIEngine)
{ {
int rv;
if (!aXPIEngine) if (!aXPIEngine)
return E_PARAM; return E_PARAM;
nsZipExtractor *unzip = new nsZipExtractor(mTmp); mTmp = NULL;
return unzip->Extract(aXPIEngine, CORE_LIB_COUNT); rv = MakeUniqueTmpDir();
if (!mTmp || rv != OK)
return E_DIR_CREATE;
nsZipExtractor *unzip = new nsZipExtractor(XPI_DIR, mTmp);
rv = unzip->Extract(aXPIEngine, CORE_LIB_COUNT);
XI_IF_DELETE(unzip);
return rv;
} }
int int
@ -388,31 +461,6 @@ nsXIEngine::ParseURL(char *aURL, char **aHost, char **aDir)
return err; return err;
} }
int
nsXIEngine::FTPAnonGet(nsFTPConn *aConn, char *aDir, char *aArchive)
{
int err = OK;
char srvrPath[MAXPATHLEN];
char loclPath[MAXPATHLEN];
struct stat dummy;
if (!aConn || !aDir || !aArchive)
return E_PARAM;
sprintf(srvrPath, "%s%s", aDir, aArchive);
sprintf(loclPath, "%s/%s", mTmp, aArchive);
err = aConn->Get(srvrPath, loclPath, nsFTPConn::BINARY, TRUE,
nsInstallDlg::DownloadCB);
if (err != nsFTPConn::OK)
return E_NO_DOWNLOAD;
if (-1 == stat(loclPath, &dummy))
err = E_NO_DOWNLOAD;
return err;
}
int int
nsXIEngine::LoadXPIStub(xpistub_t *aStub, char *aDestination) nsXIEngine::LoadXPIStub(xpistub_t *aStub, char *aDestination)
{ {
@ -494,10 +542,10 @@ nsXIEngine::InstallXPI(nsComponent *aXPI, xpistub_t *aStub)
char xpipath[MAXPATHLEN]; char xpipath[MAXPATHLEN];
nsresult rv = 0; nsresult rv = 0;
if (!aStub || !aXPI) if (!aStub || !aXPI || !mOriginalDir)
return E_PARAM; return E_PARAM;
sprintf(xpipath, "../%s", aXPI->GetArchive()); sprintf(xpipath, "%s/%s/%s", mOriginalDir, XPI_DIR, aXPI->GetArchive());
DUMP(xpipath); DUMP(xpipath);
#define XPI_NO_NEW_THREAD 0x1000 #define XPI_NO_NEW_THREAD 0x1000
@ -540,7 +588,7 @@ nsXIEngine::UnloadXPIStub(xpistub_t *aStub)
* around when the app exits (since xpcom etc. was * around when the app exits (since xpcom etc. was
* unloaded when the stub was unloaded). To get * unloaded when the stub was unloaded). To get
* around this we don't close the stub (which is * around this we don't close the stub (which is
* apparently safe on Linux/Unix. * apparently safe on Linux/Unix).
*/ */
/* close xpistub library */ /* close xpistub library */
@ -594,48 +642,205 @@ nsXIEngine::ExistAllXPIs(int aCustom, nsComponentList *aComps, int *aTotal)
} }
int int
nsXIEngine::CopyToTmp(int aCustom, nsComponentList *aComps) nsXIEngine::DeleteXPIs(int aCustom, nsComponentList *aComps)
{ {
int err = OK; int err = OK;
nsComponent *currComp = aComps->GetHead(); nsComponent *currComp = aComps->GetHead();
char cmd[256]; char currXPIPath[MAXPATHLEN];
if (!aComps || !mOriginalDir)
return E_PARAM;
int currCompNum = 1;
while (currComp) while (currComp)
{ {
if ( (aCustom == TRUE && currComp->IsSelected()) || (aCustom == FALSE) ) if ( (aCustom == TRUE && currComp->IsSelected()) || (aCustom == FALSE) )
{ {
sprintf(cmd, "cp %s/%s %s", XPI_DIR, currComp->GetArchive(), mTmp); sprintf(currXPIPath, "%s/%s/%s", mOriginalDir, XPI_DIR,
DUMP(cmd); currComp->GetArchive());
// update UI // delete the xpi
nsInstallDlg::MajorProgressCB(currComp->GetDescShort(), err = unlink(currXPIPath);
currCompNum, mTotalComps, nsInstallDlg::ACT_DOWNLOAD);
system(cmd); #ifdef DEBUG
currCompNum++; printf("%s %d: unlink %s returned: %d\n", __FILE__, __LINE__,
currXPIPath, err);
#endif
} }
currComp = currComp->GetNext(); currComp = currComp->GetNext();
} }
// all xpi should be deleted so delete the ./xpi dir
sprintf(currXPIPath, "%s/xpi", mOriginalDir);
err = rmdir(currXPIPath);
#ifdef DEBUG
printf("%s %d: rmdir %s returned: %d\n", __FILE__, __LINE__,
currXPIPath, err);
#endif
return err; return err;
} }
void int
nsXIEngine::SaveXPIs(void) nsXIEngine::GetFileSize(char *aPath)
{ {
char xpidir[MAXPATHLEN]; struct stat stbuf;
char cpcmd[3 + MAXPATHLEN + 1 + MAXPATHLEN + 1];
// make local "xpi" directory next to installer binary if (!aPath)
sprintf(xpidir, "%s/xpi", mOriginalDir); return 0;
if (0 != mkdir(xpidir, 0755))
return;
// cp all xpis from tmp to "xpi" dir if (0 == stat(aPath, &stbuf))
sprintf(cpcmd, "cp %s/*.xpi %s", mTmp, xpidir); {
DUMP(cpcmd); return stbuf.st_size;
}
system(cpcmd); return 0;
}
int
nsXIEngine::SetDLMarker(char *aCompName)
{
int rv = OK;
FILE *dlMarkerFD;
int compNameLen;
if (!aCompName)
return E_PARAM;
// open the marker file
dlMarkerFD = fopen(kDLMarkerPath, "w");
if (!dlMarkerFD)
return E_OPEN_MKR;
// write out the current comp name
compNameLen = strlen(aCompName);
if (compNameLen > 0)
{
rv = fwrite((void *) aCompName, sizeof(char), compNameLen, dlMarkerFD);
if (rv != compNameLen)
rv = E_WRITE_MKR;
else
rv = OK;
}
// close the marker file
fclose(dlMarkerFD);
#ifdef DEBUG
printf("%s %d: SetDLMarker rv = %d\n", __FILE__, __LINE__, rv);
#endif
return rv;
}
int
nsXIEngine::GetDLMarkedComp(nsComponentList *aComps, int aCustom,
nsComponent **aOutComp, int *aOutCompNum)
{
int rv = OK;
FILE *dlMarkerFD = NULL;
struct stat stbuf;
char *compNameInFile = NULL;
int compNum = 1;
nsComponent *currComp = NULL;
if (!aComps || !aOutComp || !aOutCompNum)
return E_PARAM;
*aOutComp = NULL;
currComp = aComps->GetHead();
// open the marker file
dlMarkerFD = fopen(kDLMarkerPath, "r");
if (!dlMarkerFD)
return E_OPEN_MKR;
// find it's length
if (0 != stat(kDLMarkerPath, &stbuf))
{
rv = E_STAT;
goto BAIL;
}
if (stbuf.st_size <= 0)
{
rv = E_FIND_COMP;
goto BAIL;
}
// allocate a buffer the length of the file
compNameInFile = (char *) malloc(sizeof(char) * (stbuf.st_size + 1));
if (!compNameInFile)
{
rv = E_MEM;
goto BAIL;
}
memset(compNameInFile, 0 , (stbuf.st_size + 1));
// read in the file contents
rv = fread((void *) compNameInFile, sizeof(char),
stbuf.st_size, dlMarkerFD);
if (rv != stbuf.st_size)
rv = E_READ_MKR;
else
rv = OK;
if (rv == OK)
{
// compare the comp name read in with all those in the components list
while (currComp)
{
if ( (aCustom == TRUE && currComp->IsSelected()) ||
(aCustom == FALSE) )
{
if (strcmp(currComp->GetArchive(), compNameInFile) == 0)
{
*aOutComp = currComp;
break;
}
compNum++;
}
currComp = currComp->GetNext();
}
}
*aOutCompNum = compNum;
BAIL:
if (dlMarkerFD)
fclose(dlMarkerFD);
XI_IF_FREE(compNameInFile);
return rv;
}
int
nsXIEngine::DelDLMarker()
{
return unlink(kDLMarkerPath);
}
int
nsXIEngine::TotalToDownload(int aCustom, nsComponentList *aComps)
{
int total = 0;
nsComponent *currComp;
if (!aComps)
return 0;
currComp = aComps->GetHead();
while (currComp)
{
if ( (aCustom == TRUE && currComp->IsSelected()) || (aCustom == FALSE) )
{
if (!currComp->IsDownloaded())
total++;
}
currComp = currComp->GetNext();
}
return total;
} }

Просмотреть файл

@ -42,8 +42,6 @@
#include <dlfcn.h> #include <dlfcn.h>
#include <sys/stat.h> #include <sys/stat.h>
class nsFTPConn;
/*------------------------------------------------------------------------* /*------------------------------------------------------------------------*
* XPI Stub Glue * XPI Stub Glue
*------------------------------------------------------------------------*/ *------------------------------------------------------------------------*/
@ -76,19 +74,35 @@ public:
int Download(int aCustom, nsComponentList *aComps); int Download(int aCustom, nsComponentList *aComps);
int Extract(nsComponent *aXPIEngine); int Extract(nsComponent *aXPIEngine);
int Install(int aCustom, nsComponentList *aComps, char *aDestination); int Install(int aCustom, nsComponentList *aComps, char *aDestination);
void SaveXPIs(void); int DeleteXPIs(int aCustom, nsComponentList *aComps);
static void ProgressCallback(const char* aMsg, PRInt32 aVal, PRInt32 aMax); static void ProgressCallback(const char* aMsg, PRInt32 aVal, PRInt32 aMax);
static int ExistAllXPIs(int aCustom, nsComponentList *aComps, int *aTotal); static int ExistAllXPIs(int aCustom, nsComponentList *aComps, int *aTotal);
enum
{
OK = 0,
E_PARAM = -1201,
E_MEM = -1202,
E_OPEN_MKR = -1203,
E_WRITE_MKR = -1204,
E_READ_MKR = -1205,
E_FIND_COMP = -1206,
E_STAT = -1207
};
private: private:
int MakeUniqueTmpDir(); int MakeUniqueTmpDir();
int ParseURL(char *aURL, char **aHost, char **aDir); int ParseURL(char *aURL, char **aHost, char **aDir);
int FTPAnonGet(nsFTPConn *aConn, char *aDir, char *aAcrhive);
int LoadXPIStub(xpistub_t *aStub, char *aDestionation); int LoadXPIStub(xpistub_t *aStub, char *aDestionation);
int InstallXPI(nsComponent *aComp, xpistub_t *aStub); int InstallXPI(nsComponent *aComp, xpistub_t *aStub);
int UnloadXPIStub(xpistub_t *aStub); int UnloadXPIStub(xpistub_t *aStub);
int CopyToTmp(int aCustom, nsComponentList *aComps); int GetFileSize(char *aPath);
int SetDLMarker(char *aCompName);
int GetDLMarkedComp(nsComponentList *aComps, int aCustom,
nsComponent **aOutComp, int *aOutCompNum);
int DelDLMarker();
int TotalToDownload(int aCustom, nsComponentList *aComps);
char *mTmp; char *mTmp;
int mTotalComps; int mTotalComps;

Просмотреть файл

@ -27,7 +27,8 @@
nsXIOptions::nsXIOptions() : nsXIOptions::nsXIOptions() :
mTitle(NULL), mTitle(NULL),
mDestination(NULL), mDestination(NULL),
mSetupType(-1), mSetupType(0),
mMode(MODE_DEFAULT),
mProxyHost(NULL), mProxyHost(NULL),
mProxyPort(NULL), mProxyPort(NULL),
mProxyUser(NULL), mProxyUser(NULL),

Просмотреть файл

@ -36,6 +36,14 @@ public:
char *mTitle; char *mTitle;
char *mDestination; char *mDestination;
int mSetupType; int mSetupType;
int mMode;
enum
{
MODE_DEFAULT = 0,
MODE_AUTO,
MODE_SILENT
};
char *mProxyHost; char *mProxyHost;
char *mProxyPort; char *mProxyPort;

Просмотреть файл

@ -38,6 +38,34 @@ nsXInstaller::~nsXInstaller()
XI_IF_DELETE(gCtx); XI_IF_DELETE(gCtx);
} }
int
nsXInstaller::ParseArgs(int aArgc, char **aArgv)
{
if (aArgc <= 0 || !aArgv)
return E_PARAM;
for (int argNum = 1; argNum < aArgc; ++argNum)
{
/* mode: auto (show progress UI but assume defaults
* without user intervention)
*/
if (strcmp(aArgv[argNum], "-ma") == 0)
{
gCtx->opt->mMode = nsXIOptions::MODE_AUTO;
}
/* mode: silent (show no UI and have no user
* intervention)
*/
else if (strcmp(aArgv[argNum], "-ms") == 0)
{
gCtx->opt->mMode = nsXIOptions::MODE_SILENT;
}
}
return OK;
}
int int
nsXInstaller::ParseConfig() nsXInstaller::ParseConfig()
{ {
@ -155,12 +183,22 @@ nsXInstaller::RunWizard(int argc, char **argv)
gtk_widget_show(gCtx->notebook); gtk_widget_show(gCtx->notebook);
gtk_container_add(GTK_CONTAINER(gCtx->canvas), gCtx->notebook); gtk_container_add(GTK_CONTAINER(gCtx->canvas), gCtx->notebook);
if (gCtx->opt->mMode == nsXIOptions::MODE_AUTO)
{
// show install dlg
gCtx->idlg->Show(nsXInstallerDlg::FORWARD_MOVE);
gCtx->idlg->Next((GtkWidget *)NULL, (gpointer) gCtx->idlg);
}
else
{
// show welcome dlg // show welcome dlg
gCtx->wdlg->Show(nsXInstallerDlg::FORWARD_MOVE); gCtx->wdlg->Show(nsXInstallerDlg::FORWARD_MOVE);
// pop over to main event loop // pop over to main event loop
gtk_main(); gtk_main();
}
return OK; return OK;
BAIL: BAIL:
@ -222,7 +260,7 @@ nsXInstaller::DrawCancelButton(GtkWidget *aLogoVBox)
hbox = gtk_hbox_new(FALSE, 10); hbox = gtk_hbox_new(FALSE, 10);
gtk_box_pack_start(GTK_BOX(hbox), gCtx->cancel, TRUE, TRUE, 15); gtk_box_pack_start(GTK_BOX(hbox), gCtx->cancel, TRUE, TRUE, 15);
gtk_box_pack_end(GTK_BOX(aLogoVBox), hbox, FALSE, TRUE, 10); gtk_box_pack_end(GTK_BOX(aLogoVBox), hbox, FALSE, TRUE, 10);
gtk_signal_connect(GTK_OBJECT(gCtx->cancel), "clicked", gCtx->cancelID = gtk_signal_connect(GTK_OBJECT(gCtx->cancel), "clicked",
GTK_SIGNAL_FUNC(Kill), NULL); GTK_SIGNAL_FUNC(Kill), NULL);
gtk_widget_show(hbox); gtk_widget_show(hbox);
gtk_widget_show(gCtx->cancel); gtk_widget_show(gCtx->cancel);
@ -328,8 +366,11 @@ main(int argc, char **argv)
if (installer) if (installer)
{ {
if ( (err = installer->ParseConfig()) == OK) if ( (err = installer->ParseConfig()) == OK)
{
installer->ParseArgs(argc, argv);
err = installer->RunWizard(argc, argv); err = installer->RunWizard(argc, argv);
} }
}
else else
err = E_MEM; err = E_MEM;

Просмотреть файл

@ -40,6 +40,7 @@ public:
nsXInstaller(); nsXInstaller();
~nsXInstaller(); ~nsXInstaller();
int ParseArgs(int aArgc, char **aArgv);
int ParseConfig(); int ParseConfig();
int RunWizard(int argc, char **argv); int RunWizard(int argc, char **argv);
int ParseGeneral(nsINIParser *aParser); int ParseGeneral(nsINIParser *aParser);

Просмотреть файл

@ -28,14 +28,20 @@
#include "zipstub.h" #include "zipstub.h"
#include "zipfile.h" #include "zipfile.h"
nsZipExtractor::nsZipExtractor(char *aTmp) : nsZipExtractor::nsZipExtractor(char *aSrc, char *aDest) :
mTmp(aTmp) mSrc(NULL),
mDest(NULL)
{ {
if (aSrc)
mSrc = strdup(aSrc);
if (aDest)
mDest = strdup(aDest);
} }
nsZipExtractor::~nsZipExtractor() nsZipExtractor::~nsZipExtractor()
{ {
// don't free mTmp: we don't own it XI_IF_FREE(mSrc);
XI_IF_FREE(mDest);
} }
int int
@ -56,7 +62,7 @@ nsZipExtractor::Extract(nsComponent *aXPIEngine, int aTotal)
if (!aXPIEngine || !(aXPIEngine->GetArchive())) if (!aXPIEngine || !(aXPIEngine->GetArchive()))
return E_PARAM; return E_PARAM;
sprintf(apath, "%s/%s", mTmp, aXPIEngine->GetArchive()); sprintf(apath, "%s/%s", mSrc, aXPIEngine->GetArchive());
if (-1 == stat(apath, &dummy)) if (-1 == stat(apath, &dummy))
return E_NO_DOWNLOAD; return E_NO_DOWNLOAD;
@ -107,7 +113,7 @@ nsZipExtractor::Extract(nsComponent *aXPIEngine, int aTotal)
nsInstallDlg::MajorProgressCB(leaf, i, nsInstallDlg::MajorProgressCB(leaf, i,
aTotal, nsInstallDlg::ACT_EXTRACT); aTotal, nsInstallDlg::ACT_EXTRACT);
sprintf(epath, "%s/%s", mTmp, zpath); sprintf(epath, "%s/%s", mDest, zpath);
err = DirCreateRecursive(epath); err = DirCreateRecursive(epath);
if (err != OK) goto au_revoir; if (err != OK) goto au_revoir;
@ -121,7 +127,7 @@ nsZipExtractor::Extract(nsComponent *aXPIEngine, int aTotal)
i++; i++;
} }
sprintf(bindir, "%s/%s", mTmp, TMP_EXTRACT_SUBDIR); sprintf(bindir, "%s/%s", mDest, TMP_EXTRACT_SUBDIR);
if (-1 == stat(bindir, &dummy)) if (-1 == stat(bindir, &dummy))
err = E_EXTRACTION; err = E_EXTRACTION;
@ -143,10 +149,10 @@ nsZipExtractor::DirCreateRecursive(char *aPath)
char currdir[MAXPATHLEN]; char currdir[MAXPATHLEN];
struct stat dummy; struct stat dummy;
if (!aPath || !mTmp) if (!aPath || !mDest)
return E_PARAM; return E_PARAM;
slash = aPath + strlen(mTmp); slash = aPath + strlen(mDest);
if (*slash != '/') if (*slash != '/')
return E_INVALID_PTR; return E_INVALID_PTR;

Просмотреть файл

@ -34,7 +34,7 @@
class nsZipExtractor class nsZipExtractor
{ {
public: public:
nsZipExtractor(char *aTmp); nsZipExtractor(char *aSrc, char *aDest);
~nsZipExtractor(); ~nsZipExtractor();
int Extract(nsComponent *aXPIEngine, int aTotal); int Extract(nsComponent *aXPIEngine, int aTotal);
@ -42,7 +42,8 @@ public:
private: private:
int DirCreateRecursive(char *aPath); int DirCreateRecursive(char *aPath);
char *mTmp; char *mSrc;
char *mDest;
}; };
#endif /* _NS_ZIPEXTRACTOR_H_ */ #endif /* _NS_ZIPEXTRACTOR_H_ */