Inno Setup 检查外部应用程序的版本
Inno Setup check version of external application
我想要实现的是检查 Node.js 是否已经安装,如果是,我想检查版本是否是最新的,比方说 8.x.x
从下面的问题我已经完成了安装的初步检查。我的代码看起来与问题的答案非常相似。
Using Process Exit code to show error message for a specific File in [Run]
现在我正在努力读取 node -v
命令的实际输出(预期结果是一个包含版本的字符串)。
有办法实现吗?
运行 一个应用程序并解析它的输出是检查它是否存在及其版本的一种相当低效的方法。请改用 FileSearch
(node.exe
is added to PATH
) and GetVersionNumbers
函数。
[Code]
function CheckNodeJs(var Message: string): Boolean;
var
NodeFileName: string;
NodeMS, NodeLS: Cardinal;
NodeMajorVersion, NodeMinorVersion: Cardinal;
begin
{ Search for node.exe in paths listed in PATH environment variable }
NodeFileName := FileSearch('node.exe', GetEnv('PATH'));
Result := (NodeFileName <> '');
if not Result then
begin
Message := 'Node.js not installed.';
end
else
begin
Log(Format('Found Node.js path %s', [NodeFileName]));
Result := GetVersionNumbers(NodeFileName, NodeMS, NodeLS);
if not Result then
begin
Message := Format('Cannot read Node.js version from %s', [NodeFileName]);
end
else
begin
{ NodeMS is 32-bit integer with high 16 bits holding major version and }
{ low 16 bits holding minor version }
{ shift 16 bits to the right to get major version }
NodeMajorVersion := NodeMS shr 16;
{ select only low 16 bits }
NodeMinorVersion := NodeMS and $FFFF;
Log(Format('Node.js version is %d.%d', [NodeMajorVersion, NodeMinorVersion]));
Result := (NodeMajorVersion >= 8);
if not Result then
begin
Message := 'Node.js is too old';
end
else
begin
Log('Node.js is up to date');
end;
end;
end;
end;
function InitializeSetup(): Boolean;
var
Message: string;
begin
Result := True;
if not CheckNodeJs(Message) then
begin
MsgBox(Message, mbError, MB_OK);
Result := False;
end;
end;
从 Inno Setup 6.1 开始,您可以使用 GetVersionComponents
而不是 GetVersionNumbers
来避免位魔术。
对于类似的问题,请参阅 。
我想要实现的是检查 Node.js 是否已经安装,如果是,我想检查版本是否是最新的,比方说 8.x.x
从下面的问题我已经完成了安装的初步检查。我的代码看起来与问题的答案非常相似。
Using Process Exit code to show error message for a specific File in [Run]
现在我正在努力读取 node -v
命令的实际输出(预期结果是一个包含版本的字符串)。
有办法实现吗?
运行 一个应用程序并解析它的输出是检查它是否存在及其版本的一种相当低效的方法。请改用 FileSearch
(node.exe
is added to PATH
) and GetVersionNumbers
函数。
[Code]
function CheckNodeJs(var Message: string): Boolean;
var
NodeFileName: string;
NodeMS, NodeLS: Cardinal;
NodeMajorVersion, NodeMinorVersion: Cardinal;
begin
{ Search for node.exe in paths listed in PATH environment variable }
NodeFileName := FileSearch('node.exe', GetEnv('PATH'));
Result := (NodeFileName <> '');
if not Result then
begin
Message := 'Node.js not installed.';
end
else
begin
Log(Format('Found Node.js path %s', [NodeFileName]));
Result := GetVersionNumbers(NodeFileName, NodeMS, NodeLS);
if not Result then
begin
Message := Format('Cannot read Node.js version from %s', [NodeFileName]);
end
else
begin
{ NodeMS is 32-bit integer with high 16 bits holding major version and }
{ low 16 bits holding minor version }
{ shift 16 bits to the right to get major version }
NodeMajorVersion := NodeMS shr 16;
{ select only low 16 bits }
NodeMinorVersion := NodeMS and $FFFF;
Log(Format('Node.js version is %d.%d', [NodeMajorVersion, NodeMinorVersion]));
Result := (NodeMajorVersion >= 8);
if not Result then
begin
Message := 'Node.js is too old';
end
else
begin
Log('Node.js is up to date');
end;
end;
end;
end;
function InitializeSetup(): Boolean;
var
Message: string;
begin
Result := True;
if not CheckNodeJs(Message) then
begin
MsgBox(Message, mbError, MB_OK);
Result := False;
end;
end;
从 Inno Setup 6.1 开始,您可以使用 GetVersionComponents
而不是 GetVersionNumbers
来避免位魔术。
对于类似的问题,请参阅