【问题标题】:Inno Setup Custom URL for ChromeChrome 的 Inno 设置自定义 URL
【发布时间】:2015-11-01 09:47:52
【问题描述】:

我正在使用 Eclipse 和 Inno Setup 创建一个小应用程序。使用 Ant 进行编译。一切正常,我可以找到生成默认 .iss 的位置,将其放在我的 Eclipse 包中,并可以对其进行修改以使我的安装程序注入注册表项以使 Windows 支持我的应用程序自定义 URL。

project/build/package/windows/myapp.iss,添加了[Registry] 部分)

它可以在 IE 和 Edge 下工作,但不幸的是,Chrome 不支持,因为 Google 决定在自定义 URL 方面不遵循注册表...

你们中有人知道是否可以通过 Inno Setup 安装程序安装 Chrome 的自定义 URL 吗?

目前我知道的是,我们需要修改%localappdata%/Google/Chrome/User Data/Local State 来添加协议,但是通过 Inno Setup 是否可行?

【问题讨论】:

    标签: google-chrome inno-setup custom-url


    【解决方案1】:

    Chrome的Local State配置文件为JSON格式。

    Inno 设置本身不支持 JSON。您可以尝试使用简单的字符串操作手动破解文件。

    但我建议您使用一些 3rd 方库来解析 JSON,例如 TLama's Inno JSON Config library


    代码如下。

    代码在 JSON 中添加/设置此键。我希望这就是你所追求的。

    "protocol_handler": { 
      "excluded_schemes": { 
         "myprotocol": true
      }
    }
    
    [Files]
    Source: "JSONConfig.dll"; Flags: dontcopy
    
    [code]
    function JSONQueryBoolean(FileName, Section, Key: WideString; 
      Default: Boolean; var Value: Boolean): Boolean;
      external 'JSONQueryBoolean@files:jsonconfig.dll stdcall';
    function JSONWriteBoolean(FileName, Section, Key: WideString;
      Value: Boolean): Boolean;
      external 'JSONWriteBoolean@files:jsonconfig.dll stdcall';
    
    procedure EnableChromeProtocol(Protocol: string);
    var
      FileName: WideString;
      BoolValue: Boolean;
    begin
      FileName := ExpandConstant('{localappdata}') + '\Google\Chrome\User Data\Local State';
      Log('Chrome local state config file: ' + FileName);
    
      if JSONQueryBoolean(
           FileName, 'protocol_handler.excluded_schemes', Protocol, False, BoolValue) then
      begin
        if BoolValue then
        begin
          Log('Protocol is enabled');
        end
          else
        begin
          Log('Protocol is disabled');
        end;
      end
        else
      begin
        Log('Protocol not configured');
        BoolValue := False;
      end;
    
      if not BoolValue then
      begin
        if JSONWriteBoolean(FileName, 'protocol_handler.excluded_schemes', Protocol, True) then
        begin
          Log('Protocol enabled');
        end
          else
        begin
          Log('Protocol enabling failed');
        end;
      end;
    end;
    
    procedure CurStepChanged(CurStep: TSetupStep);
    begin
      if CurStep = ssInstall then
      begin
        EnableChromeProtocol('myprotocol');
      end;
    end;
    

    代码需要 Inno Setup 的 Unicode 版本。


    另见Inno Setup: Working with JSON


    还有一个替代实现,JsonParser

    【讨论】:

    • 哇,这正是我所追求的,即使我现在无法测试,我已经可以说这是我需要的......今晚我回家后会检查如果需要,会回来的。非常感谢!
    • 好的,一切正常,只需要绝对确保 Chrome 以及他们的新后台服务已关闭,否则将覆盖此安装过程。不,要启用协议,它应该设置为“false”。但由于某些原因,它仍然不适用于我的网址,但这是另一个问题。感谢您的帮助和脚本!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-05-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多