Skip to content

Commit 4b5122b

Browse files
committed
Custom install location on a per-package manager level will provide different subdirectories for each package
1 parent 94be33f commit 4b5122b

4 files changed

Lines changed: 46 additions & 12 deletions

File tree

src/UniGetUI.Core.Tools/Tools.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,5 +694,9 @@ public static string GetCurrentLocale()
694694
{
695695
return LanguageEngine?.Locale ?? "Unset/Unknown";
696696
}
697+
698+
private static readonly HashSet<char> illegalPathChars = Path.GetInvalidFileNameChars().ToHashSet();
699+
public static string MakeValidFileName(string name)
700+
=> string.Concat(name.Where(x => !illegalPathChars.Contains(x)));
697701
}
698702
}

src/UniGetUI.PackageEngine.PackageManagerClasses/Packages/Classes/InstallOptionsFactory.cs

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using UniGetUI.Core.Data;
77
using UniGetUI.Core.Language;
88
using UniGetUI.Core.Logging;
9+
using UniGetUI.Core.Tools;
910
using UniGetUI.PackageEngine.Enums;
1011
using UniGetUI.PackageEngine.Interfaces;
1112
using UniGetUI.PackageEngine.Serializable;
@@ -39,7 +40,7 @@ public static SerializableInstallationOptions LoadForManager(IPackageManager man
3940
=> _loadFromDisk(StoragePath.Get(manager));
4041

4142
public static Task<SerializableInstallationOptions> LoadForManagerAsync(IPackageManager manager)
42-
=> Task.Run(() => _loadFromDisk(StoragePath.Get(manager)));
43+
=> Task.Run(() => LoadForManager(manager));
4344

4445
// Saving to disk (package and manager)
4546
public static void SaveForPackage(SerializableInstallationOptions options, IPackage package)
@@ -54,19 +55,34 @@ public static void SaveForManager(SerializableInstallationOptions options, IPack
5455
public static Task SaveForManagerAsync(SerializableInstallationOptions options, IPackageManager manager)
5556
=> Task.Run(() => _saveToDisk(options, StoragePath.Get(manager)));
5657

57-
// Loading applicable
58+
/// <summary>
59+
/// Loads the applicable InstallationOptions, and applies
60+
/// any required transformations in case that generic options are being used
61+
/// </summary>
62+
/// <param name="package">The package whose options to load</param>
63+
/// <param name="elevated">Overrides the RunAsAdmin property</param>
64+
/// <param name="interactive">Overrides the Interactive property</param>
65+
/// <param name="no_integrity">Overrides the SkipHashCheck property</param>
66+
/// <param name="remove_data">Overrides the RemoveDataOnUninstall property</param>
67+
/// <param name="overridePackageOptions">In case of on-the-fly command generation, the PACKAGE
68+
/// options can be overriden with this object </param>
69+
/// <returns>The applicable SerializableInstallationOptions</returns>
5870
public static SerializableInstallationOptions LoadApplicable(
5971
IPackage package,
6072
bool? elevated = null,
6173
bool? interactive = null,
6274
bool? no_integrity = null,
63-
bool? remove_data = null)
75+
bool? remove_data = null,
76+
SerializableInstallationOptions? overridePackageOptions = null)
6477
{
65-
var instance = LoadForPackage(package);
78+
var instance = overridePackageOptions ?? LoadForPackage(package);
6679
if (!instance.OverridesNextLevelOpts)
6780
{
6881
Logger.Debug($"Package {package.Id} does not override options, will use package manager's default...");
6982
instance = LoadForManager(package.Manager);
83+
84+
var legalizedId = CoreTools.MakeValidFileName(package.Id);
85+
instance.CustomInstallLocation = instance.CustomInstallLocation.Replace("%PACKAGE%", legalizedId);
7086
}
7187

7288
if (elevated is not null) instance.RunAsAdministrator = (bool)elevated;
@@ -77,12 +93,25 @@ public static SerializableInstallationOptions LoadApplicable(
7793
return instance;
7894
}
7995

96+
/// <summary>
97+
/// Loads the applicable InstallationOptions, and applies
98+
/// any required transformations in case that generic options are being used
99+
/// </summary>
100+
/// <param name="package">The package whose options to load</param>
101+
/// <param name="elevated">Overrides the RunAsAdmin property</param>
102+
/// <param name="interactive">Overrides the Interactive property</param>
103+
/// <param name="no_integrity">Overrides the SkipHashCheck property</param>
104+
/// <param name="remove_data">Overrides the RemoveDataOnUninstall property</param>
105+
/// <param name="overridePackageOptions">In case of on-the-fly command generation, the PACKAGE
106+
/// options can be overriden with this object </param>
107+
/// <returns>The applicable SerializableInstallationOptions</returns>
80108
public static Task<SerializableInstallationOptions> LoadApplicableAsync(
81109
IPackage package,
82110
bool? elevated = null,
83111
bool? interactive = null,
84112
bool? no_integrity = null,
85-
bool? remove_data = null)
113+
bool? remove_data = null,
114+
SerializableInstallationOptions? overridePackageOptions = null)
86115
=> Task.Run(() => LoadApplicable(package, elevated, interactive, no_integrity, remove_data));
87116

88117
/*
@@ -140,7 +169,7 @@ private static SerializableInstallationOptions _loadFromDisk(string key)
140169
ArgumentNullException.ThrowIfNull(jsonData);
141170
serializedOptions = new SerializableInstallationOptions(jsonData);
142171
_optionsCache[key] = serializedOptions;
143-
return serializedOptions;
172+
return serializedOptions.Copy();
144173
}
145174
}
146175
}

src/UniGetUI/Pages/DialogPages/InstallOptions_Manager.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ private void SelectDir_Click(object sender, RoutedEventArgs e)
229229
string folder = openPicker.Show();
230230
if (folder != string.Empty)
231231
{
232-
CustomInstallLocation.Text = folder;
232+
CustomInstallLocation.Text = folder.TrimEnd('\\') + "\\%PACKAGE%";
233233
ResetDir.IsEnabled = true;
234234
ApplyButton.Style = (Style)Application.Current.Resources["AccentButtonStyle"];
235235
}

src/UniGetUI/Pages/DialogPages/InstallOptions_Package.xaml.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -317,11 +317,12 @@ private void CloseButton_Click(object sender, RoutedEventArgs e)
317317
private async void GenerateCommand()
318318
{
319319
if (!_uiLoaded) return;
320-
SerializableInstallationOptions options;
321-
if (FollowGlobalOptionsSwitch.IsOn)
322-
options = await InstallOptionsFactory.LoadForManagerAsync(Package.Manager);
323-
else
324-
options = await GetUpdatedOptions(updateIgnoredUpdates: false);
320+
SerializableInstallationOptions options = await GetUpdatedOptions(updateIgnoredUpdates: false);
321+
if (!options.OverridesNextLevelOpts)
322+
{
323+
options = await InstallOptionsFactory.LoadApplicableAsync(this.Package, overridePackageOptions: options);
324+
}
325+
325326
var op = ProfileComboBox.SelectedIndex switch
326327
{
327328
1 => OperationType.Update,

0 commit comments

Comments
 (0)