mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-13 21:35:39 +00:00
Fix linux installer crash on exit by tweaking progress update.
[nsbeta2+ b = 36781; r = syd]
This commit is contained in:
parent
d2b9125781
commit
700247792d
@ -51,7 +51,6 @@ CPPSRCS = \
|
||||
|
||||
LIBS = \
|
||||
`gtk-config --libs` \
|
||||
-lpthread \
|
||||
$(NULL)
|
||||
|
||||
LOCAL_INCLUDES += -I$(srcdir)/../../../stub
|
||||
|
@ -51,12 +51,12 @@
|
||||
#define FATAL_ERROR "Fatal error [%d]: %s\n"
|
||||
#define WARNING "Warning [%d]: %s\n"
|
||||
#define DESCRIPTION "Description"
|
||||
#define DOWNLOADING "Downloading..."
|
||||
#define PREPARING "Preparing installer modules..."
|
||||
#define EXTRACTING "Extracting installer files..."
|
||||
#define INSTALLING "Installing..."
|
||||
#define DOWNLOADING "Downloading %s..."
|
||||
#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..."
|
||||
|
||||
|
||||
/*--------------------------------------------------------------------*
|
||||
@ -128,7 +128,7 @@
|
||||
/*--------------------------------------------------------------------*
|
||||
* Macros
|
||||
*--------------------------------------------------------------------*/
|
||||
#define TMP_DIR_TEMPLATE "%s/.tmp.xi.%d" // <cwd>/.tmp.xi.<N>
|
||||
#define TMP_DIR_TEMPLATE "/tmp/.tmp.xi.%d"
|
||||
#define TMP_EXTRACT_SUBDIR "bin"
|
||||
#define XPI_DIR "./xpi"
|
||||
|
||||
@ -188,12 +188,18 @@ do { \
|
||||
#define XI_ASSERT(_expr, _msg) \
|
||||
do { \
|
||||
if (!(_expr)) \
|
||||
printf("%s %d: Assertion failed! %s \n", __FILE__, __LINE__, _msg); \
|
||||
printf("%s %d: ASSERTION FAILED! %s \n", __FILE__, __LINE__, _msg); \
|
||||
} while(0);
|
||||
#else
|
||||
#define XI_ASSERT(_expr, _msg)
|
||||
#endif
|
||||
|
||||
#define XI_GTK_UPDATE_UI() \
|
||||
do { \
|
||||
while (gtk_events_pending()) \
|
||||
gtk_main_iteration(); \
|
||||
} while (0);
|
||||
|
||||
|
||||
#ifndef TRUE
|
||||
#define TRUE 1
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/param.h>
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
/*------------------------------------------------------------------*
|
||||
|
@ -30,7 +30,7 @@
|
||||
# mozilla-installer-bin GTK based binary installer.
|
||||
#
|
||||
# The mozilla-installer-bin binary is an install wizard that
|
||||
# collects user preferences about modules to install and where
|
||||
# collects user preferences about modules to install and where to
|
||||
# install them. The program then proceeds to install Mozilla.
|
||||
#
|
||||
#=====================================================================
|
||||
@ -45,4 +45,6 @@ export PATH
|
||||
MOZILLA_FIVE_HOME=.
|
||||
export MOZILLA_FIVE_HOME
|
||||
|
||||
exec ./mozilla-installer-bin --sync
|
||||
./mozilla-installer-bin --sync
|
||||
|
||||
rm -rf /tmp/.tmp.xi.*
|
||||
|
@ -117,6 +117,13 @@ nsComponentList::GetLengthSelected()
|
||||
int numSelected = 0;
|
||||
nsComponent *curr;
|
||||
|
||||
/* NOTE:
|
||||
* ----
|
||||
* If copies of components are help by this list rather than pointers
|
||||
* then this method will return an inaccurate number. Due to
|
||||
* architecture be very careful when using this method.
|
||||
*/
|
||||
|
||||
curr = mHead;
|
||||
if (!curr) return 0;
|
||||
|
||||
|
@ -26,7 +26,6 @@
|
||||
#include "nsXInstaller.h"
|
||||
#include "nsXIEngine.h"
|
||||
#include <signal.h>
|
||||
#include <pthread.h>
|
||||
|
||||
static char *sXPInstallEngine;
|
||||
static GtkWidget *sMsg0Label;
|
||||
@ -34,7 +33,7 @@ static GtkWidget *sMajorLabel;
|
||||
static GtkWidget *sMinorLabel;
|
||||
static GtkWidget *sMajorProgBar;
|
||||
static GtkWidget *sMinorProgBar;
|
||||
static int sActivity;
|
||||
static int bDownload = FALSE;
|
||||
|
||||
nsInstallDlg::nsInstallDlg() :
|
||||
mMsg0(NULL)
|
||||
@ -77,9 +76,7 @@ nsInstallDlg::Next(GtkWidget *aWidget, gpointer aData)
|
||||
{
|
||||
DUMP("Next");
|
||||
int bCus;
|
||||
pthread_t eng_th;
|
||||
nsComponentList *comps = NULL;
|
||||
pthread_t *me = (pthread_t *) malloc(sizeof(pthread_t));
|
||||
|
||||
if (aData != gCtx->idlg) return;
|
||||
if (gCtx->bMoving)
|
||||
@ -96,26 +93,24 @@ nsInstallDlg::Next(GtkWidget *aWidget, gpointer aData)
|
||||
gtk_widget_hide(gCtx->cancel);
|
||||
|
||||
// initialize progress bar cleanly
|
||||
if (nsXIEngine::ExistAllXPIs(bCus, comps))
|
||||
gtk_label_set_text(GTK_LABEL(sMajorLabel), PREPARING);
|
||||
int totalComps = 0;
|
||||
if (nsXIEngine::ExistAllXPIs(bCus, comps, &totalComps))
|
||||
bDownload = FALSE;
|
||||
else
|
||||
gtk_label_set_text(GTK_LABEL(sMajorLabel), DOWNLOADING);
|
||||
gtk_progress_set_activity_mode(GTK_PROGRESS(sMajorProgBar), TRUE);
|
||||
gtk_progress_bar_update(GTK_PROGRESS_BAR(sMajorProgBar), 1);
|
||||
bDownload = TRUE;
|
||||
|
||||
gtk_progress_set_activity_mode(GTK_PROGRESS(sMajorProgBar), FALSE);
|
||||
gtk_progress_bar_update(GTK_PROGRESS_BAR(sMajorProgBar), (gfloat) 0);
|
||||
gtk_label_set_text(GTK_LABEL(sMajorLabel), "");
|
||||
gtk_widget_show(sMajorLabel);
|
||||
gtk_widget_show(sMajorProgBar);
|
||||
|
||||
gtk_widget_hide(gCtx->back);
|
||||
gtk_widget_hide(gCtx->next);
|
||||
gtk_widget_hide(sMsg0Label);
|
||||
XI_GTK_UPDATE_UI();
|
||||
|
||||
pthread_mutex_init(&gCtx->prog_mutex, NULL);
|
||||
pthread_cond_init(&gCtx->prog_cv, NULL);
|
||||
|
||||
*me = pthread_self();
|
||||
pthread_create(&eng_th, NULL, WorkDammitWork, (void*) me);
|
||||
|
||||
gtk_timeout_add(1, ProgressUpdater, NULL);
|
||||
WorkDammitWork((void*) NULL);
|
||||
|
||||
gCtx->bMoving = TRUE;
|
||||
return;
|
||||
@ -192,8 +187,11 @@ nsInstallDlg::Show(int aDirection)
|
||||
|
||||
// vbox with two widgets packed in: label0 / progmeter0 (major)
|
||||
vbox = gtk_vbox_new(FALSE, 0);
|
||||
hbox = gtk_hbox_new(FALSE, 0);
|
||||
sMajorLabel = gtk_label_new("");
|
||||
gtk_box_pack_start(GTK_BOX(vbox), sMajorLabel, FALSE, FALSE, 0);
|
||||
gtk_box_pack_start(GTK_BOX(hbox), sMajorLabel, FALSE, FALSE, 0);
|
||||
gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
|
||||
gtk_widget_show(hbox);
|
||||
gtk_widget_show(sMajorLabel);
|
||||
|
||||
sMajorProgBar = gtk_progress_bar_new();
|
||||
@ -207,8 +205,11 @@ nsInstallDlg::Show(int aDirection)
|
||||
|
||||
// vbox with two widgets packed in: label1 / progmeter1 (minor)
|
||||
vbox = gtk_vbox_new(FALSE, 0);
|
||||
hbox = gtk_hbox_new(FALSE, 0);
|
||||
sMinorLabel = gtk_label_new("");
|
||||
gtk_box_pack_start(GTK_BOX(vbox), sMinorLabel, FALSE, FALSE, 0);
|
||||
gtk_box_pack_start(GTK_BOX(hbox), sMinorLabel, FALSE, FALSE, 0);
|
||||
gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
|
||||
gtk_widget_show(hbox);
|
||||
gtk_widget_show(sMinorLabel);
|
||||
|
||||
sMinorProgBar = gtk_progress_bar_new();
|
||||
@ -308,120 +309,40 @@ nsInstallDlg::WorkDammitWork(void *arg)
|
||||
xpiengine = comps->GetCompByArchive(sXPInstallEngine);
|
||||
|
||||
// 1> download
|
||||
sActivity = nsInstallDlg::ACT_DOWNLOAD;
|
||||
XI_ERR_BAIL(engine->Download(bCus, comps));
|
||||
|
||||
// 2> extract engine
|
||||
sActivity = nsInstallDlg::ACT_EXTRACT;
|
||||
XI_ERR_BAIL(engine->Extract(xpiengine));
|
||||
|
||||
// 3> install .xpis
|
||||
sActivity = nsInstallDlg::ACT_INSTALL;
|
||||
XI_ERR_BAIL(engine->Install(bCus, comps, gCtx->opt->mDestination));
|
||||
|
||||
// destroy installer engine thread object
|
||||
XI_IF_DELETE(engine);
|
||||
|
||||
pthread_mutex_lock(&gCtx->prog_mutex);
|
||||
gCtx->bDone = TRUE;
|
||||
gCtx->threadTurn = nsXIContext::UI_THREAD;
|
||||
pthread_cond_signal(&gCtx->prog_cv);
|
||||
pthread_mutex_unlock(&gCtx->prog_mutex);
|
||||
|
||||
DUMP("pre pthread_exit");
|
||||
pthread_exit((void *) 0);
|
||||
DUMP("post pthread_exit");
|
||||
|
||||
BAIL:
|
||||
// destroy installer engine thread object
|
||||
XI_IF_DELETE(engine);
|
||||
gtk_main_quit();
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int bExtractStarted = FALSE;
|
||||
static int bInstallStarted = FALSE;
|
||||
|
||||
gint
|
||||
nsInstallDlg::ProgressUpdater(gpointer aData)
|
||||
{
|
||||
int status = 0;
|
||||
|
||||
while (gtk_events_pending())
|
||||
gtk_main_iteration();
|
||||
|
||||
if (gCtx->bDone)
|
||||
{
|
||||
pthread_cond_destroy(&gCtx->prog_cv);
|
||||
pthread_mutex_destroy(&gCtx->prog_mutex);
|
||||
|
||||
// XXX gdk_flush();
|
||||
gtk_main_quit();
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch (sActivity)
|
||||
{
|
||||
case nsInstallDlg::ACT_DOWNLOAD:
|
||||
// DUMP("Downloading...");
|
||||
status = 1;
|
||||
break;
|
||||
|
||||
case nsInstallDlg::ACT_EXTRACT:
|
||||
// DUMP("Extracting...");
|
||||
if (!bExtractStarted)
|
||||
{
|
||||
gtk_label_set_text(GTK_LABEL(sMajorLabel), EXTRACTING);
|
||||
gtk_widget_show(sMajorLabel);
|
||||
|
||||
bExtractStarted = TRUE;
|
||||
}
|
||||
status = 1;
|
||||
break;
|
||||
|
||||
case nsInstallDlg::ACT_INSTALL:
|
||||
// DUMP("Installing...");
|
||||
if (!bInstallStarted)
|
||||
{
|
||||
gtk_label_set_text(GTK_LABEL(sMajorLabel), INSTALLING);
|
||||
gtk_widget_show(sMajorLabel);
|
||||
|
||||
bInstallStarted = TRUE;
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&gCtx->prog_mutex);
|
||||
while (gCtx->threadTurn != nsXIContext::UI_THREAD && !gCtx->bDone)
|
||||
pthread_cond_wait(&gCtx->prog_cv, &gCtx->prog_mutex);
|
||||
|
||||
gtk_widget_show(sMinorLabel);
|
||||
gtk_widget_show(sMinorProgBar);
|
||||
|
||||
if (!gCtx->bDone)
|
||||
gCtx->threadTurn = nsXIContext::ENGINE_THREAD;
|
||||
|
||||
pthread_mutex_unlock(&gCtx->prog_mutex);
|
||||
|
||||
status = 1;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
void
|
||||
nsInstallDlg::XPIProgressCB(const char *aMsg, int aVal, int aMax)
|
||||
{
|
||||
// DUMP("XPIProgressCB");
|
||||
|
||||
if (!aMsg)
|
||||
return;
|
||||
|
||||
static int updates = 0;
|
||||
char msg[64];
|
||||
char *colon = NULL, *lastSlash = NULL;
|
||||
memset(msg, 0, 64);
|
||||
|
||||
if (aMax > 0)
|
||||
{
|
||||
// reset for next component
|
||||
if (updates)
|
||||
updates = 0;
|
||||
|
||||
gfloat percent = (gfloat)((gfloat)aVal/(gfloat)aMax);
|
||||
#ifdef DEBUG
|
||||
printf("progress percent: %f\taVal: %d\taMax: %d\n", percent, aVal, aMax);
|
||||
@ -434,11 +355,17 @@ nsInstallDlg::XPIProgressCB(const char *aMsg, int aVal, int aMax)
|
||||
}
|
||||
else
|
||||
{
|
||||
updates++;
|
||||
if (updates > 5)
|
||||
updates = 0;
|
||||
gfloat percent = (gfloat)((gfloat)updates/(gfloat)5);
|
||||
|
||||
gtk_progress_set_activity_mode(GTK_PROGRESS(sMinorProgBar), TRUE);
|
||||
gtk_progress_bar_update(GTK_PROGRESS_BAR(sMinorProgBar), 1);
|
||||
gtk_progress_bar_update(GTK_PROGRESS_BAR(sMinorProgBar), percent);
|
||||
gtk_widget_show(sMinorProgBar);
|
||||
|
||||
/* tack on XPInstall action */
|
||||
memset(msg, 0, 64);
|
||||
colon = strchr(aMsg, ':');
|
||||
if (colon)
|
||||
strncpy(msg, aMsg, colon - aMsg);
|
||||
@ -456,32 +383,67 @@ nsInstallDlg::XPIProgressCB(const char *aMsg, int aVal, int aMax)
|
||||
gtk_label_set_text(GTK_LABEL(sMinorLabel), msg);
|
||||
gtk_widget_draw(sMinorLabel, NULL);
|
||||
|
||||
while (gtk_events_pending())
|
||||
gtk_main_iteration();
|
||||
XI_GTK_UPDATE_UI();
|
||||
}
|
||||
|
||||
void
|
||||
nsInstallDlg::MajorProgressCB(char *aCompName, int aCompNum, int aTotalComps)
|
||||
nsInstallDlg::MajorProgressCB(char *aName, int aNum, int aTotal, int aActivity)
|
||||
{
|
||||
// DUMP("MajorProgressCB");
|
||||
|
||||
char msg[256];
|
||||
|
||||
if (!aCompName)
|
||||
if (!aName)
|
||||
return;
|
||||
|
||||
memset(msg, 0, 256);
|
||||
sprintf(msg, INSTALLING_XPI, aCompName);
|
||||
|
||||
gtk_label_set_text(GTK_LABEL(sMajorLabel), "");
|
||||
gtk_widget_show(sMajorLabel);
|
||||
#ifdef DEBUG
|
||||
printf("%s %d: Name = %s\tNum = %d\tTotal = %d\tAct = %d\n",
|
||||
__FILE__, __LINE__, aName, aNum, aTotal, aActivity);
|
||||
#endif
|
||||
|
||||
switch (aActivity)
|
||||
{
|
||||
case ACT_DOWNLOAD:
|
||||
if (bDownload)
|
||||
sprintf(msg, DOWNLOADING, aName);
|
||||
else
|
||||
sprintf(msg, PREPARING, aName);
|
||||
break;
|
||||
|
||||
case ACT_EXTRACT:
|
||||
sprintf(msg, EXTRACTING, aName);
|
||||
break;
|
||||
|
||||
case ACT_INSTALL:
|
||||
sprintf(msg, INSTALLING_XPI, aName);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
gtk_label_set_text(GTK_LABEL(sMajorLabel), msg);
|
||||
gtk_widget_show(sMajorLabel);
|
||||
|
||||
if (aTotalComps <= 0)
|
||||
if (aTotal <= 0)
|
||||
{
|
||||
XI_ASSERT(0, "aTotal was <= 0");
|
||||
XI_GTK_UPDATE_UI();
|
||||
return;
|
||||
}
|
||||
|
||||
gfloat percent = (gfloat)((gfloat)aCompNum/(gfloat)aTotalComps);
|
||||
gfloat percent = (gfloat)((gfloat)aNum/(gfloat)aTotal);
|
||||
gtk_progress_bar_update(GTK_PROGRESS_BAR(sMajorProgBar), percent);
|
||||
gtk_widget_show(sMajorProgBar);
|
||||
|
||||
// reset minor progress ui
|
||||
if (aActivity == ACT_INSTALL)
|
||||
{
|
||||
gtk_label_set_text(GTK_LABEL(sMinorLabel), "");
|
||||
gtk_progress_bar_update(GTK_PROGRESS_BAR(sMinorProgBar), (gfloat)0);
|
||||
gtk_widget_show(sMinorLabel);
|
||||
gtk_widget_show(sMinorProgBar);
|
||||
}
|
||||
|
||||
XI_GTK_UPDATE_UI();
|
||||
}
|
||||
|
@ -40,17 +40,16 @@ public:
|
||||
static void Back(GtkWidget *aWidget, gpointer aData);
|
||||
static void Next(GtkWidget *aWidget, gpointer aData);
|
||||
|
||||
int Parse(nsINIParser* aParser);
|
||||
int Parse(nsINIParser* aParser);
|
||||
|
||||
int Show(int aDirection);
|
||||
int Hide(int aDirection);
|
||||
int Show(int aDirection);
|
||||
int Hide(int aDirection);
|
||||
|
||||
static void *WorkDammitWork(void *arg); // worker thread main
|
||||
static gint ProgressUpdater(gpointer aData);
|
||||
static void *WorkDammitWork(void *arg); // install start
|
||||
|
||||
static void XPIProgressCB(const char *aMsg, int aVal, int aMax);
|
||||
static void MajorProgressCB(char *aCompName, int aCompNum,
|
||||
int aTotalComps);
|
||||
static void XPIProgressCB(const char *aMsg, int aVal, int aMax);
|
||||
static void MajorProgressCB(char *aName, int aNum, int aTotal,
|
||||
int aActivity);
|
||||
|
||||
enum
|
||||
{
|
||||
@ -62,11 +61,11 @@ public:
|
||||
/*------------------------------------------------------------------*
|
||||
* INI Properties
|
||||
*------------------------------------------------------------------*/
|
||||
int SetMsg0(char *aMsg);
|
||||
char *GetMsg0();
|
||||
int SetMsg0(char *aMsg);
|
||||
char *GetMsg0();
|
||||
|
||||
private:
|
||||
char *mMsg0;
|
||||
char *mMsg0;
|
||||
};
|
||||
|
||||
#endif /* _NS_INSTALLDLG_H_ */
|
||||
|
@ -400,8 +400,8 @@ nsSetupTypeDlg::Show(int aDirection)
|
||||
|
||||
if (!gCtx->opt->mDestination)
|
||||
{
|
||||
gCtx->opt->mDestination = (char *) malloc(1024 * sizeof(char));
|
||||
getcwd(gCtx->opt->mDestination, 1024);
|
||||
gCtx->opt->mDestination = (char*)malloc(MAXPATHLEN * sizeof(char));
|
||||
getcwd(gCtx->opt->mDestination, MAXPATHLEN);
|
||||
}
|
||||
sFolder = gtk_label_new(gCtx->opt->mDestination);
|
||||
gtk_label_set_line_wrap(GTK_LABEL(sFolder), TRUE);
|
||||
@ -674,14 +674,13 @@ nsSetupTypeDlg::VerifyDestination()
|
||||
int stat_err = 0;
|
||||
struct stat dummy;
|
||||
GtkWidget *yesButton, *noButton, *label;
|
||||
char message[1024];
|
||||
char message[MAXPATHLEN];
|
||||
|
||||
stat_err = stat(gCtx->opt->mDestination, &dummy);
|
||||
if (stat_err == 0)
|
||||
return OK;
|
||||
|
||||
// destination doesn't exist so ask user if we should create it
|
||||
memset(message, 0, 1024);
|
||||
sprintf(message, DOESNT_EXIST, gCtx->opt->mDestination);
|
||||
|
||||
sCreateDestDlg = gtk_dialog_new();
|
||||
@ -752,7 +751,7 @@ nsSetupTypeDlg::DeleteOldInst()
|
||||
|
||||
int err = OK;
|
||||
struct stat dummy;
|
||||
char path[1024];
|
||||
char path[MAXPATHLEN];
|
||||
GtkWidget *label = NULL;
|
||||
GtkWidget *deleteBtn = NULL; /* delete button */
|
||||
GtkWidget *cancelBtn = NULL; /* cancel button */
|
||||
@ -760,7 +759,7 @@ nsSetupTypeDlg::DeleteOldInst()
|
||||
char *msg = NULL, *msgPtr = NULL, *msgChunkPtr = NULL;
|
||||
char msgChunk[65];
|
||||
|
||||
memset(path, 0, 1024);
|
||||
memset(path, 0, MAXPATHLEN);
|
||||
ConstructPath(path, gCtx->opt->mDestination, sLegacyChecks->GetFilename());
|
||||
DUMP(path);
|
||||
|
||||
@ -822,12 +821,11 @@ nsSetupTypeDlg::DeleteInstDelete(GtkWidget *aWidget, gpointer aData)
|
||||
{
|
||||
DUMP("DeleteInstDelete");
|
||||
|
||||
char cwd[1024];
|
||||
memset(cwd, 0, 1024);
|
||||
char cwd[MAXPATHLEN];
|
||||
|
||||
sDelInstUp = FALSE;
|
||||
|
||||
getcwd(cwd, 1024);
|
||||
getcwd(cwd, MAXPATHLEN);
|
||||
chdir(gCtx->opt->mDestination);
|
||||
system("rm -rf *");
|
||||
chdir(cwd);
|
||||
|
@ -53,8 +53,6 @@ nsXIContext::nsXIContext()
|
||||
nextID = 0;
|
||||
bMoving = FALSE;
|
||||
bDone = FALSE;
|
||||
|
||||
threadTurn = nsXIContext::UI_THREAD;
|
||||
}
|
||||
|
||||
nsXIContext::~nsXIContext()
|
||||
|
@ -25,9 +25,6 @@
|
||||
#ifndef _NS_XICONTEXT_H_
|
||||
#define _NS_XICONTEXT_H_
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#include "nsLicenseDlg.h"
|
||||
#include "nsWelcomeDlg.h"
|
||||
#include "nsSetupTypeDlg.h"
|
||||
@ -80,15 +77,6 @@ public:
|
||||
int bDone; /* engine thread sets boolean when done
|
||||
so that ui/main thread can exit */
|
||||
|
||||
pthread_mutex_t prog_mutex; /* mutex for sync between ui and eng th */
|
||||
pthread_cond_t prog_cv; /* cond var for ui/eng th communication */
|
||||
int threadTurn; /* toggle between engine and ui threads */
|
||||
enum
|
||||
{
|
||||
UI_THREAD = 0x0A,
|
||||
ENGINE_THREAD = 0x0F
|
||||
};
|
||||
|
||||
/*-------------------------------------------------------------------*
|
||||
* Utilities
|
||||
*-------------------------------------------------------------------*/
|
||||
|
@ -42,7 +42,9 @@ static char sCoreLibs[ CORE_LIB_COUNT * 2 ][ 32 ] =
|
||||
};
|
||||
|
||||
nsXIEngine::nsXIEngine() :
|
||||
mTmp(NULL)
|
||||
mTmp(NULL),
|
||||
mTotalComps(0),
|
||||
mOriginalDir(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
@ -50,15 +52,11 @@ nsXIEngine::~nsXIEngine()
|
||||
{
|
||||
DUMP("~nsXIEngine");
|
||||
|
||||
char cwd[1024];
|
||||
memset(cwd, 0, 1024);
|
||||
DUMP(cwd);
|
||||
|
||||
// rm tmp dir
|
||||
chdir("../..");
|
||||
rmdir(mTmp);
|
||||
// reset back to original directory
|
||||
chdir(mOriginalDir);
|
||||
|
||||
XI_IF_FREE(mTmp);
|
||||
XI_IF_FREE(mOriginalDir);
|
||||
}
|
||||
|
||||
int
|
||||
@ -82,9 +80,10 @@ nsXIEngine::Download(int aCustom, nsComponentList *aComps)
|
||||
return E_DIR_CREATE;
|
||||
|
||||
// if all .xpis exist in the ./xpi dir (blob/CD) we don't need to download
|
||||
if (ExistAllXPIs(aCustom, aComps))
|
||||
if (ExistAllXPIs(aCustom, aComps, &mTotalComps))
|
||||
return CopyToTmp(aCustom, aComps);
|
||||
|
||||
int currCompNum = 1;
|
||||
while (currComp)
|
||||
{
|
||||
if ( (aCustom == TRUE && currComp->IsSelected()) || (aCustom == FALSE) )
|
||||
@ -99,8 +98,16 @@ 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);
|
||||
|
||||
err = FTPAnonGet(currHost, currDir, currComp->GetArchive());
|
||||
if (err == OK) break; // no need to failover
|
||||
if (err == OK)
|
||||
{
|
||||
currCompNum++;
|
||||
break; // no need to failover
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -116,7 +123,7 @@ nsXIEngine::Extract(nsComponent *aXPIEngine)
|
||||
{
|
||||
DUMP("Extract");
|
||||
|
||||
char path[1024];
|
||||
char path[MAXPATHLEN];
|
||||
char bindir[512];
|
||||
char unzipcmd[512];
|
||||
struct stat dummy;
|
||||
@ -131,6 +138,10 @@ nsXIEngine::Extract(nsComponent *aXPIEngine)
|
||||
|
||||
for (i = 0; i < CORE_LIB_COUNT*2; i++)
|
||||
{
|
||||
// update UI
|
||||
nsInstallDlg::MajorProgressCB(sCoreLibs[i+1], ((i+2)/2),
|
||||
CORE_LIB_COUNT, nsInstallDlg::ACT_EXTRACT);
|
||||
|
||||
sprintf(unzipcmd, "unzip %s -d %s %s%s > /dev/null",
|
||||
path, mTmp, sCoreLibs[i], sCoreLibs[i+1]);
|
||||
i++;
|
||||
@ -152,27 +163,20 @@ nsXIEngine::Install(int aCustom, nsComponentList *aComps, char *aDestination)
|
||||
int err = OK;
|
||||
xpistub_t stub;
|
||||
char *old_LD_LIBRARY_PATH = NULL;
|
||||
char new_LD_LIBRARY_PATH[256];
|
||||
char new_LD_LIBRARY_PATH[MAXPATHLEN];
|
||||
int i;
|
||||
int compNum = 1;
|
||||
int totalComps;
|
||||
nsComponent *currComp = NULL;
|
||||
|
||||
if (!aComps || !aDestination)
|
||||
return E_PARAM;
|
||||
|
||||
// handle LD_LIBRARY_PATH settings
|
||||
memset(new_LD_LIBRARY_PATH, 0, 256);
|
||||
sprintf(new_LD_LIBRARY_PATH, "%s/bin:.", mTmp);
|
||||
DUMP(new_LD_LIBRARY_PATH);
|
||||
old_LD_LIBRARY_PATH = getenv("LD_LIBRARY_PATH");
|
||||
setenv("LD_LIBRARY_PATH", new_LD_LIBRARY_PATH, 1);
|
||||
|
||||
if (aCustom)
|
||||
totalComps = aComps->GetLengthSelected();
|
||||
else
|
||||
totalComps = aComps->GetLength();
|
||||
|
||||
currComp = aComps->GetHead();
|
||||
err = LoadXPIStub(&stub, aDestination);
|
||||
if (err == OK)
|
||||
@ -186,7 +190,7 @@ nsXIEngine::Install(int aCustom, nsComponentList *aComps, char *aDestination)
|
||||
(!aCustom) )
|
||||
{
|
||||
nsInstallDlg::MajorProgressCB(currComp->GetDescShort(),
|
||||
compNum, totalComps);
|
||||
compNum, mTotalComps, nsInstallDlg::ACT_INSTALL);
|
||||
err = InstallXPI(currComp, &stub);
|
||||
if (err != OK)
|
||||
ErrorHandler(err); // handle and continue
|
||||
@ -210,20 +214,14 @@ nsXIEngine::MakeUniqueTmpDir()
|
||||
{
|
||||
int err = OK;
|
||||
int i;
|
||||
char buf[1024];
|
||||
char cwd[1024];
|
||||
char buf[MAXPATHLEN];
|
||||
char cmd[1030];
|
||||
struct stat dummy;
|
||||
mTmp = NULL;
|
||||
|
||||
memset(cwd, 0, 1024);
|
||||
if (!getcwd(cwd, 1024))
|
||||
return E_MEM;
|
||||
|
||||
for (i = 0; i < MAX_TMP_DIRS; i++)
|
||||
{
|
||||
memset(buf, 0, 1024);
|
||||
sprintf(buf, TMP_DIR_TEMPLATE, cwd, i);
|
||||
sprintf(buf, TMP_DIR_TEMPLATE, i);
|
||||
if (-1 == stat(buf, &dummy))
|
||||
break;
|
||||
}
|
||||
@ -282,7 +280,7 @@ int
|
||||
nsXIEngine::FTPAnonGet(char *aHost, char *aDir, char *aArchive)
|
||||
{
|
||||
int err = OK;
|
||||
char qualifiedPath[1024];
|
||||
char qualifiedPath[MAXPATHLEN];
|
||||
char basename[256];
|
||||
char ftpcmds[1024];
|
||||
struct stat dummy;
|
||||
@ -316,8 +314,8 @@ nsXIEngine::LoadXPIStub(xpistub_t *aStub, char *aDestination)
|
||||
{
|
||||
int err = OK;
|
||||
|
||||
char libpath[1024];
|
||||
char libloc[1024];
|
||||
char libpath[MAXPATHLEN];
|
||||
char libloc[MAXPATHLEN];
|
||||
char *dlerr;
|
||||
nsresult rv = 0;
|
||||
|
||||
@ -327,14 +325,16 @@ nsXIEngine::LoadXPIStub(xpistub_t *aStub, char *aDestination)
|
||||
if (!aStub || !aDestination)
|
||||
return E_PARAM;
|
||||
|
||||
/* save original directory to reset it after installing */
|
||||
mOriginalDir = (char *) malloc(MAXPATHLEN * sizeof(char));
|
||||
getcwd(mOriginalDir, MAXPATHLEN);
|
||||
|
||||
/* chdir to library location for dll deps resolution */
|
||||
memset(libloc, 0, 1024);
|
||||
sprintf(libloc, "%s/bin", mTmp);
|
||||
chdir(libloc);
|
||||
|
||||
/* open the library */
|
||||
memset(libpath, 0, 1024);
|
||||
getcwd(libpath, 1024);
|
||||
getcwd(libpath, MAXPATHLEN);
|
||||
sprintf(libpath, "%s/%s", libpath, XPISTUB);
|
||||
|
||||
#ifdef DEBUG
|
||||
@ -387,13 +387,12 @@ int
|
||||
nsXIEngine::InstallXPI(nsComponent *aXPI, xpistub_t *aStub)
|
||||
{
|
||||
int err = OK;
|
||||
char xpipath[1024];
|
||||
char xpipath[MAXPATHLEN];
|
||||
nsresult rv = 0;
|
||||
|
||||
if (!aStub || !aXPI)
|
||||
return E_PARAM;
|
||||
|
||||
memset(xpipath, 0, 1024);
|
||||
sprintf(xpipath, "../%s", aXPI->GetArchive());
|
||||
DUMP(xpipath);
|
||||
|
||||
@ -456,19 +455,16 @@ nsXIEngine::ProgressCallback(const char* aMsg, PRInt32 aVal, PRInt32 aMax)
|
||||
{
|
||||
// DUMP("ProgressCallback");
|
||||
|
||||
pthread_mutex_lock(&gCtx->prog_mutex);
|
||||
|
||||
nsInstallDlg::XPIProgressCB(aMsg, (int)aVal, (int)aMax);
|
||||
|
||||
gCtx->threadTurn = nsXIContext::UI_THREAD;
|
||||
|
||||
pthread_cond_signal(&gCtx->prog_cv);
|
||||
pthread_mutex_unlock(&gCtx->prog_mutex);
|
||||
}
|
||||
|
||||
int
|
||||
nsXIEngine::ExistAllXPIs(int aCustom, nsComponentList *aComps)
|
||||
nsXIEngine::ExistAllXPIs(int aCustom, nsComponentList *aComps, int *aTotal)
|
||||
{
|
||||
// param check
|
||||
if (!aComps || !aTotal)
|
||||
return E_PARAM;
|
||||
|
||||
int bAllExist = TRUE;
|
||||
nsComponent *currComp = aComps->GetHead();
|
||||
char currArchivePath[256];
|
||||
@ -478,17 +474,18 @@ nsXIEngine::ExistAllXPIs(int aCustom, nsComponentList *aComps)
|
||||
{
|
||||
if ( (aCustom == TRUE && currComp->IsSelected()) || (aCustom == FALSE) )
|
||||
{
|
||||
memset(currArchivePath, 0, 256);
|
||||
sprintf(currArchivePath, "%s/%s", XPI_DIR, currComp->GetArchive());
|
||||
DUMP(currArchivePath);
|
||||
|
||||
if (0 != stat(currArchivePath, &dummy))
|
||||
return FALSE;
|
||||
|
||||
(*aTotal)++;
|
||||
}
|
||||
|
||||
currComp = currComp->GetNext();
|
||||
}
|
||||
|
||||
|
||||
return bAllExist;
|
||||
}
|
||||
|
||||
@ -499,14 +496,20 @@ nsXIEngine::CopyToTmp(int aCustom, nsComponentList *aComps)
|
||||
nsComponent *currComp = aComps->GetHead();
|
||||
char cmd[256];
|
||||
|
||||
int currCompNum = 1;
|
||||
while (currComp)
|
||||
{
|
||||
if ( (aCustom == TRUE && currComp->IsSelected()) || (aCustom == FALSE) )
|
||||
{
|
||||
memset(cmd, 0, 256);
|
||||
sprintf(cmd, "cp %s/%s %s", XPI_DIR, currComp->GetArchive(), mTmp);
|
||||
DUMP(cmd);
|
||||
|
||||
// update UI
|
||||
nsInstallDlg::MajorProgressCB(currComp->GetDescShort(),
|
||||
currCompNum, mTotalComps, nsInstallDlg::ACT_DOWNLOAD);
|
||||
|
||||
system(cmd);
|
||||
currCompNum++;
|
||||
}
|
||||
|
||||
currComp = currComp->GetNext();
|
||||
|
@ -75,7 +75,7 @@ public:
|
||||
int Install(int aCustom, nsComponentList *aComps, char *aDestination);
|
||||
|
||||
static void ProgressCallback(const char* aMsg, PRInt32 aVal, PRInt32 aMax);
|
||||
static int ExistAllXPIs(int aCustom, nsComponentList *aComps);
|
||||
static int ExistAllXPIs(int aCustom, nsComponentList *aComps, int *aTotal);
|
||||
|
||||
private:
|
||||
int MakeUniqueTmpDir();
|
||||
@ -87,6 +87,8 @@ private:
|
||||
int CopyToTmp(int aCustom, nsComponentList *aComps);
|
||||
|
||||
char *mTmp;
|
||||
int mTotalComps;
|
||||
char *mOriginalDir;
|
||||
};
|
||||
|
||||
#endif /* _NS_XIENGINE_H_ */
|
||||
|
@ -316,6 +316,6 @@ main(int argc, char **argv)
|
||||
|
||||
XI_IF_DELETE(installer);
|
||||
|
||||
exit(err);
|
||||
_exit(err);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user