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。