Browse Source

Add 'overwrite all' support to 'promptifolder' as well.

Martijn Laan 5 năm trước cách đây
mục cha
commit
02c6809ee8
6 tập tin đã thay đổi với 80 bổ sung43 xóa
  1. 5 0
      Files/Default.isl
  2. 5 0
      Files/Languages/Dutch.isl
  3. 2 1
      Projects/Compile.pas
  4. 62 42
      Projects/Install.pas
  5. 5 0
      Projects/MsgIDs.pas
  6. 1 0
      whatsnew.htm

+ 5 - 0
Files/Default.isl

@@ -298,7 +298,12 @@ FileExists2=The file already exists.
 FileExistsOverwriteExisting=&Overwrite the existing file
 FileExistsKeepExisting=&Keep the existing file
 FileExistsOverwriteOrKeepAll=&Do this for the next conflicts
+ExistingFileNewerSelectAction=Select action
 ExistingFileNewer=The existing file is newer than the one Setup is trying to install. It is recommended that you keep the existing file.%n%nDo you want to keep the existing file?
+ExistingFileNewer2=The existing file is newer than the one Setup is trying to install.
+ExistingFileNewerOverwriteExisting=&Overwrite the existing file
+ExistingFileNewerKeepExisting=&Keep the existing file (recommended)
+ExistingFileNewerOverwriteOrKeepAll=&Do this for the next conflicts
 ErrorChangingAttr=An error occurred while trying to change the attributes of the existing file:
 ErrorCreatingTemp=An error occurred while trying to create a file in the destination directory:
 ErrorReadingSource=An error occurred while trying to read the source file:

+ 5 - 0
Files/Languages/Dutch.isl

@@ -278,7 +278,12 @@ FileExists2=Het bestand bestaat al.
 FileExistsOverwriteExisting=&Overschrijf het bestaande bestand
 FileExistsKeepExisting=&Behoud het bestaande bestand
 FileExistsOverwriteOrKeepAll=&Dit voor de volgende conflicten uitvoeren
+ExistingFileNewerSelectAction=Selecteer actie
 ExistingFileNewer=Het bestaande bestand is nieuwer dan het bestand dat Setup probeert te installeren. U wordt aanbevolen het bestaande bestand te behouden.%n%nWilt u het bestaande bestand behouden?
+ExistingFileNewer2=Het bestaande bestand is nieuwer dan het bestand dat Setup probeert te installeren.
+ExistingFileNewerOverwriteExisting=&Overschrijf het bestaande bestand
+ExistingFileNewerKeepExisting=&Behoud het bestaande bestand (aanbevolen)
+ExistingFileNewerOverwriteOrKeepAll=&Dit voor de volgende conflicten uitvoeren
 ErrorChangingAttr=Er is een fout opgetreden bij het wijzigen van de kenmerken van het bestaande bestand:
 ErrorCreatingTemp=Er is een fout opgetreden bij het maken van een bestand in de doelmap:
 ErrorReadingSource=Er is een fout opgetreden bij het lezen van het bronbestand:

+ 2 - 1
Projects/Compile.pas

@@ -7365,7 +7365,8 @@ procedure TSetupCompiler.ReadMessagesFromScript;
 
 const
   OptionalMessages: set of TSetupMessageID = [msgComponentsDiskSpaceGBLabel, msgDiskSpaceGBLabel, msgPrepareToInstallNeedsRestart,
-    msgFileExistsSelectAction, msgFileExists2, msgFileExistsOverwriteExisting, msgFileExistsKeepExisting, msgFileExistsOverwriteOrKeepAll];
+    msgFileExistsSelectAction, msgFileExists2, msgFileExistsOverwriteExisting, msgFileExistsKeepExisting, msgFileExistsOverwriteOrKeepAll,
+    msgExistingFileNewerSelectAction, msgExistingFileNewer2, msgExistingFileNewerOverwriteExisting, msgExistingFileNewerKeepExisting, msgExistingFileNewerOverwriteOrKeepAll];
 var
   I: Integer;
   LangData: TLangData;

+ 62 - 42
Projects/Install.pas

@@ -898,12 +898,12 @@ var
   end;
 
   type
