-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathDeploymentEditor.pb
More file actions
3240 lines (2617 loc) · 115 KB
/
DeploymentEditor.pb
File metadata and controls
3240 lines (2617 loc) · 115 KB
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
;------------------------------------------------------------------------------------
;- Deployment Editor
;------------------------------------------------------------------------------------
;-- This tool has been developed by TUGI.CH - www.tugi.ch
;------------------------------------------------------------------------------------
;- License
;------------------------------------------------------------------------------------
;-- See LICENSE.txt
;------------------------------------------------------------------------------------
;- Notes
;------------------------------------------------------------------------------------
;-- See TODO.txt
;------------------------------------------------------------------------------------
;- Compiler Settings
;------------------------------------------------------------------------------------
EnableExplicit
UsePNGImageDecoder()
UseSQLiteDatabase()
UseZipPacker()
;------------------------------------------------------------------------------------
;- Structures
;------------------------------------------------------------------------------------
Structure PSADT_Parameter
; P.ID, C.Command,P.Parameter,P.Description,P.Type,P.Required
Command.s
Parameter.s
Description.s
Type.s
Required.i
EndStructure
Structure PSADT_Parameter_GadgetGroup
ActionID.i
Parameter.s
TitleGadget.i
InputGadget.i
ControlType.s
EndStructure
Structure RecentProject
FileName.s
FolderPath.s
EndStructure
Structure ProjectSetting
Value.s
EndStructure
Structure EditorPlugin
ID.s
Name.s
Version.s
Date.s
Description.s
Author.s
Website.s
Path.s
File.s
Parameter.s
UnloadProject.s
EndStructure
Structure WinGetPackage
PackageIdentifier.s
PackageVersion.s
Scope.s
ReleaseDate.s
File.s
EndStructure
Structure MsiInformation
Productmanufacturer.s
Productname.s
Productcode.s
Productversion.s
EndStructure
;------------------------------------------------------------------------------------
;- Variables, Enumerations and Maps
;------------------------------------------------------------------------------------
Global Event = #Null, Quit = #False
Global MainWindowTitle.s = "Deployment Editor - TUGI.CH"
Global DonationUrl.s = "https://www.paypal.com/donate/?hosted_button_id=PXABL8ESQQ4F8"
Global PluginDirectory.s = GetCurrentDirectory() + "Plugins"
Global SnippetsDirectory.s = GetCurrentDirectory() + "Snippets"
Global ScriptEditorFilePath.s = GetCurrentDirectory() + "Web\MonacoEditor\editor.html"
; Templates
Global Template_PSADT.s = GetCurrentDirectory() + "ThirdParty\PSAppDeployToolkit\"
Global Template_EmptyDatabase.s = GetCurrentDirectory() + "Templates\Invoke-AppDeployToolkit.db"
; PSADT
Global PSADT_Database.s = GetCurrentDirectory() + "Databases\PSADT.sqlite"
Global PSADT_TemplateFile.s = GetCurrentDirectory() + "Templates\Invoke-AppDeployToolkit.ps1"
Global PSADT_OnlineDocumentation.s = "https://psappdeploytoolkit.com/docs"
; Intune
Global IntuneWinAppUtil.s = ""
; Project
Global Project_FolderPath.s = GetCurrentDirectory() + "Test\"
Global Project_DeploymentFile.s = Project_FolderPath + "Invoke-AppDeployToolkit.ps1"
Global Project_Database.s = Project_FolderPath + "Invoke-AppDeployToolkit.db"
Global Project_PreviewMode = #False
; Windows Sandbox
Global PSADT_SandboxTemplate.s = GetCurrentDirectory() + "Templates\Windows Sandbox.wsb"
; Deployment
Global CurrentDeploymentType.s = "Installation"
; Maps
Global NewMap PSADT_Parameters.PSADT_Parameter()
Global NewMap ProjectSettings.ProjectSetting()
; Dim
Global Dim MsiInformation.MsiInformation(1)
; Lists
Global NewList EditorPlugins.EditorPlugin()
Global NewList WinGetPackages.WinGetPackage()
Global NewList RecentProjects.RecentProject()
AddElement(RecentProjects())
RecentProjects()\FileName = "Invoke-AppDeployToolkit.db"
RecentProjects()\FolderPath = Project_FolderPath
; Action
Global SelectedActionID.i
Global UnsavedChange = #False
Global NewList ActionParameterGadgets.PSADT_Parameter_GadgetGroup()
; WinAPI
Global tvi.TV_ITEM
; WinGet Package
Global Download_Url.s = "", Download_OutputFile.s = ""
Global WinGet_RepositoryUrl.s = "https://github.com/microsoft/winget-pkgs/archive/refs/heads/master.zip"
Global WinGet_RepositoryLocalFile.s = GetTemporaryDirectory() + "WinGetRepository.zip"
Global WinGet_ManifestTempFolder.s = GetTemporaryDirectory() + "Deployment Editor"
Global WinGet_Identifier.s = "", WinGet_Version.s = "", WinGet_SilentSwitch.s = ""
; Script Editor
Global ScriptEditorGadget
; Log Reader
Global LogReaderFilePath.s = GetCurrentDirectory() + "Web\LogReader\logreader.html"
;------------------------------------------------------------------------------------
;- Shortcuts
;------------------------------------------------------------------------------------
Enumeration WindowKeyboardShortcuts
; Keyboard
#Keyboard_Shortcut_Save
#Keyboard_Shortcut_Run
#Keyboard_Shortcut_Exit
; WinGet
#WinGetImport_Enter
; Window Exit
#MainWindow_Exit
EndEnumeration
; Readme
Global Readme.s = "Deployment Editor simplifies software packaging with PSAppDeployToolkit (www.psappdeploytoolkit.com)." + #CRLF$ + #CRLF$ +
"By using this application, you accept the attached license terms of the software. See also LICENSE.txt in the installation folder. Each generated project result is under the license of PSAppDeployToolkit." + #CRLF$ + #CRLF$ +
"If you have any questions, please contact us by e-mail: contact@tugi.ch."
;------------------------------------------------------------------------------------
;- Enumerations
;------------------------------------------------------------------------------------
; None
;------------------------------------------------------------------------------------
;- Forms
;------------------------------------------------------------------------------------
XIncludeFile "Forms/MainWindow.pbf"
XIncludeFile "Forms/AboutWindow.pbf"
XIncludeFile "Forms/NewProjectWindow.pbf"
XIncludeFile "Forms/ProjectSettingsWindow.pbf"
XIncludeFile "Forms/PluginWindow.pbf"
XIncludeFile "Forms/WinGetImportWindow.pbf"
XIncludeFile "Forms/ProgressWindow.pbf"
XIncludeFile "Forms/ImportExeWindow.pbf"
XIncludeFile "Forms/ImportMsiWindow.pbf"
XIncludeFile "Forms/ScriptEditorWindow.pbf"
XIncludeFile "Forms/LogReaderWindow.pbf"
;------------------------------------------------------------------------------------
;- Helpers
;------------------------------------------------------------------------------------
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
Macro GetParentDirectory(Path)
GetPathPart(RTrim(Path, "\"))
EndMacro
CompilerElse
Macro GetParentDirectory(Path)
GetPathPart(RTrim(Path, "/"))
EndMacro
CompilerEndIf
Procedure CheckDatabaseUpdate(Database, Query$)
Protected Result.i
Debug "[Debug: Database Update] Update query: " + Query$
Result = DatabaseUpdate(Database, Query$)
If Result = 0
Debug DatabaseError()
Else
Debug "[Debug: Database Update] Database update was successfully."
Debug "[Debug: Database Update] Affected rows: " + AffectedDatabaseRows(Database)
EndIf
ProcedureReturn Result
EndProcedure
;------------------------------------------------------------------------------------
;- Functions
;------------------------------------------------------------------------------------
Procedure DisableMainWindowGadgets(State = #False)
DisableGadget(ListView_Commands, State)
DisableGadget(Combo_DeploymentType, State)
DisableGadget(Tree_Sequence, State)
DisableGadget(Button_SaveAction, State)
DisableGadget(Button_AddCommand, State)
DisableGadget(Button_AddCustomScript, State)
DisableGadget(String_CommandSearch, State)
DisableGadget(Hyperlink_ProjectSettings, State)
DisableGadget(Hyperlink_ProjectSettings, State)
DisableGadget(ButtonImage_Go, State)
DisableGadget(Checkbox_SilentMode, State)
DisableGadget(ButtonImage_StartPowerShell, State)
DisableGadget(ButtonImage_Repair, State)
DisableGadget(ButtonImage_Uninstallation, State)
DisableGadget(ButtonImage_Plugins, State)
DisableGadget(ButtonImage_RefreshProject, State)
DisableGadget(ButtonImage_RunHelp, State)
DisableGadget(ButtonImage_AboutWindow, State)
DisableGadget(Hyperlink_GenerateDeployment, State)
DisableGadget(Button_LoadPreview, State)
EndProcedure
Procedure ShowSoftwareReadMe()
CompilerIf #PB_Compiler_Debugger = 0
MessageRequester("Readme", Readme, #PB_MessageRequester_Info)
CompilerEndIf
EndProcedure
Procedure ShowMainWindow()
Protected ScriptFileName$
OpenMainWindow()
WindowBounds(MainWindow, WindowWidth(MainWindow)-100, WindowHeight(MainWindow), #PB_Ignore, #PB_Ignore)
BindEvent(#PB_Event_SizeWindow, @ResizeGadgetsMainWindow(), MainWindow)
AddKeyboardShortcut(MainWindow, #PB_Shortcut_Escape, #MainWindow_Exit)
ClearGadgetItems(ListView_Scripts)
EnableGadgetDrop(Tree_Sequence, #PB_Drop_Files, #PB_Drag_Copy)
; Fix flickering
;SmartWindowRefresh(MainWindow, #False)
; Add scripts
If ExamineDirectory(0, SnippetsDirectory, "*.ps1")
While NextDirectoryEntry(0)
ScriptFileName$ = DirectoryEntryName(0)
If DirectoryEntryType(0) = #PB_DirectoryEntry_File
AddGadgetItem(ListView_Scripts, -1, ScriptFileName$)
EndIf
Wend
Else
MessageRequester("Error","Can't examine this directory: "+GetGadgetText(0),0)
EndIf
EndProcedure
Procedure ShowSnippetsFolder(Event)
RunProgram(SnippetsDirectory)
EndProcedure
Procedure AddSnippet(EventType)
Protected SelectedScriptFileName.s = GetGadgetText(ListView_Scripts)
Protected Format, ScriptContent.s
Protected LastStep.i = 0, NextStep.i = 0, LastID.i = 0
Protected Command.s = "#CustomScript"
Protected Query.s, LastResult
If SelectedScriptFileName <> ""
If ReadFile(0, SnippetsDirectory + "\" + SelectedScriptFileName)
Format = ReadStringFormat(0)
While Eof(0) = 0
ScriptContent = ScriptContent + ReadString(0, Format) + Chr(13) + Chr(10)
Wend
CloseFile(0)
Else
MessageRequester("Error", "Couldn't open the file: " + SnippetsDirectory + "\" + SelectedScriptFileName, #PB_MessageRequester_Error | #PB_MessageRequester_Ok)
EndIf
EndIf
; Retrieve last step
SetDatabaseString(1, 0, CurrentDeploymentType)
If DatabaseQuery(1, "SELECT MAX(Step) FROM Actions WHERE DeploymentType=? LIMIT 1")
If FirstDatabaseRow(1)
LastStep = GetDatabaseLong(1, 0)
Debug "[Debug: Script Custom Script Handler] Last step count: "+LastStep
EndIf
EndIf
; Calc next step
NextStep = LastStep + 1
; Add new action
If IsDatabase(1) And Command <> ""
; Insert action
Query.s = "INSERT INTO Actions (Step, Command, Name, Disabled, ContinueOnError, DeploymentType) VALUES ("+NextStep+", '"+Command+"', 'PowerShell script ("+SelectedScriptFileName+")', 0, 0, '"+CurrentDeploymentType+"')"
Debug "[Debug: Script Custom Script Handler] Update table: "+Query
CheckDatabaseUpdate(1, Query)
; Last row
SetDatabaseString(1, 0, CurrentDeploymentType)
If DatabaseQuery(1, "SELECT MAX(ID) FROM Actions WHERE DeploymentType=? LIMIT 1")
If FirstDatabaseRow(1)
LastID = GetDatabaseLong(1, 0)
Debug "[Debug: Script Custom Script Handler] Last MAX(ID) is: "+LastID
EndIf
EndIf
; Insert action value
Query.s = "INSERT INTO Actions_Values (Action, Parameter, Value) VALUES ("+LastID+", 'Script', '"+ScriptContent+"')"
Debug "[Debug: Script Custom Script Handler] Update table: "+Query
CheckDatabaseUpdate(1, Query)
EndIf
FinishDatabaseQuery(1)
RefreshProject(0)
EndProcedure
Procedure UpdateProjectSettings(SettingName.s, Value.s)
; Check if the setting already exists to update
SetDatabaseString(1, 0, SettingName)
CheckDatabaseUpdate(1, "INSERT OR IGNORE INTO Settings (Name) VALUES (?)")
FinishDatabaseQuery(1)
; Update setting value
SetDatabaseString(1, 0, Value)
SetDatabaseString(1, 1, SettingName)
CheckDatabaseUpdate(1, "UPDATE Settings SET VALUE = ? WHERE Name = ?;")
FinishDatabaseQuery(1)
EndProcedure
Procedure UpdateProjectSettingByGadget(SettingName.s, Gadget.i)
; Check if the setting already exists to update
SetDatabaseString(1, 0, SettingName)
CheckDatabaseUpdate(1, "INSERT OR IGNORE INTO Settings (Name) VALUES (?)")
FinishDatabaseQuery(1)
; Update setting value
Debug GetGadgetText(Gadget)
SetDatabaseString(1, 0, GetGadgetText(Gadget))
SetDatabaseString(1, 1, SettingName)
CheckDatabaseUpdate(1, "UPDATE Settings SET VALUE = ? WHERE Name = ?;")
FinishDatabaseQuery(1)
EndProcedure
Procedure.s ReplaceDotsAndForwardSlashes(String.s)
String = ReplaceString(String, Chr(47), Chr(95))
String = ReplaceString(String, Chr(46), Chr(95))
ProcedureReturn String
EndProcedure
Procedure DownloadInternetFile(Url.s, OutputFile.s, Gadget, What.s = "file")
Protected Download, Progress
; Receive HTTP file from url and save it as local file to the file system
Download = ReceiveHTTPFile(Url, OutputFile, #PB_HTTP_Asynchronous)
; Progress download
If Download
Debug "[Debug: Internet File Downloader] Starting download ["+Url+"] to: " + OutputFile
Repeat
Progress = HTTPProgress(Download)
Select Progress
; Success
Case #PB_HTTP_Success
SetGadgetText(Gadget, "Download successfully")
FinishHTTP(Download)
Break
; Failed
Case #PB_HTTP_Failed
Debug "[Debug: Internet File Downloader] Download failed"
SetGadgetText(Gadget, "Download failed")
FinishHTTP(Download)
DeleteFile(OutputFile)
ProcedureReturn
; Aborted
Case #PB_HTTP_Aborted
Debug "[Debug: Internet File Downloader] Download aborted"
SetGadgetText(Gadget, "Download aborted")
FinishHTTP(Download)
DeleteFile(OutputFile)
ProcedureReturn
; Default
Default
Debug "[Debug: Internet File Downloader] Progress of downloading the installer file from internet: " + StrF(Progress / (1024 * 1024), 2) + " MB"
SetGadgetText(Gadget, "Downloading "+What+" from internet: " + StrF(Progress / (1024 * 1024), 2) + " MB")
EndSelect
Delay(500) ; Don't steal the whole CPU
ForEver
EndIf
EndProcedure
Procedure.i UpdateLocalWinGetRepository()
If FileSize(WinGet_RepositoryLocalFile) = -1
Debug "[Debug: WinGet Repository Downloader] Local master copy is not existing"
; Repo doesnt exist
If MessageRequester("WinGet Repository", "You need a local copy of the WinGet repository."+Chr(10)+"Do you want To download the latest version automatically from the internet?", #PB_MessageRequester_Warning | #PB_MessageRequester_YesNo) = #PB_MessageRequester_Yes
Debug "[Debug: WinGet Repository Downloader] Downloading master from the internet"
DownloadInternetFile(WinGet_RepositoryUrl, WinGet_RepositoryLocalFile, Text_WinGetStatus)
ProcedureReturn #True
Else
Debug "[Debug: WinGet Repository Downloader] Aborted master download"
ProcedureReturn #False
EndIf
Else
; Repo exists already
Protected WinGet_RepositoryFileDate = GetFileDate(WinGet_RepositoryLocalFile, #PB_Date_Modified)
If MessageRequester("WinGet Repository", "You already have a local copy of the WinGet repository ("+FormatDate("%dd.%mm.%yyyy %hh:%ii", WinGet_RepositoryFileDate)+"). Do you want to update or download the latest version from the internet?", #PB_MessageRequester_Info | #PB_MessageRequester_YesNo) = #PB_MessageRequester_Yes
Debug "[Debug: WinGet Repository Downloader] Updating master on local filesystem"
DownloadInternetFile(WinGet_RepositoryUrl, WinGet_RepositoryLocalFile, Text_WinGetStatus)
ProcedureReturn #True
Else
Debug "[Debug: WinGet Repository Downloader] Cancelled master update"
ProcedureReturn #True
EndIf
EndIf
ProcedureReturn #False
EndProcedure
Procedure DownloadWinGetManifests()
Protected PackagePath.s, ManifestFileName.s
Protected SearchFor.s = LCase(GetGadgetText(String_WinGetPackageSearch))
Protected ResultsCount.i = 0
; Delete temp folder
DeleteDirectory(WinGet_ManifestTempFolder, "*.*", #PB_FileSystem_Recursive)
If 1 = 1
Debug "[Debug: WinGet Repository Extractor] File received and written to disk. If the remote file was not found, it will contains the webserver error."
If OpenPack(0, WinGet_RepositoryLocalFile)
; List all the entries
If ExaminePack(0)
While NextPackEntry(0)
;Debug "Name: " + PackEntryName(0) + ", Size: " + PackEntrySize(0)
If FindString(LCase(PackEntryName(0)), SearchFor) And FindString(PackEntryName(0), "installer.yaml")
;Debug "Name: " + PackEntryName(0)
;Debug "File: " + GetFilePart(PackEntryName(0))
; Remove unnecessary informations
PackagePath = ReplaceString(PackEntryName(0), "winget-pkgs-master/manifests/", "")
PackagePath = Right(PackagePath, Len(PackagePath) - 2)
; Define file name for manifest
ManifestFileName = ReplaceDotsAndForwardSlashes(PackagePath)
; Debug
; AddGadgetItem(WinGetImport_ListIcon, 0, PackagePath)
; Create directory for extraction
CreateDirectory(WinGet_ManifestTempFolder)
; Extract manifest
If UncompressPackFile(0, WinGet_ManifestTempFolder + "\" + ManifestFileName) = -1
Debug "[Debug: WinGet Repository Extractor] Error: unsuccessful unpacking of file: " + PackEntryName(0)
EndIf
; Count and limits
ResultsCount = ResultsCount + 1
EndIf
If ResultsCount >= 200
Debug "[Debug: WinGet Repository Extractor] Limited to 200 extractions"
Break
EndIf
Wend
EndIf
ClosePack(0)
EndIf
Else
Debug "[Debug: WinGet Repository Download] Failed to download package manifests."
EndIf
EndProcedure
Procedure ReadWinGetPackages()
Protected ManifestDirectory.s = WinGet_ManifestTempFolder + "\"
Protected FileName$, Format, Line.s
Protected PackageID.s, PackageVersion.s, Scope.s, ReleaseDate.s, File.s
If ExamineDirectory(0, ManifestDirectory, "*.*")
While NextDirectoryEntry(0)
FileName$ = DirectoryEntryName(0)
If DirectoryEntryType(0) = #PB_DirectoryEntry_File
;AddGadgetItem(WinGetImport_ListIcon, -1, FileName$)
If ReadFile(0, ManifestDirectory + FileName$)
Format = ReadStringFormat(0)
While Eof(0) = 0
Line = ReadString(0, Format)
If FindString(Line, "PackageIdentifier:") And Not FindString(Line, " - PackageIdentifier:")
PackageID = Trim(ReplaceString(Line, "PackageIdentifier:", ""))
EndIf
If FindString(Line, "PackageVersion:")
PackageVersion = Trim(ReplaceString(Line, "PackageVersion:", ""))
EndIf
If FindString(Line, "Scope:")
Scope = Trim(ReplaceString(Line, "Scope:", ""))
EndIf
If FindString(Line, "ReleaseDate:")
ReleaseDate = Trim(ReplaceString(Line, "ReleaseDate:", ""))
EndIf
Wend
; Add element to the list
AddElement(WinGetPackages())
WinGetPackages()\File = FileName$
WinGetPackages()\PackageIdentifier = PackageID
WinGetPackages()\PackageVersion = RemoveString(RemoveString(PackageVersion, Chr(34)), Chr(39))
WinGetPackages()\Scope = Scope
WinGetPackages()\ReleaseDate = ReleaseDate
CloseFile(0)
Else
MessageRequester("Information", "Couldn't open the file!")
EndIf
; Reset values
PackageID = ""
PackageVersion = ""
Scope = ""
ReleaseDate = ""
EndIf
Wend
Else
MessageRequester("Error","Can't examine the folder for all manifest files (or 0 search results - Please check the ID).",0)
EndIf
EndProcedure
Procedure RenderWinGetPackages()
; Reset list
ClearList(WinGetPackages())
; Read all packages
ReadWinGetPackages()
; Clear gadgets
ClearGadgetItems(WinGetImport_ListIcon)
; Render in the list icon gadget
ForEach WinGetPackages()
AddGadgetItem(WinGetImport_ListIcon, 0, WinGetPackages()\PackageIdentifier +Chr(10)+
WinGetPackages()\PackageVersion +Chr(10)+
WinGetPackages()\Scope +Chr(10)+
WinGetPackages()\ReleaseDate +Chr(10)+
WinGetPackages()\File)
Next
EndProcedure
Procedure SearchWinGetPackage(EventType)
; Set status text
SetGadgetText(Text_WinGetStatus, "Downloading and extracting packages...")
; Download and extracting manifests
DownloadWinGetManifests()
; Render package to the UI
RenderWinGetPackages()
; Set final status text
SetGadgetText(Text_WinGetStatus, "Select the package and press [Create New Project]")
EndProcedure
Procedure CloseWinGetImportWindow(EventType)
HideWindow(WinGetImportWindow, #True)
EndProcedure
Procedure CloseProgressWindow(EventType)
HideWindow(ProgressWindow, #True)
SetGadgetText(Text_ProgressStatus, "No running task.")
EndProcedure
Procedure DownloadInstallerFile(Event)
Protected Download, Progress
; Receive HTTP file from url and save it as local file to the file system
Download = ReceiveHTTPFile(Download_Url, Download_OutputFile, #PB_HTTP_Asynchronous)
; Progress download
If Download
Debug "[Debug: Installer Download] Starting download to: " + Download_OutputFile
Repeat
Progress = HTTPProgress(Download)
Select Progress
; Success
Case #PB_HTTP_Success
SetGadgetText(Text_ProgressStatus, "Download successfully: " +Chr(10)+
Download_Url +Chr(10)+Chr(10)+
"Saved file in location: " +Chr(10)+
Download_OutputFile)
FinishHTTP(Download)
Break
; Failed
Case #PB_HTTP_Failed
Debug "[Debug: Installer Download] Download failed"
SetGadgetText(Text_ProgressStatus, "Download failed: " + Download_Url)
FinishHTTP(Download)
DeleteFile(Download_OutputFile)
ProcedureReturn
; Aborted
Case #PB_HTTP_Aborted
Debug "[Debug: Installer Download] Download aborted"
SetGadgetText(Text_ProgressStatus, "Download aborted: " + Download_Url)
FinishHTTP(Download)
DeleteFile(Download_OutputFile)
ProcedureReturn
; Default
Default
Debug "[Debug: Installer Download] Progress of downloading the installer file from internet: " + StrF(Progress / (1024 * 1024), 2) + " MB"
SetGadgetText(Text_ProgressStatus, "Downloading the installer file from internet: " + StrF(Progress / (1024 * 1024), 2) + " MB")
EndSelect
Delay(500) ; Don't steal the whole CPU
ForEver
; Next steps: Create entry for project
Delay(1000)
SetGadgetText(Text_ProgressStatus, "Please wait - Adding installer and silent switch to the project...")
Delay(1000)
; Update project database
If IsDatabase(1)
If GetExtensionPart(Download_Url) = "msi"
SetDatabaseString(1, 0, "Start-ADTMsiProcess")
SetDatabaseString(1, 1, "Start MSI Installer")
SetDatabaseString(1, 2, "Running the setup installer")
CheckDatabaseUpdate(1, "INSERT INTO Actions (ID, Step, Command, Name, Disabled, Description, DeploymentType) VALUES (1, 1, ?, ?, 0, ?, 'Installation')")
CheckDatabaseUpdate(1, "INSERT INTO Actions_Values (Action, Parameter, Value) VALUES (1, 'FilePath', 'Installer.msi')")
CheckDatabaseUpdate(1, "INSERT INTO Actions_Values (Action, Parameter, Value) VALUES (1, 'Action', 'Install')")
FinishDatabaseQuery(1)
ElseIf GetExtensionPart(Download_Url) = "exe"
SetDatabaseString(1, 0, "Start-ADTProcess")
SetDatabaseString(1, 1, "Start EXE Installer")
SetDatabaseString(1, 2, "Running the setup installer")
CheckDatabaseUpdate(1, "INSERT INTO Actions (ID, Step, Command, Name, Disabled, Description, DeploymentType) VALUES (1, 1, ?, ?, 0, ?, 'Installation')")
CheckDatabaseUpdate(1, "INSERT INTO Actions_Values (Action, Parameter, Value) VALUES (1, 'FilePath', 'Installer.exe')")
CheckDatabaseUpdate(1, "INSERT INTO Actions_Values (Action, Parameter, Value) VALUES (1, 'ArgumentList', '"+WinGet_SilentSwitch+"')")
FinishDatabaseQuery(1)
Else
MessageRequester("WinGet Import", "Sorry, but the downloaded installer is an file type ("+GetExtensionPart(Download_Url)+"), which is Not currently supported For automated sequence generation.", #PB_MessageRequester_Error | #PB_MessageRequester_Ok)
EndIf
; Update progress text
SetGadgetText(Text_ProgressStatus, "The WinGet Import is now complete. You may now continue in the editor.")
; Refresh the UI
RefreshProject(0)
Delay(500)
UpdateWindow_(MainWindow)
;HideWindow(ProgressWindow, #True)
EndIf
Else
Debug "[Debug: Installer Download] Download error: Could not initiate download."
EndIf
EndProcedure
Procedure PowerShell_ReadMsi(FilePath.s)
Protected Compiler = #Null
Protected Output$ = ""
Protected Exitcode$ = ""
Protected PSExitcode.i = 1
Protected Productcode.s = ""
Compiler = RunProgram("powershell.exe",
"-NoProfile -NoLogo -WindowStyle Hidden -File .\Scripts\Read-Msi.ps1 -FilePath " + Chr(34) + FilePath + Chr(34) + " -ExecutionPolicy Bypass",
"",
#PB_Program_Open | #PB_Program_Hide | #PB_Program_Read)
Output$ = ""
If Compiler
While ProgramRunning(Compiler)
If AvailableProgramOutput(Compiler)
Output$ = ReadProgramString(Compiler)
If FindString(Output$, "Productmanufacturer:")
MsiInformation(0)\Productmanufacturer = RemoveString(Output$, "Productmanufacturer: ")
EndIf
If FindString(Output$, "Productname:")
MsiInformation(0)\Productname = RemoveString(Output$, "Productname: ")
EndIf
If FindString(Output$, "Productcode:")
MsiInformation(0)\Productcode = RemoveString(Output$, "Productcode: ")
EndIf
If FindString(Output$, "Productversion:")
MsiInformation(0)\Productversion = RemoveString(Output$, "Productversion: ")
EndIf
EndIf
Wend
PSExitcode = ProgramExitCode(Compiler)
CloseProgram(Compiler)
EndIf
If (PSExitcode = 0)
Debug "[Debug: PowerShell > MSI Reader] " + Productcode
Else
MessageRequester("PowerShell Error", Output$, #PB_MessageRequester_Ok | #PB_MessageRequester_Error)
EndIf
EndProcedure
Procedure LoadProjectSettings()
; Clear first the map with the old values
ClearMap(ProjectSettings())
; Read all new settings from the database
If OpenDatabase(1, Project_Database, "", "")
Debug "[Debug: Project Setting] Active Project Database: " + PSADT_Database
; Get all project settings
If DatabaseQuery(1, "SELECT Name, Value FROM Settings")
While NextDatabaseRow(1)
AddMapElement(ProjectSettings(), GetDatabaseString(1, 0))
ProjectSettings()\Value = GetDatabaseString(1, 1)
Wend
Else
MessageRequester("Database Error", "Can't execute the query: " + DatabaseError(), #PB_MessageRequester_Error)
EndIf
FinishDatabaseQuery(1)
Else
MessageRequester("Error", "Can't open the database: " + Project_Database, #PB_MessageRequester_Error)
EndIf
EndProcedure
Procedure.s GetProjectSetting(Key.s = "")
Protected Value.s = ""
If FindMapElement(ProjectSettings(), Key)
ForEach ProjectSettings()
If MapKey(ProjectSettings()) = Key
Value = ProjectSettings()\Value
Break
EndIf
Next
EndIf
ProcedureReturn Value
EndProcedure
Procedure ShowWinGetImportWindow(EventType)
If IsWindow(WinGetImportWindow)
HideWindow(WinGetImportWindow, #False)
SetActiveWindow(WinGetImportWindow)
Else
OpenWinGetImportWindow()
EndIf
AddKeyboardShortcut(WinGetImportWindow, #PB_Shortcut_Return, #WinGetImport_Enter)
SetGadgetText(Combo_TargetArchitecture, "x64")
; Download WinGet repository master
UpdateLocalWinGetRepository()
EndProcedure
Procedure.s ShortenPathWithDots(Path.s)
Define ResultPath.s = Path
Define BackSlashPos.i = 0
ResultPath = Right(ResultPath, 60)
BackSlashPos = FindString(ResultPath, "\", 0)
ResultPath = Right(ResultPath, Len(ResultPath) - BackSlashPos)
ProcedureReturn "...\" + RTrim(ResultPath, "\")
EndProcedure
Procedure ShowNewProjectWindow(EventType)
If IsWindow(NewProjectWindow)
HideWindow(NewProjectWindow, #False)
SetActiveWindow(NewProjectWindow)
Else
OpenNewProjectWindow()
EndIf
; Hide Gadgets
;HideGadget(NPW_Container_ImportWinGet, #True)
HideGadget(NPW_Container_Recent2, #True)
HideGadget(NPW_Container_Recent3, #True)
; Set First Recent Project
SelectElement(RecentProjects(), 0)
SetGadgetText(NPW_Recent1_Link_ProjectFile, RecentProjects()\FileName)
SetGadgetText(NPW_Recent1_Link_ProjectPath, ShortenPathWithDots(RecentProjects()\FolderPath))
EndProcedure
Procedure OpenFirstRecentFolder(EventType)
SelectElement(RecentProjects(), 0)
RunProgram("explorer.exe", RecentProjects()\FolderPath, "")
EndProcedure
Procedure ProjectIsLoaded()
If IsDatabase(1)
ProcedureReturn #True
EndIf
; If project is not loaded, show up an error message
MessageRequester("Error", "No project is currently loaded!" , #PB_MessageRequester_Error | #PB_MessageRequester_Ok)
ProcedureReturn #False
EndProcedure
Procedure CloseNewProjectWindow(EventType)
If IsWindow(NewProjectWindow)
HideWindow(NewProjectWindow, #True)
HideWindow(MainWindow, #False)
SetActiveWindow(MainWindow)
EndIf
EndProcedure
Procedure RenderProjectSettings()
SetGadgetText(PSW_ProjectName_String, GetProjectSetting("Project_Name"))
SetGadgetText(PSW_AppName_String, GetProjectSetting("App_Name"))
SetGadgetText(PSW_AppVersion_String, GetProjectSetting("App_Version"))
SetGadgetText(PSW_AppVendor_String, GetProjectSetting("App_Vendor"))
SetGadgetText(PSW_AppArch_Combo, GetProjectSetting("App_Architecture"))
SetGadgetText(PSW_AppLanguage_String, GetProjectSetting("App_Language"))
SetGadgetText(PSW_ScriptAuthor_String, GetProjectSetting("App_Author"))
If IsWindow(MainWindow)
SetGadgetText(Text_ProjectName, GetProjectSetting("Project_Name"))
EndIf
EndProcedure
Procedure ShowProjectSettingsWindow(EventType)
If IsWindow(ProjectSettingsWindow)
HideWindow(ProjectSettingsWindow, #False)
SetActiveWindow(ProjectSettingsWindow)
Else
OpenProjectSettingsWindow()
EndIf
LoadProjectSettings()
RenderProjectSettings()
EndProcedure
Procedure CloseProjectSettingsWindow(EventType)
If IsWindow(ProjectSettingsWindow)
CloseWindow(ProjectSettingsWindow)
SetActiveWindow(MainWindow)
EndIf
EndProcedure
Procedure SaveProjectSettings(EventType)
If IsDatabase(1)
UpdateProjectSettingByGadget("Project_Name", PSW_ProjectName_String)
UpdateProjectSettingByGadget("App_Name", PSW_AppName_String)
UpdateProjectSettingByGadget("App_Version", PSW_AppVersion_String)
UpdateProjectSettingByGadget("App_Vendor", PSW_AppVendor_String)
UpdateProjectSettingByGadget("App_Architecture", PSW_AppArch_Combo)
UpdateProjectSettingByGadget("App_Language", PSW_AppLanguage_String)
UpdateProjectSettingByGadget("App_Author", PSW_ScriptAuthor_String)
FinishDatabaseQuery(1)
EndIf
; Load new values
LoadProjectSettings()
Debug GetProjectSetting("Project_Name")
RenderProjectSettings()
; Close Window
CloseProjectSettingsWindow(0)
EndProcedure
Procedure ShowAboutWindow(EventType)
If IsWindow(AboutWindow)
HideWindow(AboutWindow, #False)
SetActiveWindow(AboutWindow)
Else
OpenAboutWindow()
EndIf
EndProcedure
Procedure CloseAboutWindow(EventType)
If IsWindow(AboutWindow)
HideWindow(AboutWindow, #True)
Debug "[Debug: Close About Window] Active window ID is: "+GetActiveWindow()
Debug "[Debug: Close About Window] New project window ID is: "+NewProjectWindow
If GetActiveWindow() = NewProjectWindow
SetActiveWindow(NewProjectWindow)
Else
SetActiveWindow(MainWindow)
EndIf
EndIf
EndProcedure
Procedure ShowLogReaderWindow(EventType)
If IsWindow(LogReaderWindow)
HideWindow(LogReaderWindow, #False)
SetActiveWindow(LogReaderWindow)
Else
OpenLogReaderWindow()
EndIf
; Load log reader html
SetGadgetText(WebView_LogReader, "file://" + LogReaderFilePath)
EndProcedure
Procedure CloseLogReaderWindow(EventType)
If IsWindow(LogReaderWindow)
HideWindow(LogReaderWindow, #True)
If GetActiveWindow() = NewProjectWindow
SetActiveWindow(NewProjectWindow)
Else
SetActiveWindow(MainWindow)
EndIf
EndIf
EndProcedure
Procedure ShowImportExeWindow(EventType)
If IsWindow(ImportExeWindow)
HideWindow(ImportExeWindow, #False)
SetActiveWindow(ImportExeWindow)
Else
OpenImportExeWindow()
EndIf
EndProcedure
Procedure CloseImportExeWindow(EventType)
If IsWindow(ImportExeWindow)
HideWindow(ImportExeWindow, #True)
Debug "[Debug: Close Import Exe Window] Active window ID is: "+GetActiveWindow()
Debug "[Debug: Close Import Exe Window] New project window ID is: "+NewProjectWindow
If GetActiveWindow() = NewProjectWindow
SetActiveWindow(NewProjectWindow)
Else
SetActiveWindow(MainWindow)
EndIf
EndIf
EndProcedure
Procedure ImportExeWindow_SelectFilePath(EventType)
Protected StandardFile$ = GetCurrentDirectory()
Protected Pattern$ = "Windows Executable (*.exe)|*.exe|All files (*.*)|*.*"
Protected Pattern = 0
Protected ProtectedPattern = 0