Browse Source

ArchitecturesAllowed/ArchitecturesInstallIn64BitMode as expressions: Setup.

msgOnlyOnTheseArchitectures is now not very user friendly and not localized. It can say stuff like 'not x64compatible' when the rest of the message is localized. Not so easy to fix. Depend on the script writer to set OnlyOnTheseArchitectures to a friendly version when needed?
Martijn Laan 1 year ago
parent
commit
f4ccf61f2e
2 changed files with 70 additions and 51 deletions
  1. 7 5
      Projects/Src/Compile.pas
  2. 63 46
      Projects/Src/Main.pas

+ 7 - 5
Projects/Src/Compile.pas

@@ -319,7 +319,7 @@ type
       const Parameters: array of const): Boolean;
     procedure ProcessExpressionParameter(const ParamName,
       ParamData: String; OnEvalIdentifier: TSimpleExpressionOnEvalIdentifier;
-      SlashConvert: Boolean; var ProcessedParamData: String; const Tag: Integer = 0);
+      SlashConvert: Boolean; var ProcessedParamData: String; const Tag: LongInt = 0);
     procedure ProcessWildcardsParameter(const ParamData: String;
       const AWildcards: TStringList; const TooLongMsg: String);
     procedure ReadDefaultMessages;
@@ -2917,7 +2917,7 @@ begin
   var Only64Bit := Sender.Tag = 1; { 1 means we're evaluating ArchitecturesInstallIn64BitMode }
 
   for var Architecture in Architectures do begin
-    if SameText(Name, Architecture) then begin
+    if Name = Architecture then begin
       if Only64bit and (Architecture = 'x86') then
         raise Exception.CreateFmt(SCompilerArchitectureNot64Bit, [Name]);
       Exit(True); { Result doesn't matter }
@@ -2989,7 +2989,7 @@ end;
 
 procedure TSetupCompiler.ProcessExpressionParameter(const ParamName,
   ParamData: String; OnEvalIdentifier: TSimpleExpressionOnEvalIdentifier;
-  SlashConvert: Boolean; var ProcessedParamData: String; const Tag: Integer);
+  SlashConvert: Boolean; var ProcessedParamData: String; const Tag: LongInt);
 var
   SimpleExpression: TSimpleExpression;
 begin
@@ -3562,10 +3562,12 @@ begin
         SetupHeader.AppVersion := Value;
       end;
     ssArchitecturesAllowed: begin
-        ProcessExpressionParameter(KeyName, Value, EvalArchitectureIdentifier, False, SetupHeader.ArchitecturesAllowed);
+        ProcessExpressionParameter(KeyName, LowerCase(Value),
+          EvalArchitectureIdentifier, False, SetupHeader.ArchitecturesAllowed);
       end;
     ssArchitecturesInstallIn64BitMode: begin
-        ProcessExpressionParameter(KeyName, Value, EvalArchitectureIdentifier, False, SetupHeader.ArchitecturesInstallIn64BitMode, 1);
+        ProcessExpressionParameter(KeyName, LowerCase(Value),
+          EvalArchitectureIdentifier, False, SetupHeader.ArchitecturesInstallIn64BitMode, 1);
       end;
     ssASLRCompatible: begin
         ASLRCompatible := StrToBool(Value);

+ 63 - 46
Projects/Src/Main.pas

@@ -293,6 +293,8 @@ type
         const Constant: String): String;
       class function EvalInstallIdentifier(Sender: TSimpleExpression;
         const Name: String; const Parameters: array of const): Boolean;
