-
Notifications
You must be signed in to change notification settings - Fork 1
/
nodered.iss
2962 lines (2323 loc) · 84.8 KB
/
nodered.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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
; *****
; * Windows Installer for Node-RED
; * Definition file for the Inno Setup compiler.
; * Copyright 2023 Ralph Wetzel
; * License MIT
; * https://www.github.com/ralphwetzel/node-red-windows-installer
; *
; *****
; * PreProcessor setup:
; * We configure all constants via an INI file.
; * That's easier for maintenence rather than searching for things in the source code
; *
#define INIFile RemoveBackslash(SourcePath) + "\setup.ini"
#define VersionInfoURL ReadIni(INIFile, "installer", "url", "https://nodered.org")
; Node.js Default Version - that we propose to install if none is present
#define NodeVersionRecommended ReadIni(INIFile, "node", "recommended")
; comma-separated list of major versions numbers we offer for download
#define NodeVersions ReadIni(INIFILE, "node", "versions", NodeVersionRecommended)
; URL to download node.js license from
#define NodeLicenseURL ReadIni(INIFILE, "node", "license")
#define NodeLicenseTmpFileName "node.license"
; Root URL to download node.js files from
#define NodeDownloadURL ReadIni(INIFILE, "node", "download", 'https://nodejs.org/dist')
; URL to download Node-RED license from
#define REDLicenseURL ReadIni(INIFILE, "red", "license")
#define REDLicenseTmpFileName "red.license"
; By default, we offer (for Node-RED) to install the dist-tag versions as known to npm.
; Additional versions may be defined here; duplicates don't matter!
#define REDAddVersions ReadIni(INIFile, "red", "versions", "")
; If npm is not installed, we cannot get the dist-tag versions.
; In that case, we try to get at least the 'latest' version from
; https://github.com/node-red/node-red/releases/latest
#define REDLatestTmpFileName "red.releases"
; This is the lowest version number we offer for installation
#define REDMinVersion ReadIni(INIFile, "red", "min", "1.0")
; Count of parallel installations we provision for to manage
; We need this explicitely as there's no way to add dynamically to the [Run] section
#define REDProvisionCount ReadIni(INIFile, "red", "provision", "5")
; The root key for bookkeeping of the Node-RED installations we know of on this system
#define REDInstallationsRegRoot 'SOFTWARE\Node-RED\installations'
; py shall become something like '3.7.6'
#define py ReadIni(INIFile, "python", "version")
; for pth we extract the first two digits of py
#define pth Copy(StringChange(py, '.', ''), 1, 2)
; md5 sum for the potential python installer files
#define PyMD5x86 ReadIni(INIFile, "python", "win32")
#define PyMD5x64 ReadIni(INIFile, "python", "amd64")
; the download link of the VS Studio Build Tools
; check as well: https://visualstudio.microsoft.com/downloads/
#define VSBuildToolsURL ReadIni(INIFile, "vs", "download", 'https://aka.ms/vs/17/release/vs_BuildTools.exe')
; 15 = 2015
#define VSBuildToolsMinVersion ReadIni(INIFile, "vs", "min", '15')
; URL to download vswhere from
#define VSWhereURL ReadIni(INIFILE, "vs", "where")
#define MyAppName "Node-RED"
#define MyAppVersion "> 3.0"
#define MyAppPublisher "The Node-RED community"
#define MyAppURL "https://nodered.org"
; #define MyAppExeName "MyProg.exe"
[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={{70D435D8-542E-4087-8E1C-D313404C7E9D}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
AppVerName={#MyAppName}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={autopf}\{#MyAppName}
DefaultGroupName={#MyAppName}
DisableProgramGroupPage=yes
DisableDirPage=yes
DisableWelcomePage=no
OutputBaseFilename="Node-RED Installer"
Compression=lzma
SolidCompression=yes
SetupLogging=yes
PrivilegesRequired=admin
VersionInfoCopyright={#ReadIni(INIFile, "installer", "copyright", "")}
VersionInfoDescription={#ReadIni(INIFile, "installer", "description", "")}
VersionInfoVersion={#ReadIni(INIFile, "installer", "version", "")}
WizardStyle=modern
WizardImageAlphaFormat=defined
; WizardImageBackColor=clWhite
WizardImageStretch=True
WizardImageFile="graphics\sidebar\Node RED Side Graphic - BMP.bmp"
LicenseFile="LICENSE"
SetupIconFile={#SourcePath}\icons\node-red-icons.ico
; PrivilegesRequiredOverridesAllowed=dialog
; Installer Code Signing Data
; To create a test certificate: https://stackoverflow.com/questions/84847/how-do-i-create-a-self-signed-certificate-for-code-signing-on-windows
; To create a Secure String: $xxx = ConvertTo-SecureString plain-text-string -asPlainText -force
; to convert to Base64: certutil -encode .\ssCertInfo.pfx .\ssCertInfo.base64.txt
; Action: https://github.com/dlemstra/code-sign-action
[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"
[Tasks]
; Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
; Name: "quicklaunchicon"; Description: "{cm:CreateQuickLaunchIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked; OnlyBelowVersion: 0,6.1
[Files]
; NOTE: Don't use "Flags: ignoreversion" on any shared system files
Source: "graphics\nodejs.bmp"; DestDir: "{tmp}"; DestName: "nodejs.bmp"; Flags: dontcopy
Source: "graphics\nrhex24.bmp"; DestDir: "{tmp}"; DestName: "node-red.bmp"; Flags: dontcopy
Source: "graphics\node-red-icon-small.bmp"; DestDir: "{tmp}"; DestName: "node-red-small.bmp"; Flags: dontcopy
; Source: "tools\vswhere.exe"; DestDir: "{tmp}"; DestName: "vswhere.exe"
Source: "bat\setup_loop.bat"; DestDir: "{tmp}"
Source: "icons\node-red-icons.ico"; DestDir: "{app}"; DestName: "red.ico"
[Icons]
; Name: "{group}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"
; Name: "{group}\{cm:ProgramOnTheWeb,{#MyAppName}}"; Filename: "{#MyAppURL}"
; Name: "{group}\{cm:UninstallProgram,{#MyAppName}}"; Filename: "{uninstallexe}"
; Name: "{commondesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon
; Name: "{userappdata}\Microsoft\Internet Explorer\Quick Launch\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: quicklaunchicon
[Messages]
english.WelcomeLabel1=Welcome to the%n[name] Setup Wizard
english.WelcomeLabel2=This will install Node-RED on your computer.%n%nInitially we check the version of Node.js installed is %1 or greater. We will try to install node %2 if none is found. Optionally you can choose to install node %3.%n%nIf necessary we will then remove the old core of Node-RED, before then installing the latest version. You can also optionally specify the version required.%n%nWe will finally try to run 'npm rebuild' to refresh any extra nodes you have installed that may have a native binary component. While this normally works ok, you need to check that it succeeds for your combination of installed nodes.%n%nIt is recommended that you close all other applications before continuing.
WizardReady=Final verification
ReadyLabel1=We just ran a final verification of your installation setup.
FinishedHeadingLabel=Completing the%n[name] Setup Wizard
TranslatorNote={#ReadIni(INIFile, "installer", "description", "")}%nVersion {#ReadIni(INIFile, "installer", "version", "")}%nCopyright © {#ReadIni(INIFile, "installer", "copyright", "")}%nSide graphic by Marcus J. Davies%n{#VersionInfoURL}
AboutSetupMenuItem=&About...
AboutSetupTitle=About {#ReadIni(INIFile, "installer", "description", "")}
[CustomMessages]
english.MSG_FAILED_FINISHED1=Setup failed to install Node-RED on your computer:
english.MSG_FAILED_FINISHED2=Sorry for this inconvenience!
[Run]
; main.error is the global Error flag
; Each step checks if this is set, and if (it is) returns False@Check!
; Check if Node.js should be uninstalled.
; Run the uninstall; GUID queried from Registry.
; Verify that no Node.js is known.
Filename: "msiexec"; \
Parameters: "/norestart /quiet /uninstall {code:GetInstalledNodeGUID}"; \
Flags: runascurrentuser; \
StatusMsg: "Uninstalling Node.js v{code:GetNodeVersionMain|current}..."; \
Check: RunCheck('rcsNodeUninstall', ''); \
BeforeInstall: SetupRunConfig; \
AfterInstall: Confirm('csNoNode', '');
; The next two run - in general - the same command.
; #1 Installs in silent mode
; #2 Shows the Node installer & hides our installer
; Only one of these will be executed - as switched by the Check function.
; We do not install the components addressed by flags 'NodeEtwSupport' & 'NodePerfCtrSupport'
; Check that Node.js should be installed
; Run the installer
; Verify that Node.js is ready on the system.
Filename: "msiexec"; \
Parameters: "/i {tmp}\node.msi TARGETDIR=""C:\Program Files\nodejs\"" ADDLOCAL=""DocumentationShortcuts,EnvironmentPathNode,EnvironmentPathNpmModules,npm,NodeRuntime,EnvironmentPath"" /qn"; \
Flags: runascurrentuser; \
StatusMsg: "Installing Node.js v{code:GetNodeVersionMain|selected}..."; \
Check: RunCheck('rcsNodeInstall', 'silent'); \
BeforeInstall: SetupRunConfig; \
AfterInstall: Confirm('csNode', ExpandConstant('{code:GetNodeVersionMain|selected}'));
Filename: "msiexec"; \
Parameters: "/i {tmp}\node.msi TARGETDIR=""C:\Program Files\nodejs\"" ADDLOCAL=""DocumentationShortcuts,EnvironmentPathNode,EnvironmentPathNpmModules,npm,NodeRuntime,EnvironmentPath"" "; \
Flags: runascurrentuser hidewizard; \
StatusMsg: "Installing Node.js v{code:GetNodeVersionMain|selected}..."; \
Check: RunCheck('rcsNodeInstall', 'show'); \
BeforeInstall: SetupRunConfig; \
AfterInstall: Confirm('csNode', ExpandConstant('{code:GetNodeVersionMain|selected}'));
Filename: "{tmp}\python_installer.exe"; \
Parameters: "/quiet InstallAllUsers=1 PrependPath=1 Include_test=0 Include_launcher=0"; \
Flags: runascurrentuser; \
StatusMsg: "Installing Python..."; \
Check: RunCheck('rcsPython', 'no'); \
BeforeInstall: SetupRunConfig; \
AfterInstall: Confirm('csPython', '');
Filename: "{tmp}\VSBT_installer.exe"; \
Parameters: "--norestart --quiet --includeRecommended --add Microsoft.VisualStudio.Worlkload.VCTools"; \
Flags: runascurrentuser; \
StatusMsg: "Installing VisualStudio BuildTools..."; \
Check: RunCheck('rcsVSBuildTools', ''); \
BeforeInstall: SetupRunConfig;
; AfterInstall: Confirm('csVSBuildTools', '');
; This doesn't work when running the VS installer w/ --quiet
; Parameters: """WINDOWTITLE eq VISUAL STUDIO Installer"" setup.exe"; \
; As 'setup.exe' is quite ambigous, we've checked in PrepareInstallation that there
; wasn't another process with this IMAGENAME running!
Filename: "{tmp}\setup_loop.bat"; \
Parameters: """IMAGENAME eq setup.exe"" setup.exe"; \
Flags: runasoriginaluser shellexec waituntilterminated runhidden; \
StatusMsg: "Waiting for Visual Studio Installer to finish its job..."; \
Check: RunCheck('rcsVSBuildTools', ''); \
BeforeInstall: SetupRunConfig; \
AfterInstall: Confirm('csVSBuildTools', '');
; There's a breaking change introduced - intentionally - in NPM9 (Node.js v18+)
; that dis-allows non-standard config settings
; Thus the following doesn't work (anymore).
; Not sure about the consequences...
; Reference: https://github.com/npm/cli/issues/5852
; Filename: "npm"; \
; Parameters: "config set python ""{code:GetPythonPath}"""; \
; WorkingDir: "{code:GetNodeDataReg|path}"; \
; Flags: runasoriginaluser shellexec waituntilterminated runhidden; \
; StatusMsg: "Configuring Python path for Node.js..."; \
; Check: RunCheck('rcsPythonConfig', ''); \
; BeforeInstall: SetupRunConfig; \
; AfterInstall: Confirm('csPythonConfig', '');
#define i
#sub RemoveRED
Filename: "npm"; \
Parameters: "uninstall {code:GetREDActionGlobal|{#i}} node-red"; \
WorkingDir: "{code:GetREDActionPath|{#i}}"; \
Flags: runascurrentuser shellexec waituntilterminated runhidden; \
StatusMsg: "Removing {code:GetREDCurrentMsg|{#i}}..."; \
Check: RunCheck('rcsREDRemove', '{#i}'); \
BeforeInstall: SetupRunConfig; \
AfterInstall: REDRemove('{#i}');
#endsub
#sub InstallRED
Filename: "npm"; \
Parameters: "install {code:GetREDActionGlobal|{#i}} node-red@{code:GetREDActionAction|{#i}}"; \
WorkingDir: "{code:GetREDActionPath|{#i}}"; \
Flags: runascurrentuser shellexec waituntilterminated runhidden; \
StatusMsg: "Installing {code:GetREDActionMsg|{#i}}..."; \
Check: RunCheck('rcsREDInstall', '{#i}'); \
BeforeInstall: REDPrepare('{#i}'); \
AfterInstall: REDFinalize('{#i}');
#endsub
#sub NPMRebuild
Filename: "npm"; \
Parameters: "rebuild"; \
WorkingDir: "{code:GetREDActionPath|{#i}}"; \
Flags: runascurrentuser shellexec waituntilterminated runhidden; \
StatusMsg: "Rebuilding packages for {code:GetREDActionMsg|{#i}}..."; \
Check: RunCheck('rcsREDInstall', '{#i}');
#endsub
#for {i = 0; i < Int(REDProvisionCount, 5); i++} RemoveRED
#for {i = 0; i < Int(REDProvisionCount, 5); i++} InstallRED
#for {i = 0; i < Int(REDProvisionCount, 5); i++} NPMRebuild
#undef i
[Code]
// All data managed by this installer is pushed into one huge record called 'main'.
// 'main' is of type rInstallerData.
// Dedicated records in 'main' carry information regarding Node.js, RED, Python, ...
type
rNodeVersion = record
key: string;
sha: string;
latest: string;
msi: string;
default: boolean;
file: string;
end;
// TNodeVersionList = array of rNodeVersion;
rREDVersion = record
version: string;
tag: string;
end;
TREDVersionArray = array of rREDVersion;
rNodeData = record
majors: array of integer; // Supported major versions as read from the INI file
versions: array of rNodeVersion;
default: integer;
selected: string;
run_silent: boolean;
install_tools: boolean;
current: string;
options: TStringList;
end;
rREDCalcData = record
path: string; // if defined, ensure empty directory & create package.json
port: integer;
end;
rREDRegData = record
name: string;
path: string;
version: string;
icon: string;
port: integer;
autostart: string;
end;
sREDInstallationKind = (rikGlobal, rikPath, rikNew, rikVoid);
rREDInstallation = record
key: string;
id: TObject;
kind: sREDInstallationKind;
name: string;
// _line: integer;
path: string;
version: string;
port: integer;
action: string;
autostart: boolean;
icon: boolean;
// final_path: string;
calc: rREDCalcData;
// add additional properties here!
registry: rREDRegData;
end;
sREDListItemKind = (rlikNone, rlikAction, rlikPath, rlikGlobal, rlikPort, rlikLabel, rlikIcon, rlikAutostart);
rREDListItem = record
kind: sREDListItemKind;
action: string;
link: TObject;
end;
rRedData = record
versions: array of rREDVersion;
selected: string;
current: string;
installs: array of rREDInstallation;
items: array of rREDListItem;
npm: boolean;
error: boolean;
run: array of integer; // index sequence of 'installs' to be installed. This eliminates the installs of 'rikVoid'. Populated @ UpdateReadyMemo.
end;
rPageID = record
node_license: TOutputMsgMemoWizardPage;
node_version: TInputOptionWizardPage;
red_license: TOutputMsgMemoWizardPage;
red_version: TInputOptionWizardPage;
red_action: TInputOptionWizardPage;
download: TDownloadWizardPage;
end;
rInstallationError = record
status: boolean;
msg: string;
end;
rPythonData = record
version: string; // proposed version (via .ini)
npm: boolean; // is npm aware of a python version?
installed: string; // installed version?
path: string;
end;
rVSData = record
version: string;
end;
rInstallerData = record
node: rNodeData;
red: rRedData;
// As described in the documenttion, HKLM is going be set to HKEY_LOCAL_MACHINE_64 when running on 64bit systems
// *AND* "the system's processor architecture is included in the value of the ArchitecturesInstallIn64BitMode [Setup] section directive"
// ArchitecturesInstallIn64BitMode [Setup] section yet is blank by default.
// => HKLM - by default - always == HKEY_LOCAL_MACHINE
// => set is as required: HKEY_LOCAL_MACHINE or HKEY_LOCAL_MACHINE_64
HKLM: Integer;
bit: String;
pages: rPageID;
error: rInstallationError; // Global Installation Error Status
python: rPythonData;
vs: rVSData;
end;
sImageType = (imgNODE, imgRED, imgNONE);
var
// Two additional controls
REDLicenseAcceptedRadio: TRadioButton;
REDLicenseNotAcceptedRadio: TRadioButton;
// As described in the documenttion, HKLM is going be set to HKEY_LOCAL_MACHINE_64 when running on 64bit systems
// *AND* "the system's processor architecture is included in the value of the ArchitecturesInstallIn64BitMode [Setup] section directive"
// ArchitecturesInstallIn64BitMode [Setup] section yet is blank by default.
// => HKLM - by default - always == HKEY_LOCAL_MACHINE
// => set it as required: HKEY_LOCAL_MACHINE or HKEY_LOCAL_MACHINE_64
// The list of all node versions offered to install
// nodeVersionSelectionOptions: TStringList;
// the index the user choose to install
// nodeVersionSelectionOptionsSelected: Integer;
// cbHideNodeInstaller: TNewCheckBox;
// cbInstallWindowsTools: TNewCheckBox;
// The Node-RED version the user selected for installation
// redVersionSelected: String;
// This record holds all relevant data
main: rInstallerData;
// testPage: TInputOptionWizardPage;
// testPage2: TInputOptionWizardPage;
// *****
// * Forward definition of some functions "exported" by other files
// nodedetector.iss
function detect_red_installations(var page: TOutputMarqueeProgressWizardPage): integer; forward;
function red_list(working_dir: string): string; forward;
// redactionpage.iss
function MakeRedActionPage(page: TInputOptionWizardPage): Boolean; forward;
// *
// *****
// *****
// * Support functions
procedure debug(message: string);
begin
Log('[NRI] ' + message);
end;
{procedure debugInt(int: integer);
begin
debug(IntToStr(int));
end;}
// pastebin.com/STcQLfKR
Function SplitString(const Value: string; Delimiter: string; Strings: TStrings): Boolean;
var
S: string;
begin
S := Value;
if StringChangeEx(S, Delimiter, #13#10, True) > 0 then begin
Strings.text := S;
Result := True;
Exit;
end;
Result := False;
end;
function OnDownloadProgress(const Url, FileName: String; const Progress, ProgressMax: Int64): Boolean;
begin
if Progress = ProgressMax then begin
Log(Format('Successfully downloaded file to {tmp}: %s', [FileName]));
end;
Result := True;
end;
function RightStr(S: string; C: Char; I: Integer): string;
begin
Result := StringOfChar(C, I - Length(S)) + S;
end;
function SortAsInt(List: TStringList; Index1, Index2: Integer): Integer;
var
i1, i2: Integer;
begin
i1 := StrToInt(List[Index1]);
i2 := StrToInt(List[Index2]);
if i1 < i2 then
Result := -1
else if i1 > i2 then Result := 1
else
Result := 0;
end;
// TStringList in Inno Setup flavour unfortunately does not support CustomSort
// Thus we have to detour via an Integer array sort by QuickSort
procedure QuickSort(var A: array of Integer; iLo, iHi: Integer) ;
var
Lo, Hi, Pivot, T: Integer;
begin
Lo := iLo;
Hi := iHi;
Pivot := A[(Lo + Hi) div 2];
repeat
while A[Lo] < Pivot do Inc(Lo) ;
while A[Hi] > Pivot do Dec(Hi) ;
if Lo <= Hi then
begin
T := A[Lo];
A[Lo] := A[Hi];
A[Hi] := T;
Inc(Lo) ;
Dec(Hi) ;
end;
until Lo > Hi;
if Hi > iLo then QuickSort(A, iLo, Hi) ;
if Lo < iHi then QuickSort(A, Lo, iHi) ;
end;
function Max(A, B: Integer): Integer;
begin
if A > B then
Result := A
else
Result := B;
end;
function RGB2TColor(const R, G, B: Byte): Integer;
begin
Result := (Integer(R) or (Integer(G) shl 8) or (Integer(B) shl 16));
end;
procedure TColor2RGB(const Color: TColor; var R, G, B: Byte);
begin
// convert hexa-decimal values to RGB
R := Color and $FF;
G := (Color shr 8) and $FF;
B := (Color shr 16) and $FF;
end;
function CompareVersions( checkVersion, compareVersion: string): integer;
var
checkV, compV: TStringList;
i, v1, v2, l1, l2: integer;
msg: string;
begin
checkV := TStringList.Create;
compV := TStringList.Create;
SplitString(checkVersion + '.', '.', checkV);
SplitString(compareVersion + '.', '.', compV);
l1 := checkV.Count;
l2 := compV.Count;
for i:= 0 to Max(l1, l2) - 1 do begin
if l1 > i then begin
v1 := StrToIntDef(checkV[i], -1);
end else begin
v1 := 0;
end;
if l2 > i then begin
v2 := StrToIntDef(compV[i], -1);
end else begin
v2 := 0;
end;
// Only if both versions have a non-number part
// compare those as strings
// If only one has a non-number (e.g. '-beta.2') ammendment,
// this version will be 'smaller' than the one without
if ((v1 < 0) and (v2 < 0)) then begin
Result := CompareStr(checkV[i], compV[i]);
break;
end;
if v1 > v2 then begin
Result := 1;
break;
end else if v1 < v2 then begin
Result := -1;
break;
end;
Result := 0;
end;
msg := '??';
case Result of
-1: msg := '<';
0: msg := '=';
1: msg := '>';
end;
// debug(checkVersion + ' ' + msg + ' ' + compareVersion);
end;
function GetVersion(version: String; index: Integer): Integer;
var
vv: TStringList;
begin
Result := -1;
vv := TStringList.Create;
if SplitString(version, '.', vv) then begin
if vv.Count > index then begin
Result := StrToIntDef(vv[index], 0);
end;
end;
end;
function GetVersionMajor(version: String): Integer;
begin
Result := GetVersion(version, 0);
end;
function GetVersionMinor(version: String): Integer;
begin
Result := GetVersion(version, 1);
end;
function GetVersionPatch(version: String): Integer;
begin
Result := GetVersion(version, 2);
end;
procedure set_image(img: sImageType);
var
image: string;
begin
case img of
imgNone: begin
WizardForm.WizardSmallBitmapImage.Visible := False;
Exit;
end;
imgNODE: image := 'nodejs.bmp';
imgRED: image := 'node-red.bmp';
else
Exit;
end;
if not FileExists(ExpandConstant('{tmp}\' + image)) then ExtractTemporaryFile(image);
WizardForm.WizardSmallBitmapImage.Bitmap.LoadFromFile(ExpandConstant('{tmp}\' + image));
WizardForm.WizardSmallBitmapImage.Visible := True;
end;
function BoolToStr(bool: boolean): string;
begin
if bool then
Result:='true'
else
Result :='false';
end;
function StrToBool(str: string): boolean;
begin
Result := str = 'true'
Result := (str = 'yes') or Result;
end;
function isEmptyDir(dirName: String): Boolean;
var
FindRec: TFindRec;
FileCount: Integer;
begin
Result := False;
if FindFirst(dirName+'\*', FindRec) then begin
try
repeat
if (FindRec.Name <> '.') and (FindRec.Name <> '..') then begin
FileCount := 1;
break;
end;
until not FindNext(FindRec);
finally
FindClose(FindRec);
if FileCount = 0 then Result := True;
end;
end;
end;
// *****
// * Additional page to acknowledge Node-RED License
// * https://stackoverflow.com/questions/34592002/how-to-create-two-licensefile-pages-in-inno-setup
procedure CheckREDLicenseAccepted(Sender: TObject);
begin
// Update Next button when user (un)accepts the license
WizardForm.NextButton.Enabled := REDLicenseAcceptedRadio.Checked;
end;
function CloneLicenseRadioButton(Source: TRadioButton): TRadioButton;
begin
Result := TRadioButton.Create(WizardForm);
Result.Parent := main.pages.red_license.Surface;
Result.Caption := Source.Caption;
Result.Left := Source.Left;
Result.Top := Source.Top;
Result.Width := Source.Width;
Result.Height := Source.Height;
Result.OnClick := @CheckREDLicenseAccepted;
end;
function CreateREDLicensePage(after: Integer): TOutputMsgMemoWizardPage;
begin
Result :=
CreateOutputMsgMemoPage(
after, 'Node-RED ' + SetupMessage(msgWizardLicense),
SetupMessage(msgLicenseLabel),
SetupMessage(msgLicenseLabel3), '');
// Shrink memo box to make space for radio buttons
Result.RichEditViewer.Height := WizardForm.LicenseMemo.Height;
// Clone accept/do not accept radio buttons for the second license
REDLicenseAcceptedRadio :=
CloneLicenseRadioButton(WizardForm.LicenseAcceptedRadio);
REDLicenseNotAcceptedRadio :=
CloneLicenseRadioButton(WizardForm.LicenseNotAcceptedRadio);
// Initially not accepted
REDLicenseNotAcceptedRadio.Checked := True;
end;
// *
// *****
// *****
// ** RunCMD
// ** Execute a command with Windows cmd.exe
function RunCMD(Command, WorkingDir: string; var ResultArray: TArrayOfString): Boolean;
var
bat, file, res: string;
rc, i: integer;
p1, p2: string;
msg: string;
begin
msg := '$> ' + Command;
if Length(WorkingDir) > 0 then msg := msg + ' @ ' + WorkingDir;
debug(msg);
Result := False;
// %PATH% is incomplete in cmd when we just use Exec,
// thus calling 'node' or 'npm' tells us "not found".
// => Read the two registry keys thet both hold the PATH data
// => to combine them and set PATH explicitely - for this cmd session!
// (based on an idea I got from https://stackoverflow.com/a/32420542)
p1:='';
RegQueryStringValue(main.HKLM, 'System\CurrentControlSet\Control\Session Manager\Environment', 'Path', p1);
p2:='';
RegQueryStringValue(HKCU, 'Environment', 'Path', p2);
res:= ExpandConstant('{tmp}\cmd_result.txt');
bat := '';
if (Length(p1) + Length(p2)) > 0 then
bat := 'PATH=' + p1 + ';' + p2 + ';' + #13#10;
bat := bat + command + ' > "' + res + '" 2>&1';
file := ExpandConstant('{tmp}\run_cmd.bat');
if SaveStringToFile(file, bat, False) then begin
if Exec(file, '', WorkingDir, SW_HIDE, ewWaitUntilTerminated, rc) then begin
if LoadStringsFromFile(res, ResultArray) then begin
for i:=0 to GetArrayLength(ResultArray) -1 do begin
debug('>> ' + ResultArray[i]);
end;
Result:=True;
end;
end else begin
debug('>> ' + SysErrorMessage(rc));
end;
end;
end;
// *****
// ** NodeVersionSelectionPage
// **
var
_nodeVersion_cbHideInstaller: TNewCheckBox;
_nodeVersion_cbInstallWindowsTools: TNewCheckBox;
procedure _nodeVersion_OnClickInstallBackground(Sender: TObject);
var
status: boolean;
begin
status := _nodeVersion_cbHideInstaller.Checked;
_nodeVersion_cbInstallWindowsTools.Visible := status;
main.node.run_silent := status
end;
procedure _nodeVersion_OnClickNodeVersion(Sender: TObject);
var
index: Integer;
nv: String;
begin
index := main.pages.node_version.SelectedValueIndex;
if index < main.node.options.Count then begin
nv := main.node.options[index];
main.node.selected := nv;
_nodeVersion_cbHideInstaller.Visible := (Length(nv) > 0);
_nodeVersion_cbInstallWindowsTools.Visible := ((Length(nv) > 0) and _nodeVersion_cbHideInstaller.Checked);
end;
end;
function PrepareNodeVersionSelectionPage(): Boolean;
var
sFlag: String;
i, ii: Integer;
_nvp: TInputOptionWizardPage;
_possible: array of rNodeVersion; // the Node.js versions we know of
_options: TStringList; // the Node.js versions we offer for download;
// this may include '' for "Keep the current..."
_current: string;
begin
Result := False;
// debug('PrepareNodeVersionSelectionPage');
// Page to select a Node.js version
_nvp := main.pages.node_version;
if _nvp = nil then Exit;
_nvp.SubCaptionLabel.Font.Style := [fsBold];
_nvp.CheckListBox.OnClickCheck := @_nodeVersion_OnClickNodeVersion;
// Additional checkboxes:
_nodeVersion_cbHideInstaller := TNewCheckBox.Create(_nvp);
with _nodeVersion_cbHideInstaller do begin
Parent := _nvp.Surface;
Top := _nvp.CheckListBox.Top + _nvp.CheckListBox.Height + ScaleY(8);
Height := ScaleY(_nodeVersion_cbHideInstaller.Height);
Left := _nvp.CheckListBox.Left;
Width := _nvp.CheckListBox.Width;
Caption := 'Run Node.js installer in the background.';
Checked := True;
OnClick := @_nodeVersion_OnClickInstallBackground;
end;
main.node.run_silent := True;
_nodeVersion_cbInstallWindowsTools := TNewCheckBox.Create(_nvp);
with _nodeVersion_cbInstallWindowsTools do begin
Parent := _nvp.Surface;
Top := _nodeVersion_cbHideInstaller.Top + _nodeVersion_cbHideInstaller.Height + ScaleY(8);
Height := ScaleY(_nodeVersion_cbInstallWindowsTools.Height);
Left := _nodeVersion_cbHideInstaller.Left;
Width := _nodeVersion_cbHideInstaller.Width;
Caption := 'Install Windows Tools for Native Node.js Modules - if necessary!';
Checked := True;
Enabled := True;
end;
main.node.install_tools := True;
// Read the current node.js version from the registry
_current := '';
if RegKeyExists(main.HKLM, 'SOFTWARE\Node.js') then begin
if RegQueryStringValue(main.HKLM, 'SOFTWARE\Node.js', 'Version', _current) = True then begin
_nvp.SubCaptionLabel.Caption := 'Currently installed: Node.js ' + _current;
debug('According Registry, Node.js v' + _current + ' is installed.');
end;
end;
main.node.current := _current;
// This list holds the versions numbers we offer for installation
_options := TStringList.Create;
_possible := main.node.versions;
if _current = '' then begin
_nvp.SubCaptionLabel.Caption := 'Currently there''s no Node.js version installed!';
end else begin
// Check if current version > Min version
if CompareVersions(_current, _possible[0].key) > 0 then begin
_nvp.Add('Keep CURRENT Node.js ' + _current);
_options.Add('');
// Set initial value to "Keep"
_nvp.Values[0] := True;
end;
end;
for i := 0 to GetArrayLength(_possible) - 1 do begin
_options.Add(_possible[i].latest);
ii := CompareVersions(_current, _possible[i].latest);
if ii > 0 then begin
_nvp.Add('Change to v' + _possible[i].key + ' LTS Node.js version >> ' + _possible[i].latest + ' | NOT RECOMMENDED');
continue;
end else if ii = 0 then begin
_nvp.Add('Re-Install v' + _possible[i].key + ' LTS Node.js version: ' + _possible[i].latest);
continue;
end;
sFlag := '';
if GetVersionMajor(_current) < GetVersionMajor(_possible[i].latest) then begin
if GetVersionMajor(_possible[i].latest) = main.node.default then begin
// debugInt(main.node.default);
sFlag := ' | RECOMMENDED ';
end;
end;
_nvp.Add('Update to latest v' + _possible[i].key + ' LTS Node.js version >> ' + _possible[i].latest + sFlag);
if Length(sFlag) > 0 then begin
// if no version installed: Default to recommended version
if _current = '' then
_nvp.Values[_options.Count - 1] := True;
end;
end;
main.node.options := _options;
_nodeVersion_OnClickNodeVersion(nil);
Result := True;
end;
// ** END
// ** NodeVersionSelectionPage
// *****
// *****
// ** Data Preparation Page
// ** (which isn't a true interactive page, but a Download & a Progress page inserted after wpWelcome)
function _redversion_insert_version(version, tag: String; red_versions: TREDVersionArray): TREDVersionArray;
var
buffer: TREDVersionArray;
ii, ibuffer, rvLength, cv: Integer;
begin
// Do not accept versions that are lower than #REDMinVersion
// debug('cv: ' + version + ' / {#REDMinVersion}');
cv := CompareVersions(version, '{#REDMinVersion}');
// debug('cv: ' + version + ' / {#REDMinVersion}' + ' = ' + IntToStr(cv));
if cv < 0 then begin
Result := red_versions;
Exit;
end;