97334 - new flag WIN_SYSTEM_FILE for addFile

r=dougt sr=dveditz a=asa
This commit is contained in:
dprice%netscape.com 2002-03-22 23:06:34 +00:00
parent 9d9ec89d2c
commit b3b549037f
5 changed files with 46 additions and 55 deletions

View File

@ -35,6 +35,7 @@
#include "nsSpecialSystemDirectory.h"
#include "nsDirectoryService.h"
#include "nsDirectoryServiceDefs.h"
#include "nsAppDirectoryServiceDefs.h"
static nsresult
GetPersistentStringFromSpec(nsIFile* inSpec, char **string)
@ -62,31 +63,20 @@ GetPersistentStringFromSpec(nsIFile* inSpec, char **string)
#include <sys/stat.h>
#include <windows.h>
PRInt32 ReplaceExistingWindowsFile(nsIFile* currentSpec, nsIFile* finalSpec)
PRInt32 ReplaceWindowsSystemFile(nsIFile* currentSpec, nsIFile* finalSpec)
{
// this routine is now for DOS-based windows only. WinNT should
// be taken care of by the XP code
//
// NOTE for WINNT:
//
// the MOVEFILE_DELAY_UNTIL_REBOOT option doesn't work on
// NT 3.51 SP4 or on NT 4.0 until SP2. On the broken versions
// of NT 4.0 Microsoft warns using it can lead to an irreparably
// corrupt windows' registry "after an unknown number of calls".
// Time to reinstall windows when that happens.
//
// I don't want to risk it, I also don't want two separate code
// paths to test, so we do it the lame way on all NT systems
// until such time as there are few enough old revs around to
// make it worth switching back to MoveFileEx().
PRInt32 err = -1;
/* Get OS version info */
// Get OS version info
DWORD dwVersion = GetVersion();
/* Get build numbers for Windows NT or Win32s */
char *final;
char *current;
finalSpec->GetPath(&final);
currentSpec->GetPath(&current);
// Get build numbers for Windows NT or Win32s
if (dwVersion > 0x80000000)
{
// Windows 95 or Win16
@ -97,42 +87,39 @@ PRInt32 ReplaceExistingWindowsFile(nsIFile* currentSpec, nsIFile* finalSpec)
int strlen;
char Src[_MAX_PATH]; // 8.3 name
char Dest[_MAX_PATH]; // 8.3 name
char* final;
char* current;
finalSpec->GetPath(&final);
currentSpec->GetPath(&current);
strlen = GetShortPathName( (LPCTSTR)current, (LPTSTR)Src, (DWORD)sizeof(Src) );
if ( strlen > 0 )
{
free(current);
current = strdup(Src);
current = strdup(Src);
}
strlen = GetShortPathName( (LPCTSTR) final, (LPTSTR) Dest, (DWORD) sizeof(Dest));
strlen = GetShortPathName( (LPCTSTR)final, (LPTSTR)Dest, (DWORD)sizeof(Dest) );
if ( strlen > 0 )
{
free(final);
final = strdup(Dest);
final = strdup(Dest);
}
/* NOTE: use OEM filenames! Even though it looks like a Windows
* .INI file, WININIT.INI is processed under DOS
*/
// 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);
}
else
{
// Windows NT
if ( MoveFileEx(final, current, MOVEFILE_DELAY_UNTIL_REBOOT) )
err = 0;
}
free(final);
free(current);
return err;
}
#endif
@ -348,7 +335,7 @@ PRInt32 ReplaceFileNow(nsIFile* replacementFile, nsIFile* doomedFile )
PRInt32 ReplaceFileNowOrSchedule(nsIFile* replacementFile, nsIFile* doomedFile )
PRInt32 ReplaceFileNowOrSchedule(nsIFile* replacementFile, nsIFile* doomedFile, PRInt32 aMode )
{
PRInt32 result = ReplaceFileNow( replacementFile, doomedFile );
@ -356,8 +343,9 @@ PRInt32 ReplaceFileNowOrSchedule(nsIFile* replacementFile, nsIFile* doomedFile )
{
// if we couldn't replace the file schedule it for later
#ifdef _WINDOWS
if ( ReplaceExistingWindowsFile(replacementFile, doomedFile) == 0 )
return nsInstall::REBOOT_NEEDED;
if ( (aMode & WIN_SYSTEM_FILE) &&
(ReplaceWindowsSystemFile(replacementFile, doomedFile) == 0) )
return nsInstall::REBOOT_NEEDED;
#endif
RKEY listkey;
@ -450,7 +438,7 @@ void DeleteScheduledFiles( HREG reg )
REGENUM state = 0;
nsresult rv = NS_OK;
/* perform scheduled file deletions */
// perform scheduled file deletions
if (REGERR_OK == NR_RegGetKey(reg,ROOTKEY_PRIVATE,REG_DELETE_LIST_KEY,&key))
{
// the delete key exists, so we loop through its children
@ -490,7 +478,7 @@ void DeleteScheduledFiles( HREG reg )
}
}
/* delete list node if empty */
// delete list node if empty
state = 0;
err = NR_RegEnumEntries(reg, key, &state, namebuf, sizeof(namebuf), 0);
if ( err == REGERR_NOMORE )
@ -507,7 +495,7 @@ void ReplaceScheduledFiles( HREG reg )
{
RKEY key;
/* replace files if any listed */
// replace files if any listed
if (REGERR_OK == NR_RegGetKey(reg,ROOTKEY_PRIVATE,REG_REPLACE_LIST_KEY,&key))
{
char keyname[MAXREGNAMELEN];
@ -557,7 +545,7 @@ void ReplaceScheduledFiles( HREG reg )
}
/* delete list node if empty */
// delete list node if empty
state = 0;
if (REGERR_NOMORE == NR_RegEnumSubkeys( reg, key, &state, keyname,
sizeof(keyname), REGENUM_CHILDREN ))

View File

@ -36,7 +36,7 @@
PR_BEGIN_EXTERN_C
PRInt32 DeleteFileNowOrSchedule(nsIFile* filename);
PRInt32 ReplaceFileNowOrSchedule(nsIFile* tmpfile, nsIFile* target );
PRInt32 ReplaceFileNowOrSchedule(nsIFile* tmpfile, nsIFile* target, PRInt32 aMode);
PRInt32 ScheduleFileForDeletion(nsIFile* filename);
char* GetRegFilePath();

View File

@ -120,6 +120,11 @@ class nsInstallInfo
#define FILESEP '/'
#endif
// not using 0x1 in this bitfield because it causes problems with legacy code
#define DO_NOT_UNINSTALL 0x2
#define WIN_SHARED_FILE 0x4
#define WIN_SYSTEM_FILE 0x8
class nsInstall
{
friend class nsWinReg;
@ -185,10 +190,7 @@ class nsInstall
GESTALT_INVALID_ARGUMENT = -5551,
SUCCESS = 0,
REBOOT_NEEDED = 999,
DO_NOT_UNINSTALL = 2,
WIN_SHARED_FILE = 4
REBOOT_NEEDED = 999
};

View File

@ -324,7 +324,7 @@ char* nsInstallFile::toString()
if (mReplaceFile)
{
if(mMode & nsInstall::WIN_SHARED_FILE)
if(mMode & WIN_SHARED_FILE)
{
rsrcVal = mInstall->GetResourcedString(NS_LITERAL_STRING("ReplaceSharedFile"));
}
@ -335,7 +335,7 @@ char* nsInstallFile::toString()
}
else
{
if(mMode & nsInstall::WIN_SHARED_FILE)
if(mMode & WIN_SHARED_FILE)
{
rsrcVal = mInstall->GetResourcedString(NS_LITERAL_STRING("InstallSharedFile"));
}
@ -350,7 +350,7 @@ char* nsInstallFile::toString()
char* interimCStr = nsnull;
nsString interimStr;
if(mMode & nsInstall::DO_NOT_UNINSTALL)
if(mMode & DO_NOT_UNINSTALL)
interimStr.Assign(NS_LITERAL_STRING("(*dnu*) "));
interimStr.AppendWithConversion(rsrcVal);
@ -391,10 +391,10 @@ PRInt32 nsInstallFile::CompleteFileMove()
}
else
{
result = ReplaceFileNowOrSchedule(mExtractedFile, mFinalFile );
result = ReplaceFileNowOrSchedule(mExtractedFile, mFinalFile, mMode );
}
if(mMode & nsInstall::WIN_SHARED_FILE)
if(mMode & WIN_SHARED_FILE)
{
nsXPIDLCString path;
mFinalFile->GetPath(getter_Copies(path));

View File

@ -1784,8 +1784,9 @@ static JSConstDoubleSpec install_constants[] =
{ nsInstall::REBOOT_NEEDED, "REBOOT_NEEDED" },
// these are bitwise values supported by addFile
{ nsInstall::DO_NOT_UNINSTALL, "DO_NOT_UNINSTALL" },
{ nsInstall::WIN_SHARED_FILE, "WIN_SHARED_FILE" },
{ DO_NOT_UNINSTALL, "DO_NOT_UNINSTALL" },
{ WIN_SHARED_FILE, "WIN_SHARED_FILE" },
{ WIN_SYSTEM_FILE, "WIN_SYSTEM_FILE" },
{ CHROME_SKIN, "SKIN" },
{ CHROME_LOCALE, "LOCALE" },