Skip to content

Commit

Permalink
Rename some variables for clarity.
Browse files Browse the repository at this point in the history
  • Loading branch information
martijnlaan committed Jul 3, 2020
1 parent 8a3ee1d commit 961b3b7
Showing 1 changed file with 31 additions and 33 deletions.
64 changes: 31 additions & 33 deletions Projects/Uninstall.pas
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

{
Inno Setup
Copyright (C) 1997-2012 Jordan Russell
Copyright (C) 1997-2020 Jordan Russell
Portions by Martijn Laan
For conditions of distribution and use, see LICENSE.TXT.
Uninstaller
NOTE: This unit was derived from Uninst.dpr rev 1.38.
}

interface
Expand Down Expand Up @@ -41,8 +39,8 @@ TExtUninstallLog = class(TUninstallLog)

var
UninstallExitCode: DWORD = 1;
UninstExeFile, UninstDataFile, UninstMsgFile: String;
UninstLogFile: TFile;
UninstExeFilename, UninstDataFilename, UninstMsgFilename: String;
UninstDataFile: TFile;
UninstLog: TExtUninstallLog = nil;
Title: String;
DidRespawn, SecondPhase: Boolean;
Expand Down Expand Up @@ -205,16 +203,16 @@ procedure DeleteUninstallDataFiles;
{ Truncate the .dat file to zero bytes just before relinquishing exclusive
access to it }
try
UninstLogFile.Seek(0);
UninstLogFile.Truncate;
UninstDataFile.Seek(0);
UninstDataFile.Truncate;
except
{ ignore any exceptions, just in case }
end;
FreeAndNil(UninstLogFile);
FreeAndNil(UninstDataFile);

{ Delete the .dat and .msg files }
DeleteFile(UninstDataFile);
DeleteFile(UninstMsgFile);
DeleteFile(UninstDataFilename);
DeleteFile(UninstMsgFilename);

{ Tell the first phase to terminate, then delete its .exe }
if FirstPhaseWnd <> 0 then begin
Expand All @@ -240,7 +238,7 @@ procedure DeleteUninstallDataFiles;
Sleep(500);
end;
UninstallExitCode := 0;
DelayDeleteFile(False, UninstExeFile, 13, 50, 250);
DelayDeleteFile(False, UninstExeFilename, 13, 50, 250);
if Debugging then
DebugNotifyUninstExe('');
{ Pre-Windows 2000 Add/Remove Programs will try to bring itself to the
Expand Down Expand Up @@ -275,7 +273,7 @@ procedure ProcessCommandLine;
else
if CompareText(ParamName, '/SECONDPHASE=') = 0 then begin
SecondPhase := True;
UninstExeFile := ParamValue;
UninstExeFilename := ParamValue;
end
else if CompareText(ParamName, '/FIRSTPHASEWND=') = 0 then
FirstPhaseWnd := StrToInt(ParamValue)
Expand Down Expand Up @@ -317,12 +315,12 @@ function OpenUninstDataFile(const AAccess: TFileAccess): TFile;
begin
Result := nil; { avoid warning }
try
Result := TFile.Create(UninstDataFile, fdOpenExisting, AAccess, fsNone);
Result := TFile.Create(UninstDataFilename, fdOpenExisting, AAccess, fsNone);
except
on E: EFileError do begin
SetLastError(E.ErrorCode);
RaiseLastError(FmtSetupMessage1(msgUninstallOpenError,
UninstDataFile));
UninstDataFilename));
end;
end;
end;
Expand All @@ -339,7 +337,7 @@ function RespawnFirstPhaseIfNeeded: Boolean;

