-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.iss
115 lines (95 loc) · 3.95 KB
/
example.iss
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
[Setup]
AppName=Example
AppVersion=1.0
DefaultDirName={commonpf}\Example
[Files]
Source: "jsonconfig.dll"; Flags: dontcopy
Source: "example.json"; DestDir: "{tmp}"; Flags: dontcopy
[Code]
function JSONReadString(AFileName, APath, ADefault: WideString; var AValue: WideString; var AValueLength: Integer): Boolean;
external 'JSONReadString@files:jsonconfig.dll stdcall';
function JSONReadBoolean(AFileName, APath: WideString; ADefault: Boolean; var AValue: Boolean): Boolean;
external 'JSONReadBoolean@files:jsonconfig.dll stdcall';
function JSONReadInteger(AFileName, APath: WideString; ADefault: Int64; var AValue: Int64): Boolean;
external 'JSONReadInteger@files:jsonconfig.dll stdcall';
function JSONWriteString(AFileName, APath, AValue: WideString): Boolean;
external 'JSONWriteString@files:jsonconfig.dll stdcall';
function JSONWriteBoolean(AFileName, APath: WideString; AValue: Boolean): Boolean;
external 'JSONWriteBoolean@files:jsonconfig.dll stdcall';
function JSONWriteInteger(AFileName, APath: WideString; AValue: Int64): Boolean;
external 'JSONWriteInteger@files:jsonconfig.dll stdcall';
function BoolToStr(Value: Boolean): String;
begin
Result := 'True';
if not Value then
Result := 'False';
end;
procedure AddToRTF(var Res: String; FuncName: String; Path: String; Value: String; Ok: Boolean);
begin
if Ok then
Res := Res + Format('{\i %s}: {\b %s} = {\cf1 %s}\line', [FuncName, Path, Value])
else
Res := Res + Format('{\i %s}: {\b %s} = {\cf2 %s}\line', [FuncName, Path, Value]);
Res := Res + #13#10;
end;
var
Page: TOutputMsgMemoWizardPage;
procedure InitializeWizard;
var
rtf: String;
fileName: WideString;
strVal: WideString;
strLen: Integer;
intVal: Int64;
boolVal: Boolean;
begin
Page := CreateOutputMsgMemoPage(wpWelcome, 'Information', 'Display results', '', '');
Page.RichEditViewer.UseRichEdit := True;
ExtractTemporaryFile('example.json')
fileName := ExpandConstant('{tmp}\example.json');
rtf := '{\rtf1{\colortbl;\red0\green0\blue255;\red255\green0\blue0;}';
// Read
SetLength(strVal, 256);
strLen := Length(strVal);
if JSONReadString(fileName, '/str', 'default', strVal, strLen) then
AddToRTF(rtf, 'JSONReadString', 'str', Copy(strVal, 1, strLen), True)
else
AddToRTF(rtf, 'JSONReadString', 'str', 'failed', False);
rtf := rtf + '\line' + #13#10;
SetLength(strVal, 256);
strLen := Length(strVal);
if JSONReadString(fileName, '/foo/str', 'default', strVal, strLen) then
AddToRTF(rtf, 'JSONReadString', 'foo.str', Copy(strVal, 1, strLen), True)
else
AddToRTF(rtf, 'JSONReadString', 'foo.str', 'failed', False);
if JSONReadInteger(fileName, '/foo/int', 0, intVal) then
AddToRTF(rtf, 'JSONReadInteger', 'foo.int', IntToStr(intVal), True)
else
AddToRTF(rtf, 'JSONReadInteger', 'foo.int', 'failed', False);
if JSONReadBoolean(fileName, '/bar/bool', True, boolVal) then
AddToRTF(rtf, 'JSONReadBoolean', 'bar.bool', BoolToStr(boolVal), True)
else
AddToRTF(rtf, 'JSONReadBoolean', 'bar.bool', 'failed', False);
rtf := rtf + '\line' + #13#10;
// Write
SetLength(strVal, 256);
strLen := Length(strVal);
if JSONWriteString(fileName, '/foo/str', 'InnoSetup') and JSONReadString(fileName, '/foo/str', 'default', strVal, strLen) then
AddToRTF(rtf, 'JSONWriteString', 'foo.str', Copy(strVal, 1, strLen), True)
else
AddToRTF(rtf, 'JSONWriteString', 'foo.str', 'failed', False);
if JSONWriteInteger(fileName, '/foo/int', 3) and JSONReadInteger(fileName, '/foo/int', 0, intVal) then
AddToRTF(rtf, 'JSONWriteInteger', 'foo.int', IntToStr(intVal), True)
else
AddToRTF(rtf, 'JSONWriteInteger', 'foo.int', 'failed', False);
if JSONWriteBoolean(fileName, '/bar/bool', True) and JSONReadBoolean(fileName, '/bar/bool', True, boolVal) then
AddToRTF(rtf, 'JSONWriteBoolean', 'bar.bool', BoolToStr(boolVal), True)
else
AddToRTF(rtf, 'JSONWriteBoolean', 'bar.bool', 'failed', False);
rtf := rtf + '}';
Page.RichEditViewer.RTFText := rtf;
end;
function NextButtonClick(CurPageID: Integer): Boolean;
begin
Result := not (CurPageID = Page.ID);
end;