+      class function EvalArchitectureIdentifier(Sender: TSimpleExpression;
+        const Name: String; const Parameters: array of const): Boolean;
       class function EvalComponentOrTaskIdentifier(Sender: TSimpleExpression;
         const Name: String; const Parameters: array of const): Boolean;
       class function EvalLanguageIdentifier(Sender: TSimpleExpression;
@@ -487,6 +489,21 @@ begin
   CheckOrInstallCurrentSourceFilename := '';
 end;
 
+class function TDummyClass.EvalArchitectureIdentifier(Sender: TSimpleExpression;
+  const Name: String; const Parameters: array of const): Boolean;
+begin
+  if Name = 'x86' then
+    Result := paX86 in MachineTypesSupportedBySystem
+  else if Name = 'x64' then
+    Result := paX64 in MachineTypesSupportedBySystem
+  else if Name = 'ia64' then
+    Result := paIA64 in MachineTypesSupportedBySystem
+  else if Name = 'arm64' then
+    Result := paARM64 in MachineTypesSupportedBySystem
+  else
+    raise Exception.CreateFmt('Unexpected architecture ''%s''', [Name]);
+end;
+
 class function TDummyClass.EvalComponentOrTaskIdentifier(Sender: TSimpleExpression;
   const Name: String; const Parameters: array of const): Boolean;
 var
@@ -538,34 +555,33 @@ begin
     Result := EvalCheck(Expression);
 end;
 
-function ShouldProcessEntry(const WizardComponents, WizardTasks: TStringList;
-  const Components, Tasks, Languages, Check: String): Boolean;
-
-  function EvalExpression(const Expression: String;
-    OnEvalIdentifier: TSimpleExpressionOnEvalIdentifier; Tag: LongInt): Boolean;
-  var
-    SimpleExpression: TSimpleExpression;
-  begin
+function EvalExpression(const Expression: String;
+  OnEvalIdentifier: TSimpleExpressionOnEvalIdentifier; Tag: LongInt = 0): Boolean;
+var
+  SimpleExpression: TSimpleExpression;
+begin
+  try
+    SimpleExpression := TSimpleExpression.Create;
     try
-      SimpleExpression := TSimpleExpression.Create;
-      try
-        SimpleExpression.Lazy := True;
-        SimpleExpression.Expression := Expression;
-        SimpleExpression.OnEvalIdentifier := OnEvalIdentifier;
-        SimpleExpression.ParametersAllowed := False;
-        SimpleExpression.SilentOrAllowed := True;
-        SimpleExpression.SingleIdentifierMode := False;
-        SimpleExpression.Tag := Tag;
-        Result := SimpleExpression.Eval;
-      finally
-        SimpleExpression.Free;
-      end;
-    except
-      InternalError(Format('Expression error ''%s''', [GetExceptMessage]));
-      Result := False;
+      SimpleExpression.Lazy := True;
+      SimpleExpression.Expression := Expression;
+      SimpleExpression.OnEvalIdentifier := OnEvalIdentifier;
+      SimpleExpression.ParametersAllowed := False;
+      SimpleExpression.SilentOrAllowed := True;
+      SimpleExpression.SingleIdentifierMode := False;
+      SimpleExpression.Tag := Tag;
+      Result := SimpleExpression.Eval;
+    finally
+      SimpleExpression.Free;
     end;
+  except
+    InternalError(Format('Expression error ''%s''', [GetExceptMessage]));
+    Result := False;
   end;
+end;
 
+function ShouldProcessEntry(const WizardComponents, WizardTasks: TStringList;
+  const Components, Tasks, Languages, Check: String): Boolean;
 var
   ProcessComponent, ProcessTask, ProcessLanguage: Boolean;
 begin
@@ -581,7 +597,7 @@ begin
       ProcessTask := True;
 
     if Languages <> '' then
-      ProcessLanguage := EvalExpression(Languages, TDummyClass.EvalLanguageIdentifier, 0)
+      ProcessLanguage := EvalExpression(Languages, TDummyClass.EvalLanguageIdentifier)
     else
       ProcessLanguage := True;
 
@@ -2257,27 +2273,28 @@ begin
     LogFmt('Compatibility mode: %s (%s)', [SYesNo[True], S]);
 end;
 
-function ArchitecturesToStr(const Architectures: TSetupProcessorArchitectures;
-  const Separator: String): String;
+procedure LogWindowsVersion;
+
+  function ArchitecturesToStr(const Architectures: TSetupProcessorArchitectures;
+    const Separator: String): String;
 
-  procedure AppendArchitecture(var S: String; const Separator, L: String);
+    procedure AppendArchitecture(var S: String; const Separator, L: String);
+    begin
+      if S <> '' then
+        S := S + Separator + L
+      else
+        S := L;
+    end;
+
+  var
+    I: TSetupProcessorArchitecture;
   begin
-    if S <> '' then
-      S := S + Separator + L
-    else
-      S := L;
+    Result := '';
+    for I := Low(I) to High(I) do
+      if I in Architectures then
+        AppendArchitecture(Result, Separator, SetupProcessorArchitectureNames[I]);
   end;
 
-var
-  I: TSetupProcessorArchitecture;
-begin
-  Result := '';
-  for I := Low(I) to High(I) do
-    if I in Architectures then
-      AppendArchitecture(Result, Separator, SetupProcessorArchitectureNames[I]);
-end;
-
-procedure LogWindowsVersion;
 var
   SP: String;
 begin
@@ -3043,7 +3060,7 @@ begin
         { Set Is64BitInstallMode if we're on Win64 and the processor architecture is
           one on which a "64-bit mode" install should be performed. Doing this early
           so that UsePreviousPrivileges knows where to look. Will log later. }
-        if ProcessorArchitecture in SetupHeader.ArchitecturesInstallIn64BitMode then begin
+        if EvalExpression(SetupHeader.ArchitecturesInstallIn64BitMode, TDummyClass.EvalArchitectureIdentifier) then begin
           if not IsWin64 then begin
             { A 64-bit processor was detected and 64-bit install mode was requested,
               but IsWin64 is False, indicating required WOW64 APIs are not present }
@@ -3206,9 +3223,9 @@ begin
   end;
   
   { Check processor architecture }
-  if (SetupHeader.ArchitecturesAllowed <> []) and
-     not(ProcessorArchitecture in SetupHeader.ArchitecturesAllowed) then
-    AbortInitFmt1(msgOnlyOnTheseArchitectures, ArchitecturesToStr(SetupHeader.ArchitecturesAllowed, #13#10));
+  if (SetupHeader.ArchitecturesAllowed <> '') and
+     not EvalExpression(SetupHeader.ArchitecturesAllowed, TDummyClass.EvalArchitectureIdentifier) then
+    AbortInitFmt1(msgOnlyOnTheseArchitectures, SetupHeader.ArchitecturesAllowed);
 
   { Check Windows version }
   case InstallOnThisVersion(SetupHeader.MinVersion, SetupHeader.OnlyBelowVersion) of