removing char* errormsgs and now using err code return values.

added FinishInstall().
This commit is contained in:
dougt%netscape.com 1999-02-05 22:27:08 +00:00
Родитель 45fcbcdc97
Коммит 1f509034a8
7 изменённых файлов: 158 добавлений и 96 удалений

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

@ -177,8 +177,8 @@ nsInstall::AddSubcomponent(const nsString& aRegName,
if (result != nsIDOMInstall::SU_SUCCESS) if (result != nsIDOMInstall::SU_SUCCESS)
{ {
SaveError( result ); *aReturn = SaveError( result );
return result; return NS_OK;
} }
@ -194,7 +194,8 @@ nsInstall::AddSubcomponent(const nsString& aRegName,
if (qualifiedRegName == nsnull) if (qualifiedRegName == nsnull)
{ {
return SUERR_BAD_PACKAGE_NAME; // this will stop the install script *aReturn = SaveError( SUERR_BAD_PACKAGE_NAME );
return NS_OK;
} }
/* Check for existence of the newer version */ /* Check for existence of the newer version */
@ -235,7 +236,7 @@ nsInstall::AddSubcomponent(const nsString& aRegName,
if (versionNewer) if (versionNewer)
{ {
char* errorMsg = NULL; PRInt32 error;
ie = new nsInstallFile( this, ie = new nsInstallFile( this,
*qualifiedRegName, *qualifiedRegName,
@ -244,17 +245,17 @@ nsInstall::AddSubcomponent(const nsString& aRegName,
aFolder, aFolder,
aTargetName, aTargetName,
aForceMode, aForceMode,
&errorMsg ); &error );
if (errorMsg == NULL) if (error == SU_SUCCESS)
{ {
errorMsg = ScheduleForInstall( ie ); error = ScheduleForInstall( ie );
} }
if (errorMsg != NULL) if (error != SU_SUCCESS)
{ {
SaveError( SUERR_UNEXPECTED_ERROR); *aReturn = SaveError( error );
return SUERR_UNEXPECTED_ERROR; return NS_OK;
} }
} }
@ -288,6 +289,59 @@ nsInstall::Execute(const nsString& aJarSource, const nsString& aArgs, PRInt32* a
NS_IMETHODIMP NS_IMETHODIMP
nsInstall::FinalizeInstall(PRInt32* aReturn) nsInstall::FinalizeInstall(PRInt32* aReturn)
{ {
PRBool rebootNeeded = PR_FALSE;
PRInt32 result = SanityCheck();
if (result != nsIDOMInstall::SU_SUCCESS)
{
*aReturn = SaveError( result );
return NS_OK;
}
if ( mInstalledFiles == NULL || mInstalledFiles->GetSize() == 0 )
{
// no actions queued: don't register the package version
// and no need for user confirmation
CleanUp();
return NS_OK;
}
nsInstallObject* ie = nsnull;
if ( mUninstallPackage )
{
char* packageName = mPackageName.ToNewCString();
char* userPackageName = mUserPackageName.ToNewCString();
// The Version Registry is not real. FIX!
//
//VR_UninstallCreateNode( packageName, userPackageName);
delete packageName;
delete userPackageName;
}
PRUint32 i=0;
for (i=0; i < mInstalledFiles->GetSize(); i++)
{
ie = (nsInstallObject*)mInstalledFiles->Get(i);
if (ie == NULL)
continue;
//CAN we get rid of char* crap?? FiX
//result = ie->Complete();
ie->Complete();
if (result != SU_SUCCESS)
{
ie->Abort();
*aReturn = SaveError( result );
return NS_OK;
}
//SetProgressDialogThermo(++count);
}
return NS_OK; return NS_OK;
} }
@ -462,8 +516,9 @@ nsInstall::Uninstall(const nsString& aPackageName, PRInt32* aReturn)
} }
NS_IMETHODIMP NS_IMETHODIMP
nsInstall::ExtractFileFromJar(const nsString& aJarfile, const nsString& aFinalFile, nsString& aTempFile, nsString& aErrorMsg) nsInstall::ExtractFileFromJar(const nsString& aJarfile, const nsString& aFinalFile, nsString& aTempFile, PRInt32* error)
{ {
*error = SU_SUCCESS;
return NS_OK; return NS_OK;
} }
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
@ -476,10 +531,11 @@ nsInstall::ExtractFileFromJar(const nsString& aJarfile, const nsString& aFinalFi
* Do not call installedFiles.addElement directly, because this routine also * Do not call installedFiles.addElement directly, because this routine also
* handles progress messages * handles progress messages
*/ */
char* PRInt32
nsInstall::ScheduleForInstall(nsInstallObject* ob) nsInstall::ScheduleForInstall(nsInstallObject* ob)
{ {
char *errorMsg = NULL; PRInt32 error = SU_SUCCESS;
char *objString = ob->toString(); char *objString = ob->toString();
// flash current item // flash current item
@ -488,11 +544,11 @@ nsInstall::ScheduleForInstall(nsInstallObject* ob)
PR_FREEIF(objString); PR_FREEIF(objString);
// do any unpacking or other set-up // do any unpacking or other set-up
errorMsg = ob->Prepare(); error = ob->Prepare();
if (errorMsg != NULL)
{ if (error != SU_SUCCESS)
return errorMsg; return error;
}
// Add to installation list if we haven't thrown out // Add to installation list if we haven't thrown out
@ -507,7 +563,7 @@ nsInstall::ScheduleForInstall(nsInstallObject* ob)
if (ob->RegisterPackageNode()) if (ob->RegisterPackageNode())
mRegisterPackage = PR_TRUE; mRegisterPackage = PR_TRUE;
return NULL; return SU_SUCCESS;
} }
@ -569,6 +625,10 @@ nsInstall::GetQualifiedPackageName( const nsString& name )
qualifedName = CurrentUserNode(); qualifedName = CurrentUserNode();
qualifedName->Insert( name, 7 ); qualifedName->Insert( name, 7 );
} }
else
{
qualifedName = new nsString(name);
}
if (BadRegName(qualifedName)) if (BadRegName(qualifedName))
{ {
@ -704,6 +764,36 @@ nsInstall::SaveError(PRInt32 errcode)
return errcode; return errcode;
} }
/*
* CleanUp
* call it when done with the install
*
* XXX: This is a synchronized method. FIX it.
*/
void
nsInstall::CleanUp(void)
{
nsInstallObject* ie;
CloseJARFile();
if ( mInstalledFiles != NULL )
{
PRUint32 i=0;
for (; i < mInstalledFiles->GetSize(); i++)
{
ie = (nsInstallObject*)mInstalledFiles->Get(i);
delete (ie);
}
mInstalledFiles->RemoveAll();
delete (mInstalledFiles);
mInstalledFiles = nsnull;
}
mPackageName = ""; // used to see if StartInstall() has been called
//CloseProgressDialog();
}
PRInt32 PRInt32
nsInstall::OpenJARFile(void) nsInstall::OpenJARFile(void)
@ -711,6 +801,10 @@ nsInstall::OpenJARFile(void)
return SU_SUCCESS; return SU_SUCCESS;
} }
void
nsInstall::CloseJARFile(void)
{
}
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// //
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////

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

