зеркало из https://github.com/mozilla/pjs.git
Replace command line `ftp' with our ftp impl for the linux/solaris installers.
[r=ssu; nsbeta3+ b=47886]
This commit is contained in:
Родитель
da0055fc07
Коммит
061628a73f
|
@ -31,7 +31,8 @@ include $(DEPTH)/config/autoconf.mk
|
|||
PROGRAM = mozilla-installer-bin
|
||||
|
||||
CPPSRCS = \
|
||||
XIErrors.cpp \
|
||||
XIErrors.cpp \
|
||||
nsFTPConn.cpp \
|
||||
nsXInstallerDlg.cpp \
|
||||
nsComponent.cpp \
|
||||
nsSetupType.cpp \
|
||||
|
|
|
@ -51,12 +51,14 @@
|
|||
#define FATAL_ERROR "Fatal error [%d]: %s\n"
|
||||
#define WARNING "Warning [%d]: %s\n"
|
||||
#define DESCRIPTION "Description"
|
||||
#define DOWNLOADING "Downloading %s..."
|
||||
#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."
|
||||
|
||||
|
||||
/*--------------------------------------------------------------------*
|
||||
|
|
|
@ -27,13 +27,17 @@
|
|||
#include "nsXIEngine.h"
|
||||
#include <signal.h>
|
||||
|
||||
static char *sXPInstallEngine;
|
||||
static GtkWidget *sMsg0Label;
|
||||
static GtkWidget *sMajorLabel;
|
||||
static GtkWidget *sMinorLabel;
|
||||
static GtkWidget *sMajorProgBar;
|
||||
static GtkWidget *sMinorProgBar;
|
||||
static int bDownload = FALSE;
|
||||
static char *sXPInstallEngine;
|
||||
|
||||
static GtkWidget *sMsg0Label;
|
||||
static GtkWidget *sMajorLabel;
|
||||
static GtkWidget *sMinorLabel;
|
||||
static GtkWidget *sRateLabel;
|
||||
static GtkWidget *sMajorProgBar;
|
||||
static GtkWidget *sMinorProgBar;
|
||||
|
||||
static int bDownload = FALSE;
|
||||
static struct timeval sDLStartTime;
|
||||
|
||||
nsInstallDlg::nsInstallDlg() :
|
||||
mMsg0(NULL)
|
||||
|
@ -189,10 +193,13 @@ nsInstallDlg::Show(int aDirection)
|
|||
vbox = gtk_vbox_new(FALSE, 0);
|
||||
hbox = gtk_hbox_new(FALSE, 0);
|
||||
sMajorLabel = gtk_label_new("");
|
||||
sRateLabel = gtk_label_new("");
|
||||
gtk_box_pack_start(GTK_BOX(hbox), sMajorLabel, FALSE, FALSE, 0);
|
||||
gtk_box_pack_start(GTK_BOX(hbox), sRateLabel, FALSE, FALSE, 0);
|
||||
gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
|
||||
gtk_widget_show(hbox);
|
||||
gtk_widget_show(sMajorLabel);
|
||||
gtk_widget_show(sRateLabel);
|
||||
|
||||
sMajorProgBar = gtk_progress_bar_new();
|
||||
gtk_box_pack_start(GTK_BOX(vbox), sMajorProgBar, FALSE, FALSE, 0);
|
||||
|
@ -317,10 +324,11 @@ nsInstallDlg::WorkDammitWork(void *arg)
|
|||
// 3> install .xpis
|
||||
XI_ERR_BAIL(engine->Install(bCus, comps, gCtx->opt->mDestination));
|
||||
|
||||
ShowCompleteDlg();
|
||||
|
||||
BAIL:
|
||||
// destroy installer engine thread object
|
||||
XI_IF_DELETE(engine);
|
||||
gtk_main_quit();
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
@ -344,7 +352,7 @@ nsInstallDlg::XPIProgressCB(const char *aMsg, int aVal, int aMax)
|
|||
updates = 0;
|
||||
|
||||
gfloat percent = (gfloat)((gfloat)aVal/(gfloat)aMax);
|
||||
#ifdef DEBUG
|
||||
#if 0
|
||||
printf("progress percent: %f\taVal: %d\taMax: %d\n", percent, aVal, aMax);
|
||||
#endif
|
||||
gtk_progress_set_activity_mode(GTK_PROGRESS(sMinorProgBar), FALSE);
|
||||
|
@ -404,9 +412,7 @@ nsInstallDlg::MajorProgressCB(char *aName, int aNum, int aTotal, int aActivity)
|
|||
switch (aActivity)
|
||||
{
|
||||
case ACT_DOWNLOAD:
|
||||
if (bDownload)
|
||||
sprintf(msg, DOWNLOADING, aName);
|
||||
else
|
||||
if (!bDownload)
|
||||
sprintf(msg, PREPARING, aName);
|
||||
break;
|
||||
|
||||
|
@ -447,3 +453,86 @@ nsInstallDlg::MajorProgressCB(char *aName, int aNum, int aTotal, int aActivity)
|
|||
|
||||
XI_GTK_UPDATE_UI();
|
||||
}
|
||||
|
||||
void
|
||||
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);
|
||||
gtk_label_set_text(GTK_LABEL(sMajorLabel), label);
|
||||
|
||||
gettimeofday(&sDLStartTime, NULL);
|
||||
}
|
||||
|
||||
#define SHOW_EVERY_N_KB 16
|
||||
int
|
||||
nsInstallDlg::DownloadCB(int aBytesRd, int aTotal)
|
||||
{
|
||||
struct timeval now;
|
||||
char label[64];
|
||||
int rate;
|
||||
gfloat percent;
|
||||
static int timesCalled = 0;
|
||||
|
||||
if (++timesCalled < SHOW_EVERY_N_KB)
|
||||
return 0;
|
||||
else
|
||||
timesCalled = 0;
|
||||
|
||||
gettimeofday(&now, NULL);
|
||||
rate = (int) nsFTPConn::CalcRate(&sDLStartTime, &now, aBytesRd);
|
||||
percent = (gfloat)aBytesRd/(gfloat)aTotal;
|
||||
|
||||
// only update rate in major label line
|
||||
sprintf(label, DLRATE, rate);
|
||||
gtk_label_set_text(GTK_LABEL(sRateLabel), label);
|
||||
gtk_progress_bar_update(GTK_PROGRESS_BAR(sMajorProgBar), percent);
|
||||
|
||||
XI_GTK_UPDATE_UI();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
nsInstallDlg::ClearRateLabel()
|
||||
{
|
||||
gtk_label_set_text(GTK_LABEL(sRateLabel), "");
|
||||
XI_GTK_UPDATE_UI();
|
||||
}
|
||||
|
||||
void
|
||||
nsInstallDlg::ShowCompleteDlg()
|
||||
{
|
||||
DUMP("ShowCompleteDlg");
|
||||
|
||||
GtkWidget *completeDlg, *label, *okButton, *packer;
|
||||
|
||||
// throw up completion notification
|
||||
completeDlg = gtk_dialog_new();
|
||||
label = gtk_label_new(COMPLETED);
|
||||
okButton = gtk_button_new_with_label(OK_LABEL);
|
||||
packer = gtk_packer_new();
|
||||
|
||||
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(completeDlg), TRUE);
|
||||
gtk_window_set_position(GTK_WINDOW(completeDlg), GTK_WIN_POS_CENTER);
|
||||
gtk_container_add(GTK_CONTAINER(GTK_DIALOG(completeDlg)->vbox), packer);
|
||||
gtk_container_add(GTK_CONTAINER(GTK_DIALOG(completeDlg)->action_area),
|
||||
okButton);
|
||||
gtk_signal_connect(GTK_OBJECT(okButton), "clicked",
|
||||
GTK_SIGNAL_FUNC(CompleteOK), completeDlg);
|
||||
gtk_widget_show_all(completeDlg);
|
||||
XI_GTK_UPDATE_UI();
|
||||
}
|
||||
|
||||
void
|
||||
nsInstallDlg::CompleteOK(GtkWidget *aWidget, gpointer aData)
|
||||
{
|
||||
if (aWidget)
|
||||
gtk_widget_destroy(aWidget);
|
||||
|
||||
gtk_main_quit();
|
||||
}
|
||||
|
|
|
@ -45,11 +45,12 @@ public:
|
|||
int Show(int aDirection);
|
||||
int Hide(int aDirection);
|
||||
|
||||
static void *WorkDammitWork(void *arg); // install start
|
||||
|
||||
static void XPIProgressCB(const char *aMsg, int aVal, int aMax);
|
||||
static void MajorProgressCB(char *aName, int aNum, int aTotal,
|
||||
int aActivity);
|
||||
static int DownloadCB(int aBytesRd, int aTotal);
|
||||
static void SetDownloadComp(char *aName, int aNum, int aTotal);
|
||||
static void ClearRateLabel();
|
||||
|
||||
enum
|
||||
{
|
||||
|
@ -65,6 +66,10 @@ public:
|
|||
char *GetMsg0();
|
||||
|
||||
private:
|
||||
static void *WorkDammitWork(void *arg); // install start
|
||||
static void ShowCompleteDlg();
|
||||
static void CompleteOK(GtkWidget *aWidget, gpointer aData);
|
||||
|
||||
char *mMsg0;
|
||||
};
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
#include "nsXIEngine.h"
|
||||
|
||||
#define CORE_LIB_COUNT 10
|
||||
#define CORE_LIB_COUNT 11
|
||||
|
||||
nsXIEngine::nsXIEngine() :
|
||||
mTmp(NULL),
|
||||
|
@ -54,8 +54,10 @@ nsXIEngine::Download(int aCustom, nsComponentList *aComps)
|
|||
|
||||
int err = OK;
|
||||
nsComponent *currComp = aComps->GetHead();
|
||||
nsFTPConn *conn = NULL;
|
||||
char *currURL = NULL;
|
||||
char *currHost = NULL;
|
||||
char *lastHost = NULL;
|
||||
char *currDir = NULL;
|
||||
int i;
|
||||
|
||||
|
@ -83,11 +85,37 @@ nsXIEngine::Download(int aCustom, nsComponentList *aComps)
|
|||
err = ParseURL(currURL, &currHost, &currDir);
|
||||
if (err == OK)
|
||||
{
|
||||
// update UI
|
||||
nsInstallDlg::MajorProgressCB(currComp->GetDescShort(),
|
||||
currCompNum, mTotalComps, nsInstallDlg::ACT_DOWNLOAD);
|
||||
nsInstallDlg::SetDownloadComp(currComp->GetDescShort(),
|
||||
currCompNum, mTotalComps);
|
||||
|
||||
if ( (lastHost && currHost &&
|
||||
(strcmp(lastHost, currHost) != 0)) || !conn)
|
||||
{
|
||||
if (lastHost && conn)
|
||||
{
|
||||
conn->Close();
|
||||
XI_IF_DELETE(conn);
|
||||
}
|
||||
conn = new nsFTPConn(currHost);
|
||||
err = conn->Open();
|
||||
if (err != nsFTPConn::OK)
|
||||
{
|
||||
/* open failed: failover to next URL */
|
||||
XI_IF_DELETE(conn);
|
||||
XI_IF_FREE(currHost);
|
||||
XI_IF_FREE(currDir);
|
||||
lastHost = NULL;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
err = FTPAnonGet(conn, currDir, currComp->GetArchive());
|
||||
nsInstallDlg::ClearRateLabel(); // clean after ourselves
|
||||
|
||||
XI_IF_FREE(lastHost);
|
||||
XI_IF_FREE(currDir);
|
||||
lastHost = currHost; /* helps determine open conn reuse */
|
||||
|
||||
err = FTPAnonGet(currHost, currDir, currComp->GetArchive());
|
||||
if (err == OK)
|
||||
{
|
||||
currCompNum++;
|
||||
|
@ -100,6 +128,10 @@ nsXIEngine::Download(int aCustom, nsComponentList *aComps)
|
|||
currComp = currComp->GetNext();
|
||||
}
|
||||
|
||||
XI_IF_FREE(currHost);
|
||||
if (conn)
|
||||
conn->Close();
|
||||
XI_IF_DELETE(conn);
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
@ -247,33 +279,25 @@ nsXIEngine::ParseURL(char *aURL, char **aHost, char **aDir)
|
|||
}
|
||||
|
||||
int
|
||||
nsXIEngine::FTPAnonGet(char *aHost, char *aDir, char *aArchive)
|
||||
nsXIEngine::FTPAnonGet(nsFTPConn *aConn, char *aDir, char *aArchive)
|
||||
{
|
||||
int err = OK;
|
||||
char qualifiedPath[MAXPATHLEN];
|
||||
char basename[256];
|
||||
char ftpcmds[1024];
|
||||
char srvrPath[MAXPATHLEN];
|
||||
char loclPath[MAXPATHLEN];
|
||||
struct stat dummy;
|
||||
|
||||
if (!aHost || !aDir || !aArchive)
|
||||
if (!aConn || !aDir || !aArchive)
|
||||
return E_PARAM;
|
||||
|
||||
sprintf(qualifiedPath, "%s%s", aDir, aArchive);
|
||||
sprintf(basename, "%s/%s", mTmp, aArchive);
|
||||
sprintf(ftpcmds, "\
|
||||
\
|
||||
ftp -n %s > /dev/null 2>&1 <<EndFTP\n\
|
||||
user anonymous dev@null.edu\n\
|
||||
binary\n\
|
||||
passive\n\
|
||||
get %s %s\n\
|
||||
EndFTP\n\
|
||||
\
|
||||
", aHost, qualifiedPath, basename);
|
||||
sprintf(srvrPath, "%s%s", aDir, aArchive);
|
||||
sprintf(loclPath, "%s/%s", mTmp, aArchive);
|
||||
|
||||
system(ftpcmds);
|
||||
err = aConn->Get(srvrPath, loclPath, nsFTPConn::BINARY, TRUE,
|
||||
nsInstallDlg::DownloadCB);
|
||||
if (err != nsFTPConn::OK)
|
||||
return E_NO_DOWNLOAD;
|
||||
|
||||
if (-1 == stat(basename, &dummy))
|
||||
if (-1 == stat(loclPath, &dummy))
|
||||
err = E_NO_DOWNLOAD;
|
||||
|
||||
return err;
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
#include "nsComponentList.h"
|
||||
#include "nsInstallDlg.h"
|
||||
#include "nsZipExtractor.h"
|
||||
#include "nsFTPConn.h"
|
||||
|
||||
#include "xpistub.h"
|
||||
|
||||
|
@ -81,7 +82,7 @@ public:
|
|||
private:
|
||||
int MakeUniqueTmpDir();
|
||||
int ParseURL(char *aURL, char **aHost, char **aDir);
|
||||
int FTPAnonGet(char *aHost, char *aDir, char *aAcrhive);
|
||||
int FTPAnonGet(nsFTPConn *aConn, char *aDir, char *aAcrhive);
|
||||
int LoadXPIStub(xpistub_t *aStub, char *aDestionation);
|
||||
int InstallXPI(nsComponent *aComp, xpistub_t *aStub);
|
||||
int UnloadXPIStub(xpistub_t *aStub);
|
||||
|
|
Загрузка…
Ссылка в новой задаче