Browse Source

[Setup] section directive UsePreviousLanguage now also has an effect when the Select Language dialog is not displayed because Setup is running silently, or ShowLanguageDialog=no or auto.

Martijn Laan 6 years ago
parent
commit
75facb1929
4 changed files with 49 additions and 23 deletions
  1. 2 2
      ISHelp/isetup.xml
  2. 43 9
      Projects/Main.pas
  3. 3 12
      Projects/SelLangForm.pas
  4. 1 0
      whatsnew.htm

+ 2 - 2
ISHelp/isetup.xml

@@ -4573,8 +4573,8 @@ DiskSliceSize=1457664
 <setupvalid><link topic="yesnonotes"><tt>yes</tt> or <tt>no</tt></link></setupvalid>
 <setupdefault><tt>yes</tt></setupdefault>
 <body>
-<p>When this directive is <tt>yes</tt>, the default, at startup Setup will look in the registry to see if the <link topic="sameappnotes">same application</link> is already installed, and if so, it will use the language of the previous installation as the default language selected in the list of available languages on the <i>Select Language</i> dialog.</p>
-<p>Note that this directive does not change the language used by the <i>Select Language</i> dialog itself because it cannot assume that the current user understands the same languages as the previous user. See the <link topic="languagessection">[Languages] section</link> help topic for details on which language the <i>Select Language</i> dialog uses by default.</p>
+<p>When this directive is <tt>yes</tt>, the default, at startup Setup will look in the registry to see if the <link topic="sameappnotes">same application</link> is already installed, and if so, it will use the language of the previous installation as the default language presented to the user in the wizard.</p>
+<p>Note that this directive does not change the language used by the <i>Select Language</i> dialog itself. See the <link topic="languagessection">[Languages] section</link> help topic for details on which language the <i>Select Language</i> dialog uses by default.</p>
 <p>Also note that Setup cannot re-use settings from a previous installation that had <tt>Uninstallable</tt> set to <tt>no</tt>, since the registry entries it looks for are not created when <tt>Uninstallable</tt> is <tt>no</tt>.</p>
 <p><tt>UsePreviousLanguage</tt> must be set to <tt>no</tt> when <tt>AppId</tt> includes constants.</p>
 </body>

+ 43 - 9
Projects/Main.pas

@@ -156,7 +156,7 @@ var
   RmSessionKey: array[0..CCH_RM_SESSION_KEY] of WideChar;
 
   { Other }
-  ShowLanguageDialog: Boolean;
+  ShowLanguageDialog, MatchedLangParameter: Boolean;
   InstallMode: (imNormal, imSilent, imVerySilent);
   HasIcons, IsNT, IsWin64, Is64BitInstallMode, IsAdmin, IsPowerUserOrAdmin, IsAdminInstallMode,
     NeedPassword, NeedSerial, NeedsRestart, RestartSystem,
@@ -207,6 +207,7 @@ function GetShellFolderByCSIDL(Folder: Integer; const Create: Boolean): String;
 function GetUninstallRegKeyBaseName(const ExpandedAppId: String): String;
 function GetUninstallRegSubkeyName(const UninstallRegKeyBaseName: String): String;
 function GetPreviousData(const ExpandedAppID, ValueName, DefaultValueData: String): String;
+function GetPreviousLanguage(const ExpandedAppID: String): Integer;
 procedure InitializeAdminInstallMode(const AAdminInstallMode: Boolean);
 procedure Initialize64BitInstallMode(const A64BitInstallMode: Boolean);
 procedure Log64BitInstallMode;
@@ -358,6 +359,26 @@ begin
   end;
 end;
 
+function GetPreviousLanguage(const ExpandedAppID: String): Integer;
+var
+  PrevLang: String;
+  I: Integer;
+begin
+  { do not localize or change the following string }
+  PrevLang := GetPreviousData(ExpandConst(SetupHeader.AppId), 'Inno Setup: Language', '');
+
+  if PrevLang <> '' then begin
+    for I := 0 to Entries[seLanguage].Count-1 do begin
+      if CompareText(PrevLang, PSetupLanguageEntry(Entries[seLanguage][I]).Name) = 0 then begin
+        Result := I;
+        Exit;
+      end;
+    end;
+  end;
+  
+  Result := -1;
+end;
+
 function TestPassword(const Password: String): Boolean;
 var
   Context: TSHA1Context;