@ -55,7 +55,7 @@ class nsInstall: public nsIScriptObjectOwner, public nsIDOMInstall
/*needs to be noscript*/ /*needs to be noscript*/
NS_IMETHOD ExtractFileFromJar(const nsString& aJarfile, const nsString& aFinalFile, nsString& aTempFile, nsString& aErrorMsg); NS_IMETHOD ExtractFileFromJar(const nsString& aJarfile, const nsString& aFinalFile, nsString& aTempFile, PRInt32* aError);
private: private:
@ -85,8 +85,12 @@ class nsInstall: public nsIScriptObjectOwner, public nsIDOMInstall
PRBool BadRegName(nsString* regName); PRBool BadRegName(nsString* regName);
PRInt32 SaveError(PRInt32 errcode); PRInt32 SaveError(PRInt32 errcode);
void CleanUp();
PRInt32 OpenJARFile(void); PRInt32 OpenJARFile(void);
char* ScheduleForInstall(nsInstallObject* ob); void CloseJARFile(void);
PRInt32 ScheduleForInstall(nsInstallObject* ob);
}; };

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

@ -25,6 +25,8 @@
#include "prmem.h" #include "prmem.h"
#include "plstr.h" #include "plstr.h"
#include "nsFileSpec.h"
#include "VerReg.h" #include "VerReg.h"
#include "nsInstallFile.h" #include "nsInstallFile.h"
@ -65,18 +67,16 @@ nsInstallFile::nsInstallFile(nsIDOMInstall* inInstall,
nsIDOMInstallFolder* folderSpec, nsIDOMInstallFolder* folderSpec,
const nsString& inPartialPath, const nsString& inPartialPath,
PRBool forceInstall, PRBool forceInstall,
char* *errorMsg) PRInt32 *error)
: nsInstallObject(inInstall) : nsInstallObject(inInstall)
{ {
mTempFile = nsnull; mTempFile = nsnull;
mFinalFile = nsnull; mFinalFile = nsnull;
mUpgradeFile = PR_FALSE; mUpgradeFile = PR_FALSE;
if ((folderSpec == NULL) || (inInstall == NULL) || if ((folderSpec == NULL) || (inInstall == NULL) || (inVInfo == NULL))
(inVInfo == NULL))
{ {
*errorMsg = nsInstallErrorMessages::GetErrorMsg( "Invalid arguments to the constructor", *error = nsIDOMInstall::SUERR_INVALID_ARGUMENTS;
nsIDOMInstall::SUERR_INVALID_ARGUMENTS);
return; return;
} }
@ -133,42 +133,17 @@ nsInstallFile::~nsInstallFile()
/* Prepare /* Prepare
* Extracts file out of the JAR archive into the temp directory * Extracts file out of the JAR archive into the temp directory
*/ */
char* nsInstallFile::Prepare() PRInt32 nsInstallFile::Prepare()
{ {
char *errorMsg = NULL; char *errorMsg = NULL;
if (mInstall == NULL) if (mInstall == NULL || mFinalFile == NULL || mJarLocation == NULL)
{ return nsIDOMInstall::SUERR_INVALID_ARGUMENTS;
errorMsg = nsInstallErrorMessages::GetErrorMsg("nsSoftwareUpdate object is null",
nsIDOMInstall::SUERR_INVALID_ARGUMENTS);
return errorMsg;
}
if (mJarLocation == NULL)
{
errorMsg = nsInstallErrorMessages::GetErrorMsg("JAR file is null",
nsIDOMInstall::SUERR_INVALID_ARGUMENTS);
return errorMsg; PRInt32 err;
} mInstall->ExtractFileFromJar(*mJarLocation, *mFinalFile, *mTempFile, &err);
if (mFinalFile == NULL) return err;
{
errorMsg = nsInstallErrorMessages::GetErrorMsg("folderSpec's full path (mFinalFile) was null",
nsIDOMInstall::SUERR_INVALID_ARGUMENTS);
return errorMsg;
}
nsString errString;
mInstall->ExtractFileFromJar(*mJarLocation, *mFinalFile, *mTempFile, errString);
if (errString != "")
{
return errString.ToNewCString();
}
return NULL;
} }
/* Complete /* Complete
@ -176,28 +151,15 @@ char* nsInstallFile::Prepare()
* - move the downloaded file to the final location * - move the downloaded file to the final location
* - updates the registry * - updates the registry
*/ */
char* nsInstallFile::Complete() PRInt32 nsInstallFile::Complete()
{ {
int err; int err;
int refCount; int refCount;
int rc; int rc;
if (mInstall == NULL) if (mInstall == NULL || mVersionRegistryName == NULL || mFinalFile == NULL)
{ {
return nsInstallErrorMessages::GetErrorMsg("nsSoftwareUpdate object is null", return nsIDOMInstall::SUERR_INVALID_ARGUMENTS;
nsIDOMInstall::SUERR_INVALID_ARGUMENTS);
}
if (mVersionRegistryName == NULL)
{
return nsInstallErrorMessages::GetErrorMsg("version registry name is null",
nsIDOMInstall::SUERR_INVALID_ARGUMENTS);
}
if (mFinalFile == NULL)
{
return nsInstallErrorMessages::GetErrorMsg("folderSpec's full path (mFinalFile) is null",
nsIDOMInstall::SUERR_INVALID_ARGUMENTS);
} }
/* Check the security for our target */ /* Check the security for our target */
@ -329,10 +291,9 @@ char* nsInstallFile::Complete()
delete final_file; delete final_file;
if ( err != 0 ) if ( err != 0 )
{ return nsIDOMInstall::SUERR_UNEXPECTED_ERROR;
return nsInstallErrorMessages::GetErrorMsg(nsIDOMInstall::SU_INSTALL_FILE_UNEXPECTED_MSG_ID, mFinalFile, err);
} return nsIDOMInstall::SU_SUCCESS;
return NULL;
} }
void nsInstallFile::Abort() void nsInstallFile::Abort()
@ -405,7 +366,8 @@ int nsInstallFile::NativeComplete()
} }
else else
{ {
/* Target exists, can't trust XP_FileRename--do platform /* FIX
* Target exists, can't trust XP_FileRename--do platform
* specific stuff in FE_ReplaceExistingFile() * specific stuff in FE_ReplaceExistingFile()
*/ */
result = -1; result = -1;
@ -419,7 +381,7 @@ int nsInstallFile::NativeComplete()
if (stat(finalName, &finfo) == 0) if (stat(finalName, &finfo) == 0)
{ {
/* File already exists, need to remove the original */ /* File already exists, need to remove the original */
// result = FE_ReplaceExistingFile(currentName, xpURL, finalName, xpURL, mForceInstall); // FIX result = FE_ReplaceExistingFile(currentName, xpURL, finalName, xpURL, mForceInstall);
if ( result == nsIDOMInstall::SU_REBOOT_NEEDED ) if ( result == nsIDOMInstall::SU_REBOOT_NEEDED )
{ {
} }
@ -434,8 +396,12 @@ int nsInstallFile::NativeComplete()
if (end) if (end)
{ {
end[0] = 0; end[0] = 0;
// FIX- this need to be made recursive?
result = PR_MkDir( finalName, 0); // Lame use of nsNativeFileSpec, but NSPR does not support creation
// of nested directories.
nsNativeFileSpec* directoryMaker = new nsNativeFileSpec(finalName, PR_TRUE);
delete directoryMaker;
end[0] = separator; end[0] = separator;
if ( 0 == result ) if ( 0 == result )
{ {
@ -460,7 +426,7 @@ void nsInstallFile::AddToClasspath(nsString* file)
{ {
if ( file != NULL ) { if ( file != NULL ) {
char *final_file = file->ToNewCString(); char *final_file = file->ToNewCString();
// JVM_AddToClassPath(final_file); // FIX JVM_AddToClassPath(final_file);
delete final_file; delete final_file;
} }
} }

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

@ -50,12 +50,12 @@ class nsInstallFile : public nsInstallObject
nsIDOMInstallFolder* folderSpec, nsIDOMInstallFolder* folderSpec,
const nsString& inPartialPath, const nsString& inPartialPath,
PRBool forceInstall, PRBool forceInstall,
char**errorMsg); PRInt32 *error);
virtual ~nsInstallFile(); virtual ~nsInstallFile();
char* Prepare(); PRInt32 Prepare();
char* Complete(); PRInt32 Complete();
void Abort(); void Abort();
char* toString(); char* toString();

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

@ -29,10 +29,10 @@ class nsInstallObject
nsInstallObject(nsIDOMInstall* inInstall) {mInstall = inInstall; } nsInstallObject(nsIDOMInstall* inInstall) {mInstall = inInstall; }
/* Override with your set-up action */ /* Override with your set-up action */
virtual char* Prepare() = 0; virtual PRInt32 Prepare() = 0;
/* Override with your Completion action */ /* Override with your Completion action */
virtual char* Complete() = 0; virtual PRInt32 Complete() = 0;
/* Override with an explanatory string for the progress dialog */ /* Override with an explanatory string for the progress dialog */
virtual char* toString() = 0; virtual char* toString() = 0;

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

@ -981,10 +981,10 @@ InstallExtractFileFromJar(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
{ {
nsIDOMInstall *nativeThis = (nsIDOMInstall*)JS_GetPrivate(cx, obj); nsIDOMInstall *nativeThis = (nsIDOMInstall*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE; JSBool rBool = JS_FALSE;
PRInt32 nativeRet;
nsAutoString b0; nsAutoString b0;
nsAutoString b1; nsAutoString b1;
nsAutoString b2; nsAutoString b2;
nsAutoString b3;
*rval = JSVAL_NULL; *rval = JSVAL_NULL;
@ -993,7 +993,7 @@ InstallExtractFileFromJar(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
return JS_TRUE; return JS_TRUE;
} }
if (argc >= 4) { if (argc >= 3) {
nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]); nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]);
@ -1001,16 +1001,14 @@ InstallExtractFileFromJar(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
nsJSUtils::nsConvertJSValToString(b2, cx, argv[2]); nsJSUtils::nsConvertJSValToString(b2, cx, argv[2]);
nsJSUtils::nsConvertJSValToString(b3, cx, argv[3]); if (NS_OK != nativeThis->ExtractFileFromJar(b0, b1, b2, &nativeRet)) {
if (NS_OK != nativeThis->ExtractFileFromJar(b0, b1, b2, b3)) {
return JS_FALSE; return JS_FALSE;
} }
*rval = JSVAL_VOID; *rval = INT_TO_JSVAL(nativeRet);
} }
else { else {
JS_ReportError(cx, "Function ExtractFileFromJar requires 4 parameters"); JS_ReportError(cx, "Function ExtractFileFromJar requires 3 parameters");
return JS_FALSE; return JS_FALSE;
} }
@ -1071,7 +1069,7 @@ static JSFunctionSpec InstallMethods[] =
{"SetPackageFolder", InstallSetPackageFolder, 1}, {"SetPackageFolder", InstallSetPackageFolder, 1},
{"StartInstall", InstallStartInstall, 4}, {"StartInstall", InstallStartInstall, 4},
{"Uninstall", InstallUninstall, 1}, {"Uninstall", InstallUninstall, 1},
{"ExtractFileFromJar", InstallExtractFileFromJar, 4}, {"ExtractFileFromJar", InstallExtractFileFromJar, 3},
{0} {0}
}; };

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

@ -93,7 +93,7 @@ static PRInt32 gLockCnt = 0;
nsSoftwareUpdate::nsSoftwareUpdate() nsSoftwareUpdate::nsSoftwareUpdate()
{ {
NS_INIT_REFCNT();
} }
nsSoftwareUpdate::~nsSoftwareUpdate() nsSoftwareUpdate::~nsSoftwareUpdate()