44using System . Linq ;
55using System . Xml ;
66using System . Collections . Generic ;
7- using System . Management . Automation ;
8- using System . Collections . ObjectModel ;
7+ using Windows . Management . Deployment ;
98
109namespace client . Classes
1110{
1211 class handleWindowsApp
1312 {
1413 public static Dictionary < string , string > fileDirectoryCache = new Dictionary < string , string > ( ) ;
1514
15+ private static PackageManager pkgManger = new PackageManager ( ) ;
1616 public static Image getWindowsAppIcon ( String file , bool alreadyAppID = false )
1717 {
1818 // Get the app's ID from its shortcut target file (Ex. 4DF9E0F8.Netflix_mcm4njqhnhss8!Netflix.app)
1919 String microsoftAppName = ( ! alreadyAppID ) ? GetLnkTarget ( file ) : file ;
2020
2121 // Split the string to get the app name from the beginning (Ex. 4DF9E0F8.Netflix)
22- String subAppName = microsoftAppName . Split ( '_ ' ) [ 0 ] ;
22+ String subAppName = microsoftAppName . Split ( '! ' ) [ 0 ] ;
2323
2424 // Loop through each of the folders with the app name to find the one with the manifest + logos
2525 String appPath = findWindowsAppsFolder ( subAppName ) ;
@@ -33,14 +33,14 @@ public static Image getWindowsAppIcon(String file, bool alreadyAppID = false)
3333
3434 String logoLocation = ( appManifest . SelectSingleNode ( "/sm:Package/sm:Properties/sm:Logo" , appManifestNamespace ) . InnerText ) . Replace ( "\\ " , @"\" ) ;
3535
36+
37+
3638 if ( logoLocation != null )
3739 {
3840 // Get the last instance or usage of \ to cut out the path of the logo just to have the path leading to the general logo folder
3941 logoLocation = logoLocation . Substring ( 0 , logoLocation . LastIndexOf ( @"\" ) ) ;
4042 String logoLocationFullPath = Path . GetFullPath ( appPath + "\\ " + logoLocation ) ;
4143
42- String logoPath = "" ;
43-
4444 // Search for all files with 150x150 in its name and use the first result
4545 DirectoryInfo logoDirectory = new DirectoryInfo ( logoLocationFullPath ) ;
4646 FileInfo [ ] filesInDir = getLogoFolder ( "StoreLogo" , logoDirectory ) ;
@@ -106,27 +106,12 @@ public static string findWindowsAppsFolder(string subAppName)
106106 {
107107 try
108108 {
109+ IEnumerable < Windows . ApplicationModel . Package > packages = pkgManger . FindPackagesForUser ( "" , subAppName ) ;
109110
110- using ( PowerShell powerShell = PowerShell . Create ( ) )
111- {
112- powerShell . AddScript ( $ "Get-AppxPackage -name { subAppName } ") ;
113-
114- Collection < PSObject > PSOutput = powerShell . Invoke ( ) ;
115111
116-
117- if ( PSOutput [ 0 ] != null )
118- {
119- String finalPath = Environment . ExpandEnvironmentVariables ( "%ProgramW6432%" ) + $@ "\WindowsApps\" + PSOutput [ 0 ] + @"\" ;
120- fileDirectoryCache [ subAppName ] = finalPath ;
121- return finalPath ;
122- }
123- }
124-
125- /*
126- foreach (string folder in Directory.GetDirectories(Environment.ExpandEnvironmentVariables("%ProgramW6432%") + $@"\WindowsApps\"))
127- {
128- appDirecList.Add(folder);
129- }*/
112+ String finalPath = Environment . ExpandEnvironmentVariables ( "%ProgramW6432%" ) + $@ "\WindowsApps\" + packages . First ( ) . InstalledLocation . DisplayName + @"\" ;
113+ fileDirectoryCache [ subAppName ] = finalPath ;
114+ return finalPath ;
130115 }
131116 catch ( UnauthorizedAccessException ) { } ;
132117 return "" ;
@@ -139,7 +124,7 @@ public static string findWindowsAppsFolder(string subAppName)
139124
140125 public static string findWindowsAppsName ( string AppName )
141126 {
142- String subAppName = AppName . Split ( '_ ' ) [ 0 ] ;
127+ String subAppName = AppName . Split ( '! ' ) [ 0 ] ;
143128 String appPath = findWindowsAppsFolder ( subAppName ) ;
144129
145130
0 commit comments