11using Microsoft . Windows . ApplicationModel . Resources ;
22using System ;
33using System . Collections . Generic ;
4- using System . Diagnostics . CodeAnalysis ;
54using System . Linq ;
6- using System . Text ;
7- using System . Threading . Tasks ;
85
96namespace WinUI3Localizer ;
7+
108internal class PriResourceReader
119{
1210 private readonly ResourceManager resourceManager ;
@@ -18,29 +16,30 @@ internal PriResourceReader(ResourceManager resourceManager)
1816
1917 public IEnumerable < LanguageDictionary . Item > GetItems ( string language , string subTreeName = "Resources" )
2018 {
21- if ( string . IsNullOrEmpty ( subTreeName ) || subTreeName == "/" )
19+ if ( string . IsNullOrEmpty ( subTreeName ) is true ||
20+ subTreeName == "/" )
2221 {
2322 subTreeName = "Resources" ;
2423 }
25- else if ( subTreeName . EndsWith ( '/' ) )
24+ else if ( subTreeName . EndsWith ( '/' ) is true )
2625 {
2726 subTreeName = subTreeName [ ..^ 1 ] ;
2827 }
2928
3029 ResourceMap resourceMap = this . resourceManager . MainResourceMap . TryGetSubtree ( subTreeName ) ;
31- if ( resourceMap != null )
30+
31+ if ( resourceMap is not null )
3232 {
3333 ResourceContext resourceContext = this . resourceManager . CreateResourceContext ( ) ;
3434 resourceContext . QualifierValues [ KnownResourceQualifierName . Language ] = language ;
3535
36- return GetItemsCore ( resourceMap , subTreeName , resourceContext ) ;
36+ return PriResourceReader . GetItemsCore ( resourceMap , subTreeName , resourceContext ) ;
3737 }
3838
3939 return Enumerable . Empty < LanguageDictionary . Item > ( ) ;
4040 }
4141
42-
43- private IEnumerable < LanguageDictionary . Item > GetItemsCore ( ResourceMap resourceMap , string subTreeName , ResourceContext resourceContext )
42+ private static IEnumerable < LanguageDictionary . Item > GetItemsCore ( ResourceMap resourceMap , string subTreeName , ResourceContext resourceContext )
4443 {
4544 bool isResourcesSubTree = string . Equals ( subTreeName , "Resources" , StringComparison . OrdinalIgnoreCase ) ;
4645 uint count = resourceMap . ResourceCount ;
@@ -49,49 +48,18 @@ internal PriResourceReader(ResourceManager resourceManager)
4948 {
5049 ( string key , ResourceCandidate ? candidate ) = resourceMap . GetValueByIndex ( i , resourceContext ) ;
5150
52- if ( candidate != null && candidate . Kind == ResourceCandidateKind . String )
51+ if ( candidate is not null &&
52+ candidate . Kind is ResourceCandidateKind . String )
5353 {
5454 key = key . Replace ( '/' , '.' ) ;
55+
5556 if ( ! isResourcesSubTree )
5657 {
5758 key = $ "/{ subTreeName } /{ key } ";
5859 }
59- yield return LocalizerBuilder . CreateLanguageDictionaryItem ( key , candidate . ValueAsString ) ;
60- }
61- }
62- }
63-
64- }
65-
66- internal class PriResourceReaderFactory
67- {
68- private readonly Dictionary < string , PriResourceReader > readers = new Dictionary < string , PriResourceReader > ( ) ;
6960
70- internal PriResourceReader GetPriResourceReader ( string ? priFile )
71- {
72- string ? normalizedFilePath = string . Empty ;
73-
74- if ( ! string . IsNullOrEmpty ( priFile ) )
75- {
76- normalizedFilePath = System . IO . Path . GetFullPath ( priFile ) ;
77- }
78-
79- if ( ! this . readers . TryGetValue ( normalizedFilePath , out PriResourceReader ? reader ) )
80- {
81- ResourceManager manager ;
82- if ( string . IsNullOrEmpty ( normalizedFilePath ) )
83- {
84- manager = new ResourceManager ( ) ;
85- }
86- else
87- {
88- manager = new ResourceManager ( normalizedFilePath ) ;
61+ yield return LocalizerBuilder . CreateLanguageDictionaryItem ( key , candidate . ValueAsString ) ;
8962 }
90- reader = new PriResourceReader ( manager ) ;
91- this . readers [ normalizedFilePath ] = reader ;
9263 }
93-
94- return reader ;
9564 }
9665}
97-
0 commit comments