@@ -2233,18 +2254,22 @@ end;
 
 procedure ActivateDefaultLanguage;
 { Auto-detects the most appropriate language and activates it.
-  Also initializes the ShowLanguageDialog variable.
+  Also initializes the ShowLanguageDialog and MatchedLangParameter variables.
   Note: A like-named version of this function is also present in SetupLdr.dpr. }
 var
   I: Integer;
 begin
+  MatchedLangParameter := False;
   case DetermineDefaultLanguage(GetLanguageEntryProc,
      SetupHeader.LanguageDetectionMethod, InitLang, I) of
     ddNoMatch: ShowLanguageDialog := (SetupHeader.ShowLanguageDialog <> slNo);
     ddMatch: ShowLanguageDialog := (SetupHeader.ShowLanguageDialog = slYes);
   else
-    { ddMatchLangParameter }
-    ShowLanguageDialog := False;
+    begin
+      { ddMatchLangParameter }
+      ShowLanguageDialog := False;
+      MatchedLangParameter := True;
+    end;
   end;
   SetActiveLanguage(I);
 end;
@@ -3243,12 +3268,21 @@ begin
   { Show "Select Language" dialog if necessary - requires "64-bit mode" to be
     initialized else it might query the previous language from the wrong registry
     view }
-  if ShowLanguageDialog and (Entries[seLanguage].Count > 1) and
-     not InitSilent and not InitVerySilent then begin
-    if not AskForLanguage then
-      Abort;
+  if Entries[seLanguage].Count > 1 then begin
+    if ShowLanguageDialog and not InitSilent and not InitVerySilent then begin
+      if not AskForLanguage then
+        Abort;
+    end else if not MatchedLangParameter and (shUsePreviousLanguage in SetupHeader.Options) then begin
+      { Replicate the dialog's UsePreviousLanguage functionality. }
+      { Note: if UsePreviousLanguage is set to "yes" then the compiler does not
+        allow AppId to include constants but we should still call ExpandConst
+        to handle any '{{'. }
+      I := GetPreviousLanguage(ExpandConst(SetupHeader.AppId));
+      if I <> -1 then
+        SetActiveLanguage(I);
+    end;
   end;
-
+  
   { Check processor architecture }
   if (SetupHeader.ArchitecturesAllowed <> []) and
      not(ProcessorArchitecture in SetupHeader.ArchitecturesAllowed) then

+ 3 - 12
Projects/SelLangForm.pas

@@ -71,7 +71,6 @@ var
   ClassInfo: TWndClassW;
   N: String;
 {$ENDIF}
-  PrevLang: String;
 begin
   LangForm := TSelectLanguageForm.Create(Application);
   try
@@ -117,17 +116,9 @@ begin
       { Note: if UsePreviousLanguage is set to "yes" then the compiler does not
         allow AppId to include constants but we should still call ExpandConst
         to handle any '{{'. }
-      { do not localize or change the following string }
-      PrevLang := GetPreviousData(ExpandConst(SetupHeader.AppId), 'Inno Setup: Language', '');
-
-      if PrevLang <> '' then begin
-        for I := 0 to Entries[seLanguage].Count-1 do begin
-          if CompareText(PrevLang, PSetupLanguageEntry(Entries[seLanguage][I]).Name) = 0 then begin
-            LangForm.LangCombo.ItemIndex := LangForm.LangCombo.Items.IndexOfObject(TObject(I));
-            Break;
-          end;
-        end;
-      end;
+      I := GetPreviousLanguage(ExpandConst(SetupHeader.AppId));
+      if I <> -1 then
+        LangForm.LangCombo.ItemIndex := LangForm.LangCombo.Items.IndexOfObject(TObject(I));
     end;
 
     { Select the active language if no previous language was selected }

+ 1 - 0
whatsnew.htm

@@ -30,6 +30,7 @@ For conditions of distribution and use, see <a href="http://www.jrsoftware.org/f
 <ul>
   <li>/LOG: Now logs Windows compatibility mode when this is activated by the user.</li>
   <li>Added new [Setup] section directive: <tt>SignToolRunMinimized</tt>.</li>
+  <li>[Setup] section directive <tt>UsePreviousLanguage</tt> now also has an effect when the <i>Select Language</i> dialog is not displayed because Setup is for example running silently.</li>
   <li>Checkboxes displayed by lists now look better on high DPI systems.</li>
   <li>Compiler IDE changes:
   <ul>