forked from deajan/smartmontools-win
-
Notifications
You must be signed in to change notification settings - Fork 0
/
smartmontools for Windows includes.iss
214 lines (191 loc) · 5.33 KB
/
smartmontools for Windows includes.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
//// General purpose functions (2206201501)
[code]
//// Check if 64bit installation is not selected
function AMD64InstallNotSelected: Boolean;
begin
Result := not IsComponentSelected('core\64bits');
end;
//// Returns last char of a string
function LastChar(str: String): String;
begin
result := copy(str, Length(str), 1);
end;
//// Starts service after installation
function LoadService(srv: String): Integer;
var resultcode: Integer;
begin
Exec(ExpandConstant('{sys}\sc.exe'), 'start '+ srv, '', SW_HIDE, ewWaitUntilTerminated, resultcode);
result := resultcode;
end;
//// Stops service and wait 2000ms before removing file to be sure it's not in use anymore
function UnloadService(srv: String): Integer;
var resultcode: Integer;
begin
Exec(ExpandConstant('{sys}\sc.exe'), 'stop ' + srv, '', SW_HIDE, ewWaitUntilTerminated, resultcode);
sleep(2000);
result := resultcode;
end;
procedure Uninstallservice(srv: String);
var resultcode: Integer;
begin
UnloadService(srv);
Exec(ExpandConstant('{sys}\sc.exe'), 'delete ' + srv, '', SW_HIDE, ewWaitUntilTerminated, resultcode);
end;
//// Explode a string into an array using passed delimeter
function Explode(Text: String; Separator: String): TArrayOfString;
var
i: integer;
res: TArrayOfString;
begin
i := 0;
repeat
SetArrayLength(res, i+1);
if Pos(Separator,Text) > 0 then begin
res[i] := Copy(Text, 1, Pos(Separator, Text)-1);
Text := Copy(Text, Pos(Separator,Text) + Length(Separator), Length(Text));
i := i + 1;
end else
begin
res[i] := Text;
Text := '';
end;
until Length(Text)=0;
result := res;
end;
//// Implode an array into a string using a passed delimiter
function Implode(Arr: TArrayOfString; Separator: String): String;
var
i: integer;
res: String;
begin
i := 0;
res := '';
repeat
res := res + Arr[i] + Separator;
i := i + 1;
until (i >= GetArrayLength(Arr));
result := res;
end;
//// Returns commmand line arguments, usage: GetCommandLineParam('--test')
////("--test=value" will return "value", "-t value" will return "value", "-t" will return "yes"
function GetCommandLineParam(Param: string): String;
var
CmdlineParamCount: Integer;
begin
CmdlineParamCount := 0;
while (CmdlineParamCount <= ParamCount) do
begin
if ((Param = Copy(ParamStr(CmdlineParamCount), 0, (Pos('=', ParamStr(CmdlineParamCount))) - 1)) or (Param = ParamStr(CmdlineParamCount))) then
begin
if (Pos('=',ParamStr(CmdlineParamCount)) > 0) then
begin
result := Copy(ParamStr(CmdlineParamCount), (Pos('=', ParamStr(CmdlineParamCount)) + 1), Length(ParamStr(CmdlineParamCount)));
end
else if ((Copy(ParamStr(CmdlineParamCount + 1), 0, 1) <> '-') and (Copy(ParamStr(CmdlineParamCount + 1), 0, 1) <> '/') and (Length(ParamStr(CmdlineParamCount + 1)) > 0)) then
//end else if ((Pos('-', ParamStr(CmdlineParamCount + 1)) <> 0) and (Length(ParamStr(CmdlineParamCount + 1)) > 0) and (Pos('/', ParamStr(CmdlineParamCount + 1)) <> 0)) then
begin
result := ParamStr(CmdlineParamCount + 1);
end else
begin
result := 'yes';
end;
end;
// and
//MsgBox(ParamStr(CmdlineParamCount), MbInformation, MB_OK);
CmdlineParamCount := CmdlineParamCount + 1;
end;
end;
// Determine if an earlier version of this program is already installed
function IsUpdateInstall(): Boolean;
begin
Result := RegKeyExists(HKEY_LOCAL_MACHINE, 'Software\Microsoft\Windows\CurrentVersion\Uninstall\{#AppGUID}_is1') or RegKeyExists(HKEY_LOCAL_MACHINE, 'Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{#AppGUID}_is1');
end;
// Base64 encode and decode functions found at http://www.vincenzo.net/isxkb/index.php?title=Encode/Decode_Base64
const Codes64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
function Encode64(S: AnsiString): AnsiString;
var
i: Integer;
a: Integer;
x: Integer;
b: Integer;
begin
Result := '';
a := 0;
b := 0;
for i := 1 to Length(s) do
begin
x := Ord(s[i]);
b := b * 256 + x;
a := a + 8;
while (a >= 6) do
begin
a := a - 6;
x := b div (1 shl a);
b := b mod (1 shl a);
Result := Result + copy(Codes64,x + 1,1);
end;
end;
if a > 0 then
begin
x := b shl (6 - a);
Result := Result + copy(Codes64,x + 1,1);
end;
a := Length(Result) mod 4;
if a = 2 then
Result := Result + '=='
else if a = 3 then
Result := Result + '=';
end;
function Decode64(S: AnsiString): AnsiString;
var
i: Integer;
a: Integer;
x: Integer;
b: Integer;
begin
Result := '';
a := 0;
b := 0;
for i := 1 to Length(s) do
begin
x := Pos(s[i], codes64) - 1;
if x >= 0 then
begin
b := b * 64 + x;
a := a + 6;
if a >= 8 then
begin
a := a - 8;
x := b shr a;
b := b mod (1 shl a);
x := x mod 256;
Result := Result + chr(x);
end;
end
else
Exit; // finish at unknown
end;
end;
function FileReplaceString(const FileName, SearchString, ReplaceString: string):boolean;
var
MyFile : TStrings;
MyText : string;
begin
MyFile := TStringList.Create;
try
result := true;
try
MyFile.LoadFromFile(FileName);
MyText := MyFile.Text;
if StringChangeEx(MyText, SearchString, ReplaceString, True) > 0 then //Only save if text has been changed.
begin;
MyFile.Text := MyText;
MyFile.SaveToFile(FileName);
end;
except
result := false;
end;
finally
MyFile.Free;
end;
end;