1
votes

I'm using Eclipse and Inno Setup to create a little application. Compiling is made with Ant. Everything works fine, I could find where the default .iss is generated, place it in my Eclipse package and could mod it to make my installer inject the registry keys to make Windows support my application custom URL.

(project/build/package/windows/myapp.iss, added [Registry] part)

It works, under IE and Edge, but unfortunately not for Chrome as Google decided not to follow the registry when it comes to custom URLs...

Does any of you know if it would be possible to install the custom URL for Chrome via an Inno Setup installer?

What I know so far is that we need to mod %localappdata%/Google/Chrome/User Data/Local State to add the protocol, but is it doable through Inno Setup?

1

1 Answers

1
votes

The Local State configuration file of Chrome is in the JSON format.

The Inno Setup does not support the JSON on its own. You can try to hack the file manually using a simple string manipulation.

But I'd recommend you to use some 3rd party library for parsing JSON, like TLama's Inno JSON Config library.


The code can be like below.

The code add/sets this key in the JSON. I hope this is, what you are after.

"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;

The code requires the Unicode version of Inno Setup.


See also Inno Setup: Working with JSON.


There's also an alternative implementation, the JsonParser.