Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
ResourceManager.cs
Go to the documentation of this file.
4using System.IO;
6
7namespace System.Resources;
8
9public class ResourceManager
10{
11 internal sealed class CultureNameResourceSetPair
12 {
13 public string lastCultureName;
14
16 }
17
18 internal sealed class ResourceManagerMediator
19 {
20 private readonly ResourceManager _rm;
21
22 internal string ModuleDir => _rm._moduleDir;
23
25
28
29 internal string BaseNameField => _rm.BaseNameField;
30
32
34 {
35 get
36 {
38 }
39 set
40 {
41 _rm._lookedForSatelliteContractVersion = value;
42 }
43 }
44
46 {
47 get
48 {
50 }
51 set
52 {
53 _rm._satelliteContractVersion = value;
54 }
55 }
56
58
60
61 internal string BaseName => _rm.BaseName;
62
64 {
65 if (rm == null)
66 {
67 throw new ArgumentNullException("rm");
68 }
69 _rm = rm;
70 }
71
73 {
75 }
76
81 }
82
83 protected string BaseNameField;
84
86
88
89 private readonly string _moduleDir;
90
91 private readonly Type _locationInfo;
92
94 private readonly Type _userResourceSet;
95
97
99
100 private bool _ignoreCase;
101
102 private bool _useManifest;
103
105
107
109
111
112 public static readonly int MagicNumber = -1091581234;
113
114 public static readonly int HeaderVersionNumber = 1;
115
116 private static readonly Type s_minResourceSet = typeof(ResourceSet);
117
118 public virtual string BaseName => BaseNameField;
119
120 public virtual bool IgnoreCase
121 {
122 get
123 {
124 return _ignoreCase;
125 }
126 set
127 {
129 }
130 }
131
134
136 {
137 get
138 {
139 return _fallbackLoc;
140 }
141 set
142 {
144 }
145 }
146
154
173
175 {
176 if (baseName == null)
177 {
178 throw new ArgumentNullException("baseName");
179 }
180 if (null == assembly)
181 {
182 throw new ArgumentNullException("assembly");
183 }
184 if (!assembly.IsRuntimeImplemented())
185 {
187 }
191 }
192
194 {
195 if (baseName == null)
196 {
197 throw new ArgumentNullException("baseName");
198 }
199 if (null == assembly)
200 {
201 throw new ArgumentNullException("assembly");
202 }
203 if (!assembly.IsRuntimeImplemented())
204 {
206 }
210 {
211 throw new ArgumentException(SR.Arg_ResMgrNotResSet, "usingResourceSet");
212 }
215 }
216
218 {
219 if (null == resourceSource)
220 {
221 throw new ArgumentNullException("resourceSource");
222 }
223 if (!resourceSource.IsRuntimeImplemented())
224 {
226 }
231 }
232
233 [MemberNotNull("_resourceGroveler")]
243
257
262
263 protected virtual string GetResourceFileName(CultureInfo culture)
264 {
265 if (culture.HasInvariantCultureName)
266 {
267 return BaseNameField + ".resources";
268 }
270 return BaseNameField + "." + culture.Name + ".resources";
271 }
272
274 {
276 {
278 }
279 if (_lastUsedResourceCache != null)
280 {
282 {
284 {
286 }
287 }
288 }
290 ResourceSet value = null;
291 if (resourceSets != null)
292 {
294 {
296 }
297 }
298 if (value != null)
299 {
300 if (_lastUsedResourceCache != null)
301 {
303 {
304 _lastUsedResourceCache.lastCultureName = culture.Name;
305 _lastUsedResourceCache.lastResourceSet = value;
306 }
307 }
308 return value;
309 }
310 return null;
311 }
312
343
345 {
347 ResourceSet value = null;
350 {
352 {
353 return value;
354 }
355 }
358 {
360 {
362 {
363 if (culture != item)
364 {
366 }
367 break;
368 }
369 }
371 if (value != null)
372 {
374 break;
375 }
376 }
377 if (value != null && cultureInfo != null)
378 {
380 {
382 if (item2 == cultureInfo)
383 {
384 break;
385 }
386 }
387 }
388 return value;
389 }
390
392 {
394 {
395 if (localResourceSets.TryGetValue(cultureName, out var value))
396 {
397 if (value != rs)
398 {
400 {
401 rs.Dispose();
402 }
403 rs = value;
404 }
405 }
406 else
407 {
408 localResourceSets.Add(cultureName, rs);
409 }
410 }
411 }
412
414 {
415 if (a == null)
416 {
418 }
419 string text = a.GetCustomAttribute<SatelliteContractVersionAttribute>()?.Version;
420 if (text == null)
421 {
422 return null;
423 }
424 if (!Version.TryParse(text, out Version result))
425 {
427 }
428 return result;
429 }
430
436
437 internal static bool IsDefaultType(string asmTypeName, string typeName)
438 {
439 int num = asmTypeName.IndexOf(',');
440 if (((num == -1) ? asmTypeName.Length : num) != typeName.Length)
441 {
442 return false;
443 }
444 if (string.Compare(asmTypeName, 0, typeName, 0, typeName.Length, StringComparison.Ordinal) != 0)
445 {
446 return false;
447 }
448 if (num == -1)
449 {
450 return true;
451 }
452 while (char.IsWhiteSpace(asmTypeName[++num]))
453 {
454 }
456 return string.Equals(assemblyName.Name, "mscorlib", StringComparison.OrdinalIgnoreCase);
457 }
458
459 public virtual string? GetString(string name)
460 {
461 return GetString(name, null);
462 }
463
464 public virtual string? GetString(string name, CultureInfo? culture)
465 {
466 if (name == null)
467 {
468 throw new ArgumentNullException("name");
469 }
470 if (culture == null)
471 {
473 }
475 if (resourceSet != null)
476 {
477 string @string = resourceSet.GetString(name, _ignoreCase);
478 if (@string != null)
479 {
480 return @string;
481 }
482 }
485 {
487 if (resourceSet2 == null)
488 {
489 break;
490 }
492 {
493 continue;
494 }
495 string string2 = resourceSet2.GetString(name, _ignoreCase);
496 if (string2 != null)
497 {
498 if (_lastUsedResourceCache != null)
499 {
501 {
502 _lastUsedResourceCache.lastCultureName = item.Name;
503 _lastUsedResourceCache.lastResourceSet = resourceSet2;
504 }
505 }
506 return string2;
507 }
509 }
510 return null;
511 }
512
513 public virtual object? GetObject(string name)
514 {
515 return GetObject(name, null, wrapUnmanagedMemStream: true);
516 }
517
518 public virtual object? GetObject(string name, CultureInfo? culture)
519 {
520 return GetObject(name, culture, wrapUnmanagedMemStream: true);
521 }
522
523 private object GetObject(string name, CultureInfo culture, bool wrapUnmanagedMemStream)
524 {
525 if (name == null)
526 {
527 throw new ArgumentNullException("name");
528 }
529 if (culture == null)
530 {
532 }
534 if (resourceSet != null)
535 {
536 object @object = resourceSet.GetObject(name, _ignoreCase);
537 if (@object != null)
538 {
541 {
543 }
544 return @object;
545 }
546 }
549 {
551 if (resourceSet2 == null)
552 {
553 break;
554 }
556 {
557 continue;
558 }
559 object object2 = resourceSet2.GetObject(name, _ignoreCase);
560 if (object2 != null)
561 {
562 if (_lastUsedResourceCache != null)
563 {
565 {
566 _lastUsedResourceCache.lastCultureName = item.Name;
567 _lastUsedResourceCache.lastResourceSet = resourceSet2;
568 }
569 }
572 {
574 }
575 return object2;
576 }
578 }
579 return null;
580 }
581
582 public UnmanagedMemoryStream? GetStream(string name)
583 {
584 return GetStream(name, null);
585 }
586
588 {
589 object @object = GetObject(name, culture, wrapUnmanagedMemStream: false);
591 if (unmanagedMemoryStream == null && @object != null)
592 {
594 }
596 }
597}
bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value)
void Add(TKey key, TValue value)
static bool VerifyCultureName(string cultureName, bool throwException)
static CultureInfo CurrentUICulture
static CultureInfo InvariantCulture
virtual ? Stream GetManifestResourceStream(string name)
Definition Assembly.cs:284
static CultureInfo GetNeutralResourcesLanguage(Assembly a, out UltimateResourceFallbackLocation fallbackLocation)
UltimateResourceFallbackLocation _fallbackLoc
ResourceManager(string baseName, string resourceDir, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors|DynamicallyAccessedMemberTypes.NonPublicConstructors)] Type userResourceSet)
virtual ? object GetObject(string name)
ResourceManager(Type resourceSource)
object GetObject(string name, CultureInfo culture, bool wrapUnmanagedMemStream)
virtual ? object GetObject(string name, CultureInfo? culture)
virtual ? ResourceSet InternalGetResourceSet(CultureInfo culture, bool createIfNotExists, bool tryParents)
static void AddResourceSet(Dictionary< string, ResourceSet > localResourceSets, string cultureName, ref ResourceSet rs)
virtual ? string GetString(string name, CultureInfo? culture)
UnmanagedMemoryStream? GetStream(string name)
static CultureInfo GetNeutralResourcesLanguage(Assembly a)
static readonly Type s_minResourceSet
static ResourceManager CreateFileBasedResourceManager(string baseName, string resourceDir, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors|DynamicallyAccessedMemberTypes.NonPublicConstructors)] Type? usingResourceSet)
virtual ? ResourceSet GetResourceSet(CultureInfo culture, bool createIfNotExists, bool tryParents)
virtual string GetResourceFileName(CultureInfo culture)
CultureNameResourceSetPair _lastUsedResourceCache
static bool IsDefaultType(string asmTypeName, string typeName)
ResourceManager(string baseName, Assembly assembly)
static readonly int HeaderVersionNumber
UltimateResourceFallbackLocation FallbackLocation
ResourceSet GetFirstResourceSet(CultureInfo culture)
UnmanagedMemoryStream? GetStream(string name, CultureInfo? culture)
static ? Version GetSatelliteContractVersion(Assembly a)
ResourceManager(string baseName, Assembly assembly, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors|DynamicallyAccessedMemberTypes.NonPublicConstructors)] Type? usingResourceSet)
Dictionary< string, ResourceSet > _resourceSets
virtual ? string GetString(string name)
static string Argument_MustBeRuntimeAssembly
Definition SR.cs:774
static string Arg_ResMgrNotResSet
Definition SR.cs:394
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string ArgumentNull_Assembly
Definition SR.cs:936
static string InvalidOperation_ResourceNotStream_Name
Definition SR.cs:1508
static string Arg_InvalidSatelliteContract_Asm_Ver
Definition SR.cs:212
static string Argument_MustBeRuntimeType
Definition SR.cs:782
Definition SR.cs:7
Assembly Assembly
Definition Type.cs:49
static bool TryParse([NotNullWhen(true)] string? input, [NotNullWhen(true)] out Version? result)
Definition Version.cs:324
ResourceSet GrovelForResourceSet(CultureInfo culture, Dictionary< string, ResourceSet > localResourceSets, bool tryParents, bool createIfNotExists)