在Inno Setup的安装过程中写入Node app .js配置

菲尔

我发现了如何创建向导页面来收集所需信息的方法。但是我的应用程序有一个config.js文件,我需要在其中根据用户输入更改一些值。写入该文件的最佳方法是什么?使用写入整个文件SaveStringToFile或以某种方式导入文件并替换某些字符串部分?

这是当前配置的摘录:

let cfg = {
  hapi: {
    port: 3000,
    host: '0.0.0.0',
    maxUploadBytes: 1000000 * 50 // 50 MB
  },
  jwt: {
    key: 'secretkey',
    algorithm: 'HS256',
    expiresIn: '1h'
  },
  authentication: {
    encryption: {
      saltRounds: 10 // will be used in bcrypt to encrypt passwords
    }
  },
  db_config: {
    user: 'username',
    password: 'pw',
    server: 'DESKTOP-IG',
    database: 'TestDB-1'
  },
  scripts: {
    ConnectorInstallPath: "C:\\Program\ Files\\ Connector\\"
  }
}

我必须要改变的值:user: 'username'password: 'pw'server: 'DESKTOP-IG'database: 'TestDB-1'port: 3000,和ConnectorInstallPath: "C:\\Program\ Files\\ Connector\\"

使用类似的模式进行替换server: '*'就足够了。它不需要更聪明。

非常感谢。

马丁·普里克里(Martin Prikryl)

以下函数可以更改配置文件中的属性:

function SetConfigProperty(FileName, Name: string; Value: string): Boolean;
var
  Lines: TArrayOfString;
  Count, I, P: Integer;
  HasComma: Boolean;
  Line: string;
  State: Integer;
begin
  Result := True;

  if not LoadStringsFromFile(FileName, Lines) then
  begin
    Log(Format('Error reading %s', [FileName]));
    Result := False;
  end
    else
  begin
    State := 0;

    Count := GetArrayLength(Lines);
    for I := 0 to Count - 1 do
    begin
      Line := Lines[I];
      P := Pos(':', Line);
      if (CompareText(Trim(Copy(Line, 1, P - 1)), Name) = 0) then
      begin
        Log(Format('Found property %s at line %d', [Name, (I + 1)]));

        HasComma := (Copy(Trim(Line), Length(Trim(Line)), 1) = ',');

        Line := Copy(Line, 1, P) + ' ' + Value;
        if HasComma then Line := Line + ',';
        Lines[I] := Line;

        Result := SaveStringsToFile(FileName, Lines, False);
        if not Result then
        begin
          Log(Format('Error writing %s', [FileName]));
        end
          else
        begin
          Log(Format('Modifications saved to %s', [FileName]));
        end;

        break;
      end;
      if I = Count - 1 then
      begin
        Log(Format('Property %s not found', [Name]));
        Result := False;
      end;
    end;
  end;
end;

Value必须包含冒号后面完整内容。使用字符串属性,甚至必须包含引号。例如:

SetConfigProperty(FileName, 'server', '''DESKTOP-IG''');

您可以CurStepChangedssPostInstall步骤中的事件功能中使用该功能,例如(已安装文件时):

procedure CurStepChanged(CurStep: TSetupStep);
var
  FileName: string;
  ErrorCode: Integer;