F := OpenUninstDataFile(faRead);
try
Flags := ReadUninstallLogFlags(F, UninstDataFile);
Flags := ReadUninstallLogFlags(F, UninstDataFilename);
finally
F.Free;
end;
Expand All @@ -350,7 +348,7 @@ function RespawnFirstPhaseIfNeeded: Boolean;
SetWindowPos(Application.Handle, 0, 0, 0, 0, 0, SWP_NOSIZE or
SWP_NOMOVE or SWP_NOZORDER or SWP_NOACTIVATE or SWP_HIDEWINDOW);
try
RespawnSelfElevated(UninstExeFile,
RespawnSelfElevated(UninstExeFilename,
Format('/INITPROCWND=$%x ', [Application.Handle]) + GetCmdTail,
UninstallExitCode);
except
Expand Down Expand Up @@ -379,7 +377,7 @@ procedure RunFirstPhase;
except
{ ignore exceptions }
end;
if not CopyFile(PChar(UninstExeFile), PChar(TempFile), False) then
if not CopyFile(PChar(UninstExeFilename), PChar(TempFile), False) then
RaiseLastError(SetupMessages[msgLdrCannotCreateTemp]);
{ Don't want any attribute like read-only transferred }
SetFileAttributes(PChar(TempFile), FILE_ATTRIBUTE_NORMAL);
Expand Down Expand Up @@ -506,17 +504,17 @@ procedure RunSecondPhase;
end;
end;
Log('Setup version: ' + SetupTitle + ' version ' + SetupVersion);
Log('Original Uninstall EXE: ' + UninstExeFile);
Log('Uninstall DAT: ' + UninstDataFile);
Log('Original Uninstall EXE: ' + UninstExeFilename);
Log('Uninstall DAT: ' + UninstDataFilename);
Log('Uninstall command line: ' + GetCmdTail);
LogWindowsVersion;

{ Open the .dat file for read access }
UninstLogFile := OpenUninstDataFile(faRead);
UninstDataFile := OpenUninstDataFile(faRead);

{ Load contents of the .dat file }
UninstLog := TExtUninstallLog.Create;
UninstLog.Load(UninstLogFile, UninstDataFile);
UninstLog.Load(UninstDataFile, UninstDataFilename);

Title := FmtSetupMessage1(msgUninstallAppFullTitle, UninstLog.AppName);

Expand All @@ -540,8 +538,8 @@ procedure RunSecondPhase;
{ Reopen the .dat file for exclusive, read/write access and keep it
open for the duration of the uninstall process to prevent a second
instance of the same uninstaller from running. }
FreeAndNil(UninstLogFile);
UninstLogFile := OpenUninstDataFile(faReadWrite);
FreeAndNil(UninstDataFile);
UninstDataFile := OpenUninstDataFile(faReadWrite);

if not UninstLog.ExtractLatestRecData(utCompiledCode,
SetupBinVersion {$IFDEF UNICODE} or Longint($80000000) {$ENDIF}, CompiledCodeData) then
Expand Down Expand Up @@ -580,7 +578,7 @@ procedure RunSecondPhase;
InitMainNonSHFolderConsts;
LoadSHFolderDLL;

UninstallExeFilename := UninstExeFile;
UninstallExeFilename := UninstExeFilename;
UninstallExpandedAppId := UninstLog.AppId;
UninstallSilent := Silent or VerySilent;

Expand Down Expand Up @@ -733,7 +731,7 @@ procedure RunSecondPhase;
UnloadSHFolderDLL;
RemoveTempInstallDir;
UninstLog.Free;
FreeAndNil(UninstLogFile);
FreeAndNil(UninstDataFile);
end;

if RestartSystem then begin
Expand Down Expand Up @@ -772,23 +770,23 @@ procedure RunUninstaller;

SetCurrentDir(GetSystemDir);

UninstExeFile := NewParamStr(0);
UninstExeFilename := NewParamStr(0);
ProcessCommandLine; { note: may change UninstExeFile }
UninstDataFile := PathChangeExt(UninstExeFile, '.dat');
UninstMsgFile := PathChangeExt(UninstExeFile, '.msg');
UninstDataFilename := PathChangeExt(UninstExeFilename, '.dat');
UninstMsgFilename := PathChangeExt(UninstExeFilename, '.msg');

{ Initialize messages }
F := TFile.Create(UninstExeFile, fdOpenExisting, faRead, fsRead);
F := TFile.Create(UninstExeFilename, fdOpenExisting, faRead, fsRead);
try
F.Seek(F.Size.Lo - SizeOf(UninstallerMsgTail));
F.ReadBuffer(UninstallerMsgTail, SizeOf(UninstallerMsgTail));
if UninstallerMsgTail.ID <> UninstallerMsgTailID then begin
{ No valid UninstallerMsgTail record found at the end of the EXE;
load messages from an external .msg file. }
LoadSetupMessages(UninstMsgFile, 0, True);
LoadSetupMessages(UninstMsgFilename, 0, True);
end
else
LoadSetupMessages(UninstExeFile, UninstallerMsgTail.Offset, True);
LoadSetupMessages(UninstExeFilename, UninstallerMsgTail.Offset, True);
finally
F.Free;
end;
Expand All @@ -803,8 +801,8 @@ procedure RunUninstaller;
Application.Title := SetupMessages[msgUninstallAppTitle];

{ Verify that uninstall data file exists }
if not NewFileExists(UninstDataFile) then begin
LoggedMessageBoxFmt1(msgUninstallNotFound, UninstDataFile,
if not NewFileExists(UninstDataFilename) then begin
LoggedMessageBoxFmt1(msgUninstallNotFound, UninstDataFilename,
SetupMessages[msgUninstallAppTitle], MB_ICONSTOP or MB_OK, True, IDOK);
Abort;
end;
Expand Down

0 comments on commit 961b3b7

Please sign in to comment.