Skip to content

Commit c3145a3

Browse files
committed
Instead of migrating the UseSystemChocolatey setting, the toggle can be added by not adding the local executable as the first one, so the default file will be pulled from path
1 parent 3959a38 commit c3145a3

2 files changed

Lines changed: 27 additions & 47 deletions

File tree

src/UniGetUI.Core.Settings/SettingsEngine_Names.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ public enum K
7575
DisableSuccessNotifications,
7676
DisableProgressNotifications,
7777
KillProcessesThatRefuseToDie,
78-
TransferredSystemChocolatey,
7978
ManagerPaths,
8079

8180
Test1,
@@ -163,7 +162,6 @@ public static string ResolveKey(K key)
163162
K.DisableSuccessNotifications => "DisableSuccessNotifications",
164163
K.DisableProgressNotifications => "DisableProgressNotifications",
165164
K.KillProcessesThatRefuseToDie => "KillProcessesThatRefuseToDie",
166-
K.TransferredSystemChocolatey => "TransferredSystemChocolatey",
167165
K.ManagerPaths => "ManagerPaths",
168166

169167
K.Test1 => "TestSetting1",

src/UniGetUI.PackageEngine.Managers.Chocolatey/Chocolatey.cs

Lines changed: 27 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -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
{
@@ -189,29 +191,25 @@ protected override IReadOnlyList<Package> _getInstalledPackages_UnSafe()
189191
return Packages;
190192
}
191193

192-
private static readonly string old_choco_path = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Programs\\WingetUI\\choco-cli");
193-
private static readonly string new_choco_path = Path.Join(CoreData.UniGetUIDataDirectory, "Chocolatey");
194-
195194
public override IReadOnlyList<string> FindCandidateExecutableFiles()
196195
{
197-
List<string> ChocoPaths = [];
198-
199-
var SystemPaths = CoreTools.WhichMultiple("choco");
200-
if (SystemPaths.Any()) foreach (var Path in SystemPaths) ChocoPaths.Add(Path);
201-
if (File.Exists(Path.Join(new_choco_path, "choco.exe"))) ChocoPaths.Add(Path.Join(new_choco_path, "choco.exe"));
202-
string EnvPath = Path.Join(Environment.GetEnvironmentVariable("ChocolateyInstall"), "choco.exe");
203-
if (File.Exists(EnvPath)) ChocoPaths.Add(EnvPath);
196+
List<string> candidates = [];
204197

205-
return ChocoPaths;
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;
206204
}
207205