begin
  if CurStep = ssPostInstall then
  begin
    FileName := ExpandConstant('{app}\config.js');
    SetConfigProperty(FileName, 'username', '''' + UsernameEdit.Text + '''');
    SetConfigProperty(FileName, 'Password', '''' + PasswordEdit.Text + '''');
    SetConfigProperty(FileName, 'server', '''' + ServerEdit.Text + '''');
    SetConfigProperty(FileName, 'port', PortEdit.Text);
    { ... }
  end;
end;

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

安装过程中Google App Engine上的WordPress错误

来自分类Dev

Inno Setup:在设置过程中重新启动

来自分类Dev

强制Inno安装程序在安装过程中显示UAC提示

来自分类Dev

Inno Setup:确认{app}路径中没有空格

来自分类Dev

在安装后续过程中,Inno安装程序将执行[UninstallRun]

来自分类Dev

使用inno-setup在安装过程中显示文本

来自分类Dev

在Inno Setup中取消安装

来自分类Dev

Inno Setup中的TTreeView

来自分类Dev

Inno Setup:在安装过程中重新启动不会在重启后开始

来自分类Dev

Inno Setup:如何在InitializeWizard中使用{app}?

来自分类Dev

var app = express();的用途是什么?在创建Node.Js应用程序的过程中?

来自分类Dev

在Inno Setup中从过程调用函数?

来自分类Dev

Inno Setup:在卸载过程中从安装程序读取文件

来自分类Dev

通过Inno Setup创建的安装程序无法在Windows 10上的安装过程中关闭应用程序

来自分类Dev

在静默安装过程中,Inno Setup将锁定的文件替换为下一次重新启动

来自分类Dev

添加选项以在安装过程中配置Office 365加载项

来自分类Dev

用于Inno设置的DwinsHs:编辑URL的HTTP_HEADER常量以在安装过程中下载

来自分类Dev

Inno Setup:在卸载过程中重新启动后删除文件夹

来自分类Dev

使用配置文件选择要与Inno Setup一起安装的组件

来自分类Dev

Inno Setup:加载在安装过程中为wpInfoAfter编辑的文件

来自分类Dev

Inno Setup:加载在安装过程中为wpInfoAfter编辑的文件

来自分类Dev

从{app}执行PowerShell脚本在Inno Setup中失败,而从{tmp}执行执行

来自分类Dev

Inno Setup-如何在设置过程中从文本文件编辑特定行?

来自分类Dev

在TFS安装过程中配置报告服务的要求

来自分类Dev

debian-installer在安装过程中如何配置WiFi?

来自分类Dev

Inno安装程序在安装过程中执行大的sql脚本文件

来自分类Dev

如何在Inno Setup中仅根据条件安装文件(外部配置文件)

来自分类Dev

在 apt 安装过程中跳过一个包的配置

来自分类Dev

在安装过程中忽略预置配置(使用立方)

Related 相关文章

  1. 1

    安装过程中Google App Engine上的WordPress错误

  2. 2

    Inno Setup:在设置过程中重新启动

  3. 3

    强制Inno安装程序在安装过程中显示UAC提示

  4. 4

    Inno Setup:确认{app}路径中没有空格

  5. 5

    在安装后续过程中,Inno安装程序将执行[UninstallRun]

  6. 6

    使用inno-setup在安装过程中显示文本

  7. 7

    在Inno Setup中取消安装

  8. 8

    Inno Setup中的TTreeView

  9. 9

    Inno Setup:在安装过程中重新启动不会在重启后开始

  10. 10

    Inno Setup:如何在InitializeWizard中使用{app}?

  11. 11

    var app = express();的用途是什么?在创建Node.Js应用程序的过程中?

  12. 12

    在Inno Setup中从过程调用函数?

  13. 13

    Inno Setup:在卸载过程中从安装程序读取文件

  14. 14

    通过Inno Setup创建的安装程序无法在Windows 10上的安装过程中关闭应用程序

  15. 15

    在静默安装过程中,Inno Setup将锁定的文件替换为下一次重新启动

  16. 16

    添加选项以在安装过程中配置Office 365加载项

  17. 17

    用于Inno设置的DwinsHs:编辑URL的HTTP_HEADER常量以在安装过程中下载

  18. 18

    Inno Setup:在卸载过程中重新启动后删除文件夹

  19. 19

    使用配置文件选择要与Inno Setup一起安装的组件

  20. 20

    Inno Setup:加载在安装过程中为wpInfoAfter编辑的文件

  21. 21

    Inno Setup:加载在安装过程中为wpInfoAfter编辑的文件

  22. 22

    从{app}执行PowerShell脚本在Inno Setup中失败,而从{tmp}执行执行

  23. 23

    Inno Setup-如何在设置过程中从文本文件编辑特定行?

  24. 24

    在TFS安装过程中配置报告服务的要求

  25. 25

    debian-installer在安装过程中如何配置WiFi?

  26. 26

    Inno安装程序在安装过程中执行大的sql脚本文件

  27. 27

    如何在Inno Setup中仅根据条件安装文件(外部配置文件)

  28. 28

    在 apt 安装过程中跳过一个包的配置

  29. 29

    在安装过程中忽略预置配置(使用立方)

热门标签

归档