Browse Source

Tweak WizardForm's CheckPassword + some cleanup.

Martijn Laan 11 months ago
parent
commit
f727458281

+ 3 - 6
Projects/Src/Setup.Install.pas

@@ -2904,22 +2904,19 @@ var
   end;
   end;
 
 
   procedure RenameUninstallExe;
   procedure RenameUninstallExe;
-  var
-    RetriesLeft: Integer;
-    Timer: TOneShotTimer;
-    LastError: DWORD;
   begin
   begin
     { If the uninstall EXE wasn't extracted to a .tmp file because it isn't
     { If the uninstall EXE wasn't extracted to a .tmp file because it isn't
       replacing an existing uninstall EXE, exit. }
       replacing an existing uninstall EXE, exit. }
     if UninstallTempExeFilename = '' then
     if UninstallTempExeFilename = '' then
       Exit;
       Exit;
     Log('Renaming uninstaller.');
     Log('Renaming uninstaller.');
-    RetriesLeft := 4;
+    var Timer: TOneShotTimer;
+    var RetriesLeft := 4;
     while True do begin
     while True do begin
       Timer.Start(1000);
       Timer.Start(1000);
       if MoveFileReplace(UninstallTempExeFilename, UninstallExeFilename) then
       if MoveFileReplace(UninstallTempExeFilename, UninstallExeFilename) then
         Break;
         Break;
-      LastError := GetLastError;
+      var LastError := GetLastError;
       { Does the error code indicate that the file is possibly in use? }
       { Does the error code indicate that the file is possibly in use? }
       if LastErrorIndicatesPossiblyInUse(LastError, False) then begin
       if LastErrorIndicatesPossiblyInUse(LastError, False) then begin
         if RetriesLeft > 0 then begin
         if RetriesLeft > 0 then begin

+ 3 - 6
Projects/Src/Setup.MainFunc.pas

@@ -2683,16 +2683,13 @@ var
 
 
   function HandleInitPassword(const NeedPassword: Boolean): Boolean;
   function HandleInitPassword(const NeedPassword: Boolean): Boolean;
   { Handles InitPassword and returns the updated value of NeedPassword }
   { Handles InitPassword and returns the updated value of NeedPassword }
-  { Also see Wizard.CheckPassword }
-  var
-    S: String;
-    PasswordOk: Boolean;
+  { Also see WizardForm.CheckPassword }
   begin
   begin
     Result := NeedPassword;
     Result := NeedPassword;
 
 
     if NeedPassword and (InitPassword <> '') then begin
     if NeedPassword and (InitPassword <> '') then begin
-      PasswordOk := False;
-      S := InitPassword;
+      var PasswordOk := False;
+      var S := InitPassword;
       var CryptKey: TSetupEncryptionKey;
       var CryptKey: TSetupEncryptionKey;
       GenerateEncryptionKey(S, SetupHeader.EncryptionKDFSalt, CryptKey);
       GenerateEncryptionKey(S, SetupHeader.EncryptionKDFSalt, CryptKey);
       if shPassword in SetupHeader.Options then
       if shPassword in SetupHeader.Options then

+ 20 - 9
Projects/Src/Setup.WizardForm.pas

@@ -2282,15 +2282,23 @@ end;
 procedure TWizardForm.NextButtonClick(Sender: TObject);
 procedure TWizardForm.NextButtonClick(Sender: TObject);
 
 
   function CheckPassword: Boolean;
   function CheckPassword: Boolean;
-  { Also see Main.HandleInitPassword }
-  var
-    S: String;
-    SaveCursor: HCURSOR;
+  { Also see MainFunc.HandleInitPassword }
   begin
   begin
     Result := False;
     Result := False;
-    S := PasswordEdit.Text;
+    var S := PasswordEdit.Text;
+
+    var Timer: TOneShotTimer;
+    Timer.Start(750); { See comment below }
+
     var CryptKey: TSetupEncryptionKey;
     var CryptKey: TSetupEncryptionKey;
-    GenerateEncryptionKey(S, SetupHeader.EncryptionKDFSalt, CryptKey);
+    var SaveCursor := GetCursor;
+    SetCursor(LoadCursor(0, IDC_WAIT));
+    try
+      GenerateEncryptionKey(S, SetupHeader.EncryptionKDFSalt, CryptKey);
+    finally
+      SetCursor(SaveCursor);
+    end;
+
     if shPassword in SetupHeader.Options then
     if shPassword in SetupHeader.Options then
       Result := TestPassword(CryptKey);
       Result := TestPassword(CryptKey);
     if not Result and (CodeRunner <> nil) then
     if not Result and (CodeRunner <> nil) then
@@ -2302,13 +2310,16 @@ procedure TWizardForm.NextButtonClick(Sender: TObject);
         FileExtractor.CryptKey := CryptKey;
         FileExtractor.CryptKey := CryptKey;
       PasswordEdit.Text := '';
       PasswordEdit.Text := '';
     end else begin
     end else begin
-      { Delay for 750 ms when an incorrect password is entered to
+      { Ensure a total time of 750 ms when an incorrect password is entered to
         discourage brute-force attempts }
         discourage brute-force attempts }
       if Visible then begin
       if Visible then begin
         SaveCursor := GetCursor;
         SaveCursor := GetCursor;
         SetCursor(LoadCursor(0, IDC_WAIT));
         SetCursor(LoadCursor(0, IDC_WAIT));
-        Sleep(750);
-        SetCursor(SaveCursor);
+        try
+          Timer.SleepUntilExpired;
+        finally
+          SetCursor(SaveCursor);
+        end;
       end;
       end;
       LoggedMsgBox(SetupMessages[msgIncorrectPassword], '', mbError, MB_OK, True, IDOK);
       LoggedMsgBox(SetupMessages[msgIncorrectPassword], '', mbError, MB_OK, True, IDOK);
       if Visible then begin
       if Visible then begin