1

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?

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
Psychokiller1888
  • 620
  • 2
  • 10
  • 25

1 Answers1

1

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.

Community
  • 1
  • 1
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
  • 1
    Wow, this is exactly what I was after and even though I can't test right now I can already say it is what I was needing... Will check this evening when I get home and I'll be back if needed. Thank you many times! – Psychokiller1888 Nov 01 '15 at 12:04
  • Ok, the whole thing works, just have to make absolutely sure that Chrome is closed as well as their new background service, or that will overwrite this install procedure. Not, to enable the protocol, it should be set to "false". But for some reasons it still won't work with my url, but that's another question. Thank you for your help and script! – Psychokiller1888 Nov 01 '15 at 17:52