从命令行应用程序将字符串值传递给 Inno Setup

发布于 2024-07-14 17:21:30 字数 385 浏览 4 评论 0原文

场景是,我们有一个客户端/服务器应用程序,客户端安装是使用 Inno Setup 的引导程序,它从 IP/端口号指定的服务器下载客户端。 我们希望能够通过 UDP 广播检测本地网络上是否有服务器,并可以编写一个控制台应用程序来执行此操作。 问题是,我们如何将信息从控制台应用程序传递到安装程序?

我可以捕获返回码,但它只能是一个 int。 据我所知,Inno Setup 中读取文件的唯一功能是在预处理器中,因此我们无法读取控制台应用程序在运行时创建的文件。 我唯一能想到的就是返回一个 int ,其中前 4 位数字是端口之前 '.' 和 : 的位置,然后解析出该值,这看起来很hackish、脆弱且容易出错,特别是考虑到我不太熟悉用于构造字符串的 Inno Setup 语法/函数。

有什么建议么?

The scenario is that we have a client/server app with the client install being a bootstrapper using Inno Setup that downloads the client from the server specified by IP/Port number. We'd like to be able to detect if there is a server on the local network via UDP broadcasting, and can write a console app that does that. Problem is, how do we pass the information from the console app to the installer?

I can capture the return code, but that can only be an int. As far as I can tell, the only functions to read file in Inno Setup is in the preprocessor so we can't read a file created at runtime by the console app. The only thing I can think of is to return an int where the first 4 digits are the position of the '.'s and : before the port and then parse out the value, which seems hackish, flimsy, and error prone, especially considering I'm not intimately familiar with Inno Setup syntax/functions for constructing a string.

Any suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

我喜欢麦丽素 2024-07-21 17:21:30

如果您想从 Inno Setup 中的代码解析命令行参数,请使用与此类似的方法。 只需从命令行调用安装程序,如下所示:

c:\MyInstallDirectory>MyInnoSetup.exe -myParam parameterValue

然后您可以在任何需要的地方调用 GetCommandLineParam

myVariable := GetCommandLineParam('-myParam');
{ ================================================================== }
{ Allows for standard command line parsing assuming a key/value organization }

function GetCommandlineParam (inParam: String):String; 
var 
  LoopVar : Integer; 
  BreakLoop : Boolean; 
begin 
  { Init the variable to known values } 
  LoopVar :=0; 
  Result := ''; 
  BreakLoop := False; 

  { Loop through the passed in array to find the parameter } 
  while ( (LoopVar < ParamCount) and 
      (not BreakLoop) ) do 
  begin 
    { Determine if the looked for parameter is the next value } 
    if ( (ParamStr(LoopVar) = inParam) and 
       ( (LoopVar+1) < ParamCount )) then 
    begin 
      { Set the return result equal to the next command line parameter } 
      Result := ParamStr(LoopVar+1); 

      { Break the loop } 
      BreakLoop := True; 
    end 

    { Increment the loop variable } 
    LoopVar := LoopVar + 1; 
  end; 
end; 

If you want to parse command line arguments from code in Inno Setup, then use a method similar to this. Just call the installer from the command line as follows:

c:\MyInstallDirectory>MyInnoSetup.exe -myParam parameterValue

Then you can call the GetCommandLineParam like this wherever you need it:

myVariable := GetCommandLineParam('-myParam');
{ ================================================================== }
{ Allows for standard command line parsing assuming a key/value organization }

function GetCommandlineParam (inParam: String):String; 
var 
  LoopVar : Integer; 
  BreakLoop : Boolean; 
begin 
  { Init the variable to known values } 
  LoopVar :=0; 
  Result := ''; 
  BreakLoop := False; 

  { Loop through the passed in array to find the parameter } 
  while ( (LoopVar < ParamCount) and 
      (not BreakLoop) ) do 
  begin 
    { Determine if the looked for parameter is the next value } 
    if ( (ParamStr(LoopVar) = inParam) and 
       ( (LoopVar+1) < ParamCount )) then 
    begin 
      { Set the return result equal to the next command line parameter } 
      Result := ParamStr(LoopVar+1); 

      { Break the loop } 
      BreakLoop := True; 
    end 

    { Increment the loop variable } 
    LoopVar := LoopVar + 1; 
  end; 
