From ff1dd2ab656cb6bf9c6dceb994bfd7c9aa32fb53 Mon Sep 17 00:00:00 2001 From: "dougt%netscape.com" Date: Mon, 24 Apr 2000 22:23:44 +0000 Subject: [PATCH] Fixing tree blocker. nsInstallFolder did not return an error code when it could not initialize itself. This caused crashes and return values which were not correct. I also fixed a huge about of memory leaks for allocation of strings that were never freed. r=dveditz, a=leaf. git-svn-id: svn://10.0.0.236/trunk@67001 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/xpinstall/src/nsInstall.cpp | 102 +++++++--- mozilla/xpinstall/src/nsInstallDelete.cpp | 5 +- mozilla/xpinstall/src/nsInstallFile.cpp | 9 +- mozilla/xpinstall/src/nsInstallFileOpItem.cpp | 39 ++-- mozilla/xpinstall/src/nsInstallFolder.cpp | 189 ++++++++---------- mozilla/xpinstall/src/nsInstallFolder.h | 6 +- mozilla/xpinstall/src/nsInstallPatch.cpp | 6 +- mozilla/xpinstall/src/nsJSFile.cpp | 8 +- mozilla/xpinstall/src/nsSoftwareUpdate.cpp | 22 +- mozilla/xpinstall/src/nsXPInstallManager.cpp | 37 ++-- 10 files changed, 244 insertions(+), 179 deletions(-) diff --git a/mozilla/xpinstall/src/nsInstall.cpp b/mozilla/xpinstall/src/nsInstall.cpp index 95440d5a347..4e15d9d4776 100644 --- a/mozilla/xpinstall/src/nsInstall.cpp +++ b/mozilla/xpinstall/src/nsInstall.cpp @@ -732,9 +732,9 @@ nsInstall::DiskSpaceAvailable(const nsString& aFolder, PRInt64* aReturn) LL_L2D(d, *aReturn); return NS_OK; } - + nsAutoCString temp(aFolder); nsCOMPtr folder; - NS_NewLocalFile(aFolder.ToNewCString(), getter_AddRefs(folder)); + NS_NewLocalFile(temp, getter_AddRefs(folder)); result = folder->GetDiskSpaceAvailable(aReturn); return NS_OK; @@ -962,13 +962,14 @@ nsInstall::GetComponentFolder(const nsString& aComponentName, const nsString& aS char* componentCString; char dir[MAXREGPATHLEN]; nsFileSpec nsfsDir; - + nsresult res = NS_OK; if(!aNewFolder) return INVALID_ARGUMENTS; - - *aNewFolder = nsnull; + *aNewFolder = nsnull; + + nsString tempString; if ( GetQualifiedPackageName(aComponentName, tempString) != SUCCESS ) @@ -1007,13 +1008,23 @@ nsInstall::GetComponentFolder(const nsString& aComponentName, const nsString& aS if(*dir != '\0') { - *aNewFolder = new nsInstallFolder(NS_ConvertASCIItoUCS2(dir), aSubdirectory); + nsInstallFolder * folder = new nsInstallFolder(); + if (!folder) return NS_ERROR_OUT_OF_MEMORY; + res = folder->Init(NS_ConvertASCIItoUCS2(dir), aSubdirectory); + if (NS_FAILED(res)) + { + delete folder; + } + else + { + *aNewFolder = folder; + } } if (componentCString) Recycle(componentCString); - return NS_OK; + return res; } PRInt32 @@ -1029,12 +1040,21 @@ nsInstall::GetFolder(const nsString& targetFolder, const nsString& aSubdirectory if (!aNewFolder) return INVALID_ARGUMENTS; - *aNewFolder = new nsInstallFolder(targetFolder, aSubdirectory); - if (*aNewFolder == nsnull) + * aNewFolder = nsnull; + + nsInstallFolder* folder = new nsInstallFolder(); + if (folder == nsnull) { return NS_ERROR_OUT_OF_MEMORY; } + nsresult res = folder->Init(targetFolder, aSubdirectory); + if (NS_FAILED(res)) + { + delete folder; + return res; + } + *aNewFolder = folder; return NS_OK; } @@ -1048,16 +1068,25 @@ nsInstall::GetFolder(const nsString& targetFolder, nsInstallFolder** aNewFolder) PRInt32 nsInstall::GetFolder( nsInstallFolder& aTargetFolderObj, const nsString& aSubdirectory, nsInstallFolder** aNewFolder ) { - /* This version of GetFolder takes a nsInstallFolder object as the first param */ + /* This version of GetFolder takes an nsString object as the first param */ if (!aNewFolder) return INVALID_ARGUMENTS; - - *aNewFolder = new nsInstallFolder(aTargetFolderObj, aSubdirectory); - if (*aNewFolder == nsnull) + + * aNewFolder = nsnull; + + nsInstallFolder* folder = new nsInstallFolder(); + if (folder == nsnull) { return NS_ERROR_OUT_OF_MEMORY; } + nsresult res = folder->Init(aTargetFolderObj, aSubdirectory); + if (NS_FAILED(res)) + { + delete folder; + return res; + } + *aNewFolder = folder; return NS_OK; } @@ -1354,9 +1383,20 @@ nsInstall::SetPackageFolder(nsInstallFolder& aFolder) { if (mPackageFolder) delete mPackageFolder; - - mPackageFolder = new nsInstallFolder(aFolder, nsAutoString()); + nsInstallFolder* folder = new nsInstallFolder(); + if (folder == nsnull) + { + return NS_ERROR_OUT_OF_MEMORY; + } + nsresult res = folder->Init(aFolder, nsAutoString()); + + if (NS_FAILED(res)) + { + delete folder; + return res; + } + mPackageFolder = folder; return NS_OK; } @@ -1398,7 +1438,21 @@ nsInstall::StartInstall(const nsString& aUserPackageName, const nsString& aRegis if(REGERR_OK == VR_GetDefaultDirectory(szRegPackageName, MAXREGPATHLEN, szRegPackagePath)) { - mPackageFolder = new nsInstallFolder(NS_ConvertASCIItoUCS2(szRegPackagePath), nsAutoString()); + nsInstallFolder* folder = new nsInstallFolder(); + if (folder == nsnull) + { + return NS_ERROR_OUT_OF_MEMORY; + } + nsresult res = folder->Init(NS_ConvertASCIItoUCS2(szRegPackagePath), nsAutoString()); + + if (NS_FAILED(res)) + { + delete folder; + } + else + { + mPackageFolder = folder; + } } else { @@ -1924,8 +1978,10 @@ nsInstall::FileOpFileMacAlias(nsString& aSourcePath, nsString& aAliasPath, PRInt nsCOMPtr nsfsSource; nsCOMPtr nsfsAlias; - NS_NewLocalFile(aSourcePath.ToNewCString(), getter_AddRefs(nsfsSource)); - NS_NewLocalFile(aAliasPath.ToNewCString(), getter_AddRefs(nsfsAlias)); + nsAutoCString tempSource(aSourcePath); + nsAutoCString tempAlias(aAliasPath); + NS_NewLocalFile(tempSource, getter_AddRefs(nsfsSource)); + NS_NewLocalFile(tempAlias, getter_AddRefs(nsfsAlias)); nsInstallFileOpItem* ifop = new nsInstallFileOpItem(this, NS_FOP_MAC_ALIAS, nsfsSource, nsfsAlias, aReturn); PRInt32 result = SanityCheck(); @@ -2342,8 +2398,8 @@ nsInstall::ExtractFileFromJar(const nsString& aJarfile, nsIFile* aSuggestedName, aJarfile.Right(extension, (aJarfile.Length() - extpos) ); tempFileName += extension; } - - tempFile->Append(tempFileName.ToNewCString()); + nsAutoCString temp(tempFileName); + tempFile->Append(temp); // Create a temporary file to extract to MakeUnique(tempFile); @@ -2453,10 +2509,8 @@ nsInstall::GetResourcedString(const nsString& aResName) */ if (!bStrBdlSuccess) { - char *cResName = aResName.ToNewCString(); - rscdStr.AssignWithConversion(nsInstallResources::GetDefaultVal(cResName)); - if (cResName) - Recycle(cResName); + nsAutoCString temp(aResName); + rscdStr.AssignWithConversion(nsInstallResources::GetDefaultVal(temp)); } return rscdStr.ToNewCString(); diff --git a/mozilla/xpinstall/src/nsInstallDelete.cpp b/mozilla/xpinstall/src/nsInstallDelete.cpp index 6568dd28c39..999b0a4c736 100644 --- a/mozilla/xpinstall/src/nsInstallDelete.cpp +++ b/mozilla/xpinstall/src/nsInstallDelete.cpp @@ -69,8 +69,9 @@ nsInstallDelete::nsInstallDelete( nsInstall* inInstall, *error = nsInstall::OUT_OF_MEMORY; return; } - - mFinalFile->Append(inPartialPath.ToNewCString()); + nsAutoCString tempPartialPath(inPartialPath); + + mFinalFile->Append(tempPartialPath); *error = ProcessInstallDelete(); } diff --git a/mozilla/xpinstall/src/nsInstallFile.cpp b/mozilla/xpinstall/src/nsInstallFile.cpp index 474e240b196..dd4037bb7b4 100644 --- a/mozilla/xpinstall/src/nsInstallFile.cpp +++ b/mozilla/xpinstall/src/nsInstallFile.cpp @@ -186,19 +186,22 @@ nsInstallFile::nsInstallFile(nsInstall* inInstall, location = inPartialPath.FindChar('/',PR_FALSE, offset); if ((location < 0) && (pass == 0)) //no separators were found { - mFinalFile->Append(inPartialPath.ToNewCString()); + nsAutoCString tempPartialPath(inPartialPath); + mFinalFile->Append(tempPartialPath); finished = PR_TRUE; } else if ((location < 0) && (pass > 0) && (offset < inPartialPath.mLength)) //last occurance { nsresult rv = inPartialPath.Mid(subString, offset, inPartialPath.mLength-offset); - mFinalFile->Append(subString.ToNewCString()); + nsAutoCString tempSubString(subString); + mFinalFile->Append(tempSubString); finished = PR_TRUE; } else { nsresult rv = inPartialPath.Mid(subString, offset, location-offset); - mFinalFile->Append(subString.ToNewCString()); + nsAutoCString tempSubString(subString); + mFinalFile->Append(tempSubString); offset = location + 1; pass++; } diff --git a/mozilla/xpinstall/src/nsInstallFileOpItem.cpp b/mozilla/xpinstall/src/nsInstallFileOpItem.cpp index c9c9a6db440..ae416f0f4ce 100644 --- a/mozilla/xpinstall/src/nsInstallFileOpItem.cpp +++ b/mozilla/xpinstall/src/nsInstallFileOpItem.cpp @@ -543,7 +543,8 @@ nsInstallFileOpItem::NativeFileOpFileRenamePrepare() nsIFile* target; mSrc->GetParent(&target); - target->Append(mStrTarget->ToNewCString()); + nsAutoCString tempTargetString(*mStrTarget); + target->Append(tempTargetString); target->Exists(&flagExists); if(flagExists) @@ -579,21 +580,18 @@ nsInstallFileOpItem::NativeFileOpFileRenameComplete() mSrc->GetParent(getter_AddRefs(target)); //need target for path assembly to check if the file already exists if (target) - target->Append(mStrTarget->ToNewCString()); + { + nsAutoCString tempTargetString(*mStrTarget); + target->Append(tempTargetString); + } else return nsInstall::UNEXPECTED_ERROR; target->Exists(&flagExists); if(!flagExists) { - char* cStrTarget = mStrTarget->ToNewCString(); - if(!cStrTarget) - return nsInstall::OUT_OF_MEMORY; - - mSrc->MoveTo(parent, cStrTarget); - - if (cStrTarget) - Recycle(cStrTarget); + nsAutoCString tempTargetString(*mStrTarget); + mSrc->MoveTo(parent, tempTargetString); } else return nsInstall::ALREADY_EXISTS; @@ -628,7 +626,8 @@ nsInstallFileOpItem::NativeFileOpFileRenameAbort() mSrc->GetParent(getter_AddRefs(parent)); if(parent) { - newFilename->Append(mStrTarget->ToNewCString()); + nsAutoCString tempTargetString(*mStrTarget); + newFilename->Append(tempTargetString); mSrc->GetLeafName(&leafName); @@ -797,8 +796,7 @@ PRInt32 nsInstallFileOpItem::NativeFileOpFileExecuteComplete() { //mTarget->Execute(*mParams); - mTarget->Spawn((const char**)mParams->ToNewCString(), 0);//nsIFileXXX: need to fix this call to Spawn - //It's totally bogus. + //mTarget->Spawn(nsAutoCString(*mParams), 0); // We don't care if it succeeded or not since we // don't wait for the process to end anyways. @@ -943,7 +941,7 @@ nsInstallFileOpItem::NativeFileOpDirRenamePrepare() nsCOMPtr target; mSrc->GetParent(getter_AddRefs(target)); - target->Append(mStrTarget->ToNewCString()); + target->Append(nsAutoCString(*mStrTarget)); target->Exists(&flagExists); if(flagExists) @@ -973,21 +971,16 @@ nsInstallFileOpItem::NativeFileOpDirRenameComplete() nsCOMPtr target; mSrc->GetParent(getter_AddRefs(target)); - target->Append(mStrTarget->ToNewCString()); + target->Append(nsAutoCString(*mStrTarget)); target->Exists(&flagExists); if(!flagExists) { - char* cStrTarget = mStrTarget->ToNewCString(); - if(!cStrTarget) - return nsInstall::OUT_OF_MEMORY; + nsAutoCString cStrTarget(*mStrTarget); nsCOMPtr parent; mSrc->GetParent(getter_AddRefs(parent)); ret = mSrc->MoveTo(parent, cStrTarget); - - if(cStrTarget) - Recycle(cStrTarget); } else return nsInstall::ALREADY_EXISTS; @@ -1014,7 +1007,7 @@ nsInstallFileOpItem::NativeFileOpDirRenameAbort() if(!flagExists) { mSrc->GetParent(getter_AddRefs(newDirName)); - newDirName->Append(mStrTarget->ToNewCString()); + newDirName->Append(nsAutoCString(*mStrTarget)); mSrc->GetLeafName(&leafName); mSrc->GetParent(getter_AddRefs(parent)); ret = newDirName->MoveTo(parent, leafName); @@ -1080,7 +1073,7 @@ nsInstallFileOpItem::NativeFileOpWindowsShortcutAbort() shortcutDescription = *mDescription; shortcutDescription.Append(".lnk"); mShortcutPath->Clone(getter_AddRefs(shortcutTarget)); - shortcutTarget->Append(shortcutDescription.ToNewCString()); + shortcutTarget->Append(nsAutoCString(shortcutDescription)); NativeFileOpFileDeleteComplete(shortcutTarget); #endif diff --git a/mozilla/xpinstall/src/nsInstallFolder.cpp b/mozilla/xpinstall/src/nsInstallFolder.cpp index 1edd168f4e8..0cfb031ae8e 100644 --- a/mozilla/xpinstall/src/nsInstallFolder.cpp +++ b/mozilla/xpinstall/src/nsInstallFolder.cpp @@ -60,8 +60,8 @@ struct DirectoryTable DirectoryTable[] = {"OS Drive", 108 }, {"file:///", 109 }, - {"Components", 110 }, - {"Chrome", 111 }, + {"Components", 110 }, + {"Chrome", 111 }, {"Win System", 200 }, {"Windows", 201 }, @@ -87,17 +87,17 @@ struct DirectoryTable DirectoryTable[] = MOZ_DECL_CTOR_COUNTER(nsInstallFolder); -nsInstallFolder::nsInstallFolder(const nsString& aFolderID) +nsInstallFolder::nsInstallFolder() { - nsInstallFolder( aFolderID, nsAutoString() ); + MOZ_COUNT_CTOR(nsInstallFolder); } -nsInstallFolder::nsInstallFolder(const nsString& aFolderID, const nsString& aRelativePath) +nsresult +nsInstallFolder::Init(const nsString& aFolderID, const nsString& aRelativePath) { - PRBool flagIsDir, flagExists; - - MOZ_COUNT_CTOR(nsInstallFolder); + PRBool flagIsDir, flagExists; + mFileSpec = nsnull; /* @@ -108,60 +108,67 @@ nsInstallFolder::nsInstallFolder(const nsString& aFolderID, const nsString& aRel SetDirectoryPath( aFolderID, aRelativePath ); - // check to see if that worked - if ( !mFileSpec ) + if (mFileSpec) + return NS_OK; + + // it didn't, so aFolderID is not one of the magic strings. + // maybe it's already a pathname? If so it had better be a directory + // if it already exists... + nsAutoCString tempFolderID(aFolderID); + nsCOMPtr dirCheck; + NS_NewLocalFile(tempFolderID, getter_AddRefs(dirCheck)); + + if (!dirCheck) + return NS_ERROR_FAILURE; + + dirCheck->IsDirectory(&flagIsDir); + dirCheck->Exists(&flagExists); + + if ( flagIsDir && flagExists ) { - // it didn't, so aFolderID is not one of the magic strings. - // maybe it's already a pathname? If so it had better be a directory - // if it already exists... - nsCOMPtr dirCheck; - NS_NewLocalFile(aFolderID.ToNewCString(), getter_AddRefs(dirCheck)); - if (dirCheck) + mFileSpec = dirCheck; + + if (aRelativePath.Length() > 0 ) { - dirCheck->IsDirectory(&flagIsDir); - dirCheck->Exists(&flagExists); - if ( flagIsDir || !flagExists ) - { - mFileSpec = dirCheck; + // we've got a subdirectory to tack on + nsString morePath(aFolderID); + morePath.Append(aRelativePath); + nsAutoCString tempMorePath(morePath); + NS_NewLocalFile(tempMorePath, getter_AddRefs(dirCheck)); - if (mFileSpec && aRelativePath.Length() > 0 ) - { - // we've got a subdirectory to tack on - nsString morePath(aRelativePath); - - //if ( morePath.Last() != '/' || morePath.Last() != '\\' ) - // morePath.AppendWithConversion('/'); - - mFileSpec->Append(morePath.ToNewCString()); - } - - // make sure that the directory is created. - // XXX: **why** are we creating these? they might not be used! - // nsFileSpec(mFileSpec->GetCString(), PR_TRUE); - } + mFileSpec = dirCheck; } } + if (mFileSpec) + return NS_OK; + + return NS_ERROR_FAILURE; } -nsInstallFolder::nsInstallFolder(nsInstallFolder& inFolder, const nsString& subString) +nsresult +nsInstallFolder::Init(nsInstallFolder& inFolder, const nsString& subString) { - MOZ_COUNT_CTOR(nsInstallFolder); + if (!inFolder.mFileSpec) + return NS_ERROR_NULL_POINTER; inFolder.mFileSpec->Clone(getter_AddRefs(mFileSpec)); + + if (!mFileSpec) + return NS_ERROR_FAILURE; if(!subString.IsEmpty()) - mFileSpec->Append(subString.ToNewCString()); + { + nsAutoCString tempSubString(subString); + mFileSpec->Append(tempSubString); + } + + return NS_OK; } nsInstallFolder::~nsInstallFolder() { - //if (mFileSpec != nsnull) //nsIFileXXX: since mFileSpec is an nsCOMPtr, how is it deleted? - //delete mFileSpec; - - mFileSpec = 0; - - MOZ_COUNT_DTOR(nsInstallFolder); + MOZ_COUNT_DTOR(nsInstallFolder); } void @@ -190,18 +197,13 @@ nsInstallFolder::GetDirectoryPath(nsString& aDirectoryPath) void nsInstallFolder::SetDirectoryPath(const nsString& aFolderID, const nsString& aRelativePath) { - if ( aFolderID.EqualsIgnoreCase("User Pick") ) - { - PickDefaultDirectory(); - return; - } - else if ( aFolderID.EqualsIgnoreCase("Installed") ) + if ( aFolderID.EqualsIgnoreCase("Installed") ) { // XXX block from users or remove "Installed" // XXX the filespec creation will fail due to unix slashes on Mac - + nsAutoCString tempRelPath(aRelativePath); nsCOMPtr temp; - NS_NewLocalFile(aRelativePath.ToNewCString(), getter_AddRefs(temp)); + NS_NewLocalFile(tempRelPath, getter_AddRefs(temp)); mFileSpec = temp; // creates the directories to the relative path. return; } @@ -216,6 +218,7 @@ nsInstallFolder::SetDirectoryPath(const nsString& aFolderID, const nsString& aRe if (!nsSoftwareUpdate::GetProgramDirectory()) { NS_WITH_SERVICE(nsIProperties, directoryService, NS_DIRECTORY_SERVICE_PROGID, &rv); + if (!directoryService) return; directoryService->Get("system.OS_CurrentProcessDirectory", NS_GET_IID(nsIFile), getter_AddRefs(mFileSpec)); #ifdef XP_MAC @@ -246,7 +249,7 @@ nsInstallFolder::SetDirectoryPath(const nsString& aFolderID, const nsString& aRe if (!nsSoftwareUpdate::GetProgramDirectory()) //Not in stub installer { NS_WITH_SERVICE(nsIProperties, directoryService, NS_DIRECTORY_SERVICE_PROGID, &rv); - + if (!directoryService) return; directoryService->Get("system.OS_CurrentProcessDirectory", NS_GET_IID(nsIFile), getter_AddRefs(mFileSpec)); } else //In stub installer. mProgram has been set so @@ -263,7 +266,7 @@ nsInstallFolder::SetDirectoryPath(const nsString& aFolderID, const nsString& aRe case 104: /////////////////////////////////////////////////////////// Temporary { NS_WITH_SERVICE(nsIProperties, directoryService, NS_DIRECTORY_SERVICE_PROGID, &rv); - + if (!directoryService) return; directoryService->Get("system.OS_TemporaryDirectory", NS_GET_IID(nsIFile), getter_AddRefs(mFileSpec)); } break; @@ -286,15 +289,16 @@ nsInstallFolder::SetDirectoryPath(const nsString& aFolderID, const nsString& aRe case 108: /////////////////////////////////////////////////////////// OS Drive { NS_WITH_SERVICE(nsIProperties, directoryService, NS_DIRECTORY_SERVICE_PROGID, &rv); - + if (!directoryService) return; directoryService->Get("system.OS_DriveDirectory", NS_GET_IID(nsIFile), getter_AddRefs(mFileSpec)); } break; case 109: /////////////////////////////////////////////////////////// File URL { + nsAutoCString tempRelPath(aRelativePath); nsCOMPtr temp; - NS_NewLocalFile(aRelativePath.ToNewCString(), getter_AddRefs(temp)); + NS_NewLocalFile(tempRelPath, getter_AddRefs(temp)); mFileSpec = temp; // file:// is a special case where it returns and does not @@ -311,7 +315,7 @@ nsInstallFolder::SetDirectoryPath(const nsString& aFolderID, const nsString& aRe if (!nsSoftwareUpdate::GetProgramDirectory()) { NS_WITH_SERVICE(nsIProperties, directoryService, NS_DIRECTORY_SERVICE_PROGID, &rv); - + if (!directoryService) return; directoryService->Get("system.OS_CurrentProcessDirectory", NS_GET_IID(nsIFile), getter_AddRefs(mFileSpec)); @@ -346,7 +350,7 @@ nsInstallFolder::SetDirectoryPath(const nsString& aFolderID, const nsString& aRe if (!nsSoftwareUpdate::GetProgramDirectory()) { NS_WITH_SERVICE(nsIProperties, directoryService, NS_DIRECTORY_SERVICE_PROGID, &rv); - + if (!directoryService) return; directoryService->Get("system.OS_CurrentProcessDirectory", NS_GET_IID(nsIFile), getter_AddRefs(mFileSpec)); @@ -379,7 +383,7 @@ nsInstallFolder::SetDirectoryPath(const nsString& aFolderID, const nsString& aRe case 200: /////////////////////////////////////////////////////////// Win System { NS_WITH_SERVICE(nsIProperties, directoryService, NS_DIRECTORY_SERVICE_PROGID, &rv); - + if (!directoryService) return; directoryService->Get("system.SystemDirectory", NS_GET_IID(nsIFile), getter_AddRefs(mFileSpec)); @@ -390,7 +394,7 @@ nsInstallFolder::SetDirectoryPath(const nsString& aFolderID, const nsString& aRe case 201: /////////////////////////////////////////////////////////// Windows { NS_WITH_SERVICE(nsIProperties, directoryService, NS_DIRECTORY_SERVICE_PROGID, &rv); - + if (!directoryService) return; directoryService->Get("system.WindowsDirectory", NS_GET_IID(nsIFile), getter_AddRefs(mFileSpec)); @@ -400,7 +404,7 @@ nsInstallFolder::SetDirectoryPath(const nsString& aFolderID, const nsString& aRe case 300: /////////////////////////////////////////////////////////// Mac System { NS_WITH_SERVICE(nsIProperties, directoryService, NS_DIRECTORY_SERVICE_PROGID, &rv); - + if (!directoryService) return; directoryService->Get("system.Directory", NS_GET_IID(nsIFile), getter_AddRefs(mFileSpec)); @@ -410,7 +414,7 @@ nsInstallFolder::SetDirectoryPath(const nsString& aFolderID, const nsString& aRe case 301: /////////////////////////////////////////////////////////// Mac Desktop { NS_WITH_SERVICE(nsIProperties, directoryService, NS_DIRECTORY_SERVICE_PROGID, &rv); - + if (!directoryService) return; directoryService->Get("system.DesktopDirectory", NS_GET_IID(nsIFile), getter_AddRefs(mFileSpec)); @@ -420,7 +424,7 @@ nsInstallFolder::SetDirectoryPath(const nsString& aFolderID, const nsString& aRe case 302: /////////////////////////////////////////////////////////// Mac Trash { NS_WITH_SERVICE(nsIProperties, directoryService, NS_DIRECTORY_SERVICE_PROGID, &rv); - + if (!directoryService) return; directoryService->Get("system.TrashDirectory", NS_GET_IID(nsIFile), getter_AddRefs(mFileSpec)); @@ -430,7 +434,7 @@ nsInstallFolder::SetDirectoryPath(const nsString& aFolderID, const nsString& aRe case 303: /////////////////////////////////////////////////////////// Mac Startup { NS_WITH_SERVICE(nsIProperties, directoryService, NS_DIRECTORY_SERVICE_PROGID, &rv); - + if (!directoryService) return; directoryService->Get("system.StartupDirectory", NS_GET_IID(nsIFile), getter_AddRefs(mFileSpec)); @@ -440,7 +444,7 @@ nsInstallFolder::SetDirectoryPath(const nsString& aFolderID, const nsString& aRe case 304: /////////////////////////////////////////////////////////// Mac Shutdown { NS_WITH_SERVICE(nsIProperties, directoryService, NS_DIRECTORY_SERVICE_PROGID, &rv); - + if (!directoryService) return; directoryService->Get("system.ShutdownDirectory", NS_GET_IID(nsIFile), getter_AddRefs(mFileSpec)); @@ -450,7 +454,7 @@ nsInstallFolder::SetDirectoryPath(const nsString& aFolderID, const nsString& aRe case 305: /////////////////////////////////////////////////////////// Mac Apple Menu { NS_WITH_SERVICE(nsIProperties, directoryService, NS_DIRECTORY_SERVICE_PROGID, &rv); - + if (!directoryService) return; directoryService->Get("system.AppleMenuDirectory", NS_GET_IID(nsIFile), getter_AddRefs(mFileSpec)); @@ -460,7 +464,7 @@ nsInstallFolder::SetDirectoryPath(const nsString& aFolderID, const nsString& aRe case 306: /////////////////////////////////////////////////////////// Mac Control Panel { NS_WITH_SERVICE(nsIProperties, directoryService, NS_DIRECTORY_SERVICE_PROGID, &rv); - + if (!directoryService) return; directoryService->Get("system.ControlPanelDirectory", NS_GET_IID(nsIFile), getter_AddRefs(mFileSpec)); @@ -470,7 +474,7 @@ nsInstallFolder::SetDirectoryPath(const nsString& aFolderID, const nsString& aRe case 307: /////////////////////////////////////////////////////////// Mac Extension { NS_WITH_SERVICE(nsIProperties, directoryService, NS_DIRECTORY_SERVICE_PROGID, &rv); - + if (!directoryService) return; directoryService->Get("system.ExtensionDirectory", NS_GET_IID(nsIFile), getter_AddRefs(mFileSpec)); @@ -480,7 +484,7 @@ nsInstallFolder::SetDirectoryPath(const nsString& aFolderID, const nsString& aRe case 308: /////////////////////////////////////////////////////////// Mac Fonts { NS_WITH_SERVICE(nsIProperties, directoryService, NS_DIRECTORY_SERVICE_PROGID, &rv); - + if (!directoryService) return; directoryService->Get("system.FontsDirectory", NS_GET_IID(nsIFile), getter_AddRefs(mFileSpec)); @@ -490,7 +494,7 @@ nsInstallFolder::SetDirectoryPath(const nsString& aFolderID, const nsString& aRe case 309: /////////////////////////////////////////////////////////// Mac Preferences { NS_WITH_SERVICE(nsIProperties, directoryService, NS_DIRECTORY_SERVICE_PROGID, &rv); - + if (!directoryService) return; directoryService->Get("system.PreferencesDirectory", NS_GET_IID(nsIFile), getter_AddRefs(mFileSpec)); @@ -500,7 +504,7 @@ nsInstallFolder::SetDirectoryPath(const nsString& aFolderID, const nsString& aRe case 310: /////////////////////////////////////////////////////////// Mac Documents { NS_WITH_SERVICE(nsIProperties, directoryService, NS_DIRECTORY_SERVICE_PROGID, &rv); - + if (!directoryService) return; directoryService->Get("system.DocumentsDirectory", NS_GET_IID(nsIFile), getter_AddRefs(mFileSpec)); @@ -510,7 +514,7 @@ nsInstallFolder::SetDirectoryPath(const nsString& aFolderID, const nsString& aRe case 400: /////////////////////////////////////////////////////////// Unix Local { NS_WITH_SERVICE(nsIProperties, directoryService, NS_DIRECTORY_SERVICE_PROGID, &rv); - + if (!directoryService) return; directoryService->Get("system.LocalDirectory", NS_GET_IID(nsIFile), getter_AddRefs(mFileSpec)); @@ -520,7 +524,7 @@ nsInstallFolder::SetDirectoryPath(const nsString& aFolderID, const nsString& aRe case 401: /////////////////////////////////////////////////////////// Unix Lib { NS_WITH_SERVICE(nsIProperties, directoryService, NS_DIRECTORY_SERVICE_PROGID, &rv); - + if (!directoryService) return; directoryService->Get("system.LibDirectory", NS_GET_IID(nsIFile), getter_AddRefs(mFileSpec)); @@ -540,17 +544,12 @@ nsInstallFolder::SetDirectoryPath(const nsString& aFolderID, const nsString& aRe //if (aRelativePath.Last() != '/' || aRelativePath.Last() != '\\') // tempPath.AppendWithConversion('/'); - - mFileSpec->Append(aRelativePath.ToNewCString()); + nsAutoCString tempRelPath(aRelativePath); + mFileSpec->Append(tempRelPath); } } } -void nsInstallFolder::PickDefaultDirectory() -{ - //FIX: Need to put up a dialog here and set mFileSpec - return; -} /* MapNameToEnum * maps name from the directory table to its enum */ @@ -572,27 +571,10 @@ nsInstallFolder::MapNameToEnum(const nsString& name) } -#if 0 //Remarking out for nsIFile migration (I don't think we need it anymore) - -void -nsInstallFolder::SetAppShellDirectory(PRUint32 value) -{ - nsIFileSpec* fs = NS_LocateFileOrDirectory(value); - if ( fs ) - { - mFileSpec = new nsFileSpec(); - fs->GetFileSpec(mFileSpec); - NS_RELEASE(fs); - } -} - -#endif //end nsIFile migration comment nsIFile* nsInstallFolder::GetFileSpec() { - if (mFileSpec == nsnull) - return nsnull; return mFileSpec; } @@ -605,15 +587,18 @@ nsInstallFolder::ToString(nsAutoString* outString) char* temp; PRBool flagIsFile; + if (!mFileSpec) + return NS_ERROR_NULL_POINTER; + nsresult rv = mFileSpec->GetPath(&temp); mFileSpec->IsFile(&flagIsFile); if (!flagIsFile) { - // STRING USE WARNING: perhaps |tempString| should be a |nsCString| - nsString tempString; tempString.AssignWithConversion(temp); - + nsString tempString; + tempString.AssignWithConversion(temp); tempString.AppendWithConversion(FILESEP); - outString->AssignWithConversion(tempString.ToNewCString()); + nsAutoCString tempAutoString(tempString); + outString->AssignWithConversion(tempAutoString); } else outString->AssignWithConversion(temp); diff --git a/mozilla/xpinstall/src/nsInstallFolder.h b/mozilla/xpinstall/src/nsInstallFolder.h index 8bb38db067e..7352151e71b 100644 --- a/mozilla/xpinstall/src/nsInstallFolder.h +++ b/mozilla/xpinstall/src/nsInstallFolder.h @@ -38,9 +38,9 @@ class nsInstallFolder { public: - nsInstallFolder(const nsString& aFolderID); - nsInstallFolder(nsInstallFolder& inFolder, const nsString& subString); - nsInstallFolder(const nsString& aFolderID, const nsString& aRelativePath); + nsInstallFolder(); + nsresult Init(nsInstallFolder& inFolder, const nsString& subString); + nsresult Init(const nsString& aFolderID, const nsString& aRelativePath); virtual ~nsInstallFolder(); void GetDirectoryPath(nsString& aDirectoryPath); diff --git a/mozilla/xpinstall/src/nsInstallPatch.cpp b/mozilla/xpinstall/src/nsInstallPatch.cpp index 10a6f92be62..61c2692adff 100644 --- a/mozilla/xpinstall/src/nsInstallPatch.cpp +++ b/mozilla/xpinstall/src/nsInstallPatch.cpp @@ -161,7 +161,7 @@ nsInstallPatch::nsInstallPatch( nsInstall* inInstall, mVersionInfo->Init(inVInfo); if(! inPartialPath.IsEmpty()) - mTargetFile->Append(inPartialPath.ToNewCString()); + mTargetFile->Append(nsAutoCString(inPartialPath)); } nsInstallPatch::~nsInstallPatch() @@ -462,7 +462,7 @@ nsInstallPatch::NativePatch(nsIFile *sourceFile, nsIFile *patchFile, nsIFile **n rv = sourceFile->Clone(getter_AddRefs(tempSrcFile)); //Clone the sourceFile - tempSrcFile->SetLeafName(tmpFileName.ToNewCString()); //Append the new leafname + tempSrcFile->SetLeafName(nsAutoCString(tmpFileName)); //Append the new leafname uniqueSrcFile = do_QueryInterface(tempSrcFile, &rv); //Create an nsILocalFile version to pass to MakeUnique MakeUnique(uniqueSrcFile); @@ -529,7 +529,7 @@ nsInstallPatch::NativePatch(nsIFile *sourceFile, nsIFile *patchFile, nsIFile **n } - outFileSpec->SetLeafName(newFileName.ToNewCString()); //Set new leafname + outFileSpec->SetLeafName(nsAutoCString(newFileName)); //Set new leafname nsCOMPtr outFileLocal = do_QueryInterface(outFileSpec, &rv); //Create an nsILocalFile version //to send to MakeUnique() MakeUnique(outFileLocal); diff --git a/mozilla/xpinstall/src/nsJSFile.cpp b/mozilla/xpinstall/src/nsJSFile.cpp index ac85039269d..9bc8f63feb8 100644 --- a/mozilla/xpinstall/src/nsJSFile.cpp +++ b/mozilla/xpinstall/src/nsJSFile.cpp @@ -1040,15 +1040,15 @@ InstallFileOpFileWindowsShortcut(JSContext *cx, JSObject *obj, uintN argc, jsval ConvertJSValToStr(b0, cx, argv[0]); - NS_NewLocalFile(b0.ToNewCString(), getter_AddRefs(nsfsB0)); + NS_NewLocalFile(nsAutoCString(b0), getter_AddRefs(nsfsB0)); ConvertJSValToStr(b1, cx, argv[1]); - NS_NewLocalFile(b1.ToNewCString(), getter_AddRefs(nsfsB1)); + NS_NewLocalFile(nsAutoCString(b1), getter_AddRefs(nsfsB1)); ConvertJSValToStr(b2, cx, argv[2]); ConvertJSValToStr(b3, cx, argv[3]); - NS_NewLocalFile(b3.ToNewCString(), getter_AddRefs(nsfsB3)); + NS_NewLocalFile(nsAutoCString(b3), getter_AddRefs(nsfsB3)); ConvertJSValToStr(b4, cx, argv[4]); ConvertJSValToStr(b5, cx, argv[5]); - NS_NewLocalFile(b5.ToNewCString(), getter_AddRefs(nsfsB5)); + NS_NewLocalFile(nsAutoCString(b5), getter_AddRefs(nsfsB5)); if(JSVAL_IS_NULL(argv[6])) { diff --git a/mozilla/xpinstall/src/nsSoftwareUpdate.cpp b/mozilla/xpinstall/src/nsSoftwareUpdate.cpp index 3080c60741b..c49aeefe641 100644 --- a/mozilla/xpinstall/src/nsSoftwareUpdate.cpp +++ b/mozilla/xpinstall/src/nsSoftwareUpdate.cpp @@ -36,7 +36,7 @@ #include "prlock.h" #include "NSReg.h" #include "VerReg.h" -#include "nsSpecialSystemDirectory.h" +#include "nsIDirectoryService.h" #include "nsInstall.h" #include "nsSoftwareUpdateIIDs.h" @@ -126,9 +126,25 @@ nsSoftwareUpdate::nsSoftwareUpdate() /***************************************/ NR_StartupRegistry(); /* startup the registry; if already started, this will essentially be a noop */ + - nsSpecialSystemDirectory appDir(nsSpecialSystemDirectory::OS_CurrentProcessDirectory); - VR_SetRegDirectory( appDir.GetNativePathCString() ); + nsresult rv; + NS_WITH_SERVICE(nsIProperties, directoryService, NS_DIRECTORY_SERVICE_PROGID, &rv); + + if(!directoryService) return; + + nsCOMPtr dir; + directoryService->Get("xpcom.currentProcess", NS_GET_IID(nsIFile), getter_AddRefs(dir)); + if (dir) + { + char* nativePath; + dir->GetPath(&nativePath); + // EVIL version registry does not take a nsIFile.; + VR_SetRegDirectory( nativePath ); + if (nativePath) + nsAllocator::Free(nativePath); + + } } diff --git a/mozilla/xpinstall/src/nsXPInstallManager.cpp b/mozilla/xpinstall/src/nsXPInstallManager.cpp index 347903e829c..48dec282aa1 100644 --- a/mozilla/xpinstall/src/nsXPInstallManager.cpp +++ b/mozilla/xpinstall/src/nsXPInstallManager.cpp @@ -380,19 +380,32 @@ NS_IMETHODIMP nsXPInstallManager::DownloadNext() } else if ( mItem->IsFileURL() ) { - // don't need to download, just point at local file - //rv = NS_NewFileSpecWithSpec( nsFileSpec(nsFileURL(mItem->mURL)), - // getter_AddRefs(mItem->mFile) ); - rv = NS_NewLocalFile(mItem->mURL.ToNewCString(), getter_AddRefs(mItem->mFile)); - if (NS_FAILED(rv)) + + nsCOMPtr pURL; + rv = NS_NewURI(getter_AddRefs(pURL), mItem->mURL); + + if (NS_SUCCEEDED(rv)) { - // serious problem with trigger! try to carry on - mTriggers->SendStatus( mItem->mURL.GetUnicode(), - nsInstall::DOWNLOAD_ERROR ); - mItem->mFile = 0; - } + nsCOMPtr fileURL = do_QueryInterface(pURL); + if (!fileURL) + return NS_ERROR_NULL_POINTER; + + nsCOMPtr localFile; + rv = fileURL->GetFile(getter_AddRefs(localFile)); - rv = DownloadNext(); + if (NS_FAILED(rv)) + { + // serious problem with trigger! try to carry on + mTriggers->SendStatus( mItem->mURL.GetUnicode(), + nsInstall::DOWNLOAD_ERROR ); + mItem->mFile = 0; + } + else + { + mItem->mFile = do_QueryInterface(localFile); + rv = DownloadNext(); + } + } } else { @@ -408,7 +421,7 @@ NS_IMETHODIMP nsXPInstallManager::DownloadNext() { nsString jarleaf; mItem->mURL.Right( jarleaf, mItem->mURL.Length() - (pos + 1)); - temp->Append(jarleaf.ToNewCString()); + temp->Append(nsAutoCString(jarleaf)); } else temp->Append("xpinstall.xpi");