@@ -27,6 +27,11 @@ internal class Win32AppInfo
27
27
28
28
public string Aumid { get ; set ; }
29
29
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
+
30
35
public string DisplayName { get ; set ; }
31
36
32
37
public string IconPath { get ; set ; }
@@ -39,8 +44,29 @@ public static Win32AppInfo Get()
39
44
IApplicationResolver appResolver = ( IApplicationResolver ) new CAppResolver ( ) ;
40
45
appResolver . GetAppIDForProcess ( Convert . ToUInt32 ( process . Id ) , out string appId , out _ , out _ , out _ ) ;
41
46
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
+ }
44
70
45
71
// Then try to get the shortcut (for display name and icon)
46
72
IShellItem shortcutItem = null ;
@@ -73,11 +99,11 @@ public static Win32AppInfo Get()
73
99
if ( IsAlphaBitmap ( bmp , out var bmpData ) )
74
100
{
75
101
var alphaBitmap = GetAlphaBitmapFromBitmapData ( bmpData ) ;
76
- iconPath = SaveIconToAppPath ( alphaBitmap , appId ) ;
102
+ iconPath = SaveIconToAppPath ( alphaBitmap , aumid ) ;
77
103
}
78
104
else
79
105
{
80
- iconPath = SaveIconToAppPath ( bmp , appId ) ;
106
+ iconPath = SaveIconToAppPath ( bmp , aumid ) ;
81
107
}
82
108
}
83
109
catch
@@ -103,12 +129,13 @@ public static Win32AppInfo Get()
103
129
if ( string . IsNullOrWhiteSpace ( iconPath ) )
104
130
{
105
131
// We use the one from the process
106
- iconPath = ExtractAndObtainIconFromCurrentProcess ( process , appId ) ;
132
+ iconPath = ExtractAndObtainIconFromCurrentProcess ( process , aumid ) ;
107
133
}
108
134
109
135
return new Win32AppInfo ( )
110
136
{
111
137
Aumid = aumid ,
138
+ Pre7_0_1Aumid = pre7_0_1Aumid ,
112
139
DisplayName = displayName ,
113
140
IconPath = iconPath
114
141
} ;
@@ -136,12 +163,12 @@ private static string GetDisplayNameFromCurrentProcess(Process process)
136
163
return process . ProcessName ;
137
164
}
138
165
139
- private static string ExtractAndObtainIconFromCurrentProcess ( Process process , string appId )
166
+ private static string ExtractAndObtainIconFromCurrentProcess ( Process process , string aumid )
140
167
{
141
- return ExtractAndObtainIconFromPath ( process . MainModule . FileName , appId ) ;
168
+ return ExtractAndObtainIconFromPath ( process . MainModule . FileName , aumid ) ;
142
169
}
143
170
144
- private static string ExtractAndObtainIconFromPath ( string pathToExtract , string appId )
171
+ private static string ExtractAndObtainIconFromPath ( string pathToExtract , string aumid )
145
172
{
146
173
try
147
174
{
@@ -150,7 +177,7 @@ private static string ExtractAndObtainIconFromPath(string pathToExtract, string
150
177
151
178
using ( var bmp = icon . ToBitmap ( ) )
152
179
{
153
- return SaveIconToAppPath ( bmp , appId ) ;
180
+ return SaveIconToAppPath ( bmp , aumid ) ;
154
181
}
155
182
}
156
183
catch
@@ -159,11 +186,11 @@ private static string ExtractAndObtainIconFromPath(string pathToExtract, string
159
186
}
160
187
}
161
188
162
- private static string SaveIconToAppPath ( Bitmap bitmap , string appId )
189
+ private static string SaveIconToAppPath ( Bitmap bitmap , string aumid )
163
190
{
164
191
try
165
192
{
166
- var path = Path . Combine ( GetAppDataFolderPath ( appId ) , "Icon.png" ) ;
193
+ var path = Path . Combine ( GetAppDataFolderPath ( aumid ) , "Icon.png" ) ;
167
194
168
195
// Ensure the directories exist
169
196
Directory . CreateDirectory ( Path . GetDirectoryName ( path ) ) ;
@@ -182,9 +209,9 @@ private static string SaveIconToAppPath(Bitmap bitmap, string appId)
182
209
/// Gets the app data folder path within the ToastNotificationManagerCompat folder, used for storing icon assets and any additional data.
183
210
/// </summary>
184
211
/// <returns>Returns a string of the absolute folder path.</returns>
185
- public static string GetAppDataFolderPath ( string appId )
212
+ public static string GetAppDataFolderPath ( string aumid )
186
213
{
187
- string conciseAumid = appId . Contains ( " \\ " ) ? GenerateGuid ( appId ) : appId ;
214
+ string conciseAumid = aumid . Contains ( ' \\ ' ) || aumid . Contains ( '/' ) ? GenerateGuid ( aumid ) : aumid ;
188
215
189
216
return Path . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . LocalApplicationData ) , "ToastNotificationManagerCompat" , "Apps" , conciseAumid ) ;
190
217
}
0 commit comments