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
parent e56aab3e18
commit 9bed38b495
7 changed files with 158 additions and 96 deletions

View File

@ -177,8 +177,8 @@ nsInstall::AddSubcomponent(const nsString& aRegName,
if (result != nsIDOMInstall::SU_SUCCESS)
{
SaveError( result );
return result;
*aReturn = SaveError( result );
return NS_OK;
}
@ -194,7 +194,8 @@ nsInstall::AddSubcomponent(const nsString& aRegName,
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 */
@ -235,7 +236,7 @@ nsInstall::AddSubcomponent(const nsString& aRegName,
if (versionNewer)
{
char* errorMsg = NULL;
PRInt32 error;
ie = new nsInstallFile( this,
*qualifiedRegName,
@ -244,17 +245,17 @@ nsInstall::AddSubcomponent(const nsString& aRegName,
aFolder,
aTargetName,
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);
return SUERR_UNEXPECTED_ERROR;
*aReturn = SaveError( error );
return NS_OK;
}
}
@ -288,6 +289,59 @@ nsInstall::Execute(const nsString& aJarSource, const nsString& aArgs, PRInt32* a
NS_IMETHODIMP
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;
}
@ -462,8 +516,9 @@ nsInstall::Uninstall(const nsString& aPackageName, PRInt32* aReturn)
}
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;
}
/////////////////////////////////////////////////////////////////////////
@ -476,10 +531,11 @@ nsInstall::ExtractFileFromJar(const nsString& aJarfile, const nsString& aFinalFi
* Do not call installedFiles.addElement directly, because this routine also
* handles progress messages
*/
char*
PRInt32
nsInstall::ScheduleForInstall(nsInstallObject* ob)
{
char *errorMsg = NULL;
PRInt32 error = SU_SUCCESS;
char *objString = ob->toString();
// flash current item
@ -488,11 +544,11 @@ nsInstall::ScheduleForInstall(nsInstallObject* ob)
PR_FREEIF(objString);
// do any unpacking or other set-up
errorMsg = ob->Prepare();
if (errorMsg != NULL)
{
return errorMsg;
}
error = ob->Prepare();
if (error != SU_SUCCESS)
return error;
// Add to installation list if we haven't thrown out
@ -507,7 +563,7 @@ nsInstall::ScheduleForInstall(nsInstallObject* ob)
if (ob->RegisterPackageNode())
mRegisterPackage = PR_TRUE;
return NULL;
return SU_SUCCESS;
}
@ -569,6 +625,10 @@ nsInstall::GetQualifiedPackageName( const nsString& name )
qualifedName = CurrentUserNode();
qualifedName->Insert( name, 7 );
}
else
{
qualifedName = new nsString(name);
}
if (BadRegName(qualifedName))
{
@ -704,6 +764,36 @@ nsInstall::SaveError(PRInt32 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
nsInstall::OpenJARFile(void)
@ -711,6 +801,10 @@ nsInstall::OpenJARFile(void)
return SU_SUCCESS;
}
void
nsInstall::CloseJARFile(void)
{
}
/////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////

View File

@ -55,7 +55,7 @@ class nsInstall: public nsIScriptObjectOwner, public nsIDOMInstall
/*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:
@ -85,8 +85,12 @@ class nsInstall: public nsIScriptObjectOwner, public nsIDOMInstall
PRBool BadRegName(nsString* regName);
PRInt32 SaveError(PRInt32 errcode);
void CleanUp();
PRInt32 OpenJARFile(void);
char* ScheduleForInstall(nsInstallObject* ob);
void CloseJARFile(void);
PRInt32 ScheduleForInstall(nsInstallObject* ob);
};

View File

@ -25,6 +25,8 @@
#include "prmem.h"
#include "plstr.h"
#include "nsFileSpec.h"
#include "VerReg.h"
#include "nsInstallFile.h"
@ -65,18 +67,16 @@ nsInstallFile::nsInstallFile(nsIDOMInstall* inInstall,
nsIDOMInstallFolder* folderSpec,
const nsString& inPartialPath,
PRBool forceInstall,
char* *errorMsg)
PRInt32 *error)
: nsInstallObject(inInstall)
{
mTempFile = nsnull;
mFinalFile = nsnull;
mUpgradeFile = PR_FALSE;
if ((folderSpec == NULL) || (inInstall == NULL) ||
(inVInfo == NULL))
if ((folderSpec == NULL) || (inInstall == NULL) || (inVInfo == NULL))
{
*errorMsg = nsInstallErrorMessages::GetErrorMsg( "Invalid arguments to the constructor",
nsIDOMInstall::SUERR_INVALID_ARGUMENTS);
*error = nsIDOMInstall::SUERR_INVALID_ARGUMENTS;
return;
}
@ -133,42 +133,17 @@ nsInstallFile::~nsInstallFile()
/* Prepare
* Extracts file out of the JAR archive into the temp directory
*/
char* nsInstallFile::Prepare()
PRInt32 nsInstallFile::Prepare()
{
char *errorMsg = NULL;
if (mInstall == NULL)
{
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);
if (mInstall == NULL || mFinalFile == NULL || mJarLocation == NULL)
return nsIDOMInstall::SUERR_INVALID_ARGUMENTS;
return errorMsg;
}
PRInt32 err;
mInstall->ExtractFileFromJar(*mJarLocation, *mFinalFile, *mTempFile, &err);
if (mFinalFile == NULL)
{
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;
return err;
}
/* Complete
@ -176,28 +151,15 @@ char* nsInstallFile::Prepare()
* - move the downloaded file to the final location
* - updates the registry
*/
char* nsInstallFile::Complete()
PRInt32 nsInstallFile::Complete()
{
int err;
int refCount;
int rc;
if (mInstall == NULL)
if (mInstall == NULL || mVersionRegistryName == NULL || mFinalFile == NULL)
{
return nsInstallErrorMessages::GetErrorMsg("nsSoftwareUpdate object is null",
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);
return nsIDOMInstall::SUERR_INVALID_ARGUMENTS;
}
/* Check the security for our target */
@ -329,10 +291,9 @@ char* nsInstallFile::Complete()
delete final_file;
if ( err != 0 )
{
return nsInstallErrorMessages::GetErrorMsg(nsIDOMInstall::SU_INSTALL_FILE_UNEXPECTED_MSG_ID, mFinalFile, err);
}
return NULL;
return nsIDOMInstall::SUERR_UNEXPECTED_ERROR;
return nsIDOMInstall::SU_SUCCESS;
}
void nsInstallFile::Abort()
@ -405,7 +366,8 @@ int nsInstallFile::NativeComplete()
}
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()
*/
result = -1;
@ -419,7 +381,7 @@ int nsInstallFile::NativeComplete()
if (stat(finalName, &finfo) == 0)
{
/* 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 )
{
}
@ -434,8 +396,12 @@ int nsInstallFile::NativeComplete()
if (end)
{
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;
if ( 0 == result )
{
@ -460,7 +426,7 @@ void nsInstallFile::AddToClasspath(nsString* file)
{
if ( file != NULL ) {
char *final_file = file->ToNewCString();
// JVM_AddToClassPath(final_file);
// FIX JVM_AddToClassPath(final_file);
delete final_file;
}
}

View File

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

View File

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

View File

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

View File

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