diff --git a/xpinstall/src/ScheduledTasks.cpp b/xpinstall/src/ScheduledTasks.cpp index 771e631a4aa..2904f8ec123 100644 --- a/xpinstall/src/ScheduledTasks.cpp +++ b/xpinstall/src/ScheduledTasks.cpp @@ -29,8 +29,162 @@ #include "nsFileStream.h" #include "nsInstall.h" // for error codes #include "prmem.h" +#include "ScheduledTasks.h" -REGERR DeleteFileLater(nsFileSpec& filename) +#ifdef _WINDOWS +#include +#include + +BOOL WIN32_IsMoveFileExBroken() +{ + /* the NT option MOVEFILE_DELAY_UNTIL_REBOOT is broken on + * Windows NT 3.51 Service Pack 4 and NT 4.0 before Service Pack 2 + */ + BOOL broken = FALSE; + OSVERSIONINFO osinfo; + + // they *all* appear broken--better to have one way that works. + return TRUE; + + osinfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); + if (GetVersionEx(&osinfo) && osinfo.dwPlatformId == VER_PLATFORM_WIN32_NT) + { + if ( osinfo.dwMajorVersion == 3 && osinfo.dwMinorVersion == 51 ) + { + if ( 0 == stricmp(osinfo.szCSDVersion,"Service Pack 4")) + { + broken = TRUE; + } + } + else if ( osinfo.dwMajorVersion == 4 ) + { + if (osinfo.szCSDVersion[0] == '\0' || + (0 == stricmp(osinfo.szCSDVersion,"Service Pack 1"))) + { + broken = TRUE; + } + } + } + + return broken; +} + + +PRInt32 DoWindowsReplaceExistingFileStuff(const char* currentName, const char* finalName) +{ + PRInt32 err = 0; + + char* final = strdup(finalName); + char* current = strdup(currentName); + + /* couldn't delete, probably in use. Schedule for later */ + DWORD dwVersion, dwWindowsMajorVersion; + + /* Get OS version info */ + dwVersion = GetVersion(); + dwWindowsMajorVersion = (DWORD)(LOBYTE(LOWORD(dwVersion))); + + /* Get build numbers for Windows NT or Win32s */ + + if (dwVersion < 0x80000000) // Windows NT + { + /* On Windows NT */ + if ( WIN32_IsMoveFileExBroken() ) + { + /* the MOVEFILE_DELAY_UNTIL_REBOOT option doesn't work on + * NT 3.51 SP4 or on NT 4.0 until SP2 + */ + struct stat statbuf; + PRBool nameFound = PR_FALSE; + char tmpname[_MAX_PATH]; + + strncpy( tmpname, finalName, _MAX_PATH ); + int len = strlen(tmpname); + while (!nameFound && len < _MAX_PATH ) + { + tmpname[len-1] = '~'; + tmpname[len] = '\0'; + if ( stat(tmpname, &statbuf) != 0 ) + nameFound = TRUE; + else + len++; + } + + if ( nameFound ) + { + if ( MoveFile( finalName, tmpname ) ) + { + if ( MoveFile( currentName, finalName ) ) + { + DeleteFileNowOrSchedule(nsFileSpec(tmpname)); + } + else + { + /* 2nd move failed, put old file back */ + MoveFile( tmpname, finalName ); + } + } + else + { + /* non-executable in use; schedule for later */ + return -1; // let the start registry stuff do our work! + } + } + } + else if ( MoveFileEx(currentName, finalName, MOVEFILE_DELAY_UNTIL_REBOOT) ) + { + err = 0; + } + } + else // Windows 95 or Win16 + { + /* + * Place an entry in the WININIT.INI file in the Windows directory + * to delete finalName and rename currentName to be finalName at reboot + */ + + int strlen; + char Src[_MAX_PATH]; // 8.3 name + char Dest[_MAX_PATH]; // 8.3 name + + strlen = GetShortPathName( (LPCTSTR)currentName, (LPTSTR)Src, (DWORD)sizeof(Src) ); + if ( strlen > 0 ) + { + free(current); + current = strdup(Src); + } + + strlen = GetShortPathName( (LPCTSTR) finalName, (LPTSTR) Dest, (DWORD) sizeof(Dest)); + if ( strlen > 0 ) + { + free(final); + final = strdup(Dest); + } + + /* NOTE: use OEM filenames! Even though it looks like a Windows + * .INI file, WININIT.INI is processed under DOS + */ + + AnsiToOem( final, final ); + AnsiToOem( current, current ); + + if ( WritePrivateProfileString( "Rename", final, current, "WININIT.INI" ) ) + err = 0; + } + + free(final); + free(current); + + return err; +} +#endif + + + + + + +REGERR DeleteFileNowOrSchedule(nsFileSpec& filename) { REGERR result = 0; @@ -45,12 +199,9 @@ REGERR DeleteFileLater(nsFileSpec& filename) { if (REGERR_OK == NR_RegAddKey( reg, ROOTKEY_PRIVATE, REG_DELETE_LIST_KEY, &newkey) ) { - nsPersistentFileDescriptor savethis(filename); - char* buffer = nsnull; - nsOutputStringStream s(buffer); - s << savethis; + // FIX should be using nsPersistentFileDescriptor!!! - result = NR_RegSetEntry( reg, newkey, "", REGTYPE_ENTRY_BYTES, buffer, strlen(buffer)); + result = NR_RegSetEntry( reg, newkey, (char*)(const char*)filename.GetNativePathCString(), REGTYPE_ENTRY_FILE, nsnull, 0); if (result == REGERR_OK) result = nsInstall::REBOOT_NEEDED; } @@ -63,7 +214,7 @@ REGERR DeleteFileLater(nsFileSpec& filename) } /* tmp file is the bad one that we want to replace with target. */ -REGERR ReplaceFileLater(nsFileSpec& replacementFile, nsFileSpec& doomedFile ) +REGERR ReplaceFileNowOrSchedule(nsFileSpec& replacementFile, nsFileSpec& doomedFile ) { REGERR result = 0; @@ -82,13 +233,20 @@ REGERR ReplaceFileLater(nsFileSpec& replacementFile, nsFileSpec& doomedFile ) doomedFile.GetParent(parentofFinalFile); result = replacementFile.Move(parentofFinalFile); - - char* leafName = doomedFile.GetLeafName(); - replacementFile.Rename(leafName); - nsCRT::free(leafName); + if ( NS_SUCCEEDED(result) ) + { + char* leafName = doomedFile.GetLeafName(); + replacementFile.Rename(leafName); + nsCRT::free(leafName); + } } else { +#ifdef _WINDOWS + if (DoWindowsReplaceExistingFileStuff(replacementFile.GetNativePathCString(), doomedFile.GetNativePathCString()) == 0) + return 0; +#endif + RKEY newkey; HREG reg; @@ -97,22 +255,10 @@ REGERR ReplaceFileLater(nsFileSpec& replacementFile, nsFileSpec& doomedFile ) result = NR_RegAddKey( reg, ROOTKEY_PRIVATE, REG_REPLACE_LIST_KEY, &newkey); if ( result == REGERR_OK ) { - nsPersistentFileDescriptor tempDesc(replacementFile); - nsPersistentFileDescriptor targDesc(doomedFile); - - char* tempBuffer = nsnull; - char* targBuffer = nsnull; - - nsOutputStringStream tempStream(tempBuffer); - nsOutputStringStream targStream(targBuffer); - - tempStream << tempDesc; - targStream << targDesc; - - result = NR_RegSetEntry( reg, newkey, tempBuffer, REGTYPE_ENTRY_BYTES, targBuffer, strlen(targBuffer)); + char* replacementFileName = (char*)(const char*)replacementFile.GetNativePathCString(); + result = NR_RegSetEntry( reg, newkey, (char*)(const char*)doomedFile.GetNativePathCString(), REGTYPE_ENTRY_FILE, replacementFileName, strlen(replacementFileName)); if (result == REGERR_OK) result = nsInstall::REBOOT_NEEDED; - } NR_RegClose(reg); @@ -144,16 +290,11 @@ void DeleteScheduledFiles(void) /* perform scheduled file deletions and replacements (PC only) */ if (REGERR_OK == NR_RegGetKey(reg, ROOTKEY_PRIVATE, REG_DELETE_LIST_KEY,&key)) { - char buf[MAXREGNAMELEN]; // what about the mac? FIX + char buf[MAXREGNAMELEN]; while (REGERR_OK == NR_RegEnumEntries(reg, key, &state, buf, sizeof(buf), NULL )) { - - nsPersistentFileDescriptor doomedDesc; - nsInputStringStream tempStream(buf); - tempStream >> doomedDesc; - - nsFileSpec doomedFile(doomedDesc); + nsFileSpec doomedFile(buf); doomedFile.Delete(PR_FALSE); @@ -193,12 +334,7 @@ void ReplaceScheduledFiles(void) while (REGERR_OK == NR_RegEnumEntries(reg, key, &state, tmpfile, sizeof(tmpfile), NULL )) { - - nsPersistentFileDescriptor doomedDesc; - nsInputStringStream tempStream(tmpfile); - tempStream >> doomedDesc; - - nsFileSpec replaceFile(doomedDesc); + nsFileSpec replaceFile(tmpfile); if (! replaceFile.Exists() ) { @@ -211,11 +347,7 @@ void ReplaceScheduledFiles(void) } else { - nsPersistentFileDescriptor targetDesc; - nsInputStringStream anotherStream(target); - anotherStream >> targetDesc; - - nsFileSpec targetFile(targetDesc); + nsFileSpec targetFile(target); targetFile.Delete(PR_FALSE); diff --git a/xpinstall/src/ScheduledTasks.h b/xpinstall/src/ScheduledTasks.h index 860d84c4f0c..39d5361485e 100644 --- a/xpinstall/src/ScheduledTasks.h +++ b/xpinstall/src/ScheduledTasks.h @@ -32,8 +32,8 @@ #include "nsFileSpec.h" -REGERR DeleteFileLater(nsFileSpec& filename); -REGERR ReplaceFileLater(nsFileSpec& tmpfile, nsFileSpec& target ); +REGERR DeleteFileNowOrSchedule(nsFileSpec& filename); +REGERR ReplaceFileNowOrSchedule(nsFileSpec& tmpfile, nsFileSpec& target ); extern "C" void PerformScheduledTasks(void *data); diff --git a/xpinstall/src/nsInstall.cpp b/xpinstall/src/nsInstall.cpp index 5f83e8a1818..b532dc44bfa 100644 --- a/xpinstall/src/nsInstall.cpp +++ b/xpinstall/src/nsInstall.cpp @@ -48,9 +48,7 @@ #include "nsInstall.h" #include "nsInstallFolder.h" - -#include "nsIDOMInstallVersion.h" - +#include "nsInstallVersion.h" #include "nsInstallFile.h" #include "nsInstallDelete.h" #include "nsInstallExecute.h" @@ -130,6 +128,7 @@ nsInstallInfo::~nsInstallInfo() { DeleteVector(mFromURLs); DeleteVector(mLocalFiles); + VR_Close(); } nsString& @@ -211,7 +210,7 @@ nsInstall::~nsInstall() delete mVersionInfo; } - +#ifdef _WINDOWS nsInstall::SetScriptObject(void *aScriptObject) { mScriptObject = (JSObject*) aScriptObject; @@ -241,6 +240,7 @@ nsInstall::RetrieveWinProfilePrototype() { return mWinProfileObject; } +#endif PRInt32 nsInstall::GetUserPackageName(nsString& aUserPackageName) @@ -306,21 +306,20 @@ nsInstall::AddDirectory(const nsString& aRegName, return NS_OK; } - nsString* qualifiedRegName = nsnull; + nsString qualifiedRegName; if ( aRegName == "" || aRegName == "null") { // Default subName = location in jar file - qualifiedRegName = GetQualifiedRegName( aJarSource ); + *aReturn = GetQualifiedRegName( aJarSource, qualifiedRegName); } else { - qualifiedRegName = GetQualifiedRegName( aRegName ); + *aReturn = GetQualifiedRegName( aRegName, qualifiedRegName ); } - if (qualifiedRegName == nsnull) + if (*aReturn != SUCCESS) { - *aReturn = SaveError( BAD_PACKAGE_NAME ); return NS_OK; } @@ -331,7 +330,6 @@ nsInstall::AddDirectory(const nsString& aRegName, subdirectory.Append("/"); } - PRBool bInstall; nsVector *paths = new nsVector(); @@ -347,258 +345,48 @@ nsInstall::AddDirectory(const nsString& aRegName, for (int i=0; i< pathsUpperBound; i++) { - nsInstallVersion* newVersion = new nsInstallVersion(); - - nsString *fullRegName = new nsString(*qualifiedRegName); - fullRegName->Append("/"); - fullRegName->Append(*(nsString *)paths->Get(i)); + nsString *thisPath = (nsString *)paths->Get(i); + + nsString newJarSource = aJarSource; + newJarSource += "/"; + newJarSource += *thisPath; - char* fullRegNameCString = fullRegName->ToNewCString(); + nsString fullRegName = qualifiedRegName; + fullRegName += "/"; + fullRegName += *thisPath; - if ( (aForceMode == PR_FALSE) && (aVersion == "null") && - (VR_ValidateComponent(fullRegNameCString) == 0)) + + nsString newSubDir; + + if (subdirectory != "") { - VERSION versionStruct; - VR_GetVersion( fullRegNameCString, &versionStruct); - - //fix: when we have overloading! - nsInstallVersion* oldVer = new nsInstallVersion(); - oldVer->Init(versionStruct.major, - versionStruct.minor, - versionStruct.release, - versionStruct.build); - - - newVersion->Init(aVersion); - - PRInt32 areTheyEqual; - newVersion->CompareTo(oldVer, &areTheyEqual); - delete newVersion; - - bInstall = ( areTheyEqual > 0 ); - - if (oldVer) - delete oldVer; + newSubDir = subdirectory; + } + newSubDir += *thisPath; + + ie = new nsInstallFile( this, + fullRegName, + aVersion, + newJarSource, + aFolder, + newSubDir, + aForceMode, + &result); + + if (result == nsInstall::SUCCESS) + { + result = ScheduleForInstall( ie ); } else { - // file doesn't exist or "forced" install - bInstall = PR_TRUE; - } - - delete [] fullRegNameCString; - - if (bInstall) - { - nsString *newJarSource = new nsString(aJarSource); - newJarSource->Append("/"); - newJarSource->Append(*(nsString *)paths->Get(i)); - - nsString* newSubDir; - - if (subdirectory != "") - { - newSubDir = new nsString(subdirectory); - newSubDir->Append(*(nsString*)paths->Get(i)); - } - else - { - newSubDir = new nsString(*(nsString*)paths->Get(i)); - } - - ie = new nsInstallFile( this, - *fullRegName, - newVersion, - *newJarSource, - aFolder, - *newSubDir, - aForceMode, - &result); - delete fullRegName; - delete newJarSource; - delete newSubDir; - delete newVersion; - - if (result == nsInstall::SUCCESS) - { - result = ScheduleForInstall( ie ); - } - else - { - delete ie; - } + delete ie; } + } nsInstallInfo::DeleteVector(paths); - if (qualifiedRegName != nsnull) - delete qualifiedRegName; - - *aReturn = SaveError( result ); - return NS_OK; -} - -PRInt32 -nsInstall::AddDirectory(const nsString& aRegName, - nsIDOMInstallVersion* aVersion, - const nsString& aJarSource, - const nsString& aFolder, - const nsString& aSubdir, - PRBool aForceMode, - PRInt32* aReturn) -{ - nsInstallFile* ie = nsnull; - PRInt32 result; - nsString aVersionStr; - - if ( aJarSource == "null" || aFolder == "null") - { - *aReturn = SaveError(nsInstall::INVALID_ARGUMENTS); - return NS_OK; - } - - result = SanityCheck(); - - if (result != nsInstall::SUCCESS) - { - *aReturn = SaveError( result ); - return NS_OK; - } - - nsString* qualifiedRegName = nsnull; - - if ( aRegName == "" ) - { - // Default subName = location in jar file - qualifiedRegName = GetQualifiedRegName( aJarSource ); - } - else - { - qualifiedRegName = GetQualifiedRegName( aRegName ); - } - - if (qualifiedRegName == nsnull) - { - *aReturn = SaveError( BAD_PACKAGE_NAME ); - return NS_OK; - } - - nsString subdirectory(aSubdir); - - if (subdirectory != "") - { - subdirectory.Append("/"); - } - - aVersion->ToString(aVersionStr); - - PRBool bInstall; - - nsVector *paths = new nsVector(); - - result = ExtractDirEntries(aJarSource, paths); - - PRInt32 pathsUpperBound = paths->GetUpperBound(); - - if (result != nsInstall::SUCCESS) - { - *aReturn = SaveError( result ); - return NS_OK; - } - - for (int i=0; i< pathsUpperBound; i++) - { - nsInstallVersion* newVersion = new nsInstallVersion(); - - nsString *fullRegName = new nsString(*qualifiedRegName); - fullRegName->Append("/"); - fullRegName->Append(*(nsString *)paths->Get(i)); - - char* fullRegNameCString = fullRegName->ToNewCString(); - - if ( (aForceMode == PR_FALSE) && (aVersionStr == "null") && - (VR_ValidateComponent(fullRegNameCString) == 0)) - { - VERSION versionStruct; - VR_GetVersion( fullRegNameCString, &versionStruct); - - //fix: when we have overloading! - nsInstallVersion* oldVer = new nsInstallVersion(); - oldVer->Init(versionStruct.major, - versionStruct.minor, - versionStruct.release, - versionStruct.build); - - - newVersion->Init(aVersionStr); - - PRInt32 areTheyEqual; - newVersion->CompareTo(oldVer, &areTheyEqual); - delete newVersion; - - bInstall = ( areTheyEqual > 0 ); - - if (oldVer) - delete oldVer; - - } - else - { - // file doesn't exist or "forced" install - bInstall = PR_TRUE; - } - - delete [] fullRegNameCString; - - if (bInstall) - { - nsString *newJarSource = new nsString(aJarSource); - newJarSource->Append("/"); - newJarSource->Append(*(nsString *)paths->Get(i)); - - nsString* newSubDir; - - if (subdirectory != "") - { - newSubDir = new nsString(subdirectory); - newSubDir->Append(*(nsString*)paths->Get(i)); - } - else - { - newSubDir = new nsString(*(nsString*)paths->Get(i)); - } - - ie = new nsInstallFile( this, - *fullRegName, - newVersion, - *newJarSource, - aFolder, - *newSubDir, - aForceMode, - &result); - delete fullRegName; - delete newJarSource; - delete newSubDir; - delete newVersion; - - if (result == nsInstall::SUCCESS) - { - result = ScheduleForInstall( ie ); - } - else - { - delete ie; - } - } - } - - nsInstallInfo::DeleteVector(paths); - - if (qualifiedRegName != nsnull) - delete qualifiedRegName; - *aReturn = SaveError( result ); return NS_OK; } @@ -611,323 +399,13 @@ nsInstall::AddDirectory(const nsString& aRegName, const nsString& aSubdir, PRInt32* aReturn) { - nsInstallFile* ie = nsnull; - PRInt32 result; - - // defaulting aForceMode to PR_FALSE; - PRBool aForceMode = PR_FALSE; - - if ( aJarSource == "null" || aFolder == "null") - { - *aReturn = SaveError(nsInstall::INVALID_ARGUMENTS); - return NS_OK; - } - - result = SanityCheck(); - - if (result != nsInstall::SUCCESS) - { - *aReturn = SaveError( result ); - return NS_OK; - } - - nsString* qualifiedRegName = nsnull; - - if ( aRegName == "" ) - { - // Default subName = location in jar file - qualifiedRegName = GetQualifiedRegName( aJarSource ); - } - else - { - qualifiedRegName = GetQualifiedRegName( aRegName ); - } - - if (qualifiedRegName == nsnull) - { - *aReturn = SaveError( BAD_PACKAGE_NAME ); - return NS_OK; - } - - nsString subdirectory(aSubdir); - - if (subdirectory != "") - { - subdirectory.Append("/"); - } - - PRBool bInstall; - - nsVector *paths = new nsVector(); - - result = ExtractDirEntries(aJarSource, paths); - - PRInt32 pathsUpperBound = paths->GetUpperBound(); - - if (result != nsInstall::SUCCESS) - { - *aReturn = SaveError( result ); - return NS_OK; - } - - for (int i=0; i< pathsUpperBound; i++) - { - nsInstallVersion* newVersion = new nsInstallVersion(); - - nsString *fullRegName = new nsString(*qualifiedRegName); - fullRegName->Append("/"); - fullRegName->Append(*(nsString *)paths->Get(i)); - - char* fullRegNameCString = fullRegName->ToNewCString(); - - if ( (aForceMode == PR_FALSE) && (aVersion == "null") && - (VR_ValidateComponent(fullRegNameCString) == 0)) - { - VERSION versionStruct; - VR_GetVersion( fullRegNameCString, &versionStruct); - - //fix: when we have overloading! - nsInstallVersion* oldVer = new nsInstallVersion(); - oldVer->Init(versionStruct.major, - versionStruct.minor, - versionStruct.release, - versionStruct.build); - - - newVersion->Init(aVersion); - - PRInt32 areTheyEqual; - newVersion->CompareTo(oldVer, &areTheyEqual); - delete newVersion; - - bInstall = ( areTheyEqual > 0 ); - - if (oldVer) - delete oldVer; - - } - else - { - // file doesn't exist or "forced" install - bInstall = PR_TRUE; - } - - delete [] fullRegNameCString; - - if (bInstall) - { - nsString *newJarSource = new nsString(aJarSource); - newJarSource->Append("/"); - newJarSource->Append(*(nsString *)paths->Get(i)); - - nsString* newSubDir; - - if (subdirectory != "") - { - newSubDir = new nsString(subdirectory); - newSubDir->Append(*(nsString*)paths->Get(i)); - } - else - { - newSubDir = new nsString(*(nsString*)paths->Get(i)); - } - - ie = new nsInstallFile( this, - *fullRegName, - newVersion, - *newJarSource, - aFolder, - *newSubDir, - aForceMode, - &result); - delete fullRegName; - delete newJarSource; - delete newSubDir; - delete newVersion; - - if (result == nsInstall::SUCCESS) - { - result = ScheduleForInstall( ie ); - } - else - { - delete ie; - } - } - } - - nsInstallInfo::DeleteVector(paths); - - if (qualifiedRegName != nsnull) - delete qualifiedRegName; - - *aReturn = SaveError( result ); - return NS_OK; -} - -PRInt32 -nsInstall::AddDirectory(const nsString& aRegName, - nsIDOMInstallVersion* aVersion, - const nsString& aJarSource, - const nsString& aFolder, - const nsString& aSubdir, - PRInt32* aReturn) -{ - nsInstallFile* ie = nsnull; - PRInt32 result; - nsString aVersionStr; - - // defaulting aForceMode to PR_FALSE; - PRBool aForceMode = PR_FALSE; - - if ( aJarSource == "null" || aFolder == "null") - { - *aReturn = SaveError(nsInstall::INVALID_ARGUMENTS); - return NS_OK; - } - - result = SanityCheck(); - - if (result != nsInstall::SUCCESS) - { - *aReturn = SaveError( result ); - return NS_OK; - } - - nsString* qualifiedRegName = nsnull; - - if ( aRegName == "" ) - { - // Default subName = location in jar file - qualifiedRegName = GetQualifiedRegName( aJarSource ); - } - else - { - qualifiedRegName = GetQualifiedRegName( aRegName ); - } - - if (qualifiedRegName == nsnull) - { - *aReturn = SaveError( BAD_PACKAGE_NAME ); - return NS_OK; - } - - nsString subdirectory(aSubdir); - - if (subdirectory != "") - { - subdirectory.Append("/"); - } - - aVersion->ToString(aVersionStr); - - PRBool bInstall; - - nsVector *paths = new nsVector(); - - result = ExtractDirEntries(aJarSource, paths); - - PRInt32 pathsUpperBound = paths->GetUpperBound(); - - if (result != nsInstall::SUCCESS) - { - *aReturn = SaveError( result ); - return NS_OK; - } - - for (int i=0; i< pathsUpperBound; i++) - { - nsInstallVersion* newVersion = new nsInstallVersion(); - - nsString *fullRegName = new nsString(*qualifiedRegName); - fullRegName->Append("/"); - fullRegName->Append(*(nsString *)paths->Get(i)); - - char* fullRegNameCString = fullRegName->ToNewCString(); - - if ( (aForceMode == PR_FALSE) && (aVersionStr == "null") && - (VR_ValidateComponent(fullRegNameCString) == 0)) - { - VERSION versionStruct; - VR_GetVersion( fullRegNameCString, &versionStruct); - - //fix: when we have overloading! - nsInstallVersion* oldVer = new nsInstallVersion(); - oldVer->Init(versionStruct.major, - versionStruct.minor, - versionStruct.release, - versionStruct.build); - - - newVersion->Init(aVersionStr); - - PRInt32 areTheyEqual; - newVersion->CompareTo(oldVer, &areTheyEqual); - delete newVersion; - - bInstall = ( areTheyEqual > 0 ); - - if (oldVer) - delete oldVer; - - } - else - { - // file doesn't exist or "forced" install - bInstall = PR_TRUE; - } - - delete [] fullRegNameCString; - - if (bInstall) - { - nsString *newJarSource = new nsString(aJarSource); - newJarSource->Append("/"); - newJarSource->Append(*(nsString *)paths->Get(i)); - - nsString* newSubDir; - - if (subdirectory != "") - { - newSubDir = new nsString(subdirectory); - newSubDir->Append(*(nsString*)paths->Get(i)); - } - else - { - newSubDir = new nsString(*(nsString*)paths->Get(i)); - } - - ie = new nsInstallFile( this, - *fullRegName, - newVersion, - *newJarSource, - aFolder, - *newSubDir, - aForceMode, - &result); - delete fullRegName; - delete newJarSource; - delete newSubDir; - delete newVersion; - - if (result == nsInstall::SUCCESS) - { - result = ScheduleForInstall( ie ); - } - else - { - delete ie; - } - } - } - - nsInstallInfo::DeleteVector(paths); - - if (qualifiedRegName != nsnull) - delete qualifiedRegName; - - *aReturn = SaveError( result ); - return NS_OK; + return AddDirectory(aRegName, + aVersion, + aJarSource, + aFolder, + aSubdir, + PR_FALSE, + aReturn); } PRInt32 @@ -937,324 +415,28 @@ nsInstall::AddDirectory(const nsString& aRegName, const nsString& aSubdir, PRInt32* aReturn) { - nsInstallFile* ie = nsnull; - PRInt32 result; - - // defaulting aForceMode to PR_FALSE; - PRBool aForceMode = PR_FALSE; - // defaulting aVersion to "null"; - nsString aVersion = "null"; - - if ( aJarSource == "null" || aFolder == "null") - { - *aReturn = SaveError(nsInstall::INVALID_ARGUMENTS); - return NS_OK; - } - - result = SanityCheck(); - - if (result != nsInstall::SUCCESS) - { - *aReturn = SaveError( result ); - return NS_OK; - } - - nsString* qualifiedRegName = nsnull; - - if ( aRegName == "" ) - { - // Default subName = location in jar file - qualifiedRegName = GetQualifiedRegName( aJarSource ); - } - else - { - qualifiedRegName = GetQualifiedRegName( aRegName ); - } - - if (qualifiedRegName == nsnull) - { - *aReturn = SaveError( BAD_PACKAGE_NAME ); - return NS_OK; - } - - nsString subdirectory(aSubdir); - - if (subdirectory != "") - { - subdirectory.Append("/"); - } - - PRBool bInstall; - - nsVector *paths = new nsVector(); - - result = ExtractDirEntries(aJarSource, paths); - - PRInt32 pathsUpperBound = paths->GetUpperBound(); - - if (result != nsInstall::SUCCESS) - { - *aReturn = SaveError( result ); - return NS_OK; - } - - for (int i=0; i< pathsUpperBound; i++) - { - nsInstallVersion* newVersion = new nsInstallVersion(); - - nsString *fullRegName = new nsString(*qualifiedRegName); - fullRegName->Append("/"); - fullRegName->Append(*(nsString *)paths->Get(i)); - - char* fullRegNameCString = fullRegName->ToNewCString(); - - if ( (aForceMode == PR_FALSE) && (aVersion == "null") && - (VR_ValidateComponent(fullRegNameCString) == 0)) - { - VERSION versionStruct; - VR_GetVersion( fullRegNameCString, &versionStruct); - - //fix: when we have overloading! - nsInstallVersion* oldVer = new nsInstallVersion(); - oldVer->Init(versionStruct.major, - versionStruct.minor, - versionStruct.release, - versionStruct.build); - - - newVersion->Init(aVersion); - - PRInt32 areTheyEqual; - newVersion->CompareTo(oldVer, &areTheyEqual); - delete newVersion; - - bInstall = ( areTheyEqual > 0 ); - - if (oldVer) - delete oldVer; - - } - else - { - // file doesn't exist or "forced" install - bInstall = PR_TRUE; - } - - delete [] fullRegNameCString; - - if (bInstall) - { - nsString *newJarSource = new nsString(aJarSource); - newJarSource->Append("/"); - newJarSource->Append(*(nsString *)paths->Get(i)); - - nsString* newSubDir; - - if (subdirectory != "") - { - newSubDir = new nsString(subdirectory); - newSubDir->Append(*(nsString*)paths->Get(i)); - } - else - { - newSubDir = new nsString(*(nsString*)paths->Get(i)); - } - - ie = new nsInstallFile( this, - *fullRegName, - newVersion, - *newJarSource, - aFolder, - *newSubDir, - aForceMode, - &result); - delete fullRegName; - delete newJarSource; - delete newSubDir; - delete newVersion; - - if (result == nsInstall::SUCCESS) - { - result = ScheduleForInstall( ie ); - } - else - { - delete ie; - } - } - } - - nsInstallInfo::DeleteVector(paths); - - if (qualifiedRegName != nsnull) - delete qualifiedRegName; - - *aReturn = SaveError( result ); - return NS_OK; + return AddDirectory(aRegName, + "", + aJarSource, + aFolder, + aSubdir, + PR_FALSE, + aReturn); } PRInt32 nsInstall::AddDirectory(const nsString& aJarSource, PRInt32* aReturn) { - nsInstallFile* ie = nsnull; - PRInt32 result; + return AddDirectory("", + "", + aJarSource, + "", + "", + PR_FALSE, + aReturn); - // defaulting aForceMode to PR_FALSE; - PRBool aForceMode = PR_FALSE; - // defaulting aVersion to "null"; - nsString aVersion = "null"; -// fix: aFolder should not default to "null". - nsString aFolder = "null"; - nsString aSubdir = ""; - nsString aRegName = ""; - - if ( aJarSource == "null" || aFolder == "null") - { - *aReturn = SaveError(nsInstall::INVALID_ARGUMENTS); - return NS_OK; - } - - result = SanityCheck(); - - if (result != nsInstall::SUCCESS) - { - *aReturn = SaveError( result ); - return NS_OK; - } - - nsString* qualifiedRegName = nsnull; - - if ( aRegName == "" ) - { - // Default subName = location in jar file - qualifiedRegName = GetQualifiedRegName( aJarSource ); - } - else - { - qualifiedRegName = GetQualifiedRegName( aRegName ); - } - - if (qualifiedRegName == nsnull) - { - *aReturn = SaveError( BAD_PACKAGE_NAME ); - return NS_OK; - } - - nsString subdirectory(aSubdir); - - if (subdirectory != "") - { - subdirectory.Append("/"); - } - - PRBool bInstall; - - nsVector *paths = new nsVector(); - - result = ExtractDirEntries(aJarSource, paths); - - PRInt32 pathsUpperBound = paths->GetUpperBound(); - - if (result != nsInstall::SUCCESS) - { - *aReturn = SaveError( result ); - return NS_OK; - } - - for (int i=0; i< pathsUpperBound; i++) - { - nsInstallVersion* newVersion = new nsInstallVersion(); - - nsString *fullRegName = new nsString(*qualifiedRegName); - fullRegName->Append("/"); - fullRegName->Append(*(nsString *)paths->Get(i)); - - char* fullRegNameCString = fullRegName->ToNewCString(); - - if ( (aForceMode == PR_FALSE) && (aVersion == "null") && - (VR_ValidateComponent(fullRegNameCString) == 0)) - { - VERSION versionStruct; - VR_GetVersion( fullRegNameCString, &versionStruct); - - //fix: when we have overloading! - nsInstallVersion* oldVer = new nsInstallVersion(); - oldVer->Init(versionStruct.major, - versionStruct.minor, - versionStruct.release, - versionStruct.build); - - - newVersion->Init(aVersion); - - PRInt32 areTheyEqual; - newVersion->CompareTo(oldVer, &areTheyEqual); - delete newVersion; - - bInstall = ( areTheyEqual > 0 ); - - if (oldVer) - delete oldVer; - - } - else - { - // file doesn't exist or "forced" install - bInstall = PR_TRUE; - } - - delete [] fullRegNameCString; - - if (bInstall) - { - nsString *newJarSource = new nsString(aJarSource); - newJarSource->Append("/"); - newJarSource->Append(*(nsString *)paths->Get(i)); - - nsString* newSubDir; - - if (subdirectory != "") - { - newSubDir = new nsString(subdirectory); - newSubDir->Append(*(nsString*)paths->Get(i)); - } - else - { - newSubDir = new nsString(*(nsString*)paths->Get(i)); - } - - ie = new nsInstallFile( this, - *fullRegName, - newVersion, - *newJarSource, - aFolder, - *newSubDir, - aForceMode, - &result); - delete fullRegName; - delete newJarSource; - delete newSubDir; - delete newVersion; - - if (result == nsInstall::SUCCESS) - { - result = ScheduleForInstall( ie ); - } - else - { - delete ie; - } - } - } - - nsInstallInfo::DeleteVector(paths); - - if (qualifiedRegName != nsnull) - delete qualifiedRegName; - - *aReturn = SaveError( result ); - return NS_OK; + } PRInt32 @@ -1267,7 +449,7 @@ nsInstall::AddSubcomponent(const nsString& aRegName, PRInt32* aReturn) { nsInstallFile* ie; - nsString* qualifiedRegName = nsnull; + nsString qualifiedRegName; PRInt32 errcode = nsInstall::SUCCESS; @@ -1286,204 +468,39 @@ nsInstall::AddSubcomponent(const nsString& aRegName, } - if ( aRegName == "" ) + if ( aRegName == "" || aRegName == "null") { // Default subName = location in jar file - qualifiedRegName = GetQualifiedRegName( aJarSource ); + *aReturn = GetQualifiedRegName( aJarSource, qualifiedRegName); } else { - qualifiedRegName = GetQualifiedRegName( aRegName ); + *aReturn = GetQualifiedRegName( aRegName, qualifiedRegName ); } - if (qualifiedRegName == nsnull) + if (*aReturn != SUCCESS) { - *aReturn = SaveError( BAD_PACKAGE_NAME ); return NS_OK; } - /* Check for existence of the newer version */ - - nsInstallVersion *newVersion = new nsInstallVersion(); - newVersion->Init(aVersion); + + ie = new nsInstallFile( this, + qualifiedRegName, + aVersion, + aJarSource, + aFolder, + aTargetName, + aForceMode, + &errcode ); - PRBool versionNewer = PR_FALSE; - char* qualifiedRegNameString = qualifiedRegName->ToNewCString(); - - if ( (aForceMode == PR_FALSE ) && (aVersion != "null") && ( VR_ValidateComponent( qualifiedRegNameString ) == 0 ) ) + if (errcode == nsInstall::SUCCESS) { - VERSION versionStruct; - - VR_GetVersion( qualifiedRegNameString, &versionStruct ); - - nsInstallVersion* oldVersion = new nsInstallVersion(); -// FIX. Once we move to XPConnect, we can have parameterized constructors. - oldVersion->Init(versionStruct.major, - versionStruct.minor, - versionStruct.release, - versionStruct.build); - - PRInt32 areTheyEqual; - newVersion->CompareTo((nsInstallVersion*)oldVersion, &areTheyEqual); - - if ( areTheyEqual != nsIDOMInstallVersion::EQUAL ) - versionNewer = PR_TRUE; - - if ( oldVersion ) - delete oldVersion; + errcode = ScheduleForInstall( ie ); } - else + else { - versionNewer = PR_TRUE; - } - - - if (qualifiedRegNameString != nsnull) - delete [] qualifiedRegNameString; - - if (versionNewer) - { - ie = new nsInstallFile( this, - *qualifiedRegName, - newVersion, - aJarSource, - aFolder, - aTargetName, - aForceMode, - &errcode ); - - if (errcode == nsInstall::SUCCESS) - { - errcode = ScheduleForInstall( ie ); - } - else - { - delete ie; - } - } - - if (qualifiedRegName != nsnull) - delete qualifiedRegName; - - if (newVersion != nsnull) - delete newVersion; - - *aReturn = SaveError( errcode ); - return NS_OK; -} - -PRInt32 -nsInstall::AddSubcomponent(const nsString& aRegName, - nsIDOMInstallVersion* aVersion, - const nsString& aJarSource, - const nsString& aFolder, - const nsString& aTargetName, - PRBool aForceMode, - PRInt32* aReturn) -{ - nsInstallFile* ie; - nsString* qualifiedRegName = nsnull; - nsString aVersionStr; - - PRInt32 errcode = nsInstall::SUCCESS; - - if ( aJarSource == "null" || aFolder == "null") - { - *aReturn = SaveError( nsInstall::INVALID_ARGUMENTS ); - return NS_OK; - } - - PRInt32 result = SanityCheck(); - - if (result != nsInstall::SUCCESS) - { - *aReturn = SaveError( result ); - return NS_OK; - } - - - if ( aRegName == "" ) - { - // Default subName = location in jar file - qualifiedRegName = GetQualifiedRegName( aJarSource ); - } - else - { - qualifiedRegName = GetQualifiedRegName( aRegName ); - } - - if (qualifiedRegName == nsnull) - { - *aReturn = SaveError( BAD_PACKAGE_NAME ); - return NS_OK; - } - - /* Check for existence of the newer version */ - - nsInstallVersion *newVersion = new nsInstallVersion(); - aVersion->ToString(aVersionStr); - newVersion->Init(aVersionStr); - - PRBool versionNewer = PR_FALSE; - char* qualifiedRegNameString = qualifiedRegName->ToNewCString(); - - if ( (aForceMode == PR_FALSE ) && (aVersionStr != "null") && ( VR_ValidateComponent( qualifiedRegNameString ) == 0 ) ) - { - VERSION versionStruct; - - VR_GetVersion( qualifiedRegNameString, &versionStruct ); - - nsInstallVersion* oldVersion = new nsInstallVersion(); -// FIX. Once we move to XPConnect, we can have parameterized constructors. - oldVersion->Init(versionStruct.major, - versionStruct.minor, - versionStruct.release, - versionStruct.build); - - PRInt32 areTheyEqual; - newVersion->CompareTo((nsInstallVersion*)oldVersion, &areTheyEqual); - - if ( areTheyEqual != nsIDOMInstallVersion::EQUAL ) - versionNewer = PR_TRUE; - - if ( oldVersion ) - delete oldVersion; - } - else - { - versionNewer = PR_TRUE; - } - - - if (qualifiedRegNameString != nsnull) - delete [] qualifiedRegNameString; - - if (versionNewer) - { - ie = new nsInstallFile( this, - *qualifiedRegName, - newVersion, - aJarSource, - aFolder, - aTargetName, - aForceMode, - &errcode ); - - if (errcode == nsInstall::SUCCESS) - { - errcode = ScheduleForInstall( ie ); - } - else - { - delete ie; - } - } - - if (qualifiedRegName != nsnull) - delete qualifiedRegName; - - if (newVersion != nsnull) - delete newVersion; + delete ie; + } *aReturn = SaveError( errcode ); return NS_OK; @@ -1497,228 +514,13 @@ nsInstall::AddSubcomponent(const nsString& aRegName, const nsString& aTargetName, PRInt32* aReturn) { - nsInstallFile* ie; - nsString* qualifiedRegName = nsnull; - PRBool aForceMode = PR_FALSE; - - PRInt32 errcode = nsInstall::SUCCESS; - - if ( aJarSource == "null" || aFolder == "null") - { - *aReturn = SaveError( nsInstall::INVALID_ARGUMENTS ); - return NS_OK; - } - - PRInt32 result = SanityCheck(); - - if (result != nsInstall::SUCCESS) - { - *aReturn = SaveError( result ); - return NS_OK; - } - - - if ( aRegName == "" ) - { - // Default subName = location in jar file - qualifiedRegName = GetQualifiedRegName( aJarSource ); - } - else - { - qualifiedRegName = GetQualifiedRegName( aRegName ); - } - - if (qualifiedRegName == nsnull) - { - *aReturn = SaveError( BAD_PACKAGE_NAME ); - return NS_OK; - } - - /* Check for existence of the newer version */ - - nsInstallVersion *newVersion = new nsInstallVersion(); - newVersion->Init(aVersion); - - PRBool versionNewer = PR_FALSE; - char* qualifiedRegNameString = qualifiedRegName->ToNewCString(); - - if ( (aForceMode == PR_FALSE ) && (aVersion != "null") && ( VR_ValidateComponent( qualifiedRegNameString ) == 0 ) ) - { - VERSION versionStruct; - - VR_GetVersion( qualifiedRegNameString, &versionStruct ); - - nsInstallVersion* oldVersion = new nsInstallVersion(); -// FIX. Once we move to XPConnect, we can have parameterized constructors. - oldVersion->Init(versionStruct.major, - versionStruct.minor, - versionStruct.release, - versionStruct.build); - - PRInt32 areTheyEqual; - newVersion->CompareTo((nsInstallVersion*)oldVersion, &areTheyEqual); - - if ( areTheyEqual != nsIDOMInstallVersion::EQUAL ) - versionNewer = PR_TRUE; - - if ( oldVersion ) - delete oldVersion; - } - else - { - versionNewer = PR_TRUE; - } - - - if (qualifiedRegNameString != nsnull) - delete [] qualifiedRegNameString; - - if (versionNewer) - { - ie = new nsInstallFile( this, - *qualifiedRegName, - newVersion, - aJarSource, - aFolder, - aTargetName, - aForceMode, - &errcode ); - - if (errcode == nsInstall::SUCCESS) - { - errcode = ScheduleForInstall( ie ); - } - else - { - delete ie; - } - } - - if (qualifiedRegName != nsnull) - delete qualifiedRegName; - - if (newVersion != nsnull) - delete newVersion; - - *aReturn = SaveError( errcode ); - return NS_OK; -} - -PRInt32 -nsInstall::AddSubcomponent(const nsString& aRegName, - nsIDOMInstallVersion* aVersion, - const nsString& aJarSource, - const nsString& aFolder, - const nsString& aTargetName, - PRInt32* aReturn) -{ - nsInstallFile* ie; - nsString* qualifiedRegName = nsnull; - PRBool aForceMode = PR_FALSE; - nsString aVersionStr; - - PRInt32 errcode = nsInstall::SUCCESS; - - if ( aJarSource == "null" || aFolder == "null") - { - *aReturn = SaveError( nsInstall::INVALID_ARGUMENTS ); - return NS_OK; - } - - PRInt32 result = SanityCheck(); - - if (result != nsInstall::SUCCESS) - { - *aReturn = SaveError( result ); - return NS_OK; - } - - - if ( aRegName == "" ) - { - // Default subName = location in jar file - qualifiedRegName = GetQualifiedRegName( aJarSource ); - } - else - { - qualifiedRegName = GetQualifiedRegName( aRegName ); - } - - if (qualifiedRegName == nsnull) - { - *aReturn = SaveError( BAD_PACKAGE_NAME ); - return NS_OK; - } - - /* Check for existence of the newer version */ - - nsInstallVersion *newVersion = new nsInstallVersion(); - aVersion->ToString(aVersionStr); - newVersion->Init(aVersionStr); - - PRBool versionNewer = PR_FALSE; - char* qualifiedRegNameString = qualifiedRegName->ToNewCString(); - - if ( (aForceMode == PR_FALSE ) && (aVersionStr != "null") && ( VR_ValidateComponent( qualifiedRegNameString ) == 0 ) ) - { - VERSION versionStruct; - - VR_GetVersion( qualifiedRegNameString, &versionStruct ); - - nsInstallVersion* oldVersion = new nsInstallVersion(); -// FIX. Once we move to XPConnect, we can have parameterized constructors. - oldVersion->Init(versionStruct.major, - versionStruct.minor, - versionStruct.release, - versionStruct.build); - - PRInt32 areTheyEqual; - newVersion->CompareTo((nsInstallVersion*)oldVersion, &areTheyEqual); - - if ( areTheyEqual != nsIDOMInstallVersion::EQUAL ) - versionNewer = PR_TRUE; - - if ( oldVersion ) - delete oldVersion; - } - else - { - versionNewer = PR_TRUE; - } - - - if (qualifiedRegNameString != nsnull) - delete [] qualifiedRegNameString; - - if (versionNewer) - { - ie = new nsInstallFile( this, - *qualifiedRegName, - newVersion, - aJarSource, - aFolder, - aTargetName, - aForceMode, - &errcode ); - - if (errcode == nsInstall::SUCCESS) - { - errcode = ScheduleForInstall( ie ); - } - else - { - delete ie; - } - } - - if (qualifiedRegName != nsnull) - delete qualifiedRegName; - - if (newVersion != nsnull) - delete newVersion; - - *aReturn = SaveError( errcode ); - return NS_OK; + return AddSubcomponent(aRegName, + aVersion, + aJarSource, + aFolder, + aTargetName, + PR_FALSE, + aReturn); } PRInt32 @@ -1728,230 +530,29 @@ nsInstall::AddSubcomponent(const nsString& aRegName, const nsString& aTargetName, PRInt32* aReturn) { - nsInstallFile* ie; - nsString* qualifiedRegName = nsnull; - PRInt32 errcode = nsInstall::SUCCESS; - - // defaulting aForceMode to PR_FALSE and aVersion to "null" - PRBool aForceMode = PR_FALSE; - nsString aVersion = "null"; - - if ( aJarSource == "null" || aFolder == "null") - { - *aReturn = SaveError( nsInstall::INVALID_ARGUMENTS ); - return NS_OK; - } - - PRInt32 result = SanityCheck(); - - if (result != nsInstall::SUCCESS) - { - *aReturn = SaveError( result ); - return NS_OK; - } - - - if ( aRegName == "" ) - { - // Default subName = location in jar file - qualifiedRegName = GetQualifiedRegName( aJarSource ); - } - else - { - qualifiedRegName = GetQualifiedRegName( aRegName ); - } - - if (qualifiedRegName == nsnull) - { - *aReturn = SaveError( BAD_PACKAGE_NAME ); - return NS_OK; - } - - /* Check for existence of the newer version */ - - nsInstallVersion *newVersion = new nsInstallVersion(); - newVersion->Init(aVersion); - - PRBool versionNewer = PR_FALSE; - char* qualifiedRegNameString = qualifiedRegName->ToNewCString(); - - if ( (aForceMode == PR_FALSE ) && (aVersion != "null") && ( VR_ValidateComponent( qualifiedRegNameString ) == 0 ) ) - { - VERSION versionStruct; - - VR_GetVersion( qualifiedRegNameString, &versionStruct ); - - nsInstallVersion* oldVersion = new nsInstallVersion(); -// FIX. Once we move to XPConnect, we can have parameterized constructors. - oldVersion->Init(versionStruct.major, - versionStruct.minor, - versionStruct.release, - versionStruct.build); - - PRInt32 areTheyEqual; - newVersion->CompareTo((nsInstallVersion*)oldVersion, &areTheyEqual); - - if ( areTheyEqual != nsIDOMInstallVersion::EQUAL ) - versionNewer = PR_TRUE; - - if ( oldVersion ) - delete oldVersion; - } - else - { - versionNewer = PR_TRUE; - } - - - if (qualifiedRegNameString != nsnull) - delete [] qualifiedRegNameString; - - if (versionNewer) - { - ie = new nsInstallFile( this, - *qualifiedRegName, - newVersion, - aJarSource, - aFolder, - aTargetName, - aForceMode, - &errcode ); - - if (errcode == nsInstall::SUCCESS) - { - errcode = ScheduleForInstall( ie ); - } - else - { - delete ie; - } - } - - if (qualifiedRegName != nsnull) - delete qualifiedRegName; - - if (newVersion != nsnull) - delete newVersion; - - *aReturn = SaveError( errcode ); - return NS_OK; + return AddSubcomponent(aRegName, + "", + aJarSource, + aFolder, + aTargetName, + PR_FALSE, + aReturn); } PRInt32 nsInstall::AddSubcomponent(const nsString& aJarSource, PRInt32* aReturn) { - nsInstallFile* ie; - nsString* qualifiedRegName = nsnull; - PRInt32 errcode = nsInstall::SUCCESS; - - // defaulting aRegName to "", aForceMode to PR_FALSE, and aVersion to "null" - nsString aTargetName = aJarSource; - nsString aRegName = ""; -// fix: aFolder should not default to "null". - nsString aFolder = "null"; - PRBool aForceMode = PR_FALSE; - nsString aVersion = "null"; - - if ( aJarSource == "null" || aFolder == "null") - { - *aReturn = SaveError( nsInstall::INVALID_ARGUMENTS ); - return NS_OK; - } - - PRInt32 result = SanityCheck(); - - if (result != nsInstall::SUCCESS) - { - *aReturn = SaveError( result ); - return NS_OK; - } - - - if ( aRegName == "" ) - { - // Default subName = location in jar file - qualifiedRegName = GetQualifiedRegName( aJarSource ); - } - else - { - qualifiedRegName = GetQualifiedRegName( aRegName ); - } - - if (qualifiedRegName == nsnull) - { - *aReturn = SaveError( BAD_PACKAGE_NAME ); - return NS_OK; - } - - /* Check for existence of the newer version */ - - nsInstallVersion *newVersion = new nsInstallVersion(); - newVersion->Init(aVersion); - - PRBool versionNewer = PR_FALSE; - char* qualifiedRegNameString = qualifiedRegName->ToNewCString(); - - if ( (aForceMode == PR_FALSE ) && (aVersion != "null") && ( VR_ValidateComponent( qualifiedRegNameString ) == 0 ) ) - { - VERSION versionStruct; - - VR_GetVersion( qualifiedRegNameString, &versionStruct ); - - nsInstallVersion* oldVersion = new nsInstallVersion(); -// FIX. Once we move to XPConnect, we can have parameterized constructors. - oldVersion->Init(versionStruct.major, - versionStruct.minor, - versionStruct.release, - versionStruct.build); - - PRInt32 areTheyEqual; - newVersion->CompareTo((nsInstallVersion*)oldVersion, &areTheyEqual); - - if ( areTheyEqual != nsIDOMInstallVersion::EQUAL ) - versionNewer = PR_TRUE; + //FIX aFolder needs to be found! + return AddSubcomponent("", + "", + aJarSource, + "", + "", + PR_FALSE, + aReturn); - if ( oldVersion ) - delete oldVersion; - } - else - { - versionNewer = PR_TRUE; - } - - if (qualifiedRegNameString != nsnull) - delete [] qualifiedRegNameString; - - if (versionNewer) - { - ie = new nsInstallFile( this, - *qualifiedRegName, - newVersion, - aJarSource, - aFolder, - aTargetName, - aForceMode, - &errcode ); - - if (errcode == nsInstall::SUCCESS) - { - errcode = ScheduleForInstall( ie ); - } - else - { - delete ie; - } - } - - if (qualifiedRegName != nsnull) - delete qualifiedRegName; - - if (newVersion != nsnull) - delete newVersion; - - *aReturn = SaveError( errcode ); - return NS_OK; } PRInt32 @@ -1965,23 +566,21 @@ nsInstall::DeleteComponent(const nsString& aRegistryName, PRInt32* aReturn) return NS_OK; } + nsString qualifiedRegName; + + *aReturn = GetQualifiedRegName( aRegistryName, qualifiedRegName); - nsString* qualifiedRegName = GetQualifiedRegName( aRegistryName); - - if (qualifiedRegName == nsnull) + if (*aReturn != SUCCESS) { - *aReturn = SaveError( BAD_PACKAGE_NAME ); return NS_OK; } - nsInstallDelete* id = new nsInstallDelete(this, "", *qualifiedRegName, &result); + nsInstallDelete* id = new nsInstallDelete(this, "", qualifiedRegName, &result); if (result == nsInstall::SUCCESS) { result = ScheduleForInstall( id ); } - delete qualifiedRegName; - *aReturn = SaveError(result); return NS_OK; @@ -2018,6 +617,7 @@ nsInstall::DeleteFile(const nsString& aFolder, const nsString& aRelativeFileName PRInt32 nsInstall::DiskSpaceAvailable(const nsString& aFolder, PRInt32* aReturn) { + //fix return NS_OK; } @@ -2046,24 +646,7 @@ nsInstall::Execute(const nsString& aJarSource, const nsString& aArgs, PRInt32* a PRInt32 nsInstall::Execute(const nsString& aJarSource, PRInt32* aReturn) { - PRInt32 result = SanityCheck(); - nsString aArgs = ""; - - if (result != nsInstall::SUCCESS) - { - *aReturn = SaveError( result ); - return NS_OK; - } - - nsInstallExecute* ie = new nsInstallExecute(this, aJarSource, aArgs, &result); - - if (result == nsInstall::SUCCESS) - { - result = ScheduleForInstall( ie ); - } - - *aReturn = SaveError(result); - return NS_OK; + return Execute(aJarSource, "", aReturn); } PRInt32 @@ -2120,7 +703,6 @@ nsInstall::FinalizeInstall(PRInt32* aReturn) } } - *aReturn = NS_OK; return NS_OK; } @@ -2142,15 +724,16 @@ nsInstall::GetComponentFolder(const nsString& aComponentName, const nsString& aS // FIX: aSubdirectory is not processed at all in this function. *aFolder = nsnull; - - nsString *tempString = GetQualifiedPackageName( aComponentName ); - if (tempString == nsnull) + nsString tempString; + + if ( GetQualifiedPackageName(aComponentName, tempString) == SUCCESS ) + { return NS_OK; - - componentCString = tempString->ToNewCString(); - delete tempString; - + } + + componentCString = tempString.ToNewCString(); + dir = (char*)PR_Malloc(MAXREGPATHLEN); err = VR_GetDefaultDirectory( componentCString, MAXREGPATHLEN, dir ); if (err != REGERR_OK) @@ -2195,59 +778,7 @@ nsInstall::GetComponentFolder(const nsString& aComponentName, const nsString& aS PRInt32 nsInstall::GetComponentFolder(const nsString& aComponentName, nsString** aFolder) { - long err; - char* dir; - char* componentCString; - - *aFolder = nsnull; - - nsString *tempString = GetQualifiedPackageName( aComponentName ); - - if (tempString == nsnull) - return NS_OK; - - componentCString = tempString->ToNewCString(); - delete tempString; - - dir = (char*)PR_Malloc(MAXREGPATHLEN); - err = VR_GetDefaultDirectory( componentCString, MAXREGPATHLEN, dir ); - if (err != REGERR_OK) - { - PR_FREEIF(dir); - } - - - if ( dir == NULL ) - { - dir = (char*)PR_Malloc(MAXREGPATHLEN); - err = VR_GetPath( componentCString, MAXREGPATHLEN, dir ); - if (err != REGERR_OK) - { - PR_FREEIF(dir); - } - - if ( dir != nsnull ) - { - int i; - - nsString dirStr(dir); - if ( (i = dirStr.RFind(FILESEP)) > 0 ) - { - PR_FREEIF(dir); - dir = (char*)PR_Malloc(i); - dir = dirStr.ToCString(dir, i); - } - } - } - - if ( dir != NULL ) - { - *aFolder = new nsString(dir); - } - - PR_FREEIF(dir); - delete [] componentCString; - return NS_OK; + return GetComponentFolder(aComponentName, "", aFolder); } PRInt32 @@ -2268,19 +799,7 @@ nsInstall::GetFolder(const nsString& targetFolder, const nsString& aSubdirectory PRInt32 nsInstall::GetFolder(const nsString& targetFolder, nsString** aFolder) { - nsInstallFolder* spec = nsnull; - *aFolder = nsnull; - - // defaulting aSubdirectory to "". - nsString aSubdirectory = ""; - - spec = new nsInstallFolder(targetFolder, aSubdirectory); - - nsString dirString; - spec->GetDirectoryPath(dirString); - - *aFolder = new nsString(dirString); - return NS_OK; + return GetFolder(targetFolder, "", aFolder); } PRInt32 @@ -2349,68 +868,22 @@ nsInstall::Patch(const nsString& aRegName, const nsString& aVersion, const nsStr return NS_OK; } - nsString* qualifiedRegName = GetQualifiedRegName( aRegName ); + nsString qualifiedRegName; - if (qualifiedRegName == nsnull) + *aReturn = GetQualifiedRegName( aRegName, qualifiedRegName); + + if (*aReturn != SUCCESS) { - *aReturn = SaveError( nsInstall::BAD_PACKAGE_NAME ); return NS_OK; } - nsInstallVersion *newVersion = new nsInstallVersion(); - newVersion->Init(aVersion); - nsInstallPatch* ip = new nsInstallPatch( this, - *qualifiedRegName, - newVersion, + qualifiedRegName, + aVersion, aJarSource, &result); - delete newVersion; - - if (result == nsInstall::SUCCESS) - { - result = ScheduleForInstall( ip ); - } - - *aReturn = SaveError(result); - return NS_OK; -} - -PRInt32 -nsInstall::Patch(const nsString& aRegName, nsIDOMInstallVersion* aVersion, const nsString& aJarSource, const nsString& aFolder, const nsString& aTargetName, PRInt32* aReturn) -{ - PRInt32 result = SanityCheck(); - nsString aVersionStr; - - if (result != nsInstall::SUCCESS) - { - *aReturn = SaveError( result ); - return NS_OK; - } - - nsString* qualifiedRegName = GetQualifiedRegName( aRegName ); - - if (qualifiedRegName == nsnull) - { - *aReturn = SaveError( nsInstall::BAD_PACKAGE_NAME ); - return NS_OK; - } - - nsInstallVersion *newVersion = new nsInstallVersion(); - aVersion->ToString(aVersionStr); - newVersion->Init(aVersionStr); - - nsInstallPatch* ip = new nsInstallPatch( this, - *qualifiedRegName, - newVersion, - aJarSource, - &result); - - - delete newVersion; - if (result == nsInstall::SUCCESS) { result = ScheduleForInstall( ip ); @@ -2423,44 +896,7 @@ nsInstall::Patch(const nsString& aRegName, nsIDOMInstallVersion* aVersion, const PRInt32 nsInstall::Patch(const nsString& aRegName, const nsString& aJarSource, const nsString& aFolder, const nsString& aTargetName, PRInt32* aReturn) { - PRInt32 result = SanityCheck(); - - // defaulting aVersion to "null"; - nsString aVersion = "null"; - - if (result != nsInstall::SUCCESS) - { - *aReturn = SaveError( result ); - return NS_OK; - } - - nsString* qualifiedRegName = GetQualifiedRegName( aRegName ); - - if (qualifiedRegName == nsnull) - { - *aReturn = SaveError( nsInstall::BAD_PACKAGE_NAME ); - return NS_OK; - } - - nsInstallVersion *newVersion = new nsInstallVersion(); - newVersion->Init(aVersion); - - nsInstallPatch* ip = new nsInstallPatch( this, - *qualifiedRegName, - newVersion, - aJarSource, - &result); - - - delete newVersion; - - if (result == nsInstall::SUCCESS) - { - result = ScheduleForInstall( ip ); - } - - *aReturn = SaveError(result); - return NS_OK; + return Patch(aRegName, "", aJarSource, aFolder, aTargetName, aReturn); } PRInt32 @@ -2476,60 +912,32 @@ nsInstall::SetPackageFolder(const nsString& aFolder) return NS_OK; } -/** - * Call this to initialize the update - * Opens the jar file and gets the certificate of the installer - * Opens up the gui, and asks for proper security privileges - * - * @param aUserPackageName - * - * @param aPackageName Full qualified version registry name of the package - * (ex: "/Plugins/Adobe/Acrobat") - * NULL or empty package names are errors - * - * @param inVInfo version of the package installed. - * Can be NULL, in which case package is installed - * without a version. Having a NULL version, this - * package is automatically updated in the future - * (ie. no version check is performed). - * - * @param flags Once was securityLevel(LIMITED_INSTALL or FULL_INSTALL). Now - * can be either NO_STATUS_DLG or NO_FINALIZE_DLG - */ + PRInt32 -nsInstall::StartInstall(const nsString& aUserPackageName, const nsString& aPackageName, const nsString& aVersion, PRInt32 aFlags, PRInt32* aReturn) +nsInstall::StartInstall(const nsString& aUserPackageName, const nsString& aRegistryPackageName, const nsString& aVersion, PRInt32* aReturn) { -// FIX: aFlags is not processed. *aReturn = nsInstall::SUCCESS; ResetError(); mUserCancelled = PR_FALSE; - if ( aPackageName.Equals("") || aPackageName.EqualsIgnoreCase("null")) + if ( aRegistryPackageName.Equals("") || aRegistryPackageName.EqualsIgnoreCase("null")) { *aReturn = nsInstall::INVALID_ARGUMENTS; return NS_OK; } mUIName = aUserPackageName; - - - nsString *tempString = GetQualifiedPackageName( aPackageName ); - mRegistryPackageName.SetLength(0); - mRegistryPackageName.Append( *tempString ); + *aReturn = GetQualifiedPackageName( aRegistryPackageName, mRegistryPackageName ); - delete tempString; - - /* Check to see if the PackageName ends in a '/'. If it does nuke it. */ - - if (mRegistryPackageName.Last() == '/') + if (*aReturn != nsInstall::SUCCESS) { - PRInt32 index = mRegistryPackageName.Length(); - mRegistryPackageName.Truncate(--index); + return NS_OK; } - + + if (mVersionInfo != nsnull) delete mVersionInfo; @@ -2548,228 +956,17 @@ nsInstall::StartInstall(const nsString& aUserPackageName, const nsString& aPacka return -1; /* FIX: need real error code */ } - /* Show our window here */ - SaveError(*aReturn); - if (*aReturn != nsInstall::SUCCESS) - { - mRegistryPackageName = ""; // Reset! - } - - if (mNotifier) - mNotifier->InstallStarted(nsAutoCString(mUIName)); - - return NS_OK; -} - -PRInt32 -nsInstall::StartInstall(const nsString& aUserPackageName, const nsString& aPackageName, nsIDOMInstallVersion* aVersion, PRInt32 aFlags, PRInt32* aReturn) -{ -// FIX: aFlags is not processed. - *aReturn = nsInstall::SUCCESS; - nsString aVersionStr; - - ResetError(); - - mUserCancelled = PR_FALSE; - - if ( aPackageName.Equals("") || aPackageName.EqualsIgnoreCase("null")) - { - *aReturn = nsInstall::INVALID_ARGUMENTS; - return NS_OK; - } - - mUIName = aUserPackageName; - - - nsString *tempString = GetQualifiedPackageName( aPackageName ); - - mRegistryPackageName.SetLength(0); - mRegistryPackageName.Append( *tempString ); - - delete tempString; - - /* Check to see if the PackageName ends in a '/'. If it does nuke it. */ - - if (mRegistryPackageName.Last() == '/') - { - PRInt32 index = mRegistryPackageName.Length(); - mRegistryPackageName.Truncate(--index); - } - - if (mVersionInfo != nsnull) - delete mVersionInfo; - - mVersionInfo = new nsInstallVersion(); - aVersion->ToString(aVersionStr); - mVersionInfo->Init(aVersionStr); - - mInstalledFiles = new nsVector(); - mPatchList = new nsHashtable(); - - /* this function should also check security!!! */ - *aReturn = OpenJARFile(); - - if (*aReturn != nsInstall::SUCCESS) - { - /* if we can not continue with the javascript return a JAR error*/ - return -1; /* FIX: need real error code */ - } - - /* Show our window here */ - - SaveError(*aReturn); - - if (*aReturn != nsInstall::SUCCESS) - { - mRegistryPackageName = ""; // Reset! - } - if (mNotifier) mNotifier->InstallStarted(nsAutoCString(mUIName)); return NS_OK; } -PRInt32 -nsInstall::StartInstall(const nsString& aUserPackageName, const nsString& aPackageName, const nsString& aVersion, PRInt32* aReturn) -{ -// FIX: aFlags is not processed. A default value needs to be used since this function does not accept an aFlags value. - *aReturn = nsInstall::SUCCESS; - - ResetError(); - - mUserCancelled = PR_FALSE; - - if ( aPackageName.Equals("") || aPackageName.EqualsIgnoreCase("null")) - { - *aReturn = nsInstall::INVALID_ARGUMENTS; - return NS_OK; - } - - mUIName = aUserPackageName; - - - nsString *tempString = GetQualifiedPackageName( aPackageName ); - - mRegistryPackageName.SetLength(0); - mRegistryPackageName.Append( *tempString ); - - delete tempString; - - /* Check to see if the PackageName ends in a '/'. If it does nuke it. */ - - if (mRegistryPackageName.Last() == '/') - { - PRInt32 index = mRegistryPackageName.Length(); - mRegistryPackageName.Truncate(--index); - } - - if (mVersionInfo != nsnull) - delete mVersionInfo; - - mVersionInfo = new nsInstallVersion(); - mVersionInfo->Init(aVersion); - - mInstalledFiles = new nsVector(); - mPatchList = new nsHashtable(); - - /* this function should also check security!!! */ - *aReturn = OpenJARFile(); - - if (*aReturn != nsInstall::SUCCESS) - { - /* if we can not continue with the javascript return a JAR error*/ - return -1; /* FIX: need real error code */ - } - - /* Show our window here */ - - SaveError(*aReturn); - - if (*aReturn != nsInstall::SUCCESS) - { - mRegistryPackageName = ""; // Reset! - } - - if (mNotifier) - mNotifier->InstallStarted(nsAutoCString(mUIName)); - - return NS_OK; -} PRInt32 -nsInstall::StartInstall(const nsString& aUserPackageName, const nsString& aPackageName, nsIDOMInstallVersion* aVersion, PRInt32* aReturn) -{ -// FIX: aFlags is not processed. A default value needs to be used since this function does not accept an aFlags value. - *aReturn = nsInstall::SUCCESS; - nsString aVersionStr; - - ResetError(); - - mUserCancelled = PR_FALSE; - - if ( aPackageName.Equals("") || aPackageName.EqualsIgnoreCase("null")) - { - *aReturn = nsInstall::INVALID_ARGUMENTS; - return NS_OK; - } - - mUIName = aUserPackageName; - - - nsString *tempString = GetQualifiedPackageName( aPackageName ); - - mRegistryPackageName.SetLength(0); - mRegistryPackageName.Append( *tempString ); - - delete tempString; - - /* Check to see if the PackageName ends in a '/'. If it does nuke it. */ - - if (mRegistryPackageName.Last() == '/') - { - PRInt32 index = mRegistryPackageName.Length(); - mRegistryPackageName.Truncate(--index); - } - - if (mVersionInfo != nsnull) - delete mVersionInfo; - - mVersionInfo = new nsInstallVersion(); - aVersion->ToString(aVersionStr); - mVersionInfo->Init(aVersionStr); - - mInstalledFiles = new nsVector(); - mPatchList = new nsHashtable(); - - /* this function should also check security!!! */ - *aReturn = OpenJARFile(); - - if (*aReturn != nsInstall::SUCCESS) - { - /* if we can not continue with the javascript return a JAR error*/ - return -1; /* FIX: need real error code */ - } - - /* Show our window here */ - - SaveError(*aReturn); - - if (*aReturn != nsInstall::SUCCESS) - { - mRegistryPackageName = ""; // Reset! - } - - if (mNotifier) - mNotifier->InstallStarted(nsAutoCString(mUIName)); - - return NS_OK; -} - -PRInt32 -nsInstall::Uninstall(const nsString& aPackageName, PRInt32* aReturn) +nsInstall::Uninstall(const nsString& aRegistryPackageName, PRInt32* aReturn) { PRInt32 result = SanityCheck(); @@ -2778,17 +975,18 @@ nsInstall::Uninstall(const nsString& aPackageName, PRInt32* aReturn) *aReturn = SaveError( result ); return NS_OK; } - - nsString* qualifiedPackageName = GetQualifiedPackageName( aPackageName ); - if (qualifiedPackageName == nsnull) + nsString qualifiedPackageName; + + *aReturn = GetQualifiedPackageName( aRegistryPackageName, qualifiedPackageName ); + + if (*aReturn != SUCCESS) { - *aReturn = SaveError( BAD_PACKAGE_NAME ); return NS_OK; } nsInstallUninstall *ie = new nsInstallUninstall( this, - *qualifiedPackageName, + qualifiedPackageName, &result ); if (result == nsInstall::SUCCESS) @@ -2800,8 +998,6 @@ nsInstall::Uninstall(const nsString& aPackageName, PRInt32* aReturn) delete ie; } - delete qualifiedPackageName; - *aReturn = SaveError(result); return NS_OK; @@ -2908,96 +1104,90 @@ nsInstall::SanityCheck(void) * into a full name that can be used in calls to the version registry. */ -nsString * -nsInstall::GetQualifiedPackageName( const nsString& name ) +PRInt32 +nsInstall::GetQualifiedPackageName( const nsString& name, nsString& qualifiedName ) { - nsString* qualifedName = nsnull; - - /* this functions is really messed up. The original checkin is messed as well */ + nsString startOfName; + name.Left(startOfName, 7); - if ( name.Equals( "=USER=/") ) + if ( startOfName.Equals( "=USER=/") ) { - qualifedName = CurrentUserNode(); - qualifedName->Insert( name, 7 ); + CurrentUserNode(qualifiedName); + qualifiedName += name; } else { - qualifedName = new nsString(name); + qualifiedName = name; } - if (BadRegName(qualifedName)) + if (BadRegName(qualifiedName)) { - if (qualifedName != nsnull) - { - delete qualifedName; - qualifedName = nsnull; - } + return BAD_PACKAGE_NAME; } - return qualifedName; + + + /* Check to see if the PackageName ends in a '/'. If it does nuke it. */ + + if (qualifiedName.Last() == '/') + { + PRInt32 index = qualifiedName.Length(); + qualifiedName.Truncate(--index); + } + + return SUCCESS; } /** * GetQualifiedRegName * - * Allocates a new string and returns it. Caller is supposed to free it - * * This routine converts a package-relative component registry name * into a full name that can be used in calls to the version registry. */ -nsString * -nsInstall::GetQualifiedRegName(const nsString& name ) +PRInt32 +nsInstall::GetQualifiedRegName(const nsString& name, nsString& qualifiedRegName ) { - nsString *qualifiedRegName; + nsString startOfName; + name.Left(startOfName, 7); - nsString comm("=COMM=/"); - nsString usr ("=USER=/"); + nsString usr (); - if ( name.Compare(comm, PR_TRUE) == 0 ) + if ( startOfName.Equals("=COMM=/") || startOfName.Equals("=USER=/")) { - qualifiedRegName = new nsString( name ); - qualifiedRegName->Cut( 0, comm.Length() ); - } - else if ( name.Compare(usr, PR_TRUE) == 0 ) - { - qualifiedRegName = new nsString( name ); - qualifiedRegName->Cut( 0, usr.Length() ); + qualifiedRegName = name; + qualifiedRegName.Cut( 0, 7 ); } else if ( name.CharAt(0) != '/' ) { - if (mUIName != "") + if (mRegistryPackageName != "") { - qualifiedRegName = new nsString(mUIName); - qualifiedRegName->Append("/"); - qualifiedRegName->Append(name); + qualifiedRegName = mRegistryPackageName; + qualifiedRegName += "/"; + qualifiedRegName += name; } else { - qualifiedRegName = new nsString(name); + qualifiedRegName = name; } } else { - qualifiedRegName = new nsString(name); + qualifiedRegName = name; } if (BadRegName(qualifiedRegName)) { - delete qualifiedRegName; - qualifiedRegName = NULL; + return BAD_PACKAGE_NAME; } - return qualifiedRegName; + return SUCCESS; } -nsString* -nsInstall::CurrentUserNode() -{ - nsString *qualifedName; - nsString *profileName; - +void +nsInstall::CurrentUserNode(nsString& userRegNode) +{ char *profname; int len = MAXREGNAMELEN; int err; @@ -3012,39 +1202,33 @@ nsInstall::CurrentUserNode() profname = NULL; } - profileName = new nsString(profname); - qualifedName = new nsString("/Netscape/Users/"); - - qualifedName->Append(*profileName); - qualifedName->Append("/"); - - if (profileName != nsnull) - delete profileName; - - return qualifedName; + userRegNode = "/Netscape/Users/"; + if (profname != nsnull) + { + userRegNode += nsString(profname); + userRegNode += "/"; + PR_FREEIF(profname); + } } // catch obvious registry name errors proactively // rather than returning some cryptic libreg error PRBool -nsInstall::BadRegName(nsString* regName) +nsInstall::BadRegName(const nsString& regName) { - if (regName == nsnull) - return PR_TRUE; - - if ((regName->First() == ' ' ) || (regName->Last() == ' ' )) + if ((regName.First() == ' ' ) || (regName.Last() == ' ' )) return PR_TRUE; - if ( regName->Find("//") != -1 ) + if ( regName.Find("//") != -1 ) return PR_TRUE; - if ( regName->Find(" /") != -1 ) + if ( regName.Find(" /") != -1 ) return PR_TRUE; - if ( regName->Find("/ ") != -1 ) + if ( regName.Find("/ ") != -1 ) return PR_TRUE; - if ( regName->Find("=") != -1 ) + if ( regName.Find("=") != -1 ) return PR_TRUE; return PR_FALSE; diff --git a/xpinstall/src/nsInstall.h b/xpinstall/src/nsInstall.h index 4815e9ad129..b510662c26b 100644 --- a/xpinstall/src/nsInstall.h +++ b/xpinstall/src/nsInstall.h @@ -135,31 +135,29 @@ class nsInstall nsInstall(); virtual ~nsInstall(); - PRInt32 SetScriptObject(void* aScriptObject); + PRInt32 SetScriptObject(void* aScriptObject); - PRInt32 SaveWinRegPrototype(void* aScriptObject); PRInt32 SaveWinProfilePrototype(void* aScriptObject); JSObject* RetrieveWinRegPrototype(void); JSObject* RetrieveWinProfilePrototype(void); - + PRInt32 GetUserPackageName(nsString& aUserPackageName); PRInt32 GetRegPackageName(nsString& aRegPackageName); PRInt32 AbortInstall(); + PRInt32 AddDirectory(const nsString& aRegName, const nsString& aVersion, const nsString& aJarSource, const nsString& aFolder, const nsString& aSubdir, PRBool aForceMode, PRInt32* aReturn); - PRInt32 AddDirectory(const nsString& aRegName, nsIDOMInstallVersion* aVersion, const nsString& aJarSource, const nsString& aFolder, const nsString& aSubdir, PRBool aForceMode, PRInt32* aReturn); PRInt32 AddDirectory(const nsString& aRegName, const nsString& aVersion, const nsString& aJarSource, const nsString& aFolder, const nsString& aSubdir, PRInt32* aReturn); - PRInt32 AddDirectory(const nsString& aRegName, nsIDOMInstallVersion* aVersion, const nsString& aJarSource, const nsString& aFolder, const nsString& aSubdir, PRInt32* aReturn); PRInt32 AddDirectory(const nsString& aRegName, const nsString& aJarSource, const nsString& aFolder, const nsString& aSubdir, PRInt32* aReturn); PRInt32 AddDirectory(const nsString& aJarSource, PRInt32* aReturn); + PRInt32 AddSubcomponent(const nsString& aRegName, const nsString& aVersion, const nsString& aJarSource, const nsString& aFolder, const nsString& aTargetName, PRBool aForceMode, PRInt32* aReturn); - PRInt32 AddSubcomponent(const nsString& aRegName, nsIDOMInstallVersion* aVersion, const nsString& aJarSource, const nsString& aFolder, const nsString& aTargetName, PRBool aForceMode, PRInt32* aReturn); PRInt32 AddSubcomponent(const nsString& aRegName, const nsString& aVersion, const nsString& aJarSource, const nsString& aFolder, const nsString& aTargetName, PRInt32* aReturn); - PRInt32 AddSubcomponent(const nsString& aRegName, nsIDOMInstallVersion* aVersion, const nsString& aJarSource, const nsString& aFolder, const nsString& aTargetName, PRInt32* aReturn); PRInt32 AddSubcomponent(const nsString& aRegName, const nsString& aJarSource, const nsString& aFolder, const nsString& aTargetName, PRInt32* aReturn); PRInt32 AddSubcomponent(const nsString& aJarSource, PRInt32* aReturn); + PRInt32 DeleteComponent(const nsString& aRegistryName, PRInt32* aReturn); PRInt32 DeleteFile(const nsString& aFolder, const nsString& aRelativeFileName, PRInt32* aReturn); PRInt32 DiskSpaceAvailable(const nsString& aFolder, PRInt32* aReturn); @@ -175,18 +173,13 @@ class nsInstall PRInt32 GetWinProfile(const nsString& aFolder, const nsString& aFile, JSContext* jscontext, JSClass* WinProfileClass, jsval* aReturn); PRInt32 GetWinRegistry(JSContext* jscontext, JSClass* WinRegClass, jsval* aReturn); PRInt32 Patch(const nsString& aRegName, const nsString& aVersion, const nsString& aJarSource, const nsString& aFolder, const nsString& aTargetName, PRInt32* aReturn); - PRInt32 Patch(const nsString& aRegName, nsIDOMInstallVersion* aVersion, const nsString& aJarSource, const nsString& aFolder, const nsString& aTargetName, PRInt32* aReturn); PRInt32 Patch(const nsString& aRegName, const nsString& aJarSource, const nsString& aFolder, const nsString& aTargetName, PRInt32* aReturn); PRInt32 ResetError(); PRInt32 SetPackageFolder(const nsString& aFolder); - PRInt32 StartInstall(const nsString& aUserPackageName, const nsString& aPackageName, const nsString& aVersion, PRInt32 aFlags, PRInt32* aReturn); - PRInt32 StartInstall(const nsString& aUserPackageName, const nsString& aPackageName, nsIDOMInstallVersion* aVersion, PRInt32 aFlags, PRInt32* aReturn); PRInt32 StartInstall(const nsString& aUserPackageName, const nsString& aPackageName, const nsString& aVersion, PRInt32* aReturn); - PRInt32 StartInstall(const nsString& aUserPackageName, const nsString& aPackageName, nsIDOMInstallVersion* aVersion, PRInt32* aReturn); PRInt32 Uninstall(const nsString& aPackageName, PRInt32* aReturn); - PRInt32 ExtractFileFromJar(const nsString& aJarfile, nsFileSpec* aSuggestedName, nsFileSpec** aRealName); void AddPatch(nsHashKey *aKey, nsFileSpec* fileName); void GetPatch(nsHashKey *aKey, nsFileSpec* fileName); @@ -230,10 +223,12 @@ class nsInstall PRInt32 SanityCheck(void); void GetTime(nsString &aString); - nsString * GetQualifiedRegName( const nsString& name ); - nsString* GetQualifiedPackageName( const nsString& name ); - nsString* CurrentUserNode(); - PRBool BadRegName(nsString* regName); + + PRInt32 GetQualifiedRegName(const nsString& name, nsString& qualifiedRegName ); + PRInt32 GetQualifiedPackageName( const nsString& name, nsString& qualifiedName ); + + void CurrentUserNode(nsString& userRegNode); + PRBool BadRegName(const nsString& regName); PRInt32 SaveError(PRInt32 errcode); void CleanUp(); diff --git a/xpinstall/src/nsInstallDelete.cpp b/xpinstall/src/nsInstallDelete.cpp index 0d4afa87d24..8f339441a35 100644 --- a/xpinstall/src/nsInstallDelete.cpp +++ b/xpinstall/src/nsInstallDelete.cpp @@ -222,7 +222,7 @@ PRInt32 nsInstallDelete::NativeComplete() { if (mFinalFile->IsFile()) { - return DeleteFileLater(*mFinalFile); + return DeleteFileNowOrSchedule(*mFinalFile); } else { diff --git a/xpinstall/src/nsInstallExecute.cpp b/xpinstall/src/nsInstallExecute.cpp index 946838b82ef..5a27473349e 100644 --- a/xpinstall/src/nsInstallExecute.cpp +++ b/xpinstall/src/nsInstallExecute.cpp @@ -87,7 +87,7 @@ PRInt32 nsInstallExecute::Complete() PRInt32 result = app.Execute( mArgs ); - DeleteFileLater( app ); + DeleteFileNowOrSchedule( app ); return result; } @@ -98,15 +98,25 @@ void nsInstallExecute::Abort() if (mExecutableFile == nsnull) return; - DeleteFileLater(*mExecutableFile); + DeleteFileNowOrSchedule(*mExecutableFile); } char* nsInstallExecute::toString() { char* buffer = new char[1024]; - sprintf( buffer, nsInstallResources::GetExecuteString(), mExecutableFile->GetCString()); - + // if the FileSpec is NULL, just us the in jar file name. + + if (mExecutableFile == nsnull) + { + char *tempString = mJarLocation.ToNewCString(); + sprintf( buffer, nsInstallResources::GetExecuteString(), tempString); + delete [] tempString; + } + else + { + sprintf( buffer, nsInstallResources::GetExecuteString(), mExecutableFile->GetCString()); + } return buffer; } diff --git a/xpinstall/src/nsInstallFile.cpp b/xpinstall/src/nsInstallFile.cpp index 3a8f50bb474..6323a8778e1 100644 --- a/xpinstall/src/nsInstallFile.cpp +++ b/xpinstall/src/nsInstallFile.cpp @@ -28,7 +28,7 @@ #include "VerReg.h" #include "ScheduledTasks.h" #include "nsInstall.h" -#include "nsInstallVersion.h" +#include "nsIDOMInstallVersion.h" #include "nsInstallResources.h" /* Public Methods */ @@ -40,9 +40,11 @@ inJarLocation - location inside the JAR file inFinalFileSpec - final location on disk */ + + nsInstallFile::nsInstallFile(nsInstall* inInstall, const nsString& inComponentName, - nsIDOMInstallVersion* inVInfo, + const nsString& inVInfo, const nsString& inJarLocation, const nsString& folderSpec, const nsString& inPartialPath, @@ -50,30 +52,79 @@ nsInstallFile::nsInstallFile(nsInstall* inInstall, PRInt32 *error) : nsInstallObject(inInstall) { - mExtracedFile= nsnull; - mFinalFile = nsnull; - mUpgradeFile = PR_FALSE; + mVersionRegistryName = nsnull; + mJarLocation = nsnull; + mExtracedFile = nsnull; + mFinalFile = nsnull; + mVersionInfo = nsnull; - if ((folderSpec == "null") || (inInstall == NULL) || (inVInfo == NULL)) + mUpgradeFile = PR_FALSE; + + if ((folderSpec == "null") || (inInstall == NULL)) { *error = nsInstall::INVALID_ARGUMENTS; return; } + + /* Check for existence of the newer version */ + + PRBool versionNewer = PR_FALSE; // Is this a newer version + char* qualifiedRegNameString = inComponentName.ToNewCString(); + + if ( (forceInstall == PR_FALSE ) && (inVInfo != "") && ( VR_ValidateComponent( qualifiedRegNameString ) == 0 ) ) + { + nsInstallVersion *newVersion = new nsInstallVersion(); + newVersion->Init(inVInfo); + + VERSION versionStruct; + + VR_GetVersion( qualifiedRegNameString, &versionStruct ); + + nsInstallVersion* oldVersion = new nsInstallVersion(); + + oldVersion->Init(versionStruct.major, + versionStruct.minor, + versionStruct.release, + versionStruct.build); + + PRInt32 areTheyEqual; + newVersion->CompareTo(oldVersion, &areTheyEqual); + + delete oldVersion; + delete newVersion; + + if (areTheyEqual == nsIDOMInstallVersion::MAJOR_DIFF_MINUS || + areTheyEqual == nsIDOMInstallVersion::MINOR_DIFF_MINUS || + areTheyEqual == nsIDOMInstallVersion::REL_DIFF_MINUS || + areTheyEqual == nsIDOMInstallVersion::BLD_DIFF_MINUS ) + { + // the file to be installed is OLDER than what is on disk. Return error + delete qualifiedRegNameString; + *error = areTheyEqual; + return; + } + } + + delete qualifiedRegNameString; + mFinalFile = new nsFileSpec(folderSpec); *mFinalFile += inPartialPath; - mReplaceFile = mFinalFile->Exists(); + mReplaceFile = mFinalFile->Exists(); + + if (mReplaceFile == PR_FALSE) + { + nsFileSpec parent; + mFinalFile->GetParent(parent); + nsFileSpec makeDirs(parent.GetCString(), PR_TRUE); + } mForceInstall = forceInstall; mVersionRegistryName = new nsString(inComponentName); mJarLocation = new nsString(inJarLocation); - mVersionInfo = new nsInstallVersion(); - - nsString tempString; - inVInfo->ToString(tempString); - mVersionInfo->Init(tempString); + mVersionInfo = new nsString(inVInfo); nsString regPackageName; mInstall->GetRegPackageName(regPackageName); @@ -87,9 +138,12 @@ nsInstallFile::nsInstallFile(nsInstall* inInstall, } else { - //mChildFile = mVersionRegistryName.startsWith(regPackageName); - /* Because nsString doesn't support startWith, implemented the following. Waiting for approval */ - if (mVersionRegistryName->Find(regPackageName) == 0) + + // there is no "starts with" api in nsString. LAME! + nsString startsWith; + mVersionRegistryName->Left(startsWith, regPackageName.Length()); + + if (startsWith.Equals(regPackageName)) { mChildFile = true; } @@ -98,8 +152,6 @@ nsInstallFile::nsInstallFile(nsInstall* inInstall, mChildFile = false; } } - - } @@ -202,7 +254,7 @@ PRInt32 nsInstallFile::CompleteFileMove() } else { - result = ReplaceFileLater(*mExtracedFile, *mFinalFile ); + result = ReplaceFileNowOrSchedule(*mExtracedFile, *mFinalFile ); } return result; @@ -251,11 +303,18 @@ nsInstallFile::RegisterInVersionRegistry() } VR_Install( (char*)(const char*)nsAutoCString(*mVersionRegistryName), - (char*)(const char*)nsNSPRPath(*mFinalFile), - (char*)(const char*)nsAutoCString(regPackageName), + (char*)(const char*)mFinalFile->GetNativePathCString(), // DO NOT CHANGE THIS. + (char*)(const char*)nsAutoCString(*mVersionInfo), PR_FALSE ); - if (!mUpgradeFile) + if (mUpgradeFile) + { + if (refCount == 0) + VR_SetRefCount( (char*)(const char*)nsAutoCString(*mVersionRegistryName), 1 ); + else + VR_SetRefCount( (char*)(const char*)nsAutoCString(*mVersionRegistryName), refCount ); //FIX?? what should the ref count be/ + } + else { if (refCount != 0) { @@ -263,18 +322,11 @@ nsInstallFile::RegisterInVersionRegistry() } else { - if (mFinalFile->Exists()) + if (mReplaceFile) VR_SetRefCount( (char*)(const char*)nsAutoCString(*mVersionRegistryName), 2 ); else VR_SetRefCount( (char*)(const char*)nsAutoCString(*mVersionRegistryName), 1 ); } - } - else - { - if (refCount == 0) - VR_SetRefCount( (char*)(const char*)nsAutoCString(*mVersionRegistryName), 1 ); - else - VR_SetRefCount( (char*)(const char*)nsAutoCString(*mVersionRegistryName), 0 ); } if ( !mChildFile && !mUpgradeFile ) diff --git a/xpinstall/src/nsInstallFile.h b/xpinstall/src/nsInstallFile.h index 1b13801e710..2bf84917bc9 100644 --- a/xpinstall/src/nsInstallFile.h +++ b/xpinstall/src/nsInstallFile.h @@ -51,7 +51,7 @@ class nsInstallFile : public nsInstallObject *************************************************************/ nsInstallFile( nsInstall* inInstall, const nsString& inVRName, - nsIDOMInstallVersion* inVInfo, + const nsString& inVInfo, const nsString& inJarLocation, const nsString& folderSpec, const nsString& inPartialPath, @@ -72,7 +72,7 @@ class nsInstallFile : public nsInstallObject private: /* Private Fields */ - nsInstallVersion* mVersionInfo; /* Version info for this file*/ + nsString* mVersionInfo; /* Version info for this file*/ nsString* mJarLocation; /* Location in the JAR */ nsFileSpec* mExtracedFile; /* temporary file location */ diff --git a/xpinstall/src/nsInstallFolder.cpp b/xpinstall/src/nsInstallFolder.cpp index 22d8ef32fec..61d86d74ec4 100644 --- a/xpinstall/src/nsInstallFolder.cpp +++ b/xpinstall/src/nsInstallFolder.cpp @@ -28,11 +28,15 @@ #include "nscore.h" #include "prtypes.h" +#include "nsRepository.h" #include "nsString.h" #include "nsFileSpec.h" #include "nsSpecialSystemDirectory.h" +#include "nsFileLocations.h" +#include "nsIFileLocator.h" + struct DirectoryTable { char * directoryName; /* The formal directory name */ @@ -48,9 +52,12 @@ struct DirectoryTable DirectoryTable[] = {"Temporary", 104 }, {"Installed", 105 }, {"Current User", 106 }, - {"NetHelp", 107 }, + {"Preferences", 107 }, {"OS Drive", 108 }, - {"File URL", 109 }, + {"file:///", 109 }, + + {"Components", 110 }, + {"Chrome", 111 }, {"Win System", 200 }, {"Windows", 201 }, @@ -77,13 +84,34 @@ struct DirectoryTable DirectoryTable[] = nsInstallFolder::nsInstallFolder(const nsString& aFolderID) { - nsInstallFolder(aFolderID, ""); + mFileSpec = nsnull; + SetDirectoryPath( aFolderID, ""); } nsInstallFolder::nsInstallFolder(const nsString& aFolderID, const nsString& aRelativePath) { mFileSpec = nsnull; - SetDirectoryPath( aFolderID, aRelativePath); + + /* + aFolderID can be either a Folder enum in which case we merely pass it to SetDirectoryPath, or + it can be a Directory. If it is the later, it must already exist and of course be a directory + not a file. + */ + + nsFileSpec dirCheck(aFolderID); + if ( (dirCheck.Error() == NS_OK) && (dirCheck.IsDirectory()) && (dirCheck.Exists())) + { + nsString tempString = aFolderID; + tempString += aRelativePath; + mFileSpec = new nsFileSpec(tempString); + + // make sure that the directory is created. + nsFileSpec(mFileSpec->GetCString(), PR_TRUE); + } + else + { + SetDirectoryPath( aFolderID, aRelativePath); + } } @@ -96,7 +124,7 @@ nsInstallFolder::~nsInstallFolder() void nsInstallFolder::GetDirectoryPath(nsString& aDirectoryPath) { - aDirectoryPath.SetLength(0); + aDirectoryPath = ""; if (mFileSpec != nsnull) { @@ -125,108 +153,123 @@ nsInstallFolder::SetDirectoryPath(const nsString& aFolderID, const nsString& aRe switch (folderDirSpecID) { case 100: /////////////////////////////////////////////////////////// Plugins - // FIX + SetAppShellDirectory(nsSpecialFileSpec::App_PluginsDirectory ); break; case 101: /////////////////////////////////////////////////////////// Program - *this = nsSpecialSystemDirectory::OS_CurrentProcessDirectory; + mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::OS_CurrentProcessDirectory )); break; case 102: /////////////////////////////////////////////////////////// Communicator - *this = nsSpecialSystemDirectory::OS_CurrentProcessDirectory; // FIX? + mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::OS_CurrentProcessDirectory )); break; case 103: /////////////////////////////////////////////////////////// User Pick // we should never be here. + mFileSpec = nsnull; break; case 104: /////////////////////////////////////////////////////////// Temporary - *this = nsSpecialSystemDirectory::OS_TemporaryDirectory; + mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::OS_TemporaryDirectory )); break; case 105: /////////////////////////////////////////////////////////// Installed // we should never be here. + mFileSpec = nsnull; break; case 106: /////////////////////////////////////////////////////////// Current User - // FIX + SetAppShellDirectory(nsSpecialFileSpec::App_UserProfileDirectory50 ); break; - case 107: /////////////////////////////////////////////////////////// NetHelp - // FIX + case 107: /////////////////////////////////////////////////////////// Preferences + SetAppShellDirectory(nsSpecialFileSpec::App_PrefsDirectory50 ); break; case 108: /////////////////////////////////////////////////////////// OS Drive - *this = nsSpecialSystemDirectory::OS_DriveDirectory; + mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::OS_DriveDirectory )); break; case 109: /////////////////////////////////////////////////////////// File URL - // we should never be here. + { + nsString tempFileURLString = aFolderID; + tempFileURLString += aRelativePath; + mFileSpec = new nsFileSpec( nsFileURL(tempFileURLString) ); + } + break; + + case 110: /////////////////////////////////////////////////////////// Components + SetAppShellDirectory(nsSpecialFileSpec::App_ComponentsDirectory ); + break; + + case 111: /////////////////////////////////////////////////////////// Chrome + SetAppShellDirectory(nsSpecialFileSpec::App_ChromeDirectory ); break; case 200: /////////////////////////////////////////////////////////// Win System - *this = nsSpecialSystemDirectory::Win_SystemDirectory; + mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Win_SystemDirectory )); break; case 201: /////////////////////////////////////////////////////////// Windows - *this = nsSpecialSystemDirectory::Win_WindowsDirectory; + mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Win_WindowsDirectory )); break; case 300: /////////////////////////////////////////////////////////// Mac System - *this = nsSpecialSystemDirectory::Mac_SystemDirectory; + mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Mac_SystemDirectory )); break; case 301: /////////////////////////////////////////////////////////// Mac Desktop - *this = nsSpecialSystemDirectory::Mac_DesktopDirectory; + mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Mac_DesktopDirectory )); break; case 302: /////////////////////////////////////////////////////////// Mac Trash - *this = nsSpecialSystemDirectory::Mac_TrashDirectory; + mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Mac_TrashDirectory )); break; case 303: /////////////////////////////////////////////////////////// Mac Startup - *this = nsSpecialSystemDirectory::Mac_StartupDirectory; + mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Mac_StartupDirectory )); break; case 304: /////////////////////////////////////////////////////////// Mac Shutdown - *this = nsSpecialSystemDirectory::Mac_StartupDirectory; + mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Mac_StartupDirectory )); break; case 305: /////////////////////////////////////////////////////////// Mac Apple Menu - *this = nsSpecialSystemDirectory::Mac_AppleMenuDirectory; + mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Mac_AppleMenuDirectory )); break; case 306: /////////////////////////////////////////////////////////// Mac Control Panel - *this = nsSpecialSystemDirectory::Mac_ControlPanelDirectory; + mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Mac_ControlPanelDirectory )); break; case 307: /////////////////////////////////////////////////////////// Mac Extension - *this = nsSpecialSystemDirectory::Mac_ExtensionDirectory; + mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Mac_ExtensionDirectory )); break; case 308: /////////////////////////////////////////////////////////// Mac Fonts - *this = nsSpecialSystemDirectory::Mac_FontsDirectory; + mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Mac_FontsDirectory )); break; case 309: /////////////////////////////////////////////////////////// Mac Preferences - *this = nsSpecialSystemDirectory::Mac_PreferencesDirectory; + mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Mac_PreferencesDirectory )); break; case 310: /////////////////////////////////////////////////////////// Mac Documents - *this = nsSpecialSystemDirectory::Mac_DocumentsDirectory; + mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Mac_DocumentsDirectory )); break; case 400: /////////////////////////////////////////////////////////// Unix Local - *this = nsSpecialSystemDirectory::Unix_LocalDirectory; + mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Unix_LocalDirectory )); break; case 401: /////////////////////////////////////////////////////////// Unix Lib - *this = nsSpecialSystemDirectory::Unix_LibDirectory; + mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Unix_LibDirectory )); break; case -1: default: + mFileSpec = nsnull; return; } #ifndef XP_MAC @@ -271,11 +314,23 @@ nsInstallFolder::MapNameToEnum(const nsString& name) } +static NS_DEFINE_IID(kFileLocatorIID, NS_IFILELOCATOR_IID); +static NS_DEFINE_IID(kFileLocatorCID, NS_FILELOCATOR_CID); -//---------------------------------------------------------------------------------------- -void nsInstallFolder::operator = (enum nsSpecialSystemDirectory::SystemDirectories aSystemSystemDirectory) -//---------------------------------------------------------------------------------------- +void +nsInstallFolder::SetAppShellDirectory(PRUint32 value) { - nsSpecialSystemDirectory temp(aSystemSystemDirectory); - mFileSpec = new nsFileSpec(temp); -} + nsIFileLocator * appShellLocator; + + nsresult rv = nsComponentManager::CreateInstance(kFileLocatorCID, + nsnull, + kFileLocatorIID, + (void**) &appShellLocator); + + if ( NS_SUCCEEDED(rv) ) + { + mFileSpec = new nsFileSpec(); + appShellLocator->GetFileLocation(value, mFileSpec); + NS_RELEASE(appShellLocator); + } +} \ No newline at end of file diff --git a/xpinstall/src/nsInstallFolder.h b/xpinstall/src/nsInstallFolder.h index 96ac687cdda..df4cb9cb916 100644 --- a/xpinstall/src/nsInstallFolder.h +++ b/xpinstall/src/nsInstallFolder.h @@ -51,8 +51,7 @@ class nsInstallFolder void SetDirectoryPath(const nsString& aFolderID, const nsString& aRelativePath); void PickDefaultDirectory(); PRInt32 MapNameToEnum(const nsString& name); - - void operator = (enum nsSpecialSystemDirectory::SystemDirectories aSystemSystemDirectory); + void SetAppShellDirectory(PRUint32 value); }; diff --git a/xpinstall/src/nsInstallPatch.cpp b/xpinstall/src/nsInstallPatch.cpp index 9baff74a696..df1879040d2 100644 --- a/xpinstall/src/nsInstallPatch.cpp +++ b/xpinstall/src/nsInstallPatch.cpp @@ -62,7 +62,7 @@ static int32 gdiff_validateFile( pDIFFDATA dd, int file ); nsInstallPatch::nsInstallPatch( nsInstall* inInstall, const nsString& inVRName, - nsIDOMInstallVersion* inVInfo, + const nsString& inVInfo, const nsString& inJarLocation, PRInt32 *error) @@ -87,21 +87,18 @@ nsInstallPatch::nsInstallPatch( nsInstall* inInstall, mPatchedFile = nsnull; mRegistryName = new nsString(inVRName); mJarLocation = new nsString(inJarLocation); - - nsString tempString; - inVInfo->ToString(tempString); - mVersionInfo = new nsInstallVersion(); - mVersionInfo->Init(tempString); + mTargetFile = new nsFileSpec(folderSpec); - - mTargetFile = new nsFileSpec(folderSpec); + mVersionInfo = new nsInstallVersion(); + + mVersionInfo->Init(inVInfo); } nsInstallPatch::nsInstallPatch( nsInstall* inInstall, const nsString& inVRName, - nsIDOMInstallVersion* inVInfo, + const nsString& inVInfo, const nsString& inJarLocation, const nsString& folderSpec, const nsString& inPartialPath, @@ -120,15 +117,12 @@ nsInstallPatch::nsInstallPatch( nsInstall* inInstall, mPatchedFile = nsnull; mRegistryName = new nsString(inVRName); mJarLocation = new nsString(inJarLocation); - - nsString tempString; - inVInfo->ToString(tempString); - mVersionInfo = new nsInstallVersion(); - mVersionInfo->Init(tempString); + mVersionInfo = new nsInstallVersion(); - - mTargetFile = new nsFileSpec(folderSpec); - if(inPartialPath != "null") + mVersionInfo->Init(inVInfo); + + mTargetFile = new nsFileSpec(folderSpec); + if(inPartialPath != "null") *mTargetFile += inPartialPath; } @@ -216,7 +210,7 @@ PRInt32 nsInstallPatch::Prepare() if ( deleteOldSrc ) { - DeleteFileLater(*fileName ); + DeleteFileNowOrSchedule(*fileName ); } return err; @@ -239,7 +233,7 @@ PRInt32 nsInstallPatch::Complete() if (fileName != nsnull && (*fileName == *mPatchedFile) ) { // the patch has not been superceded--do final replacement - err = ReplaceFileLater( *mTargetFile, *mPatchedFile); + err = ReplaceFileNowOrSchedule( *mTargetFile, *mPatchedFile); if ( 0 == err || nsInstall::REBOOT_NEEDED == err ) { nsString tempVersionString; @@ -280,7 +274,7 @@ void nsInstallPatch::Abort() if (fileName != nsnull && (*fileName == *mPatchedFile) ) { - DeleteFileLater( *mPatchedFile ); + DeleteFileNowOrSchedule( *mPatchedFile ); } } diff --git a/xpinstall/src/nsInstallPatch.h b/xpinstall/src/nsInstallPatch.h index c422245bce9..14cfe7d645c 100644 --- a/xpinstall/src/nsInstallPatch.h +++ b/xpinstall/src/nsInstallPatch.h @@ -26,7 +26,7 @@ #include "nsInstall.h" #include "nsInstallFolder.h" -#include "nsIDOMInstallVersion.h" +#include "nsInstallVersion.h" class nsInstallPatch : public nsInstallObject @@ -35,7 +35,7 @@ class nsInstallPatch : public nsInstallObject nsInstallPatch( nsInstall* inInstall, const nsString& inVRName, - nsIDOMInstallVersion* inVInfo, + const nsString& inVInfo, const nsString& inJarLocation, const nsString& folderSpec, const nsString& inPartialPath, @@ -43,7 +43,7 @@ class nsInstallPatch : public nsInstallObject nsInstallPatch( nsInstall* inInstall, const nsString& inVRName, - nsIDOMInstallVersion* inVInfo, + const nsString& inVInfo, const nsString& inJarLocation, PRInt32 *error); diff --git a/xpinstall/src/nsInstallTrigger.cpp b/xpinstall/src/nsInstallTrigger.cpp index 356588059d2..756a281ef65 100644 --- a/xpinstall/src/nsInstallTrigger.cpp +++ b/xpinstall/src/nsInstallTrigger.cpp @@ -136,10 +136,8 @@ nsInstallTrigger::StartSoftwareUpdate(const nsString& aURL, PRInt32 aFlags, PRIn nsString localFile; CreateTempFileFromURL(aURL, localFile); - nsInstallInfo *nextInstall = new nsInstallInfo( aURL, localFile, aFlags); - // start the download (this will clean itself up) - nsSoftwareUpdateListener *downloader = new nsSoftwareUpdateListener(nextInstall); + nsSoftwareUpdateListener *downloader = new nsSoftwareUpdateListener(aURL, localFile, aFlags); *aReturn = NS_OK; // maybe we should do something more. return NS_OK; @@ -151,10 +149,8 @@ nsInstallTrigger::StartSoftwareUpdate(const nsString& aURL, PRInt32* aReturn) nsString localFile; CreateTempFileFromURL(aURL, localFile); - nsInstallInfo *nextInstall = new nsInstallInfo( aURL, localFile, 0); - // start the download (this will clean itself up) - nsSoftwareUpdateListener *downloader = new nsSoftwareUpdateListener(nextInstall); + nsSoftwareUpdateListener *downloader = new nsSoftwareUpdateListener(aURL, localFile, 0); *aReturn = NS_OK; // maybe we should do something more. return NS_OK; diff --git a/xpinstall/src/nsInstallUninstall.cpp b/xpinstall/src/nsInstallUninstall.cpp index 883b12f33b2..e05c769898a 100644 --- a/xpinstall/src/nsInstallUninstall.cpp +++ b/xpinstall/src/nsInstallUninstall.cpp @@ -182,14 +182,14 @@ REGERR su_UninstallProcessItem(char *component_path) else { err = VR_Remove(component_path); - DeleteFileLater(nsFileSpec(filepath)); + DeleteFileNowOrSchedule(nsFileSpec(filepath)); } } else { /* delete node and file */ err = VR_Remove(component_path); - DeleteFileLater(nsFileSpec(filepath)); + DeleteFileNowOrSchedule(nsFileSpec(filepath)); } } return err; diff --git a/xpinstall/src/nsJSInstall.cpp b/xpinstall/src/nsJSInstall.cpp index eea7c297ed7..feb2c77cb14 100644 --- a/xpinstall/src/nsJSInstall.cpp +++ b/xpinstall/src/nsJSInstall.cpp @@ -158,7 +158,10 @@ static void PR_CALLBACK FinalizeInstall(JSContext *cx, JSObject *obj) delete nativeThis; } -void nsCvrtJSValToStr(nsString& aString, +/***********************************************************************/ +/* JS Utilities */ +/***********************************************************************/ +void ConvertJSValToStr(nsString& aString, JSContext* aContext, jsval aValue) { @@ -169,11 +172,11 @@ void nsCvrtJSValToStr(nsString& aString, } else { - aString.Truncate(); + aString = ""; } } -void nsCvrtStrToJSVal(const nsString& aProp, +void ConvertStrToJSVal(const nsString& aProp, JSContext* aContext, jsval* aReturn) { @@ -182,7 +185,7 @@ void nsCvrtStrToJSVal(const nsString& aProp, *aReturn = STRING_TO_JSVAL(jsstring); } -PRBool nsCvrtJSValToBool(PRBool* aProp, +PRBool ConvertJSValToBool(PRBool* aProp, JSContext* aContext, jsval aValue) { @@ -200,7 +203,7 @@ PRBool nsCvrtJSValToBool(PRBool* aProp, return JS_TRUE; } -PRBool nsCvrtJSValToObj(nsISupports** aSupports, +PRBool ConvertJSValToObj(nsISupports** aSupports, REFNSIID aIID, const nsString& aTypeName, JSContext* aContext, @@ -237,6 +240,33 @@ PRBool nsCvrtJSValToObj(nsISupports** aSupports, } +void ConvertJSvalToVersionString(nsString& versionString, JSContext* cx, jsval argument) +{ + versionString = ""; + + if( JSVAL_IS_OBJECT(argument) ) + { + if(!JSVAL_IS_NULL(argument)) + { + JSObject* jsobj = JSVAL_TO_OBJECT(argument); + JSClass* jsclass = JS_GetClass(cx, jsobj); + + if ((nsnull != jsclass) && (jsclass->flags & JSCLASS_HAS_PRIVATE)) + { + nsIDOMInstallVersion* version = (nsIDOMInstallVersion*)JS_GetPrivate(cx, jsobj); + version->ToString(versionString); + } + } + } + else + { + ConvertJSValToStr(versionString, cx, argument); + } +} +/***********************************************************************/ +/***********************************************************************/ + + // // Native method AbortInstall // @@ -301,7 +331,7 @@ InstallAddDirectory(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval { // public int AddDirectory (String jarSourcePath) - nsCvrtJSValToStr(b0, cx, argv[0]); + ConvertJSValToStr(b0, cx, argv[0]); if(NS_OK != nativeThis->AddDirectory(b0, &nativeRet)) { @@ -317,10 +347,10 @@ InstallAddDirectory(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval // String localDirSpec, // String relativeLocalPath); - nsCvrtJSValToStr(b0, cx, argv[0]); - nsCvrtJSValToStr(b1, cx, argv[1]); - nsCvrtJSValToStr(b2, cx, argv[2]); - nsCvrtJSValToStr(b3, cx, argv[3]); + ConvertJSValToStr(b0, cx, argv[0]); + ConvertJSValToStr(b1, cx, argv[1]); + ConvertJSValToStr(b2, cx, argv[2]); + ConvertJSValToStr(b3, cx, argv[3]); if(NS_OK != nativeThis->AddDirectory(b0, b1, b2, b3, &nativeRet)) { @@ -337,38 +367,19 @@ InstallAddDirectory(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval // Object localDirSpec, // String relativeLocalPath); - nsCvrtJSValToStr(b0, cx, argv[0]); - nsCvrtJSValToStr(b2, cx, argv[2]); - nsCvrtJSValToStr(b3, cx, argv[3]); - nsCvrtJSValToStr(b4, cx, argv[4]); - - if(JSVAL_IS_OBJECT(argv[1])) + ConvertJSValToStr(b0, cx, argv[0]); + ConvertJSvalToVersionString(b1, cx, argv[1]); + ConvertJSValToStr(b2, cx, argv[2]); + ConvertJSValToStr(b3, cx, argv[3]); + ConvertJSValToStr(b4, cx, argv[4]); + + if(NS_OK != nativeThis->AddDirectory(b0, b1, b2, b3, b4, &nativeRet)) { - if(!JSVAL_IS_NULL(argv[1])) - { - JSObject* jsobj = JSVAL_TO_OBJECT(argv[1]); - JSClass* jsclass = JS_GetClass(cx, jsobj); - if ((nsnull != jsclass) && (jsclass->flags & JSCLASS_HAS_PRIVATE)) - { - nsIDOMInstallVersion* version = (nsIDOMInstallVersion*)JS_GetPrivate(cx, jsobj); - - if(NS_OK != nativeThis->AddDirectory(b0, version, b2, b3, b4, &nativeRet)) - { - return JS_FALSE; - } - } - } + return JS_FALSE; } - else - { - nsCvrtJSValToStr(b1, cx, argv[1]); - if(NS_OK != nativeThis->AddDirectory(b0, b1, b2, b3, b4, &nativeRet)) - { - return JS_FALSE; - } - } - + *rval = INT_TO_JSVAL(nativeRet); + } else if (argc == 6) { @@ -379,42 +390,22 @@ InstallAddDirectory(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval // String relativeLocalPath, // Boolean forceUpdate); - nsCvrtJSValToStr(b0, cx, argv[0]); - nsCvrtJSValToStr(b2, cx, argv[2]); - nsCvrtJSValToStr(b3, cx, argv[3]); - nsCvrtJSValToStr(b4, cx, argv[4]); + ConvertJSValToStr(b0, cx, argv[0]); + ConvertJSvalToVersionString(b1, cx, argv[1]); + ConvertJSValToStr(b2, cx, argv[2]); + ConvertJSValToStr(b3, cx, argv[3]); + ConvertJSValToStr(b4, cx, argv[4]); - if(!nsCvrtJSValToBool(&b5, cx, argv[5])) + if(!ConvertJSValToBool(&b5, cx, argv[5])) { return JS_FALSE; } - if(JSVAL_IS_OBJECT(argv[1])) + if(NS_OK != nativeThis->AddDirectory(b0, b1, b2, b3, b4, b5, &nativeRet)) { - if(!JSVAL_IS_NULL(argv[1])) - { - JSObject* jsobj = JSVAL_TO_OBJECT(argv[1]); - JSClass* jsclass = JS_GetClass(cx, jsobj); - if ((nsnull != jsclass) && (jsclass->flags & JSCLASS_HAS_PRIVATE)) - { - nsIDOMInstallVersion* version = (nsIDOMInstallVersion*)JS_GetPrivate(cx, jsobj); - - if(NS_OK != nativeThis->AddDirectory(b0, version, b2, b3, b4, b5, &nativeRet)) - { - return JS_FALSE; - } - } - } + return JS_FALSE; } - else - { - nsCvrtJSValToStr(b1, cx, argv[1]); - if(NS_OK != nativeThis->AddDirectory(b0, b1, b2, b3, b4, b5, &nativeRet)) - { - return JS_FALSE; - } - } - + *rval = INT_TO_JSVAL(nativeRet); } else @@ -459,40 +450,20 @@ InstallAddSubcomponent(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, js // String relativeLocalPath, // Boolean forceUpdate); - nsCvrtJSValToStr(b0, cx, argv[0]); - nsCvrtJSValToStr(b2, cx, argv[2]); - nsCvrtJSValToStr(b3, cx, argv[3]); - nsCvrtJSValToStr(b4, cx, argv[4]); + ConvertJSValToStr(b0, cx, argv[0]); + ConvertJSvalToVersionString(b1, cx, argv[1]); + ConvertJSValToStr(b2, cx, argv[2]); + ConvertJSValToStr(b3, cx, argv[3]); + ConvertJSValToStr(b4, cx, argv[4]); - if(!nsCvrtJSValToBool(&b5, cx, argv[5])) + if(!ConvertJSValToBool(&b5, cx, argv[5])) { return JS_FALSE; } - if(JSVAL_IS_OBJECT(argv[1])) + if(NS_OK != nativeThis->AddSubcomponent(b0, b1, b2, b3, b4, b5, &nativeRet)) { - if(!JSVAL_IS_NULL(argv[1])) - { - JSObject* jsobj = JSVAL_TO_OBJECT(argv[1]); - JSClass* jsclass = JS_GetClass(cx, jsobj); - if ((nsnull != jsclass) && (jsclass->flags & JSCLASS_HAS_PRIVATE)) - { - nsIDOMInstallVersion* version = (nsIDOMInstallVersion*)JS_GetPrivate(cx, jsobj); - - if(NS_OK != nativeThis->AddSubcomponent(b0, version, b2, b3, b4, b5, &nativeRet)) - { - return JS_FALSE; - } - } - } - } - else - { - nsCvrtJSValToStr(b1, cx, argv[1]); - if(NS_OK != nativeThis->AddSubcomponent(b0, b1, b2, b3, b4, b5, &nativeRet)) - { - return JS_FALSE; - } + return JS_FALSE; } *rval = INT_TO_JSVAL(nativeRet); @@ -505,37 +476,17 @@ InstallAddSubcomponent(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, js // Object localDirSpec, // String relativeLocalPath); - nsCvrtJSValToStr(b0, cx, argv[0]); - nsCvrtJSValToStr(b2, cx, argv[2]); - nsCvrtJSValToStr(b3, cx, argv[3]); - nsCvrtJSValToStr(b4, cx, argv[4]); + ConvertJSValToStr(b0, cx, argv[0]); + ConvertJSvalToVersionString(b1, cx, argv[1]); + ConvertJSValToStr(b2, cx, argv[2]); + ConvertJSValToStr(b3, cx, argv[3]); + ConvertJSValToStr(b4, cx, argv[4]); - if(JSVAL_IS_OBJECT(argv[1])) + if(NS_OK != nativeThis->AddSubcomponent(b0, b1, b2, b3, b4, &nativeRet)) { - if(!JSVAL_IS_NULL(argv[1])) - { - JSObject* jsobj = JSVAL_TO_OBJECT(argv[1]); - JSClass* jsclass = JS_GetClass(cx, jsobj); - if ((nsnull != jsclass) && (jsclass->flags & JSCLASS_HAS_PRIVATE)) - { - nsIDOMInstallVersion* version = (nsIDOMInstallVersion*)JS_GetPrivate(cx, jsobj); - - if(NS_OK != nativeThis->AddSubcomponent(b0, version, b2, b3, b4, &nativeRet)) - { - return JS_FALSE; - } - } - } - } - else - { - nsCvrtJSValToStr(b1, cx, argv[1]); - if(NS_OK != nativeThis->AddSubcomponent(b0, b1, b2, b3, b4, &nativeRet)) - { return JS_FALSE; - } } - + *rval = INT_TO_JSVAL(nativeRet); } else if(argc >= 4) @@ -545,10 +496,10 @@ InstallAddSubcomponent(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, js // Object localDirSpec, // String relativeLocalPath); - nsCvrtJSValToStr(b0, cx, argv[0]); - nsCvrtJSValToStr(b1, cx, argv[1]); - nsCvrtJSValToStr(b2, cx, argv[2]); - nsCvrtJSValToStr(b3, cx, argv[3]); + ConvertJSValToStr(b0, cx, argv[0]); + ConvertJSValToStr(b1, cx, argv[1]); + ConvertJSValToStr(b2, cx, argv[2]); + ConvertJSValToStr(b3, cx, argv[3]); if(NS_OK != nativeThis->AddSubcomponent(b0, b1, b2, b3, &nativeRet)) { @@ -561,7 +512,7 @@ InstallAddSubcomponent(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, js { // public int AddSubcomponent ( String jarSourcePath); - nsCvrtJSValToStr(b0, cx, argv[0]); + ConvertJSValToStr(b0, cx, argv[0]); if(NS_OK != nativeThis->AddSubcomponent(b0, &nativeRet)) { @@ -602,7 +553,7 @@ InstallDeleteComponent(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, js { // public int DeleteComponent ( String registryName); - nsCvrtJSValToStr(b0, cx, argv[0]); + ConvertJSValToStr(b0, cx, argv[0]); if(NS_OK != nativeThis->DeleteComponent(b0, &nativeRet)) { @@ -645,8 +596,8 @@ InstallDeleteFile(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval * // public int DeleteFile ( Object folder, // String relativeFileName); - nsCvrtJSValToStr(b0, cx, argv[0]); - nsCvrtJSValToStr(b1, cx, argv[1]); + ConvertJSValToStr(b0, cx, argv[0]); + ConvertJSValToStr(b1, cx, argv[1]); if(NS_OK != nativeThis->DeleteFile(b0, b1, &nativeRet)) { @@ -687,7 +638,7 @@ InstallDiskSpaceAvailable(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, { // public int DiskSpaceAvailable ( Object localDirSpec); - nsCvrtJSValToStr(b0, cx, argv[0]); + ConvertJSValToStr(b0, cx, argv[0]); if(NS_OK != nativeThis->DiskSpaceAvailable(b0, &nativeRet)) { @@ -730,8 +681,8 @@ InstallExecute(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rva // public int Execute ( String jarSourcePath, // String args); - nsCvrtJSValToStr(b0, cx, argv[0]); - nsCvrtJSValToStr(b1, cx, argv[1]); + ConvertJSValToStr(b0, cx, argv[0]); + ConvertJSValToStr(b1, cx, argv[1]); if(NS_OK != nativeThis->Execute(b0, b1, &nativeRet)) { @@ -744,7 +695,7 @@ InstallExecute(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rva { // public int Execute ( String jarSourcePath); - nsCvrtJSValToStr(b0, cx, argv[0]); + ConvertJSValToStr(b0, cx, argv[0]); if(NS_OK != nativeThis->Execute(b0, &nativeRet)) { @@ -824,7 +775,7 @@ InstallGestalt(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rva // public int Gestalt ( String selector, // long *response); - nsCvrtJSValToStr(b0, cx, argv[0]); + ConvertJSValToStr(b0, cx, argv[0]); if(NS_OK != nativeThis->Gestalt(b0, &nativeRet)) { @@ -867,8 +818,8 @@ InstallGetComponentFolder(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, // public int GetComponentFolder ( String registryName, // String subDirectory); - nsCvrtJSValToStr(b0, cx, argv[0]); - nsCvrtJSValToStr(b1, cx, argv[1]); + ConvertJSValToStr(b0, cx, argv[0]); + ConvertJSValToStr(b1, cx, argv[1]); if(NS_OK != nativeThis->GetComponentFolder(b0, b1, &nativeRet)) { @@ -878,13 +829,13 @@ InstallGetComponentFolder(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, if(nsnull == nativeRet) *rval = JSVAL_NULL; else - nsCvrtStrToJSVal(*nativeRet, cx, rval); + ConvertStrToJSVal(*nativeRet, cx, rval); } else if(argc >= 1) { // public int GetComponentFolder ( String registryName); - nsCvrtJSValToStr(b0, cx, argv[0]); + ConvertJSValToStr(b0, cx, argv[0]); if(NS_OK != nativeThis->GetComponentFolder(b0, &nativeRet)) { @@ -894,7 +845,7 @@ InstallGetComponentFolder(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, if(nsnull == nativeRet) *rval = JSVAL_NULL; else - nsCvrtStrToJSVal(*nativeRet, cx, rval); + ConvertStrToJSVal(*nativeRet, cx, rval); } else { @@ -930,8 +881,8 @@ InstallGetFolder(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *r // public int GetFolder ( String folderName, --OR-- Object localDirSpec, // String subDirectory); - nsCvrtJSValToStr(b0, cx, argv[0]); - nsCvrtJSValToStr(b1, cx, argv[1]); + ConvertJSValToStr(b0, cx, argv[0]); + ConvertJSValToStr(b1, cx, argv[1]); if(NS_OK != nativeThis->GetFolder(b0, b1, &nativeRet)) { @@ -941,13 +892,13 @@ InstallGetFolder(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *r if(nsnull == nativeRet) *rval = JSVAL_NULL; else - nsCvrtStrToJSVal(*nativeRet, cx, rval); + ConvertStrToJSVal(*nativeRet, cx, rval); } else if(argc >= 1) { // public int GetFolder ( String folderName); - nsCvrtJSValToStr(b0, cx, argv[0]); + ConvertJSValToStr(b0, cx, argv[0]); if(NS_OK != nativeThis->GetFolder(b0, &nativeRet)) { @@ -957,7 +908,7 @@ InstallGetFolder(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *r if(nsnull == nativeRet) *rval = JSVAL_NULL; else - nsCvrtStrToJSVal(*nativeRet, cx, rval); + ConvertStrToJSVal(*nativeRet, cx, rval); } else { @@ -1033,8 +984,8 @@ InstallGetWinProfile(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsva // public int GetWinProfile (Object folder, // String file); - nsCvrtJSValToStr(b0, cx, argv[0]); - nsCvrtJSValToStr(b1, cx, argv[1]); + ConvertJSValToStr(b0, cx, argv[0]); + ConvertJSValToStr(b1, cx, argv[1]); if(NS_OK != nativeThis->GetWinProfile(b0, b1, cx, &WinProfileClass, rval)) { @@ -1119,35 +1070,15 @@ InstallPatch(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) // Object localDirSpec, // String relativeLocalPath); - nsCvrtJSValToStr(b0, cx, argv[0]); - nsCvrtJSValToStr(b2, cx, argv[2]); - nsCvrtJSValToStr(b3, cx, argv[3]); - nsCvrtJSValToStr(b4, cx, argv[4]); + ConvertJSValToStr(b0, cx, argv[0]); + ConvertJSvalToVersionString(b1, cx, argv[1]); + ConvertJSValToStr(b2, cx, argv[2]); + ConvertJSValToStr(b3, cx, argv[3]); + ConvertJSValToStr(b4, cx, argv[4]); - if(JSVAL_IS_OBJECT(argv[1])) + if(NS_OK != nativeThis->Patch(b0, b1, b2, b3, b4, &nativeRet)) { - if(!JSVAL_IS_NULL(argv[1])) - { - JSObject* jsobj = JSVAL_TO_OBJECT(argv[1]); - JSClass* jsclass = JS_GetClass(cx, jsobj); - if ((nsnull != jsclass) && (jsclass->flags & JSCLASS_HAS_PRIVATE)) - { - nsIDOMInstallVersion* version = (nsIDOMInstallVersion*)JS_GetPrivate(cx, jsobj); - - if(NS_OK != nativeThis->Patch(b0, version, b2, b3, b4, &nativeRet)) - { - return JS_FALSE; - } - } - } - } - else - { - nsCvrtJSValToStr(b1, cx, argv[1]); - if(NS_OK != nativeThis->Patch(b0, b1, b2, b3, b4, &nativeRet)) - { return JS_FALSE; - } } *rval = INT_TO_JSVAL(nativeRet); @@ -1159,10 +1090,10 @@ InstallPatch(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) // Object localDirSpec, // String relativeLocalPath); - nsCvrtJSValToStr(b0, cx, argv[0]); - nsCvrtJSValToStr(b1, cx, argv[1]); - nsCvrtJSValToStr(b2, cx, argv[2]); - nsCvrtJSValToStr(b3, cx, argv[3]); + ConvertJSValToStr(b0, cx, argv[0]); + ConvertJSValToStr(b1, cx, argv[1]); + ConvertJSValToStr(b2, cx, argv[2]); + ConvertJSValToStr(b3, cx, argv[3]); if(NS_OK != nativeThis->Patch(b0, b1, b2, b3, &nativeRet)) { @@ -1239,7 +1170,7 @@ InstallSetPackageFolder(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, j { // public int SetPackageFolder (Object folder); - nsCvrtJSValToStr(b0, cx, argv[0]); + ConvertJSValToStr(b0, cx, argv[0]); if(NS_OK != nativeThis->SetPackageFolder(b0)) { @@ -1269,7 +1200,6 @@ InstallStartInstall(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval nsAutoString b0; nsAutoString b1; nsAutoString b2; - PRInt32 b3; *rval = JSVAL_NULL; @@ -1278,90 +1208,27 @@ InstallStartInstall(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval return JS_TRUE; } - if(argc >= 4) - { - // public int StartInstall (String userPackageName, - // String package, - // String version, --OR-- VersionInfo version, - // int flags); - - nsCvrtJSValToStr(b0, cx, argv[0]); - nsCvrtJSValToStr(b1, cx, argv[1]); - - if(!JS_ValueToInt32(cx, argv[3], (int32 *)&b3)) - { - JS_ReportError(cx, "Parameter must be a number"); - return JS_FALSE; - } - - if(JSVAL_IS_OBJECT(argv[2])) - { - if(!JSVAL_IS_NULL(argv[2])) - { - JSObject* jsobj = JSVAL_TO_OBJECT(argv[2]); - JSClass* jsclass = JS_GetClass(cx, jsobj); - if ((nsnull != jsclass) && (jsclass->flags & JSCLASS_HAS_PRIVATE)) - { - nsIDOMInstallVersion* version = (nsIDOMInstallVersion*)JS_GetPrivate(cx, jsobj); - - if(NS_OK != nativeThis->StartInstall(b0, b1, version, b3, &nativeRet)) - { - return JS_FALSE; - } - } - } - } - else - { - nsCvrtJSValToStr(b2, cx, argv[2]); - if(NS_OK != nativeThis->StartInstall(b0, b1, b2, b3, &nativeRet)) - { - return JS_FALSE; - } - } - - *rval = INT_TO_JSVAL(nativeRet); - } - else if(argc >= 3) + if(argc == 3 || argc == 4) { // public int StartInstall (String userPackageName, // String package, // String version); --OR-- VersionInfo version + // flags? + ConvertJSValToStr(b0, cx, argv[0]); + ConvertJSValToStr(b1, cx, argv[1]); + ConvertJSvalToVersionString(b2, cx, argv[2]); - nsCvrtJSValToStr(b0, cx, argv[0]); - nsCvrtJSValToStr(b1, cx, argv[1]); - - if(JSVAL_IS_OBJECT(argv[2])) + if(NS_OK != nativeThis->StartInstall(b0, b1, b2, &nativeRet)) { - if(!JSVAL_IS_NULL(argv[2])) - { - JSObject* jsobj = JSVAL_TO_OBJECT(argv[2]); - JSClass* jsclass = JS_GetClass(cx, jsobj); - if ((nsnull != jsclass) && (jsclass->flags & JSCLASS_HAS_PRIVATE)) - { - nsIDOMInstallVersion* version = (nsIDOMInstallVersion*)JS_GetPrivate(cx, jsobj); - - if(NS_OK != nativeThis->StartInstall(b0, b1, version, &nativeRet)) - { - return JS_FALSE; - } - } - } - } - else - { - nsCvrtJSValToStr(b2, cx, argv[2]); - if(NS_OK != nativeThis->StartInstall(b0, b1, b2, &nativeRet)) - { return JS_FALSE; - } } + *rval = INT_TO_JSVAL(nativeRet); } else { - JS_ReportError(cx, "Function StartInstall requires 4 parameters"); + JS_ReportError(cx, "Function StartInstall requires 3 parameters"); return JS_FALSE; } @@ -1391,7 +1258,7 @@ InstallUninstall(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *r { // public int Uninstall (String packageName); - nsCvrtJSValToStr(b0, cx, argv[0]); + ConvertJSValToStr(b0, cx, argv[0]); if(NS_OK != nativeThis->Uninstall(b0, &nativeRet)) { @@ -1417,7 +1284,7 @@ InstallTRACE(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { nsAutoString b0; - nsCvrtJSValToStr(b0, cx, argv[0]); + ConvertJSValToStr(b0, cx, argv[0]); char *tempStr; tempStr = b0.ToNewCString(); diff --git a/xpinstall/src/nsJSInstallTriggerGlobal.cpp b/xpinstall/src/nsJSInstallTriggerGlobal.cpp index ef3fa5c912d..55c78b41dd6 100644 --- a/xpinstall/src/nsJSInstallTriggerGlobal.cpp +++ b/xpinstall/src/nsJSInstallTriggerGlobal.cpp @@ -29,19 +29,19 @@ #include "nsIDOMInstallVersion.h" #include "nsIDOMInstallTriggerGlobal.h" -extern void nsCvrtJSValToStr(nsString& aString, +extern void ConvertJSValToStr(nsString& aString, JSContext* aContext, jsval aValue); -extern void nsCvrtStrToJSVal(const nsString& aProp, +extern void ConvertStrToJSVal(const nsString& aProp, JSContext* aContext, jsval* aReturn); -extern PRBool nsCvrtJSValToBool(PRBool* aProp, +extern PRBool ConvertJSValToBool(PRBool* aProp, JSContext* aContext, jsval aValue); -extern PRBool nsCvrtJSValToObj(nsISupports** aSupports, +extern PRBool ConvertJSValToObj(nsISupports** aSupports, REFNSIID aIID, const nsString& aTypeName, JSContext* aContext, @@ -199,7 +199,7 @@ InstallTriggerGlobalStartSoftwareUpdate(JSContext *cx, JSObject *obj, uintN argc // public int StartSoftwareUpdate(String url, // int flag); - nsCvrtJSValToStr(b0, cx, argv[0]); + ConvertJSValToStr(b0, cx, argv[0]); if(!JS_ValueToInt32(cx, argv[1], (int32 *)&b1)) { @@ -218,7 +218,7 @@ InstallTriggerGlobalStartSoftwareUpdate(JSContext *cx, JSObject *obj, uintN argc { // public int StartSoftwareUpdate(String url); - nsCvrtJSValToStr(b0, cx, argv[0]); + ConvertJSValToStr(b0, cx, argv[0]); if(NS_OK != nativeThis->StartSoftwareUpdate(b0, &nativeRet)) { @@ -269,8 +269,8 @@ InstallTriggerGlobalConditionalSoftwareUpdate(JSContext *cx, JSObject *obj, uint // String version, --OR-- VersionInfo version // int mode); - nsCvrtJSValToStr(b0, cx, argv[0]); - nsCvrtJSValToStr(b1, cx, argv[1]); + ConvertJSValToStr(b0, cx, argv[0]); + ConvertJSValToStr(b1, cx, argv[1]); if(!JS_ValueToInt32(cx, argv[2], (int32 *)&b2int)) { @@ -283,7 +283,7 @@ InstallTriggerGlobalConditionalSoftwareUpdate(JSContext *cx, JSObject *obj, uint JS_ReportError(cx, "5th parameter must be a number"); return JS_FALSE; } - + if(JSVAL_IS_OBJECT(argv[3])) { JSObject* jsobj = JSVAL_TO_OBJECT(argv[3]); @@ -300,7 +300,7 @@ InstallTriggerGlobalConditionalSoftwareUpdate(JSContext *cx, JSObject *obj, uint } else { - nsCvrtJSValToStr(b3str, cx, argv[3]); + ConvertJSValToStr(b3str, cx, argv[3]); if(NS_OK != nativeThis->ConditionalSoftwareUpdate(b0, b1, b2int, b3str, b4, &nativeRet)) { return JS_FALSE; @@ -316,8 +316,8 @@ InstallTriggerGlobalConditionalSoftwareUpdate(JSContext *cx, JSObject *obj, uint // String version, --OR-- VersionInfo version // int mode); - nsCvrtJSValToStr(b0, cx, argv[0]); - nsCvrtJSValToStr(b1, cx, argv[1]); + ConvertJSValToStr(b0, cx, argv[0]); + ConvertJSValToStr(b1, cx, argv[1]); if(!JS_ValueToInt32(cx, argv[3], (int32 *)&b3int)) { @@ -341,7 +341,7 @@ InstallTriggerGlobalConditionalSoftwareUpdate(JSContext *cx, JSObject *obj, uint } else { - nsCvrtJSValToStr(b2str, cx, argv[2]); + ConvertJSValToStr(b2str, cx, argv[2]); if(NS_OK != nativeThis->ConditionalSoftwareUpdate(b0, b1, b2str, b3int, &nativeRet)) { return JS_FALSE; @@ -356,8 +356,8 @@ InstallTriggerGlobalConditionalSoftwareUpdate(JSContext *cx, JSObject *obj, uint // String registryName, // String version); --OR-- VersionInfo version - nsCvrtJSValToStr(b0, cx, argv[0]); - nsCvrtJSValToStr(b1, cx, argv[1]); + ConvertJSValToStr(b0, cx, argv[0]); + ConvertJSValToStr(b1, cx, argv[1]); if(JSVAL_IS_OBJECT(argv[2])) { @@ -375,7 +375,7 @@ InstallTriggerGlobalConditionalSoftwareUpdate(JSContext *cx, JSObject *obj, uint } else { - nsCvrtJSValToStr(b2str, cx, argv[2]); + ConvertJSValToStr(b2str, cx, argv[2]); if(NS_OK != nativeThis->ConditionalSoftwareUpdate(b0, b1, b2str, &nativeRet)) { return JS_FALSE; @@ -425,7 +425,7 @@ InstallTriggerGlobalCompareVersion(JSContext *cx, JSObject *obj, uintN argc, jsv // int release, // int build); - nsCvrtJSValToStr(b0, cx, argv[0]); + ConvertJSValToStr(b0, cx, argv[0]); if(!JS_ValueToInt32(cx, argv[1], (int32 *)&b1int)) { @@ -460,7 +460,7 @@ InstallTriggerGlobalCompareVersion(JSContext *cx, JSObject *obj, uintN argc, jsv // public int CompareVersion(String registryName, // String version); --OR-- VersionInfo version - nsCvrtJSValToStr(b0, cx, argv[0]); + ConvertJSValToStr(b0, cx, argv[0]); if(JSVAL_IS_OBJECT(argv[1])) { @@ -478,7 +478,7 @@ InstallTriggerGlobalCompareVersion(JSContext *cx, JSObject *obj, uintN argc, jsv } else { - nsCvrtJSValToStr(b1str, cx, argv[1]); + ConvertJSValToStr(b1str, cx, argv[1]); if(NS_OK != nativeThis->CompareVersion(b0, b1str, &nativeRet)) { return JS_FALSE; diff --git a/xpinstall/src/nsJSInstallVersion.cpp b/xpinstall/src/nsJSInstallVersion.cpp index f0c1a3464fa..9c40f435a82 100644 --- a/xpinstall/src/nsJSInstallVersion.cpp +++ b/xpinstall/src/nsJSInstallVersion.cpp @@ -31,24 +31,26 @@ #include "nsRepository.h" #include "nsDOMCID.h" -extern void nsCvrtJSValToStr(nsString& aString, +extern void ConvertJSValToStr(nsString& aString, JSContext* aContext, jsval aValue); -extern void nsCvrtStrToJSVal(const nsString& aProp, +extern void ConvertStrToJSVal(const nsString& aProp, JSContext* aContext, jsval* aReturn); -extern PRBool nsCvrtJSValToBool(PRBool* aProp, +extern PRBool ConvertJSValToBool(PRBool* aProp, JSContext* aContext, jsval aValue); -extern PRBool nsCvrtJSValToObj(nsISupports** aSupports, +extern PRBool ConvertJSValToObj(nsISupports** aSupports, REFNSIID aIID, const nsString& aTypeName, JSContext* aContext, jsval aValue); +void ConvertJSvalToVersionString(nsString& versionString, JSContext* cx, jsval* argument); + static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID); static NS_DEFINE_IID(kIJSScriptObjectIID, NS_IJSSCRIPTOBJECT_IID); @@ -399,7 +401,7 @@ InstallVersionCompareTo(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, j if(JSVAL_IS_OBJECT(argv[0])) { - if(JS_FALSE == nsCvrtJSValToObj((nsISupports **)&versionObj, + if(JS_FALSE == ConvertJSValToObj((nsISupports **)&versionObj, kIInstallVersionIID, "InstallVersion", cx, @@ -415,7 +417,7 @@ InstallVersionCompareTo(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, j } else { - nsCvrtJSValToStr(b0str, cx, argv[0]); + ConvertJSValToStr(b0str, cx, argv[0]); if(NS_OK != nativeThis->CompareTo(b0str, &nativeRet)) { diff --git a/xpinstall/src/nsJSWinProfile.cpp b/xpinstall/src/nsJSWinProfile.cpp index 62c482b8bb5..925c5cdfd7f 100644 --- a/xpinstall/src/nsJSWinProfile.cpp +++ b/xpinstall/src/nsJSWinProfile.cpp @@ -25,19 +25,19 @@ #include "nsWinProfile.h" #include "nsJSWinProfile.h" -extern void nsCvrtJSValToStr(nsString& aString, +extern void ConvertJSValToStr(nsString& aString, JSContext* aContext, jsval aValue); -extern void nsCvrtStrToJSVal(const nsString& aProp, +extern void ConvertStrToJSVal(const nsString& aProp, JSContext* aContext, jsval* aReturn); -extern PRBool nsCvrtJSValToBool(PRBool* aProp, +extern PRBool ConvertJSValToBool(PRBool* aProp, JSContext* aContext, jsval aValue); -extern PRBool nsCvrtJSValToObj(nsISupports** aSupports, +extern PRBool ConvertJSValToObj(nsISupports** aSupports, REFNSIID aIID, const nsString& aTypeName, JSContext* aContext, @@ -77,12 +77,12 @@ WinProfileGetString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval // public int getString ( String section, // String key); - nsCvrtJSValToStr(b0, cx, argv[0]); - nsCvrtJSValToStr(b1, cx, argv[1]); + ConvertJSValToStr(b0, cx, argv[0]); + ConvertJSValToStr(b1, cx, argv[1]); nativeThis->getString(b0, b1, &nativeRet); - nsCvrtStrToJSVal(nativeRet, cx, rval); + ConvertStrToJSVal(nativeRet, cx, rval); } else { @@ -119,9 +119,9 @@ WinProfileWriteString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsv // String key, // String value); - nsCvrtJSValToStr(b0, cx, argv[0]); - nsCvrtJSValToStr(b1, cx, argv[1]); - nsCvrtJSValToStr(b2, cx, argv[2]); + ConvertJSValToStr(b0, cx, argv[0]); + ConvertJSValToStr(b1, cx, argv[1]); + ConvertJSValToStr(b2, cx, argv[2]); if(NS_OK != nativeThis->writeString(b0, b1, b2, &nativeRet)) { diff --git a/xpinstall/src/nsJSWinReg.cpp b/xpinstall/src/nsJSWinReg.cpp index 9d1f30ad9f0..811c4d04f35 100644 --- a/xpinstall/src/nsJSWinReg.cpp +++ b/xpinstall/src/nsJSWinReg.cpp @@ -27,19 +27,19 @@ static void PR_CALLBACK WinRegCleanup(JSContext *cx, JSObject *obj); -extern void nsCvrtJSValToStr(nsString& aString, +extern void ConvertJSValToStr(nsString& aString, JSContext* aContext, jsval aValue); -extern void nsCvrtStrToJSVal(const nsString& aProp, +extern void ConvertStrToJSVal(const nsString& aProp, JSContext* aContext, jsval* aReturn); -extern PRBool nsCvrtJSValToBool(PRBool* aProp, +extern PRBool ConvertJSValToBool(PRBool* aProp, JSContext* aContext, jsval aValue); -extern PRBool nsCvrtJSValToObj(nsISupports** aSupports, +extern PRBool ConvertJSValToObj(nsISupports** aSupports, REFNSIID aIID, const nsString& aTypeName, JSContext* aContext, @@ -124,8 +124,8 @@ WinRegCreateKey(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rv // public int createKey ( String subKey, // String className); - nsCvrtJSValToStr(b0, cx, argv[0]); - nsCvrtJSValToStr(b1, cx, argv[1]); + ConvertJSValToStr(b0, cx, argv[0]); + ConvertJSValToStr(b1, cx, argv[1]); if(NS_OK != nativeThis->createKey(b0, b1, &nativeRet)) { @@ -165,7 +165,7 @@ WinRegDeleteKey(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rv { // public int deleteKey ( String subKey); - nsCvrtJSValToStr(b0, cx, argv[0]); + ConvertJSValToStr(b0, cx, argv[0]); if(NS_OK != nativeThis->deleteKey(b0, &nativeRet)) { @@ -208,8 +208,8 @@ WinRegDeleteValue(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval * // public int deleteValue ( String subKey, // String valueName); - nsCvrtJSValToStr(b0, cx, argv[0]); - nsCvrtJSValToStr(b1, cx, argv[1]); + ConvertJSValToStr(b0, cx, argv[0]); + ConvertJSValToStr(b1, cx, argv[1]); if(NS_OK != nativeThis->deleteValue(b0, b1, &nativeRet)) { @@ -253,9 +253,9 @@ WinRegSetValueString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsva // String valueName, // String value); - nsCvrtJSValToStr(b0, cx, argv[0]); - nsCvrtJSValToStr(b1, cx, argv[1]); - nsCvrtJSValToStr(b2, cx, argv[2]); + ConvertJSValToStr(b0, cx, argv[0]); + ConvertJSValToStr(b1, cx, argv[1]); + ConvertJSValToStr(b2, cx, argv[2]); if(NS_OK != nativeThis->setValueString(b0, b1, b2, &nativeRet)) { @@ -297,8 +297,8 @@ WinRegGetValueString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsva // public int getValueString ( String subKey, // String valueName); - nsCvrtJSValToStr(b0, cx, argv[0]); - nsCvrtJSValToStr(b1, cx, argv[1]); + ConvertJSValToStr(b0, cx, argv[0]); + ConvertJSValToStr(b1, cx, argv[1]); if(NS_OK != nativeThis->getValueString(b0, b1, &nativeRet)) { @@ -342,12 +342,12 @@ WinRegSetValue(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rva // String valueName, // nsWinRegItem *value); - nsCvrtJSValToStr(b0, cx, argv[0]); - nsCvrtJSValToStr(b1, cx, argv[1]); + ConvertJSValToStr(b0, cx, argv[0]); + ConvertJSValToStr(b1, cx, argv[1]); // fix: this parameter is an object, not a string. // A way needs to be figured out to convert the JSVAL to this object type -// nsCvrtJSValToStr(b2, cx, argv[2]); +// ConvertJSValToStr(b2, cx, argv[2]); // if(NS_OK != nativeThis->setValue(b0, b1, b2, &nativeRet)) // { @@ -389,8 +389,8 @@ WinRegGetValue(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rva // public int getValue ( String subKey, // String valueName); - nsCvrtJSValToStr(b0, cx, argv[0]); - nsCvrtJSValToStr(b1, cx, argv[1]); + ConvertJSValToStr(b0, cx, argv[0]); + ConvertJSValToStr(b1, cx, argv[1]); if(NS_OK != nativeThis->getValue(b0, b1, &nativeRet)) { diff --git a/xpinstall/src/nsLoggingProgressNotifier.cpp b/xpinstall/src/nsLoggingProgressNotifier.cpp index 96be16e265f..dffccaf8561 100644 --- a/xpinstall/src/nsLoggingProgressNotifier.cpp +++ b/xpinstall/src/nsLoggingProgressNotifier.cpp @@ -35,22 +35,20 @@ nsLoggingProgressNotifier::nsLoggingProgressNotifier() { - nsSpecialSystemDirectory logFile(nsSpecialSystemDirectory::OS_CurrentProcessDirectory); - logFile += "Install.log"; - - mLogStream = new nsOutputFileStream(logFile, PR_WRONLY | PR_CREATE_FILE | PR_APPEND, 0744 ); - mLogStream->seek(logFile.GetFileSize()); } nsLoggingProgressNotifier::~nsLoggingProgressNotifier() { - mLogStream->close(); - delete mLogStream; } void nsLoggingProgressNotifier::BeforeJavascriptEvaluation(void) { + nsSpecialSystemDirectory logFile(nsSpecialSystemDirectory::OS_CurrentProcessDirectory); + logFile += "Install.log"; + + mLogStream = new nsOutputFileStream(logFile, PR_WRONLY | PR_CREATE_FILE | PR_APPEND, 0744 ); + mLogStream->seek(logFile.GetFileSize()); } void @@ -63,11 +61,17 @@ nsLoggingProgressNotifier::AfterJavascriptEvaluation(void) *mLogStream << " Finished Installation " << time << nsEndl << nsEndl; PL_strfree(time); + + mLogStream->close(); + delete mLogStream; + mLogStream = nsnull; } void nsLoggingProgressNotifier::InstallStarted(const char* UIPackageName) { + if (mLogStream == nsnull) return; + char* time; GetTime(&time); @@ -91,12 +95,16 @@ nsLoggingProgressNotifier::ItemScheduled(const char* message ) void nsLoggingProgressNotifier::InstallFinalization(const char* message, long itemNum, long totNum ) { - *mLogStream << " " << message << nsEndl; + if (mLogStream == nsnull) return; + + *mLogStream << " Item [" << (itemNum+1) << "/" << totNum << "]\t" << message << nsEndl; } void nsLoggingProgressNotifier::InstallAborted(void) { + if (mLogStream == nsnull) return; + char* time; GetTime(&time); diff --git a/xpinstall/src/nsSoftwareUpdateStream.cpp b/xpinstall/src/nsSoftwareUpdateStream.cpp index 29e871721a9..e69de29bb2d 100644 --- a/xpinstall/src/nsSoftwareUpdateStream.cpp +++ b/xpinstall/src/nsSoftwareUpdateStream.cpp @@ -1,163 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public License - * Version 1.0 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS IS" - * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See - * the License for the specific language governing rights and limitations - * under the License. - * - * The Original Code is Mozilla Communicator client code. - * - * The Initial Developer of the Original Code is Netscape Communications - * Corporation. Portions created by Netscape are Copyright (C) 1998 - * Netscape Communications Corporation. All Rights Reserved. - */ - -#include "nsSoftwareUpdateStream.h" -#include "nscore.h" -#include "nsFileSpec.h" -#include "nsVector.h" - -#include "nsISupports.h" -#include "nsIServiceManager.h" - -#include "nsIURL.h" -#include "nsINetlibURL.h" -#include "nsINetService.h" -#include "nsIInputStream.h" -#include "nsIStreamListener.h" - -#include "nsISoftwareUpdate.h" -#include "nsSoftwareUpdateIIDs.h" - - -static NS_DEFINE_IID(kISoftwareUpdateIID, NS_ISOFTWAREUPDATE_IID); -static NS_DEFINE_IID(kSoftwareUpdateCID, NS_SoftwareUpdate_CID); - - -nsSoftwareUpdateListener::nsSoftwareUpdateListener(nsInstallInfo *nextInstall) -{ - NS_INIT_REFCNT(); - - mInstallInfo = nextInstall; - mOutFileDesc = PR_Open(nsAutoCString(nextInstall->GetLocalFile()), PR_CREATE_FILE | PR_RDWR, 0744); - - if(mOutFileDesc == NULL) - { - mResult = -1; - }; - - mResult = nsServiceManager::GetService( kSoftwareUpdateCID, - kISoftwareUpdateIID, - (nsISupports**)&mSoftwareUpdate); - - if (NS_FAILED(mResult)) - return; - - nsIURL *pURL = nsnull; - mResult = NS_NewURL(&pURL, nextInstall->GetFromURL()); - - if (NS_FAILED(mResult)) - return; - - mResult = NS_OpenURL(pURL, this); -} - -nsSoftwareUpdateListener::~nsSoftwareUpdateListener() -{ - delete mInstallInfo; - mSoftwareUpdate->Release(); -} - - -NS_IMPL_ISUPPORTS( nsSoftwareUpdateListener, kIStreamListenerIID ) - -NS_IMETHODIMP -nsSoftwareUpdateListener::GetBindInfo(nsIURL* aURL, nsStreamBindingInfo* info) -{ - return NS_OK; -} - -NS_IMETHODIMP -nsSoftwareUpdateListener::OnProgress( nsIURL* aURL, - PRUint32 Progress, - PRUint32 ProgressMax) -{ - return NS_OK; -} - -NS_IMETHODIMP -nsSoftwareUpdateListener::OnStatus(nsIURL* aURL, - const PRUnichar* aMsg) -{ - return NS_OK; -} - -NS_IMETHODIMP -nsSoftwareUpdateListener::OnStartBinding(nsIURL* aURL, - const char *aContentType) -{ - return NS_OK; -} - -NS_IMETHODIMP -nsSoftwareUpdateListener::OnStopBinding(nsIURL* aURL, - nsresult status, - const PRUnichar* aMsg) -{ - switch( status ) - { - - case NS_BINDING_SUCCEEDED: - PR_Close(mOutFileDesc); - // Add to the XPInstall Queue. Yes this is a bit redunant. I be you are asking, why I have a nsInstallInfo, am - // creating a new one. well, if I pull this out into its own dll, I would not want to pass a class around. - - mSoftwareUpdate->InstallJar(mInstallInfo->GetFromURL(), - mInstallInfo->GetLocalFile(), - mInstallInfo->GetFlags() ); - break; - - case NS_BINDING_FAILED: - case NS_BINDING_ABORTED: - mResult = status; - PR_Close(mOutFileDesc); - break; - - default: - mResult = NS_ERROR_ILLEGAL_VALUE; - } - - return mResult; -} - -#define BUF_SIZE 1024 - -NS_IMETHODIMP -nsSoftwareUpdateListener::OnDataAvailable(nsIURL* aURL, nsIInputStream *pIStream, PRUint32 length) -{ - PRUint32 len; - nsresult err; - char buffer[BUF_SIZE]; - - do - { - err = pIStream->Read(buffer, BUF_SIZE, &len); - - if (mResult == 0 && err == 0) - { - if ( PR_Write(mOutFileDesc, buffer, len) == -1 ) - { - /* Error */ - return -1; - } - } - - } while (len > 0 && err == NS_OK); - - return 0; -} \ No newline at end of file diff --git a/xpinstall/src/nsSoftwareUpdateStream.h b/xpinstall/src/nsSoftwareUpdateStream.h index 563175d0937..e69de29bb2d 100644 --- a/xpinstall/src/nsSoftwareUpdateStream.h +++ b/xpinstall/src/nsSoftwareUpdateStream.h @@ -1,75 +0,0 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public License - * Version 1.0 (the "NPL"); you may not use this file except in - * compliance with the NPL. You may obtain a copy of the NPL at - * http://www.mozilla.org/NPL/ - * - * Software distributed under the NPL is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL - * for the specific language governing rights and limitations under the - * NPL. - * - * The Initial Developer of this code under the NPL is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All Rights - * Reserved. - */ - -#ifndef _NS_SOFTWAREUPDATESTREAM_H__ -#define _NS_SOFTWAREUPDATESTREAM_H__ - -#include "nsInstall.h" - -#include "nscore.h" -#include "nsISupports.h" -#include "nsString.h" - -#include "nsIURL.h" -#include "nsINetlibURL.h" -#include "nsINetService.h" -#include "nsIInputStream.h" -#include "nsIStreamListener.h" - -#include "nsISoftwareUpdate.h" - -static NS_DEFINE_IID(kInetServiceIID, NS_INETSERVICE_IID); -static NS_DEFINE_IID(kInetServiceCID, NS_NETSERVICE_CID); -static NS_DEFINE_IID(kInetLibURLIID, NS_INETLIBURL_IID); -static NS_DEFINE_IID(kIStreamListenerIID, NS_ISTREAMLISTENER_IID); - - -extern "C" nsresult DownloadJar(nsInstallInfo *nextInstall); - - -class nsSoftwareUpdateListener : public nsIStreamListener -{ - - public: - NS_DECL_ISUPPORTS - - nsSoftwareUpdateListener(nsInstallInfo *nextInstall); - - NS_IMETHOD GetBindInfo(nsIURL* aURL, nsStreamBindingInfo* info); - NS_IMETHOD OnProgress(nsIURL* aURL, PRUint32 Progress, PRUint32 ProgressMax); - NS_IMETHOD OnStatus(nsIURL* aURL, const PRUnichar* aMsg); - NS_IMETHOD OnStartBinding(nsIURL* aURL, const char *aContentType); - NS_IMETHOD OnDataAvailable(nsIURL* aURL, nsIInputStream *pIStream, PRUint32 length); - NS_IMETHOD OnStopBinding(nsIURL* aURL, nsresult status, const PRUnichar* aMsg); - - - - - protected: - virtual ~nsSoftwareUpdateListener(); - - - private: - - nsISoftwareUpdate *mSoftwareUpdate; - PRFileDesc *mOutFileDesc; - nsInstallInfo *mInstallInfo; - PRInt32 mResult; -}; - -#endif \ No newline at end of file diff --git a/xpinstall/standalone/standalone.cpp b/xpinstall/standalone/standalone.cpp index 865169c51ba..63231764a4b 100644 --- a/xpinstall/standalone/standalone.cpp +++ b/xpinstall/standalone/standalone.cpp @@ -36,8 +36,8 @@ #include "nsSoftwareUpdateIIDs.h" static nsISoftwareUpdate *softwareUpdate= NULL; -static NS_DEFINE_IID(kISoftwareUpdateIID, NS_ISOFTWAREUPDATE_IID); -static NS_DEFINE_IID(kSoftwareUpdateCID, NS_SoftwareUpdate_CID); +static NS_DEFINE_IID(kFileLocatorIID, NS_IFILELOCATOR_IID); +static NS_DEFINE_IID(kFileLocatorCID, NS_FILELOCATOR_CID); /*********************************************/