代码之家  ›  专栏  ›  技术社区  ›  Ch3micaL

Inno设置检查外部应用程序版本

  •  2
  • Ch3micaL  · 技术社区  · 7 年前

    我要实现的是检查node.js是否已经安装,如果已经安装,那么我要检查最新版本,比如8.x.x。

    从下面的问题来看,我已经对它的安装进行了初步检查。我的代码看起来很像问题的答案。

    Using Process Exit code to show error message for a specific File in [Run]

    现在我正在努力阅读 node -v 命令(预期结果是包含版本的字符串)。

    有没有办法做到这一点?

    1 回复  |  直到 7 年前
        1
  •  2
  •   Martin Prikryl    7 年前

    运行一个应用程序并分析其输出是非常低效的方法来检查它是否存在及其版本。使用 FileSearch ( node.exe 被添加到 PATH ) 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;
    

    有关类似问题,请参见 Checking if Chrome is installed and is of specific version using Inno Setup .

    推荐文章