-
Notifications
You must be signed in to change notification settings - Fork 1
/
example.iss
83 lines (66 loc) · 2.45 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
[Setup]
AppName=Example
AppVersion=1.0
DefaultDirName={commonpf}\Example
[Files]
Source: "yamlconfig.dll"; Flags: dontcopy
Source: "example.yaml"; DestDir: "{tmp}"; Flags: dontcopy
[Code]
const
CP_ACP = 0;
CP_UTF8 = 65001;
function YAMLReadString(AFileName, APath, ADefault: AnsiString): PAnsiChar;
external 'YAMLReadString@files:yamlconfig.dll cdecl';
function YAMLWriteString(AFileName, APath, AValue:AnsiString): Integer;
external 'YAMLWriteString@files:yamlconfig.dll cdecl';
function MultiByteToWideChar(
CodePage: UINT; dwFlags: DWORD; const lpMultiByteStr: AnsiString; cchMultiByte: Integer;
lpWideCharStr: string; cchWideChar: Integer): Integer;
external '[email protected] stdcall';
function ANSIToUTF8(Str:AnsiString):String;
var
Len:Integer;
begin
Len := MultiByteToWideChar(CP_UTF8, 0, Str, Length(Str), Result, 0);
SetLength(Result, Len);
MultiByteToWideChar(CP_UTF8, 0, Str, Length(Str), Result, Len);
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: AnsiString;
strVal: AnsiString;
begin
Page := CreateOutputMsgMemoPage(wpWelcome, 'Information', 'Display results', '', '');
Page.RichEditViewer.UseRichEdit := True;
ExtractTemporaryFile('example.yaml')
fileName := ExpandConstant('{tmp}\example.yaml');
rtf := '{\rtf1{\colortbl;\red0\green0\blue255;\red255\green0\blue0;}';
strVal := YAMLReadString(fileName, 'foo.str', 'default');
AddToRTF(rtf, 'YAMLReadString', 'foo.str', ANSIToUTF8(strVal), True);
//rtf := rtf + '\line' + #13#10;
strVal := YAMLReadString('æóëèê.txt', 'anything', 'default');
AddToRTF(rtf, 'YAMLReadString', 'foo.str', ANSIToUTF8(strVal), True);
rtf := rtf + '\line' + #13#10;
// Write
if YAMLWriteString(fileName, 'iss', 'InnoSetup')=0 {and YAMLReadString(fileName, 'foo.str', 'default', strVal, strLen)} then
AddToRTF(rtf, 'YAMLWriteString', 'foo.str', {Copy(strVal, 1, strLen)}'ok', True)
else
AddToRTF(rtf, 'YAMLWriteString', 'foo.str', 'failed', False);
rtf := rtf + '}';
Page.RichEditViewer.RTFText := rtf;
end;
function NextButtonClick(CurPageID: Integer): Boolean;
begin
Result := not (CurPageID = Page.ID);
end;