Installer now uses libjar for extraction eliminating the dependency on the

"unzip" command in the user's path.
[nsbeta3+ b=48109; r=ssu]
This commit is contained in:
sgehani%netscape.com 2000-08-18 22:10:44 +00:00
Родитель 00aa10a96d
Коммит ec2018a592
5 изменённых файлов: 221 добавлений и 48 удалений

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

@ -42,6 +42,7 @@ CPPSRCS = \
nsSetupTypeDlg.cpp \
nsComponentsDlg.cpp \
nsInstallDlg.cpp \
nsZipExtractor.cpp \
nsXIOptions.cpp \
nsXIContext.cpp \
nsXInstaller.cpp \
@ -51,6 +52,7 @@ CPPSRCS = \
LIBS = \
`gtk-config --libs` \
-ljar50_s \
$(NULL)
LOCAL_INCLUDES += -I$(srcdir)/../../../stub

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

@ -25,21 +25,6 @@
#include "nsXIEngine.h"
#define CORE_LIB_COUNT 10
static char sCoreLibs[ CORE_LIB_COUNT * 2 ][ 32 ] =
{
/* Archive Subdir File */
/* -------------- ---- */
"bin/", "libjsdom.so",
"bin/", "libmozjs.so",
"bin/", "libnspr4.so",
"bin/", "libplc4.so",
"bin/", "libplds4.so",
"bin/", "libxpcom.so",
"bin/", "libxpistub.so",
"bin/", "libzlib.so",
"bin/components/", "libxpinstall.so",
"bin/components/", "libjar50.so"
};
nsXIEngine::nsXIEngine() :
mTmp(NULL),
@ -121,38 +106,11 @@ nsXIEngine::Download(int aCustom, nsComponentList *aComps)
int
nsXIEngine::Extract(nsComponent *aXPIEngine)
{
DUMP("Extract");
char path[MAXPATHLEN];
char bindir[512];
char unzipcmd[512];
struct stat dummy;
int i;
if (!aXPIEngine || !(aXPIEngine->GetArchive()))
if (!aXPIEngine)
return E_PARAM;
sprintf(path, "%s/%s", mTmp, aXPIEngine->GetArchive());
if (-1 == stat(path, &dummy))
return E_NO_DOWNLOAD;
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++;
system(unzipcmd);
}
sprintf(bindir, "%s/%s", mTmp, TMP_EXTRACT_SUBDIR);
if (-1 == stat(bindir, &dummy))
return E_EXTRACTION;
return OK;
nsZipExtractor *unzip = new nsZipExtractor(mTmp);
return unzip->Extract(aXPIEngine, CORE_LIB_COUNT);
}
int
@ -215,7 +173,6 @@ nsXIEngine::MakeUniqueTmpDir()
int err = OK;
int i;
char buf[MAXPATHLEN];
char cmd[1030];
struct stat dummy;
mTmp = NULL;
@ -230,8 +187,7 @@ nsXIEngine::MakeUniqueTmpDir()
if (!mTmp) return E_MEM;
sprintf(mTmp, "%s", buf);
sprintf(cmd, "mkdir %s", mTmp);
system(cmd);
mkdir(mTmp, 0755);
return err;
}

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

@ -30,6 +30,7 @@
#include "nsComponent.h"
#include "nsComponentList.h"
#include "nsInstallDlg.h"
#include "nsZipExtractor.h"
#include "xpistub.h"

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