end; 
泪之魂 2024-07-21 17:21:30

不知道如何从命令行加载参数,但您可以使用 LoadStringFromFile 加载文件内容或 GetIniString 从 ini 文件读取参数。

更一般地说,在 Inno Setup 帮助文件中查找“支持功能参考”。 此页面将为您提供所有 Inno 函数的列表(不包括预处理器)。 如果您找不到此页面(如果您只找到有关预处理器的信息),那么您可能正在查找错误的帮助文件。 请注意,Inno Setup 帮助的目录不是那么好,但索引非常好。

命令行参数记录在“设置命令行参数”页面上。 您可能可以通过使用现有参数之一来欺骗 Inno,但使用 ini 文件似乎是最直接的方法。

Don't know how to load a parameter from the command line, but you can use LoadStringFromFile to load the contents of a file or GetIniString to read a parameter from an ini file.

More generally, look for "Support Functions Reference" in the Inno Setup Help file. This page will give you a list of all the Inno functions (not including the preprocessor). If you can't find this page (if you only find information about the preprocessor) then you may be looking in the wrong helpfile. Note that the Inno Setup Help table of contents isn't all that great but the index is very good.

Command line parameters are documented on the page "Setup Command Line Parameters". It's possible that you might be able to trick Inno by using one of the existing parameters, but using an ini file seems like it would be the most straightforward approach.

笑叹一世浮沉 2024-07-21 17:21:30

上面的匿名回答应该被点赞。

我只需在脚本中按名称引用参数即可将参数传递给安装程序:

{param:filePath|abc}

然后在调用安装程序时使用所需的格式传递参数值:

MyInnoSetup.exe /filePath=../foo.exe

The above anonymous answer should be upvoted.

I was able to pass an argument to my installer by just referring to the parameter by name in the script:

{param:filePath|abc}

And then when calling the installer pass the parameter value using the required format:

MyInnoSetup.exe /filePath=../foo.exe
俏︾媚 2024-07-21 17:21:30

InnoSetup 包含一种类似 Pascal 的解释型扩展语言,可以在安装程序运行时用于很多事情。

例如,我知道它可以读取注册表,并且我相当确定它可以读取文件,至少可以从某些文件夹中读取文件。 您的控制台模式应用程序可以写入临时文件或删除一个或多个包含安装程序其余部分所需信息的注册表项,并且可以从脚本环境返回到正确的安装脚本中。 安装程序甚至可以稍后清理临时文件和/或密钥。

InnoSetup includes an interpreted Pascal-like extension language that can be used to a lot of things during the installer's runtime.

For instance, I know it can read the registry, and I am fairly sure it can read files, at least from some folders. Your console-mode app could write a temp file or drop one or more registry keys containing the info needed in the rest of the installer, and that can be returned from the scripting environment into the setup script proper. The installer could even clean up the temp file and/or keys later.

‖放下 2024-07-21 17:21:30

来自 Inno Setup 手册:

{param:ParamName|DefaultValue}

Embeds a command line parameter value.
    * ParamName specifies the name of the command line parameter to read from.
    * DefaultValue determines the string to embed if the specified command 
      line parameter does not exist, or its value could not be determined.

示例:

[Setup]
应用程序 ID=...
AppName={param:exe_name|xyz}.exe

更多:www downloadatoz com/manual/in/inno-setup/topic_consts.htm

From the Inno Setup manual:

{param:ParamName|DefaultValue}

Embeds a command line parameter value.
    * ParamName specifies the name of the command line parameter to read from.
    * DefaultValue determines the string to embed if the specified command 
      line parameter does not exist, or its value could not be determined.

Example:

[Setup]
AppId=...
AppName={param:exe_name|xyz}.exe

More: www downloadatoz com/manual/in/inno-setup/topic_consts.htm

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文