208206
protected override ManagerStatus LoadManager()
209207
{
210-
if (!Directory.Exists(old_choco_path))
208+
if (!Directory.Exists(OldChocoPath))
211209
{
212210
Logger.Debug("Old chocolatey path does not exist, not migrating Chocolatey");
213211
}
214-
else if (CoreTools.IsSymbolicLinkDir(old_choco_path))
212+
else if (CoreTools.IsSymbolicLinkDir(OldChocoPath))
215213
{
216214
Logger.ImportantInfo("Old chocolatey path is a symbolic link, not migrating Chocolatey...");
217215
}
@@ -227,20 +225,20 @@ protected override ManagerStatus LoadManager()
227225

228226
string current_env_var =
229227
Environment.GetEnvironmentVariable("chocolateyinstall", EnvironmentVariableTarget.User) ?? "";
230-
if (current_env_var != "" && Path.GetRelativePath(current_env_var, old_choco_path) == ".")
228+
if (current_env_var != "" && Path.GetRelativePath(current_env_var, OldChocoPath) == ".")
231229
{
232230
Logger.ImportantInfo("Migrating ChocolateyInstall environment variable to new location");
233-
Environment.SetEnvironmentVariable("chocolateyinstall", new_choco_path, EnvironmentVariableTarget.User);
231+
Environment.SetEnvironmentVariable("chocolateyinstall", NewChocoPath, EnvironmentVariableTarget.User);
234232
}
235233

236-
if (!Directory.Exists(new_choco_path))
234+
if (!Directory.Exists(NewChocoPath))
237235
{
238-
Directory.CreateDirectory(new_choco_path);
236+
Directory.CreateDirectory(NewChocoPath);
239237
}
240238

241-
foreach (string old_subdir in Directory.GetDirectories(old_choco_path, "*", SearchOption.AllDirectories))
239+
foreach (string old_subdir in Directory.GetDirectories(OldChocoPath, "*", SearchOption.AllDirectories))
242240
{
243-
string new_subdir = old_subdir.Replace(old_choco_path, new_choco_path);
241+
string new_subdir = old_subdir.Replace(OldChocoPath, NewChocoPath);
244242
if (!Directory.Exists(new_subdir))
245243
{
246244
Logger.Debug("New directory: " + new_subdir);
@@ -252,9 +250,9 @@ protected override ManagerStatus LoadManager()
252250
}
253251
}
254252

255-
foreach (string old_file in Directory.GetFiles(old_choco_path, "*", SearchOption.AllDirectories))
253+
foreach (string old_file in Directory.GetFiles(OldChocoPath, "*", SearchOption.AllDirectories))
256254
{
257-
string new_file = old_file.Replace(old_choco_path, new_choco_path);
255+
string new_file = old_file.Replace(OldChocoPath, NewChocoPath);
258256
if (!File.Exists(new_file))
259257
{
260258
Logger.Info("Copying " + old_file);
@@ -267,7 +265,7 @@ protected override ManagerStatus LoadManager()
267265
}
268266
}
269267

270-
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())
271269
{
272270
if (!Directory.EnumerateFiles(old_subdir).Any() && !Directory.EnumerateDirectories(old_subdir).Any())
273271
{
@@ -276,15 +274,15 @@ protected override ManagerStatus LoadManager()
276274
}
277275
}
278276

279-
if (!Directory.EnumerateFiles(old_choco_path).Any() && !Directory.EnumerateDirectories(old_choco_path).Any())
277+
if (!Directory.EnumerateFiles(OldChocoPath).Any() && !Directory.EnumerateDirectories(OldChocoPath).Any())
280278
{
281-
Logger.Info("Deleting old Chocolatey directory " + old_choco_path);
282-
Directory.Delete(old_choco_path);
279+
Logger.Info("Deleting old Chocolatey directory " + OldChocoPath);
280+
Directory.Delete(OldChocoPath);
283281
}
284282

285-
CoreTools.CreateSymbolicLinkDir(old_choco_path, new_choco_path);
283+
CoreTools.CreateSymbolicLinkDir(OldChocoPath, NewChocoPath);
286284
Settings.Set(Settings.K.ChocolateySymbolicLinkCreated, true);
287-
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}.");
288286

289287
}
290288
catch (Exception e)
@@ -294,22 +292,6 @@ protected override ManagerStatus LoadManager()
294292
}
295293
}
296294

297-
if (Settings.Get(Settings.K.UseSystemChocolatey) && !Settings.Get(Settings.K.TransferredSystemChocolatey))
298-
{
299-
var SystemPaths = CoreTools.WhichMultiple("choco");
300-
if (SystemPaths.Count > 0)
301-
{
302-
string SysPath = SystemPaths.ElementAt(0);
303-
for (int idx = 1; idx < SystemPaths.Count; idx++)
304-
{
305-
if (!SystemPaths.ElementAt(idx).Contains("UniGetUI"))
306-
SysPath = SystemPaths.ElementAt(idx);
307-
}
308-
Settings.SetDictionaryItem(Settings.K.ManagerPaths, "Chocolatey", SysPath);
309-
Settings.Set(Settings.K.TransferredSystemChocolatey, true);
310-
}
311-
}
312-
313295
var (found, executable) = GetExecutableFile();
314296
ManagerStatus status = new() { Found = found, ExecutablePath = executable, ExecutableCallArgs = "", };
315297

0 commit comments

Comments
 (0)