-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDeploymentEditor.pb
1852 lines (1502 loc) · 62.1 KB
/
DeploymentEditor.pb
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()
;UseGIFImageDecoder()
UseSQLiteDatabase()
;------------------------------------------------------------------------------------
;- 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
;------------------------------------------------------------------------------------
;- Variables, Enumerations and Maps
;------------------------------------------------------------------------------------
Global Event = #Null, Quit = #False
Global MainWindowTitle.s = "Deployment Editor ("+#DE_Version+") - TUGI.CH"
Global DonationUrl.s = "https://www.paypal.com/donate/?hosted_button_id=PXABL8ESQQ4F8"
; Templates
Global Template_PSADT.s = GetCurrentDirectory() + "ThirdParty\PSAppDeployToolkit\"
Global Template_EmptyDatabase.s = GetCurrentDirectory() + "Templates\Deploy-Application.db"
; PSADT
Global PSADT_Database.s = GetCurrentDirectory() + "Databases\PSADT.sqlite"
Global PSADT_TemplateFile.s = GetCurrentDirectory() + "Templates\Deploy-Application.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 + "Deploy-Application.ps1"
Global Project_Database.s = Project_FolderPath + "Deploy-Application.db"
; Deployment
Global CurrentDeploymentType.s = "Installation"
; Maps
Global NewMap PSADT_Parameters.PSADT_Parameter()
Global NewMap ProjectSettings.ProjectSetting()
; Lists
Global NewList RecentProjects.RecentProject()
; > Add Demo Project
AddElement(RecentProjects())
RecentProjects()\FileName = "Deploy-Application.db"
RecentProjects()\FolderPath = Project_FolderPath
; Action
Global SelectedActionID.i
Global UnsavedChange = #False
Global NewList ActionParameterGadgets.PSADT_Parameter_GadgetGroup()
; WinAPI
Global tvi.TV_ITEM
; Shortcuts
Enumeration KeyboardShortcuts
; Menu
#MenuItem_New
#MenuItem_Open
#MenuItem_Save
#MenuItem_Reload
#MenuItem_Quit
#MenuItem_ShowProjectFolder
#MenuItem_ShowFilesFolder
#MenuItem_ShowSupportFilesFolder
#MenuItem_OpenWithISE
#MenuItem_OpenWithNotepadPlusPlus
#MenuItem_RunInstallation
#MenuItem_RunUninstall
#MenuItem_RunRepair
#MenuItem_CreateIntunePackage
#MenuItem_ShowLogs
#MenuItem_GenerateExecutablesList
#MenuItem_ShowPlugins
#MenuItem_PSADT_OnlineDocumentation
#MenuItem_PSADT_OnlineVariablesOverview
#MenuItem_AboutApp
; Keyboard
#Keyboard_Shortcut_Save
#Keyboard_Shortcut_Run
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"
;------------------------------------------------------------------------------------
;- 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 "Update query: " + Query$
Result = DatabaseUpdate(Database, Query$)
If Result = 0
Debug DatabaseError()
Else
Debug "Database update was successfully."
Debug "Affected rows: " + AffectedDatabaseRows(Database)
EndIf
ProcedureReturn Result
EndProcedure
;------------------------------------------------------------------------------------
;- Functions
;------------------------------------------------------------------------------------
Procedure ShowSoftwareReadMe()
CompilerIf #PB_Compiler_Debugger = 0
MessageRequester("Readme", Readme, #PB_MessageRequester_Info)
CompilerEndIf
EndProcedure
Procedure ShowMainWindow()
OpenMainWindow()
WindowBounds(MainWindow, WindowWidth(MainWindow)-100, WindowHeight(MainWindow), #PB_Ignore, #PB_Ignore)
BindEvent(#PB_Event_SizeWindow, @ResizeGadgetsMainWindow(), MainWindow)
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.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 LoadProjectSettings()
; Clear first the map with the old values
ClearMap(ProjectSettings())
; Read all new settings from the database
If OpenDatabase(1, Project_Database, "", "")
Debug "Loaded Project Database successfully: " + 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 ShowProjectSettingsWindow(EventType)
If IsWindow(ProjectSettingsWindow)
HideWindow(ProjectSettingsWindow, #False)
SetActiveWindow(ProjectSettingsWindow)
Else
OpenProjectSettingsWindow()
EndIf
LoadProjectSettings()
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"))
EndProcedure
Procedure CloseProjectSettingsWindow(EventType)
If IsWindow(ProjectSettingsWindow)
HideWindow(ProjectSettingsWindow, #True)
SetActiveWindow(MainWindow)
EndIf
EndProcedure
Procedure UpdateProjectSettingByGadget(SettingName.s, Gadget)
SetDatabaseString(1, 0, GetGadgetText(Gadget))
SetDatabaseString(1, 1, SettingName)
CheckDatabaseUpdate(1, "UPDATE Settings SET Value = ? WHERE Name = ?")
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()
; Update Main Window
SetGadgetText(Text_ProjectName, GetProjectSetting("Project_Name"))
; 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 "Active window ID is: "+GetActiveWindow()
Debug "New project window ID is: "+NewProjectWindow
If GetActiveWindow() = NewProjectWindow
SetActiveWindow(NewProjectWindow)
Else
SetActiveWindow(MainWindow)
EndIf
EndIf
EndProcedure
Procedure ShowLicensing(EventType)
RunProgram(GetCurrentDirectory() + "LICENSE.txt", "", "")
EndProcedure
Procedure OpenDonationUrl(EventType)
RunProgram(DonationUrl, "", "")
EndProcedure
Procedure NotAvailableFeatureMessage(EventType)
MessageRequester("Feature not available", "This feature is not yet available for this version. Sign up for the newsletter on the website to be kept up to date.", #PB_MessageRequester_Info | #PB_MessageRequester_Ok)
EndProcedure
Procedure ShowSoftwareLogFolder(EventType)
Debug "Start Windows Explorer for Software Logs."
RunProgram("explorer.exe", "C:\Windows\Logs\Software", "")
EndProcedure
Procedure ShowProjectFolder(EventType)
RunProgram("explorer.exe", Project_FolderPath, "")
EndProcedure
Procedure ShowFilesFolder(EventType)
RunProgram("explorer.exe", Project_FolderPath + "Files\", "")
EndProcedure
Procedure ShowSupportFilesFolder(EventType)
RunProgram("explorer.exe", Project_FolderPath + "SupportFiles\", "")
EndProcedure
Procedure ShowOnlineDocumentation(EventType)
RunProgram(PSADT_OnlineDocumentation, "", "")
EndProcedure
Procedure ShowOnlineVariablesOverview(EventType)
RunProgram(PSADT_OnlineDocumentation + "/variables", "", "")
EndProcedure
Procedure ShowCommandHelp(EventType)
Protected CurrentCommand.s = GetGadgetText(String_ActionCommand)
RunProgram(PSADT_OnlineDocumentation + "/reference/functions/"+CurrentCommand, "", "")
EndProcedure
Procedure TreeSequence_SetFirstLevelBold()
Protected a.i
For a = 0 To CountGadgetItems(Tree_Sequence) - 1
tvi\mask = #TVIF_HANDLE | #TVIF_CHILDREN
tvi\hItem = GadgetItemID(Tree_Sequence, a)
SendMessage_(GadgetID(Tree_Sequence), #TVM_GETITEM, 0, @tvi)
If tvi\cChildren
tvi\mask = #TVIF_HANDLE | #TVIF_STATE
tvi\state = #TVIS_BOLD
tvi\stateMask = #TVIS_BOLD
SendMessage_(GadgetID(Tree_Sequence), #TVM_SETITEM, 0, tvi)
EndIf
Next
EndProcedure
Procedure TreeSequence_AllExpanded(State = #PB_Tree_Expanded)
Protected i.i
For i = 0 To CountGadgetItems(Tree_Sequence) - 1
SetGadgetItemState(Tree_Sequence, i, State)
Next i
EndProcedure
Procedure LoadProjectFile()
Protected CurrentStep.i = 0, LastStep.i = -1
; Close database if already opened
If IsDatabase(1)
CloseDatabase(1)
EndIf
; Open the database
If OpenDatabase(1, Project_Database, "", "")
Debug "Loaded Project Database successfully: " + Project_Database
SetDatabaseString(1, 0, CurrentDeploymentType)
If DatabaseQuery(1, "SELECT ID,Step,Command,Name,Disabled,Description,ContinueOnError,Action,Parameter,Value,DeploymentType,VariableName FROM View_Sequence WHERE DeploymentType=? ORDER BY Step ASC")
; Add steps into the treeview
While NextDatabaseRow(1)
; Formatting
Protected Prefix.s = ""
Protected IsDisabled = #False
Protected IconImage = ImageID(Img_MainWindow_7)
Protected Affix.s = ""
CurrentStep = GetDatabaseLong(1, 1)
;Debug "Current step is (" + CurrentStep + ") And last step was (" + LastStep + ")"
If CurrentStep <> LastStep
; Styles by status
If GetDatabaseLong(1, 4) = 1
Prefix = "Disabled | "
IsDisabled = #True
IconImage = ImageID(Img_MainWindow_8)
EndIf
; PowerShell custom script?
If GetDatabaseString(1, 2) = "#CustomScript"
IconImage = ImageID(Img_MainWindow_12)
EndIf
; Contine on Error?
Protected ContinueOnErrorEnabled = GetDatabaseLong(1, 6)
If ContinueOnErrorEnabled
Affix + " (Continue on Error)"
EndIf
; Title
AddGadgetItem(Tree_Sequence, -1, Space(1) + Prefix + GetDatabaseString(1, 3) + Affix + Space(1), IconImage)
SetGadgetItemData(Tree_Sequence, CountGadgetItems(Tree_Sequence) - 1, GetDatabaseLong(1, 0))
; Coloring
If IsDisabled
SetGadgetItemColor(Tree_Sequence, CountGadgetItems(Tree_Sequence) - 1, #PB_Gadget_FrontColor, RGB(168, 168, 168))
SetGadgetItemColor(Tree_Sequence, CountGadgetItems(Tree_Sequence) - 1, #PB_Gadget_BackColor, RGB(245, 245, 245))
Else
If GetDatabaseString(1, 2) = "#CustomScript"
SetGadgetItemColor(Tree_Sequence, CountGadgetItems(Tree_Sequence) - 1, #PB_Gadget_FrontColor, RGB(6, 21, 17))
SetGadgetItemColor(Tree_Sequence, CountGadgetItems(Tree_Sequence) - 1, #PB_Gadget_BackColor, RGB(202, 231, 247))
Else
SetGadgetItemColor(Tree_Sequence, CountGadgetItems(Tree_Sequence) - 1, #PB_Gadget_FrontColor, RGB(6, 21, 17))
SetGadgetItemColor(Tree_Sequence, CountGadgetItems(Tree_Sequence) - 1, #PB_Gadget_BackColor, RGB(218, 242, 236))
EndIf
EndIf
; Font
If LoadFont(999, "Segoe UI", 11)
SetGadgetFont(Tree_Sequence, FontID(999)) ; Set the loaded Courier 10 font as new standard
EndIf
; Description as first item
AddGadgetItem(Tree_Sequence, -1, "Description: " + GetDatabaseString(1, 5), 0, 1)
; Variable as second item
If Trim(GetDatabaseString(1, 11)) <> ""
AddGadgetItem(Tree_Sequence, -1, "Variable: " + GetDatabaseString(1, 11), 0, 1)
EndIf
EndIf
; Check value
Protected Value.s = GetDatabaseString(1, 9)
If RemoveString(Value, " ") = ""
Value = "(none)"
EndIf
If GetDatabaseString(1, 8) <> ""
AddGadgetItem(Tree_Sequence, -1, GetDatabaseString(1, 8) + ": " + Value, 0, 1)
If Value = "(none)"
SetGadgetItemColor(Tree_Sequence, CountGadgetItems(Tree_Sequence) - 1, #PB_Gadget_FrontColor, RGB(99, 99, 107))
EndIf
Else
AddGadgetItem(Tree_Sequence, -1, "No values for parameters found.", 0, 1)
SetGadgetItemColor(Tree_Sequence, CountGadgetItems(Tree_Sequence) - 1, #PB_Gadget_BackColor, RGB(255, 255, 223))
EndIf
LastStep = CurrentStep
Prefix = ""
Wend
FinishDatabaseQuery(1)
Else
MessageRequester("Database Error", "Can't execute the query: " + DatabaseError(), #PB_MessageRequester_Error)
EndIf
Else
MessageRequester("Database Error", "Can't open the database: " + Project_Database, #PB_MessageRequester_Error)
EndIf
EndProcedure
Procedure TreeSequence_ExpandedByID(ID.i = 0)
Protected Index.i = 0
For Index = 0 To CountGadgetItems(Tree_Sequence)
Protected Item.i = GetGadgetItemData(Tree_Sequence, Index)
If Item = ID
ProcedureReturn SetGadgetItemState(Tree_Sequence, Index, #PB_Tree_Expanded)
EndIf
Next
EndProcedure
Procedure RefreshProject(EventType)
ClearGadgetItems(Tree_Sequence)
LoadProjectFile()
TreeSequence_SetFirstLevelBold()
;TreeSequence_AllExpanded()
EndProcedure
Procedure LoadCommandsAndParameters()
Protected PSADT_Command.s, PSADT_Category.s
If OpenDatabase(0, PSADT_Database, "", "")
Debug "Loaded PSADT Database successfully: " + PSADT_Database
; Get all commands
If DatabaseQuery(0, "SELECT Command,Category FROM Commands ORDER BY Name ASC")
While NextDatabaseRow(0)
PSADT_Command = GetDatabaseString(0, 0)
PSADT_Category = GetDatabaseString(0, 1)
If FindString(PSADT_Command, "#", 1) = 0
AddGadgetItem(ListView_Commands, -1, PSADT_Command)
EndIf
Wend
Else
MessageRequester("Database Error", "Can't execute the query: " + DatabaseError(), #PB_MessageRequester_Error)
EndIf
; Get all parameters
If DatabaseQuery(0, "SELECT P.ID, C.Command,P.Parameter,P.Description,P.Type,P.Required FROM Parameters AS P LEFT JOIN Commands AS C ON P.Command = C.ID")
While NextDatabaseRow(0)
Define Parameter_ID = GetDatabaseLong(0, 0)
PSADT_Parameters(Str(Parameter_ID))\Command = GetDatabaseString(0, 1)
PSADT_Parameters()\Parameter = GetDatabaseString(0, 2)
PSADT_Parameters()\Description = GetDatabaseString(0, 3)
PSADT_Parameters()\Type = GetDatabaseString(0, 4)
PSADT_Parameters()\Required = GetDatabaseLong(0, 5)
Wend
Else
MessageRequester("Database Error", "Can't execute the query: " + DatabaseError(), #PB_MessageRequester_Error)
EndIf
FinishDatabaseQuery(0)
Else
MessageRequester("Error", "Can't open the database: " + PSADT_Database, #PB_MessageRequester_Error)
EndIf
EndProcedure
Procedure.s ParameterTypeByCommand(CommandToSearch.s = "", ParameterToSearch.s = "")
;Protected NewMap Result.PSADT_Parameter()
Protected MyParameterType.s = ""
ForEach PSADT_Parameters()
;Debug PSADT_Parameters()\Command + " : " + PSADT_Parameters()\Type
If PSADT_Parameters()\Command = CommandToSearch And PSADT_Parameters()\Parameter = ParameterToSearch
Protected RKey.s = MapKey(PSADT_Parameters())
MyParameterType = PSADT_Parameters()\Type
Break
;Debug "Found parameter for " + Command + ": " + PSADT_Parameters()\Parameter
;Result(RKey)\Command = PSADT_Parameters()\Command
;Result(RKey)\Parameter = PSADT_Parameters()\Parameter
;Result(RKey)\Description = PSADT_Parameters()\Description
;Result(RKey)\Type = PSADT_Parameters()\Type
;Result(RKey)\Required = PSADT_Parameters()\Required
EndIf
Next
ProcedureReturn MyParameterType
EndProcedure
Procedure LoadUI()
; Output in debug console
Debug "Triggered LoadUI()"
; Update gadgets and hide image placeholders
SetGadgetState(Combo_DeploymentType, 0)
HideGadget(Image_Check, #True)
HideGadget(Image_DisabledStep, #True)
HideGadget(Image_PowerShell, #True)
HideGadget(Image_Exclamation, #True)
; Load available PowerShell commands and the project
LoadCommandsAndParameters()
;Debug ParameterTypeByCommand("Remove-File", "Path")
; Set keyboard shortcuts for Main Window
AddKeyboardShortcut(MainWindow, #PB_Shortcut_Control | #PB_Shortcut_S, #Keyboard_Shortcut_Save)
AddKeyboardShortcut(MainWindow, #PB_Shortcut_F5, #Keyboard_Shortcut_Run)
; Set version in window title for Main Window
SetWindowTitle(MainWindow, MainWindowTitle)
EndProcedure
Procedure ListFilesRecursive(Dir.s, List Files.s())
Protected D
NewList Directories.s()
If Right(Dir, 1) <> "\"
Dir + "\"
EndIf
D = ExamineDirectory(#PB_Any, Dir, "")
While NextDirectoryEntry(D)
Select DirectoryEntryType(D)
Case #PB_DirectoryEntry_File
AddElement(Files())
Files() = Dir + DirectoryEntryName(D)
Case #PB_DirectoryEntry_Directory
Select DirectoryEntryName(D)
Case ".", ".."
Continue
Default
AddElement(Directories())
Directories() = Dir + DirectoryEntryName(D)
EndSelect
EndSelect
Wend
FinishDirectory(D)
ForEach Directories()
ListFilesRecursive(Directories(), Files())
Next
EndProcedure
Procedure GenerateExecutablesList(EventType)
; Check if the project is loaded
If Not ProjectIsLoaded() : ProcedureReturn 0 : EndIf
; Set variables and paths
Protected InstallationPath.s = PathRequester("Path to the installation folder", "C:\Program Files")
Protected ExecutablesList.s = ""
If InstallationPath
NewList F.s()
ListFilesRecursive(InstallationPath, F())
ForEach F()
If GetExtensionPart(F()) = "exe"
ExecutablesList = ExecutablesList + "," + GetFilePart(F(), #PB_FileSystem_NoExtension)
EndIf
Next
ExecutablesList = LTrim(ExecutablesList, ",")
InputRequester("Executables List", "Result:", ExecutablesList)
EndIf
EndProcedure
Procedure SaveAndCloseProject()
If IsDatabase(1)
SaveAction(0)
CloseDatabase(1)
EndIf
EndProcedure
Procedure CreateIntunePackage(EventType)
; First close the project database
SaveAndCloseProject()
Delay(300)
; Set variables and paths
Protected InstallerFile.s, InstallerPath.s, PackagePath.s
Protected WrapperParameters$, Compiler, Output$, Exitcode = 1
InstallerFile = "Deploy-Application.exe"
InstallerPath = Project_FolderPath + InstallerFile
PackagePath = PathRequester("Intune Package Destination", "C:\")
; Check package path if empty
If Trim(PackagePath) = ""
RefreshProject(0)
ProcedureReturn 0
EndIf
; Check if IntuneWinAppUtil.exe exists in the user temp folder
If FileSize(IntuneWinAppUtil) = -1
StatusBarText(0, 0, "Error: IntuneWinAppUtil missing")
RefreshProject(0)
ProcedureReturn MessageRequester("Win32 Content Prep Tool", IntuneWinAppUtil + " is missing!", #PB_MessageRequester_Ok | #PB_MessageRequester_Error)
EndIf
; Check if *.intunewin file with same name exists in the package folder
If ExamineDirectory(0, PackagePath, "*.intunewin")
While NextDirectoryEntry(0)
If DirectoryEntryType(0) = #PB_DirectoryEntry_File
Protected SearchedPackageFile.s = GetFilePart(InstallerFile, #PB_FileSystem_NoExtension) + ".intunewin"
If DirectoryEntryName(0) = SearchedPackageFile
RefreshProject(0)
ProcedureReturn MessageRequester("Existing Intune package file", "Please delete first the existing package to continue: " + DirectoryEntryName(0), #PB_MessageRequester_Ok | #PB_MessageRequester_Warning)
EndIf
EndIf
Wend
FinishDirectory(0)
EndIf
; Define parameters for IntuneWinAppUtil
WrapperParameters$ = "-c %FolderPath% -s %InstallerPath% -o %PackagePath%"
WrapperParameters$ = ReplaceString(WrapperParameters$, "%FolderPath%", Chr(34) + RTrim(Project_FolderPath, "\") + Chr(34))
WrapperParameters$ = ReplaceString(WrapperParameters$, "%InstallerPath%", Chr(34) + InstallerPath + Chr(34))
WrapperParameters$ = ReplaceString(WrapperParameters$, "%PackagePath%", Chr(34) + PackagePath + Chr(34))
Debug "Parameters for the wrapper: " + WrapperParameters$
; Run IntuneWinAppUtil
StatusBarText(0, 0, "Create Intune package...")
Compiler = RunProgram(IntuneWinAppUtil, WrapperParameters$, "", #PB_Program_Open) ; #PB_Program_Open | #PB_Program_Read | #PB_Program_Hide
Output$ = ""
If Compiler
While ProgramRunning(Compiler)
If AvailableProgramOutput(Compiler)
Output$ + ReadProgramString(Compiler) + Chr(13)
EndIf
Wend
Exitcode = ProgramExitCode(Compiler)
Output$ + Chr(13) + Chr(13)
Output$ + "Exitcode: " + Str(Exitcode)
CloseProgram(Compiler)
StatusBarText(0, 0, "Done.")
EndIf
; Check the exit code
If Exitcode = 0
Debug "Successfully created the Intune package."
MessageRequester("Intune Package Creation", "The Intune package has been successfully created: "+PackagePath, #PB_MessageRequester_Info | #PB_MessageRequester_Ok)
Else
Debug "Error Intune package creation!"
MessageRequester("Intune Package Creation", "The Intune package compiler failed.", #PB_MessageRequester_Error | #PB_MessageRequester_Ok)
EndIf
; Load project again
RefreshProject(0)
EndProcedure
Procedure OpenFirstRecentProject(EventType)
; Set Project Folder and File
SelectElement(RecentProjects(), 0)
Project_FolderPath.s = RecentProjects()\FolderPath
Project_DeploymentFile.s = Project_FolderPath + "Deploy-Application.ps1"
Project_Database.s = Project_FolderPath + RecentProjects()\FileName
; Load Project and Settings
RefreshProject(0)
LoadProjectSettings()
; Close New Project Window
CloseNewProjectWindow(0)
; Show Main Window
HideWindow(MainWindow, #False)
SetActiveWindow(MainWindow)
SetGadgetText(Text_ProjectName, GetProjectSetting("Project_Name"))
; Enable GUI
DisableGadget(ListView_Commands, #False)
DisableGadget(Combo_DeploymentType, #False)
DisableGadget(Tree_Sequence, #False)
DisableGadget(Button_SaveAction, #False)
DisableGadget(Button_AddCommand, #False)
DisableGadget(Button_AddCustomScript, #False)
EndProcedure
Procedure OpenOtherProject(EventType)
; Request file location
Protected StandardFile$, Pattern$, File$, Pattern
StandardFile$ = "C:\"
Pattern$ = "Project Database (*.db)|*.db|All files (*.*)|*.*"
Pattern = 0
File$ = OpenFileRequester("Please choose project database file to load", StandardFile$, Pattern$, Pattern)
If File$ = ""
Debug "Canceled project database selection."
ProcedureReturn 0
EndIf
; Set Project Folder and File
Project_FolderPath.s = GetPathPart(File$)
Project_DeploymentFile.s = Project_FolderPath + "Deploy-Application.ps1"
Project_Database.s = Project_FolderPath + GetFilePart(File$)
; Load Project and Settings
RefreshProject(0)
LoadProjectSettings()
; Close New Project Window
CloseNewProjectWindow(0)
; Show Main Window
HideWindow(MainWindow, #False)
SetActiveWindow(MainWindow)
SetGadgetText(Text_ProjectName, GetProjectSetting("Project_Name"))
; Enable GUI
DisableGadget(ListView_Commands, #False)
DisableGadget(Combo_DeploymentType, #False)
DisableGadget(Tree_Sequence, #False)
DisableGadget(Button_SaveAction, #False)
DisableGadget(Button_AddCommand, #False)
DisableGadget(Button_AddCustomScript, #False)
EndProcedure
Procedure CreateNewProject(EventType)
; Set destination path for the new project
Protected InitialPath$, Path$, ExamineFolder
InitialPath$ = "C:\"
Path$ = PathRequester("Please choose your path for the new project", InitialPath$)
If Path$
Debug "Choosen path is: " + Path$
Else
Debug "Abort project creation - No folder selected."
ProcedureReturn 0
EndIf
; Ask user for confirmation
Define Confirmation = MessageRequester("Confirmation", "Please confirm the destination folder first - all files will be overwritten with the default template files: " + Path$, #PB_MessageRequester_YesNoCancel | #PB_MessageRequester_Warning)
If Confirmation = #PB_MessageRequester_No Or Confirmation = #PB_MessageRequester_Cancel
ProcedureReturn MessageRequester("Cancelled", "You have canceled the creation of a new project.", #PB_MessageRequester_Ok | #PB_MessageRequester_Info)
EndIf
; Copy template folder from PSADT source
Debug "Copy PSADT framework..."
Debug "Source Template folder: " + Template_PSADT
Debug "Destination folder: " + Path$
CopyDirectory(Template_PSADT, Path$, "", #PB_FileSystem_Recursive | #PB_FileSystem_Force)
; Copy empty database template to destination folder
Debug "Copy empty database file..."
CopyFile(Template_EmptyDatabase, Path$ + "Deploy-Application.db")
; Set Project Folder and File
Project_FolderPath.s = Path$
Project_DeploymentFile.s = Project_FolderPath + "Deploy-Application.ps1"
Project_Database.s = Project_FolderPath + "Deploy-Application.db"
; Load Project and Settings
RefreshProject(0)
LoadProjectSettings()
; Close New Project Window
CloseNewProjectWindow(0)
; Show Main Window
HideWindow(MainWindow, #False)
SetActiveWindow(MainWindow)
SetGadgetText(Text_ProjectName, GetProjectSetting("Project_Name"))
; Enable GUI
DisableGadget(ListView_Commands, #False)
DisableGadget(Combo_DeploymentType, #False)
DisableGadget(Tree_Sequence, #False)
DisableGadget(Button_SaveAction, #False)
DisableGadget(Button_AddCommand, #False)
DisableGadget(Button_AddCustomScript, #False)
EndProcedure
Procedure.s GetActionParameterValueByID(ActionID.i, Parameter.s)
Protected Value.s = ""
Protected RequestQuery.s = "SELECT Value FROM Actions_Values WHERE Parameter='"+Parameter+"' AND Action="+ActionID
Debug "Query is: " + RequestQuery
If DatabaseQuery(1, RequestQuery)
While NextDatabaseRow(1)
Value = GetDatabaseString(1, 0)
Wend
FinishDatabaseQuery(1)
Else
MessageRequester("Database Error", "Can't execute the query: " + DatabaseError(), #PB_MessageRequester_Error)
EndIf
ProcedureReturn Value
EndProcedure
Procedure EditorInputHandler()
Debug "Input in Editor > Action triggered."
UnsavedChange = #True
EndProcedure
Procedure OptionsInputHandler()
Debug "Input in Editor > Options triggered."
SaveAction(0)
EndProcedure
Procedure RenderActionEditor(ID.i = -1)
; Default values
Protected SelectedItem.i = GetGadgetState(Tree_Sequence)
Protected Command.s = "", Name.s = "", Description.s = "", VariableName.s = ""
Protected Disabled.i = 0, ContinueOnError.i = 0
If ID = -1
ID = GetGadgetItemData(Tree_Sequence, SelectedItem)
EndIf
; Check for previous changes
Protected UnsavedChangeMessage
If UnsavedChange
UnsavedChange = #False
UnsavedChangeMessage = MessageRequester("Save Changes", "Do you want to save your previous change?", #PB_MessageRequester_Warning | #PB_MessageRequester_YesNoCancel)
If UnsavedChangeMessage = #PB_MessageRequester_Yes
SaveAction(0)
TreeSequence_ExpandedByID(ID)
EndIf
EndIf
Debug "You clicked on item with data ID: " + ID
SelectedActionID = ID
If ID = 0
Debug "No action rendering by ID=0."
SetGadgetText(String_ActionCommand, "")
SetGadgetText(String_ActionName, "")
SetGadgetText(String_ActionVariable, "")
SetGadgetText(Editor_ActionDescription, "")
SetGadgetState(Checkbox_ContinueOnError, #PB_Checkbox_Unchecked)
SetGadgetState(Checkbox_DisabledAction, #PB_Checkbox_Unchecked)
; Disable gadgets
DisableGadget(String_ActionName, #True)
DisableGadget(Editor_ActionDescription, #True)
DisableGadget(String_ActionVariable, #True)
DisableGadget(Checkbox_ContinueOnError, #True)
DisableGadget(Checkbox_DisabledAction, #True)
DisableGadget(Button_SaveAction, #True)
DisableGadget(Button_RemoveAction, #True)
DisableGadget(ButtonImage_MoveUp, #True)
DisableGadget(ButtonImage_MoveDown, #True)
DisableGadget(ButtonImage_ShowCommandHelp, #True)
DisableGadget(Button_DisableAction, #True)