@@ -603,109 +603,112 @@ internal string LogoPathFromUri(string uri)
603
603
604
604
string path = Path . Combine ( Package . Location , uri ) ;
605
605
606
- // TODO: NOT sure why we needed this? Maybe for Windows 8?
607
- //if (uri.Contains("\\"))
608
- //{
609
- // path = Path.Combine(Package.Location, uri);
610
- //}
611
- //else
612
- //{
613
- // // for C:\Windows\MiracastView etc
614
- // path = Path.Combine(Package.Location, "Assets", uri);
615
- //}
616
-
617
- var extension = Path . GetExtension ( path ) ;
618
- if ( extension != null )
619
- {
620
- if ( File . Exists ( path ) )
621
- {
622
- return path ; // shortcut, avoid enumerating files
623
- }
606
+ var logoPath = TryToFindLogo ( uri , path ) ;
607
+ if ( String . IsNullOrEmpty ( logoPath ) )
608
+ {
609
+ // TODO: Don't know why, just keep it at the moment
610
+ // Maybe on older version of Windows 10?
611
+ // for C:\Windows\MiracastView etc
612
+ return TryToFindLogo ( uri , Path . Combine ( Package . Location , "Assets" , uri ) ) ;
613
+ }
614
+ return logoPath ;
624
615
625
- var logoNamePrefix = Path . GetFileNameWithoutExtension ( uri ) ; // e.g Square44x44
626
- var logoDir = Path . GetDirectoryName ( path ) ; // e.g ..\..\Assets
627
- if ( String . IsNullOrEmpty ( logoNamePrefix ) || String . IsNullOrEmpty ( logoDir ) || ! Directory . Exists ( logoDir ) )
616
+ string TryToFindLogo ( string uri , string path )
617
+ {
618
+ var extension = Path . GetExtension ( path ) ;
619
+ if ( extension != null )
628
620
{
629
- // Known issue: Edge always triggers it since logo is not at uri
630
- ProgramLogger . LogException ( $ "|UWP|LogoPathFromUri|{ Package . Location } " +
631
- $ "|{ UserModelId } can't find logo uri for { uri } in package location (logo name or directory not found): { Package . Location } ", new FileNotFoundException ( ) ) ;
632
- return string . Empty ;
633
- }
621
+ if ( File . Exists ( path ) )
622
+ {
623
+ return path ; // shortcut, avoid enumerating files
624
+ }
634
625
635
- var files = Directory . EnumerateFiles ( logoDir ) ;
636
-
637
- // Just ignore all qulifiers
638
- // select like logo[xxx].png
639
- // https://learn.microsoft.com/en-us/windows/uwp/app-resources/tailor-resources-lang-scale-contrast
640
- var selected = files . FirstOrDefault ( file =>
641
- Path . GetFileName ( file ) . StartsWith ( logoNamePrefix ) && extension == Path . GetExtension ( file )
642
- ) ;
643
-
644
- //var scaleFactors = new Dictionary<PackageVersion, List<int>>
645
- //{
646
- // // scale factors on win10: https://docs.microsoft.com/en-us/windows/uwp/controls-and-patterns/tiles-and-notifications-app-assets#asset-size-tables,
647
- // {
648
- // PackageVersion.Windows10, new List<int>
649
- // {
650
- // 100,
651
- // 125,
652
- // 150,
653
- // 200,
654
- // 400
655
- // }
656
- // },
657
- // {
658
- // PackageVersion.Windows81, new List<int>
659
- // {
660
- // 100,
661
- // 120,
662
- // 140,
663
- // 160,
664
- // 180
665
- // }
666
- // },
667
- // {
668
- // PackageVersion.Windows8, new List<int>
669
- // {
670
- // 100
671
- // }
672
- // }
673
- //};
674
-
675
- //if (scaleFactors.ContainsKey(Package.Version))
676
- //{
677
- // foreach (var factor in scaleFactors[Package.Version])
678
- // {
679
- // // https://learn.microsoft.com/en-us/windows/uwp/app-resources/tailor-resources-lang-scale-contrast
680
- // suffixes.Add($"scale-{factor}{extension}"); // MS don't require scale as the last
681
- // }
682
- //}
683
-
684
- if ( ! string . IsNullOrEmpty ( selected ) )
685
- {
686
- return selected ;
626
+ var logoNamePrefix = Path . GetFileNameWithoutExtension ( uri ) ; // e.g Square44x44
627
+ var logoDir = Path . GetDirectoryName ( path ) ; // e.g ..\..\Assets
628
+ if ( String . IsNullOrEmpty ( logoNamePrefix ) || String . IsNullOrEmpty ( logoDir ) || ! Directory . Exists ( logoDir ) )
629
+ {
630
+ // Known issue: Edge always triggers it since logo is not at uri
631
+ ProgramLogger . LogException ( $ "|UWP|LogoPathFromUri|{ Package . Location } " +
632
+ $ "|{ UserModelId } can't find logo uri for { uri } in package location (logo name or directory not found): { Package . Location } ", new FileNotFoundException ( ) ) ;
633
+ return string . Empty ;
634
+ }
635
+
636
+ var files = Directory . EnumerateFiles ( logoDir ) ;
637
+
638
+ // Currently we don't care which one to choose
639
+ // Just ignore all qualifiers
640
+ // select like logo.[xxx_yyy].png
641
+ // https://learn.microsoft.com/en-us/windows/uwp/app-resources/tailor-resources-lang-scale-contrast
642
+ var selected = files . FirstOrDefault ( file =>
643
+ Path . GetFileName ( file ) . StartsWith ( logoNamePrefix ) && extension == Path . GetExtension ( file )
644
+ ) ;
645
+
646
+ //var scaleFactors = new Dictionary<PackageVersion, List<int>>
647
+ //{
648
+ // // scale factors on win10: https://docs.microsoft.com/en-us/windows/uwp/controls-and-patterns/tiles-and-notifications-app-assets#asset-size-tables,
649
+ // {
650
+ // PackageVersion.Windows10, new List<int>
651
+ // {
652
+ // 100,
653
+ // 125,
654
+ // 150,
655
+ // 200,
656
+ // 400
657
+ // }
658
+ // },
659
+ // {
660
+ // PackageVersion.Windows81, new List<int>
661
+ // {
662
+ // 100,
663
+ // 120,
664
+ // 140,
665
+ // 160,
666
+ // 180
667
+ // }
668
+ // },
669
+ // {
670
+ // PackageVersion.Windows8, new List<int>
671
+ // {
672
+ // 100
673
+ // }
674
+ // }
675
+ //};
676
+
677
+ //if (scaleFactors.ContainsKey(Package.Version))
678
+ //{
679
+ // foreach (var factor in scaleFactors[Package.Version])
680
+ // {
681
+ // // https://learn.microsoft.com/en-us/windows/uwp/app-resources/tailor-resources-lang-scale-contrast
682
+ // suffixes.Add($"scale-{factor}{extension}"); // MS don't require scale as the last
683
+ // }
684
+ //}
685
+
686
+ if ( ! string . IsNullOrEmpty ( selected ) )
687
+ {
688
+ return selected ;
689
+ }
690
+ else
691
+ {
692
+ ProgramLogger . LogException ( $ "|UWP|LogoPathFromUri|{ Package . Location } " +
693
+ $ "|{ UserModelId } can't find logo uri for { uri } in package location (can't find specified logo): { Package . Location } ", new FileNotFoundException ( ) ) ;
694
+ return string . Empty ;
695
+ }
687
696
}
688
697
else
689
698
{
690
699
ProgramLogger . LogException ( $ "|UWP|LogoPathFromUri|{ Package . Location } " +
691
- $ "|{ UserModelId } can't find logo uri for { uri } in package location (can't find specified logo): { Package . Location } ", new FileNotFoundException ( ) ) ;
700
+ $ "|Unable to find extension from { uri } for { UserModelId } " +
701
+ $ "in package location { Package . Location } ", new FileNotFoundException ( ) ) ;
692
702
return string . Empty ;
693
703
}
694
704
}
695
- else
696
- {
697
- ProgramLogger . LogException ( $ "|UWP|LogoPathFromUri|{ Package . Location } " +
698
- $ "|Unable to find extension from { uri } for { UserModelId } " +
699
- $ "in package location { Package . Location } ", new FileNotFoundException ( ) ) ;
700
- return string . Empty ;
701
- }
702
705
}
703
706
704
707
705
708
public ImageSource Logo ( )
706
709
{
707
710
var logo = ImageFromPath ( LogoPath ) ;
708
- var plated = PlatedImage ( logo ) ;
711
+ var plated = PlatedImage ( logo ) ; // TODO: maybe get plated directly from app package?
709
712
710
713
// todo magic! temp fix for cross thread object
711
714
plated . Freeze ( ) ;
0 commit comments