我们可以使用 Inno Setup 6.1 中新的 "Version" 功能来简化脚本吗?
Can we use the new "Version" functions in Inno Setup 6.1 to make the script simpler?
我的脚本中有几个地方使用版本号:
场景一
#define AppVerText() \
GetVersionComponents(SourceDir + '\Meeting Schedule Assistant.exe', \
Local[0], Local[1], Local[2], Local[3]), \
Str(Local[0]) + "." + Str(Local[1]) + "." + Str(Local[2])
场景二
{ Is the installed version at least 14.14 ? }
Result := (Major < 14) or
((Major = 14) and ((Minor < 14) or
((Minor = 14) and ((Bld < 26429) or
((Bld = 26429) and (Rbld < 3))))));
if (Result) then
各种值是从注册表项中提取的。
场景三
{ Check Windows Version }
WindowsVersion := GetWindowsVersion;
Log(Format('Windows Version: %x', [WindowsVersion]));
(* Windows must be Win 7 SP1 (6.1.7601), Win 8.1 (6.3.9200) or higher,
eg: Win 10 (10.0.10240)
See: http://www.jrsoftware.org/ishelp/index.php?topic=winvernotes
Microsoft .Net Framework 4.6.2 will only work with these operating systems. *)
if (WindowsVersion < MakeVersion(6, 1, 7601)) or
((WindowsVersion >= MakeVersion(6, 2, 0)) and
(WindowsVersion < MakeVersion(6, 3, 0))) then
begin
MsgBox(SetupMessage(msgWindowsVersionNotSupported), mbError, MB_OK);
Result := False;
end;
调用:
function MakeVersion(Major, Minor, Build: Cardinal): Cardinal;
begin
Result := (Major shl 24) + (Minor shl 16) + Build;
end;
我只是想知道我们是否能够使用 Inno Setup 6.1 中引入的新“版本”Pascal 函数等?
你可以利用ComparePackedVersion
function (together with PackVersionComponents
):
Result :=
(ComparePackedVersion(
PackVersionComponents(Major, Minor, Bld, Rbld),
PackVersionComponents(14, 14, 26429, 3)) < 0);
在代码长度方面没有太大的改进。但它更不容易出错,也更容易理解。
我相信直接比较打包版本号实际上是安全的(至少除非您的主要版本不高于 2^15)。尽管 PackVersionComponents
不鼓励这样做。
Result :=
(PackVersionComponents(Major, Minor, Bld, Rbld) <
PackVersionComponents(14, 14, 26429, 3));
相关问题:
对于 Windows 版本测试,您可以将其与 GetWindowsVersionEx
结合使用:
GetWindowsVersionEx(WinVer);
WinVerPacked := PackVersionComponents(WinVer.Major, WinVer.Minor, WinVer.Build, 0);
if (ComparePackedVersion(WinVerPacked, PackVersionComponents(6, 1, 7601, 0)) < 0) or
((ComparePackedVersion(WinVerPacked, PackVersionComponents(6, 2, 0, 0)) >= 0) and
(ComparePackedVersion(WinVerPacked, PackVersionComponents(6, 3, 0, 0)) < 0)) then
begin
MsgBox(SetupMessage(msgWindowsVersionNotSupported), mbError, MB_OK);
Result := False;
end;
和上面类似,这也应该有效:
if (WinVerPacked < PackVersionComponents(6, 1, 7601, 0)) or
((WinVerPacked >= PackVersionComponents(6, 2, 0, 0)) and
(WinVerPacked < PackVersionComponents(6, 3, 0, 0))) then
您的第一个场景没有任何需要改进的地方。
我的脚本中有几个地方使用版本号:
场景一
#define AppVerText() \ GetVersionComponents(SourceDir + '\Meeting Schedule Assistant.exe', \ Local[0], Local[1], Local[2], Local[3]), \ Str(Local[0]) + "." + Str(Local[1]) + "." + Str(Local[2])
场景二
{ Is the installed version at least 14.14 ? } Result := (Major < 14) or ((Major = 14) and ((Minor < 14) or ((Minor = 14) and ((Bld < 26429) or ((Bld = 26429) and (Rbld < 3)))))); if (Result) then
各种值是从注册表项中提取的。
场景三
{ Check Windows Version } WindowsVersion := GetWindowsVersion; Log(Format('Windows Version: %x', [WindowsVersion])); (* Windows must be Win 7 SP1 (6.1.7601), Win 8.1 (6.3.9200) or higher, eg: Win 10 (10.0.10240) See: http://www.jrsoftware.org/ishelp/index.php?topic=winvernotes Microsoft .Net Framework 4.6.2 will only work with these operating systems. *) if (WindowsVersion < MakeVersion(6, 1, 7601)) or ((WindowsVersion >= MakeVersion(6, 2, 0)) and (WindowsVersion < MakeVersion(6, 3, 0))) then begin MsgBox(SetupMessage(msgWindowsVersionNotSupported), mbError, MB_OK); Result := False; end;
调用:
function MakeVersion(Major, Minor, Build: Cardinal): Cardinal; begin Result := (Major shl 24) + (Minor shl 16) + Build; end;
我只是想知道我们是否能够使用 Inno Setup 6.1 中引入的新“版本”Pascal 函数等?
你可以利用ComparePackedVersion
function (together with PackVersionComponents
):
Result :=
(ComparePackedVersion(
PackVersionComponents(Major, Minor, Bld, Rbld),
PackVersionComponents(14, 14, 26429, 3)) < 0);
在代码长度方面没有太大的改进。但它更不容易出错,也更容易理解。
我相信直接比较打包版本号实际上是安全的(至少除非您的主要版本不高于 2^15)。尽管 PackVersionComponents
不鼓励这样做。
Result :=
(PackVersionComponents(Major, Minor, Bld, Rbld) <
PackVersionComponents(14, 14, 26429, 3));
相关问题:
对于 Windows 版本测试,您可以将其与 GetWindowsVersionEx
结合使用:
GetWindowsVersionEx(WinVer);
WinVerPacked := PackVersionComponents(WinVer.Major, WinVer.Minor, WinVer.Build, 0);
if (ComparePackedVersion(WinVerPacked, PackVersionComponents(6, 1, 7601, 0)) < 0) or
((ComparePackedVersion(WinVerPacked, PackVersionComponents(6, 2, 0, 0)) >= 0) and
(ComparePackedVersion(WinVerPacked, PackVersionComponents(6, 3, 0, 0)) < 0)) then
begin
MsgBox(SetupMessage(msgWindowsVersionNotSupported), mbError, MB_OK);
Result := False;
end;
和上面类似,这也应该有效:
if (WinVerPacked < PackVersionComponents(6, 1, 7601, 0)) or
((WinVerPacked >= PackVersionComponents(6, 2, 0, 0)) and
(WinVerPacked < PackVersionComponents(6, 3, 0, 0))) then
您的第一个场景没有任何需要改进的地方。