-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathutils.iss
141 lines (129 loc) · 3.92 KB
/
utils.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
[Code]
// Yeah... Too much complex to be by default in IS Pascal I guess...
function StrSplit(Text: String; Separator: String): TArrayOfString;
var
i, p: Integer;
Dest: TArrayOfString;
begin
i := 0;
repeat
SetArrayLength(Dest, i+1);
p := Pos(Separator,Text);
if p > 0 then begin
Dest[i] := Copy(Text, 1, p-1);
Text := Copy(Text, p + Length(Separator), Length(Text));
i := i + 1;
end else begin
Dest[i] := Text;
Text := '';
end;
until Length(Text)=0;
Result := Dest
end;
function GetUninstallRegPath(Reverse: Boolean): String;
begin
if not Reverse then
begin
#if InstallType == "EE"
Result := 'Software\Microsoft\Windows\CurrentVersion\Uninstall\{{#EE_AppID}}_is1';
#elif InstallType == "NeoEE"
Result := 'Software\Microsoft\Windows\CurrentVersion\Uninstall\{{#NeoEE_AppID}}_is1';
#else
#error "Unknown Install Type"
#endif
end else begin
#if InstallType == "EE"
Result := 'Software\Microsoft\Windows\CurrentVersion\Uninstall\{{#NeoEE_AppID}}_is1';
#elif InstallType == "NeoEE"
Result := 'Software\Microsoft\Windows\CurrentVersion\Uninstall\{{#EE_AppID}}_is1';
#else
#error "Unknown Install Type"
#endif
end;
end;
function IsAnotherGameInstalled(): Boolean;
begin
Result := False;
if RegValueExists(HKA, GetUninstallRegPath(True), 'UninstallString')
then begin
Result := True;
end;
end;
function IsGameInstalled(): Boolean;
begin
Result := False;
if RegValueExists(HKA, GetUninstallRegPath(False), 'UninstallString')
then begin
Result := True;
end;
end;
// Return HTTP code or -1 if error
function SendRequest(const URL: String; const HttpFallback: Boolean; const Asynchronous: Boolean): Integer;
var
WinHttpRequest: Variant;
Https: Boolean;
begin
Result := -1;
Https := False;
if (Pos('https://', URL) <> 0) then
Https := True;
// if (Https and not IsWindowsXPOrNewer()) // Force HTTP usage for < XP
// StringChangeEx(URL, 'https', 'http', True)
Log('Sending request: ' + URL + ' (HTTPS: ' + IntToStr(Integer(Https)) + ')');
try
WinHttpRequest := CreateOleObject('WinHttp.WinHttpRequest.5.1'); // 5.0 for < Win2000 SP3 / WinXP SP1 ?
WinHttpRequest.SetTimeouts(6000, 4000, 4000, 4000);
WinHttpRequest.Open('GET', URL, False);
WinHttpRequest.Send;
if (Asynchronous) then
begin
Result := -2
end else begin
WinHttpRequest.WaitForResponse()
Result := WinHttpRequest.Status;
end;
Log('Status: ' + IntToStr(Result));
except
Log('Failed request: ' + URL);
Log(GetExceptionMessage);
Result := -1;
if (Https and HttpFallback) then
begin
Log('URL was using HTTPS, trying HTTP as fallback...');
StringChangeEx(URL, 'https', 'http', True);
Result := SendRequest(URL, False, Asynchronous);
end;
end;
end;
function DownloadString(const URL: string; var Response: string; const HttpFallback: Boolean): Integer;
var
WinHttpRequest: Variant;
Https: Boolean;
begin
Result := -1;
Https := False;
if (Pos('https://', URL) <> 0) then
Https := True;
Log('Downloading string: ' + URL + ' (HTTPS: ' + IntToStr(Integer(Https)) + ')');
try
Response := '';
WinHttpRequest := CreateOleObject('WinHttp.WinHttpRequest.5.1'); // 5.0 for < Win2000 SP3 / WinXP SP1 ?
WinHttpRequest.SetTimeouts(8000, 4000, 4000, 4000);
WinHttpRequest.Open('GET', URL, False);
WinHttpRequest.Send;
WinHttpRequest.WaitForResponse();
Result := WinHttpRequest.Status;
Response := WinHttpRequest.ResponseText;
Log('Downloaded string: ' + URL + ' [Code: ' + IntToStr(Result) + ', Length: ' + IntToStr(Length(Response)) + ']');
except
Log('Failed to download: ' + URL);
Log(GetExceptionMessage);
Result := -1;
if (Https and HttpFallback) then
begin
Log('URL was using HTTPS, trying HTTP as fallback...');
StringChangeEx(URL, 'https', 'http', True);
Result := DownloadString(URL, Response, False);
end;
end;
end;