Made ScheduledTasks to more work to reduce code bloat.

git-svn-id: svn://10.0.0.236/branches/XPINSTALL_DEV_BRANCH@26483 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
dougt%netscape.com
1999-04-06 18:22:41 +00:00
parent 484757e362
commit 98940c6172
8 changed files with 75 additions and 143 deletions

View File

@@ -27,25 +27,35 @@
#include "NSReg.h"
#include "nsFileSpec.h"
#include "nsFileStream.h"
#include "nsInstall.h" // for error codes
REGERR DeleteFileLater(nsFileSpec& filename)
{
RKEY newkey;
REGERR result = -1;
HREG reg;
if ( REGERR_OK == NR_RegOpen("", &reg) )
REGERR result = 0;
filename.Delete(false);
if (filename.Exists())
{
if (REGERR_OK == NR_RegAddKey( reg, ROOTKEY_PRIVATE, REG_DELETE_LIST_KEY, &newkey) )
RKEY newkey;
HREG reg;
if ( REGERR_OK == NR_RegOpen("", &reg) )
{
nsPersistentFileDescriptor savethis(filename);
char* buffer;
nsOutputStringStream s(buffer);
s << savethis;
if (REGERR_OK == NR_RegAddKey( reg, ROOTKEY_PRIVATE, REG_DELETE_LIST_KEY, &newkey) )
{
nsPersistentFileDescriptor savethis(filename);
char* buffer;
nsOutputStringStream s(buffer);
s << savethis;
result = NR_RegSetEntry( reg, newkey, "", REGTYPE_ENTRY_BYTES, buffer, strlen(buffer));
result = NR_RegSetEntry( reg, newkey, "", REGTYPE_ENTRY_BYTES, buffer, strlen(buffer));
if (result == REGERR_OK)
result = nsInstall::REBOOT_NEEDED;
}
NR_RegClose(reg);
}
NR_RegClose(reg);
}
return result;
@@ -53,31 +63,52 @@ REGERR DeleteFileLater(nsFileSpec& filename)
REGERR ReplaceFileLater(nsFileSpec& tmpfile, nsFileSpec& target )
{
RKEY newkey;
REGERR result;
HREG reg;
if ( REGERR_OK == NR_RegOpen("", &reg) )
REGERR result = 0;
if (! target.Exists() )
{
result = NR_RegAddKey( reg, ROOTKEY_PRIVATE, REG_REPLACE_LIST_KEY, &newkey);
if ( result == REGERR_OK )
{
nsPersistentFileDescriptor tempDesc(tmpfile);
nsPersistentFileDescriptor targDesc(target);
char* tempBuffer;
char* targBuffer;
// Now that we have move the existing file, we can move the mExtracedFile into place.
nsFileSpec parentofFinalFile;
nsOutputStringStream tempStream(tempBuffer);
nsOutputStringStream targStream(targBuffer);
tempStream << tempDesc;
targStream << targDesc;
result = NR_RegSetEntry( reg, newkey, tempBuffer, REGTYPE_ENTRY_BYTES, targBuffer, strlen(targBuffer));
}
NR_RegClose(reg);
target.GetParent(parentofFinalFile);
result = tmpfile.Move(parentofFinalFile);
char* leafName = target.GetLeafName();
tmpfile.Rename(leafName);
delete [] leafName;
}
else
{
RKEY newkey;
HREG reg;
if ( REGERR_OK == NR_RegOpen("", &reg) )
{
result = NR_RegAddKey( reg, ROOTKEY_PRIVATE, REG_REPLACE_LIST_KEY, &newkey);
if ( result == REGERR_OK )
{
nsPersistentFileDescriptor tempDesc(tmpfile);
nsPersistentFileDescriptor targDesc(target);
char* tempBuffer;
char* targBuffer;
nsOutputStringStream tempStream(tempBuffer);
nsOutputStringStream targStream(targBuffer);
tempStream << tempDesc;
targStream << targDesc;
result = NR_RegSetEntry( reg, newkey, tempBuffer, REGTYPE_ENTRY_BYTES, targBuffer, strlen(targBuffer));
if (result == REGERR_OK)
result = nsInstall::REBOOT_NEEDED;
}
NR_RegClose(reg);
}
}
return result;
}

View File

@@ -36,7 +36,7 @@ REGERR DeleteFileLater(nsFileSpec& filename);
REGERR ReplaceFileLater(nsFileSpec& tmpfile, nsFileSpec& target );
extern "C" void PerformScheduledTasks(void *data)
extern "C" void PerformScheduledTasks(void *data);
#endif

View File

@@ -222,14 +222,7 @@ PRInt32 nsInstallDelete::NativeComplete()
{
if (mFinalFile->IsFile())
{
mFinalFile->Delete(false);
if (mFinalFile->Exists())
{
// If file still exists, we need to delete it later!
DeleteFileLater(*mFinalFile);
return nsInstall::REBOOT_NEEDED;
}
return DeleteFileLater(*mFinalFile);
}
else
{

View File

@@ -98,12 +98,7 @@ void nsInstallExecute::Abort()
if (mExecutableFile == nsnull)
return;
mExecutableFile->Delete(PR_FALSE);
if ( mExecutableFile->Exists() )
{
DeleteFileLater(*mExecutableFile);
}
DeleteFileLater(*mExecutableFile);
}
char* nsInstallExecute::toString()

View File

@@ -200,41 +200,7 @@ PRInt32 nsInstallFile::CompleteFileMove()
}
else
{
if (mFinalFile->Exists() == PR_FALSE)
{
// We can simple move the extracted file to the mFinalFile's parent
nsFileSpec parentofFinalFile;
mFinalFile->GetParent(parentofFinalFile);
result = mExtracedFile->Move(parentofFinalFile);
char* leafName = mFinalFile->GetLeafName();
mExtracedFile->Rename(leafName);
delete [] leafName;
}
else
{
mFinalFile->Delete(PR_FALSE);
if (! mFinalFile->Exists())
{
// Now that we have move the existing file, we can move the mExtracedFile into place.
nsFileSpec parentofFinalFile;
mFinalFile->GetParent(parentofFinalFile);
result = mExtracedFile->Move(parentofFinalFile);
char* leafName = mFinalFile->GetLeafName();
mExtracedFile->Rename(leafName);
delete [] leafName;
}
else
{
ReplaceFileLater(*mExtracedFile, *mFinalFile );
result = nsInstall::REBOOT_NEEDED;
}
}
result = ReplaceFileLater(*mExtracedFile, *mFinalFile );
}
return result;

View File

@@ -183,7 +183,7 @@ PRInt32 nsInstallPatch::Prepare()
if ( deleteOldSrc )
{
NativeDeleteFile( fileName );
DeleteFileLater(*fileName );
}
return err;
@@ -206,7 +206,7 @@ PRInt32 nsInstallPatch::Complete()
if (fileName != nsnull && (*fileName == *mPatchedFile) )
{
// the patch has not been superceded--do final replacement
err = NativeReplace( *mTargetFile, *mPatchedFile );
err = ReplaceFileLater( *mTargetFile, *mPatchedFile );
if ( 0 == err || nsInstall::REBOOT_NEEDED == err )
{
nsString tempVersionString;
@@ -247,7 +247,7 @@ void nsInstallPatch::Abort()
if (fileName != nsnull && (*fileName == *mPatchedFile) )
{
NativeDeleteFile( mPatchedFile );
DeleteFileLater( *mPatchedFile );
}
}
@@ -279,58 +279,6 @@ nsInstallPatch::NativePatch(const nsFileSpec &sourceFile, const nsFileSpec &patc
return -1;
}
PRInt32
nsInstallPatch::NativeDeleteFile(nsFileSpec* doomedFile)
{
if (doomedFile->Exists())
{
if (doomedFile->IsFile())
{
doomedFile->Delete(false);
if (doomedFile->Exists())
{
// If file still exists, we need to delete it later!
DeleteFileLater(*doomedFile);
return nsInstall::REBOOT_NEEDED;
}
}
else
{
return nsInstall::FILE_IS_DIRECTORY;
}
}
return nsInstall::FILE_DOES_NOT_EXIST;
}
PRInt32
nsInstallPatch::NativeReplace(nsFileSpec& oldfile, nsFileSpec& newFile)
{
oldfile.Delete(PR_FALSE);
if (oldfile.Exists())
{
ReplaceFileLater(newFile, oldfile);
return nsInstall::REBOOT_NEEDED;
}
else
{
// We can simple move the extracted file to the mFinalFile's parent
nsFileSpec parentofFinalFile;
oldfile.GetParent(parentofFinalFile);
newFile.Move(parentofFinalFile);
char* leafName = newFile.GetLeafName();
newFile.Rename(leafName);
delete [] leafName;
}
return nsInstall::SUCCESS;
}
void*
nsInstallPatch::HashFilePath(const nsFilePath& aPath)
{

View File

@@ -73,8 +73,6 @@ class nsInstallPatch : public nsInstallObject
PRInt32 NativePatch(const nsFileSpec &sourceFile, const nsFileSpec &patchfile, nsFileSpec **newFile);
PRInt32 NativeReplace(nsFileSpec& target, nsFileSpec& tempFile);
PRInt32 NativeDeleteFile(nsFileSpec* doomedFile);
void* HashFilePath(const nsFilePath& aPath);
};

View File

@@ -146,7 +146,7 @@ nsSoftwareUpdate::Startup()
/* Perform Scheduled Tasks */
/***************************************/
#if 0
PR_CreateThread(PR_USER_THREAD,
PerformScheduledTasks,
nsnull,
@@ -154,7 +154,8 @@ nsSoftwareUpdate::Startup()
PR_GLOBAL_THREAD,
PR_UNJOINABLE_THREAD,
0);
#endif
PerformScheduledTasks(nsnull);
return NS_OK;
}