66using UniGetUI . Core . Data ;
77using UniGetUI . Core . Language ;
88using UniGetUI . Core . Logging ;
9+ using UniGetUI . Core . Tools ;
910using UniGetUI . PackageEngine . Enums ;
1011using UniGetUI . PackageEngine . Interfaces ;
1112using 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 }
0 commit comments