@@ -263,6 +263,8 @@ public class Application : IProgram
263
263
public string LogoPath { get ; set ; }
264
264
public UWP Package { get ; set ; }
265
265
266
+ public Application ( ) { }
267
+
266
268
private int Score ( string query )
267
269
{
268
270
var displayNameMatch = StringMatcher . FuzzySearch ( query , DisplayName ) ;
@@ -363,73 +365,70 @@ public Application(IAppxManifestApplication manifestApp, UWP package)
363
365
BackgroundColor = manifestApp . GetStringValue ( "BackgroundColor" ) ;
364
366
Package = package ;
365
367
366
- DisplayName = ResourceFromPri ( package . FullName , DisplayName ) ;
367
- Description = ResourceFromPri ( package . FullName , Description ) ;
368
+ DisplayName = ResourceFromPri ( package . FullName , package . Name , DisplayName ) ;
369
+ Description = ResourceFromPri ( package . FullName , package . Name , Description ) ;
368
370
LogoUri = LogoUriFromManifest ( manifestApp ) ;
369
371
LogoPath = LogoPathFromUri ( LogoUri ) ;
370
372
371
373
Enabled = true ;
372
374
}
373
375
374
- internal string ResourceFromPri ( string packageFullName , string resourceReference )
376
+ internal string ResourceFromPri ( string packageFullName , string packageName , string rawReferenceValue )
375
377
{
376
- const string prefix = "ms-resource:" ;
377
- if ( ! string . IsNullOrWhiteSpace ( resourceReference ) && resourceReference . StartsWith ( prefix ) )
378
- {
379
- // magic comes from @talynone
380
- // https://github.com/talynone/Wox.Plugin.WindowsUniversalAppLauncher/blob/master/StoreAppLauncher/Helpers/NativeApiHelper.cs#L139-L153
381
- string key = resourceReference . Substring ( prefix . Length ) ;
382
- string parsed ;
383
- if ( key . StartsWith ( "//" ) )
384
- {
385
- parsed = prefix + key ;
386
- }
387
- else if ( key . StartsWith ( "/" ) )
388
- {
389
- parsed = prefix + "//" + key ;
390
- }
391
- else
392
- {
393
- parsed = prefix + "///resources/" + key ;
394
- }
378
+ if ( string . IsNullOrWhiteSpace ( rawReferenceValue ) || ! rawReferenceValue . StartsWith ( "ms-resource:" ) )
379
+ return rawReferenceValue ;
395
380
396
- var outBuffer = new StringBuilder ( 128 ) ;
397
- string source = $ "@{{{packageFullName}? { parsed } }}";
398
- var capacity = ( uint ) outBuffer . Capacity ;
399
- var hResult = SHLoadIndirectString ( source , outBuffer , capacity , IntPtr . Zero ) ;
400
- if ( hResult == Hresult . Ok )
381
+ var formattedPriReference = FormattedPriReferenceValue ( packageName , rawReferenceValue ) ;
382
+
383
+ var outBuffer = new StringBuilder ( 128 ) ;
384
+ string source = $ "@{{{packageFullName}? { formattedPriReference } }}";
385
+ var capacity = ( uint ) outBuffer . Capacity ;
386
+ var hResult = SHLoadIndirectString ( source , outBuffer , capacity , IntPtr . Zero ) ;
387
+ if ( hResult == Hresult . Ok )
388
+ {
389
+ var loaded = outBuffer . ToString ( ) ;
390
+ if ( ! string . IsNullOrEmpty ( loaded ) )
401
391
{
402
- var loaded = outBuffer . ToString ( ) ;
403
- if ( ! string . IsNullOrEmpty ( loaded ) )
404
- {
405
- return loaded ;
406
- }
407
- else
408
- {
409
- ProgramLogger . LogException ( $ "|UWP|ResourceFromPri|{ Package . Location } |Can't load null or empty result "
410
- + $ "pri { source } in uwp location { Package . Location } ", new NullReferenceException ( ) ) ;
411
- return string . Empty ;
412
- }
392
+ return loaded ;
413
393
}
414
394
else
415
395
{
416
- // https://github.com/Wox-launcher/Wox/issues/964
417
- // known hresult 2147942522:
418
- // 'Microsoft Corporation' violates pattern constraint of '\bms-resource:.{1,256}'.
419
- // for
420
- // Microsoft.MicrosoftOfficeHub_17.7608.23501.0_x64__8wekyb3d8bbwe: ms-resource://Microsoft.MicrosoftOfficeHub/officehubintl/AppManifest_GetOffice_Description
421
- // Microsoft.BingFoodAndDrink_3.0.4.336_x64__8wekyb3d8bbwe: ms-resource:AppDescription
422
- var e = Marshal . GetExceptionForHR ( ( int ) hResult ) ;
423
- ProgramLogger . LogException ( $ "|UWP|ResourceFromPri|{ Package . Location } |Load pri failed { source } with HResult { hResult } and location { Package . Location } ", e ) ;
396
+ ProgramLogger . LogException ( $ "|UWP|ResourceFromPri|{ Package . Location } |Can't load null or empty result "
397
+ + $ "pri { source } in uwp location { Package . Location } ", new NullReferenceException ( ) ) ;
424
398
return string . Empty ;
425
399
}
426
400
}
427
401
else
428
402
{
429
- return resourceReference ;
403
+ var e = Marshal . GetExceptionForHR ( ( int ) hResult ) ;
404
+ ProgramLogger . LogException ( $ "|UWP|ResourceFromPri|{ Package . Location } |Load pri failed { source } with HResult { hResult } and location { Package . Location } ", e ) ;
405
+ return string . Empty ;
430
406
}
431
407
}
432
408
409
+ public string FormattedPriReferenceValue ( string packageName , string rawPriReferenceValue )
410
+ {
411
+ const string prefix = "ms-resource:" ;
412
+
413
+ if ( string . IsNullOrWhiteSpace ( rawPriReferenceValue ) || ! rawPriReferenceValue . StartsWith ( prefix ) )
414
+ return rawPriReferenceValue ;
415
+
416
+ string key = rawPriReferenceValue . Substring ( prefix . Length ) ;
417
+ if ( key . StartsWith ( "//" ) )
418
+ return $ "{ prefix } { key } ";
419
+
420
+ if ( ! key . StartsWith ( "/" ) )
421
+ {
422
+ key = $ "/{ key } ";
423
+ }
424
+
425
+ if ( ! key . ToLower ( ) . Contains ( "resources" ) )
426
+ {
427
+ key = $ "/Resources{ key } ";
428
+ }
429
+
430
+ return $ "{ prefix } //{ packageName } { key } ";
431
+ }
433
432
434
433
internal string LogoUriFromManifest ( IAppxManifestApplication app )
435
434
{
0 commit comments