forked from Zeugwerk/Twinpack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTwinpack.iss
268 lines (237 loc) · 8.97 KB
/
Twinpack.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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
; Script generated by the Inno Script Studio Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
; #define MyAppName "Twinpack"
; #define MyAppVersion "0.1.0.0"
; #define MyConfiguration "Debug"
#define MyAppPublisher "Zeugwerk GmbH"
#define MyAppURL "http://www.zeugwerk.at/"
#define MyAppExeName "Twinpack.exe"
#define TcXaeShellExtensionsFolder "C:\Program Files (x86)\Beckhoff\TcXaeShell\Common7\IDE\Extensions\"
[Setup]
; NOTE: The value of AppId uniquely identifies this application.
; Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId={{326905EF-5BAA-50D5-9F26-B205B58C91EF}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
CreateAppDir=no
OutputBaseFilename={#MyAppName} {#MyAppVersion}
Compression=lzma
SolidCompression=yes
VersionInfoCompany=Zeugwerk GmbH
VersionInfoProductName=Zeugwerk Creator
CloseApplications=force
RestartApplications=True
SetupIconFile=Zeugwerk.ico
WizardSmallImageFile=Zeugwerk.bmp
LicenseFile=LICENSE
InfoBeforeFile=DISCLAIMER
[Files]
Source: "TwinpackVsix\bin\{#MyConfiguration}\Package\*"; DestDir: "{#TcXaeShellExtensionsFolder}Zeugwerk\Twinpack"; Flags: ignoreversion recursesubdirs createallsubdirs; Check: InstallVsixInTcXaeShell;
Source: "TwinpackVsix\bin\{#MyConfiguration}\TwinpackVsix.vsix"; DestDir: "{tmp}"; Flags: deleteafterinstall;
Source: "vswhere.exe"; DestDir: "{tmp}"; Flags: deleteafterinstall;
[Dirs]
Name: "C:\Program Files (x86)\Beckhoff\TcXaeShell\Common7\IDE\Extensions\Zeugwerk\Twinpack"
[InstallDelete]
Type: filesandordirs; Name: "{#TcXaeShellExtensionsFolder}Zeugwerk\Twinpack\*"
[Code]
function VsWhereValue(ParameterName: string; OutputData: string): TStringList;
var
Lines: TStringList;
Line: string;
i: integer;
begin
Result := TStringList.Create;
Lines := TStringList.Create;
try
Lines.Text := OutputData;
for i := 0 TO Lines.Count - 1 do
begin
Line := Lines[i];
if Pos(ParameterName + ':', Line) > 0 then
begin
Result.Add(Trim(Copy(Line, Pos(ParameterName + ':', Line) + Length(ParameterName) + 2, MaxInt)));
end;
end;
finally
Lines.Free;
end;
end;
procedure OpenPrivacyPolicy(Sender : TObject);
var
ErrorCode : Integer;
begin
ShellExec('open', 'https://github.com/Zeugwerk/Twinpack/blob/main/PRIVACY_POLICY.md', '', '', SW_SHOWNORMAL, ewNoWait, ErrorCode);
end;
// Exec with output stored in result.
// ResultString will only be altered if True is returned.
function ExecWithResult(Filename, Params, WorkingDir: String; ShowCmd: Integer; Wait: TExecWait; var ResultCode: Integer; var ResultString: String): Boolean;
var
TempFilename: String;
Command: String;
ResultStringAnsi: AnsiString;
begin
TempFilename := ExpandConstant('{tmp}\~execwithresult.txt');
Command := Format('"%s" /S /C ""%s" %s > "%s""', [ExpandConstant('{cmd}'), Filename, Params, TempFilename]);
Result := Exec(ExpandConstant('{cmd}'), Command, WorkingDir, ShowCmd, Wait, ResultCode);
if not Result then
Exit;
LoadStringFromFile(TempFilename, ResultStringAnsi);
ResultString := ResultStringAnsi;
DeleteFile(TempFilename);
// Remove new-line at the end
if (Length(ResultString) >= 2) and (ResultString[Length(ResultString) - 1] = #13) and (ResultString[Length(ResultString)] = #10) then
Delete(ResultString, Length(ResultString) - 1, 2);
end;
var
UserPage : TInputQueryWizardPage;
UserPagePolicyLabel : TLabel;
VisualStudioOptionsPage: TInputOptionWizardPage;
UserPageRegisterButton: TNewButton;
OutputFile: string;
OutputData: AnsiString;
InstallationPaths: TStringList;
DisplayNames: TStringList;
ErrorCode: integer;
i : integer;
VsWhereOutput : string;
function ValidateEmail(strEmail : String) : boolean;
var
strTemp : String;
nSpace : Integer;
nAt : Integer;
nDot : Integer;
begin
strEmail := Trim(strEmail);
nSpace := Pos(' ', strEmail);
nAt := Pos('@', strEmail);
strTemp := Copy(strEmail, nAt + 1, Length(strEmail) - nAt + 1);
nDot := Pos('.', strTemp) + nAt;
Result := ((nSpace = 0) and (1 < nAt) and (nAt + 1 < nDot) and (nDot < Length(strEmail)));
end;
procedure RegisterEnable(Sender: TObject);
begin
UserPageRegisterButton.Enabled := ValidateEmail(UserPage.Edits[0].Text);
end;
function IntToHex(Value: Integer): string;
begin
Result := Format('%.2x', [Value]);
end;
function UrlEncode(data: AnsiString): AnsiString;
var
i : Integer;
begin
Result := '';
for i := 1 to Length(data) do begin
if ((Ord(data[i]) < 65) or (Ord(data[i]) > 90)) and ((Ord(data[i]) < 97) or (Ord(data[i]) > 122)) then begin
Result := Result + '%' + IntToHex(Ord(data[i]));
end else
Result := Result + data[i];
end;
end;
procedure Register(Sender: TObject);
var
WinHttpReq: Variant;
begin
WinHttpReq := CreateOleObject('WinHttp.WinHttpRequest.5.1');
WinHttpReq.Open('GET', 'https://operations.zeugwerk.dev/api.php?method=zkregister&usermail='+UrlEncode(UserPage.Edits[0].Text), False);
WinHttpReq.Send('');
if WinHttpReq.Status <> 200 then
begin
MsgBox('Could not connect to Login server. Please check your internet connection!', mbError, MB_OK);
end
else
begin
if Pos('HTTP/1.1 200', Trim(WinHttpReq.ResponseText)) > 0 then
begin
WizardForm.NextButton.OnClick(nil);
end
else
begin
MsgBox('This email adress is already reserved or used. You might already be registered with this email address.', mbError, MB_OK);
end;
end;
end;
procedure InitializeWizard;
begin
ExtractTemporaryFile('vswhere.exe');
ExecWithResult(ExpandConstant('{tmp}\\vswhere.exe'), '-all -products * -version [15.0,17.0)', '', SW_HIDE, ewWaitUntilTerminated, ErrorCode, VsWhereOutput);
{ Create the pages }
{ UserPage }
UserPage := CreateInputQueryPage(wpWelcome,
'Welcome to the Twinpack Installer', 'Twinpack is a package manage tool to faciliate sharing of TwinCAT libraries within the community.',
'Register a Twinpack account (only needed if you want to publish packages to the Twinpack Server)');
UserPage.Add('Email:', False);
UserPage.Edits[0].OnChange := @RegisterEnable;
UserPageRegisterButton := TNewButton.Create(UserPage);
UserPageRegisterButton.Left := UserPage.Edits[0].Left;
UserPageRegisterButton.Top := UserPage.Edits[0].Top + UserPage.Edits[0].Height + ScaleY(5);
UserPageRegisterButton.Parent := UserPage.Edits[0].Parent;
UserPageRegisterButton.ParentFont := True;
UserPageRegisterButton.Caption := 'Register';
UserPageRegisterButton.OnClick := @Register;
UserPageRegisterButton.Enabled := False;
UserPagePolicyLabel := TLabel.Create(UserPage);
UserPagePolicyLabel.Left := UserPageRegisterButton.Left + UserPageRegisterButton.Width + ScaleX(5);
UserPagePolicyLabel.Top := UserPageRegisterButton.Top + ScaleY(5);
UserPagePolicyLabel.Parent := UserPage.Edits[0].Parent;
UserPagePolicyLabel.Caption := 'Privacy policy';
UserPagePolicyLabel.OnClick := @OpenPrivacyPolicy;
UserPagePolicyLabel.Font.Style := UserPagePolicyLabel.Font.Style + [fsUnderline];
UserPagePolicyLabel.Font.Color := clBlue;
UserPagePolicyLabel.Cursor := crHand;
{ VisualStudioOptionsPage }
VisualStudioOptionsPage := CreateInputOptionPage(UserPage.ID,
'Install options', 'Twinpack is compatible with multiple IDEs',
'Please choose the Visual Studio versions that Twinpack is installed for.',
False, False);
// Add items
VisualStudioOptionsPage.Add('TcXAEShell');
if(DirExists('C:\Program Files (x86)\Beckhoff\TcXaeShell')) then
VisualStudioOptionsPage.CheckListBox.Checked[0] := true
else
VisualStudioOptionsPage.CheckListBox.ItemEnabled[0] := false;
DisplayNames := VsWhereValue('displayName', VsWhereOutput);
InstallationPaths := VsWhereValue('installationPath', VsWhereOutput);
for i:= 0 to DisplayNames.Count-1 do
begin
if(FileExists(InstallationPaths[i] + '\Common7\IDE\VSIXInstaller.exe')) then
VisualStudioOptionsPage.Add(DisplayNames[i]);
end;
end;
const
SHCONTCH_NOPROGRESSBOX = 4;
SHCONTCH_RESPONDYESTOALL = 16;
function InstallVsixInTcXaeShell(): Boolean;
begin
Result := VisualStudioOptionsPage.CheckListBox.Checked[0] = True;
end;
procedure CurStepChanged (CurStep: TSetupStep);
var
WorkingDir: String;
ReturnCode: Integer;
i: Integer;
begin
if (ssInstall = CurStep) then
begin
ExtractTemporaryFile('TwinpackVsix.vsix');
for i := 0 to DisplayNames.Count-1 do
begin
if(VisualStudioOptionsPage.CheckListBox.Checked[i+1]) then
ShellExec('', InstallationPaths[i] + '\Common7\IDE\VSIXInstaller.exe', ExpandConstant('{tmp}\TwinpackVsix.vsix'), '', SW_HIDE, ewWaitUntilTerminated, ReturnCode)
end;
end;
end;
function InstallVsixThroughVsixInstaller(): Boolean;
begin
Result := False;
if(VisualStudioOptionsPage.CheckListBox.Checked[1] = True) then
begin
Result := True;
end
end;