@@ -17,29 +17,39 @@ public class CustomActions
1717 // Specify or calculate the total number of ticks the custom action adds to the length of the ProgressBar
1818 public const uint TotalTicks = TickIncrement * NumberItems ;
1919 private const uint NumberItems = 100 ;
20+
2021 private const string PowerShellFilesElevatedDeferredProperty = "PowerShellFilesElevatedDeferred" ;
2122 private const string PowerShellFilesDeferredProperty = "PowerShellFilesDeferred" ;
2223 private const string PowerShellScriptsElevatedDeferredProperty = "PowerShellScriptsElevatedDeferred" ;
2324 private const string PowerShellScriptsDeferredProperty = "PowerShellScriptsDeferred" ;
2425
26+ private const string PowerShellFilesElevatedUninstallDeferredProperty = "PowerShellFilesElevatedUninstallDeferred" ;
27+ private const string PowerShellFilesUninstallDeferredProperty = "PowerShellFilesUninstallDeferred" ;
28+ private const string PowerShellScriptsElevatedUninstallDeferredProperty = "PowerShellScriptsElevatedUninstallDeferred" ;
29+ private const string PowerShellScriptsUninstallDeferredProperty = "PowerShellScriptsUninstallDeferred" ;
30+
2531 [ CustomAction ]
2632 public static ActionResult PowerShellFilesImmediate ( Session session )
2733 {
34+ session . Log ( "PowerShellFilesImmediate start" ) ;
35+
2836 return FilesImmediate ( session , 0 , PowerShellFilesDeferredProperty ) ;
2937 }
3038
3139 [ CustomAction ]
32- public static ActionResult PowerShellFilesElevatedImmediate ( Session session )
40+ public static ActionResult PowerShellFilesDeferred ( Session session )
3341 {
34- return FilesImmediate ( session , 1 , PowerShellFilesElevatedDeferredProperty ) ;
42+ session . Log ( "PowerShellFilesDeferred start" ) ;
43+
44+ return FilesDeferred ( session , PowerShellFilesDeferredProperty ) ;
3545 }
3646
3747 [ CustomAction ]
38- public static ActionResult PowerShellFilesDeferred ( Session session )
48+ public static ActionResult PowerShellFilesElevatedImmediate ( Session session )
3949 {
40- session . Log ( "PowerShellFilesDeferred start" ) ;
50+ session . Log ( "PowerShellFilesElevatedImmediate start" ) ;
4151
42- return FilesDeferred ( session , PowerShellFilesDeferredProperty ) ;
52+ return FilesImmediate ( session , 1 , PowerShellFilesElevatedDeferredProperty ) ;
4353 }
4454
4555 [ CustomAction ]
@@ -51,29 +61,103 @@ public static ActionResult PowerShellFilesElevatedDeferred(Session session)
5161 }
5262
5363 [ CustomAction ]
54- public static ActionResult PowerShellScriptsImmediate ( Session session )
64+ public static ActionResult PowerShellFilesUninstall ( Session session )
5565 {
56- return ScriptsImmediate ( session , 0 , PowerShellScriptsDeferredProperty ) ;
66+ session . Log ( "PowerShellFilesUninstall start" ) ;
67+
68+ return FilesImmediate ( session , 0 , PowerShellFilesUninstallDeferredProperty ) ;
5769 }
5870
71+
5972 [ CustomAction ]
60- public static ActionResult PowerShellScriptsElevatedImmediate ( Session session )
73+ public static ActionResult PowerShellFilesUninstallDeferred ( Session session )
6174 {
62- return ScriptsImmediate ( session , 1 , PowerShellScriptsElevatedDeferredProperty ) ;
75+ session . Log ( "PowerShellFilesUninstallDeferred start" ) ;
76+
77+ return FilesDeferred ( session , PowerShellFilesUninstallDeferredProperty ) ;
78+ }
79+
80+
81+ [ CustomAction ]
82+ public static ActionResult PowerShellFilesElevatedUninstall ( Session session )
83+ {
84+ session . Log ( "PowerShellFilesElevatedUninstall start" ) ;
85+
86+ return FilesImmediate ( session , 1 , PowerShellFilesElevatedUninstallDeferredProperty ) ;
87+ }
88+
89+ [ CustomAction ]
90+ public static ActionResult PowerShellFilesElevatedUninstallDeferred ( Session session )
91+ {
92+ session . Log ( "PowerShellFilesElevatedUninstallDeferred start" ) ;
93+
94+ return FilesDeferred ( session , PowerShellFilesElevatedUninstallDeferredProperty ) ;
95+ }
96+
97+ [ CustomAction ]
98+ public static ActionResult PowerShellScriptsImmediate ( Session session )
99+ {
100+ session . Log ( "PowerShellScriptsImmediate start" ) ;
101+
102+ return ScriptsImmediate ( session , 0 , PowerShellScriptsDeferredProperty ) ;
63103 }
64104
65105 [ CustomAction ]
66106 public static ActionResult PowerShellScriptsDeferred ( Session session )
67107 {
108+ session . Log ( "PowerShellScriptsDeferred start" ) ;
109+
68110 return ScriptsDeferred ( session , PowerShellScriptsDeferredProperty ) ;
69111 }
70112
113+ [ CustomAction ]
114+ public static ActionResult PowerShellScriptsElevatedImmediate ( Session session )
115+ {
116+ session . Log ( "PowerShellScriptsElevatedImmediate start" ) ;
117+
118+ return ScriptsImmediate ( session , 1 , PowerShellScriptsElevatedDeferredProperty ) ;
119+ }
120+
71121 [ CustomAction ]
72122 public static ActionResult PowerShellScriptsElevatedDeferred ( Session session )
73123 {
124+ session . Log ( "PowerShellScriptsElevatedDeferred start" ) ;
125+
74126 return ScriptsDeferred ( session , PowerShellScriptsElevatedDeferredProperty ) ;
75127 }
76128
129+ [ CustomAction ]
130+ public static ActionResult PowerShellScriptsUninstall ( Session session )
131+ {
132+ session . Log ( "PowerShellScriptsUninstall start" ) ;
133+
134+ return ScriptsImmediate ( session , 0 , PowerShellScriptsUninstallDeferredProperty ) ;
135+ }
136+
137+ [ CustomAction ]
138+ public static ActionResult PowerShellScriptsUninstallDeferred ( Session session )
139+ {
140+ session . Log ( "PowerShellScriptsUninstallDeferred start" ) ;
141+
142+ return ScriptsDeferred ( session , PowerShellScriptsUninstallDeferredProperty ) ;
143+ }
144+
145+ [ CustomAction ]
146+ public static ActionResult PowerShellScriptsElevatedUninstall ( Session session )
147+ {
148+ session . Log ( "PowerShellScriptsElevatedUninstall start" ) ;
149+
150+ return ScriptsImmediate ( session , 1 , PowerShellScriptsElevatedUninstallDeferredProperty ) ;
151+ }
152+
153+ [ CustomAction ]
154+ public static ActionResult PowerShellScriptsElevatedUninstallDeferred ( Session session )
155+ {
156+ session . Log ( "PowerShellScriptsElevatedUninstallDeferred start" ) ;
157+
158+ return ScriptsDeferred ( session , PowerShellScriptsElevatedUninstallDeferredProperty ) ;
159+ }
160+
77161 [ Serializable ]
78162 public class ScriptActionData
79163 {
@@ -92,13 +176,20 @@ private static ActionResult ScriptsImmediate(Session session, int elevated, stri
92176 try
93177 {
94178 List < ScriptActionData > scripts = new List < ScriptActionData > ( ) ;
95- using ( View view = db . OpenView ( string . Format ( "SELECT `Id`, `Script`, `IgnoreErrors` FROM `PowerShellScripts` WHERE `Elevated` = {0} ORDER BY `Order`" , elevated ) ) )
179+ using ( View view = db . OpenView ( string . Format ( "SELECT `Id`, `Script`, `IgnoreErrors`, `Condition` FROM `PowerShellScripts` WHERE `Elevated` = {0} ORDER BY `Order`" , elevated ) ) )
96180 {
97181 view . Execute ( ) ;
98182
99183 Record row ;
100184 while ( ( row = view . Fetch ( ) ) != null )
101185 {
186+ string condition = row [ "Condition" ] ? . ToString ( ) ;
187+ if ( ! string . IsNullOrEmpty ( condition ) && ! session . EvaluateCondition ( condition ) )
188+ {
189+ session . Log ( $ "Condition evaluated to false. Skip PS script { row [ "Id" ] ? . ToString ( ) } ") ;
190+ continue ;
191+ }
192+
102193 string script = Encoding . Unicode . GetString ( Convert . FromBase64String ( row [ "Script" ] . ToString ( ) ) ) ;
103194 script = session . Format ( script ) ;
104195 script = Convert . ToBase64String ( Encoding . Unicode . GetBytes ( script ) ) ;
@@ -204,7 +295,7 @@ private static ActionResult ScriptsDeferred(Session session, string deferredProp
204295 foreach ( ScriptActionData datum in scripts )
205296 {
206297 string script = Encoding . Unicode . GetString ( Convert . FromBase64String ( datum . Script ) ) ;
207- session . Log ( "Executing PowerShell script:\n {0}" , script ) ;
298+ session . Log ( $ "Executing PowerShell script { datum . Id } :\n { script } " ) ;
208299
209300 using ( var task = new PowerShellTask ( script , session ) )
210301 {
@@ -254,14 +345,21 @@ private static ActionResult FilesImmediate(Session session, int elevated, string
254345 try
255346 {
256347 XDocument doc ;
257- using ( View view = db . OpenView ( string . Format ( "SELECT `Id`, `File`, `Arguments`, `IgnoreErrors` FROM `{0}` WHERE `Elevated` = {1} ORDER BY `Order`" , tableName , elevated ) ) )
348+ using ( View view = db . OpenView ( string . Format ( "SELECT `Id`, `File`, `Arguments`, `IgnoreErrors`, `Condition` FROM `{0}` WHERE `Elevated` = {1} ORDER BY `Order`" , tableName , elevated ) ) )
258349 {
259350 view . Execute ( ) ;
260351
261352 doc = new XDocument ( new XDeclaration ( "1.0" , "utf-16" , "yes" ) , new XElement ( "r" ) ) ;
262353
263354 foreach ( Record row in view )
264355 {
356+ string condition = row [ "Condition" ] ? . ToString ( ) ;
357+ if ( ! string . IsNullOrEmpty ( condition ) && ! session . EvaluateCondition ( condition ) )
358+ {
359+ session . Log ( $ "Condition evaluated to false. Skip PS file { row [ "Id" ] ? . ToString ( ) } ") ;
360+ continue ;
361+ }
362+
265363 var args = session . Format ( row [ "Arguments" ] . ToString ( ) ) ;
266364 var IgnoreErrors = session . Format ( row [ "IgnoreErrors" ] . ToString ( ) ) ;
267365
@@ -356,9 +454,9 @@ private static ActionResult FilesDeferred(Session session, string deferredProper
356454 foreach ( XElement row in doc . Root . Elements ( "d" ) )
357455 {
358456 string file = row . Attribute ( "file" ) . Value ;
359-
360457 string arguments = row . Attribute ( "args" ) . Value ;
361458 string IgnoreErrors = row . Attribute ( "IgnoreErrors" ) . Value ;
459+ session . Log ( $ "Executing PowerShell file: '{ file } ' { arguments } ") ;
362460
363461 using ( var task = new PowerShellTask ( file , arguments , session ) )
364462 {
0 commit comments