@@ -27,6 +27,11 @@ internal class Win32AppInfo
2727
2828 public string Aumid { get ; set ; }
2929
30+ /// <summary>
31+ /// Gets the AUMID before it was fixed up with the backslash issue
32+ /// </summary>
33+ public string Pre7_0_1Aumid { get ; private set ; }
34+
3035 public string DisplayName { get ; set ; }
3136
3237 public string IconPath { get ; set ; }
@@ -39,8 +44,29 @@ public static Win32AppInfo Get()
3944 IApplicationResolver appResolver = ( IApplicationResolver ) new CAppResolver ( ) ;
4045 appResolver . GetAppIDForProcess ( Convert . ToUInt32 ( process . Id ) , out string appId , out _ , out _ , out _ ) ;
4146
42- // Use app ID (or hashed app ID) as AUMID
43- string aumid = appId . Length > AUMID_MAX_LENGTH ? HashAppId ( appId ) : appId ;
47+ string aumid ;
48+ string pre7_0_1Aumid = null ;
49+
50+ // If the app ID is too long
51+ if ( appId . Length > AUMID_MAX_LENGTH )
52+ {
53+ // Hash the AUMID
54+ aumid = HashAppId ( appId ) ;
55+ }
56+
57+ // Else if it contains a backslash
58+ else if ( appId . Contains ( '\\ ' ) )
59+ {
60+ // For versions 19042 and older of Windows 10, we can't use backslashes - Issue #3870
61+ // So we change it to not include those
62+ aumid = appId . Replace ( '\\ ' , '/' ) ;
63+ pre7_0_1Aumid = appId ;
64+ }
65+ else
66+ {
67+ // Use as-is
68+ aumid = appId ;
69+ }
4470
4571 // Then try to get the shortcut (for display name and icon)
4672 IShellItem shortcutItem = null ;
@@ -73,11 +99,11 @@ public static Win32AppInfo Get()
7399 if ( IsAlphaBitmap ( bmp , out var bmpData ) )
74100 {
75101 var alphaBitmap = GetAlphaBitmapFromBitmapData ( bmpData ) ;
76- iconPath = SaveIconToAppPath ( alphaBitmap , appId ) ;
102+ iconPath = SaveIconToAppPath ( alphaBitmap , aumid ) ;
77103 }
78104 else
79105 {
80- iconPath = SaveIconToAppPath ( bmp , appId ) ;
106+ iconPath = SaveIconToAppPath ( bmp , aumid ) ;
81107 }
82108 }
83109 catch
@@ -103,12 +129,13 @@ public static Win32AppInfo Get()
103129 if ( string . IsNullOrWhiteSpace ( iconPath ) )
104130 {
105131 // We use the one from the process
106- iconPath = ExtractAndObtainIconFromCurrentProcess ( process , appId ) ;
132+ iconPath = ExtractAndObtainIconFromCurrentProcess ( process , aumid ) ;
107133 }
108134
109135 return new Win32AppInfo ( )
110136 {
111137 Aumid = aumid ,
138+ Pre7_0_1Aumid = pre7_0_1Aumid ,
112139 DisplayName = displayName ,
113140 IconPath = iconPath
114141 } ;
@@ -136,12 +163,12 @@ private static string GetDisplayNameFromCurrentProcess(Process process)
136163 return process . ProcessName ;
137164 }
138165
139- private static string ExtractAndObtainIconFromCurrentProcess ( Process process , string appId )
166+ private static string ExtractAndObtainIconFromCurrentProcess ( Process process , string aumid )
140167 {
141- return ExtractAndObtainIconFromPath ( process . MainModule . FileName , appId ) ;
168+ return ExtractAndObtainIconFromPath ( process . MainModule . FileName , aumid ) ;
142169 }
143170
144- private static string ExtractAndObtainIconFromPath ( string pathToExtract , string appId )
171+ private static string ExtractAndObtainIconFromPath ( string pathToExtract , string aumid )
145172 {
146173 try
147174 {
@@ -150,7 +177,7 @@ private static string ExtractAndObtainIconFromPath(string pathToExtract, string
150177
151178 using ( var bmp = icon . ToBitmap ( ) )
152179 {
153- return SaveIconToAppPath ( bmp , appId ) ;
180+ return SaveIconToAppPath ( bmp , aumid ) ;
154181 }
155182 }
156183 catch
@@ -159,11 +186,11 @@ private static string ExtractAndObtainIconFromPath(string pathToExtract, string
159186 }
160187 }
161188
162- private static string SaveIconToAppPath ( Bitmap bitmap , string appId )
189+ private static string SaveIconToAppPath ( Bitmap bitmap , string aumid )
163190 {
164191 try
165192 {
166- var path = Path . Combine ( GetAppDataFolderPath ( appId ) , "Icon.png" ) ;
193+ var path = Path . Combine ( GetAppDataFolderPath ( aumid ) , "Icon.png" ) ;
167194
168195 // Ensure the directories exist
169196 Directory . CreateDirectory ( Path . GetDirectoryName ( path ) ) ;
@@ -182,9 +209,9 @@ private static string SaveIconToAppPath(Bitmap bitmap, string appId)
182209 /// Gets the app data folder path within the ToastNotificationManagerCompat folder, used for storing icon assets and any additional data.
183210 /// </summary>
184211 /// <returns>Returns a string of the absolute folder path.</returns>
185- public static string GetAppDataFolderPath ( string appId )
212+ public static string GetAppDataFolderPath ( string aumid )
186213 {
187- string conciseAumid = appId . Contains ( " \\ " ) ? GenerateGuid ( appId ) : appId ;
214+ string conciseAumid = aumid . Contains ( ' \\ ' ) || aumid . Contains ( '/' ) ? GenerateGuid ( aumid ) : aumid ;
188215
189216 return Path . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . LocalApplicationData ) , "ToastNotificationManagerCompat" , "Apps" , conciseAumid ) ;
190217 }
0 commit comments