-    TYesOrNoToAll = (ynNone, ynYes, ynNo);
+    TOverwriteAll = (oaUnknown, oaOverwrite, oaKeep);
 
   procedure ProcessFileEntry(const CurFile: PSetupFileEntry;
     const DisableFsRedir: Boolean; ASourceFile, ADestName: String;
     const FileLocationFilenames: TStringList; const AExternalSize: Integer64;
-    var ConfirmOverwriteAll: TYesOrNoToAll);
+    var ConfirmOverwriteOverwriteAll, PromptIfOlderOverwriteAll: TOverwriteAll);
 
     procedure InstallFont(const Filename, FontName: String;
       const AddToFontTableNow: Boolean);
@@ -1038,6 +1038,27 @@ var
       end;
     end;
 
+    function AskOverwrite(const DestFile, Instruction, Caption, Caption2: string; const ButtonLabels: array of String;
+      const VerificationText: String; const Default, Overwrite: Integer; var OverwriteAll: TOverwriteAll): Boolean;
+    var
+      VerificationFlagChecked: BOOL;
+    begin
+      if OverwriteAll = oaKeep then
+        Result := False { The user already said to keep (=not overwrite) all }
+      else if (Caption2 = '') then
+        Result := LoggedMsgBox(DestFile + SNewLine2 + Caption, '', mbError, MB_YESNO, True, Default) = Overwrite
+      else begin
+        Result := LoggedTaskDialogMsgBox('', Instruction, DestFile + SNewLine2 + Caption2, '',
+          mbConfirmation, MB_YESNO, ButtonLabels, 0, True, Default, VerificationText, @VerificationFlagChecked) = Overwrite;
+        if VerificationFlagChecked then begin
+          if Result then
+            OverwriteAll := oaOverwrite
+          else
+            OverwriteAll := oaKeep;
+        end;
+      end;
+    end;
+
   var
     ProgressUpdated: Boolean;
     PreviousProgress: Integer64;
@@ -1061,7 +1082,6 @@ var
     LastError: DWORD;
     DestF, SourceF: TFile;
     Flags: TMakeDirFlags;
-    VerificationFlagChecked: BOOL;
     Overwrite: Boolean;
   label Retry, Skip;
   begin
