From a9e4b2ccd38223aed13f378dc9a340b1e96025b5 Mon Sep 17 00:00:00 2001 From: "dougt%netscape.com" Date: Sun, 18 Jul 1999 20:56:12 +0000 Subject: [PATCH] Fixes to address memory allocation problems - Bug #8227 --- xpinstall/src/nsInstall.cpp | 165 +++++++++++++++-- xpinstall/src/nsInstall.h | 2 + xpinstall/src/nsInstallDelete.cpp | 30 +++- xpinstall/src/nsInstallExecute.cpp | 9 +- xpinstall/src/nsInstallFile.cpp | 39 +++- xpinstall/src/nsInstallFileOpItem.cpp | 107 ++++++----- xpinstall/src/nsInstallFolder.cpp | 4 +- xpinstall/src/nsInstallPatch.cpp | 30 +++- xpinstall/src/nsInstallUninstall.cpp | 8 +- xpinstall/src/nsJSWinProfile.cpp | 4 +- xpinstall/src/nsJSWinReg.cpp | 22 +-- xpinstall/src/nsSoftwareUpdateRun.cpp | 3 + xpinstall/src/nsWinProfile.cpp | 82 ++++----- xpinstall/src/nsWinProfile.h | 18 +- xpinstall/src/nsWinProfileItem.cpp | 46 ++--- xpinstall/src/nsWinProfileItem.h | 8 +- xpinstall/src/nsWinReg.cpp | 241 +++++++++++++------------ xpinstall/src/nsWinReg.h | 56 +++--- xpinstall/src/nsWinRegItem.cpp | 244 +++++++++++++------------- xpinstall/src/nsWinRegItem.h | 12 +- 20 files changed, 697 insertions(+), 433 deletions(-) diff --git a/xpinstall/src/nsInstall.cpp b/xpinstall/src/nsInstall.cpp index 8c6f9a3aa627..9999832bc910 100644 --- a/xpinstall/src/nsInstall.cpp +++ b/xpinstall/src/nsInstall.cpp @@ -290,6 +290,12 @@ nsInstall::AddDirectory(const nsString& aRegName, nsVector *paths = new nsVector(); + if (paths == nsnull) + { + *aReturn = SaveError(nsInstall::OUT_OF_MEMORY); + return NS_OK; + } + result = ExtractDirEntries(aJarSource, paths); if (result != nsInstall::SUCCESS) { @@ -328,6 +334,12 @@ nsInstall::AddDirectory(const nsString& aRegName, aForceMode, &result); + if (ie == nsnull) + { + *aReturn = SaveError(nsInstall::OUT_OF_MEMORY); + return NS_OK; + } + if (result == nsInstall::SUCCESS) { result = ScheduleForInstall( ie ); @@ -456,6 +468,12 @@ nsInstall::AddSubcomponent(const nsString& aRegName, tempTargetName, aForceMode, &errcode ); + + if (ie == nsnull) + { + *aReturn = SaveError(nsInstall::OUT_OF_MEMORY); + return NS_OK; + } if (errcode == nsInstall::SUCCESS) { @@ -545,6 +563,13 @@ nsInstall::DeleteComponent(const nsString& aRegistryName, PRInt32* aReturn) } nsInstallDelete* id = new nsInstallDelete(this, "", qualifiedRegName, &result); + + if (id == nsnull) + { + *aReturn = SaveError(nsInstall::OUT_OF_MEMORY); + return NS_OK; + } + if (result == nsInstall::SUCCESS) { result = ScheduleForInstall( id ); @@ -568,6 +593,12 @@ nsInstall::DeleteFile(const nsString& aFolder, const nsString& aRelativeFileName nsInstallDelete* id = new nsInstallDelete(this, aFolder, aRelativeFileName, &result); + if (id == nsnull) + { + *aReturn = SaveError(nsInstall::OUT_OF_MEMORY); + return NS_OK; + } + if (result == nsInstall::SUCCESS) { result = ScheduleForInstall( id ); @@ -604,6 +635,12 @@ nsInstall::Execute(const nsString& aJarSource, const nsString& aArgs, PRInt32* a } nsInstallExecute* ie = new nsInstallExecute(this, aJarSource, aArgs, &result); + + if (ie == nsnull) + { + *aReturn = SaveError(nsInstall::OUT_OF_MEMORY); + return NS_OK; + } if (result == nsInstall::SUCCESS) { @@ -783,7 +820,9 @@ nsInstall::GetComponentFolder(const nsString& aComponentName, const nsString& aS *aFolder = new nsString(nsfsDir.GetNativePathCString()); } - delete [] componentCString; + if (componentCString) + delete [] componentCString; + return NS_OK; } @@ -800,11 +839,14 @@ nsInstall::GetFolder(const nsString& targetFolder, const nsString& aSubdirectory *aFolder = nsnull; spec = new nsInstallFolder(targetFolder, aSubdirectory); - - nsString dirString; - spec->GetDirectoryPath(dirString); + + if (spec != nsnull) + { + nsString dirString; + spec->GetDirectoryPath(dirString); - *aFolder = new nsString(dirString); + *aFolder = new nsString(dirString); + } return NS_OK; } @@ -824,22 +866,24 @@ nsInstall::GetLastError(PRInt32* aReturn) PRInt32 nsInstall::GetWinProfile(const nsString& aFolder, const nsString& aFile, JSContext* jscontext, JSClass* WinProfileClass, jsval* aReturn) { + *aReturn = JSVAL_NULL; + #ifdef _WINDOWS JSObject* winProfileObject; nsWinProfile* nativeWinProfileObject = new nsWinProfile(this, aFolder, aFile); + + if (nativeWinProfileObject == nsnull) + return NS_OK; + JSObject* winProfilePrototype = this->RetrieveWinProfilePrototype(); - + winProfileObject = JS_NewObject(jscontext, WinProfileClass, winProfilePrototype, NULL); if(winProfileObject == NULL) - { - return PR_FALSE; - } - + return NS_OK; + JS_SetPrivate(jscontext, winProfileObject, nativeWinProfileObject); *aReturn = OBJECT_TO_JSVAL(winProfileObject); -#else - *aReturn = JSVAL_NULL; #endif /* _WINDOWS */ return NS_OK; @@ -848,22 +892,24 @@ nsInstall::GetWinProfile(const nsString& aFolder, const nsString& aFile, JSConte PRInt32 nsInstall::GetWinRegistry(JSContext* jscontext, JSClass* WinRegClass, jsval* aReturn) { + *aReturn = JSVAL_NULL; + #ifdef _WINDOWS JSObject* winRegObject; nsWinReg* nativeWinRegObject = new nsWinReg(this); + + if (nativeWinRegObject == nsnull) + return NS_OK; + JSObject* winRegPrototype = this->RetrieveWinRegPrototype(); winRegObject = JS_NewObject(jscontext, WinRegClass, winRegPrototype, NULL); if(winRegObject == NULL) - { - return PR_FALSE; - } - + return NS_OK; + JS_SetPrivate(jscontext, winRegObject, nativeWinRegObject); *aReturn = OBJECT_TO_JSVAL(winRegObject); -#else - *aReturn = JSVAL_NULL; #endif /* _WINDOWS */ return NS_OK; @@ -1034,6 +1080,11 @@ nsInstall::Patch(const nsString& aRegName, const nsString& aVersion, const nsStr aTargetName, &result); + if (ip == nsnull) + { + *aReturn = SaveError(nsInstall::OUT_OF_MEMORY); + return NS_OK; + } if (result == nsInstall::SUCCESS) { @@ -1070,6 +1121,12 @@ nsInstall::StartInstall(const nsString& aUserPackageName, const nsString& aRegis { char szRegPackagePath[MAXREGPATHLEN]; char* szRegPackageName = aRegistryPackageName.ToNewCString(); + + if (szRegPackageName == nsnull) + { + *aReturn = SaveError(nsInstall::OUT_OF_MEMORY); + return NS_FALSE; + } *szRegPackagePath = '0'; *aReturn = nsInstall::SUCCESS; @@ -1109,10 +1166,22 @@ nsInstall::StartInstall(const nsString& aUserPackageName, const nsString& aRegis delete mVersionInfo; mVersionInfo = new nsInstallVersion(); + if (mVersionInfo == nsnull) + { + *aReturn = nsInstall::OUT_OF_MEMORY; + return nsInstall::OUT_OF_MEMORY; + } + mVersionInfo->Init(aVersion); mInstalledFiles = new nsVector(); mPatchList = new nsHashtable(); + + if (mInstalledFiles == nsnull || mPatchList == nsnull) + { + *aReturn = nsInstall::OUT_OF_MEMORY; + return nsInstall::OUT_OF_MEMORY; + } /* this function should also check security!!! */ *aReturn = OpenJARFile(); @@ -1156,6 +1225,12 @@ nsInstall::Uninstall(const nsString& aRegistryPackageName, PRInt32* aReturn) qualifiedPackageName, &result ); + if (ie == nsnull) + { + *aReturn = SaveError(nsInstall::OUT_OF_MEMORY); + return NS_OK; + } + if (result == nsInstall::SUCCESS) { result = ScheduleForInstall( ie ); @@ -1196,6 +1271,12 @@ nsInstall::FileOpDirCreate(nsFileSpec& aTarget, PRInt32* aReturn) { nsInstallFileOpItem* ifop = new nsInstallFileOpItem(this, NS_FOP_DIR_CREATE, aTarget, aReturn); + if (ifop == nsnull) + { + *aReturn = SaveError(nsInstall::OUT_OF_MEMORY); + return NS_OK; + } + if (*aReturn == nsInstall::SUCCESS) { *aReturn = ScheduleForInstall( ifop ); @@ -1226,6 +1307,12 @@ nsInstall::FileOpDirRemove(nsFileSpec& aTarget, PRInt32 aFlags, PRInt32* aReturn { nsInstallFileOpItem* ifop = new nsInstallFileOpItem(this, NS_FOP_DIR_REMOVE, aTarget, aFlags, aReturn); + if (ifop) + { + *aReturn = SaveError(nsInstall::OUT_OF_MEMORY); + return NS_OK; + } + if (*aReturn == nsInstall::SUCCESS) { *aReturn = ScheduleForInstall( ifop ); @@ -1246,6 +1333,12 @@ nsInstall::FileOpDirRename(nsFileSpec& aSrc, nsString& aTarget, PRInt32* aReturn { nsInstallFileOpItem* ifop = new nsInstallFileOpItem(this, NS_FOP_DIR_RENAME, aSrc, aTarget, aReturn); + if (ifop) + { + *aReturn = SaveError(nsInstall::OUT_OF_MEMORY); + return NS_OK; + } + if (*aReturn == nsInstall::SUCCESS) { *aReturn = ScheduleForInstall( ifop ); @@ -1266,6 +1359,12 @@ nsInstall::FileOpFileCopy(nsFileSpec& aSrc, nsFileSpec& aTarget, PRInt32* aRetur { nsInstallFileOpItem* ifop = new nsInstallFileOpItem(this, NS_FOP_FILE_COPY, aSrc, aTarget, aReturn); + if (ifop) + { + *aReturn = SaveError(nsInstall::OUT_OF_MEMORY); + return NS_OK; + } + if (*aReturn == nsInstall::SUCCESS) { *aReturn = ScheduleForInstall( ifop ); @@ -1286,6 +1385,12 @@ nsInstall::FileOpFileDelete(nsFileSpec& aTarget, PRInt32 aFlags, PRInt32* aRetur { nsInstallFileOpItem* ifop = new nsInstallFileOpItem(this, NS_FOP_FILE_DELETE, aTarget, aFlags, aReturn); + if (ifop) + { + *aReturn = SaveError(nsInstall::OUT_OF_MEMORY); + return NS_OK; + } + if (*aReturn == nsInstall::SUCCESS) { *aReturn = ScheduleForInstall( ifop ); @@ -1306,6 +1411,12 @@ nsInstall::FileOpFileExecute(nsFileSpec& aTarget, nsString& aParams, PRInt32* aR { nsInstallFileOpItem* ifop = new nsInstallFileOpItem(this, NS_FOP_FILE_EXECUTE, aTarget, aParams, aReturn); + if (ifop) + { + *aReturn = SaveError(nsInstall::OUT_OF_MEMORY); + return NS_OK; + } + if (*aReturn == nsInstall::SUCCESS) { *aReturn = ScheduleForInstall( ifop ); @@ -1381,6 +1492,12 @@ nsInstall::FileOpFileMove(nsFileSpec& aSrc, nsFileSpec& aTarget, PRInt32* aRetur { nsInstallFileOpItem* ifop = new nsInstallFileOpItem(this, NS_FOP_FILE_MOVE, aSrc, aTarget, aReturn); + if (ifop) + { + *aReturn = SaveError(nsInstall::OUT_OF_MEMORY); + return NS_OK; + } + if (*aReturn == nsInstall::SUCCESS) { *aReturn = ScheduleForInstall( ifop ); @@ -1401,6 +1518,12 @@ nsInstall::FileOpFileRename(nsFileSpec& aSrc, nsString& aTarget, PRInt32* aRetur { nsInstallFileOpItem* ifop = new nsInstallFileOpItem(this, NS_FOP_FILE_RENAME, aSrc, aTarget, aReturn); + if (ifop) + { + *aReturn = SaveError(nsInstall::OUT_OF_MEMORY); + return NS_OK; + } + if (*aReturn == nsInstall::SUCCESS) { *aReturn = ScheduleForInstall( ifop ); @@ -1798,11 +1921,17 @@ nsInstall::ExtractFileFromJar(const nsString& aJarfile, nsFileSpec* aSuggestedNa tempFile.MakeUnique(); extractHereSpec = new nsFileSpec(tempFile); + + if (extractHereSpec == nsnull) + return nsInstall::OUT_OF_MEMORY; } else { // extract to the final destination. extractHereSpec = new nsFileSpec(*aSuggestedName); + if (extractHereSpec == nsnull) + return nsInstall::OUT_OF_MEMORY; + extractHereSpec->MakeUnique(); } diff --git a/xpinstall/src/nsInstall.h b/xpinstall/src/nsInstall.h index 9c4c46c240ba..f6ef79914267 100644 --- a/xpinstall/src/nsInstall.h +++ b/xpinstall/src/nsInstall.h @@ -132,6 +132,8 @@ class nsInstall EXTRACTION_FAILED = -225, FILENAME_ALREADY_USED = -226, ABORT_INSTALL = -227, + + OUT_OF_MEMORY = -299, GESTALT_UNKNOWN_ERR = -5550, GESTALT_INVALID_ARGUMENT = -5551, diff --git a/xpinstall/src/nsInstallDelete.cpp b/xpinstall/src/nsInstallDelete.cpp index 28316bb4e3fa..b3cf48a3f841 100644 --- a/xpinstall/src/nsInstallDelete.cpp +++ b/xpinstall/src/nsInstallDelete.cpp @@ -55,6 +55,13 @@ nsInstallDelete::nsInstallDelete( nsInstall* inInstall, mFinalFile = new nsFileSpec(folderSpec); + + if (mFinalFile == nsnull) + { + *error = nsInstall::OUT_OF_MEMORY; + return; + } + *mFinalFile += inPartialPath; *error = ProcessInstallDelete(); @@ -103,8 +110,11 @@ PRInt32 nsInstallDelete::Complete() if (mDeleteStatus == DELETE_COMPONENT) { char* temp = mRegistryName.ToNewCString(); - err = VR_Remove(temp); - delete [] temp; + if (temp) + { + err = VR_Remove(temp); + delete [] temp; + } } if ((mDeleteStatus == DELETE_FILE) || (err == REGERR_OK)) @@ -128,11 +138,15 @@ char* nsInstallDelete::toString() { char* buffer = new char[1024]; + if (buffer == nsnull) + return nsnull; + if (mDeleteStatus == DELETE_COMPONENT) { char* temp = mRegistryName.ToNewCString(); sprintf( buffer, nsInstallResources::GetDeleteComponentString(), temp); - delete [] temp; + if (temp) + delete [] temp; } else { @@ -167,6 +181,9 @@ PRInt32 nsInstallDelete::ProcessInstallDelete() { /* Check if the component is in the registry */ tempCString = mRegistryName.ToNewCString(); + + if (tempCString == nsnull) + return nsInstall::OUT_OF_MEMORY; err = VR_InRegistry( tempCString ); @@ -180,6 +197,9 @@ PRInt32 nsInstallDelete::ProcessInstallDelete() tempRegistryString = (char*)PR_Calloc(MAXREGPATHLEN, sizeof(char)); + if (tempRegistryString == nsnull) + return nsInstall::OUT_OF_MEMORY; + err = VR_GetPath( tempCString , MAXREGPATHLEN, tempRegistryString); if (err == REGERR_OK) @@ -188,6 +208,10 @@ PRInt32 nsInstallDelete::ProcessInstallDelete() delete mFinalFile; mFinalFile = new nsFileSpec(tempRegistryString); + + if (mFinalFile == nsnull) + return nsInstall::OUT_OF_MEMORY; + } PR_FREEIF(tempRegistryString); diff --git a/xpinstall/src/nsInstallExecute.cpp b/xpinstall/src/nsInstallExecute.cpp index 5a27473349e8..d786c1ae0d54 100644 --- a/xpinstall/src/nsInstallExecute.cpp +++ b/xpinstall/src/nsInstallExecute.cpp @@ -105,20 +105,25 @@ char* nsInstallExecute::toString() { char* buffer = new char[1024]; + if (buffer == nsnull) + return nsnull; + // if the FileSpec is NULL, just us the in jar file name. if (mExecutableFile == nsnull) { char *tempString = mJarLocation.ToNewCString(); + sprintf( buffer, nsInstallResources::GetExecuteString(), tempString); - delete [] tempString; + + if (tempString) + delete [] tempString; } else { sprintf( buffer, nsInstallResources::GetExecuteString(), mExecutableFile->GetCString()); } return buffer; - } diff --git a/xpinstall/src/nsInstallFile.cpp b/xpinstall/src/nsInstallFile.cpp index 09d4759e5ecc..3434b9492e6f 100644 --- a/xpinstall/src/nsInstallFile.cpp +++ b/xpinstall/src/nsInstallFile.cpp @@ -73,6 +73,14 @@ nsInstallFile::nsInstallFile(nsInstall* inInstall, if ( (forceInstall == PR_FALSE ) && (inVInfo != "") && ( VR_ValidateComponent( qualifiedRegNameString ) == 0 ) ) { nsInstallVersion *newVersion = new nsInstallVersion(); + + if (newVersion == nsnull) + { + delete [] qualifiedRegNameString; + *error = nsInstall::OUT_OF_MEMORY; + return; + } + newVersion->Init(inVInfo); VERSION versionStruct; @@ -80,6 +88,14 @@ nsInstallFile::nsInstallFile(nsInstall* inInstall, VR_GetVersion( qualifiedRegNameString, &versionStruct ); nsInstallVersion* oldVersion = new nsInstallVersion(); + + if (newVersion == nsnull) + { + delete [] qualifiedRegNameString; + delete oldVersion; + *error = nsInstall::OUT_OF_MEMORY; + return; + } oldVersion->Init(versionStruct.major, versionStruct.minor, @@ -98,7 +114,7 @@ nsInstallFile::nsInstallFile(nsInstall* inInstall, areTheyEqual == nsIDOMInstallVersion::BLD_DIFF_MINUS ) { // the file to be installed is OLDER than what is on disk. Return error - delete qualifiedRegNameString; + delete [] qualifiedRegNameString; *error = areTheyEqual; return; } @@ -107,7 +123,13 @@ nsInstallFile::nsInstallFile(nsInstall* inInstall, delete [] qualifiedRegNameString; mFinalFile = new nsFileSpec(folderSpec); - + + if (mFinalFile == nsnull) + { + *error = nsInstall::OUT_OF_MEMORY; + return; + } + if ( mFinalFile->Exists() ) { // is there a file with the same name as the proposed folder? @@ -146,7 +168,15 @@ nsInstallFile::nsInstallFile(nsInstall* inInstall, mVersionRegistryName = new nsString(inComponentName); mJarLocation = new nsString(inJarLocation); mVersionInfo = new nsString(inVInfo); - + + if (mVersionRegistryName == nsnull || + mJarLocation == nsnull || + mVersionInfo == nsnull ) + { + *error = nsInstall::OUT_OF_MEMORY; + return; + } + nsString regPackageName; mInstall->GetRegPackageName(regPackageName); @@ -240,6 +270,9 @@ char* nsInstallFile::toString() { char* buffer = new char[1024]; + if (buffer == nsnull) + return nsnull; + if (mFinalFile == nsnull) { sprintf( buffer, nsInstallResources::GetInstallFileString(), nsnull); diff --git a/xpinstall/src/nsInstallFileOpItem.cpp b/xpinstall/src/nsInstallFileOpItem.cpp index 3ecafc9a6522..5c575b0a0ffa 100644 --- a/xpinstall/src/nsInstallFileOpItem.cpp +++ b/xpinstall/src/nsInstallFileOpItem.cpp @@ -30,15 +30,19 @@ nsInstallFileOpItem::nsInstallFileOpItem(nsInstall* aInstallObj, PRInt32* aReturn) :nsInstallObject(aInstallObj) { - mIObj = aInstallObj; + *aReturn = NS_OK; + + mIObj = aInstallObj; mCommand = aCommand; mFlags = aFlags; mSrc = nsnull; - mParams = nsnull; - mTarget = new nsFileSpec(aTarget); - mStrTarget = nsnull; + mParams = nsnull; + mStrTarget = nsnull; - *aReturn = NS_OK; + mTarget = new nsFileSpec(aTarget); + + if (mTarget == nsnull) + *aReturn = nsInstall::OUT_OF_MEMORY; } nsInstallFileOpItem::nsInstallFileOpItem(nsInstall* aInstallObj, @@ -48,15 +52,19 @@ nsInstallFileOpItem::nsInstallFileOpItem(nsInstall* aInstallObj, PRInt32* aReturn) :nsInstallObject(aInstallObj) { - mIObj = aInstallObj; + *aReturn = NS_OK; + + mIObj = aInstallObj; mCommand = aCommand; mFlags = 0; - mSrc = new nsFileSpec(aSrc); - mParams = nsnull; - mTarget = new nsFileSpec(aTarget); - mStrTarget = nsnull; - - *aReturn = NS_OK; + mParams = nsnull; + mStrTarget = nsnull; + + mSrc = new nsFileSpec(aSrc); + mTarget = new nsFileSpec(aTarget); + + if (mTarget == nsnull || mSrc == nsnull) + *aReturn = nsInstall::OUT_OF_MEMORY; } nsInstallFileOpItem::nsInstallFileOpItem(nsInstall* aInstallObj, @@ -65,15 +73,20 @@ nsInstallFileOpItem::nsInstallFileOpItem(nsInstall* aInstallObj, PRInt32* aReturn) :nsInstallObject(aInstallObj) { - mIObj = aInstallObj; + *aReturn = NS_OK; + + mIObj = aInstallObj; mCommand = aCommand; mFlags = 0; mSrc = nsnull; - mParams = nsnull; - mTarget = new nsFileSpec(aTarget); - mStrTarget = nsnull; + mParams = nsnull; + mStrTarget = nsnull; + + mTarget = new nsFileSpec(aTarget); + + if (mTarget == nsnull) + *aReturn = nsInstall::OUT_OF_MEMORY; - *aReturn = NS_OK; } nsInstallFileOpItem::nsInstallFileOpItem(nsInstall* aInstallObj, @@ -83,34 +96,36 @@ nsInstallFileOpItem::nsInstallFileOpItem(nsInstall* aInstallObj, PRInt32* aReturn) :nsInstallObject(aInstallObj) { - mIObj = aInstallObj; + *aReturn = NS_OK; + mIObj = aInstallObj; mCommand = aCommand; mFlags = 0; - switch(mCommand) - { - case NS_FOP_DIR_RENAME: - case NS_FOP_FILE_RENAME: - mSrc = new nsFileSpec(a1); - mTarget = nsnull; - mParams = nsnull; - mStrTarget = new nsString(a2); - break; - case NS_FOP_FILE_EXECUTE: - mSrc = nsnull; - mTarget = new nsFileSpec(a1); - mParams = new nsString(a2); - mStrTarget = nsnull; - break; - default: - mSrc = nsnull; - mTarget = new nsFileSpec(a1); - mParams = new nsString(a2); - mStrTarget = nsnull; - break; - } + switch(mCommand) + { + case NS_FOP_DIR_RENAME: + case NS_FOP_FILE_RENAME: + mSrc = new nsFileSpec(a1); + mTarget = nsnull; + mParams = nsnull; + mStrTarget = new nsString(a2); + + if (mSrc == nsnull || mStrTarget == nsnull) + *aReturn = nsInstall::OUT_OF_MEMORY; + + break; - *aReturn = NS_OK; + case NS_FOP_FILE_EXECUTE: + default: + mSrc = nsnull; + mTarget = new nsFileSpec(a1); + mParams = new nsString(a2); + mStrTarget = nsnull; + + if (mTarget == nsnull || mParams == nsnull) + *aReturn = nsInstall::OUT_OF_MEMORY; + break; + } } nsInstallFileOpItem::~nsInstallFileOpItem() @@ -175,7 +190,7 @@ float nsInstallFileOpItem::GetInstallOrder() char* nsInstallFileOpItem::toString() { - nsString result; + nsString result; char* resultCString; switch(mCommand) @@ -287,7 +302,9 @@ nsInstallFileOpItem::NativeFileOpDirRename(nsFileSpec* aSrc, nsString* aTarget) char* szTarget = aTarget->ToNewCString(); aSrc->Rename(szTarget); - delete [] szTarget; + + if (szTarget) + delete [] szTarget; return NS_OK; } @@ -326,7 +343,9 @@ nsInstallFileOpItem::NativeFileOpFileRename(nsFileSpec* aSrc, nsString* aTarget) char* szTarget = aTarget->ToNewCString(); aSrc->Rename(szTarget); - delete [] szTarget; + + if (szTarget) + delete [] szTarget; return NS_OK; } diff --git a/xpinstall/src/nsInstallFolder.cpp b/xpinstall/src/nsInstallFolder.cpp index 523d07ca1782..35beeceee945 100644 --- a/xpinstall/src/nsInstallFolder.cpp +++ b/xpinstall/src/nsInstallFolder.cpp @@ -303,8 +303,8 @@ nsInstallFolder::SetDirectoryPath(const nsString& aFolderID, const nsString& aRe mFileSpec = nsnull; return; } - - if (aRelativePath.Length() > 0) + + if (aRelativePath.Length() > 0 && mFileSpec) { nsString tempPath(aRelativePath); diff --git a/xpinstall/src/nsInstallPatch.cpp b/xpinstall/src/nsInstallPatch.cpp index 84ecfd548d4b..5bc77bdffe3d 100644 --- a/xpinstall/src/nsInstallPatch.cpp +++ b/xpinstall/src/nsInstallPatch.cpp @@ -88,11 +88,18 @@ nsInstallPatch::nsInstallPatch( nsInstall* inInstall, mRegistryName = new nsString(inVRName); mJarLocation = new nsString(inJarLocation); mTargetFile = new nsFileSpec(folderSpec); - mVersionInfo = new nsInstallVersion(); + if (mRegistryName == nsnull || + mJarLocation == nsnull || + mTargetFile == nsnull || + mVersionInfo == nsnull ) + { + *error = nsInstall::OUT_OF_MEMORY; + return; + } + mVersionInfo->Init(inVInfo); - } @@ -118,10 +125,20 @@ nsInstallPatch::nsInstallPatch( nsInstall* inInstall, mRegistryName = new nsString(inVRName); mJarLocation = new nsString(inJarLocation); mVersionInfo = new nsInstallVersion(); + mTargetFile = new nsFileSpec(folderSpec); + + if (mRegistryName == nsnull || + mJarLocation == nsnull || + mTargetFile == nsnull || + mVersionInfo == nsnull ) + { + *error = nsInstall::OUT_OF_MEMORY; + return; + } mVersionInfo->Init(inVInfo); - mTargetFile = new nsFileSpec(folderSpec); + if(inPartialPath != "null") *mTargetFile += inPartialPath; } @@ -247,8 +264,8 @@ PRInt32 nsInstallPatch::Complete() tempVersion, PR_FALSE ); - delete [] tempRegName; - delete [] tempVersion; + if (tempRegName) delete [] tempRegName; + if (tempVersion) delete [] tempVersion; } else @@ -281,6 +298,9 @@ void nsInstallPatch::Abort() char* nsInstallPatch::toString() { char* buffer = new char[1024]; + + if (buffer == nsnull) + return buffer; if (mTargetFile != nsnull) sprintf( buffer, nsInstallResources::GetPatchFileString(), mTargetFile->GetCString()); diff --git a/xpinstall/src/nsInstallUninstall.cpp b/xpinstall/src/nsInstallUninstall.cpp index e05c769898a1..2b0789b9bc4b 100644 --- a/xpinstall/src/nsInstallUninstall.cpp +++ b/xpinstall/src/nsInstallUninstall.cpp @@ -96,9 +96,15 @@ char* nsInstallUninstall::toString() { char* buffer = new char[1024]; + if (buffer == nsnull) + return buffer; + char* temp = mUIName.ToNewCString(); + sprintf( buffer, nsInstallResources::GetUninstallString(), temp); - delete [] temp; + + if (temp) + delete [] temp; return buffer; } diff --git a/xpinstall/src/nsJSWinProfile.cpp b/xpinstall/src/nsJSWinProfile.cpp index 925c5cdfd7f3..18baa5d8a205 100644 --- a/xpinstall/src/nsJSWinProfile.cpp +++ b/xpinstall/src/nsJSWinProfile.cpp @@ -80,7 +80,7 @@ WinProfileGetString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval ConvertJSValToStr(b0, cx, argv[0]); ConvertJSValToStr(b1, cx, argv[1]); - nativeThis->getString(b0, b1, &nativeRet); + nativeThis->GetString(b0, b1, &nativeRet); ConvertStrToJSVal(nativeRet, cx, rval); } @@ -123,7 +123,7 @@ WinProfileWriteString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsv ConvertJSValToStr(b1, cx, argv[1]); ConvertJSValToStr(b2, cx, argv[2]); - if(NS_OK != nativeThis->writeString(b0, b1, b2, &nativeRet)) + if(NS_OK != nativeThis->WriteString(b0, b1, b2, &nativeRet)) { return JS_FALSE; } diff --git a/xpinstall/src/nsJSWinReg.cpp b/xpinstall/src/nsJSWinReg.cpp index 35dd6dae8625..55f8a0ce0839 100644 --- a/xpinstall/src/nsJSWinReg.cpp +++ b/xpinstall/src/nsJSWinReg.cpp @@ -83,7 +83,7 @@ WinRegSetRootKey(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *r return JS_FALSE; } - if(NS_OK != nativeThis->setRootKey(b0)) + if(NS_OK != nativeThis->SetRootKey(b0)) { return JS_FALSE; } @@ -127,7 +127,7 @@ WinRegCreateKey(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rv ConvertJSValToStr(b0, cx, argv[0]); ConvertJSValToStr(b1, cx, argv[1]); - if(NS_OK != nativeThis->createKey(b0, b1, &nativeRet)) + if(NS_OK != nativeThis->CreateKey(b0, b1, &nativeRet)) { return JS_FALSE; } @@ -167,7 +167,7 @@ WinRegDeleteKey(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rv ConvertJSValToStr(b0, cx, argv[0]); - if(NS_OK != nativeThis->deleteKey(b0, &nativeRet)) + if(NS_OK != nativeThis->DeleteKey(b0, &nativeRet)) { return JS_FALSE; } @@ -211,7 +211,7 @@ WinRegDeleteValue(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval * ConvertJSValToStr(b0, cx, argv[0]); ConvertJSValToStr(b1, cx, argv[1]); - if(NS_OK != nativeThis->deleteValue(b0, b1, &nativeRet)) + if(NS_OK != nativeThis->DeleteValue(b0, b1, &nativeRet)) { return JS_FALSE; } @@ -257,7 +257,7 @@ WinRegSetValueString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsva ConvertJSValToStr(b1, cx, argv[1]); ConvertJSValToStr(b2, cx, argv[2]); - if(NS_OK != nativeThis->setValueString(b0, b1, b2, &nativeRet)) + if(NS_OK != nativeThis->SetValueString(b0, b1, b2, &nativeRet)) { return JS_FALSE; } @@ -300,7 +300,7 @@ WinRegGetValueString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsva ConvertJSValToStr(b0, cx, argv[0]); ConvertJSValToStr(b1, cx, argv[1]); - if(NS_OK != nativeThis->getValueString(b0, b1, &nativeRet)) + if(NS_OK != nativeThis->GetValueString(b0, b1, &nativeRet)) { return JS_FALSE; } @@ -357,7 +357,7 @@ WinRegSetValueNumber(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsva return JS_FALSE; } - if(NS_OK != nativeThis->setValueNumber(b0, b1, ib2, &nativeRet)) + if(NS_OK != nativeThis->SetValueNumber(b0, b1, ib2, &nativeRet)) { return JS_FALSE; } @@ -400,7 +400,7 @@ WinRegGetValueNumber(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsva ConvertJSValToStr(b0, cx, argv[0]); ConvertJSValToStr(b1, cx, argv[1]); - if(NS_OK != nativeThis->getValueNumber(b0, b1, &nativeRet)) + if(NS_OK != nativeThis->GetValueNumber(b0, b1, &nativeRet)) { return JS_FALSE; } @@ -449,7 +449,7 @@ WinRegSetValue(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rva // A way needs to be figured out to convert the JSVAL to this object type // ConvertJSValToStr(b2, cx, argv[2]); -// if(NS_OK != nativeThis->setValue(b0, b1, b2, &nativeRet)) +// if(NS_OK != nativeThis->SetValue(b0, b1, b2, &nativeRet)) // { // return JS_FALSE; // } @@ -492,7 +492,7 @@ WinRegGetValue(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rva ConvertJSValToStr(b0, cx, argv[0]); ConvertJSValToStr(b1, cx, argv[1]); - if(NS_OK != nativeThis->getValue(b0, b1, &nativeRet)) + if(NS_OK != nativeThis->GetValue(b0, b1, &nativeRet)) { return JS_FALSE; } @@ -529,7 +529,7 @@ WinRegInstallObject(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval // public int installObject (); - nativeRet = nativeThis->installObject(); + nativeRet = nativeThis->InstallObject(); *rval = INT_TO_JSVAL(nativeRet); return JS_TRUE; diff --git a/xpinstall/src/nsSoftwareUpdateRun.cpp b/xpinstall/src/nsSoftwareUpdateRun.cpp index fe82941314dc..7a65f1cb5a33 100644 --- a/xpinstall/src/nsSoftwareUpdateRun.cpp +++ b/xpinstall/src/nsSoftwareUpdateRun.cpp @@ -183,6 +183,9 @@ GetInstallScriptFromJarfile(const char* jarFile, char** scriptBuffer, PRUint32 * nsInputFileStream fileStream(installJSFileSpec); (fileStream.GetIStream())->GetLength(&bufferLength); buffer = new char[bufferLength + 1]; + + if (buffer == nsnull) + return NS_ERROR_FAILURE; rv = (fileStream.GetIStream())->Read(buffer, bufferLength, &readLength); diff --git a/xpinstall/src/nsWinProfile.cpp b/xpinstall/src/nsWinProfile.cpp index d11ef1448f1a..29bc11f61006 100644 --- a/xpinstall/src/nsWinProfile.cpp +++ b/xpinstall/src/nsWinProfile.cpp @@ -25,61 +25,63 @@ nsWinProfile::nsWinProfile( nsInstall* suObj, const nsString& folder, const nsString& file ) { - filename = new nsString(folder); - if(filename->Last() != '\\') + mFilename = new nsString(folder); + + if (mFilename) { - filename->Append("\\"); + if(mFilename->Last() != '\\') + { + mFilename->Append("\\"); + } + mFilename->Append(file); + + mInstallObject = suObj; } - filename->Append(file); - - su = suObj; - -// principal = suObj->GetPrincipal(); -// privMgr = nsPrivilegeManager::getPrivilegeManager(); -// impersonation = nsTarget::findTarget(IMPERSONATOR); -// target = (nsUserTarget*)nsTarget::findTarget(INSTALL_PRIV); } nsWinProfile::~nsWinProfile() { - delete filename; + if (mFilename) + delete mFilename; } PRInt32 -nsWinProfile::getString(nsString section, nsString key, nsString* aReturn) +nsWinProfile::GetString(nsString section, nsString key, nsString* aReturn) { - return nativeGetString(section, key, aReturn); + return NativeGetString(section, key, aReturn); } PRInt32 -nsWinProfile::writeString(nsString section, nsString key, nsString value, PRInt32* aReturn) +nsWinProfile::WriteString(nsString section, nsString key, nsString value, PRInt32* aReturn) { + *aReturn = NS_OK; + nsWinProfileItem* wi = new nsWinProfileItem(this, section, key, value); - *aReturn = NS_OK; + if(wi == nsnull) + return nsInstall::OUT_OF_MEMORY; - if(wi == NULL) - return PR_FALSE; - - su->ScheduleForInstall(wi); + if (mInstallObject) + mInstallObject->ScheduleForInstall(wi); + return NS_OK; } -nsString* nsWinProfile::getFilename() +nsString* nsWinProfile::GetFilename() { - return filename; + return mFilename; } -nsInstall* nsWinProfile::installObject() +nsInstall* nsWinProfile::InstallObject() { - return su; + return mInstallObject; } PRInt32 -nsWinProfile::finalWriteString( nsString section, nsString key, nsString value ) +nsWinProfile::FinalWriteString( nsString section, nsString key, nsString value ) { /* do we need another security check here? */ - return nativeWriteString(section, key, value); + return NativeWriteString(section, key, value); } /* Private Methods */ @@ -87,35 +89,35 @@ nsWinProfile::finalWriteString( nsString section, nsString key, nsString value ) #define STRBUFLEN 255 PRInt32 -nsWinProfile::nativeGetString(nsString section, nsString key, nsString* aReturn ) +nsWinProfile::NativeGetString(nsString section, nsString key, nsString* aReturn ) { - int numChars; + int numChars; char valbuf[STRBUFLEN]; char* sectionCString; char* keyCString; char* filenameCString; /* make sure conversions worked */ - if(section.First() != '\0' && key.First() != '\0' && filename->First() != '\0') + if(section.First() != '\0' && key.First() != '\0' && mFilename->First() != '\0') { sectionCString = section.ToNewCString(); keyCString = key.ToNewCString(); - filenameCString = filename->ToNewCString(); + filenameCString = mFilename->ToNewCString(); numChars = GetPrivateProfileString(sectionCString, keyCString, "", valbuf, STRBUFLEN, filenameCString); *aReturn = valbuf; - delete [] sectionCString; - delete [] keyCString; - delete [] filenameCString; + if (sectionCString) delete [] sectionCString; + if (keyCString) delete [] keyCString; + if (filenameCString) delete [] filenameCString; } return numChars; } PRInt32 -nsWinProfile::nativeWriteString( nsString section, nsString key, nsString value ) +nsWinProfile::NativeWriteString( nsString section, nsString key, nsString value ) { char* sectionCString; char* keyCString; @@ -124,19 +126,19 @@ nsWinProfile::nativeWriteString( nsString section, nsString key, nsString value int success = 0; /* make sure conversions worked */ - if(section.First() != '\0' && key.First() != '\0' && filename->First() != '\0') + if(section.First() != '\0' && key.First() != '\0' && mFilename->First() != '\0') { sectionCString = section.ToNewCString(); keyCString = key.ToNewCString(); valueCString = value.ToNewCString(); - filenameCString = filename->ToNewCString(); + filenameCString = mFilename->ToNewCString(); success = WritePrivateProfileString( sectionCString, keyCString, valueCString, filenameCString ); - delete [] sectionCString; - delete [] keyCString; - delete [] valueCString; - delete [] filenameCString; + if (sectionCString) delete [] sectionCString; + if (keyCString) delete [] keyCString; + if (valueCString) delete [] valueCString; + if (filenameCString) delete [] filenameCString; } return success; diff --git a/xpinstall/src/nsWinProfile.h b/xpinstall/src/nsWinProfile.h index 55da06990706..8ea929597959 100644 --- a/xpinstall/src/nsWinProfile.h +++ b/xpinstall/src/nsWinProfile.h @@ -42,7 +42,7 @@ class nsWinProfile * * @return false for failure, true for success */ - PRInt32 writeString( nsString section, nsString key, nsString value, PRInt32* aReturn ); + PRInt32 WriteString( nsString section, nsString key, nsString value, PRInt32* aReturn ); /** * Reads a value from a windows "ini" file. We don't support using @@ -50,23 +50,23 @@ class nsWinProfile * * @return String value from INI, "" if not found, null if error */ - PRInt32 getString( nsString section, nsString key, nsString* aReturn ); + PRInt32 GetString( nsString section, nsString key, nsString* aReturn ); - nsString* getFilename(); - nsInstall* installObject(); + nsString* GetFilename(); + nsInstall* InstallObject(); - PRInt32 finalWriteString( nsString section, nsString key, nsString value ); + PRInt32 FinalWriteString( nsString section, nsString key, nsString value ); private: /* Private Fields */ - nsString* filename; - nsInstall* su; + nsString* mFilename; + nsInstall* mInstallObject; /* Private Methods */ - PRInt32 nativeWriteString( nsString section, nsString key, nsString value ); - PRInt32 nativeGetString( nsString section, nsString key, nsString* aReturn ); + PRInt32 NativeWriteString( nsString section, nsString key, nsString value ); + PRInt32 NativeGetString( nsString section, nsString key, nsString* aReturn ); }; #endif /* nsWinProfile_h__ */ diff --git a/xpinstall/src/nsWinProfileItem.cpp b/xpinstall/src/nsWinProfileItem.cpp index 9927360665e0..0c31ff6e8b86 100644 --- a/xpinstall/src/nsWinProfileItem.cpp +++ b/xpinstall/src/nsWinProfileItem.cpp @@ -26,49 +26,55 @@ nsWinProfileItem::nsWinProfileItem(nsWinProfile* profileObj, nsString sectionName, nsString keyName, - nsString val) : nsInstallObject(profileObj->installObject()) + nsString val) : nsInstallObject(profileObj->InstallObject()) { - profile = profileObj; - section = new nsString(sectionName); - key = new nsString(keyName); - value = new nsString(val); + mProfile = profileObj; + mSection = new nsString(sectionName); + mKey = new nsString(keyName); + mValue = new nsString(val); } nsWinProfileItem::~nsWinProfileItem() { - delete profile; - delete section; - delete key; - delete value; + delete mProfile; // <-- is this the correct thing to do here?? FIX + if (mSection) delete mSection; + if (mKey) delete mKey; + if (mValue) delete mValue; } PRInt32 nsWinProfileItem::Complete() { - profile->finalWriteString(*section, *key, *value); - return NS_OK; + if (mProfile) + mProfile->FinalWriteString(*mSection, *mKey, *mValue); + + return NS_OK; } float nsWinProfileItem::GetInstallOrder() { - return 4; + return 4; // <--- what is this magic number?? FIX } char* nsWinProfileItem::toString() { char* resultCString; - nsString* result; - nsString* filename = new nsString(*profile->getFilename()); + + nsString* filename = new nsString(*mProfile->GetFilename()); + nsString* result = new nsString("Write "); + + if (filename == nsnull || result == nsnull) + return nsnull; - result = new nsString("Write "); result->Append(*filename); result->Append(": ["); - result->Append(*section); + result->Append(*mSection); result->Append("] "); - result->Append(*key); + result->Append(*mKey); result->Append("="); - result->Append(*value); + result->Append(*mValue); resultCString = result->ToNewCString(); + delete result; delete filename; @@ -92,7 +98,7 @@ PRInt32 nsWinProfileItem::Prepare() PRBool nsWinProfileItem::CanUninstall() { - return FALSE; + return PR_FALSE; } /* RegisterPackageNode @@ -102,6 +108,6 @@ nsWinProfileItem::CanUninstall() PRBool nsWinProfileItem::RegisterPackageNode() { - return TRUE; + return PR_TRUE; } diff --git a/xpinstall/src/nsWinProfileItem.h b/xpinstall/src/nsWinProfileItem.h index 8bca6aef1bc3..960771c8f324 100644 --- a/xpinstall/src/nsWinProfileItem.h +++ b/xpinstall/src/nsWinProfileItem.h @@ -65,10 +65,10 @@ public: private: /* Private Fields */ - nsWinProfile* profile; // initiating profile object - nsString* section; // Name of section - nsString* key; // Name of key - nsString* value; // data to write + nsWinProfile* mProfile; // initiating profile object + nsString* mSection; // Name of section + nsString* mKey; // Name of key + nsString* mValue; // data to write /* Private Methods */ diff --git a/xpinstall/src/nsWinReg.cpp b/xpinstall/src/nsWinReg.cpp index 34bb3f2a259a..56df8c65e56e 100644 --- a/xpinstall/src/nsWinReg.cpp +++ b/xpinstall/src/nsWinReg.cpp @@ -24,178 +24,191 @@ nsWinReg::nsWinReg(nsInstall* suObj) { - su = suObj; - rootkey = (PRInt32)HKEY_CLASSES_ROOT; + mInstallObject = suObj; + mRootKey = (PRInt32)HKEY_CLASSES_ROOT; } PRInt32 -nsWinReg::setRootKey(PRInt32 key) +nsWinReg::SetRootKey(PRInt32 key) { - rootkey = key; - return NS_OK; + mRootKey = key; + return NS_OK; } PRInt32 -nsWinReg::createKey(const nsString& subkey, const nsString& classname, PRInt32* aReturn) +nsWinReg::CreateKey(const nsString& subkey, const nsString& classname, PRInt32* aReturn) { - nsWinRegItem* wi = new nsWinRegItem(this, rootkey, NS_WIN_REG_CREATE, subkey, classname, "null"); + nsWinRegItem* wi = new nsWinRegItem(this, mRootKey, NS_WIN_REG_CREATE, subkey, classname, "null"); if(wi == nsnull) - { - return NS_OK; - } - su->ScheduleForInstall(wi); - return 0; + { + return NS_OK; + } + + if (mInstallObject) + mInstallObject->ScheduleForInstall(wi); + + return 0; } PRInt32 -nsWinReg::deleteKey(const nsString& subkey, PRInt32* aReturn) +nsWinReg::DeleteKey(const nsString& subkey, PRInt32* aReturn) { - nsWinRegItem* wi = new nsWinRegItem(this, rootkey, NS_WIN_REG_DELETE, subkey, "null", "null"); + nsWinRegItem* wi = new nsWinRegItem(this, mRootKey, NS_WIN_REG_DELETE, subkey, "null", "null"); if(wi == nsnull) - { - return NS_OK; - } - su->ScheduleForInstall(wi); - return 0; + { + return NS_OK; + } + + if (mInstallObject) + mInstallObject->ScheduleForInstall(wi); + + return 0; } PRInt32 -nsWinReg::deleteValue(const nsString& subkey, const nsString& valname, PRInt32* aReturn) +nsWinReg::DeleteValue(const nsString& subkey, const nsString& valname, PRInt32* aReturn) { - nsWinRegItem* wi = new nsWinRegItem(this, rootkey, NS_WIN_REG_DELETE_VAL, subkey, valname, "null"); + nsWinRegItem* wi = new nsWinRegItem(this, mRootKey, NS_WIN_REG_DELETE_VAL, subkey, valname, "null"); if(wi == nsnull) - { - return NS_OK; - } - su->ScheduleForInstall(wi); - return 0; + { + return NS_OK; + } + + if (mInstallObject) + mInstallObject->ScheduleForInstall(wi); + + return 0; } PRInt32 -nsWinReg::setValueString(const nsString& subkey, const nsString& valname, const nsString& value, PRInt32* aReturn) +nsWinReg::SetValueString(const nsString& subkey, const nsString& valname, const nsString& value, PRInt32* aReturn) { - nsWinRegItem* wi = new nsWinRegItem(this, rootkey, NS_WIN_REG_SET_VAL_STRING, subkey, valname, value); + nsWinRegItem* wi = new nsWinRegItem(this, mRootKey, NS_WIN_REG_SET_VAL_STRING, subkey, valname, value); if(wi == nsnull) - { - return NS_OK; - } - su->ScheduleForInstall(wi); - return 0; + { + return NS_OK; + } + + if (mInstallObject) + mInstallObject->ScheduleForInstall(wi); + + return 0; } PRInt32 -nsWinReg::getValueString(const nsString& subkey, const nsString& valname, nsString* aReturn) +nsWinReg::GetValueString(const nsString& subkey, const nsString& valname, nsString* aReturn) { - nativeGetValueString(subkey, valname, aReturn); - - return NS_OK; + NativeGetValueString(subkey, valname, aReturn); + return NS_OK; } PRInt32 -nsWinReg::setValueNumber(const nsString& subkey, const nsString& valname, PRInt32 value, PRInt32* aReturn) +nsWinReg::SetValueNumber(const nsString& subkey, const nsString& valname, PRInt32 value, PRInt32* aReturn) { - nsWinRegItem* wi = new nsWinRegItem(this, rootkey, NS_WIN_REG_SET_VAL_NUMBER, subkey, valname, value); + nsWinRegItem* wi = new nsWinRegItem(this, mRootKey, NS_WIN_REG_SET_VAL_NUMBER, subkey, valname, value); if(wi == nsnull) - { - return NS_OK; - } - su->ScheduleForInstall(wi); - return 0; + { + return NS_OK; + } + + if (mInstallObject) + mInstallObject->ScheduleForInstall(wi); + + return 0; } PRInt32 -nsWinReg::getValueNumber(const nsString& subkey, const nsString& valname, PRInt32* aReturn) +nsWinReg::GetValueNumber(const nsString& subkey, const nsString& valname, PRInt32* aReturn) { - nativeGetValueNumber(subkey, valname, aReturn); - - return NS_OK; + NativeGetValueNumber(subkey, valname, aReturn); + return NS_OK; } PRInt32 -nsWinReg::setValue(const nsString& subkey, const nsString& valname, nsWinRegValue* value, PRInt32* aReturn) +nsWinReg::SetValue(const nsString& subkey, const nsString& valname, nsWinRegValue* value, PRInt32* aReturn) { // fix: need to figure out what to do with nsWinRegValue class. // - // nsWinRegItem* wi = new nsWinRegItem(this, rootkey, NS_WIN_REG_SET_VAL, subkey, valname, (nsWinRegValue*)value); + // nsWinRegItem* wi = new nsWinRegItem(this, mRootKey, NS_WIN_REG_SET_VAL, subkey, valname, (nsWinRegValue*)value); // // if(wi == nsnull) // { // return NS_OK; // } - // su->ScheduleForInstall(wi); + // mInstallObject->ScheduleForInstall(wi); return 0; } PRInt32 -nsWinReg::getValue(const nsString& subkey, const nsString& valname, nsWinRegValue** aReturn) +nsWinReg::GetValue(const nsString& subkey, const nsString& valname, nsWinRegValue** aReturn) { // fix: return NS_OK; } -nsInstall* nsWinReg::installObject() +nsInstall* nsWinReg::InstallObject() { - return su; + return mInstallObject; } PRInt32 -nsWinReg::finalCreateKey(PRInt32 root, const nsString& subkey, const nsString& classname, PRInt32* aReturn) +nsWinReg::FinalCreateKey(PRInt32 root, const nsString& subkey, const nsString& classname, PRInt32* aReturn) { - setRootKey(root); - *aReturn = nativeCreateKey(subkey, classname); - return NS_OK; + SetRootKey(root); + *aReturn = NativeCreateKey(subkey, classname); + return NS_OK; } PRInt32 -nsWinReg::finalDeleteKey(PRInt32 root, const nsString& subkey, PRInt32* aReturn) +nsWinReg::FinalDeleteKey(PRInt32 root, const nsString& subkey, PRInt32* aReturn) { - setRootKey(root); - *aReturn = nativeDeleteKey(subkey); - return NS_OK; + SetRootKey(root); + *aReturn = NativeDeleteKey(subkey); + return NS_OK; } PRInt32 -nsWinReg::finalDeleteValue(PRInt32 root, const nsString& subkey, const nsString& valname, PRInt32* aReturn) +nsWinReg::FinalDeleteValue(PRInt32 root, const nsString& subkey, const nsString& valname, PRInt32* aReturn) { - setRootKey(root); - *aReturn = nativeDeleteValue(subkey, valname); - return NS_OK; + SetRootKey(root); + *aReturn = NativeDeleteValue(subkey, valname); + return NS_OK; } PRInt32 -nsWinReg::finalSetValueString(PRInt32 root, const nsString& subkey, const nsString& valname, const nsString& value, PRInt32* aReturn) +nsWinReg::FinalSetValueString(PRInt32 root, const nsString& subkey, const nsString& valname, const nsString& value, PRInt32* aReturn) { - setRootKey(root); - *aReturn = nativeSetValueString(subkey, valname, value); - return NS_OK; + SetRootKey(root); + *aReturn = NativeSetValueString(subkey, valname, value); + return NS_OK; } PRInt32 -nsWinReg::finalSetValueNumber(PRInt32 root, const nsString& subkey, const nsString& valname, PRInt32 value, PRInt32* aReturn) +nsWinReg::FinalSetValueNumber(PRInt32 root, const nsString& subkey, const nsString& valname, PRInt32 value, PRInt32* aReturn) { - setRootKey(root); - *aReturn = nativeSetValueNumber(subkey, valname, value); - return NS_OK; + SetRootKey(root); + *aReturn = NativeSetValueNumber(subkey, valname, value); + return NS_OK; } PRInt32 -nsWinReg::finalSetValue(PRInt32 root, const nsString& subkey, const nsString& valname, nsWinRegValue* value, PRInt32* aReturn) +nsWinReg::FinalSetValue(PRInt32 root, const nsString& subkey, const nsString& valname, nsWinRegValue* value, PRInt32* aReturn) { - setRootKey(root); - *aReturn = nativeSetValue(subkey, valname, value); - return NS_OK; + SetRootKey(root); + *aReturn = NativeSetValue(subkey, valname, value); + return NS_OK; } /* Private Methods */ PRInt32 -nsWinReg::nativeCreateKey(const nsString& subkey, const nsString& classname) +nsWinReg::NativeCreateKey(const nsString& subkey, const nsString& classname) { HKEY root, newkey; LONG result; @@ -204,7 +217,7 @@ nsWinReg::nativeCreateKey(const nsString& subkey, const nsString& classname) char* classnameCString = classname.ToNewCString(); #ifdef WIN32 - root = (HKEY)rootkey; + root = (HKEY)mRootKey; result = RegCreateKeyEx(root, subkeyCString, 0, classnameCString, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, nsnull, &newkey, &disposition); if(ERROR_SUCCESS == result) @@ -213,31 +226,31 @@ nsWinReg::nativeCreateKey(const nsString& subkey, const nsString& classname) } #endif - delete [] subkeyCString; - delete [] classnameCString; + if (subkeyCString) delete [] subkeyCString; + if (classnameCString) delete [] classnameCString; return result; } PRInt32 -nsWinReg::nativeDeleteKey(const nsString& subkey) +nsWinReg::NativeDeleteKey(const nsString& subkey) { HKEY root; LONG result; char* subkeyCString = subkey.ToNewCString(); #ifdef WIN32 - root = (HKEY) rootkey; + root = (HKEY) mRootKey; result = RegDeleteKey( root, subkeyCString ); #endif - delete [] subkeyCString; + if (subkeyCString) delete [] subkeyCString; return result; } PRInt32 -nsWinReg::nativeDeleteValue(const nsString& subkey, const nsString& valname) +nsWinReg::NativeDeleteValue(const nsString& subkey, const nsString& valname) { #if defined (WIN32) || defined (XP_OS2) HKEY root, newkey; @@ -245,7 +258,7 @@ nsWinReg::nativeDeleteValue(const nsString& subkey, const nsString& valname) char* subkeyCString = subkey.ToNewCString(); char* valnameCString = valname.ToNewCString(); - root = (HKEY) rootkey; + root = (HKEY) mRootKey; result = RegOpenKeyEx( root, subkeyCString, 0, KEY_WRITE, &newkey); if ( ERROR_SUCCESS == result ) @@ -254,8 +267,8 @@ nsWinReg::nativeDeleteValue(const nsString& subkey, const nsString& valname) RegCloseKey( newkey ); } - delete [] subkeyCString; - delete [] valnameCString; + if (subkeyCString) delete [] subkeyCString; + if (valnameCString) delete [] valnameCString; return result; #else @@ -264,7 +277,7 @@ nsWinReg::nativeDeleteValue(const nsString& subkey, const nsString& valname) } PRInt32 -nsWinReg::nativeSetValueString(const nsString& subkey, const nsString& valname, const nsString& value) +nsWinReg::NativeSetValueString(const nsString& subkey, const nsString& valname, const nsString& value) { HKEY root; HKEY newkey; @@ -277,7 +290,7 @@ nsWinReg::nativeSetValueString(const nsString& subkey, const nsString& valname, length = subkey.Length(); - root = (HKEY) rootkey; + root = (HKEY) mRootKey; result = RegOpenKeyEx( root, subkeyCString, 0, KEY_ALL_ACCESS, &newkey); if(ERROR_SUCCESS == result) @@ -286,9 +299,9 @@ nsWinReg::nativeSetValueString(const nsString& subkey, const nsString& valname, RegCloseKey( newkey ); } - delete [] subkeyCString; - delete [] valnameCString; - delete [] valueCString; + if (subkeyCString) delete [] subkeyCString; + if (valnameCString) delete [] valnameCString; + if (valueCString) delete [] valueCString; return result; } @@ -296,7 +309,7 @@ nsWinReg::nativeSetValueString(const nsString& subkey, const nsString& valname, #define STRBUFLEN 255 void -nsWinReg::nativeGetValueString(const nsString& subkey, const nsString& valname, nsString* aReturn) +nsWinReg::NativeGetValueString(const nsString& subkey, const nsString& valname, nsString* aReturn) { unsigned char valbuf[_MAXKEYVALUE_]; HKEY root; @@ -307,7 +320,7 @@ nsWinReg::nativeGetValueString(const nsString& subkey, const nsString& valname, char* subkeyCString = subkey.ToNewCString(); char* valnameCString = valname.ToNewCString(); - root = (HKEY) rootkey; + root = (HKEY) mRootKey; result = RegOpenKeyEx( root, subkeyCString, 0, KEY_READ, &newkey ); if ( ERROR_SUCCESS == result ) { @@ -321,12 +334,12 @@ nsWinReg::nativeGetValueString(const nsString& subkey, const nsString& valname, *aReturn = (char*)valbuf; } - delete [] subkeyCString; - delete [] valnameCString; + if (subkeyCString) delete [] subkeyCString; + if (valnameCString) delete [] valnameCString; } PRInt32 -nsWinReg::nativeSetValueNumber(const nsString& subkey, const nsString& valname, PRInt32 value) +nsWinReg::NativeSetValueNumber(const nsString& subkey, const nsString& valname, PRInt32 value) { HKEY root; HKEY newkey; @@ -335,7 +348,7 @@ nsWinReg::nativeSetValueNumber(const nsString& subkey, const nsString& valname, char* subkeyCString = subkey.ToNewCString(); char* valnameCString = valname.ToNewCString(); - root = (HKEY) rootkey; + root = (HKEY) mRootKey; result = RegOpenKeyEx( root, subkeyCString, 0, KEY_ALL_ACCESS, &newkey); if(ERROR_SUCCESS == result) @@ -344,14 +357,14 @@ nsWinReg::nativeSetValueNumber(const nsString& subkey, const nsString& valname, RegCloseKey( newkey ); } - delete [] subkeyCString; - delete [] valnameCString; + if (subkeyCString) delete [] subkeyCString; + if (valnameCString) delete [] valnameCString; return result; } void -nsWinReg::nativeGetValueNumber(const nsString& subkey, const nsString& valname, PRInt32* aReturn) +nsWinReg::NativeGetValueNumber(const nsString& subkey, const nsString& valname, PRInt32* aReturn) { PRInt32 valbuf; PRInt32 valbuflen; @@ -364,7 +377,7 @@ nsWinReg::nativeGetValueNumber(const nsString& subkey, const nsString& valname, char* valnameCString = valname.ToNewCString(); valbuflen = sizeof(PRInt32); - root = (HKEY) rootkey; + root = (HKEY) mRootKey; result = RegOpenKeyEx( root, subkeyCString, 0, KEY_READ, &newkey ); if ( ERROR_SUCCESS == result ) { @@ -378,12 +391,12 @@ nsWinReg::nativeGetValueNumber(const nsString& subkey, const nsString& valname, *aReturn = valbuf; } - delete [] subkeyCString; - delete [] valnameCString; + if (subkeyCString) delete [] subkeyCString; + if (valnameCString) delete [] valnameCString; } PRInt32 -nsWinReg::nativeSetValue(const nsString& subkey, const nsString& valname, nsWinRegValue* value) +nsWinReg::NativeSetValue(const nsString& subkey, const nsString& valname, nsWinRegValue* value) { #if defined (WIN32) || defined (XP_OS2) HKEY root; @@ -396,7 +409,7 @@ nsWinReg::nativeSetValue(const nsString& subkey, const nsString& valname, nsWinR char* valnameCString = valname.ToNewCString(); - root = (HKEY) rootkey; + root = (HKEY) mRootKey; result = RegOpenKeyEx( root, subkeyCString, 0, KEY_ALL_ACCESS, &newkey ); if(ERROR_SUCCESS == result) @@ -409,8 +422,8 @@ nsWinReg::nativeSetValue(const nsString& subkey, const nsString& valname, nsWinR RegCloseKey( newkey ); } - delete [] subkeyCString; - delete [] valnameCString; + if (subkeyCString) delete [] subkeyCString; + if (valnameCString) delete [] valnameCString; return result; #else @@ -419,7 +432,7 @@ nsWinReg::nativeSetValue(const nsString& subkey, const nsString& valname, nsWinR } nsWinRegValue* -nsWinReg::nativeGetValue(const nsString& subkey, const nsString& valname) +nsWinReg::NativeGetValue(const nsString& subkey, const nsString& valname) { #if defined (WIN32) || defined (XP_OS2) unsigned char valbuf[STRBUFLEN]; @@ -433,7 +446,7 @@ nsWinReg::nativeGetValue(const nsString& subkey, const nsString& valname) char* subkeyCString = subkey.ToNewCString(); char* valnameCString = valname.ToNewCString(); - root = (HKEY) rootkey; + root = (HKEY) mRootKey; result = RegOpenKeyEx( root, subkeyCString, 0, KEY_ALL_ACCESS, &newkey ); if(ERROR_SUCCESS == result) @@ -449,8 +462,8 @@ nsWinReg::nativeGetValue(const nsString& subkey, const nsString& valname) RegCloseKey( newkey ); } - delete [] subkeyCString; - delete [] valnameCString; + if (subkeyCString) delete [] subkeyCString; + if (valnameCString) delete [] valnameCString; return value; #else diff --git a/xpinstall/src/nsWinReg.h b/xpinstall/src/nsWinReg.h index c2d0c3491229..7e264ee63bba 100644 --- a/xpinstall/src/nsWinReg.h +++ b/xpinstall/src/nsWinReg.h @@ -59,45 +59,45 @@ class nsWinReg nsWinReg(nsInstall* suObj); - PRInt32 setRootKey(PRInt32 key); - PRInt32 createKey(const nsString& subkey, const nsString& classname, PRInt32* aReturn); - PRInt32 deleteKey(const nsString& subkey, PRInt32* aReturn); - PRInt32 deleteValue(const nsString& subkey, const nsString& valname, PRInt32* aReturn); - PRInt32 setValueString(const nsString& subkey, const nsString& valname, const nsString& value, PRInt32* aReturn); - PRInt32 getValueString(const nsString& subkey, const nsString& valname, nsString* aReturn); - PRInt32 setValueNumber(const nsString& subkey, const nsString& valname, PRInt32 value, PRInt32* aReturn); - PRInt32 getValueNumber(const nsString& subkey, const nsString& valname, PRInt32* aReturn); - PRInt32 setValue(const nsString& subkey, const nsString& valname, nsWinRegValue* value, PRInt32* aReturn); - PRInt32 getValue(const nsString& subkey, const nsString& valname, nsWinRegValue** aReturn); + PRInt32 SetRootKey(PRInt32 key); + PRInt32 CreateKey(const nsString& subkey, const nsString& classname, PRInt32* aReturn); + PRInt32 DeleteKey(const nsString& subkey, PRInt32* aReturn); + PRInt32 DeleteValue(const nsString& subkey, const nsString& valname, PRInt32* aReturn); + PRInt32 SetValueString(const nsString& subkey, const nsString& valname, const nsString& value, PRInt32* aReturn); + PRInt32 GetValueString(const nsString& subkey, const nsString& valname, nsString* aReturn); + PRInt32 SetValueNumber(const nsString& subkey, const nsString& valname, PRInt32 value, PRInt32* aReturn); + PRInt32 GetValueNumber(const nsString& subkey, const nsString& valname, PRInt32* aReturn); + PRInt32 SetValue(const nsString& subkey, const nsString& valname, nsWinRegValue* value, PRInt32* aReturn); + PRInt32 GetValue(const nsString& subkey, const nsString& valname, nsWinRegValue** aReturn); - nsInstall* installObject(void); + nsInstall* InstallObject(void); - PRInt32 finalCreateKey(PRInt32 root, const nsString& subkey, const nsString& classname, PRInt32* aReturn); - PRInt32 finalDeleteKey(PRInt32 root, const nsString& subkey, PRInt32* aReturn); - PRInt32 finalDeleteValue(PRInt32 root, const nsString& subkey, const nsString& valname, PRInt32* aReturn); - PRInt32 finalSetValueString(PRInt32 root, const nsString& subkey, const nsString& valname, const nsString& value, PRInt32* aReturn); - PRInt32 finalSetValueNumber(PRInt32 root, const nsString& subkey, const nsString& valname, PRInt32 value, PRInt32* aReturn); - PRInt32 finalSetValue(PRInt32 root, const nsString& subkey, const nsString& valname, nsWinRegValue* value, PRInt32* aReturn); + PRInt32 FinalCreateKey(PRInt32 root, const nsString& subkey, const nsString& classname, PRInt32* aReturn); + PRInt32 FinalDeleteKey(PRInt32 root, const nsString& subkey, PRInt32* aReturn); + PRInt32 FinalDeleteValue(PRInt32 root, const nsString& subkey, const nsString& valname, PRInt32* aReturn); + PRInt32 FinalSetValueString(PRInt32 root, const nsString& subkey, const nsString& valname, const nsString& value, PRInt32* aReturn); + PRInt32 FinalSetValueNumber(PRInt32 root, const nsString& subkey, const nsString& valname, PRInt32 value, PRInt32* aReturn); + PRInt32 FinalSetValue(PRInt32 root, const nsString& subkey, const nsString& valname, nsWinRegValue* value, PRInt32* aReturn); private: /* Private Fields */ - PRInt32 rootkey; - nsInstall* su; + PRInt32 mRootKey; + nsInstall* mInstallObject; /* Private Methods */ - PRInt32 nativeCreateKey(const nsString& subkey, const nsString& classname); - PRInt32 nativeDeleteKey(const nsString& subkey); - PRInt32 nativeDeleteValue(const nsString& subkey, const nsString& valname); + PRInt32 NativeCreateKey(const nsString& subkey, const nsString& classname); + PRInt32 NativeDeleteKey(const nsString& subkey); + PRInt32 NativeDeleteValue(const nsString& subkey, const nsString& valname); - PRInt32 nativeSetValueString(const nsString& subkey, const nsString& valname, const nsString& value); - void nativeGetValueString(const nsString& subkey, const nsString& valname, nsString* aReturn); - PRInt32 nativeSetValueNumber(const nsString& subkey, const nsString& valname, PRInt32 value); - void nativeGetValueNumber(const nsString& subkey, const nsString& valname, PRInt32* aReturn); + PRInt32 NativeSetValueString(const nsString& subkey, const nsString& valname, const nsString& value); + void NativeGetValueString(const nsString& subkey, const nsString& valname, nsString* aReturn); + PRInt32 NativeSetValueNumber(const nsString& subkey, const nsString& valname, PRInt32 value); + void NativeGetValueNumber(const nsString& subkey, const nsString& valname, PRInt32* aReturn); - PRInt32 nativeSetValue(const nsString& subkey, const nsString& valname, nsWinRegValue* value); - nsWinRegValue* nativeGetValue(const nsString& subkey, const nsString& valname); + PRInt32 NativeSetValue(const nsString& subkey, const nsString& valname, nsWinRegValue* value); + nsWinRegValue* NativeGetValue(const nsString& subkey, const nsString& valname); }; #endif /* __NS_WINREG_H__ */ diff --git a/xpinstall/src/nsWinRegItem.cpp b/xpinstall/src/nsWinRegItem.cpp index d2cf834d2765..d2a3cb5af13e 100644 --- a/xpinstall/src/nsWinRegItem.cpp +++ b/xpinstall/src/nsWinRegItem.cpp @@ -26,140 +26,134 @@ /* Public Methods */ nsWinRegItem::nsWinRegItem(nsWinReg* regObj, PRInt32 root, PRInt32 action, const nsString& sub, const nsString& valname, const nsString& val) -: nsInstallObject(regObj->installObject()) +: nsInstallObject(regObj->InstallObject()) { - reg = regObj; - command = action; - rootkey = root; + mReg = regObj; + mCommand = action; + mRootkey = root; /* I'm assuming we need to copy these */ - subkey = new nsString(sub); - name = new nsString(valname); - value = new nsString(val); + mSubkey = new nsString(sub); + mName = new nsString(valname); + mValue = new nsString(val); } nsWinRegItem::nsWinRegItem(nsWinReg* regObj, PRInt32 root, PRInt32 action, const nsString& sub, const nsString& valname, PRInt32 val) -: nsInstallObject(regObj->installObject()) +: nsInstallObject(regObj->InstallObject()) { - reg = regObj; - command = action; - rootkey = root; + mReg = regObj; + mCommand = action; + mRootkey = root; /* I'm assuming we need to copy these */ - subkey = new nsString(sub); - name = new nsString(valname); - value = new PRInt32(val); + mSubkey = new nsString(sub); + mName = new nsString(valname); + mValue = new PRInt32(val); } nsWinRegItem::~nsWinRegItem() { - delete reg; - delete subkey; - delete name; - delete value; + if (mReg) delete mReg; + if (mSubkey) delete mSubkey; + if (mName) delete mName; + if (mValue) delete mValue; } PRInt32 nsWinRegItem::Complete() { PRInt32 aReturn = NS_OK; + + if (mReg == nsnull) + return nsInstall::OUT_OF_MEMORY; - switch (command) + switch (mCommand) { case NS_WIN_REG_CREATE: - reg->finalCreateKey(rootkey, *subkey, *name, &aReturn); - break; + mReg->FinalCreateKey(mRootkey, *mSubkey, *mName, &aReturn); + break; + case NS_WIN_REG_DELETE: - reg->finalDeleteKey(rootkey, *subkey, &aReturn); - break; + mReg->FinalDeleteKey(mRootkey, *mSubkey, &aReturn); + break; + case NS_WIN_REG_DELETE_VAL: - reg->finalDeleteValue(rootkey, *subkey, *name, &aReturn); - break; + mReg->FinalDeleteValue(mRootkey, *mSubkey, *mName, &aReturn); + break; + case NS_WIN_REG_SET_VAL_STRING: - reg->finalSetValueString(rootkey, *subkey, *name, *(nsString*)value, &aReturn); - break; + mReg->FinalSetValueString(mRootkey, *mSubkey, *mName, *(nsString*)mValue, &aReturn); + break; + case NS_WIN_REG_SET_VAL_NUMBER: - reg->finalSetValueNumber(rootkey, *subkey, *name, *(PRInt32*)value, &aReturn); - break; + mReg->FinalSetValueNumber(mRootkey, *mSubkey, *mName, *(PRInt32*)mValue, &aReturn); + break; + case NS_WIN_REG_SET_VAL: - reg->finalSetValue(rootkey, *subkey, *name, (nsWinRegValue*)value, &aReturn); - break; + mReg->FinalSetValue(mRootkey, *mSubkey, *mName, (nsWinRegValue*)mValue, &aReturn); + break; } return aReturn; } float nsWinRegItem::GetInstallOrder() { - return 3; + return 3; // <-- what is this??? } #define kCRK "Create Registry Key " -#define kDRK "Delete Registry key " -#define kDRV "Delete Registry value " -#define kSRV "Store Registry value " +#define kDRK "Delete Registry Key " +#define kDRV "Delete Registry Value " +#define kSRV "Store Registry Value " #define kUNK "Unknown " char* nsWinRegItem::toString() { - nsString* keyString; - nsString* result; - char* resultCString; + nsString* keyString = nsnull; + nsString* result = nsnull; + char* resultCString = nsnull; - switch(command) + switch(mCommand) { - case NS_WIN_REG_CREATE: - keyString = keystr(rootkey, subkey, nsnull); - result = new nsString(kCRK); - result->Append(*keyString); - resultCString = result->ToNewCString(); - delete keyString; - delete result; - return resultCString; - case NS_WIN_REG_DELETE: - keyString = keystr(rootkey, subkey, nsnull); - result = new nsString(kDRK); - result->Append(*keyString); - resultCString = result->ToNewCString(); - delete keyString; - delete result; - return resultCString; - case NS_WIN_REG_DELETE_VAL: - keyString = keystr(rootkey, subkey, name); - result = new nsString(kDRV); - result->Append(*keyString); - resultCString = result->ToNewCString(); - delete keyString; - delete result; - return resultCString; - case NS_WIN_REG_SET_VAL_STRING: - keyString = keystr(rootkey, subkey, name); - result = new nsString(kSRV); - result->Append(*keyString); - resultCString = result->ToNewCString(); - delete keyString; - delete result; - return resultCString; - case NS_WIN_REG_SET_VAL: - keyString = keystr(rootkey, subkey, name); - result = new nsString(kSRV); - result->Append(*keyString); - resultCString = result->ToNewCString(); - delete keyString; - delete result; - return resultCString; - default: - keyString = keystr(rootkey, subkey, name); - result = new nsString(kUNK); - result->Append(*keyString); - resultCString = result->ToNewCString(); - delete keyString; - delete result; - return resultCString; + case NS_WIN_REG_CREATE: + keyString = keystr(mRootkey, mSubkey, nsnull); + result = new nsString(kCRK); + + case NS_WIN_REG_DELETE: + keyString = keystr(mRootkey, mSubkey, nsnull); + result = new nsString(kDRK); + + case NS_WIN_REG_DELETE_VAL: + keyString = keystr(mRootkey, mSubkey, mName); + result = new nsString(kDRV); + + case NS_WIN_REG_SET_VAL_STRING: + keyString = keystr(mRootkey, mSubkey, mName); + result = new nsString(kSRV); + + case NS_WIN_REG_SET_VAL: + keyString = keystr(mRootkey, mSubkey, mName); + result = new nsString(kSRV); + + default: + keyString = keystr(mRootkey, mSubkey, mName); + result = new nsString(kUNK); } + + if (result) + { + result->Append(*keyString); + resultCString = result->ToNewCString(); + } + + if (keyString) delete keyString; + if (result) delete result; + + return resultCString; } PRInt32 nsWinRegItem::Prepare() { - return NULL; + return nsnull; } void nsWinRegItem::Abort() @@ -168,45 +162,53 @@ void nsWinRegItem::Abort() /* Private Methods */ -nsString* nsWinRegItem::keystr(PRInt32 root, nsString* subkey, nsString* name) +nsString* nsWinRegItem::keystr(PRInt32 root, nsString* mSubkey, nsString* mName) { - nsString* rootstr; - nsString* finalstr; - char* istr; + nsString rootstr; + nsString* finalstr = nsnull; + char* istr = nsnull; switch(root) { - case (int)(HKEY_CLASSES_ROOT) : - rootstr = new nsString("\\HKEY_CLASSES_ROOT\\"); - break; - case (int)(HKEY_CURRENT_USER) : - rootstr = new nsString("\\HKEY_CURRENT_USER\\"); - break; - case (int)(HKEY_LOCAL_MACHINE) : - rootstr = new nsString("\\HKEY_LOCAL_MACHINE\\"); - break; - case (int)(HKEY_USERS) : - rootstr = new nsString("\\HKEY_USERS\\"); - break; - default: - istr = itoa(root); - rootstr = new nsString("\\#"); - rootstr->Append(istr); - rootstr->Append("\\"); - PR_DELETE(istr); - break; + case (int)(HKEY_CLASSES_ROOT) : + rootstr = "\\HKEY_CLASSES_ROOT\\"; + break; + + case (int)(HKEY_CURRENT_USER) : + rootstr = "\\HKEY_CURRENT_USER\\"; + break; + + case (int)(HKEY_LOCAL_MACHINE) : + rootstr = "\\HKEY_LOCAL_MACHINE\\"; + break; + + case (int)(HKEY_USERS) : + rootstr = "\\HKEY_USERS\\"; + break; + + default: + istr = itoa(root); + if (istr) + { + rootstr = "\\#"; + rootstr.Append(istr); + rootstr.Append("\\"); + + PR_DELETE(istr); + } + break; } - finalstr = new nsString(*rootstr); - if(name != nsnull) + finalstr = new nsString(rootstr); + if(mName != nsnull && finalstr != nsnull) { - finalstr->Append(*subkey); - finalstr->Append(" ["); - finalstr->Append(*name); - finalstr->Append("]"); + finalstr->Append(*mSubkey); + finalstr->Append(" ["); + finalstr->Append(*mName); + finalstr->Append("]"); } - delete rootstr; - return finalstr; + + return finalstr; } @@ -256,7 +258,7 @@ void nsWinRegItem::reverseString(char* s) PRBool nsWinRegItem:: CanUninstall() { - return FALSE; + return PR_FALSE; } /* RegisterPackageNode @@ -266,6 +268,6 @@ nsWinRegItem:: CanUninstall() PRBool nsWinRegItem:: RegisterPackageNode() { - return TRUE; + return PR_TRUE; } diff --git a/xpinstall/src/nsWinRegItem.h b/xpinstall/src/nsWinRegItem.h index 96aa7a006296..8442aadb6fc0 100644 --- a/xpinstall/src/nsWinRegItem.h +++ b/xpinstall/src/nsWinRegItem.h @@ -69,12 +69,12 @@ private: /* Private Fields */ - nsWinReg* reg; // initiating WinReg object - PRInt32 rootkey; - PRInt32 command; - nsString* subkey; // Name of section - nsString* name; // Name of key - void* value; // data to write + nsWinReg* mReg; // initiating WinReg object + PRInt32 mRootkey; + PRInt32 mCommand; + nsString* mSubkey; // Name of section + nsString* mName; // Name of key + void* mValue; // data to write /* Private Methods */