1
- // Copyright © 2017 - 2021 Chocolatey Software, Inc
1
+ // Copyright © 2017 - 2022 Chocolatey Software, Inc
2
2
// Copyright © 2011 - 2017 RealDimensions Software, LLC
3
3
//
4
4
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -23,10 +23,7 @@ namespace chocolatey.infrastructure.app.services
23
23
using System . Management . Automation ;
24
24
using System . Management . Automation . Runspaces ;
25
25
using System . Reflection ;
26
- using System . Security . Cryptography ;
27
- using System . Text ;
28
26
using adapters ;
29
- using builders ;
30
27
using commandline ;
31
28
using configuration ;
32
29
using cryptography ;
@@ -38,8 +35,6 @@ namespace chocolatey.infrastructure.app.services
38
35
using powershell ;
39
36
using results ;
40
37
using utility ;
41
- using Assembly = adapters . Assembly ;
42
- using Console = System . Console ;
43
38
using CryptoHashProvider = cryptography . CryptoHashProvider ;
44
39
using Environment = System . Environment ;
45
40
using IFileSystem = filesystem . IFileSystem ;
@@ -112,12 +107,15 @@ private IEnumerable<string> get_hook_scripts(ChocolateyConfiguration configurati
112
107
case CommandNameType . install :
113
108
filenameBase += "install-" ;
114
109
break ;
110
+
115
111
case CommandNameType . uninstall :
116
112
filenameBase += "uninstall-" ;
117
113
break ;
114
+
118
115
case CommandNameType . upgrade :
119
116
filenameBase += "beforemodify-" ;
120
117
break ;
118
+
121
119
default :
122
120
throw new ApplicationException ( "Could not find CommandNameType '{0}' to get hook scripts" . format_with ( command ) ) ;
123
121
}
@@ -353,7 +351,6 @@ public bool run_action(ChocolateyConfiguration configuration, PackageResult pack
353
351
`choco -h` for details." ) ;
354
352
}
355
353
356
-
357
354
if ( result . ExitCode != 0 )
358
355
{
359
356
Environment . ExitCode = result . ExitCode ;
@@ -534,7 +531,7 @@ public void prepare_powershell_environment(IPackage package, ChocolateyConfigura
534
531
}
535
532
}
536
533
537
- SecurityProtocol . set_protocol ( configuration , provideWarning : false ) ;
534
+ SecurityProtocol . set_protocol ( configuration , provideWarning : false ) ;
538
535
}
539
536
540
537
private ResolveEventHandler _handler = null ;
@@ -593,6 +590,12 @@ private void remove_assembly_resolver()
593
590
}
594
591
}
595
592
593
+ [ Obsolete ( "This version of running the powershell host do not support running additional hooks. Use the appropriate overload instead" ) ]
594
+ public PowerShellExecutionResults run_host ( ChocolateyConfiguration config , string chocoPowershellScript , Action < Pipeline > additionalActionsBeforeScript )
595
+ {
596
+ return run_host ( config , chocoPowershellScript , additionalActionsBeforeScript , Enumerable . Empty < string > ( ) , Enumerable . Empty < string > ( ) ) ;
597
+ }
598
+
596
599
public PowerShellExecutionResults run_host ( ChocolateyConfiguration config , string chocoPowerShellScript , Action < Pipeline > additionalActionsBeforeScript , IEnumerable < string > hookPreScriptPathList , IEnumerable < string > hookPostScriptPathList )
597
600
{
598
601
// since we control output in the host, always set these true
@@ -732,11 +735,11 @@ public PowerShellExecutionResults run_host(ChocolateyConfiguration config, strin
732
735
if ( host . ExitCode == 0 ) host . SetShouldExit ( 1 ) ;
733
736
host . HostException = pipeline . PipelineStateInfo . Reason ;
734
737
break ;
738
+
735
739
case PipelineState . Completed :
736
740
if ( host . ExitCode == - 1 ) host . SetShouldExit ( 0 ) ;
737
741
break ;
738
742
}
739
-
740
743
}
741
744
}
742
745
}
0 commit comments