@@ -1211,11 +1231,16 @@ var
                    (ExistingVersionInfo.LS > CurFileVersionInfo.LS))) then begin
                 { Existing file is newer, ask user what to do unless we shouldn't }
                 if (foPromptIfOlder in CurFile^.Options) and not IsProtectedFile then begin
-                  Overwrite := LoggedMsgBox(DestFile + SNewLine2 + SetupMessages[msgExistingFileNewer],
-                      '', mbError, MB_YESNO, True, IDYES) = IDNO;
-                  if not Overwrite then begin
-                    Log('User opted not to overwrite the existing file. Skipping.');
-                    goto Skip;
+                  if PromptIfOlderOverwriteAll <> oaOverwrite then begin
+                    Overwrite := AskOverwrite(DestFile, SetupMessages[msgExistingFileNewerSelectAction],
+                      SetupMessages[msgExistingFileNewer], SetupMessages[msgExistingFileNewer2],
+                      [SetupMessages[msgExistingFileNewerKeepExisting], SetupMessages[msgExistingFileNewerOverwriteExisting]],
+                      SetupMessages[msgExistingFileNewerOverwriteOrKeepAll],
+                      IDYES, IDNO, PromptIfOlderOverwriteAll);
+                    if not Overwrite then begin
+                      Log('User opted not to overwrite the existing file. Skipping.');
+                      goto Skip;
+                    end;
                   end;
                 end else begin
                   Log('Existing file is a newer version. Skipping.');
@@ -1293,11 +1318,16 @@ var
             if CompareFileTime(ExistingFileDate, CurFileDate) > 0 then begin
               { Existing file has a later time stamp, ask user what to do unless we shouldn't }
               if (foPromptIfOlder in CurFile^.Options) and not IsProtectedFile then begin
-                Overwrite := LoggedMsgBox(DestFile + SNewLine2 + SetupMessages[msgExistingFileNewer],
-                    '', mbError, MB_YESNO, True, IDYES) = IDNO;
-                if not Overwrite then begin
-                  Log('User opted not to overwrite the existing file. Skipping.');
-                  goto Skip;
+                if PromptIfOlderOverwriteAll <> oaOverwrite then begin
+                  Overwrite := AskOverwrite(DestFile, SetupMessages[msgExistingFileNewerSelectAction],
+                    SetupMessages[msgExistingFileNewer], SetupMessages[msgExistingFileNewer2],
+                    [SetupMessages[msgExistingFileNewerKeepExisting], SetupMessages[msgExistingFileNewerOverwriteExisting]],
+                    SetupMessages[msgExistingFileNewerOverwriteOrKeepAll],
+                    IDYES, IDNO, PromptIfOlderOverwriteAll);
+                  if not Overwrite then begin
+                    Log('User opted not to overwrite the existing file. Skipping.');
+                    goto Skip;
+                  end;
                 end;
               end else begin
                 Log('Existing file has a later time stamp. Skipping.');
@@ -1316,31 +1346,19 @@ var
             goto Skip;
           end;
 
-          { If file already exists and foConfirmOverwrite is in Options and the user didn't already
-            say it's OK to overwrite all, ask the user if it's OK to overwrite unless the user
-            already said to keep (=not overwrite) all }
-          if (foConfirmOverwrite in CurFile^.Options) and not(ConfirmOverwriteAll = ynYes) then begin
-            if ConfirmOverwriteAll = ynNo then
-              Overwrite := False
-            else if (SetupMessages[msgFileExists2] = '') then
-              Overwrite := LoggedMsgBox(DestFile + SNewLine2 + SetupMessages[msgFileExists], '',
-                mbConfirmation, MB_YESNO, True, IDNO) = IDYES
-            else begin
-              Overwrite := LoggedTaskDialogMsgBox('', SetupMessages[msgFileExistsSelectAction],
-                DestFile + SNewLine2 + SetupMessages[msgFileExists2], '', mbConfirmation, MB_YESNO,
+          { If file already exists and foConfirmOverwrite is in Options, ask the user what to do }
+          if foConfirmOverwrite in CurFile^.Options then begin
+            if ConfirmOverwriteOverwriteAll <> oaOverwrite then begin
+              Overwrite := AskOverwrite(DestFile, SetupMessages[msgFileExistsSelectAction],
+                SetupMessages[msgFileExists], SetupMessages[msgFileExists2],
                 [SetupMessages[msgFileExistsOverwriteExisting], SetupMessages[msgFileExistsKeepExisting]],
-                0, True, IDNO, SetupMessages[msgFileExistsOverwriteOrKeepAll], @VerificationFlagChecked) = IDYES;
-              if VerificationFlagChecked then begin
-                if Overwrite then
-                  ConfirmOverwriteAll := ynYes
-                else
-                  ConfirmOverwriteAll := ynNo;
+                SetupMessages[msgFileExistsOverwriteOrKeepAll],
+                IDNO, IDYES, ConfirmOverwriteOverwriteAll);
+              if not Overwrite then begin
+                Log('User opted not to overwrite the existing file. Skipping.');
+                goto Skip;
               end;
             end;
-            if not Overwrite then begin
-              Log('User opted not to overwrite the existing file. Skipping.');
-              goto Skip;
-            end;
           end;
 
           { Check if existing file is read-only }
@@ -1716,7 +1734,7 @@ var
     function RecurseExternalCopyFiles(const DisableFsRedir: Boolean;
       const SearchBaseDir, SearchSubDir, SearchWildcard: String; const SourceIsWildcard: Boolean;
       const CurFile: PSetupFileEntry; const FileLocationFilenames: TStringList;
-      var ExpectedBytesLeft: Integer64; var ConfirmOverwriteAll: TYesOrNoToAll): Boolean;
+      var ExpectedBytesLeft: Integer64; var ConfirmOverwriteOverwriteAll, PromptIfOlderOverwriteAll: TOverwriteAll): Boolean;
     var
       SearchFullPath, FileName, SourceFile, DestName: String;
       H: THandle;
@@ -1756,7 +1774,7 @@ var
                 Size := ExpectedBytesLeft;
               end;
               ProcessFileEntry(CurFile, DisableFsRedir, SourceFile, DestName,
-                FileLocationFilenames, Size, ConfirmOverwriteAll);
+                FileLocationFilenames, Size, ConfirmOverwriteOverwriteAll, PromptIfOlderOverwriteAll);
               Dec6464(ExpectedBytesLeft, Size);
             end;
           until not FindNextFile(H, FindData);
@@ -1774,7 +1792,7 @@ var
                 Result := RecurseExternalCopyFiles(DisableFsRedir, SearchBaseDir,
                   SearchSubDir + FindData.cFileName + '\', SearchWildcard,
                   SourceIsWildcard, CurFile, FileLocationFileNames,
-                  ExpectedBytesLeft, ConfirmOverwriteAll) or Result;
+                  ExpectedBytesLeft, ConfirmOverwriteOverwriteAll, PromptIfOlderOverwriteAll) or Result;
             until not FindNextFile(H, FindData);
           finally
             Windows.FindClose(H);
