@@ -18,8 +18,10 @@ namespace UniGetUI.PackageEngine.Managers.ChocolateyManager
1818{
1919 public class Chocolatey : BaseNuGet
2020 {
21- public static new string [ ] FALSE_PACKAGE_IDS = [ "Directory" , "" , "Did" , "Features?" , "Validation" , "-" , "being" , "It" , "Error" , "L'accs" , "Maximum" , "This" , "Output is package name " , "operable" , "Invalid" ] ;
22- public static new string [ ] FALSE_PACKAGE_VERSIONS = [ "" , "of" , "Did" , "Features?" , "Validation" , "-" , "being" , "It" , "Error" , "L'accs" , "Maximum" , "This" , "packages" , "current version" , "installed version" , "is" , "program" , "validations" , "argument" , "no" ] ;
21+ public static readonly string [ ] FALSE_PACKAGE_IDS = [ "Directory" , "" , "Did" , "Features?" , "Validation" , "-" , "being" , "It" , "Error" , "L'accs" , "Maximum" , "This" , "Output is package name " , "operable" , "Invalid" ] ;
22+ public static readonly string [ ] FALSE_PACKAGE_VERSIONS = [ "" , "of" , "Did" , "Features?" , "Validation" , "-" , "being" , "It" , "Error" , "L'accs" , "Maximum" , "This" , "packages" , "current version" , "installed version" , "is" , "program" , "validations" , "argument" , "no" ] ;
23+ private static readonly string OldChocoPath = Path . Join ( Environment . GetFolderPath ( Environment . SpecialFolder . LocalApplicationData ) , "Programs\\ WingetUI\\ choco-cli" ) ;
24+ private static readonly string NewChocoPath = Path . Join ( CoreData . UniGetUIDataDirectory , "Chocolatey" ) ;
2325
2426 public Chocolatey ( )
2527 {
@@ -54,7 +56,6 @@ public Chocolatey()
5456 InstallVerb = "install" ,
5557 UninstallVerb = "uninstall" ,
5658 UpdateVerb = "upgrade" ,
57- ExecutableCallArgs = "" ,
5859 KnownSources = [ new ManagerSource ( this , "community" , new Uri ( "https://community.chocolatey.org/api/v2/" ) ) ] ,
5960 DefaultSource = new ManagerSource ( this , "community" , new Uri ( "https://community.chocolatey.org/api/v2/" ) ) ,
6061
@@ -75,7 +76,7 @@ public static string GetProxyArgument()
7576 return $ "--proxy { proxyUri . ToString ( ) } ";
7677
7778 var creds = Settings . GetProxyCredentials ( ) ;
78- if ( creds is null )
79+ if ( creds is null )
7980 return $ "--proxy { proxyUri . ToString ( ) } ";
8081
8182 return $ "--proxy={ proxyUri . ToString ( ) } --proxy-user={ Uri . EscapeDataString ( creds . UserName ) } " +
@@ -89,7 +90,7 @@ protected override IReadOnlyList<Package> GetAvailableUpdates_UnSafe()
8990 StartInfo = new ProcessStartInfo
9091 {
9192 FileName = Status . ExecutablePath ,
92- Arguments = Properties . ExecutableCallArgs + " outdated " + GetProxyArgument ( ) ,
93+ Arguments = Status . ExecutableCallArgs + " outdated " + GetProxyArgument ( ) ,
9394 RedirectStandardOutput = true ,
9495 RedirectStandardError = true ,
9596 RedirectStandardInput = true ,
@@ -143,7 +144,7 @@ protected override IReadOnlyList<Package> _getInstalledPackages_UnSafe()
143144 StartInfo = new ProcessStartInfo
144145 {
145146 FileName = Status . ExecutablePath ,
146- Arguments = Properties . ExecutableCallArgs + " list " + GetProxyArgument ( ) ,
147+ Arguments = Status . ExecutableCallArgs + " list " + GetProxyArgument ( ) ,
147148 RedirectStandardOutput = true ,
148149 RedirectStandardError = true ,
149150 RedirectStandardInput = true ,
@@ -190,18 +191,25 @@ protected override IReadOnlyList<Package> _getInstalledPackages_UnSafe()
190191 return Packages ;
191192 }
192193
193- protected override ManagerStatus LoadManager ( )
194+ public override IReadOnlyList < string > FindCandidateExecutableFiles ( )
194195 {
195- ManagerStatus status = new ( ) ;
196+ List < string > candidates = [ ] ;
196197
197- string old_choco_path = Path . Join ( Environment . GetFolderPath ( Environment . SpecialFolder . LocalApplicationData ) , "Programs\\ WingetUI\\ choco-cli" ) ;
198- string new_choco_path = Path . Join ( CoreData . UniGetUIDataDirectory , "Chocolatey" ) ;
198+ if ( ! Settings . Get ( Settings . K . UseSystemChocolatey ) )
199+ {
200+ candidates . Add ( Path . Join ( NewChocoPath , "choco.exe" ) ) ;
201+ }
202+ candidates . AddRange ( CoreTools . WhichMultiple ( "choco.exe" ) ) ;
203+ return candidates ;
204+ }
199205
200- if ( ! Directory . Exists ( old_choco_path ) )
206+ protected override ManagerStatus LoadManager ( )
207+ {
208+ if ( ! Directory . Exists ( OldChocoPath ) )
201209 {
202210 Logger . Debug ( "Old chocolatey path does not exist, not migrating Chocolatey" ) ;
203211 }
204- else if ( CoreTools . IsSymbolicLinkDir ( old_choco_path ) )
212+ else if ( CoreTools . IsSymbolicLinkDir ( OldChocoPath ) )
205213 {
206214 Logger . ImportantInfo ( "Old chocolatey path is a symbolic link, not migrating Chocolatey..." ) ;
207215 }
@@ -217,20 +225,20 @@ protected override ManagerStatus LoadManager()
217225
218226 string current_env_var =
219227 Environment . GetEnvironmentVariable ( "chocolateyinstall" , EnvironmentVariableTarget . User ) ?? "" ;
220- if ( current_env_var != "" && Path . GetRelativePath ( current_env_var , old_choco_path ) == "." )
228+ if ( current_env_var != "" && Path . GetRelativePath ( current_env_var , OldChocoPath ) == "." )
221229 {
222230 Logger . ImportantInfo ( "Migrating ChocolateyInstall environment variable to new location" ) ;
223- Environment . SetEnvironmentVariable ( "chocolateyinstall" , new_choco_path , EnvironmentVariableTarget . User ) ;
231+ Environment . SetEnvironmentVariable ( "chocolateyinstall" , NewChocoPath , EnvironmentVariableTarget . User ) ;
224232 }
225233
226- if ( ! Directory . Exists ( new_choco_path ) )
234+ if ( ! Directory . Exists ( NewChocoPath ) )
227235 {
228- Directory . CreateDirectory ( new_choco_path ) ;
236+ Directory . CreateDirectory ( NewChocoPath ) ;
229237 }
230238
231- foreach ( string old_subdir in Directory . GetDirectories ( old_choco_path , "*" , SearchOption . AllDirectories ) )
239+ foreach ( string old_subdir in Directory . GetDirectories ( OldChocoPath , "*" , SearchOption . AllDirectories ) )
232240 {
233- string new_subdir = old_subdir . Replace ( old_choco_path , new_choco_path ) ;
241+ string new_subdir = old_subdir . Replace ( OldChocoPath , NewChocoPath ) ;
234242 if ( ! Directory . Exists ( new_subdir ) )
235243 {
236244 Logger . Debug ( "New directory: " + new_subdir ) ;
@@ -242,9 +250,9 @@ protected override ManagerStatus LoadManager()
242250 }
243251 }
244252
245- foreach ( string old_file in Directory . GetFiles ( old_choco_path , "*" , SearchOption . AllDirectories ) )
253+ foreach ( string old_file in Directory . GetFiles ( OldChocoPath , "*" , SearchOption . AllDirectories ) )
246254 {
247- string new_file = old_file . Replace ( old_choco_path , new_choco_path ) ;
255+ string new_file = old_file . Replace ( OldChocoPath , NewChocoPath ) ;
248256 if ( ! File . Exists ( new_file ) )
249257 {
250258 Logger . Info ( "Copying " + old_file ) ;
@@ -257,7 +265,7 @@ protected override ManagerStatus LoadManager()
257265 }
258266 }
259267
260- foreach ( string old_subdir in Directory . GetDirectories ( old_choco_path , "*" , SearchOption . AllDirectories ) . Reverse ( ) )
268+ foreach ( string old_subdir in Directory . GetDirectories ( OldChocoPath , "*" , SearchOption . AllDirectories ) . Reverse ( ) )
261269 {
262270 if ( ! Directory . EnumerateFiles ( old_subdir ) . Any ( ) && ! Directory . EnumerateDirectories ( old_subdir ) . Any ( ) )
263271 {
@@ -266,15 +274,15 @@ protected override ManagerStatus LoadManager()
266274 }
267275 }
268276
269- if ( ! Directory . EnumerateFiles ( old_choco_path ) . Any ( ) && ! Directory . EnumerateDirectories ( old_choco_path ) . Any ( ) )
277+ if ( ! Directory . EnumerateFiles ( OldChocoPath ) . Any ( ) && ! Directory . EnumerateDirectories ( OldChocoPath ) . Any ( ) )
270278 {
271- Logger . Info ( "Deleting old Chocolatey directory " + old_choco_path ) ;
272- Directory . Delete ( old_choco_path ) ;
279+ Logger . Info ( "Deleting old Chocolatey directory " + OldChocoPath ) ;
280+ Directory . Delete ( OldChocoPath ) ;
273281 }
274282
275- CoreTools . CreateSymbolicLinkDir ( old_choco_path , new_choco_path ) ;
283+ CoreTools . CreateSymbolicLinkDir ( OldChocoPath , NewChocoPath ) ;
276284 Settings . Set ( Settings . K . ChocolateySymbolicLinkCreated , true ) ;
277- Logger . Info ( $ "Symbolic link created successfully from { old_choco_path } to { new_choco_path } .") ;
285+ Logger . Info ( $ "Symbolic link created successfully from { OldChocoPath } to { NewChocoPath } .") ;
278286
279287 }
280288 catch ( Exception e )
@@ -284,21 +292,8 @@ protected override ManagerStatus LoadManager()
284292 }
285293 }
286294
287- if ( Settings . Get ( Settings . K . UseSystemChocolatey ) )
288- {
289- status . ExecutablePath = CoreTools . Which ( "choco.exe" ) . Item2 ;
290- }
291- else if ( File . Exists ( Path . Join ( new_choco_path , "choco.exe" ) ) )
292- {
293- status . ExecutablePath = Path . Join ( new_choco_path , "choco.exe" ) ;
294- }
295- else
296- {
297- status . ExecutablePath = Path . Join ( CoreData . UniGetUIDataDirectory , "Chocolatey" , "choco.exe" ) ;
298- if ( ! File . Exists ( status . ExecutablePath ) ) status . ExecutablePath = "" ;
299- }
300-
301- status . Found = File . Exists ( status . ExecutablePath ) ;
295+ var ( found , executable ) = GetExecutableFile ( ) ;
296+ ManagerStatus status = new ( ) { Found = found , ExecutablePath = executable , ExecutableCallArgs = "" , } ;
302297
303298 if ( ! status . Found )
304299 {
@@ -324,7 +319,7 @@ protected override ManagerStatus LoadManager()
324319 // If the user is running bundled chocolatey and chocolatey is not in path, add chocolatey to path
325320 if ( ! Settings . Get ( Settings . K . UseSystemChocolatey )
326321 && ! File . Exists ( "C:\\ ProgramData\\ Chocolatey\\ bin\\ choco.exe" ) )
327- /* && Settings.Get(Settings.K.ShownWelcomeWizard)) */
322+ /* && Settings.Get(Settings.K.ShownWelcomeWizard)) */
328323 {
329324 string ? path = Environment . GetEnvironmentVariable ( "PATH" , EnvironmentVariableTarget . User ) ;
330325 if ( ! path ? . Contains ( status . ExecutablePath . Replace ( "\\ choco.exe" , "\\ bin" ) ) ?? false )
0 commit comments