@ -0,0 +1,166 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Mozilla Communicator client code,
* released March 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Samir Gehani <sgehani@netscape.com>
*/
#include "nsZipExtractor.h"
#define STANDALONE 1
#include "zipstub.h"
#include "zipfile.h"
nsZipExtractor::nsZipExtractor(char *aTmp) :
mTmp(aTmp)
{
}
nsZipExtractor::~nsZipExtractor()
{
// don't free mTmp: we don't own it
}
int
nsZipExtractor::Extract(nsComponent *aXPIEngine, int aTotal)
{
DUMP("Extract");
char apath[MAXPATHLEN]; /* archive path */
char bindir[512];
char zpath[MAXPATHLEN]; /* path of file in zip archive */
char epath[MAXPATHLEN]; /* path of file after being extracted */
char *leaf = NULL, *lslash = NULL;
struct stat dummy;
int i, bFoundAll = FALSE, err = OK;
PRInt32 zerr = ZIP_OK;
void *hZip = NULL, *hFind = NULL;
if (!aXPIEngine || !(aXPIEngine->GetArchive()))
return E_PARAM;
sprintf(apath, "%s/%s", mTmp, aXPIEngine->GetArchive());
if (-1 == stat(apath, &dummy))
return E_NO_DOWNLOAD;
/* initialize archive etc.
*/
zerr = ZIP_OpenArchive(apath, &hZip);
if (zerr != ZIP_OK) return E_EXTRACTION;
hFind = ZIP_FindInit(hZip, (const char *) NULL);
if (!hFind)
{
err = E_EXTRACTION;
goto au_revoir;
}
/* extract files
*/
i = 0;
while (!bFoundAll)
{
memset(zpath, 0, MAXPATHLEN);
zerr = ZIP_FindNext(hFind, zpath, MAXPATHLEN);
if (zerr == ZIP_ERR_FNF)
{
bFoundAll = true;
break;
}
if (zerr != ZIP_OK)
{
err = E_EXTRACTION;
goto au_revoir;
}
/* directory encountered: ignore entry
*/
lslash = strrchr(zpath, '/');
if (lslash == (zpath + strlen(zpath) - 1))
continue;
if (!lslash)
leaf = zpath;
else
leaf = lslash + 1;
if (!leaf)
continue;
/* update UI
*/
nsInstallDlg::MajorProgressCB(leaf, i,
aTotal, nsInstallDlg::ACT_EXTRACT);
sprintf(epath, "%s/%s", mTmp, zpath);
err = DirCreateRecursive(epath);
if (err != OK) goto au_revoir;
zerr = ZIP_ExtractFile(hZip, zpath, epath);
if (zerr != ZIP_OK)
{
err = E_EXTRACTION;
goto au_revoir;
}
i++;
}
sprintf(bindir, "%s/%s", mTmp, TMP_EXTRACT_SUBDIR);
if (-1 == stat(bindir, &dummy))
err = E_EXTRACTION;
au_revoir:
/* close archive etc.
*/
if (hFind)
ZIP_FindFree(hFind);
if (hZip)
ZIP_CloseArchive(&hZip);
return err;
}
int
nsZipExtractor::DirCreateRecursive(char *aPath)
{
int err = OK;
char *slash = NULL, *pathpos = NULL;
char currdir[MAXPATHLEN];
struct stat dummy;
if (!aPath || !mTmp)
return E_PARAM;
slash = aPath + strlen(mTmp);
if (*slash != '/')
return E_INVALID_PTR;
while (slash)
{
memset(currdir, 0, MAXPATHLEN);
strncpy(currdir, aPath, slash - aPath);
if (-1 == stat(currdir, &dummy))
mkdir(currdir, 0755);
pathpos = slash;
slash = strchr(pathpos+1, '/');
}
return err;
}

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

@ -0,0 +1,48 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Mozilla Communicator client code,
* released March 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Samir Gehani <sgehani@netscape.com>
*/
#ifndef _NS_ZIPEXTRACTOR_H_
#define _NS_ZIPEXTRACTOR_H_
#include "XIDefines.h"
#include "nsComponent.h"
#include "nsXInstaller.h"
#include <sys/stat.h>
class nsZipExtractor
{
public:
nsZipExtractor(char *aTmp);
~nsZipExtractor();
int Extract(nsComponent *aXPIEngine, int aTotal);
private:
int DirCreateRecursive(char *aPath);
char *mTmp;
};
#endif /* _NS_ZIPEXTRACTOR_H_ */