@@ -1814,9 +1832,10 @@ var
     SourceWildcard: String;
     ProgressBefore, ExpectedBytesLeft: Integer64;
     DisableFsRedir, FoundFiles: Boolean;
-    ConfirmOverwriteAll: TYesOrNoToAll;
+    ConfirmOverwriteOverwriteAll, PromptIfOlderOverwriteAll: TOverwriteAll;
   begin
-    ConfirmOverwriteAll := ynNone;
+    ConfirmOverwriteOverwriteAll := oaUnknown;
+    PromptIfOlderOverwriteAll := oaUnknown;
 
     FileLocationFilenames := TStringList.Create;
     try
@@ -1841,7 +1860,8 @@ var
           if CurFile^.LocationEntry <> -1 then begin
             ExternalSize.Hi := 0;  { not used... }
             ExternalSize.Lo := 0;
-            ProcessFileEntry(CurFile, DisableFsRedir, '', '', FileLocationFilenames, ExternalSize, ConfirmOverwriteAll);
+            ProcessFileEntry(CurFile, DisableFsRedir, '', '', FileLocationFilenames, ExternalSize,
+              ConfirmOverwriteOverwriteAll, PromptIfOlderOverwriteAll);
           end
           else begin
             { File is an 'external' file }
@@ -1859,7 +1879,7 @@ var
               FoundFiles := RecurseExternalCopyFiles(DisableFsRedir,
                 PathExtractPath(SourceWildcard), '', PathExtractName(SourceWildcard),
                 IsWildcard(SourceWildcard), CurFile, FileLocationFileNames,
-                ExpectedBytesLeft, ConfirmOverwriteAll);
+                ExpectedBytesLeft, ConfirmOverwriteOverwriteAll, PromptIfOlderOverwriteAll);
             until FoundFiles or
                   (foSkipIfSourceDoesntExist in CurFile^.Options) or
                   AbortRetryIgnoreTaskDialogMsgBox(

+ 5 - 0
Projects/MsgIDs.pas

@@ -98,7 +98,12 @@ type
     msgErrorRestartReplace,
     msgErrorTitle,
     msgErrorTooManyFilesInDir,
+    msgExistingFileNewerSelectAction,
     msgExistingFileNewer,
+    msgExistingFileNewer2,
+    msgExistingFileNewerOverwriteExisting,
+    msgExistingFileNewerKeepExisting,
+    msgExistingFileNewerOverwriteOrKeepAll,
     msgExistingFileReadOnly2,
     msgExistingFileReadOnlyRetry,
     msgExistingFileReadOnlyKeepExisting,

+ 1 - 0
whatsnew.htm

@@ -42,6 +42,7 @@ For conditions of distribution and use, see <a href="https://jrsoftware.org/file
   <li>Some messages have been added in this version: (<a href="https://github.com/jrsoftware/issrc/commit/812a27664fbd767ad870c5c2456df9e4f43676d9#diff-cd0edf55eb9daa93e632d6d4d86a91d8">View differences in Default.isl</a>).
   <ul>
     <li>FileExistsSelectAction, FileExists2, FileExistsOverwriteExisting, FileExistsKeepExisting, FileExistsOverwriteOrKeepAll: If the FileExists2 message is set by a translation, Setup will instead use these messages instead of the FileExist message to show <a href="https://i.imgur.com/AnF6qo8.png">more user friendly prompts</a> to overwrite or keep existing files if the <tt>confirmoverwrite</tt> flag is set.</li>
+    <li>ExistingFileNewerSelectAction, ExistingFileNewer2, ExistingFileNewerOverwriteExisting, ExistingFileNewerKeepExisting, ExistingFileNewerOverwriteOrKeepAll: If the ExistingFileNewer2 message is set by a translation, Setup will instead use these messages instead of the ExistingFileNewer message to show <a href="https://i.imgur.com/vbXFpUE.png">more user friendly prompts</a> to keep or overwrite existing files if the <tt>promptifolder</tt> flag is set.</li>
   </ul>
   </li>
   <li>QuickStart Pack: Now registers the Inno Setup compiler path in the Inno Script Studio options so that it will find the Inno Setup compiler automatically. Required because Inno Script Studio doesn't officially support Inno Setup 6.</li>