diff --git a/mozilla/xpinstall/packager/windows/browser.jst b/mozilla/xpinstall/packager/windows/browser.jst index 21f8c96c4c6..494979d567e 100644 --- a/mozilla/xpinstall/packager/windows/browser.jst +++ b/mozilla/xpinstall/packager/windows/browser.jst @@ -25,7 +25,7 @@ function createShortcuts() winreg = getWinRegistry(); fWindows = getFolder("Windows"); fCommunicator = getFolder("Communicator"); - fTemp = fCommunicator + "\\$MainExeFile$"; + fTemp = fCommunicator + "$MainExeFile$"; fileExe = getFolder("file:///", fTemp); scExeDesc = "$ProductName$"; scProfileDesc = "Profile Manager"; @@ -226,7 +226,7 @@ if(verifyDiskSpace(fCommunicator, srDest) == true) // check return value if(!checkError(err)) { - fileComponentRegStr = fCommunicator + "\\component.reg"; + fileComponentRegStr = fCommunicator + "component.reg"; fileComponentReg = getFolder("file:///", fileComponentRegStr); err = fileDelete(fileComponentReg); logComment("fileDelete() returned: " + err); diff --git a/mozilla/xpinstall/packager/windows/xpcom.jst b/mozilla/xpinstall/packager/windows/xpcom.jst index eae91ff043c..68544505dff 100644 --- a/mozilla/xpinstall/packager/windows/xpcom.jst +++ b/mozilla/xpinstall/packager/windows/xpcom.jst @@ -63,7 +63,7 @@ fWindowsSystem = getFolder("Win System"); logComment("fCommunicator: " + fCommunicator); // build the uninstall folder path -szUninstall = fCommunicator + "\\Uninstall"; +szUninstall = fCommunicator + "Uninstall"; fUninstall = getFolder("file:///", szUninstall); File.dirCreate(fUninstall); @@ -71,8 +71,8 @@ File.dirCreate(fUninstall); // the uninstaller. // These two files are created after installation is done, thus // are normally not logged for uninstall. -logComment("[0/0] Installing: " + fCommunicator + "\\component.reg"); -logComment("[0/0] Installing: " + fCommunicator + "\\xpcom.log"); +logComment("[0/0] Installing: " + fCommunicator + "component.reg"); +logComment("[0/0] Installing: " + fCommunicator + "xpcom.log"); if(verifyDiskSpace(fCommunicator, srDest) == true) { @@ -88,7 +88,7 @@ if(verifyDiskSpace(fCommunicator, srDest) == true) // check return value if(!checkError(err)) { - fileComponentRegStr = fCommunicator + "\\component.reg"; + fileComponentRegStr = fCommunicator + "component.reg"; fileComponentReg = getFolder("file:///", fileComponentRegStr); err = fileDelete(fileComponentReg); logComment("fileDelete() returned: " + err); diff --git a/mozilla/xpinstall/public/nsISoftwareUpdate.h b/mozilla/xpinstall/public/nsISoftwareUpdate.h index 075deb99d8c..25ebaa3f75a 100644 --- a/mozilla/xpinstall/public/nsISoftwareUpdate.h +++ b/mozilla/xpinstall/public/nsISoftwareUpdate.h @@ -61,7 +61,7 @@ class nsISoftwareUpdate : public nsISupports public: NS_DEFINE_STATIC_IID_ACCESSOR(NS_ISOFTWAREUPDATE_IID) - NS_IMETHOD InstallJar(nsIFileSpec* localFile, + NS_IMETHOD InstallJar(nsIFile* localFile, const PRUnichar* URL, const PRUnichar* arguments, long flags, diff --git a/mozilla/xpinstall/public/nsPIXPIStubHook.idl b/mozilla/xpinstall/public/nsPIXPIStubHook.idl index 3868fbf8a4e..62e21bcf906 100644 --- a/mozilla/xpinstall/public/nsPIXPIStubHook.idl +++ b/mozilla/xpinstall/public/nsPIXPIStubHook.idl @@ -24,6 +24,7 @@ #include "nsISupports.idl" #include "nsIFileSpec.idl" +#include "nsIFile.idl" /** * nsPIXPIStubHook @@ -34,5 +35,5 @@ [uuid(089929F0-4ED9-11d3-ABDD-000064657374)] interface nsPIXPIStubHook : nsISupports { - void StubInitialize(in nsIFileSpec dir); + void StubInitialize(in nsIFile dir); }; diff --git a/mozilla/xpinstall/src/ScheduledTasks.cpp b/mozilla/xpinstall/src/ScheduledTasks.cpp index 1c7bdc3f9f9..34471ba2865 100644 --- a/mozilla/xpinstall/src/ScheduledTasks.cpp +++ b/mozilla/xpinstall/src/ScheduledTasks.cpp @@ -33,19 +33,16 @@ static nsresult -GetPersistentStringFromSpec(const nsFileSpec& inSpec, char **string) +GetPersistentStringFromSpec(nsIFile* inSpec, char **string) { + nsresult rv; + if (!string) return NS_ERROR_NULL_POINTER; - nsCOMPtr spec; -#ifdef XP_MAC - nsFileSpec interim = inSpec.GetFSSpec(); /* XXX get rid of mError in nsFileSpec */ - nsresult rv = NS_NewFileSpecWithSpec(interim, getter_AddRefs(spec)); -#else - nsresult rv = NS_NewFileSpecWithSpec(inSpec, getter_AddRefs(spec)); -#endif + nsCOMPtr LocalFile = do_QueryInterface(inSpec, &rv); + if (NS_SUCCEEDED(rv)) { - rv = spec->GetPersistentDescriptorString(string); + rv = LocalFile->GetPath(string); } else { *string = nsnull; @@ -61,7 +58,7 @@ GetPersistentStringFromSpec(const nsFileSpec& inSpec, char **string) #include #include -PRInt32 ReplaceExistingWindowsFile(const nsFileSpec& currentSpec, const nsFileSpec& finalSpec) +PRInt32 ReplaceExistingWindowsFile(nsIFile* currentSpec, nsIFile* finalSpec) { // this routine is now for DOS-based windows only. WinNT should // be taken care of by the XP code @@ -97,9 +94,13 @@ PRInt32 ReplaceExistingWindowsFile(const nsFileSpec& currentSpec, const nsFileSp char Src[_MAX_PATH]; // 8.3 name char Dest[_MAX_PATH]; // 8.3 name - char* final = strdup(finalSpec.GetNativePathCString()); - char* current = strdup(currentSpec.GetNativePathCString()); + + char* final; + char* current; + finalSpec->GetPath(&final); + currentSpec->GetPath(¤t); + strlen = GetShortPathName( (LPCTSTR)current, (LPTSTR)Src, (DWORD)sizeof(Src) ); if ( strlen > 0 ) { @@ -135,13 +136,15 @@ PRInt32 ReplaceExistingWindowsFile(const nsFileSpec& currentSpec, const nsFileSp -PRInt32 DeleteFileNowOrSchedule(const nsFileSpec& filename) +PRInt32 DeleteFileNowOrSchedule(nsIFile* filename) { - PRInt32 result = nsInstall::SUCCESS; + PRBool flagExists; + PRInt32 result = nsInstall::SUCCESS; - filename.Delete(PR_FALSE); - if (filename.Exists()) + filename->Delete(PR_FALSE); + filename->Exists(&flagExists); + if (flagExists) { // could not delete, schedule it for later @@ -188,57 +191,75 @@ PRInt32 DeleteFileNowOrSchedule(const nsFileSpec& filename) -PRInt32 ReplaceFileNow(nsFileSpec& replacementFile, nsFileSpec& doomedFile ) +PRInt32 ReplaceFileNow(nsIFile* replacementFile, nsIFile* doomedFile ) { + PRBool flagExists, flagIsEqual; + nsresult rv; + // replacement file must exist, doomed file doesn't have to - if ( !replacementFile.Exists() ) + replacementFile->Exists(&flagExists); + if ( !flagExists ) return nsInstall::DOES_NOT_EXIST; // don't have to do anything if the files are the same - if ( replacementFile == doomedFile ) + replacementFile->Equals(doomedFile, &flagIsEqual); + if ( flagIsEqual ) return nsInstall::SUCCESS; PRInt32 result = nsInstall::ACCESS_DENIED; // first try to rename the doomed file out of the way (if it exists) - char* leafname; - nsFileSpec tmpFile( doomedFile ); - if ( tmpFile.Exists() ) + char* leafname = nsnull; + nsCOMPtr tmpFile; + nsCOMPtr tmpLocalFile; + nsCOMPtr parent; + + doomedFile->Clone(getter_AddRefs(tmpFile)); + tmpFile->Exists(&flagExists); + if ( flagExists ) { - tmpFile.MakeUnique(); - leafname = tmpFile.GetLeafName(); - tmpFile = doomedFile; - tmpFile.Rename( leafname ); - nsCRT::free( leafname ); + tmpLocalFile = do_QueryInterface(tmpFile, &rv); // Convert to an nsILocalFile + MakeUnique(tmpLocalFile); // for the call to MakeUnique + + tmpLocalFile->GetParent(getter_AddRefs(parent)); //get the parent for later use in MoveTo + tmpLocalFile->GetLeafName(&leafname); //this is the new "unique" leafname + + doomedFile->Clone(getter_AddRefs(tmpFile)); // recreate the tmpFile as a doomedFile + tmpFile->MoveTo(parent, leafname); + + if (leafname) nsCRT::free( leafname ); } // if doomedFile is gone move new file into place - nsresult rv; - if ( !doomedFile.Exists() ) + doomedFile->Exists(&flagExists); + if ( !flagExists ) { - nsFileSpec parentofFinalFile; - nsFileSpec parentofReplacementFile; + nsCOMPtr parentofFinalFile; + nsCOMPtr parentofReplacementFile; - doomedFile.GetParent(parentofFinalFile); - replacementFile.GetParent(parentofReplacementFile); + doomedFile->GetParent(getter_AddRefs(parentofFinalFile)); + replacementFile->GetParent(getter_AddRefs(parentofReplacementFile)); // XXX looks dangerous, the replacement file name may NOT be unique in the // target directory if we have to move it! Either we should never move the // files like this (i.e. error if not in the same dir) or we need to take // a little more care in the move. - if(parentofReplacementFile != parentofFinalFile) + parentofReplacementFile->Equals(parentofFinalFile, &flagIsEqual); + if(!flagIsEqual) { NS_WARN_IF_FALSE( 0, "File unpacked into a non-dest dir" ); - rv = replacementFile.MoveToDir(parentofFinalFile); + replacementFile->GetLeafName(&leafname); + rv = replacementFile->MoveTo(parentofFinalFile, leafname); } else rv = NS_OK; - leafname = doomedFile.GetLeafName(); + doomedFile->GetLeafName(&leafname); + replacementFile->GetParent(getter_AddRefs(parent)); if ( NS_SUCCEEDED(rv) ) - rv = replacementFile.Rename( leafname ); + rv = replacementFile->MoveTo(parent, leafname ); if ( NS_SUCCEEDED(rv) ) { @@ -249,7 +270,8 @@ PRInt32 ReplaceFileNow(nsFileSpec& replacementFile, nsFileSpec& doomedFile ) else { // couldn't rename file, try to put old file back - tmpFile.Rename( leafname ); + tmpFile->GetParent(getter_AddRefs(parent)); + tmpFile->MoveTo(parent, leafname); } nsCRT::free( leafname ); } @@ -261,7 +283,7 @@ PRInt32 ReplaceFileNow(nsFileSpec& replacementFile, nsFileSpec& doomedFile ) -PRInt32 ReplaceFileNowOrSchedule(nsFileSpec& replacementFile, nsFileSpec& doomedFile ) +PRInt32 ReplaceFileNowOrSchedule(nsIFile* replacementFile, nsIFile* doomedFile ) { PRInt32 result = ReplaceFileNow( replacementFile, doomedFile ); @@ -359,6 +381,7 @@ void DeleteScheduledFiles( HREG reg ) REGERR err; RKEY key; REGENUM state = 0; + nsresult rv = NS_OK; /* perform scheduled file deletions */ if (REGERR_OK == NR_RegGetKey(reg,ROOTKEY_PRIVATE,REG_DELETE_LIST_KEY,&key)) @@ -369,10 +392,9 @@ void DeleteScheduledFiles( HREG reg ) char namebuf[MAXREGNAMELEN]; char valbuf[MAXREGPATHLEN]; - nsFileSpec doomedFile; - nsCOMPtr spec; + nsCOMPtr doomedFile; + nsCOMPtr spec; - nsresult rv = NS_NewFileSpec(getter_AddRefs(spec)); if (NS_SUCCEEDED(rv)) { while (REGERR_OK == NR_RegEnumEntries( reg, key, &state, namebuf, @@ -384,12 +406,15 @@ void DeleteScheduledFiles( HREG reg ) { // no need to check return value of // SetPersistentDescriptorString, it's always NS_OK - spec->SetPersistentDescriptorString(valbuf); - rv = spec->GetFileSpec(&doomedFile); + //spec->SetPersistentDescriptorString(valbuf); //nsIFileXXX: Do we still need this instead of InitWithPath? + NS_NewLocalFile((char*)valbuf, getter_AddRefs(spec)); + spec->Clone(getter_AddRefs(doomedFile)); if (NS_SUCCEEDED(rv)) { - doomedFile.Delete(PR_FALSE); - if ( !doomedFile.Exists() ) + PRBool flagExists; + doomedFile->Delete(PR_FALSE); + doomedFile->Exists(&flagExists); + if ( !flagExists ) { // deletion successful, don't have to retry NR_RegDeleteEntry( reg, key, namebuf ); @@ -422,14 +447,14 @@ void ReplaceScheduledFiles( HREG reg ) char doomedFile[MAXREGPATHLEN]; char srcFile[MAXREGPATHLEN]; - nsFileSpec doomedSpec; - nsFileSpec srcSpec; - nsCOMPtr src; - nsCOMPtr dest; + nsCOMPtr doomedSpec; + nsCOMPtr srcSpec; + nsCOMPtr src; + nsCOMPtr dest; nsresult rv1, rv2; - rv1 = NS_NewFileSpec(getter_AddRefs(src)); - rv2 = NS_NewFileSpec(getter_AddRefs(dest)); + rv1 = NS_NewLocalFile("", getter_AddRefs(src)); + rv2 = NS_NewLocalFile("", getter_AddRefs(dest)); if (NS_SUCCEEDED(rv1) && NS_SUCCEEDED(rv2)) { uint32 bufsize; @@ -447,11 +472,11 @@ void ReplaceScheduledFiles( HREG reg ) if ( err1 == REGERR_OK && err2 == REGERR_OK ) { - src->SetPersistentDescriptorString(srcFile); - rv1 = src->GetFileSpec(&srcSpec); + src->InitWithPath((char*)srcFile); + rv1 = src->Clone(getter_AddRefs(srcSpec)); - dest->SetPersistentDescriptorString(doomedFile); - rv2 = dest->GetFileSpec(&doomedSpec); + dest->InitWithPath((char*)doomedFile); + rv2 = dest->Clone(getter_AddRefs(doomedSpec)); if (NS_SUCCEEDED(rv1) && NS_SUCCEEDED(rv2)) { diff --git a/mozilla/xpinstall/src/ScheduledTasks.h b/mozilla/xpinstall/src/ScheduledTasks.h index 7be3016a033..a31906acbd0 100644 --- a/mozilla/xpinstall/src/ScheduledTasks.h +++ b/mozilla/xpinstall/src/ScheduledTasks.h @@ -30,11 +30,12 @@ #include "NSReg.h" //#include "mozreg.h" #include "nsFileSpec.h" +#include "nsIFile.h" PR_BEGIN_EXTERN_C -PRInt32 DeleteFileNowOrSchedule(const nsFileSpec& filename); -PRInt32 ReplaceFileNowOrSchedule(nsFileSpec& tmpfile, nsFileSpec& target ); +PRInt32 DeleteFileNowOrSchedule(nsIFile* filename); +PRInt32 ReplaceFileNowOrSchedule(nsIFile* tmpfile, nsIFile* target ); void PerformScheduledTasks(HREG reg); diff --git a/mozilla/xpinstall/src/nsInstall.cpp b/mozilla/xpinstall/src/nsInstall.cpp index 23b178761b1..b351db76c9c 100644 --- a/mozilla/xpinstall/src/nsInstall.cpp +++ b/mozilla/xpinstall/src/nsInstall.cpp @@ -37,6 +37,7 @@ #include "nsFileSpec.h" #include "nsFileStream.h" #include "nsSpecialSystemDirectory.h" +#include "nsDirectoryService.h" #include "nsIPref.h" @@ -72,9 +73,11 @@ #ifdef XP_MAC #include "Gestalt.h" #include "nsAppleSingleDecoder.h" +#include "nsILocalFileMac.h" #endif #include "nsILocalFile.h" +#include "nsIURL.h" static NS_DEFINE_IID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID); static NS_DEFINE_IID(kIEventQueueServiceIID, NS_IEVENTQUEUESERVICE_IID); @@ -99,7 +102,7 @@ static NS_DEFINE_IID(kIStringBundleServiceIID, NS_ISTRINGBUNDLESERVICE_IID); MOZ_DECL_CTOR_COUNTER(nsInstallInfo); -nsInstallInfo::nsInstallInfo(nsIFileSpec* aFile, +nsInstallInfo::nsInstallInfo(nsIFile* aFile, const PRUnichar* aURL, const PRUnichar* aArgs, long flags, @@ -122,17 +125,17 @@ nsInstallInfo::~nsInstallInfo() } nsresult -nsInstallInfo::GetLocalFile(nsFileSpec& aSpec) +nsInstallInfo::GetLocalFile(nsIFile** aSpec) { if (!mFile) return NS_ERROR_NULL_POINTER; - - return mFile->GetFileSpec(&aSpec); + + return mFile->Clone(getter_AddRefs(aSpec)); } - - +static NS_DEFINE_CID(kStandardURLCID, NS_STANDARDURL_CID); + static NS_DEFINE_IID(kISoftwareUpdateIID, NS_ISOFTWAREUPDATE_IID); static NS_DEFINE_IID(kSoftwareUpdateCID, NS_SoftwareUpdate_CID); @@ -155,8 +158,8 @@ nsInstall::nsInstall(nsIZipReader * theJARFile) mRegisterPackage = PR_FALSE; mStatusSent = PR_FALSE; mStartInstallCompleted = PR_FALSE; - mJarFileLocation = ""; -// mInstallArguments = ""; + mJarFileLocation = nsnull; + //mInstallArguments = ""; mPackageFolder = nsnull; // mJarFileData is an opaque handle to the jarfile. @@ -262,7 +265,9 @@ nsInstall::InternalAbort(PRInt32 errcode) nsInstallObject* ie; if (mInstalledFiles != nsnull) { - for (PRInt32 i=mInstalledFiles->Count() - 1; i >= 0; i--) + //PRUint32 i; + //mInstalledFiles->Count(&i); + for (PRInt32 i = mInstalledFiles->Count(); i >= 0; i--) { ie = (nsInstallObject *)mInstalledFiles->ElementAt(i); if (ie) @@ -730,9 +735,10 @@ nsInstall::DiskSpaceAvailable(const nsString& aFolder, PRInt64* aReturn) return NS_OK; } - nsFileSpec fsFolder(aFolder); + nsCOMPtr folder; + NS_NewLocalFile(aFolder.ToNewCString(), getter_AddRefs(folder)); - *aReturn = fsFolder.GetDiskSpaceAvailable(); + result = folder->GetDiskSpaceAvailable(aReturn); return NS_OK; } @@ -790,8 +796,12 @@ nsInstall::FinalizeInstall(PRInt32* aReturn) } - if ( mInstalledFiles != NULL && mInstalledFiles->Count() > 0 ) + if ( mInstalledFiles != NULL) { + //PRUint32 i = 0; + //mInstalledFiles->Count(&i); + if ( mInstalledFiles->Count() > 0 ) + { if ( mUninstallPackage ) { VR_UninstallCreateNode( (char*)(const char*) nsAutoCString(mRegistryPackageName), @@ -817,6 +827,8 @@ nsInstall::FinalizeInstall(PRInt32* aReturn) nsInstallObject* ie = nsnull; + //PRUint32 numberOfFiles = 0; + //mInstalledFiles->Count(&numberOfFiles); for (PRInt32 i=0; i < mInstalledFiles->Count(); i++) { ie = (nsInstallObject*)mInstalledFiles->ElementAt(i); @@ -879,6 +891,7 @@ nsInstall::FinalizeInstall(PRInt32* aReturn) mNotifier->FinalStatus(mInstallURL.GetUnicode(), *aReturn); mStatusSent = PR_TRUE; } + } } else { @@ -1139,8 +1152,8 @@ nsInstall::LoadResources(JSContext* cx, const nsString& aBaseName, jsval* aRetur return NS_OK; } nsresult ret; - nsFileSpec* resFile; - nsFileURL* resFileURL = nsnull; + nsCOMPtr resFile; + nsCOMPtr resFileURL = nsnull; nsIURI *url = nsnull; nsILocale* locale = nsnull; nsIStringBundleService* service = nsnull; @@ -1161,7 +1174,7 @@ nsInstall::LoadResources(JSContext* cx, const nsString& aBaseName, jsval* aRetur // extract properties file // XXX append locale info: lang code, country code, .properties suffix to aBaseName - PRInt32 err = ExtractFileFromJar(aBaseName, nsnull, &resFile); + PRInt32 err = ExtractFileFromJar(aBaseName, nsnull, getter_AddRefs(resFile)); if ( (!resFile) || (err != nsInstall::SUCCESS) ) { SaveError( err ); @@ -1182,12 +1195,18 @@ nsInstall::LoadResources(JSContext* cx, const nsString& aBaseName, jsval* aRetur goto cleanup; // construct properties file URL as required by StringBundle interface - resFileURL = new nsFileURL( *resFile ); - ret = NS_NewURI(&url, resFileURL->GetURLString()); - if (resFileURL) - delete resFileURL; - if (NS_FAILED(ret)) - goto cleanup; + + //nsCOMPtr url; + ret = nsComponentManager::CreateInstance(kStandardURLCID, nsnull, + NS_GET_IID(nsIFileURL), + getter_AddRefs(resFileURL)); + + if (NS_FAILED(ret)) goto cleanup; + + ret = resFileURL->SetFile(resFile); + + if (NS_FAILED(ret)) goto cleanup; + // get the string bundle using the extracted properties file #if 1 @@ -1262,12 +1281,6 @@ cleanup: NS_IF_RELEASE( url ); NS_IF_RELEASE( bundle ); NS_IF_RELEASE( propEnum ); - if (resFile) - { - // delete the transient properties file - resFile->Delete(PR_FALSE); - delete resFile; - } return NS_OK; } @@ -1410,6 +1423,7 @@ nsInstall::StartInstall(const nsString& aUserPackageName, const nsString& aRegis mVersionInfo->Init(aVersion); mInstalledFiles = new nsVoidArray(); + //nsresult rv = NS_NewISupportsArray(getter_AddRefs(mInstalledFiles)); if (mInstalledFiles == nsnull) { @@ -1473,7 +1487,7 @@ nsInstall::Uninstall(const nsString& aRegistryPackageName, PRInt32* aReturn) void -nsInstall::AddPatch(nsHashKey *aKey, nsFileSpec* fileName) +nsInstall::AddPatch(nsHashKey *aKey, nsIFile* fileName) { if (mPatchList != nsnull) { @@ -1482,7 +1496,7 @@ nsInstall::AddPatch(nsHashKey *aKey, nsFileSpec* fileName) } void -nsInstall::GetPatch(nsHashKey *aKey, nsFileSpec** fileName) +nsInstall::GetPatch(nsHashKey *aKey, nsIFile** fileName) { if (!fileName) return; @@ -1491,72 +1505,68 @@ nsInstall::GetPatch(nsHashKey *aKey, nsFileSpec** fileName) if (mPatchList != nsnull) { - *fileName = (nsFileSpec*) mPatchList->Get(aKey); + *fileName = (nsIFile*) mPatchList->Get(aKey); } } PRInt32 nsInstall::FileOpDirCreate(nsInstallFolder& aTarget, PRInt32* aReturn) { - nsFileSpec* localFS = new nsFileSpec(*aTarget.GetFileSpec()); - if (localFS == nsnull) + nsCOMPtr localFile = aTarget.GetFileSpec(); + if (localFile == nsnull) { *aReturn = SaveError(nsInstall::OUT_OF_MEMORY); return NS_OK; } - nsInstallFileOpItem* ifop = new nsInstallFileOpItem(this, NS_FOP_DIR_CREATE, *localFS, aReturn); + nsInstallFileOpItem* ifop = new nsInstallFileOpItem(this, NS_FOP_DIR_CREATE, localFile, aReturn); + if (ifop == nsnull) + { + *aReturn = SaveError(nsInstall::OUT_OF_MEMORY); + return NS_OK; + } + + PRInt32 result = SanityCheck(); + if (result != nsInstall::SUCCESS) + { + delete ifop; + *aReturn = SaveError( result ); + return NS_OK; + } + + if (*aReturn == nsInstall::SUCCESS) + { + *aReturn = ScheduleForInstall( ifop ); + } + + SaveError(*aReturn); + + return NS_OK; +} + +PRInt32 +nsInstall::FileOpDirGetParent(nsInstallFolder& aTarget, nsIFile** aReturn) +{ + nsCOMPtr localFile = aTarget.GetFileSpec(); + + localFile->GetParent(aReturn); + + return NS_OK; +} + +PRInt32 +nsInstall::FileOpDirRemove(nsInstallFolder& aTarget, PRInt32 aFlags, PRInt32* aReturn) +{ + nsCOMPtr localFile = aTarget.GetFileSpec(); + if (localFile == nsnull) + { + *aReturn = SaveError(nsInstall::OUT_OF_MEMORY); + return NS_OK; + } + + nsInstallFileOpItem* ifop = new nsInstallFileOpItem(this, NS_FOP_DIR_REMOVE, localFile, aFlags, aReturn); if (ifop == nsnull) { - delete localFS; - *aReturn = SaveError(nsInstall::OUT_OF_MEMORY); - return NS_OK; - } - - PRInt32 result = SanityCheck(); - if (result != nsInstall::SUCCESS) - { - delete localFS; - delete ifop; - *aReturn = SaveError( result ); - return NS_OK; - } - - if (*aReturn == nsInstall::SUCCESS) - { - *aReturn = ScheduleForInstall( ifop ); - } - delete localFS; - - SaveError(*aReturn); - - return NS_OK; -} - -PRInt32 -nsInstall::FileOpDirGetParent(nsInstallFolder& aTarget, nsFileSpec* aReturn) -{ - nsFileSpec* localFS = aTarget.GetFileSpec(); - - localFS->GetParent(*aReturn); - - return NS_OK; -} - -PRInt32 -nsInstall::FileOpDirRemove(nsInstallFolder& aTarget, PRInt32 aFlags, PRInt32* aReturn) -{ - nsFileSpec* localFS = new nsFileSpec(*aTarget.GetFileSpec()); - if (localFS == nsnull) - { - *aReturn = SaveError(nsInstall::OUT_OF_MEMORY); - return NS_OK; - } - - nsInstallFileOpItem* ifop = new nsInstallFileOpItem(this, NS_FOP_DIR_REMOVE, *localFS, aFlags, aReturn); - if (ifop == nsnull) - { - delete localFS; *aReturn = SaveError(nsInstall::OUT_OF_MEMORY); return NS_OK; } @@ -1564,7 +1574,6 @@ nsInstall::FileOpDirRemove(nsInstallFolder& aTarget, PRInt32 aFlags, PRInt32* aR PRInt32 result = SanityCheck(); if (result != nsInstall::SUCCESS) { - delete localFS; delete ifop; *aReturn = SaveError( result ); return NS_OK; @@ -1575,8 +1584,6 @@ nsInstall::FileOpDirRemove(nsInstallFolder& aTarget, PRInt32 aFlags, PRInt32* aR *aReturn = ScheduleForInstall( ifop ); } - delete localFS; - SaveError(*aReturn); return NS_OK; @@ -1585,17 +1592,16 @@ nsInstall::FileOpDirRemove(nsInstallFolder& aTarget, PRInt32 aFlags, PRInt32* aR PRInt32 nsInstall::FileOpDirRename(nsInstallFolder& aSrc, nsString& aTarget, PRInt32* aReturn) { - nsFileSpec* localFS = new nsFileSpec(*aSrc.GetFileSpec()); - if (localFS == nsnull) + nsCOMPtr localFile = aSrc.GetFileSpec(); + if (localFile == nsnull) { *aReturn = SaveError(nsInstall::OUT_OF_MEMORY); return NS_OK; } - nsInstallFileOpItem* ifop = new nsInstallFileOpItem(this, NS_FOP_DIR_RENAME, *localFS, aTarget, aReturn); + nsInstallFileOpItem* ifop = new nsInstallFileOpItem(this, NS_FOP_DIR_RENAME, localFile, aTarget, aReturn); if (ifop == nsnull) { - delete localFS; *aReturn = SaveError(nsInstall::OUT_OF_MEMORY); return NS_OK; } @@ -1603,7 +1609,6 @@ nsInstall::FileOpDirRename(nsInstallFolder& aSrc, nsString& aTarget, PRInt32* aR PRInt32 result = SanityCheck(); if (result != nsInstall::SUCCESS) { - delete localFS; delete ifop; *aReturn = SaveError( result ); return NS_OK; @@ -1614,8 +1619,6 @@ nsInstall::FileOpDirRename(nsInstallFolder& aSrc, nsString& aTarget, PRInt32* aR *aReturn = ScheduleForInstall( ifop ); } - delete localFS; - SaveError(*aReturn); return NS_OK; @@ -1624,25 +1627,23 @@ nsInstall::FileOpDirRename(nsInstallFolder& aSrc, nsString& aTarget, PRInt32* aR PRInt32 nsInstall::FileOpFileCopy(nsInstallFolder& aSrc, nsInstallFolder& aTarget, PRInt32* aReturn) { - nsFileSpec* localSrcFS = new nsFileSpec(*aSrc.GetFileSpec()); - if (localSrcFS == nsnull) + nsCOMPtr localSrcFile = aSrc.GetFileSpec(); + if (localSrcFile == nsnull) { *aReturn = SaveError(nsInstall::OUT_OF_MEMORY); return NS_OK; } - nsFileSpec* localTargetFS = new nsFileSpec(*aTarget.GetFileSpec()); - if (localTargetFS == nsnull) + nsCOMPtrlocalTargetFile = aTarget.GetFileSpec(); + if (localTargetFile == nsnull) { *aReturn = SaveError(nsInstall::OUT_OF_MEMORY); return NS_OK; } - nsInstallFileOpItem* ifop = new nsInstallFileOpItem(this, NS_FOP_FILE_COPY, *localSrcFS, *localTargetFS, aReturn); + nsInstallFileOpItem* ifop = new nsInstallFileOpItem(this, NS_FOP_FILE_COPY, localSrcFile, localTargetFile, aReturn); if (ifop == nsnull) { - delete localSrcFS; - delete localTargetFS; *aReturn = SaveError(nsInstall::OUT_OF_MEMORY); return NS_OK; } @@ -1650,8 +1651,6 @@ nsInstall::FileOpFileCopy(nsInstallFolder& aSrc, nsInstallFolder& aTarget, PRInt PRInt32 result = SanityCheck(); if (result != nsInstall::SUCCESS) { - delete localSrcFS; - delete localTargetFS; delete ifop; *aReturn = SaveError( result ); return NS_OK; @@ -1662,9 +1661,6 @@ nsInstall::FileOpFileCopy(nsInstallFolder& aSrc, nsInstallFolder& aTarget, PRInt *aReturn = ScheduleForInstall( ifop ); } - delete localSrcFS; - delete localTargetFS; - SaveError(*aReturn); return NS_OK; @@ -1673,17 +1669,16 @@ nsInstall::FileOpFileCopy(nsInstallFolder& aSrc, nsInstallFolder& aTarget, PRInt PRInt32 nsInstall::FileOpFileDelete(nsInstallFolder& aTarget, PRInt32 aFlags, PRInt32* aReturn) { - nsFileSpec* localFS = new nsFileSpec(*aTarget.GetFileSpec()); - if (localFS == nsnull) + nsCOMPtr localFile = aTarget.GetFileSpec(); + if (localFile == nsnull) { *aReturn = SaveError(nsInstall::OUT_OF_MEMORY); return NS_OK; } - nsInstallFileOpItem* ifop = new nsInstallFileOpItem(this, NS_FOP_FILE_DELETE, *localFS, aFlags, aReturn); + nsInstallFileOpItem* ifop = new nsInstallFileOpItem(this, NS_FOP_FILE_DELETE, localFile, aFlags, aReturn); if (ifop == nsnull) { - delete localFS; *aReturn = SaveError(nsInstall::OUT_OF_MEMORY); return NS_OK; } @@ -1691,7 +1686,6 @@ nsInstall::FileOpFileDelete(nsInstallFolder& aTarget, PRInt32 aFlags, PRInt32* a PRInt32 result = SanityCheck(); if (result != nsInstall::SUCCESS) { - delete localFS; delete ifop; *aReturn = SaveError( result ); return NS_OK; @@ -1702,8 +1696,6 @@ nsInstall::FileOpFileDelete(nsInstallFolder& aTarget, PRInt32 aFlags, PRInt32* a *aReturn = ScheduleForInstall( ifop ); } - delete localFS; - SaveError(*aReturn); return NS_OK; @@ -1712,17 +1704,16 @@ nsInstall::FileOpFileDelete(nsInstallFolder& aTarget, PRInt32 aFlags, PRInt32* a PRInt32 nsInstall::FileOpFileExecute(nsInstallFolder& aTarget, nsString& aParams, PRInt32* aReturn) { - nsFileSpec* localFS = new nsFileSpec(*aTarget.GetFileSpec()); - if (localFS == nsnull) + nsCOMPtr localFile = aTarget.GetFileSpec(); + if (localFile == nsnull) { *aReturn = SaveError(nsInstall::OUT_OF_MEMORY); return NS_OK; } - nsInstallFileOpItem* ifop = new nsInstallFileOpItem(this, NS_FOP_FILE_EXECUTE, *localFS, aParams, aReturn); + nsInstallFileOpItem* ifop = new nsInstallFileOpItem(this, NS_FOP_FILE_EXECUTE, localFile, aParams, aReturn); if (ifop == nsnull) { - delete localFS; *aReturn = SaveError(nsInstall::OUT_OF_MEMORY); return NS_OK; } @@ -1730,7 +1721,6 @@ nsInstall::FileOpFileExecute(nsInstallFolder& aTarget, nsString& aParams, PRInt3 PRInt32 result = SanityCheck(); if (result != nsInstall::SUCCESS) { - delete localFS; delete ifop; *aReturn = SaveError( result ); return NS_OK; @@ -1741,8 +1731,6 @@ nsInstall::FileOpFileExecute(nsInstallFolder& aTarget, nsString& aParams, PRInt3 *aReturn = ScheduleForInstall( ifop ); } - delete localFS; - SaveError(*aReturn); return NS_OK; @@ -1751,9 +1739,9 @@ nsInstall::FileOpFileExecute(nsInstallFolder& aTarget, nsString& aParams, PRInt3 PRInt32 nsInstall::FileOpFileExists(nsInstallFolder& aTarget, PRBool* aReturn) { - nsFileSpec* localFS = aTarget.GetFileSpec(); + nsCOMPtr localFile = aTarget.GetFileSpec(); - *aReturn = localFS->Exists(); + localFile->Exists(aReturn); return NS_OK; } @@ -1766,78 +1754,80 @@ nsInstall::FileOpFileGetNativeVersion(nsInstallFolder& aTarget, nsString* aRetur PRInt32 nsInstall::FileOpFileGetDiskSpaceAvailable(nsInstallFolder& aTarget, PRInt64* aReturn) { - nsFileSpec* localFS = aTarget.GetFileSpec(); + nsresult rv; + nsCOMPtr file = aTarget.GetFileSpec(); + nsCOMPtr localFile = do_QueryInterface(file, &rv); - *aReturn = localFS->GetDiskSpaceAvailable(); + localFile->GetDiskSpaceAvailable(aReturn); //nsIFileXXX: need to figure out how to call GetDiskSpaceAvailable return NS_OK; } +//nsIFileXXX: need to get nsIFile equivalent to GetModDate PRInt32 nsInstall::FileOpFileGetModDate(nsInstallFolder& aTarget, nsFileSpec::TimeStamp* aReturn) { - nsFileSpec* localFS = aTarget.GetFileSpec(); + //nsCOMPtr localFile = aTarget.GetFileSpec(); - localFS->GetModDate(*aReturn); + //localFile->GetModDate(*aReturn); return NS_OK; } PRInt32 -nsInstall::FileOpFileGetSize(nsInstallFolder& aTarget, PRUint32* aReturn) +nsInstall::FileOpFileGetSize(nsInstallFolder& aTarget, PRInt64* aReturn) { - nsFileSpec* localFS = aTarget.GetFileSpec(); + nsCOMPtr localFile = aTarget.GetFileSpec(); - *aReturn = localFS->GetFileSize(); + localFile->GetFileSize(aReturn); return NS_OK; } PRInt32 nsInstall::FileOpFileIsDirectory(nsInstallFolder& aTarget, PRBool* aReturn) { - nsFileSpec* localFS = aTarget.GetFileSpec(); + nsCOMPtr localFile = aTarget.GetFileSpec(); - *aReturn = localFS->IsDirectory(); + localFile->IsDirectory(aReturn); return NS_OK; } PRInt32 nsInstall::FileOpFileIsFile(nsInstallFolder& aTarget, PRBool* aReturn) { - nsFileSpec* localFS = aTarget.GetFileSpec(); + nsCOMPtr localFile = aTarget.GetFileSpec(); - *aReturn = localFS->IsFile(); + localFile->IsFile(aReturn); return NS_OK; } +//nsIFileXXX: need to get the ModDateChanged equivalent for nsIFile PRInt32 nsInstall::FileOpFileModDateChanged(nsInstallFolder& aTarget, nsFileSpec::TimeStamp& aOldStamp, PRBool* aReturn) { - nsFileSpec* localFS = aTarget.GetFileSpec(); + //nsFileSpec* localFS = aTarget.GetFileSpec(); - *aReturn = localFS->ModDateChanged(aOldStamp); + //*aReturn = localFS->ModDateChanged(aOldStamp); return NS_OK; } PRInt32 nsInstall::FileOpFileMove(nsInstallFolder& aSrc, nsInstallFolder& aTarget, PRInt32* aReturn) { - nsFileSpec* localSrcFS = new nsFileSpec(*aSrc.GetFileSpec()); - if (localSrcFS == nsnull) + nsCOMPtr localSrcFile = aSrc.GetFileSpec(); + if (localSrcFile == nsnull) { *aReturn = SaveError(nsInstall::OUT_OF_MEMORY); return NS_OK; } - nsFileSpec* localTargetFS = new nsFileSpec(*aTarget.GetFileSpec()); - if (localTargetFS == nsnull) + nsCOMPtr localTargetFile = aTarget.GetFileSpec(); + if (localTargetFile == nsnull) { *aReturn = SaveError(nsInstall::OUT_OF_MEMORY); return NS_OK; } - nsInstallFileOpItem* ifop = new nsInstallFileOpItem(this, NS_FOP_FILE_MOVE, *localSrcFS, *localTargetFS, aReturn); + nsInstallFileOpItem* ifop = new nsInstallFileOpItem(this, NS_FOP_FILE_MOVE, localSrcFile, localTargetFile, aReturn); if (ifop == nsnull) { - delete localSrcFS; - delete localTargetFS; *aReturn = SaveError(nsInstall::OUT_OF_MEMORY); return NS_OK; } @@ -1845,8 +1835,6 @@ nsInstall::FileOpFileMove(nsInstallFolder& aSrc, nsInstallFolder& aTarget, PRInt PRInt32 result = SanityCheck(); if (result != nsInstall::SUCCESS) { - delete localSrcFS; - delete localTargetFS; delete ifop; *aReturn = SaveError( result ); return NS_OK; @@ -1857,9 +1845,6 @@ nsInstall::FileOpFileMove(nsInstallFolder& aSrc, nsInstallFolder& aTarget, PRInt *aReturn = ScheduleForInstall( ifop ); } - delete localSrcFS; - delete localTargetFS; - SaveError(*aReturn); return NS_OK; @@ -1868,17 +1853,16 @@ nsInstall::FileOpFileMove(nsInstallFolder& aSrc, nsInstallFolder& aTarget, PRInt PRInt32 nsInstall::FileOpFileRename(nsInstallFolder& aSrc, nsString& aTarget, PRInt32* aReturn) { - nsFileSpec* localFS = new nsFileSpec(*aSrc.GetFileSpec()); - if (localFS == nsnull) + nsCOMPtr localFile = aSrc.GetFileSpec(); + if (localFile == nsnull) { *aReturn = SaveError(nsInstall::OUT_OF_MEMORY); return NS_OK; } - nsInstallFileOpItem* ifop = new nsInstallFileOpItem(this, NS_FOP_FILE_RENAME,*localFS, aTarget, aReturn); + nsInstallFileOpItem* ifop = new nsInstallFileOpItem(this, NS_FOP_FILE_RENAME, localFile, aTarget, aReturn); if (ifop == nsnull) { - delete localFS; *aReturn = SaveError(nsInstall::OUT_OF_MEMORY); return NS_OK; } @@ -1886,7 +1870,6 @@ nsInstall::FileOpFileRename(nsInstallFolder& aSrc, nsString& aTarget, PRInt32* a PRInt32 result = SanityCheck(); if (result != nsInstall::SUCCESS) { - delete localFS; delete ifop; *aReturn = SaveError( result ); return NS_OK; @@ -1897,15 +1880,13 @@ nsInstall::FileOpFileRename(nsInstallFolder& aSrc, nsString& aTarget, PRInt32* a *aReturn = ScheduleForInstall( ifop ); } - delete localFS; - SaveError(*aReturn); return NS_OK; } PRInt32 -nsInstall::FileOpFileWindowsShortcut(nsFileSpec& aTarget, nsFileSpec& aShortcutPath, nsString& aDescription, nsFileSpec& aWorkingPath, nsString& aParams, nsFileSpec& aIcon, PRInt32 aIconId, PRInt32* aReturn) +nsInstall::FileOpFileWindowsShortcut(nsIFile* aTarget, nsIFile* aShortcutPath, nsString& aDescription, nsIFile* aWorkingPath, nsString& aParams, nsIFile* aIcon, PRInt32 aIconId, PRInt32* aReturn) { nsInstallFileOpItem* ifop = new nsInstallFileOpItem(this, NS_FOP_WIN_SHORTCUT, aTarget, aShortcutPath, aDescription, aWorkingPath, aParams, aIcon, aIconId, aReturn); @@ -1940,9 +1921,13 @@ nsInstall::FileOpFileMacAlias(nsString& aSourcePath, nsString& aAliasPath, PRInt *aReturn = nsInstall::SUCCESS; #ifdef XP_MAC - nsFileSpec nsfsSource(aSourcePath, PR_FALSE); - nsFileSpec nsfsAlias(aAliasPath, PR_TRUE); + //nsFileSpec nsfsSource(aSourcePath, PR_FALSE); + //nsFileSpec nsfsAlias(aAliasPath, PR_TRUE); + nsCOMPtr nsfsSource; + nsCOMPtr nsfsAlias; + NS_NewLocalFile(aSourcePath.ToNewCString(), getter_AddRefs(nsfsSource)); + NS_NewLocalFile(aAliasPath.ToNewCString(), getter_AddRefs(nsfsAlias)); nsInstallFileOpItem* ifop = new nsInstallFileOpItem(this, NS_FOP_MAC_ALIAS, nsfsSource, nsfsAlias, aReturn); PRInt32 result = SanityCheck(); @@ -2239,13 +2224,15 @@ nsInstall::CleanUp(void) { nsInstallObject* ie; - if ( mInstalledFiles != NULL ) + if ( mInstalledFiles != nsnull ) { + //PRUint32 numberOfObjects = 0; + //mInstalledFiles->Count(&numberOfObjects); for (PRInt32 i=0; i < mInstalledFiles->Count(); i++) { ie = (nsInstallObject*)mInstalledFiles->ElementAt(i); if (ie) - delete (ie); + delete ie; } mInstalledFiles->Clear(); @@ -2274,11 +2261,13 @@ nsInstall::CleanUp(void) void nsInstall::GetJarFileLocation(nsString& aFile) { - aFile.AssignWithConversion(mJarFileLocation.GetCString()); + char* temp; + mJarFileLocation->GetPath(&temp); + aFile.AssignWithConversion(temp); } void -nsInstall::SetJarFileLocation(const nsFileSpec& aFile) +nsInstall::SetJarFileLocation(nsIFile* aFile) { mJarFileLocation = aFile; } @@ -2331,14 +2320,19 @@ nsInstall::Confirm(nsString& string, PRBool* aReturn) // aRealName - This is the name that we did extract to. This will be allocated by use and should be disposed by the caller. PRInt32 -nsInstall::ExtractFileFromJar(const nsString& aJarfile, nsFileSpec* aSuggestedName, nsFileSpec** aRealName) +nsInstall::ExtractFileFromJar(const nsString& aJarfile, nsIFile* aSuggestedName, nsIFile** aRealName) { PRInt32 extpos = 0; - nsFileSpec *extractHereSpec; + nsCOMPtr extractHereSpec; + nsCOMPtr tempFile; + nsresult rv; if (aSuggestedName == nsnull) { - nsSpecialSystemDirectory tempFile(nsSpecialSystemDirectory::OS_TemporaryDirectory); + NS_WITH_SERVICE(nsIProperties, directoryService, NS_DIRECTORY_SERVICE_PROGID, &rv); + + directoryService->Get("system.OS_TemporaryDirectory", NS_GET_IID(nsIFile), getter_AddRefs(tempFile)); + nsString tempFileName; tempFileName.AssignWithConversion("xpinstall"); // Get the extension of the file in the JAR @@ -2351,12 +2345,12 @@ nsInstall::ExtractFileFromJar(const nsString& aJarfile, nsFileSpec* aSuggestedNa tempFileName += extension; } - tempFile += tempFileName; + tempFile->Append(tempFileName.ToNewCString()); // Create a temporary file to extract to - tempFile.MakeUnique(); + MakeUnique(tempFile); - extractHereSpec = new nsFileSpec(tempFile); + tempFile->Clone(getter_AddRefs(extractHereSpec)); if (extractHereSpec == nsnull) return nsInstall::OUT_OF_MEMORY; @@ -2364,30 +2358,34 @@ nsInstall::ExtractFileFromJar(const nsString& aJarfile, nsFileSpec* aSuggestedNa else { // extract to the final destination. - extractHereSpec = new nsFileSpec(*aSuggestedName); - if (extractHereSpec == nsnull) + nsCOMPtr temp; + aSuggestedName->Clone(getter_AddRefs(temp)); + tempFile = do_QueryInterface(temp, &rv); + if (tempFile == nsnull) return nsInstall::OUT_OF_MEMORY; - extractHereSpec->MakeUnique(); + MakeUnique(tempFile); + extractHereSpec = tempFile; } // We will overwrite what is in the way. is this something that we want to do? extractHereSpec->Delete(PR_FALSE); - nsresult rv; - nsCOMPtr file; - rv = NS_NewLocalFile(*extractHereSpec, getter_AddRefs(file)); - if (NS_SUCCEEDED(rv)) - rv = mJarFileData->Extract(nsAutoCString(aJarfile), file); + //nsCOMPtr file; + //rv = NS_NewLocalFile(*extractHereSpec, getter_AddRefs(file)); + //if (NS_SUCCEEDED(rv)) + rv = mJarFileData->Extract(nsAutoCString(aJarfile), extractHereSpec); if (NS_FAILED(rv)) { - if (extractHereSpec != nsnull) - delete extractHereSpec; return EXTRACTION_FAILED; } #ifdef XP_MAC - FSSpec finalSpec, extractedSpec = extractHereSpec->GetFSSpec(); + FSSpec finalSpec, extractedSpec; + + nsCOMPtr tempExtractHereSpec; + tempExtractHereSpec = do_QueryInterface(extractHereSpec, &rv); + tempExtractHereSpec->GetFSSpec(&extractedSpec); if ( nsAppleSingleDecoder::IsAppleSingleFile(&extractedSpec) ) { @@ -2399,8 +2397,6 @@ nsInstall::ExtractFileFromJar(const nsString& aJarfile, nsFileSpec* aSuggestedNa if (decodeErr != noErr) { - if (extractHereSpec) - delete extractHereSpec; if (asd) delete asd; return EXTRACTION_FAILED; @@ -2414,12 +2410,13 @@ nsInstall::ExtractFileFromJar(const nsString& aJarfile, nsFileSpec* aSuggestedNa FSpDelete(&extractedSpec); // "real name" in AppleSingle entry may cause file rename - *extractHereSpec = finalSpec; + tempExtractHereSpec->InitWithFSSpec(&finalSpec); + extractHereSpec = do_QueryInterface(tempExtractHereSpec, &rv); } } #endif - *aRealName = extractHereSpec; + extractHereSpec->Clone(getter_AddRefs(aRealName)); return nsInstall::SUCCESS; } @@ -2542,3 +2539,46 @@ nsInstall::DeleteVector(nsVoidArray* vector) vector = nsnull; } } + +nsresult MakeUnique(nsILocalFile* file) +{ + PRBool flagExists; + + nsresult rv = file->Exists(&flagExists); + + if (NS_FAILED(rv)) return rv; + if (!flagExists) return NS_ERROR_FAILURE; + + char* leafName; + + rv = file->GetLeafName(&leafName); + if (NS_FAILED(rv)) return rv; + + char* lastDot = strrchr(leafName, '.'); + char* suffix = ""; + if (lastDot) + { + suffix = nsCRT::strdup(lastDot); // include '.' + *lastDot = '\0'; // strip suffix and dot. + } + + // 27 should work on Macintosh, Unix, and Win32. + const int maxRootLength = 27 - nsCRT::strlen(suffix) - 1; + + if ((int)nsCRT::strlen(leafName) > (int)maxRootLength) + leafName[maxRootLength] = '\0'; + + for (short indx = 1; indx < 1000 && flagExists; indx++) + { + // start with "Picture-1.jpg" after "Picture.jpg" exists + char newName[32]; + sprintf(newName, "%s-%d%s", leafName, indx, suffix); + file->SetLeafName(newName); + + rv = file->Exists(&flagExists); + if (NS_FAILED(rv)) return rv; + } + return NS_OK; +} + + diff --git a/mozilla/xpinstall/src/nsInstall.h b/mozilla/xpinstall/src/nsInstall.h index bf98f5a29c4..19b77d074d6 100644 --- a/mozilla/xpinstall/src/nsInstall.h +++ b/mozilla/xpinstall/src/nsInstall.h @@ -39,6 +39,7 @@ #include "nsVoidArray.h" #include "nsHashtable.h" #include "nsCOMPtr.h" +#include "nsILocalFile.h" #include "nsSoftwareUpdate.h" @@ -61,7 +62,7 @@ class nsInstallInfo { public: - nsInstallInfo( nsIFileSpec* aFile, + nsInstallInfo( nsIFile* aFile, const PRUnichar* aURL, const PRUnichar* aArgs, long aFlags, @@ -69,7 +70,7 @@ class nsInstallInfo virtual ~nsInstallInfo(); - nsresult GetLocalFile(nsFileSpec& aSpec); + nsresult GetLocalFile(nsIFile** aSpec); void GetURL(nsString& aURL) { aURL = mURL; } @@ -87,7 +88,7 @@ class nsInstallInfo nsString mURL; nsString mArgs; - nsCOMPtr mFile; + nsCOMPtr mFile; nsCOMPtr mNotifier; }; @@ -221,7 +222,7 @@ class nsInstall PRInt32 Uninstall(const nsString& aPackageName, PRInt32* aReturn); PRInt32 FileOpDirCreate(nsInstallFolder& aTarget, PRInt32* aReturn); - PRInt32 FileOpDirGetParent(nsInstallFolder& aTarget, nsFileSpec* aReturn); + PRInt32 FileOpDirGetParent(nsInstallFolder& aTarget, nsIFile** aReturn); PRInt32 FileOpDirRemove(nsInstallFolder& aTarget, PRInt32 aFlags, PRInt32* aReturn); PRInt32 FileOpDirRename(nsInstallFolder& aSrc, nsString& aTarget, PRInt32* aReturn); PRInt32 FileOpFileCopy(nsInstallFolder& aSrc, nsInstallFolder& aTarget, PRInt32* aReturn); @@ -231,25 +232,25 @@ class nsInstall PRInt32 FileOpFileGetNativeVersion(nsInstallFolder& aTarget, nsString* aReturn); PRInt32 FileOpFileGetDiskSpaceAvailable(nsInstallFolder& aTarget, PRInt64* aReturn); PRInt32 FileOpFileGetModDate(nsInstallFolder& aTarget, nsFileSpec::TimeStamp* aReturn); - PRInt32 FileOpFileGetSize(nsInstallFolder& aTarget, PRUint32* aReturn); + PRInt32 FileOpFileGetSize(nsInstallFolder& aTarget, PRInt64* aReturn); PRInt32 FileOpFileIsDirectory(nsInstallFolder& aTarget, PRBool* aReturn); PRInt32 FileOpFileIsFile(nsInstallFolder& aTarget, PRBool* aReturn); PRInt32 FileOpFileModDateChanged(nsInstallFolder& aTarget, nsFileSpec::TimeStamp& aOldStamp, PRBool* aReturn); PRInt32 FileOpFileMove(nsInstallFolder& aSrc, nsInstallFolder& aTarget, PRInt32* aReturn); PRInt32 FileOpFileRename(nsInstallFolder& aSrc, nsString& aTarget, PRInt32* aReturn); - PRInt32 FileOpFileWindowsShortcut(nsFileSpec& aTarget, nsFileSpec& aShortcutPath, nsString& aDescription, nsFileSpec& aWorkingPath, nsString& aParams, nsFileSpec& aIcon, PRInt32 aIconId, PRInt32* aReturn); + PRInt32 FileOpFileWindowsShortcut(nsIFile* aTarget, nsIFile* aShortcutPath, nsString& aDescription, nsIFile* aWorkingPath, nsString& aParams, nsIFile* aIcon, PRInt32 aIconId, PRInt32* aReturn); PRInt32 FileOpFileMacAlias(nsString& aSourcePath, nsString& aAliasPath, PRInt32* aReturn); PRInt32 FileOpFileUnixLink(nsInstallFolder& aTarget, PRInt32 aFlags, PRInt32* aReturn); void LogComment(nsString& aComment); - PRInt32 ExtractFileFromJar(const nsString& aJarfile, nsFileSpec* aSuggestedName, nsFileSpec** aRealName); + PRInt32 ExtractFileFromJar(const nsString& aJarfile, nsIFile* aSuggestedName, nsIFile** aRealName); char* GetResourcedString(const nsString& aResName); - void AddPatch(nsHashKey *aKey, nsFileSpec* fileName); - void GetPatch(nsHashKey *aKey, nsFileSpec** fileName); + void AddPatch(nsHashKey *aKey, nsIFile* fileName); + void GetPatch(nsHashKey *aKey, nsIFile** fileName); void GetJarFileLocation(nsString& aFile); - void SetJarFileLocation(const nsFileSpec& aFile); + void SetJarFileLocation(nsIFile* aFile); void GetInstallArguments(nsString& args); void SetInstallArguments(const nsString& args); @@ -273,7 +274,7 @@ class nsInstall JSObject* mWinProfileObject; - nsFileSpec mJarFileLocation; + nsCOMPtr mJarFileLocation; nsIZipReader* mJarFileData; nsString mInstallArguments; @@ -292,6 +293,7 @@ class nsInstall nsInstallVersion* mVersionInfo; /* Component version info */ nsVoidArray* mInstalledFiles; + //nsCOMPtr mInstalledFiles; nsHashtable* mPatchList; nsIXPINotifier *mNotifier; @@ -320,4 +322,6 @@ class nsInstall static void DeleteVector(nsVoidArray* vector); }; +nsresult MakeUnique(nsILocalFile* file); + #endif diff --git a/mozilla/xpinstall/src/nsInstallDelete.cpp b/mozilla/xpinstall/src/nsInstallDelete.cpp index 1418467caed..6568dd28c39 100644 --- a/mozilla/xpinstall/src/nsInstallDelete.cpp +++ b/mozilla/xpinstall/src/nsInstallDelete.cpp @@ -56,21 +56,21 @@ nsInstallDelete::nsInstallDelete( nsInstall* inInstall, mDeleteStatus = DELETE_FILE; mFinalFile = nsnull; - nsFileSpec* tmp = folderSpec->GetFileSpec(); + nsCOMPtr tmp = folderSpec->GetFileSpec(); if (!tmp) { *error = nsInstall::INVALID_ARGUMENTS; return; } - mFinalFile = new nsFileSpec(*tmp); + tmp->Clone(getter_AddRefs(mFinalFile));; if (mFinalFile == nsnull) { *error = nsInstall::OUT_OF_MEMORY; return; } - *mFinalFile += inPartialPath; + mFinalFile->Append(inPartialPath.ToNewCString()); *error = ProcessInstallDelete(); } @@ -99,8 +99,6 @@ nsInstallDelete::nsInstallDelete( nsInstall* inInstall, nsInstallDelete::~nsInstallDelete() { - if (mFinalFile == nsnull) - delete mFinalFile; MOZ_COUNT_DTOR(nsInstallDelete); } @@ -175,7 +173,9 @@ char* nsInstallDelete::toString() if (rsrcVal) { - sprintf( buffer, rsrcVal, mFinalFile->GetCString()); + char* temp; + mFinalFile->GetPath(&temp); + sprintf( buffer, rsrcVal, temp); nsCRT::free(rsrcVal); } } @@ -231,10 +231,12 @@ PRInt32 nsInstallDelete::ProcessInstallDelete() if (err == REGERR_OK) { - if (mFinalFile) - delete mFinalFile; + //if (mFinalFile) + // delete mFinalFile; - mFinalFile = new nsFileSpec(tempRegistryString); + nsCOMPtr tempLocalFile; + NS_NewLocalFile(tempRegistryString, getter_AddRefs(tempLocalFile)); + mFinalFile = tempLocalFile; if (mFinalFile == nsnull) return nsInstall::OUT_OF_MEMORY; @@ -248,9 +250,13 @@ PRInt32 nsInstallDelete::ProcessInstallDelete() if(tempCString) Recycle(tempCString); - if (mFinalFile->Exists()) + PRBool flagExists, flagIsFile; + + mFinalFile->Exists(&flagExists); + if (flagExists) { - if (mFinalFile->IsFile()) + mFinalFile->IsFile(&flagIsFile); + if (flagIsFile) { err = nsInstall::SUCCESS; } @@ -271,12 +277,16 @@ PRInt32 nsInstallDelete::ProcessInstallDelete() PRInt32 nsInstallDelete::NativeComplete() { - NS_WARN_IF_FALSE(mFinalFile->Exists(),"nsInstallDelete::Complete -- file should exist!"); - if (mFinalFile->Exists()) + PRBool flagExists, flagIsFile; + + mFinalFile->Exists(&flagExists); + NS_WARN_IF_FALSE(flagExists,"nsInstallDelete::Complete -- file should exist!"); + if (flagExists) { - if (mFinalFile->IsFile()) + mFinalFile->IsFile(&flagIsFile); + if (flagIsFile) { - return DeleteFileNowOrSchedule(*mFinalFile); + return DeleteFileNowOrSchedule(mFinalFile); } else { diff --git a/mozilla/xpinstall/src/nsInstallDelete.h b/mozilla/xpinstall/src/nsInstallDelete.h index 6f6e5bd58ea..ffc1c012eae 100644 --- a/mozilla/xpinstall/src/nsInstallDelete.h +++ b/mozilla/xpinstall/src/nsInstallDelete.h @@ -65,7 +65,7 @@ class nsInstallDelete : public nsInstallObject /* Private Fields */ - nsFileSpec* mFinalFile; + nsCOMPtr mFinalFile; nsString mRegistryName; PRInt32 mDeleteStatus; diff --git a/mozilla/xpinstall/src/nsInstallExecute.cpp b/mozilla/xpinstall/src/nsInstallExecute.cpp index d6ac9dc05ec..b7b316c896a 100644 --- a/mozilla/xpinstall/src/nsInstallExecute.cpp +++ b/mozilla/xpinstall/src/nsInstallExecute.cpp @@ -63,8 +63,6 @@ nsInstallExecute:: nsInstallExecute( nsInstall* inInstall, nsInstallExecute::~nsInstallExecute() { - if (mExecutableFile) - delete mExecutableFile; MOZ_COUNT_DTOR(nsInstallExecute); } @@ -76,22 +74,26 @@ PRInt32 nsInstallExecute::Prepare() if (mInstall == NULL || mJarLocation.IsEmpty()) return nsInstall::INVALID_ARGUMENTS; - return mInstall->ExtractFileFromJar(mJarLocation, nsnull, &mExecutableFile); + return mInstall->ExtractFileFromJar(mJarLocation, nsnull, getter_AddRefs(mExecutableFile)); } PRInt32 nsInstallExecute::Complete() { + PRBool flagExists; + PRInt32 result = NS_OK; + if (mExecutableFile == nsnull) return nsInstall::INVALID_ARGUMENTS; - nsFileSpec app( *mExecutableFile); + nsCOMPtr app = mExecutableFile; - if (!app.Exists()) - { - return nsInstall::INVALID_ARGUMENTS; - } + app->Exists(&flagExists); + if (!flagExists) + { + return nsInstall::INVALID_ARGUMENTS; + } - PRInt32 result = app.Execute( mArgs ); + //PRInt32 result = app->Spawn(); // nsIFileXXX: Need to implement Spawn or stay with Execute. DeleteFileNowOrSchedule( app ); @@ -104,7 +106,7 @@ void nsInstallExecute::Abort() if (mExecutableFile == nsnull) return; - DeleteFileNowOrSchedule(*mExecutableFile); + DeleteFileNowOrSchedule(mExecutableFile); } char* nsInstallExecute::toString() @@ -137,7 +139,9 @@ char* nsInstallExecute::toString() if (rsrcVal) { - sprintf( buffer, rsrcVal, mExecutableFile->GetCString()); + char* temp; + mExecutableFile->GetPath(&temp); + sprintf( buffer, rsrcVal, temp); nsCRT::free(rsrcVal); } } diff --git a/mozilla/xpinstall/src/nsInstallExecute.h b/mozilla/xpinstall/src/nsInstallExecute.h index 668e88efe87..a6951eeebf0 100644 --- a/mozilla/xpinstall/src/nsInstallExecute.h +++ b/mozilla/xpinstall/src/nsInstallExecute.h @@ -62,7 +62,7 @@ class nsInstallExecute : public nsInstallObject nsString mJarLocation; // Location in the JAR nsString mArgs; // command line arguments - nsFileSpec *mExecutableFile; // temporary file location + nsCOMPtr mExecutableFile; // temporary file location PRInt32 NativeComplete(void); diff --git a/mozilla/xpinstall/src/nsInstallFile.cpp b/mozilla/xpinstall/src/nsInstallFile.cpp index b83663d41d3..e48bbdb66df 100644 --- a/mozilla/xpinstall/src/nsInstallFile.cpp +++ b/mozilla/xpinstall/src/nsInstallFile.cpp @@ -66,6 +66,8 @@ nsInstallFile::nsInstallFile(nsInstall* inInstall, { MOZ_COUNT_CTOR(nsInstallFile); + PRBool flagExists, flagIsFile; + if ((folderSpec == nsnull) || (inInstall == NULL)) { *error = nsInstall::INVALID_ARGUMENTS; @@ -136,24 +138,26 @@ nsInstallFile::nsInstallFile(nsInstall* inInstall, Recycle(qualifiedRegNameString); #endif - nsFileSpec* tmp = folderSpec->GetFileSpec(); + nsCOMPtr tmp = folderSpec->GetFileSpec(); if (!tmp) { *error = nsInstall::INVALID_ARGUMENTS; return; } - mFinalFile = new nsFileSpec(*tmp); + tmp->Clone(getter_AddRefs(mFinalFile)); if (mFinalFile == nsnull) { *error = nsInstall::OUT_OF_MEMORY; return; } - if ( mFinalFile->Exists() ) + mFinalFile->Exists(&flagExists); + if (flagExists) { // is there a file with the same name as the proposed folder? - if ( mFinalFile->IsFile() ) + mFinalFile->IsFile(&flagIsFile); + if ( flagIsFile) { *error = nsInstall::FILENAME_ALREADY_USED; return; @@ -166,25 +170,63 @@ nsInstallFile::nsInstallFile(nsInstall* inInstall, * to be an existing dir */ int dirPermissions = 0755; // std default for UNIX, ignored otherwise - mFinalFile->CreateDir(dirPermissions); + mFinalFile->Create(1, dirPermissions); } - *mFinalFile += inPartialPath; - - mReplaceFile = mFinalFile->Exists(); + //Need to parse the inPartialPath to remove any separators + PRBool finished = PR_FALSE; + PRUint32 offset = 0; + PRInt32 location = 0, pass = 0; + nsString subString; + + //nsString tempPartialPath(inPartialPath); + + while (!finished) + { + location = inPartialPath.FindChar('/',PR_FALSE, offset); + if ((location < 0) && (pass == 0)) //no separators were found + { + mFinalFile->Append(inPartialPath.ToNewCString()); + finished = PR_TRUE; + } + else if ((location < 0) && (pass > 0) && (offset < inPartialPath.mLength)) //last occurance + { + nsresult rv = inPartialPath.Mid(subString, offset, inPartialPath.mLength); + mFinalFile->Append(subString.ToNewCString()); + finished = PR_TRUE; + } + else + { + nsresult rv = inPartialPath.Mid(subString, offset, location); + mFinalFile->Append(subString.ToNewCString()); + offset = location + 1; + pass++; + } + } + + //{ + // nsresult rv = mFinalFile->Append(inPartialPath.ToNewCString()); + // if (rv != NS_OK) + // { + // *error = nsInstall::ILLEGAL_RELATIVE_PATH; + // return; + // } + //} + mFinalFile->Exists(&mReplaceFile); if (mReplaceFile == PR_FALSE) { /* although it appears that we are creating the dir _again_ it is necessary * when inPartialPath has arbitrary levels of nested dirs before the leaf */ - nsFileSpec parent; - mFinalFile->GetParent(parent); - nsFileSpec makeDirs(parent.GetCString(), PR_TRUE); + nsCOMPtr parent; + mFinalFile->GetParent(getter_AddRefs(parent)); + //nsFileSpec makeDirs(parent.GetCString(), PR_TRUE); + parent->Create(1, 0755); //nsIFileXXX: What kind of permissions are required here? } - mVersionRegistryName = new nsString(inComponentName); - mJarLocation = new nsString(inJarLocation); + mVersionRegistryName = new nsString(inComponentName); + mJarLocation = new nsString(inJarLocation); mVersionInfo = new nsString(inVInfo); if (mVersionRegistryName == nsnull || @@ -222,14 +264,14 @@ nsInstallFile::~nsInstallFile() if (mJarLocation) delete mJarLocation; - if (mExtractedFile) - delete mExtractedFile; - - if (mFinalFile) - delete mFinalFile; - if (mVersionInfo) - delete mVersionInfo; + delete mVersionInfo; + + //if(mFinalFile) + // mFinalFile = nsnull; + + //if(mExtractedFile) + // mExtractedFile = nsnull; MOZ_COUNT_DTOR(nsInstallFile); } @@ -245,7 +287,7 @@ PRInt32 nsInstallFile::Prepare() if (mInstall == nsnull || mFinalFile == nsnull || mJarLocation == nsnull ) return nsInstall::INVALID_ARGUMENTS; - return mInstall->ExtractFileFromJar(*mJarLocation, mFinalFile, &mExtractedFile); + return mInstall->ExtractFileFromJar(*mJarLocation, mFinalFile, getter_AddRefs(mExtractedFile)); } /* Complete @@ -290,7 +332,7 @@ char* nsInstallFile::toString() { char* buffer = new char[RESBUFSIZE]; char* rsrcVal = nsnull; - const char* fname = nsnull; + char* fname = nsnull; if (buffer == nsnull || !mInstall) return nsnull; @@ -313,7 +355,7 @@ char* nsInstallFile::toString() if (rsrcVal) { if (mFinalFile) - fname = mFinalFile->GetCString(); + mFinalFile->GetPath(&fname); PR_snprintf( buffer, RESBUFSIZE, rsrcVal, fname ); @@ -333,14 +375,14 @@ PRInt32 nsInstallFile::CompleteFileMove() return nsInstall::UNEXPECTED_ERROR; } - if ( *mExtractedFile == *mFinalFile ) + if ( mExtractedFile == mFinalFile ) { /* No need to rename, they are the same */ result = nsInstall::SUCCESS; } else { - result = ReplaceFileNowOrSchedule(*mExtractedFile, *mFinalFile ); + result = ReplaceFileNowOrSchedule(mExtractedFile, mFinalFile ); } return result; @@ -388,8 +430,10 @@ nsInstallFile::RegisterInVersionRegistry() refCount = 0; } + char* temp; + mFinalFile->GetPath(&temp); VR_Install( (char*)(const char*)nsAutoCString(*mVersionRegistryName), - (char*)(const char*)mFinalFile->GetNativePathCString(), // DO NOT CHANGE THIS. + (char*)(const char*)temp, // DO NOT CHANGE THIS. (char*)(const char*)nsAutoCString(*mVersionInfo), PR_FALSE ); diff --git a/mozilla/xpinstall/src/nsInstallFile.h b/mozilla/xpinstall/src/nsInstallFile.h index 4e58c1c2d75..43016f8de50 100644 --- a/mozilla/xpinstall/src/nsInstallFile.h +++ b/mozilla/xpinstall/src/nsInstallFile.h @@ -79,11 +79,11 @@ class nsInstallFile : public nsInstallObject private: /* Private Fields */ - nsString* mVersionInfo; /* Version info for this file*/ + nsString* mVersionInfo; /* Version info for this file*/ - nsString* mJarLocation; /* Location in the JAR */ - nsFileSpec* mExtractedFile; /* temporary file location */ - nsFileSpec* mFinalFile; /* final file destination */ + nsString* mJarLocation; /* Location in the JAR */ + nsCOMPtr mExtractedFile; /* temporary file location */ + nsCOMPtr mFinalFile; /* final file destination */ nsString* mVersionRegistryName; /* full version path */ diff --git a/mozilla/xpinstall/src/nsInstallFileOpItem.cpp b/mozilla/xpinstall/src/nsInstallFileOpItem.cpp index 9c47d56eb27..c9c9a6db440 100644 --- a/mozilla/xpinstall/src/nsInstallFileOpItem.cpp +++ b/mozilla/xpinstall/src/nsInstallFileOpItem.cpp @@ -35,6 +35,7 @@ #include "Gestalt.h" #include "Resources.h" #include "script.h" +#include "nsILocalFileMac.h" #endif /* Public Methods */ @@ -43,38 +44,36 @@ MOZ_DECL_CTOR_COUNTER(nsInstallFileOpItem); nsInstallFileOpItem::nsInstallFileOpItem(nsInstall* aInstallObj, PRInt32 aCommand, - nsFileSpec& aTarget, + nsIFile* aTarget, PRInt32 aFlags, PRInt32* aReturn) -:nsInstallObject(aInstallObj) +:nsInstallObject(aInstallObj), + mTarget(aTarget) { MOZ_COUNT_CTOR(nsInstallFileOpItem); - *aReturn = nsInstall::SUCCESS; - mIObj = aInstallObj; - mCommand = aCommand; - mFlags = aFlags; - mSrc = nsnull; - mParams = nsnull; - mStrTarget = nsnull; + *aReturn = nsInstall::SUCCESS; + mIObj = aInstallObj; + mCommand = aCommand; + mFlags = aFlags; + mSrc = nsnull; + mParams = nsnull; + mStrTarget = nsnull; mShortcutPath = nsnull; mDescription = nsnull; mWorkingPath = nsnull; mParams = nsnull; mIcon = nsnull; - - mTarget = new nsFileSpec(aTarget); - - if(mTarget == nsnull) - *aReturn = nsInstall::OUT_OF_MEMORY; } nsInstallFileOpItem::nsInstallFileOpItem(nsInstall* aInstallObj, PRInt32 aCommand, - nsFileSpec& aSrc, - nsFileSpec& aTarget, + nsIFile* aSrc, + nsIFile* aTarget, PRInt32* aReturn) -:nsInstallObject(aInstallObj) +:nsInstallObject(aInstallObj), + mSrc(aSrc), + mTarget(aTarget) { MOZ_COUNT_CTOR(nsInstallFileOpItem); @@ -90,19 +89,14 @@ nsInstallFileOpItem::nsInstallFileOpItem(nsInstall* aInstallObj, mWorkingPath = nsnull; mParams = nsnull; mIcon = nsnull; - - mSrc = new nsFileSpec(aSrc); - mTarget = new nsFileSpec(aTarget); - - if(mTarget == nsnull || mSrc == nsnull) - *aReturn = nsInstall::OUT_OF_MEMORY; } nsInstallFileOpItem::nsInstallFileOpItem(nsInstall* aInstallObj, PRInt32 aCommand, - nsFileSpec& aTarget, + nsIFile* aTarget, PRInt32* aReturn) -:nsInstallObject(aInstallObj) +:nsInstallObject(aInstallObj), + mTarget(aTarget) { MOZ_COUNT_CTOR(nsInstallFileOpItem); @@ -119,16 +113,11 @@ nsInstallFileOpItem::nsInstallFileOpItem(nsInstall* aInstallObj, mWorkingPath = nsnull; mParams = nsnull; mIcon = nsnull; - - mTarget = new nsFileSpec(aTarget); - if(mTarget == nsnull) - *aReturn = nsInstall::OUT_OF_MEMORY; - } nsInstallFileOpItem::nsInstallFileOpItem(nsInstall* aInstallObj, PRInt32 aCommand, - nsFileSpec& a1, + nsIFile* a1, nsString& a2, PRInt32* aReturn) :nsInstallObject(aInstallObj) @@ -150,7 +139,7 @@ nsInstallFileOpItem::nsInstallFileOpItem(nsInstall* aInstallObj, { case NS_FOP_DIR_RENAME: case NS_FOP_FILE_RENAME: - mSrc = new nsFileSpec(a1); + mSrc = a1; mTarget = nsnull; mParams = nsnull; mStrTarget = new nsString(a2); @@ -163,27 +152,28 @@ nsInstallFileOpItem::nsInstallFileOpItem(nsInstall* aInstallObj, case NS_FOP_FILE_EXECUTE: default: mSrc = nsnull; - mTarget = new nsFileSpec(a1); + mTarget = a1; mParams = new nsString(a2); mStrTarget = nsnull; - if (mTarget == nsnull || mParams == nsnull) - *aReturn = nsInstall::OUT_OF_MEMORY; - break; } } nsInstallFileOpItem::nsInstallFileOpItem(nsInstall* aInstallObj, PRInt32 aCommand, - nsFileSpec& aTarget, - nsFileSpec& aShortcutPath, + nsIFile* aTarget, + nsIFile* aShortcutPath, nsString& aDescription, - nsFileSpec& aWorkingPath, + nsIFile* aWorkingPath, nsString& aParams, - nsFileSpec& aIcon, + nsIFile* aIcon, PRInt32 aIconId, PRInt32* aReturn) -:nsInstallObject(aInstallObj) +:nsInstallObject(aInstallObj), + mTarget(aTarget), + mShortcutPath(aShortcutPath), + mWorkingPath(aWorkingPath), + mIcon(aIcon) { MOZ_COUNT_CTOR(nsInstallFileOpItem); @@ -196,49 +186,33 @@ nsInstallFileOpItem::nsInstallFileOpItem(nsInstall* aInstallObj, mStrTarget = nsnull; mAction = ACTION_NONE; - mTarget = new nsFileSpec(aTarget); - if(mTarget == nsnull) - *aReturn = nsInstall::OUT_OF_MEMORY; - - mShortcutPath = new nsFileSpec(aShortcutPath); - if(mShortcutPath == nsnull) - *aReturn = nsInstall::OUT_OF_MEMORY; - mDescription = new nsString(aDescription); if(mDescription == nsnull) *aReturn = nsInstall::OUT_OF_MEMORY; - mWorkingPath = new nsFileSpec(aWorkingPath); - if(mWorkingPath == nsnull) - *aReturn = nsInstall::OUT_OF_MEMORY; - mParams = new nsString(aParams); if(mParams == nsnull) *aReturn = nsInstall::OUT_OF_MEMORY; - - mIcon = new nsFileSpec(aIcon); - if(mIcon == nsnull) - *aReturn = nsInstall::OUT_OF_MEMORY; } nsInstallFileOpItem::~nsInstallFileOpItem() { - if(mSrc) - delete mSrc; - if(mTarget) - delete mTarget; + //if(mSrc) + // delete mSrc; + //if(mTarget) + // delete mTarget; if(mStrTarget) delete mStrTarget; if(mParams) delete mParams; - if(mShortcutPath) - delete mShortcutPath; + //if(mShortcutPath) + // delete mShortcutPath; if(mDescription) delete mDescription; - if(mWorkingPath) - delete mWorkingPath; - if(mIcon) - delete mIcon; + //if(mWorkingPath) + // delete mWorkingPath; + //if(mIcon) + // delete mIcon; MOZ_COUNT_DTOR(nsInstallFileOpItem); } @@ -298,6 +272,7 @@ char* nsInstallFileOpItem::toString() { nsString result; char* resultCString; + char* temp; // XXX these hardcoded strings should be replaced by nsInstall::GetResourcedString(id) @@ -307,28 +282,34 @@ char* nsInstallFileOpItem::toString() { case NS_FOP_FILE_COPY: result.AssignWithConversion("Copy File: "); - result.AppendWithConversion(mSrc->GetNativePathCString()); + mSrc->GetPath(&temp); + result.AppendWithConversion(temp); result.AppendWithConversion(" to "); - result.AppendWithConversion(mTarget->GetNativePathCString()); + mTarget->GetPath(&temp); + result.AppendWithConversion(temp); resultCString = result.ToNewCString(); break; case NS_FOP_FILE_DELETE: - result.AssignWithConversion("Delete File: "); - result.AppendWithConversion(mTarget->GetNativePathCString()); + result.AssignWithConversion("Delete File: "); + mTarget->GetPath(&temp); + result.AppendWithConversion(temp); resultCString = result.ToNewCString(); break; case NS_FOP_FILE_EXECUTE: result.AssignWithConversion("Execute File: "); - result.AppendWithConversion(mTarget->GetNativePathCString()); + mTarget->GetPath(&temp); + result.AppendWithConversion(temp); result.AppendWithConversion(" "); result.Append(*mParams); resultCString = result.ToNewCString(); break; case NS_FOP_FILE_MOVE: result.AssignWithConversion("Move File: "); - result.AppendWithConversion(mSrc->GetNativePathCString()); + mSrc->GetPath(&temp); + result.AppendWithConversion(temp); result.AppendWithConversion(" to "); - result.AppendWithConversion(mTarget->GetNativePathCString()); + mTarget->GetPath(&temp); + result.AppendWithConversion(temp); resultCString = result.ToNewCString(); break; case NS_FOP_FILE_RENAME: @@ -338,12 +319,14 @@ char* nsInstallFileOpItem::toString() break; case NS_FOP_DIR_CREATE: result.AssignWithConversion("Create Folder: "); - result.AppendWithConversion(mTarget->GetNativePathCString()); + mTarget->GetPath(&temp); + result.AppendWithConversion(temp); resultCString = result.ToNewCString(); break; case NS_FOP_DIR_REMOVE: result.AssignWithConversion("Remove Folder: "); - result.AppendWithConversion(mTarget->GetNativePathCString()); + mTarget->GetPath(&temp); + result.AppendWithConversion(temp); resultCString = result.ToNewCString(); break; case NS_FOP_DIR_RENAME: @@ -353,14 +336,16 @@ char* nsInstallFileOpItem::toString() break; case NS_FOP_WIN_SHORTCUT: result.AssignWithConversion("Windows Shortcut: "); - result.AppendWithConversion(*mShortcutPath); + mShortcutPath->GetPath(&temp); + result.AppendWithConversion(temp); result.AppendWithConversion("\\"); result.Append(*mDescription); resultCString = result.ToNewCString(); break; case NS_FOP_MAC_ALIAS: result.AssignWithConversion("Mac Alias: "); - result.AppendWithConversion(mSrc->GetCString()); + mSrc->GetPath(&temp); + result.AppendWithConversion(temp); resultCString = result.ToNewCString(); break; case NS_FOP_UNIX_LINK: @@ -490,21 +475,16 @@ PRInt32 nsInstallFileOpItem::NativeFileOpDirCreatePrepare() { PRInt32 ret = nsInstall::ALREADY_EXISTS; - PRBool flagPreExist; + PRBool flagExists; mAction = nsInstallFileOpItem::ACTION_FAILED; - if(mTarget->Exists()) - flagPreExist = PR_TRUE; - else - flagPreExist = PR_FALSE; - - mTarget->CreateDirectory(); - - if(mTarget->Exists() && (PR_FALSE == flagPreExist)) + mTarget->Exists(&flagExists); + if (!flagExists) { - mAction = nsInstallFileOpItem::ACTION_SUCCESS; - ret = nsInstall::SUCCESS; + mTarget->Create(1, 0644); + mAction = nsInstallFileOpItem::ACTION_SUCCESS; + ret = nsInstall::SUCCESS; } return ret; @@ -522,9 +502,14 @@ nsInstallFileOpItem::NativeFileOpDirCreateAbort() PRInt32 nsInstallFileOpItem::NativeFileOpDirRemovePrepare() { - if(mTarget->Exists()) + PRBool flagExists, flagIsFile; + + mTarget->Exists(&flagExists); + + if(flagExists) { - if(!mTarget->IsFile()) + mTarget->IsFile(&flagIsFile); + if(!flagIsFile) return nsInstall::SUCCESS; else return nsInstall::IS_FILE; @@ -543,20 +528,25 @@ nsInstallFileOpItem::NativeFileOpDirRemoveComplete() PRInt32 nsInstallFileOpItem::NativeFileOpFileRenamePrepare() { + PRBool flagExists, flagIsFile; + // XXX needs to check file attributes to make sure // user has proper permissions to delete file. // Waiting on dougt's fix to nsFileSpec(). // In the meantime, check as much as possible. - if(mSrc->Exists()) + mSrc->Exists(&flagExists); + if(flagExists) { - if(mSrc->IsFile()) + mSrc->IsFile(&flagIsFile); + if(flagIsFile) { - nsFileSpec target; + nsIFile* target; - mSrc->GetParent(target); - target += *mStrTarget; + mSrc->GetParent(&target); + target->Append(mStrTarget->ToNewCString()); - if(target.Exists()) + target->Exists(&flagExists); + if(flagExists) return nsInstall::ALREADY_EXISTS; else return nsInstall::SUCCESS; @@ -572,29 +562,44 @@ PRInt32 nsInstallFileOpItem::NativeFileOpFileRenameComplete() { PRInt32 ret = nsInstall::SUCCESS; - - if(mSrc->Exists()) + PRBool flagExists, flagIsFile; + + mSrc->Exists(&flagExists); + if(flagExists) { - if(mSrc->IsFile()) + mSrc->IsFile(&flagIsFile); + if(flagIsFile) { - nsFileSpec target; + nsCOMPtr parent; + nsCOMPtr target; - mSrc->GetParent(target); - target += *mStrTarget; + mSrc->GetParent(getter_AddRefs(parent)); //need parent seprated for use in MoveTo method + if(parent) + { + mSrc->GetParent(getter_AddRefs(target)); //need target for path assembly to check if the file already exists - if(!target.Exists()) - { - char* cStrTarget = mStrTarget->ToNewCString(); - if(!cStrTarget) - return nsInstall::OUT_OF_MEMORY; + if (target) + target->Append(mStrTarget->ToNewCString()); + else + return nsInstall::UNEXPECTED_ERROR; - ret = mSrc->Rename(cStrTarget); + target->Exists(&flagExists); + if(!flagExists) + { + char* cStrTarget = mStrTarget->ToNewCString(); + if(!cStrTarget) + return nsInstall::OUT_OF_MEMORY; - if (cStrTarget) - Recycle(cStrTarget); - } - else - return nsInstall::ALREADY_EXISTS; + mSrc->MoveTo(parent, cStrTarget); + + if (cStrTarget) + Recycle(cStrTarget); + } + else + return nsInstall::ALREADY_EXISTS; + } + else + return nsInstall::UNEXPECTED_ERROR; } else ret = nsInstall::SOURCE_IS_DIRECTORY; @@ -608,20 +613,35 @@ nsInstallFileOpItem::NativeFileOpFileRenameComplete() PRInt32 nsInstallFileOpItem::NativeFileOpFileRenameAbort() { - PRInt32 ret = nsInstall::SUCCESS; - char* leafName; - nsFileSpec newFilename; + PRInt32 ret = nsInstall::SUCCESS; + PRBool flagExists; + char* leafName; + nsCOMPtr newFilename; + nsCOMPtr parent; - if(!mSrc->Exists()) + mSrc->Exists(&flagExists); + if(!flagExists) { - mSrc->GetParent(newFilename); - newFilename += *mStrTarget; - leafName = mSrc->GetLeafName(); - - ret = newFilename.Rename(leafName); + mSrc->GetParent(getter_AddRefs(newFilename)); + if(newFilename) + { + mSrc->GetParent(getter_AddRefs(parent)); + if(parent) + { + newFilename->Append(mStrTarget->ToNewCString()); - if(leafName) - nsCRT::free(leafName); + mSrc->GetLeafName(&leafName); + + newFilename->MoveTo(parent, leafName); + + if(leafName) + nsCRT::free(leafName); + } + else + return nsInstall::UNEXPECTED_ERROR; + } + else + return nsInstall::UNEXPECTED_ERROR; } return ret; @@ -630,26 +650,38 @@ nsInstallFileOpItem::NativeFileOpFileRenameAbort() PRInt32 nsInstallFileOpItem::NativeFileOpFileCopyPrepare() { + PRBool flagExists, flagIsFile; + char* leafName; + nsCOMPtr tempVar; + // XXX needs to check file attributes to make sure // user has proper permissions to delete file. // Waiting on dougt's fix to nsFileSpec(). // In the meantime, check as much as possible. - if(mSrc->Exists()) + + mSrc->Exists(&flagExists); + if(flagExists) { - if(mSrc->IsFile()) + mSrc->IsFile(&flagIsFile); + if(flagIsFile) { - if(!mTarget->Exists()) + mTarget->Exists(&flagExists); + if(!flagExists) return nsInstall::DOES_NOT_EXIST; - else if(mTarget->IsFile()) - return nsInstall::IS_FILE; else { - nsFileSpec tempVar; + mTarget->IsFile(&flagIsFile); + if(flagIsFile) + return nsInstall::IS_FILE; + else + { + tempVar = mTarget; + mSrc->GetLeafName(&leafName); + tempVar->Append(leafName); + } - tempVar = *mTarget; - tempVar += mSrc->GetLeafName(); - - if(tempVar.Exists()) + tempVar->Exists(&flagExists); + if(flagExists) return nsInstall::ALREADY_EXISTS; } @@ -666,9 +698,14 @@ PRInt32 nsInstallFileOpItem::NativeFileOpFileCopyComplete() { PRInt32 ret; + char* leafName; + nsCOMPtr parent; mAction = nsInstallFileOpItem::ACTION_FAILED; - ret = mSrc->CopyToDir(*mTarget); + + mSrc->GetLeafName(&leafName); + mTarget->GetParent(getter_AddRefs(parent)); + ret = mSrc->CopyTo(parent, leafName); if(nsInstall::SUCCESS == ret) mAction = nsInstallFileOpItem::ACTION_SUCCESS; @@ -678,13 +715,15 @@ nsInstallFileOpItem::NativeFileOpFileCopyComplete() PRInt32 nsInstallFileOpItem::NativeFileOpFileCopyAbort() { - nsFileSpec fullTarget = *mTarget; - PRInt32 ret = nsInstall::SUCCESS; + nsCOMPtr fullTarget = mTarget; + PRInt32 ret = nsInstall::SUCCESS; if(nsInstallFileOpItem::ACTION_SUCCESS == mAction) { - fullTarget += mSrc->GetLeafName(); - fullTarget.Delete(PR_FALSE); + char* leafName; + mSrc->GetLeafName(&leafName); + fullTarget->Append(leafName); + fullTarget->Delete(PR_FALSE); } return ret; @@ -693,13 +732,18 @@ nsInstallFileOpItem::NativeFileOpFileCopyAbort() PRInt32 nsInstallFileOpItem::NativeFileOpFileDeletePrepare() { + PRBool flagExists, flagIsFile; + // XXX needs to check file attributes to make sure // user has proper permissions to delete file. // Waiting on dougt's fix to nsFileSpec(). // In the meantime, check as much as possible. - if(mTarget->Exists()) + + mTarget->Exists(&flagExists); + if(flagExists) { - if(mTarget->IsFile()) + mTarget->IsFile(&flagIsFile); + if(flagIsFile) return nsInstall::SUCCESS; else return nsInstall::IS_DIRECTORY; @@ -709,12 +753,16 @@ nsInstallFileOpItem::NativeFileOpFileDeletePrepare() } PRInt32 -nsInstallFileOpItem::NativeFileOpFileDeleteComplete(nsFileSpec *aTarget) +nsInstallFileOpItem::NativeFileOpFileDeleteComplete(nsIFile *aTarget) { - if(aTarget->Exists()) + PRBool flagExists, flagIsFile; + + aTarget->Exists(&flagExists); + if(flagExists) { - if(aTarget->IsFile()) - return DeleteFileNowOrSchedule(*aTarget); + aTarget->IsFile(&flagIsFile); + if(flagIsFile) + return DeleteFileNowOrSchedule(aTarget); else return nsInstall::IS_DIRECTORY; } @@ -725,15 +773,18 @@ nsInstallFileOpItem::NativeFileOpFileDeleteComplete(nsFileSpec *aTarget) PRInt32 nsInstallFileOpItem::NativeFileOpFileExecutePrepare() { + PRBool flagExists, flagIsFile; // XXX needs to check file attributes to make sure // user has proper permissions to delete file. // Waiting on dougt's fix to nsFileSpec(). // In the meantime, check as much as possible. // Also, an absolute path (with filename) must be // used. Xpinstall does not assume files are on the path. - if(mTarget->Exists()) + mTarget->Exists(&flagExists); + if(flagExists) { - if(mTarget->IsFile()) + mTarget->IsFile(&flagIsFile); + if(flagIsFile) return nsInstall::SUCCESS; else return nsInstall::IS_DIRECTORY; @@ -745,7 +796,9 @@ nsInstallFileOpItem::NativeFileOpFileExecutePrepare() PRInt32 nsInstallFileOpItem::NativeFileOpFileExecuteComplete() { - mTarget->Execute(*mParams); + //mTarget->Execute(*mParams); + mTarget->Spawn((const char**)mParams->ToNewCString(), 0);//nsIFileXXX: need to fix this call to Spawn + //It's totally bogus. // We don't care if it succeeded or not since we // don't wait for the process to end anyways. @@ -757,23 +810,34 @@ nsInstallFileOpItem::NativeFileOpFileExecuteComplete() PRInt32 nsInstallFileOpItem::NativeFileOpFileMovePrepare() { - if(mSrc->Exists()) + PRBool flagExists, flagIsFile; + + mSrc->Exists(&flagExists); + if(flagExists) { - if(!mTarget->Exists()) + mTarget->Exists(&flagExists); + if(!flagExists) return nsInstall::DOES_NOT_EXIST; - else if(mTarget->IsFile()) - return nsInstall::IS_FILE; else { - nsFileSpec tempVar; - - tempVar = *mTarget; - tempVar += mSrc->GetLeafName(); - - if(tempVar.Exists()) - return nsInstall::ALREADY_EXISTS; + mTarget->IsFile(&flagIsFile); + if(flagIsFile) + return nsInstall::IS_FILE; else - return NativeFileOpFileCopyPrepare(); + { + nsCOMPtr tempVar; + char* leaf; + + mTarget->Clone(getter_AddRefs(tempVar)); + mSrc->GetLeafName(&leaf); + tempVar->Append(leaf); + + tempVar->Exists(&flagExists); + if(flagExists) + return nsInstall::ALREADY_EXISTS; + else + return NativeFileOpFileCopyPrepare(); + } } } @@ -783,12 +847,15 @@ nsInstallFileOpItem::NativeFileOpFileMovePrepare() PRInt32 nsInstallFileOpItem::NativeFileOpFileMoveComplete() { + PRBool flagExists; PRInt32 ret = nsInstall::SUCCESS; mAction = nsInstallFileOpItem::ACTION_FAILED; - if(mSrc->Exists()) + mSrc->Exists(&flagExists); + if(flagExists) { - if(!mTarget->Exists()) + mTarget->Exists(&flagExists); + if(!flagExists) ret = nsInstall::DOES_NOT_EXIST; else { @@ -816,38 +883,44 @@ nsInstallFileOpItem::NativeFileOpFileMoveComplete() PRInt32 nsInstallFileOpItem::NativeFileOpFileMoveAbort() { + PRBool flagExists; PRInt32 ret = nsInstall::SUCCESS; if(nsInstallFileOpItem::ACTION_SUCCESS == mAction) { - if(mSrc->Exists()) + mSrc->Exists(&flagExists); + if(flagExists) ret = NativeFileOpFileDeleteComplete(mTarget); - else if(mTarget->Exists()) - { - nsFileSpec tempVar; - PRInt32 ret2 = nsInstall::SUCCESS; - - // switch the values of mSrc and mTarget - // so the original state can be restored. - // NativeFileOpFileCopyComplete() copies from - // mSrc to mTarget by default. - tempVar = *mTarget; - *mTarget = *mSrc; - *mSrc = tempVar; - - ret = NativeFileOpFileCopyComplete(); - if(nsInstall::SUCCESS == ret) - { - ret2 = NativeFileOpFileDeleteComplete(mSrc); - - // We don't care if the value of ret2 is other than - // REBOOT_NEEDED. ret takes precedence otherwise. - if(nsInstall::REBOOT_NEEDED == ret2) - ret = ret2; - } - } else - ret = nsInstall::DOES_NOT_EXIST; + { + mTarget->Exists(&flagExists); + if(flagExists) + { + nsCOMPtr tempVar; + PRInt32 ret2 = nsInstall::SUCCESS; + + // switch the values of mSrc and mTarget + // so the original state can be restored. + // NativeFileOpFileCopyComplete() copies from + // mSrc to mTarget by default. + mTarget->Clone(getter_AddRefs(tempVar)); + mSrc->Clone(getter_AddRefs(mTarget)); + tempVar->Clone(getter_AddRefs(mSrc)); + + ret = NativeFileOpFileCopyComplete(); + if(nsInstall::SUCCESS == ret) + { + ret2 = NativeFileOpFileDeleteComplete(mSrc); + + // We don't care if the value of ret2 is other than + // REBOOT_NEEDED. ret takes precedence otherwise. + if(nsInstall::REBOOT_NEEDED == ret2) + ret = ret2; + } + } + else + ret = nsInstall::DOES_NOT_EXIST; + } } return ret; @@ -856,20 +929,24 @@ nsInstallFileOpItem::NativeFileOpFileMoveAbort() PRInt32 nsInstallFileOpItem::NativeFileOpDirRenamePrepare() { + PRBool flagExists, flagIsFile; // XXX needs to check file attributes to make sure // user has proper permissions to delete file. // Waiting on dougt's fix to nsFileSpec(). // In the meantime, check as much as possible. - if(mSrc->Exists()) + mSrc->Exists(&flagExists); + if(flagExists) { - if(!mSrc->IsFile()) + mSrc->IsFile(&flagIsFile); + if(!flagIsFile) { - nsFileSpec target; + nsCOMPtr target; - mSrc->GetParent(target); - target += *mStrTarget; + mSrc->GetParent(getter_AddRefs(target)); + target->Append(mStrTarget->ToNewCString()); - if(target.Exists()) + target->Exists(&flagExists); + if(flagExists) return nsInstall::ALREADY_EXISTS; else return nsInstall::SUCCESS; @@ -884,24 +961,30 @@ nsInstallFileOpItem::NativeFileOpDirRenamePrepare() PRInt32 nsInstallFileOpItem::NativeFileOpDirRenameComplete() { + PRBool flagExists, flagIsFile; PRInt32 ret = nsInstall::SUCCESS; - if(mSrc->Exists()) + mSrc->Exists(&flagExists); + if(flagExists) { - if(!mSrc->IsFile()) + mSrc->IsFile(&flagIsFile); + if(!flagIsFile) { - nsFileSpec target; + nsCOMPtr target; - mSrc->GetParent(target); - target += *mStrTarget; + mSrc->GetParent(getter_AddRefs(target)); + target->Append(mStrTarget->ToNewCString()); - if(!target.Exists()) + target->Exists(&flagExists); + if(!flagExists) { char* cStrTarget = mStrTarget->ToNewCString(); if(!cStrTarget) return nsInstall::OUT_OF_MEMORY; - ret = mSrc->Rename(cStrTarget); + nsCOMPtr parent; + mSrc->GetParent(getter_AddRefs(parent)); + ret = mSrc->MoveTo(parent, cStrTarget); if(cStrTarget) Recycle(cStrTarget); @@ -921,17 +1004,20 @@ nsInstallFileOpItem::NativeFileOpDirRenameComplete() PRInt32 nsInstallFileOpItem::NativeFileOpDirRenameAbort() { + PRBool flagExists; PRInt32 ret = nsInstall::SUCCESS; char* leafName; - nsFileSpec newDirName; + nsCOMPtr newDirName; + nsCOMPtr parent; - if(!mSrc->Exists()) + mSrc->Exists(&flagExists); + if(!flagExists) { - mSrc->GetParent(newDirName); - newDirName += *mStrTarget; - leafName = mSrc->GetLeafName(); - - ret = newDirName.Rename(leafName); + mSrc->GetParent(getter_AddRefs(newDirName)); + newDirName->Append(mStrTarget->ToNewCString()); + mSrc->GetLeafName(&leafName); + mSrc->GetParent(getter_AddRefs(parent)); + ret = newDirName->MoveTo(parent, leafName); if(leafName) nsCRT::free(leafName); @@ -948,17 +1034,27 @@ nsInstallFileOpItem::NativeFileOpWindowsShortcutComplete() #ifdef _WINDOWS char *cDescription = mDescription->ToNewCString(); char *cParams = mParams->ToNewCString(); + + char *targetNativePathStr; + char *shortcutNativePathStr; + char *workingpathNativePathStr; + char *iconNativePathStr; if((cDescription == nsnull) || (cParams == nsnull)) ret = nsInstall::OUT_OF_MEMORY; else { - ret = CreateALink(mTarget->GetNativePathCString(), - mShortcutPath->GetNativePathCString(), + mTarget->GetPath(&targetNativePathStr); + mShortcutPath->GetPath(&shortcutNativePathStr); + mWorkingPath->GetPath(&workingpathNativePathStr); + mIcon->GetPath(&iconNativePathStr); + + ret = CreateALink(targetNativePathStr, + shortcutNativePathStr, cDescription, - mWorkingPath->GetNativePathCString(), + workingpathNativePathStr, cParams, - mIcon->GetNativePathCString(), + iconNativePathStr, mIconId); if(nsInstall::SUCCESS == ret) @@ -979,14 +1075,14 @@ nsInstallFileOpItem::NativeFileOpWindowsShortcutAbort() { #ifdef _WINDOWS nsString shortcutDescription; - nsFileSpec shortcutTarget; + nsCOMPtr shortcutTarget; shortcutDescription = *mDescription; shortcutDescription.Append(".lnk"); - shortcutTarget = *mShortcutPath; - shortcutTarget += shortcutDescription; + mShortcutPath->Clone(getter_AddRefs(shortcutTarget)); + shortcutTarget->Append(shortcutDescription.ToNewCString()); - NativeFileOpFileDeleteComplete(&shortcutTarget); + NativeFileOpFileDeleteComplete(shortcutTarget); #endif return nsInstall::SUCCESS; @@ -999,17 +1095,23 @@ nsInstallFileOpItem::NativeFileOpMacAliasComplete() #ifdef XP_MAC // XXX gestalt to see if alias manager is around - FSSpec *fsPtrAlias = mTarget->GetFSSpecPtr(); + nsCOMPtr localFileMacTarget = do_QueryInterface(mTarget); + nsCOMPtr localFileMacSrc = do_QueryInterface(mSrc); + + FSSpec *fsPtrAlias, *srcPtrAlias; AliasHandle aliasH; FInfo info; OSErr err = noErr; - err = NewAliasMinimal( mSrc->GetFSSpecPtr(), &aliasH ); + localFileMacTarget->GetFSSpec(fsPtrAlias); + localFileMacSrc->GetFSSpec(srcPtrAlias); + + err = NewAliasMinimal( srcPtrAlias, &aliasH ); if (err != noErr) // bubble up Alias Manager error return err; // create the alias file - FSpGetFInfo(mSrc->GetFSSpecPtr(), &info); + FSpGetFInfo(srcPtrAlias, &info); FSpCreateResFile(fsPtrAlias, info.fdCreator, info.fdType, smRoman); short refNum = FSpOpenResFile(fsPtrAlias, fsRdWrPerm); if (refNum != -1) diff --git a/mozilla/xpinstall/src/nsInstallFileOpItem.h b/mozilla/xpinstall/src/nsInstallFileOpItem.h index ef4d986daed..16eda0d4c89 100644 --- a/mozilla/xpinstall/src/nsInstallFileOpItem.h +++ b/mozilla/xpinstall/src/nsInstallFileOpItem.h @@ -25,7 +25,7 @@ #include "prtypes.h" -#include "nsFileSpec.h" +#include "nsIFile.h" #include "nsSoftwareUpdate.h" #include "nsInstallObject.h" #include "nsInstall.h" @@ -47,7 +47,7 @@ class nsInstallFileOpItem : public nsInstallObject // FileOpFileDelete() nsInstallFileOpItem(nsInstall* installObj, PRInt32 aCommand, - nsFileSpec& aTarget, + nsIFile* aTarget, PRInt32 aFlags, PRInt32* aReturn); @@ -58,15 +58,15 @@ class nsInstallFileOpItem : public nsInstallObject // FileMacAlias() nsInstallFileOpItem(nsInstall* installObj, PRInt32 aCommand, - nsFileSpec& aSrc, - nsFileSpec& aTarget, + nsIFile* aSrc, + nsIFile* aTarget, PRInt32* aReturn); // used by: // FileOpDirCreate() nsInstallFileOpItem(nsInstall* aInstallObj, PRInt32 aCommand, - nsFileSpec& aTarget, + nsIFile* aTarget, PRInt32* aReturn); // used by: @@ -75,22 +75,22 @@ class nsInstallFileOpItem : public nsInstallObject // FileOpFileRename() nsInstallFileOpItem(nsInstall* aInstallObj, PRInt32 aCommand, - nsFileSpec& a1, + nsIFile* a1, nsString& a2, PRInt32* aReturn); // used by: // WindowsShortcut() - nsInstallFileOpItem(nsInstall* aInstallObj, - PRInt32 aCommand, - nsFileSpec& aTarget, - nsFileSpec& aShortcutPath, - nsString& aDescription, - nsFileSpec& aWorkingPath, - nsString& aParams, - nsFileSpec& aIcon, - PRInt32 aIconId, - PRInt32* aReturn); + nsInstallFileOpItem(nsInstall* aInstallObj, + PRInt32 aCommand, + nsIFile* aTarget, + nsIFile* aShortcutPath, + nsString& aDescription, + nsIFile* aWorkingPath, + nsString& aParams, + nsIFile* aIcon, + PRInt32 aIconId, + PRInt32* aReturn); virtual ~nsInstallFileOpItem(); @@ -107,20 +107,20 @@ class nsInstallFileOpItem : public nsInstallObject /* Private Fields */ - nsInstall* mIObj; // initiating Install object - nsFileSpec* mSrc; - nsFileSpec* mTarget; - nsFileSpec* mShortcutPath; - nsFileSpec* mWorkingPath; - nsFileSpec* mIcon; - nsString* mDescription; - nsString* mStrTarget; - nsString* mParams; - long mFStat; - PRInt32 mFlags; - PRInt32 mIconId; - PRInt32 mCommand; - PRInt32 mAction; + nsInstall* mIObj; // initiating Install object + nsCOMPtr mSrc; + nsCOMPtr mTarget; + nsCOMPtr mShortcutPath; + nsCOMPtr mWorkingPath; + nsCOMPtr mIcon; + nsString* mDescription; + nsString* mStrTarget; + nsString* mParams; + long mFStat; + PRInt32 mFlags; + PRInt32 mIconId; + PRInt32 mCommand; + PRInt32 mAction; /* Private Methods */ @@ -135,7 +135,7 @@ class nsInstallFileOpItem : public nsInstallObject PRInt32 NativeFileOpFileCopyComplete(); PRInt32 NativeFileOpFileCopyAbort(); PRInt32 NativeFileOpFileDeletePrepare(); - PRInt32 NativeFileOpFileDeleteComplete(nsFileSpec *aTarget); + PRInt32 NativeFileOpFileDeleteComplete(nsIFile *aTarget); PRInt32 NativeFileOpFileExecutePrepare(); PRInt32 NativeFileOpFileExecuteComplete(); PRInt32 NativeFileOpFileMovePrepare(); diff --git a/mozilla/xpinstall/src/nsInstallFolder.cpp b/mozilla/xpinstall/src/nsInstallFolder.cpp index 913f82d237d..e686217d2f2 100644 --- a/mozilla/xpinstall/src/nsInstallFolder.cpp +++ b/mozilla/xpinstall/src/nsInstallFolder.cpp @@ -33,6 +33,9 @@ #include "nsString.h" #include "nsFileSpec.h" #include "nsIFileSpec.h" +#include "nsIFile.h" +#include "nsILocalFile.h" +#include "nsDirectoryService.h" #include "nsSpecialSystemDirectory.h" #include "nsFileLocations.h" @@ -57,8 +60,8 @@ struct DirectoryTable DirectoryTable[] = {"OS Drive", 108 }, {"file:///", 109 }, - {"Components", 110 }, - {"Chrome", 111 }, + {"Components", 110 }, + {"Chrome", 111 }, {"Win System", 200 }, {"Windows", 201 }, @@ -91,7 +94,9 @@ nsInstallFolder::nsInstallFolder(const nsString& aFolderID) nsInstallFolder::nsInstallFolder(const nsString& aFolderID, const nsString& aRelativePath) { - MOZ_COUNT_CTOR(nsInstallFolder); + PRBool flagIsDir, flagExists; + + MOZ_COUNT_CTOR(nsInstallFolder); mFileSpec = nsnull; @@ -109,26 +114,28 @@ nsInstallFolder::nsInstallFolder(const nsString& aFolderID, const nsString& aRel // 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... - nsFileSpec dirCheck(aFolderID); - if ( (dirCheck.Error() == NS_OK) && - ( dirCheck.IsDirectory() || !dirCheck.Exists() ) ) + nsCOMPtr dirCheck; + NS_NewLocalFile(aFolderID.ToNewCString(), getter_AddRefs(dirCheck)); + dirCheck->IsDirectory(&flagIsDir); + dirCheck->Exists(&flagExists); + if ( flagIsDir || !flagExists ) { - mFileSpec = new nsFileSpec( dirCheck ); + mFileSpec = dirCheck; if (mFileSpec && aRelativePath.Length() > 0 ) { // we've got a subdirectory to tack on nsString morePath(aRelativePath); - if ( morePath.Last() != '/' || morePath.Last() != '\\' ) - morePath.AppendWithConversion('/'); + //if ( morePath.Last() != '/' || morePath.Last() != '\\' ) + // morePath.AppendWithConversion('/'); - *mFileSpec += morePath; + 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); + // nsFileSpec(mFileSpec->GetCString(), PR_TRUE); } } } @@ -138,40 +145,43 @@ nsInstallFolder::nsInstallFolder(nsInstallFolder& inFolder, const nsString& subS { MOZ_COUNT_CTOR(nsInstallFolder); - mFileSpec = new nsFileSpec(); - if (mFileSpec != nsnull) - { - *mFileSpec = *inFolder.mFileSpec; + inFolder.mFileSpec->Clone(getter_AddRefs(mFileSpec)); - if (!subString.IsEmpty()) - *mFileSpec += subString; - } + if(!subString.IsEmpty()) + mFileSpec->Append(subString.ToNewCString()); } nsInstallFolder::~nsInstallFolder() { - if (mFileSpec != nsnull) - delete mFileSpec; + //if (mFileSpec != nsnull) //nsIFileXXX: since mFileSpec is an nsCOMPtr, how is it deleted? + //delete mFileSpec; + mFileSpec = 0; + MOZ_COUNT_DTOR(nsInstallFolder); } void nsInstallFolder::GetDirectoryPath(nsString& aDirectoryPath) { - aDirectoryPath.SetLength(0); + PRBool flagIsDir; + char* thePath; + + aDirectoryPath.SetLength(0); if (mFileSpec != nsnull) { - // We want the a NATIVE path. - aDirectoryPath.AssignWithConversion(mFileSpec->GetCString()); + // We want the a NATIVE path. + mFileSpec->GetPath(&thePath); + aDirectoryPath.AssignWithConversion(thePath); - if (mFileSpec->IsDirectory()) - { - if (aDirectoryPath.Last() != FILESEP) - aDirectoryPath.AppendWithConversion(FILESEP); - } + mFileSpec->IsDirectory(&flagIsDir); + if (flagIsDir) + { + if (aDirectoryPath.Last() != FILESEP) + aDirectoryPath.AppendWithConversion(FILESEP); + } } } @@ -187,7 +197,10 @@ nsInstallFolder::SetDirectoryPath(const nsString& aFolderID, const nsString& aRe { // XXX block from users or remove "Installed" // XXX the filespec creation will fail due to unix slashes on Mac - mFileSpec = new nsFileSpec(aRelativePath, PR_TRUE); // creates the directories to the relative path. + + nsCOMPtr temp; + NS_NewLocalFile(aRelativePath.ToNewCString(), getter_AddRefs(temp)); + mFileSpec = temp; // creates the directories to the relative path. return; } else @@ -200,22 +213,25 @@ nsInstallFolder::SetDirectoryPath(const nsString& aFolderID, const nsString& aRe case 100: /////////////////////////////////////////////////////////// Plugins if (!nsSoftwareUpdate::GetProgramDirectory()) { - SetAppShellDirectory(nsSpecialFileSpec::App_PluginsDirectory ); + NS_WITH_SERVICE(nsIProperties, directoryService, NS_DIRECTORY_SERVICE_PROGID, &rv); + + directoryService->Get("system.OS_CurrentProcessDirectory", NS_GET_IID(nsIFile), getter_AddRefs(mFileSpec)); +#ifdef XP_MAC + mFileSpec->Append("Plugins"); +#else + mFileSpec->Append("plugins"); +#endif } else { - mFileSpec = new nsFileSpec(); - if ( !mFileSpec ) - rv = NS_ERROR_OUT_OF_MEMORY; - else - rv = nsSoftwareUpdate::GetProgramDirectory()->GetFileSpec(mFileSpec); + rv = nsSoftwareUpdate::GetProgramDirectory()->Clone(getter_AddRefs(mFileSpec)); if (NS_SUCCEEDED(rv)) { #ifdef XP_MAC - *mFileSpec += "Plugins"; + mFileSpec->Append("Plugins"); #else - *mFileSpec += "plugins"; + mFileSpec->Append("plugins"); #endif } else @@ -225,18 +241,15 @@ nsInstallFolder::SetDirectoryPath(const nsString& aFolderID, const nsString& aRe case 101: /////////////////////////////////////////////////////////// Program case 102: /////////////////////////////////////////////////////////// Communicator - if (!nsSoftwareUpdate::GetProgramDirectory()) - mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::OS_CurrentProcessDirectory )); - else + if (!nsSoftwareUpdate::GetProgramDirectory()) //Not in stub installer { - mFileSpec = new nsFileSpec(); - if ( !mFileSpec ) - rv = NS_ERROR_OUT_OF_MEMORY; - else - rv = nsSoftwareUpdate::GetProgramDirectory()->GetFileSpec(mFileSpec); + NS_WITH_SERVICE(nsIProperties, directoryService, NS_DIRECTORY_SERVICE_PROGID, &rv); - if (!NS_SUCCEEDED(rv)) - mFileSpec = nsnull; + directoryService->Get("system.OS_CurrentProcessDirectory", NS_GET_IID(nsIFile), getter_AddRefs(mFileSpec)); + } + else //In stub installer. mProgram has been set so + { + rv = nsSoftwareUpdate::GetProgramDirectory()->Clone(getter_AddRefs(mFileSpec)); } break; @@ -246,8 +259,12 @@ nsInstallFolder::SetDirectoryPath(const nsString& aFolderID, const nsString& aRe break; case 104: /////////////////////////////////////////////////////////// Temporary - mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::OS_TemporaryDirectory )); - break; + { + NS_WITH_SERVICE(nsIProperties, directoryService, NS_DIRECTORY_SERVICE_PROGID, &rv); + + directoryService->Get("system.OS_TemporaryDirectory", NS_GET_IID(nsIFile), getter_AddRefs(mFileSpec)); + } + break; case 105: /////////////////////////////////////////////////////////// Installed // we should never be here. @@ -255,15 +272,21 @@ nsInstallFolder::SetDirectoryPath(const nsString& aFolderID, const nsString& aRe break; case 106: /////////////////////////////////////////////////////////// Current User - SetAppShellDirectory(nsSpecialFileSpec::App_UserProfileDirectory50 ); + //nsIFileXXX: User profile dir not implemented in nsDirectoryService + //SetAppShellDirectory(nsSpecialFileSpec::App_UserProfileDirectory50 ); break; case 107: /////////////////////////////////////////////////////////// Preferences - SetAppShellDirectory(nsSpecialFileSpec::App_PrefsDirectory50 ); + //nsIFileXXX: User profile dir not implemented in nsDirectoryService + //SetAppShellDirectory(nsSpecialFileSpec::App_PrefsDirectory50 ); break; case 108: /////////////////////////////////////////////////////////// OS Drive - mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::OS_DriveDirectory )); + { + NS_WITH_SERVICE(nsIProperties, directoryService, NS_DIRECTORY_SERVICE_PROGID, &rv); + + directoryService->Get("system.OS_DriveDirectory", NS_GET_IID(nsIFile), getter_AddRefs(mFileSpec)); + } break; case 109: /////////////////////////////////////////////////////////// File URL @@ -273,10 +296,14 @@ nsInstallFolder::SetDirectoryPath(const nsString& aFolderID, const nsString& aRe mFileSpec = nsnull; return; } + + nsCOMPtr temp; nsString tempFileURLString = aFolderID; tempFileURLString += aRelativePath; - mFileSpec = new nsFileSpec( nsFileURL(tempFileURLString) ); + + NS_NewLocalFile(aRelativePath.ToNewCString(), getter_AddRefs(temp)); + mFileSpec = temp; // file:// is a special case where it returns and does not // go to the standard relative path code below. This is @@ -290,106 +317,222 @@ nsInstallFolder::SetDirectoryPath(const nsString& aFolderID, const nsString& aRe case 110: /////////////////////////////////////////////////////////// Components if (!nsSoftwareUpdate::GetProgramDirectory()) - SetAppShellDirectory(nsSpecialFileSpec::App_ComponentsDirectory ); - else { - mFileSpec = new nsFileSpec(); - if ( !mFileSpec ) - rv = NS_ERROR_OUT_OF_MEMORY; - else - rv = nsSoftwareUpdate::GetProgramDirectory()->GetFileSpec(mFileSpec); + NS_WITH_SERVICE(nsIProperties, directoryService, NS_DIRECTORY_SERVICE_PROGID, &rv); + + directoryService->Get("system.OS_CurrentProcessDirectory", + NS_GET_IID(nsIFile), + getter_AddRefs(mFileSpec)); if (NS_SUCCEEDED(rv)) { #ifdef XP_MAC - *mFileSpec += "Components"; + mFileSpec->Append("Components"); #else - *mFileSpec += "components"; + mFileSpec->Append("components"); #endif } } + else + { + rv = nsSoftwareUpdate::GetProgramDirectory()->Clone(getter_AddRefs(mFileSpec)); + + if (NS_SUCCEEDED(rv)) + { +#ifdef XP_MAC + mFileSpec->Append("Components"); +#else + mFileSpec->Append("components"); +#endif + } + else + mFileSpec = nsnull; + } break; case 111: /////////////////////////////////////////////////////////// Chrome if (!nsSoftwareUpdate::GetProgramDirectory()) - SetAppShellDirectory(nsSpecialFileSpec::App_ChromeDirectory ); - else - { - mFileSpec = new nsFileSpec(); - if ( !mFileSpec ) - rv = NS_ERROR_OUT_OF_MEMORY; - else - rv = nsSoftwareUpdate::GetProgramDirectory()->GetFileSpec(mFileSpec); + { + NS_WITH_SERVICE(nsIProperties, directoryService, NS_DIRECTORY_SERVICE_PROGID, &rv); + + directoryService->Get("system.OS_CurrentProcessDirectory", + NS_GET_IID(nsIFile), + getter_AddRefs(mFileSpec)); + if (NS_SUCCEEDED(rv)) { #ifdef XP_MAC - *mFileSpec += "Chrome"; + mFileSpec->Append("Chrome"); #else - *mFileSpec += "chrome"; + mFileSpec->Append("chrome"); +#endif + } + } + else + { + rv = nsSoftwareUpdate::GetProgramDirectory()->Clone(getter_AddRefs(mFileSpec)); + + if (NS_SUCCEEDED(rv)) + { +#ifdef XP_MAC + mFileSpec->Append("Chrome"); +#else + mFileSpec->Append("chrome"); #endif } } break; case 200: /////////////////////////////////////////////////////////// Win System - mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Win_SystemDirectory )); - break; + { + NS_WITH_SERVICE(nsIProperties, directoryService, NS_DIRECTORY_SERVICE_PROGID, &rv); + + directoryService->Get("system.SystemDirectory", + NS_GET_IID(nsIFile), + getter_AddRefs(mFileSpec)); + + } + break; case 201: /////////////////////////////////////////////////////////// Windows - mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Win_WindowsDirectory )); + { + NS_WITH_SERVICE(nsIProperties, directoryService, NS_DIRECTORY_SERVICE_PROGID, &rv); + + directoryService->Get("system.WindowsDirectory", + NS_GET_IID(nsIFile), + getter_AddRefs(mFileSpec)); + } break; case 300: /////////////////////////////////////////////////////////// Mac System - mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Mac_SystemDirectory )); + { + NS_WITH_SERVICE(nsIProperties, directoryService, NS_DIRECTORY_SERVICE_PROGID, &rv); + + directoryService->Get("system.Directory", + NS_GET_IID(nsIFile), + getter_AddRefs(mFileSpec)); + } break; case 301: /////////////////////////////////////////////////////////// Mac Desktop - mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Mac_DesktopDirectory )); + { + NS_WITH_SERVICE(nsIProperties, directoryService, NS_DIRECTORY_SERVICE_PROGID, &rv); + + directoryService->Get("system.DesktopDirectory", + NS_GET_IID(nsIFile), + getter_AddRefs(mFileSpec)); + } break; case 302: /////////////////////////////////////////////////////////// Mac Trash - mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Mac_TrashDirectory )); + { + NS_WITH_SERVICE(nsIProperties, directoryService, NS_DIRECTORY_SERVICE_PROGID, &rv); + + directoryService->Get("system.TrashDirectory", + NS_GET_IID(nsIFile), + getter_AddRefs(mFileSpec)); + } break; case 303: /////////////////////////////////////////////////////////// Mac Startup - mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Mac_StartupDirectory )); + { + NS_WITH_SERVICE(nsIProperties, directoryService, NS_DIRECTORY_SERVICE_PROGID, &rv); + + directoryService->Get("system.StartupDirectory", + NS_GET_IID(nsIFile), + getter_AddRefs(mFileSpec)); + } break; case 304: /////////////////////////////////////////////////////////// Mac Shutdown - mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Mac_ShutdownDirectory )); + { + NS_WITH_SERVICE(nsIProperties, directoryService, NS_DIRECTORY_SERVICE_PROGID, &rv); + + directoryService->Get("system.ShutdownDirectory", + NS_GET_IID(nsIFile), + getter_AddRefs(mFileSpec)); + } break; case 305: /////////////////////////////////////////////////////////// Mac Apple Menu - mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Mac_AppleMenuDirectory )); + { + NS_WITH_SERVICE(nsIProperties, directoryService, NS_DIRECTORY_SERVICE_PROGID, &rv); + + directoryService->Get("system.AppleMenuDirectory", + NS_GET_IID(nsIFile), + getter_AddRefs(mFileSpec)); + } break; case 306: /////////////////////////////////////////////////////////// Mac Control Panel - mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Mac_ControlPanelDirectory )); + { + NS_WITH_SERVICE(nsIProperties, directoryService, NS_DIRECTORY_SERVICE_PROGID, &rv); + + directoryService->Get("system.ControlPanelDirectory", + NS_GET_IID(nsIFile), + getter_AddRefs(mFileSpec)); + } break; case 307: /////////////////////////////////////////////////////////// Mac Extension - mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Mac_ExtensionDirectory )); + { + NS_WITH_SERVICE(nsIProperties, directoryService, NS_DIRECTORY_SERVICE_PROGID, &rv); + + directoryService->Get("system.ExtensionDirectory", + NS_GET_IID(nsIFile), + getter_AddRefs(mFileSpec)); + } break; case 308: /////////////////////////////////////////////////////////// Mac Fonts - mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Mac_FontsDirectory )); + { + NS_WITH_SERVICE(nsIProperties, directoryService, NS_DIRECTORY_SERVICE_PROGID, &rv); + + directoryService->Get("system.FontsDirectory", + NS_GET_IID(nsIFile), + getter_AddRefs(mFileSpec)); + } break; case 309: /////////////////////////////////////////////////////////// Mac Preferences - mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Mac_PreferencesDirectory )); + { + NS_WITH_SERVICE(nsIProperties, directoryService, NS_DIRECTORY_SERVICE_PROGID, &rv); + + directoryService->Get("system.PreferencesDirectory", + NS_GET_IID(nsIFile), + getter_AddRefs(mFileSpec)); + } break; case 310: /////////////////////////////////////////////////////////// Mac Documents - mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Mac_DocumentsDirectory )); + { + NS_WITH_SERVICE(nsIProperties, directoryService, NS_DIRECTORY_SERVICE_PROGID, &rv); + + directoryService->Get("system.DocumentsDirectory", + NS_GET_IID(nsIFile), + getter_AddRefs(mFileSpec)); + } break; case 400: /////////////////////////////////////////////////////////// Unix Local - mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Unix_LocalDirectory )); + { + NS_WITH_SERVICE(nsIProperties, directoryService, NS_DIRECTORY_SERVICE_PROGID, &rv); + + directoryService->Get("system.LocalDirectory", + NS_GET_IID(nsIFile), + getter_AddRefs(mFileSpec)); + } break; case 401: /////////////////////////////////////////////////////////// Unix Lib - mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Unix_LibDirectory )); + { + NS_WITH_SERVICE(nsIProperties, directoryService, NS_DIRECTORY_SERVICE_PROGID, &rv); + + directoryService->Get("system.LibDirectory", + NS_GET_IID(nsIFile), + getter_AddRefs(mFileSpec)); + } break; @@ -401,12 +544,12 @@ nsInstallFolder::SetDirectoryPath(const nsString& aFolderID, const nsString& aRe if (aRelativePath.Length() > 0 && mFileSpec) { - nsString tempPath(aRelativePath); + //nsString tempPath(aRelativePath); - if (aRelativePath.Last() != '/' || aRelativePath.Last() != '\\') - tempPath.AppendWithConversion('/'); + //if (aRelativePath.Last() != '/' || aRelativePath.Last() != '\\') + // tempPath.AppendWithConversion('/'); - *mFileSpec += tempPath; + mFileSpec->Append(aRelativePath.ToNewCString()); } } } @@ -436,6 +579,9 @@ nsInstallFolder::MapNameToEnum(const nsString& name) return -1; } + +#if 0 //Remarking out for nsIFile migration (I don't think we need it anymore) + void nsInstallFolder::SetAppShellDirectory(PRUint32 value) { @@ -444,11 +590,13 @@ nsInstallFolder::SetAppShellDirectory(PRUint32 value) { mFileSpec = new nsFileSpec(); fs->GetFileSpec(mFileSpec); - NS_RELEASE(fs); + NS_RELEASE(fs); } } -nsFileSpec* +#endif //end nsIFile migration comment + +nsIFile* nsInstallFolder::GetFileSpec() { if (mFileSpec == nsnull) @@ -462,6 +610,19 @@ nsInstallFolder::ToString(nsAutoString* outString) //XXX: May need to fix. Native charset paths will be converted into Unicode when the get to JS // This will appear to work on Latin-1 charsets but won't work on Mac or other charsets. - outString->AssignWithConversion( mFileSpec->GetCString() ); - return NS_OK; + char* temp; + PRBool flagIsFile; + + nsresult rv = mFileSpec->GetPath(&temp); + mFileSpec->IsFile(&flagIsFile); + if (!flagIsFile) + { + nsString tempString(temp); + + tempString += FILESEP; + outString->AssignWithConversion(tempString.ToNewCString()); + } + else + outString->AssignWithConversion(temp); + return rv; } diff --git a/mozilla/xpinstall/src/nsInstallFolder.h b/mozilla/xpinstall/src/nsInstallFolder.h index a61781f74b5..8bb38db067e 100644 --- a/mozilla/xpinstall/src/nsInstallFolder.h +++ b/mozilla/xpinstall/src/nsInstallFolder.h @@ -44,12 +44,12 @@ class nsInstallFolder virtual ~nsInstallFolder(); void GetDirectoryPath(nsString& aDirectoryPath); - nsFileSpec* GetFileSpec(); + nsIFile* GetFileSpec(); PRInt32 ToString(nsAutoString* outString); private: - nsFileSpec* mFileSpec; + nsCOMPtr mFileSpec; void SetDirectoryPath(const nsString& aFolderID, const nsString& aRelativePath); void PickDefaultDirectory(); diff --git a/mozilla/xpinstall/src/nsInstallPatch.cpp b/mozilla/xpinstall/src/nsInstallPatch.cpp index 686f4c73d36..10a6f92be62 100644 --- a/mozilla/xpinstall/src/nsInstallPatch.cpp +++ b/mozilla/xpinstall/src/nsInstallPatch.cpp @@ -37,6 +37,7 @@ #ifdef XP_MAC #include "PatchableAppleSingle.h" +#include "nsILocalFileMac.h" #endif #define BUFSIZE 32768 @@ -89,15 +90,18 @@ nsInstallPatch::nsInstallPatch( nsInstall* inInstall, *error = nsInstall::NO_SUCH_COMPONENT; return; } - nsString folderSpec; folderSpec.AssignWithConversion(tempTargetFile); + nsString folderSpec; folderSpec.AssignWithConversion(tempTargetFile); + + nsCOMPtr tmp; + NS_NewLocalFile((char*)tempTargetFile, getter_AddRefs(tmp)); mPatchFile = nsnull; mTargetFile = nsnull; mPatchedFile = nsnull; mRegistryName = new nsString(inVRName); mJarLocation = new nsString(inJarLocation); - mTargetFile = new nsFileSpec(folderSpec); mVersionInfo = new nsInstallVersion(); + tmp->Clone(getter_AddRefs(mTargetFile)); if (mRegistryName == nsnull || mJarLocation == nsnull || @@ -130,7 +134,7 @@ nsInstallPatch::nsInstallPatch( nsInstall* inInstall, return; } - nsFileSpec* tmp = folderSpec->GetFileSpec(); + nsCOMPtr tmp = folderSpec->GetFileSpec(); if (!tmp) { *error = nsInstall::INVALID_ARGUMENTS; @@ -143,7 +147,7 @@ nsInstallPatch::nsInstallPatch( nsInstall* inInstall, mRegistryName = new nsString(inVRName); mJarLocation = new nsString(inJarLocation); mVersionInfo = new nsInstallVersion(); - mTargetFile = new nsFileSpec(*tmp); + tmp->Clone(getter_AddRefs(mTargetFile)); if (mRegistryName == nsnull || mJarLocation == nsnull || @@ -156,9 +160,8 @@ nsInstallPatch::nsInstallPatch( nsInstall* inInstall, mVersionInfo->Init(inVInfo); - if(! inPartialPath.IsEmpty()) - *mTargetFile += inPartialPath; + mTargetFile->Append(inPartialPath.ToNewCString()); } nsInstallPatch::~nsInstallPatch() @@ -166,8 +169,8 @@ nsInstallPatch::~nsInstallPatch() if (mVersionInfo) delete mVersionInfo; - if (mTargetFile) - delete mTargetFile; + //if (mTargetFile) + // delete mTargetFile; if (mJarLocation) delete mJarLocation; @@ -175,11 +178,11 @@ nsInstallPatch::~nsInstallPatch() if (mRegistryName) delete mRegistryName; - if (mPatchedFile) - delete mPatchedFile; + //if (mPatchedFile) + // delete mPatchedFile; - if (mPatchFile) - delete mPatchFile; + //if (mPatchFile) + // delete mPatchFile; MOZ_COUNT_DTOR(nsInstallPatch); } @@ -188,14 +191,16 @@ nsInstallPatch::~nsInstallPatch() PRInt32 nsInstallPatch::Prepare() { PRInt32 err; - PRBool deleteOldSrc; + PRBool deleteOldSrc, flagExists, flagIsFile; if (mTargetFile == nsnull) return nsInstall::INVALID_ARGUMENTS; - if (mTargetFile->Exists()) + mTargetFile->Exists(&flagExists); + if (flagExists) { - if (mTargetFile->IsFile()) + mTargetFile->IsFile(&flagIsFile); + if (flagIsFile) { err = nsInstall::SUCCESS; } @@ -214,13 +219,14 @@ PRInt32 nsInstallPatch::Prepare() return err; } - err = mInstall->ExtractFileFromJar(*mJarLocation, mTargetFile, &mPatchFile); + err = mInstall->ExtractFileFromJar(*mJarLocation, mTargetFile, getter_AddRefs(mPatchFile)); - nsFileSpec *fileName = nsnull; - nsVoidKey ikey( HashFilePath( nsFilePath(*mTargetFile) ) ); - - mInstall->GetPatch(&ikey, &fileName); + nsCOMPtr fileName = nsnull; + //nsVoidKey ikey( HashFilePath( nsFilePath(*mTargetFile) ) );//nsIFileXXX: nsFilePath? + nsVoidKey ikey( HashFilePath( mTargetFile )); + + mInstall->GetPatch(&ikey, getter_AddRefs(fileName)); if (fileName != nsnull) { @@ -232,12 +238,13 @@ PRInt32 nsInstallPatch::Prepare() deleteOldSrc = PR_FALSE; } - err = NativePatch( *fileName, // the file to patch - *mPatchFile, // the patch that was extracted from the jarfile - &mPatchedFile); // the new patched file + err = NativePatch( fileName, // the file to patch + mPatchFile, // the patch that was extracted from the jarfile + getter_AddRefs(mPatchedFile)); // the new patched file // clean up extracted diff data file - if ( (mPatchFile != nsnull) && (mPatchFile->Exists()) ) + mPatchFile->Exists(&flagExists); + if ( (mPatchFile != nsnull) && (flagExists) ) { mPatchFile->Delete(PR_FALSE); } @@ -246,19 +253,20 @@ PRInt32 nsInstallPatch::Prepare() if (err != nsInstall::SUCCESS) { // clean up tmp patched file since patching failed - if ((mPatchedFile != nsnull) && (mPatchedFile->Exists())) - { - mPatchedFile->Delete(PR_FALSE); - } + mPatchFile->Exists(&flagExists); + if ((mPatchedFile != nsnull) && (flagExists)) + { + mPatchedFile->Delete(PR_FALSE); + } return err; } PR_ASSERT(mPatchedFile != nsnull); - mInstall->AddPatch(&ikey, mPatchedFile ); - + mInstall->AddPatch(&ikey, mPatchedFile ); + if ( deleteOldSrc ) { - DeleteFileNowOrSchedule(*fileName ); + DeleteFileNowOrSchedule(fileName ); } return err; @@ -266,6 +274,8 @@ PRInt32 nsInstallPatch::Prepare() PRInt32 nsInstallPatch::Complete() { + PRBool flagEquals; + if ((mInstall == nsnull) || (mVersionInfo == nsnull) || (mPatchedFile == nsnull) || (mTargetFile == nsnull)) { return nsInstall::INVALID_ARGUMENTS; @@ -273,19 +283,23 @@ PRInt32 nsInstallPatch::Complete() PRInt32 err = nsInstall::SUCCESS; - nsFileSpec *fileName = nsnull; - nsVoidKey ikey( HashFilePath( nsFilePath(*mTargetFile) ) ); + nsCOMPtr fileName = nsnull; + //nsVoidKey ikey( HashFilePath( nsFilePath(*mTargetFile) ) );//nsIFileXXX: nsFilePath? + nsVoidKey ikey( HashFilePath( mTargetFile )); - mInstall->GetPatch(&ikey, &fileName); + mInstall->GetPatch(&ikey, getter_AddRefs(fileName)); if (fileName == nsnull) { err = nsInstall::UNEXPECTED_ERROR; } - else if (*fileName == *mPatchedFile) + else { + fileName->Equals(mPatchedFile, &flagEquals); + if (flagEquals) + { // the patch has not been superceded--do final replacement - err = ReplaceFileNowOrSchedule( *mPatchedFile, *mTargetFile); + err = ReplaceFileNowOrSchedule( mPatchedFile, mTargetFile); if ( 0 == err || nsInstall::REBOOT_NEEDED == err ) { nsString tempVersionString; @@ -293,12 +307,14 @@ PRInt32 nsInstallPatch::Complete() char* tempRegName = mRegistryName->ToNewCString(); char* tempVersion = tempVersionString.ToNewCString(); + char* tempPath; + mTargetFile->GetPath(&tempPath); // DO NOT propogate version registry errors, it will abort // FinalizeInstall() leaving things hosed. These piddly errors // aren't worth that. VR_Install( tempRegName, - (char*)(const char *)mTargetFile->GetNativePathCString(), + tempPath, tempVersion, PR_FALSE ); @@ -310,32 +326,35 @@ PRInt32 nsInstallPatch::Complete() { err = nsInstall::UNEXPECTED_ERROR; } - } - else - { + } + else + { // nothing -- old intermediate patched file was // deleted by a superceding patch + } } - return err; } void nsInstallPatch::Abort() { - nsFileSpec *fileName = nsnull; - nsVoidKey ikey( HashFilePath( nsFilePath(*mTargetFile) ) ); + PRBool flagEquals; + nsCOMPtr fileName = nsnull; + //nsVoidKey ikey( HashFilePath( nsFilePath(*mTargetFile) ) ); //nsIFileXXX: nsFilePath? + nsVoidKey ikey( HashFilePath( mTargetFile )); - mInstall->GetPatch(&ikey, &fileName); + mInstall->GetPatch(&ikey, getter_AddRefs(fileName)); - if (fileName != nsnull && (*fileName == *mPatchedFile) ) + fileName->Equals(mPatchedFile, &flagEquals); + if (fileName != nsnull && (flagEquals) ) { - DeleteFileNowOrSchedule( *mPatchedFile ); + DeleteFileNowOrSchedule( mPatchedFile ); } } char* nsInstallPatch::toString() { - char* buffer = new char[1024]; + char* buffer = new char[1024]; char* rsrcVal = nsnull; if (buffer == nsnull || !mInstall) @@ -347,7 +366,9 @@ char* nsInstallPatch::toString() if (rsrcVal) { - sprintf( buffer, rsrcVal, mTargetFile->GetCString()); + char* temp; + mTargetFile->GetPath(&temp); + sprintf( buffer, rsrcVal, temp); nsCRT::free(rsrcVal); } } @@ -370,22 +391,25 @@ nsInstallPatch::RegisterPackageNode() PRInt32 -nsInstallPatch::NativePatch(const nsFileSpec &sourceFile, const nsFileSpec &patchFile, nsFileSpec **newFile) +nsInstallPatch::NativePatch(nsIFile *sourceFile, nsIFile *patchFile, nsIFile **newFile) //nsIFileXXX: changed & to * { - DIFFDATA *dd; - PRInt32 status = GDIFF_ERR_MEM; - char *tmpurl = NULL; - char *realfile = PL_strdup(nsNSPRPath(sourceFile)); // needs to be sourceFile!!! - nsFileSpec *outFileSpec = new nsFileSpec; - nsFileSpec *tempSrcFile = new nsFileSpec; // TODO: do you need to free? - - if (!outFileSpec) { - status = GDIFF_ERR_MEM; - goto cleanup; - } - - *outFileSpec = sourceFile; + PRBool flagExists; + nsresult rv; + DIFFDATA *dd; + PRInt32 status = GDIFF_ERR_MEM; + char *tmpurl = NULL; + //nsFileSpec *outFileSpec = new nsFileSpec; + //nsFileSpec *tempSrcFile = new nsFileSpec; // TODO: do you need to free? + nsCOMPtr outFileSpec; + nsCOMPtr tempSrcFile; + nsCOMPtr uniqueSrcFile; + nsCOMPtr patchFileLocal = do_QueryInterface(patchFile, &rv); + + char* realfile; + sourceFile->GetPath(&realfile); + + sourceFile->Clone(getter_AddRefs(outFileSpec)); dd = (DIFFDATA *)PR_Calloc( 1, sizeof(DIFFDATA)); if (dd != NULL) @@ -401,149 +425,185 @@ nsInstallPatch::NativePatch(const nsFileSpec &sourceFile, const nsFileSpec &patc dd->bufsize = BUFSIZE; // validate patch header & check for special instructions - dd->fDiff = PR_Open (nsNSPRPath(patchFile), PR_RDONLY, 0666); - + patchFileLocal->OpenNSPRFileDesc(PR_RDONLY, 0666, &dd->fDiff); if (dd->fDiff != NULL) { status = gdiff_parseHeader(dd); - } else { + } + else + { status = GDIFF_ERR_ACCESS; } - // in case we need to unbind Win32 images OR encode Mac file - if (( dd->bWin32BoundImage || dd->bMacAppleSingle) && (status == GDIFF_OK )) + // in case we need to unbind Win32 images OR encode Mac file + if (( dd->bWin32BoundImage || dd->bMacAppleSingle) && (status == GDIFF_OK )) + { + // make an unique tmp file (FILENAME-src.EXT) + char* leafName; + rv = sourceFile->GetLeafName(&leafName); + + nsString tmpName; tmpName.AssignWithConversion("-src"); + nsString tmpFileName; tmpFileName.AssignWithConversion(leafName); + + PRInt32 i; + if ((i = tmpFileName.RFindChar('.')) > 0) { - // make an unique tmp file (FILENAME-src.EXT) - *tempSrcFile = sourceFile; - nsString tmpName; tmpName.AssignWithConversion("-src"); - nsString tmpFileName; tmpFileName.AssignWithConversion(sourceFile.GetLeafName()); - - PRInt32 i; - if ((i = tmpFileName.RFindChar('.')) > 0) - { - nsString ext; - nsString fName; - tmpFileName.Right(ext, (tmpFileName.Length() - i) ); - tmpFileName.Left(fName, (tmpFileName.Length() - (tmpFileName.Length() - i))); - tmpFileName = fName + tmpName + ext; - - } else { - tmpFileName += tmpName; - } - - - tempSrcFile->SetLeafName(tmpFileName); - tempSrcFile->MakeUnique(); - -#ifdef WIN32 - // unbind Win32 images - char *tmpFile = PL_strdup(nsNSPRPath(*tempSrcFile)); - if (su_unbind(realfile, tmpFile)) - { - PL_strfree(realfile); - realfile = PL_strdup(tmpFile); - } - else - { - status = GDIFF_ERR_MEM; - } - PL_strfree(tmpFile); -#endif -#ifdef XP_MAC - // Encode src file, and put into temp file - FSSpec sourceSpec = sourceFile.GetFSSpec(); - FSSpec tempSpec = tempSrcFile->GetFSSpec(); - - status = PAS_EncodeFile(&sourceSpec, &tempSpec); - - if (status == noErr) - { - // set - PL_strfree(realfile); - realfile = PL_strdup(nsNSPRPath(*tempSrcFile)); - } -#endif - } - - if (status != NS_OK) - goto cleanup; - - // make a unique file at the same location of our source file (FILENAME-ptch.EXT) - nsString patchFileName; patchFileName.AssignWithConversion("-ptch"); - nsString newFileName; newFileName.AssignWithConversion(sourceFile.GetLeafName()); - - PRInt32 index; - if ((index = newFileName.RFindChar('.')) > 0) - { - nsString extention; - nsString fileName; - newFileName.Right(extention, (newFileName.Length() - index) ); - newFileName.Left(fileName, (newFileName.Length() - (newFileName.Length() - index))); - newFileName = fileName + patchFileName + extention; + nsString ext; + nsString fName; + tmpFileName.Right(ext, (tmpFileName.Length() - i) ); + tmpFileName.Left(fName, (tmpFileName.Length() - (tmpFileName.Length() - i))); + tmpFileName = fName + tmpName + ext; } else { - newFileName += patchFileName; + tmpFileName += tmpName; } + + rv = sourceFile->Clone(getter_AddRefs(tempSrcFile)); //Clone the sourceFile + tempSrcFile->SetLeafName(tmpFileName.ToNewCString()); //Append the new leafname + uniqueSrcFile = do_QueryInterface(tempSrcFile, &rv); //Create an nsILocalFile version to pass to MakeUnique + MakeUnique(uniqueSrcFile); - outFileSpec->SetLeafName(newFileName); - outFileSpec->MakeUnique(); + char* realfile; + sourceFile->GetPath(&realfile); - char *outFile = PL_strdup(nsNSPRPath(*outFileSpec)); +#ifdef WIN32 + // unbind Win32 images - // apply patch to the source file - dd->fSrc = PR_Open ( realfile, PR_RDONLY, 0666); - dd->fOut = PR_Open ( outFile, PR_RDWR|PR_CREATE_FILE|PR_TRUNCATE, 0666); + char* unboundFile; + uniqueSrcFile->GetPath(&unboundFile); - if (dd->fSrc != NULL && dd->fOut != NULL) - { - status = gdiff_validateFile (dd, SRCFILE); + if (su_unbind(realfile, unboundFile)) // + { + PL_strfree(realfile); + realfile = PL_strdup(unboundFile); + } + else + { + status = GDIFF_ERR_MEM; + } + PL_strfree(unboundFile); +#endif +#ifdef XP_MAC + // Encode src file, and put into temp file + FSSpec sourceSpec, tempSpec; + nsCOMPtr tempSourceFile; + tempSourceFile = do_QueryInterface(sourceFile, &rv); + tempSourceFile->GetFSSpec(&sourceSpec); + + status = PAS_EncodeFile(&sourceSpec, &tempSpec); - // specify why diff failed - if (status == GDIFF_ERR_CHECKSUM) - status = GDIFF_ERR_CHECKSUM_TARGET; + if (status == noErr) + { + // set + PL_strfree(realfile); + tempSrcFile->GetPath(&realfile); + } +#endif + } - if (status == GDIFF_OK) - status = gdiff_ApplyPatch(dd); + if (status != NS_OK) + goto cleanup; - if (status == GDIFF_OK) - status = gdiff_validateFile (dd, OUTFILE); + // make a unique file at the same location of our source file (FILENAME-ptch.EXT) + nsString patchFileName; patchFileName.AssignWithConversion("-ptch"); + char* leafName; + sourceFile->GetLeafName(&leafName); + nsString newFileName; newFileName.AssignWithConversion(leafName);; - if (status == GDIFF_ERR_CHECKSUM) - status = GDIFF_ERR_CHECKSUM_RESULT; + PRInt32 index; + if ((index = newFileName.RFindChar('.')) > 0) + { + nsString extention; + nsString fileName; + newFileName.Right(extention, (newFileName.Length() - index) ); + newFileName.Left(fileName, (newFileName.Length() - (newFileName.Length() - index))); + newFileName = fileName + patchFileName + extention; - *newFile = outFileSpec; - if ( outFile != nsnull) - PL_strfree( outFile ); + } + else + { + newFileName += patchFileName; + } - } else { - status = GDIFF_ERR_ACCESS; - } - } + outFileSpec->SetLeafName(newFileName.ToNewCString()); //Set new leafname + nsCOMPtr outFileLocal = do_QueryInterface(outFileSpec, &rv); //Create an nsILocalFile version + //to send to MakeUnique() + MakeUnique(outFileLocal); + + // apply patch to the source file + //dd->fSrc = PR_Open ( realfile, PR_RDONLY, 0666); + //dd->fOut = PR_Open ( outFile, PR_RDWR|PR_CREATE_FILE|PR_TRUNCATE, 0666); + nsCOMPtr realFileLocal = do_CreateInstance(NS_LOCAL_FILE_PROGID);; + realFileLocal->InitWithPath(realfile); + + realFileLocal->OpenNSPRFileDesc(PR_RDONLY, 0666, &dd->fSrc); + outFileLocal->OpenNSPRFileDesc(PR_RDWR|PR_CREATE_FILE|PR_TRUNCATE, 0666, &dd->fOut); + + if (dd->fSrc != NULL && dd->fOut != NULL) + { + status = gdiff_validateFile (dd, SRCFILE); + + // specify why diff failed + if (status == GDIFF_ERR_CHECKSUM) + status = GDIFF_ERR_CHECKSUM_TARGET; + + if (status == GDIFF_OK) + status = gdiff_ApplyPatch(dd); + + if (status == GDIFF_OK) + status = gdiff_validateFile (dd, OUTFILE); + + if (status == GDIFF_ERR_CHECKSUM) + status = GDIFF_ERR_CHECKSUM_RESULT; + + rv = outFileSpec->Clone(getter_AddRefs(newFile)); + } + else + { + status = GDIFF_ERR_ACCESS; + } + } #ifdef XP_MAC - if ( dd->bMacAppleSingle && status == GDIFF_OK ) - { + if ( dd->bMacAppleSingle && status == GDIFF_OK ) + { // create another file, so that we can decode somewhere - nsFileSpec anotherName = *outFileSpec; - anotherName.MakeUnique(); + //nsFileSpec anotherName = *outFileSpec; + nsCOMPtr anotherName; + nsCOMPtr bsTemp; + + outFileSpec->Clone(getter_AddRefs(bsTemp)); //Clone because we'll be changing the name + anotherName = do_QueryInterface(bsTemp, &rv); //Set the old name + MakeUnique(anotherName); //Now give it the new name // Close the out file so that we can read it PR_Close( dd->fOut ); dd->fOut = NULL; - FSSpec outSpec = outFileSpec->GetFSSpec(); - FSSpec anotherSpec = anotherName.GetFSSpec(); + FSSpec outSpec; + FSSpec anotherSpec; + nsCOMPtr outSpecMacSpecific; + nsCOMPtr anotherNameMacSpecific; - if ( outFileSpec->Exists() ) + anotherNameMacSpecific = do_QueryInterface(anotherName, &rv); //set value to nsILocalFileMac (sheesh) + outSpecMacSpecific = do_QueryInterface(outFileSpec, &rv); //ditto + + anotherNameMacSpecific->GetFSSpec(&anotherSpec); + outSpecMacSpecific->GetFSSpec(&outSpec); + + outFileSpec->Exists(&flagExists); + if ( flagExists ) { - printf("filesize: %d\n", outFileSpec->GetFileSize()); + PRInt64 fileSize; + outFileSpec->GetFileSize(&fileSize); + printf("filesize: %d\n", fileSize); } @@ -553,16 +613,18 @@ nsInstallPatch::NativePatch(const nsFileSpec &sourceFile, const nsFileSpec &patc goto cleanup; } - nsFileSpec parent; + nsCOMPtr parent; - outFileSpec->GetParent(parent); + outFileSpec->GetParent(getter_AddRefs(parent)); outFileSpec->Delete(PR_FALSE); - anotherName.CopyToDir(parent); - *outFileSpec = anotherName; + char* leaf; + anotherName->GetLeafName(&leaf); + anotherName->CopyTo(parent, leaf); + + anotherName->Clone(getter_AddRefs(newFile)); - *newFile = outFileSpec; } #endif @@ -574,28 +636,25 @@ cleanup: if ( dd->fSrc != nsnull ) PR_Close( dd->fSrc ); - if ( dd->fDiff != nsnull ) PR_Close( dd->fDiff ); - - if ( dd->fOut != nsnull ) - { + + if ( dd->fOut != nsnull ) PR_Close( dd->fOut ); - } - + if ( status != GDIFF_OK ) - //XP_FileRemove( outfile, outtype ); - newFile = NULL; - - PR_FREEIF( dd->databuf ); + //XP_FileRemove( outfile, outtype ); + newFile = NULL; + + PR_FREEIF( dd->databuf ); PR_FREEIF( dd->oldChecksum ); PR_FREEIF( dd->newChecksum ); PR_DELETE(dd); } - if ( tmpurl != NULL ) { + if ( tmpurl != NULL ) { //XP_FileRemove( tmpurl, xpURL ); - tmpurl = NULL; + tmpurl = NULL; PR_DELETE( tmpurl ); } @@ -604,50 +663,53 @@ cleanup: PL_strfree(realfile); } - if ((tempSrcFile != nsnull) && (tempSrcFile->Exists()) ) + if (tempSrcFile) { - tempSrcFile->Delete(PR_FALSE); + tempSrcFile->Exists(&flagExists); + if (flagExists) + tempSrcFile->Delete(PR_FALSE); } - /* lets map any GDIFF error to nice SU errors */ + /* lets map any GDIFF error to nice SU errors */ - switch (status) - { + switch (status) + { case GDIFF_OK: break; - case GDIFF_ERR_HEADER: - case GDIFF_ERR_BADDIFF: - case GDIFF_ERR_OPCODE: - case GDIFF_ERR_CHKSUMTYPE: - status = nsInstall::PATCH_BAD_DIFF; - break; - case GDIFF_ERR_CHECKSUM_TARGET: - status = nsInstall::PATCH_BAD_CHECKSUM_TARGET; - break; - case GDIFF_ERR_CHECKSUM_RESULT: - status = nsInstall::PATCH_BAD_CHECKSUM_RESULT; - break; - case GDIFF_ERR_OLDFILE: - case GDIFF_ERR_ACCESS: - case GDIFF_ERR_MEM: - case GDIFF_ERR_UNKNOWN: - default: - status = nsInstall::UNEXPECTED_ERROR; - break; - } + case GDIFF_ERR_HEADER: + case GDIFF_ERR_BADDIFF: + case GDIFF_ERR_OPCODE: + case GDIFF_ERR_CHKSUMTYPE: + status = nsInstall::PATCH_BAD_DIFF; + break; + case GDIFF_ERR_CHECKSUM_TARGET: + status = nsInstall::PATCH_BAD_CHECKSUM_TARGET; + break; + case GDIFF_ERR_CHECKSUM_RESULT: + status = nsInstall::PATCH_BAD_CHECKSUM_RESULT; + break; + case GDIFF_ERR_OLDFILE: + case GDIFF_ERR_ACCESS: + case GDIFF_ERR_MEM: + case GDIFF_ERR_UNKNOWN: + default: + status = nsInstall::UNEXPECTED_ERROR; + break; + } return status; - // return -1; //old return value + // return -1; //old return value } void* -nsInstallPatch::HashFilePath(const nsFilePath& aPath) +nsInstallPatch::HashFilePath(nsIFile* aPath) { PRUint32 rv = 0; - char* cPath = PL_strdup(nsNSPRPath(aPath)); + char* cPath; + aPath->GetPath(&cPath); if(cPath != nsnull) { @@ -661,7 +723,7 @@ nsInstallPatch::HashFilePath(const nsFilePath& aPath) } } - PL_strfree(cPath); + PL_strfree(cPath); return (void*)rv; } diff --git a/mozilla/xpinstall/src/nsInstallPatch.h b/mozilla/xpinstall/src/nsInstallPatch.h index a6abf19cdce..4a3421d3546 100644 --- a/mozilla/xpinstall/src/nsInstallPatch.h +++ b/mozilla/xpinstall/src/nsInstallPatch.h @@ -67,17 +67,17 @@ class nsInstallPatch : public nsInstallObject nsInstallVersion *mVersionInfo; - nsFileSpec *mTargetFile; - nsFileSpec *mPatchFile; - nsFileSpec *mPatchedFile; + nsCOMPtr mTargetFile; + nsCOMPtr mPatchFile; + nsCOMPtr mPatchedFile; nsString *mJarLocation; nsString *mRegistryName; - PRInt32 NativePatch(const nsFileSpec &sourceFile, const nsFileSpec &patchfile, nsFileSpec **newFile); - void* HashFilePath(const nsFilePath& aPath); + PRInt32 NativePatch(nsIFile *sourceFile, nsIFile *patchfile, nsIFile **newFile); + void* HashFilePath(nsIFile* aPath); }; #endif /* nsInstallPatch_h__ */ diff --git a/mozilla/xpinstall/src/nsInstallUninstall.cpp b/mozilla/xpinstall/src/nsInstallUninstall.cpp index 74909c7c0ff..10a4a723f11 100644 --- a/mozilla/xpinstall/src/nsInstallUninstall.cpp +++ b/mozilla/xpinstall/src/nsInstallUninstall.cpp @@ -189,10 +189,14 @@ REGERR su_UninstallProcessItem(char *component_path) int refcount; int err; char filepath[MAXREGPATHLEN]; + nsCOMPtr nsLFPath; + nsCOMPtr nsFPath; err = VR_GetPath(component_path, sizeof(filepath), filepath); if ( err == REGERR_OK ) { + NS_NewLocalFile((char*)filepath, getter_AddRefs(nsLFPath)); + nsFPath = nsLFPath; err = VR_GetRefCount(component_path, &refcount); if ( err == REGERR_OK ) { @@ -202,14 +206,14 @@ REGERR su_UninstallProcessItem(char *component_path) else { err = VR_Remove(component_path); - DeleteFileNowOrSchedule(nsFileSpec(filepath)); + DeleteFileNowOrSchedule(nsFPath); } } else { /* delete node and file */ err = VR_Remove(component_path); - DeleteFileNowOrSchedule(nsFileSpec(filepath)); + DeleteFileNowOrSchedule(nsFPath); } } return err; diff --git a/mozilla/xpinstall/src/nsJSFile.cpp b/mozilla/xpinstall/src/nsJSFile.cpp index c0eebcaa2e5..ac85039269d 100644 --- a/mozilla/xpinstall/src/nsJSFile.cpp +++ b/mozilla/xpinstall/src/nsJSFile.cpp @@ -119,7 +119,7 @@ JSBool PR_CALLBACK InstallFileOpDirGetParent(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { nsInstall* nativeThis = (nsInstall*)JS_GetPrivate(cx, obj); - nsFileSpec nativeRet; + nsCOMPtr nativeRet; nsString nativeRetNSStr; JSObject *jsObj; nsInstallFolder *folder; @@ -151,13 +151,16 @@ InstallFileOpDirGetParent(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, folder = (nsInstallFolder*)JS_GetPrivate(cx, jsObj); - if(!folder || NS_OK != nativeThis->FileOpDirGetParent(*folder, &nativeRet)) + if(!folder || NS_OK != nativeThis->FileOpDirGetParent(*folder, getter_AddRefs(nativeRet))) { // error, return NULL return JS_TRUE; } - nativeRetNSStr.AssignWithConversion(nativeRet.GetNativePathCString()); + char* temp; + nativeRet->GetPath(&temp); + nativeRetNSStr.AssignWithConversion(temp); + *rval = STRING_TO_JSVAL(JS_NewUCStringCopyN(cx, nativeRetNSStr.GetUnicode(), nativeRetNSStr.Length())); return JS_TRUE; @@ -335,8 +338,10 @@ InstallFileOpFileCopy(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsv srcFolder = (nsInstallFolder*)JS_GetPrivate(cx, jsSrcObj); targetFolder = (nsInstallFolder*)JS_GetPrivate(cx, jsTargetObj); + PRInt32 tempRet; + tempRet = nativeThis->FileOpFileCopy(*srcFolder, *targetFolder, &nativeRet); - if(!srcFolder || !targetFolder || NS_OK != nativeThis->FileOpFileCopy(*srcFolder, *targetFolder, &nativeRet)) + if(!srcFolder || !targetFolder || NS_OK != tempRet) { return JS_TRUE; } @@ -356,7 +361,7 @@ InstallFileOpFileCopy(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsv // Native method FileDelete // JSBool PR_CALLBACK -InstallFileOpFileDelete(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +InstallFileOpFileRemove(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { nsInstall *nativeThis = (nsInstall*)JS_GetPrivate(cx, obj); PRInt32 nativeRet; @@ -664,11 +669,11 @@ JSBool PR_CALLBACK InstallFileOpFileGetSize(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { nsInstall* nativeThis = (nsInstall*)JS_GetPrivate(cx, obj); - PRUint32 nativeRet; + PRInt64 nativeRet; JSObject *jsObj; nsInstallFolder *folder; - *rval = INT_TO_JSVAL(nsInstall::UNEXPECTED_ERROR);; + *rval = INT_TO_JSVAL(nsInstall::UNEXPECTED_ERROR); // If there's no private data, this must be the prototype, so ignore if(nsnull == nativeThis) @@ -698,20 +703,12 @@ InstallFileOpFileGetSize(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, { return JS_TRUE; } - - if ( nativeRet <= JSVAL_INT_MAX ) - *rval = INT_TO_JSVAL(nativeRet); - else - { - JSInt64 l; - jsdouble d; - - JSLL_UI2L( l, nativeRet ); - JSLL_L2D( d, l ); - - JS_NewDoubleValue( cx, d, rval ); - } - + + PRFloat64 f; /* jsdouble's *are* PRFloat64's */ + + LL_L2F( f, nativeRet ); /* make float which is same type for js and nspr (native double) */ + JS_NewDoubleValue( cx, f, rval ); + return JS_TRUE; } @@ -1014,10 +1011,10 @@ InstallFileOpFileWindowsShortcut(JSContext *cx, JSObject *obj, uintN argc, jsval nsAutoString b3; nsAutoString b4; nsAutoString b5; - nsFileSpec nsfsB0; - nsFileSpec nsfsB1; - nsFileSpec nsfsB3; - nsFileSpec nsfsB5; + nsCOMPtr nsfsB0; + nsCOMPtr nsfsB1; + nsCOMPtr nsfsB3; + nsCOMPtr nsfsB5; PRInt32 b6; //JSObject *jsObj; @@ -1041,16 +1038,17 @@ InstallFileOpFileWindowsShortcut(JSContext *cx, JSObject *obj, uintN argc, jsval // String aIcon, // Number aIconId); + ConvertJSValToStr(b0, cx, argv[0]); - nsfsB0 = b0; + NS_NewLocalFile(b0.ToNewCString(), getter_AddRefs(nsfsB0)); ConvertJSValToStr(b1, cx, argv[1]); - nsfsB1 = b1; + NS_NewLocalFile(b1.ToNewCString(), getter_AddRefs(nsfsB1)); ConvertJSValToStr(b2, cx, argv[2]); ConvertJSValToStr(b3, cx, argv[3]); - nsfsB3 = b3; + NS_NewLocalFile(b3.ToNewCString(), getter_AddRefs(nsfsB3)); ConvertJSValToStr(b4, cx, argv[4]); ConvertJSValToStr(b5, cx, argv[5]); - nsfsB5 = b5; + NS_NewLocalFile(b5.ToNewCString(), getter_AddRefs(nsfsB5)); if(JSVAL_IS_NULL(argv[6])) { @@ -1301,7 +1299,7 @@ static JSFunctionSpec FileOpMethods[] = {"dirRemove", InstallFileOpDirRemove, 2}, {"dirRename", InstallFileOpDirRename, 2}, {"copy", InstallFileOpFileCopy, 2}, - {"delete", InstallFileOpFileDelete, 2}, + {"remove", InstallFileOpFileRemove, 1}, {"exists", InstallFileOpFileExists, 1}, {"execute", InstallFileOpFileExecute, 2}, {"nativeVersion", InstallFileOpFileGetNativeVersion, 1}, diff --git a/mozilla/xpinstall/src/nsJSFile.h b/mozilla/xpinstall/src/nsJSFile.h index b0c1b767ec9..f8041487d35 100644 --- a/mozilla/xpinstall/src/nsJSFile.h +++ b/mozilla/xpinstall/src/nsJSFile.h @@ -44,7 +44,7 @@ JSBool PR_CALLBACK InstallFileOpFileCopy(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); JSBool PR_CALLBACK -InstallFileOpFileDelete(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); +InstallFileOpFileRemove(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); JSBool PR_CALLBACK InstallFileOpFileExists(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); diff --git a/mozilla/xpinstall/src/nsJSInstall.cpp b/mozilla/xpinstall/src/nsJSInstall.cpp index f1bfff2b873..3a5b54cd525 100644 --- a/mozilla/xpinstall/src/nsJSInstall.cpp +++ b/mozilla/xpinstall/src/nsJSInstall.cpp @@ -1865,7 +1865,7 @@ static JSFunctionSpec InstallMethods[] = {"dirRemove", InstallFileOpDirRemove, 2}, {"dirRename", InstallFileOpDirRename, 2}, {"fileCopy", InstallFileOpFileCopy, 2}, - {"fileDelete", InstallFileOpFileDelete, 2}, + {"fileDelete", InstallFileOpFileRemove, 1}, {"fileExists", InstallFileOpFileExists, 1}, {"fileExecute", InstallFileOpFileExecute, 2}, {"fileGetNativeVersion", InstallFileOpFileGetNativeVersion, 1}, @@ -1910,7 +1910,7 @@ static JSFunctionSpec InstallMethods[] = {"DirRemove", InstallFileOpDirRemove, 2}, {"DirRename", InstallFileOpDirRename, 2}, {"FileCopy", InstallFileOpFileCopy, 2}, - {"FileDelete", InstallFileOpFileDelete, 2}, + {"FileDelete", InstallFileOpFileRemove, 1}, {"FileExists", InstallFileOpFileExists, 1}, {"FileExecute", InstallFileOpFileExecute, 2}, {"FileGetNativeVersion", InstallFileOpFileGetNativeVersion, 1}, @@ -1937,7 +1937,7 @@ static JSFunctionSpec InstallMethods[] = JSObject * InitXPInstallObjects(JSContext *jscontext, JSObject *global, - const nsFileSpec& jarfile, + nsIFile* jarfile, const PRUnichar* url, const PRUnichar* args, nsIZipReader * theJARFile) diff --git a/mozilla/xpinstall/src/nsSoftwareUpdate.cpp b/mozilla/xpinstall/src/nsSoftwareUpdate.cpp index 4e634c565db..3080c60741b 100644 --- a/mozilla/xpinstall/src/nsSoftwareUpdate.cpp +++ b/mozilla/xpinstall/src/nsSoftwareUpdate.cpp @@ -91,7 +91,7 @@ static NS_DEFINE_CID(kInstallVersion_CID, NS_SoftwareUpdateInstallVersion_CID); static NS_DEFINE_CID(knsRegistryCID, NS_REGISTRY_CID); nsSoftwareUpdate* nsSoftwareUpdate::mInstance = nsnull; -nsIFileSpec* nsSoftwareUpdate::mProgramDir = nsnull; +nsCOMPtr nsSoftwareUpdate::mProgramDir = nsnull; #if NOTIFICATION_ENABLE #include "nsUpdateNotification.h" @@ -154,7 +154,7 @@ nsSoftwareUpdate::~nsSoftwareUpdate() NR_ShutdownRegistry(); - NS_IF_RELEASE( mProgramDir ); + //NS_IF_RELEASE( mProgramDir ); mInstance = nsnull; } @@ -296,7 +296,7 @@ nsSoftwareUpdate::SetActiveNotifier(nsIXPINotifier *notifier) } NS_IMETHODIMP -nsSoftwareUpdate::InstallJar( nsIFileSpec* aLocalFile, +nsSoftwareUpdate::InstallJar( nsIFile* aLocalFile, const PRUnichar* aURL, const PRUnichar* aArguments, long flags, @@ -478,7 +478,7 @@ nsSoftwareUpdate::RegisterNameset() NS_IMETHODIMP -nsSoftwareUpdate::StubInitialize(nsIFileSpec *aDir) +nsSoftwareUpdate::StubInitialize(nsIFile *aDir) { if (mStubLockout) return NS_ERROR_ABORT; @@ -489,13 +489,12 @@ nsSoftwareUpdate::StubInitialize(nsIFileSpec *aDir) mStubLockout = PR_TRUE; // fix GetFolder return path - mProgramDir = aDir; - NS_ADDREF(mProgramDir); + nsresult rv = aDir->Clone(getter_AddRefs(mProgramDir)); // make sure registry updates go to the right place - nsFileSpec instDir; - if (NS_SUCCEEDED( aDir->GetFileSpec( &instDir ) ) ) - VR_SetRegDirectory( instDir.GetNativePathCString() ); + char* tempPath; + rv = aDir->GetPath(&tempPath); + VR_SetRegDirectory( tempPath ); // Create the logfile observer nsLoggingProgressNotifier *logger = new nsLoggingProgressNotifier(); @@ -503,7 +502,7 @@ nsSoftwareUpdate::StubInitialize(nsIFileSpec *aDir) // setup version registry path char* path; - nsresult rv = aDir->GetNativePath( &path ); + aDir->GetPath( &path ); if (NS_SUCCEEDED(rv)) { VR_SetRegDirectory( path ); diff --git a/mozilla/xpinstall/src/nsSoftwareUpdate.h b/mozilla/xpinstall/src/nsSoftwareUpdate.h index 10f50537512..8c4e661f093 100644 --- a/mozilla/xpinstall/src/nsSoftwareUpdate.h +++ b/mozilla/xpinstall/src/nsSoftwareUpdate.h @@ -45,12 +45,12 @@ class nsSoftwareUpdate: public nsIAppShellComponent, * information used within the XPI module -- not * available through any interface */ - static nsIFileSpec* GetProgramDirectory() { return mProgramDir; } + static nsIFile* GetProgramDirectory() { return mProgramDir; } NS_DECL_ISUPPORTS NS_DECL_NSIAPPSHELLCOMPONENT - NS_IMETHOD InstallJar( nsIFileSpec* localFile, + NS_IMETHOD InstallJar( nsIFile* localFile, const PRUnichar* URL, const PRUnichar* arguments, long flags = 0, @@ -68,15 +68,15 @@ class nsSoftwareUpdate: public nsIAppShellComponent, * once, and is also set by the AppShellComponent initialize * so it can't be called during a normal Mozilla run */ - NS_IMETHOD StubInitialize(nsIFileSpec *dir); + NS_IMETHOD StubInitialize(nsIFile *dir); nsSoftwareUpdate(); virtual ~nsSoftwareUpdate(); private: - static nsSoftwareUpdate* mInstance; - static nsIFileSpec* mProgramDir; + static nsSoftwareUpdate* mInstance; + static nsCOMPtr mProgramDir; #if NOTIFICATION_ENABLE static nsIUpdateNotification *mUpdateNotifier; diff --git a/mozilla/xpinstall/src/nsSoftwareUpdateRun.cpp b/mozilla/xpinstall/src/nsSoftwareUpdateRun.cpp index 7aa0ecb85da..fbb919a9e80 100644 --- a/mozilla/xpinstall/src/nsSoftwareUpdateRun.cpp +++ b/mozilla/xpinstall/src/nsSoftwareUpdateRun.cpp @@ -53,14 +53,14 @@ static NS_DEFINE_CID(kSoftwareUpdateCID, NS_SoftwareUpdate_CID); static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID); -extern JSObject *InitXPInstallObjects(JSContext *jscontext, JSObject *global, const nsFileSpec& jarfile, const PRUnichar* url, const PRUnichar* args, nsIZipReader* hZip); +extern JSObject *InitXPInstallObjects(JSContext *jscontext, JSObject *global, nsIFile* jarfile, const PRUnichar* url, const PRUnichar* args, nsIZipReader* hZip); extern nsresult InitInstallVersionClass(JSContext *jscontext, JSObject *global, void** prototype); extern nsresult InitInstallTriggerGlobalClass(JSContext *jscontext, JSObject *global, void** prototype); // Defined in this file: static void XPInstallErrorReporter(JSContext *cx, const char *message, JSErrorReport *report); -static PRInt32 GetInstallScriptFromJarfile(nsIZipReader* hZip, nsFileSpec& jarFile, char** scriptBuffer, PRUint32 *scriptLength); -static nsresult SetupInstallContext(nsIZipReader* hZip, const nsFileSpec& jarFile, const PRUnichar* url, const PRUnichar* args, JSRuntime *jsRT, JSContext **jsCX, JSObject **jsGlob); +static PRInt32 GetInstallScriptFromJarfile(nsIZipReader* hZip, nsIFile* jarFile, char** scriptBuffer, PRUint32 *scriptLength); +static nsresult SetupInstallContext(nsIZipReader* hZip, const nsIFile* jarFile, const PRUnichar* url, const PRUnichar* args, JSRuntime *jsRT, JSContext **jsCX, JSObject **jsGlob); extern "C" void RunInstallOnThread(void *data); @@ -163,15 +163,16 @@ XPInstallErrorReporter(JSContext *cx, const char *message, JSErrorReport *report /////////////////////////////////////////////////////////////////////////////////////////////// static PRInt32 -GetInstallScriptFromJarfile(nsIZipReader* hZip, nsFileSpec& jarFile, char** scriptBuffer, PRUint32 *scriptLength) +GetInstallScriptFromJarfile(nsIZipReader* hZip, nsIFile* jarFile, char** scriptBuffer, PRUint32 *scriptLength) { PRInt32 result = NS_OK; *scriptBuffer = nsnull; *scriptLength = 0; - nsCOMPtr jFile; - nsresult rv = NS_NewLocalFile(jarFile, getter_AddRefs(jFile)); + nsIFile* jFile; + nsresult rv =jarFile->Clone(&jFile); + //NS_NewLocalFile(jarFile, getter_AddRefs(jFile)); if (NS_SUCCEEDED(rv)) rv = hZip->Init(jFile); @@ -250,7 +251,7 @@ GetInstallScriptFromJarfile(nsIZipReader* hZip, nsFileSpec& jarFile, char** scri // Argument : JSObject **jsGlob - created global object /////////////////////////////////////////////////////////////////////////////////////////////// static nsresult SetupInstallContext(nsIZipReader* hZip, - const nsFileSpec& jarFile, + nsIFile* jarFile, const PRUnichar* url, const PRUnichar* args, JSRuntime *rt, @@ -383,10 +384,10 @@ extern "C" void RunInstallOnThread(void *data) nsString args; installInfo->GetArguments(args); - nsFileSpec jarpath; - rv = installInfo->GetLocalFile(jarpath); + nsCOMPtr jarpath; + rv = installInfo->GetLocalFile(getter_AddRefs(jarpath)); if (NS_SUCCEEDED(rv)) - { + { finalStatus = GetInstallScriptFromJarfile( hZip, jarpath, &scriptBuffer, @@ -468,6 +469,8 @@ extern "C" void RunInstallOnThread(void *data) if ( ownRuntime ) JS_DestroyRuntime(rt); } + // force zip archive closed before other cleanup + hZip = 0; } else { diff --git a/mozilla/xpinstall/src/nsXPITriggerInfo.h b/mozilla/xpinstall/src/nsXPITriggerInfo.h index 1053e9dcbc9..b66e6b5c606 100644 --- a/mozilla/xpinstall/src/nsXPITriggerInfo.h +++ b/mozilla/xpinstall/src/nsXPITriggerInfo.h @@ -31,6 +31,8 @@ #include "nsISupportsUtils.h" #include "nsIXPINotifier.h" #include "nsIFileSpec.h" +#include "nsILocalFile.h" +#include "nsIOutputStream.h" #include "jsapi.h" #include "prthread.h" #include "plevent.h" @@ -59,7 +61,8 @@ class nsXPITriggerItem nsString mArguments; PRInt32 mFlags; - nsCOMPtr mFile; + nsCOMPtr mFile; + nsCOMPtr mOutStream; PRBool IsFileURL() { return mURL.EqualsWithConversion("file:/",PR_FALSE,6); } PRBool IsRelativeURL(); diff --git a/mozilla/xpinstall/src/nsXPInstallManager.cpp b/mozilla/xpinstall/src/nsXPInstallManager.cpp index 3937ce07844..d94dfcd865f 100644 --- a/mozilla/xpinstall/src/nsXPInstallManager.cpp +++ b/mozilla/xpinstall/src/nsXPInstallManager.cpp @@ -32,9 +32,12 @@ #include "nsIURL.h" +#include "nsIFileTransportService.h" +#include "nsIOutputStream.h" #include "nsNetUtil.h" #include "nsIBufferInputStream.h" #include "nsIInputStream.h" +#include "nsIFileStreams.h" #include "nsIStreamListener.h" #include "nsISoftwareUpdate.h" @@ -45,9 +48,10 @@ #include "nsInstallProgressDialog.h" #include "nsInstallResources.h" #include "nsSpecialSystemDirectory.h" -#include "nsFileStream.h" +//#include "nsFileStream.h" #include "nsProxyObjectManager.h" #include "nsIDOMWindow.h" +#include "nsDirectoryService.h" #include "nsIAppShellComponentImpl.h" #include "nsIPrompt.h" @@ -303,8 +307,9 @@ 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_NewFileSpecWithSpec( nsFileSpec(nsFileURL(mItem->mURL)), + // getter_AddRefs(mItem->mFile) ); + rv = NS_NewLocalFile(mItem->mURL.ToNewCString(), getter_AddRefs(mItem->mFile)); if (NS_FAILED(rv)) { // serious problem with trigger! try to carry on @@ -319,20 +324,24 @@ NS_IMETHODIMP nsXPInstallManager::DownloadNext() { // We have one to download // --- figure out a temp file name - nsSpecialSystemDirectory temp(nsSpecialSystemDirectory::OS_TemporaryDirectory); + nsCOMPtr temp; + NS_WITH_SERVICE(nsIProperties, directoryService, NS_DIRECTORY_SERVICE_PROGID, &rv); + + directoryService->Get("system.OS_TemporaryDirectory", NS_GET_IID(nsIFile), getter_AddRefs(temp)); + PRInt32 pos = mItem->mURL.RFindChar('/'); if ( pos != -1 ) { nsString jarleaf; - mItem->mURL.Right( jarleaf, mItem->mURL.Length() - pos); - temp += jarleaf; + mItem->mURL.Right( jarleaf, mItem->mURL.Length() - (pos + 1)); + temp->Append(jarleaf.ToNewCString()); } else - temp += "xpinstall.xpi"; + temp->Append("xpinstall.xpi"); - temp.MakeUnique(); + MakeUnique(temp); //nsIFileXXX: need MakeUnique function. - rv = NS_NewFileSpecWithSpec( temp, getter_AddRefs(mItem->mFile) ); + mItem->mFile = temp; if (NS_SUCCEEDED(rv)) { // --- start the download @@ -421,18 +430,21 @@ void nsXPInstallManager::Shutdown() // proxy exists: we're being called from script thread mProxy->Close(); } +// else if (mDlg) +// mDlg->Close(); + +// mDlg = 0; // Clean up downloaded files nsXPITriggerItem* item; - nsFileSpec tmpSpec; + nsCOMPtr tmpSpec; for (PRUint32 i = 0; i < mTriggers->Size(); i++ ) { item = NS_STATIC_CAST(nsXPITriggerItem*, mTriggers->Get(i)); if ( item && item->mFile && !item->IsFileURL() ) { - item->mFile->GetFileSpec(&tmpSpec); - tmpSpec.Delete(PR_FALSE); + item->mFile->Delete(PR_FALSE); } } @@ -508,9 +520,27 @@ nsXPInstallManager::OnStartRequest(nsIChannel* channel, nsISupports *ctxt) NS_ASSERTION( mItem && mItem->mFile, "XPIMgr::OnStartRequest bad state"); if ( mItem && mItem->mFile ) { - rv = mItem->mFile->OpenStreamForWriting(); - } + NS_ASSERTION( !mItem->mOutStream, "Received double OnStartRequest from Necko"); + NS_DEFINE_CID(kFileTransportServiceCID, NS_FILETRANSPORTSERVICE_CID); + NS_WITH_SERVICE( nsIFileTransportService, fts, kFileTransportServiceCID, &rv ); + + if (NS_SUCCEEDED(rv) && !mItem->mOutStream) + { + nsCOMPtr outChannel; + + rv = fts->CreateTransport(mItem->mFile, + PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE, + 0664, + getter_AddRefs( outChannel)); + + if (NS_SUCCEEDED(rv)) + { + // Open output stream. + rv = outChannel->OpenOutputStream( getter_AddRefs( mItem->mOutStream ) ); + } + } + } return rv; } @@ -539,18 +569,24 @@ nsXPInstallManager::OnStopRequest(nsIChannel* channel, nsISupports *ctxt, rv = NS_ERROR_ILLEGAL_VALUE; } - if ( mItem->mFile ) - mItem->mFile->CloseStream(); + NS_ASSERTION( mItem, "Bad state in XPIManager"); + NS_ASSERTION( mItem->mOutStream, "XPIManager: output stream doesn't exist"); + if ( mItem && mItem->mOutStream ) + { + mItem->mOutStream->Close(); + mItem->mOutStream = nsnull; + } if (!NS_SUCCEEDED(rv)) { if ( mItem->mFile ) { + PRBool flagExists; nsFileSpec fspec; nsresult rv2 ; - rv2 = mItem->mFile->GetFileSpec(&fspec); - if ( NS_SUCCEEDED(rv2) && fspec.Exists() ) - fspec.Delete(0); + rv2 = mItem->mFile->Exists(&flagExists); + if (NS_SUCCEEDED(rv2) && flagExists) + mItem->mFile->Delete(PR_FALSE); mItem->mFile = 0; } @@ -571,9 +607,10 @@ nsXPInstallManager::OnDataAvailable(nsIChannel* channel, nsISupports *ctxt, PRUint32 length) { PRUint32 amt; - PRInt32 result; + //PRInt32 result; nsresult err; char buffer[8*1024]; + PRUint32 writeCount; if (mCancelled) { @@ -591,9 +628,10 @@ nsXPInstallManager::OnDataAvailable(nsIChannel* channel, nsISupports *ctxt, //printf("pIStream->Read Failed! %d", err); return err; } - err = mItem->mFile->Write( buffer, amt, &result); + err = mItem->mOutStream->Write( buffer, amt, &writeCount); + //err = mItem->mFile->Write( buffer, amt, &result); //printf("mItem->mFile->Write err:%d amt:%d result:%d\n", err, amt, result); - if (NS_FAILED(err) || result != (PRInt32)amt) + if (NS_FAILED(err) || writeCount != (PRInt32)amt) { //printf("mItem->mFile->Write Failed! err:%d amt:%d result:%d\n", err, amt, result); return NS_ERROR_FAILURE; diff --git a/mozilla/xpinstall/src/nsXPInstallManager.h b/mozilla/xpinstall/src/nsXPInstallManager.h index 794d904ba26..7ab80789fd4 100644 --- a/mozilla/xpinstall/src/nsXPInstallManager.h +++ b/mozilla/xpinstall/src/nsXPInstallManager.h @@ -99,6 +99,7 @@ class nsXPInstallManager : public nsIXPINotifier, nsCOMPtr mProxy; nsCOMPtr mStringBundle; + }; #endif diff --git a/mozilla/xpinstall/stub/xpistub.cpp b/mozilla/xpinstall/stub/xpistub.cpp index 063c54b258d..a7b9149aa7a 100644 --- a/mozilla/xpinstall/stub/xpistub.cpp +++ b/mozilla/xpinstall/stub/xpistub.cpp @@ -178,9 +178,16 @@ PR_PUBLIC_API(nsresult) XPI_Init( //-------------------------------------------------------------------- nsCOMPtr hook = do_QueryInterface(gXPI); nsFileSpec dirSpec( aProgramDir ); - nsCOMPtr iDirSpec; + nsCOMPtr iDirSpec; - NS_NewFileSpecWithSpec( dirSpec, getter_AddRefs(iDirSpec) ); + //NS_NewFileSpecWithSpec( dirSpec, getter_AddRefs(iDirSpec) ); +#if XP_MAC + NS_NewLocalFile(nsnull, getter_AddRefs(iDirSpec)); + nsCOMPtr macfile = do_QueryInterface(iDirSpec); + macfile->InitWithFSSpec(&aProgramDir); +#else + NS_NewLocalFile(aProgramDir, getter_AddRefs(iDirSpec)); +#endif if (hook && iDirSpec) hook->StubInitialize( iDirSpec ); @@ -238,14 +245,20 @@ PR_PUBLIC_API(PRInt32) XPI_Install( { nsresult rv = NS_ERROR_NULL_POINTER; nsString args; args.AssignWithConversion(aArgs); - nsCOMPtr iFile; + nsCOMPtr iFile; nsFileSpec file(aFile); nsFileURL URL(file); nsString URLstr; URLstr.AssignWithConversion(URL.GetURLString()); gInstallStatus = -322; // unique stub error code - - NS_NewFileSpecWithSpec( file, getter_AddRefs(iFile) ); + +#if XP_MAC + NS_NewLocalFile(nsnull, getter_AddRefs(iFile)); + nsCOMPtr macfile = do_QueryInterface(iFile); + macfile->InitWithFSSpec(&aFile); +#else + NS_NewLocalFile(aFile, getter_AddRefs(iFile)); +#endif if (iFile && gXPI) rv = gXPI->InstallJar( iFile, URLstr.GetUnicode(), args.GetUnicode(),