@@ -22,15 +22,18 @@ public sealed class PackerPolicy : ICollection<PackerPolicyItem>
2222 public static PackerPolicy Load ( string namespaceDirPath )
2323 {
2424 var policyFile = Path . Combine ( namespaceDirPath , DefaultFileName ) ;
25- if ( ! File . Exists ( policyFile ) ) return Shared ;
25+ if ( ! File . Exists ( policyFile ) )
26+ return Shared ;
2627 try
2728 {
2829 var json = File . ReadAllText ( policyFile ) ;
2930 Log . Debug ( "策略文件内容: {Json}" , json ) ;
3031 var policies = JsonSerializer . Deserialize < PackerPolicy > (
3132 json , SourceGenerationContext . JsonOptions ) ;
32- if ( policies is null ) { Log . Warning ( "策略反序列化结果为 null: {File}" , policyFile ) ; return Shared ; }
33- if ( policies . _items . Count == 0 ) { Log . Warning ( "策略列表为空: {File}" , policyFile ) ; return Shared ; }
33+ if ( policies is null )
34+ { Log . Warning ( "策略反序列化结果为 null: {File}" , policyFile ) ; return Shared ; }
35+ if ( policies . _items . Count == 0 )
36+ { Log . Warning ( "策略列表为空: {File}" , policyFile ) ; return Shared ; }
3437 Log . Debug ( "成功加载 {Count} 条策略: {File}" , policies . _items . Count , policyFile ) ;
3538 return policies ;
3639 }
@@ -71,7 +74,7 @@ protected IResourceFileProvider CreateProvider(
7174 var json = File . ReadAllText ( filePath ) ;
7275 var entries = new Dictionary < string , string > ( ) ;
7376 foreach ( var prop in JsonDocument . Parse ( json ) . RootElement . EnumerateObject ( ) )
74- if ( prop . Value . ValueKind == System . Text . Json . JsonValueKind . String )
77+ if ( prop . Value . ValueKind == JsonValueKind . String )
7578 entries [ prop . Name ] = prop . Value . GetString ( ) ! ;
7679 return new JsonFile ( entries , relativePath )
7780 {
@@ -81,14 +84,8 @@ protected IResourceFileProvider CreateProvider(
8184
8285 case { parentDir : "lang" , ext : ".lang" } :
8386 var content = File . ReadAllText ( filePath ) ;
84- var entries2 = new Dictionary < string , string > ( ) ;
85- foreach ( var line in content . EnumerateLines ( ) )
86- {
87- var eq = line . IndexOf ( '=' ) ;
88- if ( eq == - 1 ) continue ;
89- entries2 . TryAdd ( line [ ..eq ] . Trim ( ) . ToString ( ) , line [ ( eq + 1 ) ..] . Trim ( ) . ToString ( ) ) ;
90- }
91- return new LangFile ( entries2 , relativePath )
87+ entries = LangFile . DeserializeFromLang ( content ) ;
88+ return new LangFile ( entries , relativePath )
9289 {
9390 Namespace = ns ,
9491 PolicyItem = this
@@ -112,17 +109,20 @@ public override IEnumerable<IResourceFileProvider> CreateProviders(
112109 foreach ( var domainDir in Directory . EnumerateDirectories ( namespaceResource . LocalPath ) )
113110 {
114111 var domainName = Path . GetFileName ( domainDir ) ;
115- if ( config . ExclusionDomains . Contains ( domainName ) ) continue ;
112+ if ( config . ExclusionDomains . Contains ( domainName ) )
113+ continue ;
116114 bool domainForceInclude = config . InclusionDomains . Contains ( domainName ) ;
117115
118116 foreach ( var file in Directory . EnumerateFiles ( domainDir , "*" , SearchOption . AllDirectories ) )
119117 {
120118 var relativePath = Path . GetRelativePath ( namespaceResource . LocalPath , file ) . Replace ( '\\ ' , '/' ) ;
121- if ( config . ExclusionPaths . Contains ( relativePath ) ) continue ;
119+ if ( config . ExclusionPaths . Contains ( relativePath ) )
120+ continue ;
122121 if ( ! domainForceInclude )
123122 {
124123 bool inTargetLang = relativePath . Contains ( "zh_cn" , StringComparison . OrdinalIgnoreCase ) ;
125- if ( ! config . InclusionPaths . Contains ( relativePath ) && ! inTargetLang ) continue ;
124+ if ( ! config . InclusionPaths . Contains ( relativePath ) && ! inTargetLang )
125+ continue ;
126126 }
127127 yield return CreateProvider ( file , relativePath , namespaceResource ) ;
128128 }
@@ -136,7 +136,8 @@ public override IEnumerable<IResourceFileProvider> CreateProviders(
136136 INamespaceResource namespaceResource , FloatingConfig config )
137137 {
138138 var targetDir = new DirectoryInfo ( Source ) ;
139- if ( ! targetDir . Exists ) yield break ;
139+ if ( ! targetDir . Exists )
140+ yield break ;
140141 var targetNs = new AssetsNamespaceResource (
141142 targetDir . FullName , targetDir . Name , targetDir . Parent ? . Name ?? "" , namespaceResource . ModVersion ) ;
142143 foreach ( var policy in targetNs . PackerPolicies )
0 commit comments