33using UniGetUI . Core . Logging ;
44using UniGetUI . PackageEngine . Enums ;
55using UniGetUI . PackageEngine . Interfaces ;
6+ using UniGetUI . PackageEngine . PackageClasses ;
67
78namespace UniGetUI . PackageEngine . Managers . WingetManager ;
89
910public static class NativePackageHandler
1011{
1112 private static readonly ConcurrentDictionary < long , CatalogPackage > __nativePackages = new ( ) ;
1213 private static readonly ConcurrentDictionary < long , CatalogPackageMetadata > __nativeDetails = new ( ) ;
13- private static readonly ConcurrentDictionary < long , PackageInstallerInfo > __nativeInstallers_Install = new ( ) ;
14+ private static ConcurrentDictionary < long , PackageInstallerInfo > __nativeInstallers_Install = new ( ) ;
1415 private static ConcurrentDictionary < long , PackageInstallerInfo > __nativeInstallers_Uninstall = new ( ) ;
1516
1617 /// <summary>
@@ -66,7 +67,7 @@ public static void AddPackage(IPackage package, CatalogPackage catalogPackage)
6667 /// <summary>
6768 /// Get (cached or load) the native installer for the given package, if any. The operation type determines wether
6869 /// </summary>
69- public static PackageInstallerInfo ? GetInstallationOptions ( IPackage package , OperationType operation )
70+ public static PackageInstallerInfo ? GetInstallationOptions ( IPackage package , IInstallationOptions unigetuiOptions , OperationType operation )
7071 // => TaskRecycler<PackageInstallerInfo?>.RunOrAttach(_getInstallationOptions, package, operation);
7172 //
7273 //private static PackageInstallerInfo? _getInstallationOptions(IPackage package, OperationType operation)
@@ -76,22 +77,23 @@ public static void AddPackage(IPackage package, CatalogPackage catalogPackage)
7677
7778 PackageInstallerInfo ? installerInfo ;
7879 if ( operation is OperationType . Uninstall )
79- installerInfo = _getInstallationOptionsOnDict ( package , ref __nativeInstallers_Uninstall , true ) ;
80+ installerInfo = _getInstallationOptionsOnDict ( package , ref __nativeInstallers_Uninstall , true , unigetuiOptions ) ;
8081 else
81- installerInfo = _getInstallationOptionsOnDict ( package , ref __nativeInstallers_Uninstall , false ) ;
82+ installerInfo = _getInstallationOptionsOnDict ( package , ref __nativeInstallers_Install , false , unigetuiOptions ) ;
8283
8384 return installerInfo ;
8485 }
8586
8687 public static void Clear ( )
8788 {
88- __nativePackages . Clear ( ) ; ;
89- __nativeDetails . Clear ( ) ; ;
90- __nativeInstallers_Install . Clear ( ) ; ;
89+ __nativePackages . Clear ( ) ;
90+ __nativeDetails . Clear ( ) ;
91+ __nativeInstallers_Install . Clear ( ) ;
9192 __nativeInstallers_Uninstall . Clear ( ) ;
9293 }
9394
94- private static PackageInstallerInfo ? _getInstallationOptionsOnDict ( IPackage package , ref ConcurrentDictionary < long , PackageInstallerInfo > source , bool installed )
95+ private static PackageInstallerInfo ? _getInstallationOptionsOnDict ( IPackage package ,
96+ ref ConcurrentDictionary < long , PackageInstallerInfo > source , bool installed , IInstallationOptions unigetuiOptions )
9597 {
9698 if ( source . TryGetValue ( package . GetHash ( ) , out PackageInstallerInfo ? installerInfo ) )
9799 return installerInfo ;
@@ -100,8 +102,26 @@ public static void Clear()
100102 if ( installed ) catalogPackage = GetPackage ( package ) ? . InstalledVersion ;
101103 else catalogPackage = GetPackage ( package ) ? . DefaultInstallVersion ;
102104
103- InstallOptions ? options = NativeWinGetHelper . ExternalFactory ? . CreateInstallOptions ( ) ;
104- installerInfo = catalogPackage ? . GetApplicableInstaller ( options ) ;
105+ InstallOptions ? wingetOptions = NativeWinGetHelper . ExternalFactory ? . CreateInstallOptions ( ) ;
106+ InstallOptions ? wingetDefaultOptions = NativeWinGetHelper . ExternalFactory ? . CreateInstallOptions ( ) ;
107+
108+ if ( wingetOptions is null )
109+ {
110+ Logger . Error ( "WinGetFactory.CreateInstallOptions returned null!" ) ;
111+ return installerInfo ;
112+ }
113+
114+ if ( unigetuiOptions . InstallationScope is PackageScope . Machine )
115+ {
116+ wingetOptions . PackageInstallScope = PackageInstallScope . System ;
117+ }
118+ else if ( unigetuiOptions . InstallationScope is PackageScope . User )
119+ {
120+ wingetOptions . PackageInstallScope = PackageInstallScope . User ;
121+ }
122+
123+ installerInfo = catalogPackage ? . GetApplicableInstaller ( wingetOptions ) ;
124+ installerInfo ??= catalogPackage ? . GetApplicableInstaller ( wingetDefaultOptions ) ;
105125
106126 if ( installerInfo is not null )
107127 source [ package . GetHash ( ) ] = installerInfo ;
0 commit comments