Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
ManifestBasedResourceGroveler.cs
Go to the documentation of this file.
4using System.IO;
6
7namespace System.Resources;
8
10{
12
14 {
15 return ((RuntimeAssembly)mainAssembly).InternalGetSatelliteAssembly(culture, version, throwOnFileNotFound: false);
16 }
17
22
24 {
25 ResourceSet value = null;
26 Stream stream = null;
29 if (cultureInfo.HasInvariantCultureName && _mediator.FallbackLoc == UltimateResourceFallbackLocation.MainAssembly)
30 {
32 }
33 else
34 {
36 if (assembly == null && culture.HasInvariantCultureName && _mediator.FallbackLoc == UltimateResourceFallbackLocation.Satellite)
37 {
39 }
40 }
42 if (assembly != null)
43 {
45 {
47 }
49 }
50 if (createIfNotExists && stream != null && value == null)
51 {
53 }
54 else if (stream == null && tryParents && culture.HasInvariantCultureName)
55 {
57 }
58 return value;
59 }
60
62 {
64 if (lookForCulture.Name == _mediator.NeutralResourcesCulture.Name && _mediator.FallbackLoc == UltimateResourceFallbackLocation.MainAssembly)
65 {
67 }
68 else if (lookForCulture.HasInvariantCultureName && _mediator.FallbackLoc == UltimateResourceFallbackLocation.Satellite)
69 {
70 result = _mediator.NeutralResourcesCulture;
71 }
72 return result;
73 }
74
101
103 {
104 if (store.CanSeek && store.Length > 4)
105 {
106 long position = store.Position;
108 int num = binaryReader.ReadInt32();
109 if (num == ResourceManager.MagicNumber)
110 {
111 int num2 = binaryReader.ReadInt32();
112 string text = null;
113 string text2 = null;
115 {
116 binaryReader.ReadInt32();
117 text = binaryReader.ReadString();
118 text2 = binaryReader.ReadString();
119 }
120 else
121 {
123 {
125 }
126 int num3 = binaryReader.ReadInt32();
127 long offset = binaryReader.BaseStream.Position + num3;
128 text = binaryReader.ReadString();
129 text2 = binaryReader.ReadString();
130 binaryReader.BaseStream.Seek(offset, SeekOrigin.Begin);
131 }
132 store.Position = position;
134 {
136 }
138 {
140 }
142 }
143 store.Position = position;
144 }
145 if (_mediator.UserResourceSet == null)
146 {
148 }
149 object[] args = new object[2] { store, assembly };
150 try
151 {
152 try
153 {
154 return (ResourceSet)Activator.CreateInstance(_mediator.UserResourceSet, args);
155 }
157 {
158 }
159 return (ResourceSet)Activator.CreateInstance(args: new object[1] { store }, type: _mediator.UserResourceSet);
160 }
162 {
163 throw new InvalidOperationException(SR.Format(SR.InvalidOperation_ResMgrBadResSet_Type, _mediator.UserResourceSet.AssemblyQualifiedName), innerException);
164 }
165 }
166
167 [RequiresUnreferencedCode("The CustomResourceTypesSupport feature switch has been enabled for this app which is being trimmed. Custom readers as well as custom objects on the resources file are not observable by the trimmer and so required assemblies, types and members may be removed.")]
169 {
171 if (ResourceManager.IsDefaultType(readerTypeName, "System.Resources.ResourceReader"))
172 {
174 }
175 else
176 {
179 }
180 object[] args = new object[1] { resourceReader };
181 Type type2 = mediator.UserResourceSet;
182 if (type2 == null)
183 {
185 }
186 return (ResourceSet)Activator.CreateInstance(type2, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.CreateInstance, null, args, null, null);
187 }
188
190 {
191 return satellite.GetManifestResourceStream(_mediator.LocationInfo, fileName) ?? CaseInsensitiveManifestResourceStreamLookup(satellite, fileName);
192 }
193
195 {
196 string text = _mediator.LocationInfo?.Namespace;
197 char ptr = Type.Delimiter;
198 string text2 = ((text != null && name != null) ? string.Concat(text, new ReadOnlySpan<char>(ref ptr, 1), name) : (text + name));
199 string text3 = null;
200 string[] manifestResourceNames = satellite.GetManifestResourceNames();
201 foreach (string text4 in manifestResourceNames)
202 {
203 if (string.Equals(text4, text2, StringComparison.InvariantCultureIgnoreCase))
204 {
205 if (text3 != null)
206 {
208 }
209 text3 = text4;
210 }
211 }
212 if (text3 == null)
213 {
214 return null;
215 }
216 return satellite.GetManifestResourceStream(text3);
217 }
218
220 {
221 if (!_mediator.LookedForSatelliteContractVersion)
222 {
224 _mediator.LookedForSatelliteContractVersion = true;
225 }
226 Assembly result = null;
227 try
228 {
230 }
231 catch (FileLoadException)
232 {
233 }
235 {
236 }
237 return result;
238 }
239
241 {
242 if (_mediator.UserResourceSet != null)
243 {
244 return false;
245 }
246 if (readerTypeName != null && !ResourceManager.IsDefaultType(readerTypeName, "System.Resources.ResourceReader"))
247 {
248 return false;
249 }
250 if (resSetTypeName != null && !ResourceManager.IsDefaultType(resSetTypeName, "System.Resources.RuntimeResourceSet"))
251 {
252 return false;
253 }
254 return true;
255 }
256
258 {
260 string p = AssemblyNameFormatter.ComputeDisplayName(name.Name + ".resources.dll", _mediator.SatelliteContractVersion, null, name.GetPublicKeyToken());
261 string text = _mediator.NeutralResourcesCulture.Name;
262 if (text.Length == 0)
263 {
264 text = "<invariant>";
265 }
267 }
268
270 {
271 try
272 {
273 string[] manifestResourceNames = assembly.GetManifestResourceNames();
274 int num = manifestResourceNames.Length;
275 string text = "\"";
276 if (num > 10)
277 {
278 num = 10;
279 text = "\", ...";
280 }
281 return "\"" + string.Join("\", \"", manifestResourceNames, 0, num) + text;
282 }
283 catch
284 {
285 return "\"\"";
286 }
287 }
288
290 {
291 if (_mediator.MainAssembly == typeof(object).Assembly && _mediator.BaseName.Equals("System.Private.CoreLib"))
292 {
293 Environment.FailFast("System.Private.CoreLib.resources couldn't be found! Large parts of the BCL won't work!");
294 }
295 string text = string.Empty;
296 if (_mediator.LocationInfo != null && _mediator.LocationInfo.Namespace != null)
297 {
298 text = _mediator.LocationInfo.Namespace + Type.Delimiter;
299 }
300 text += fileName;
302 }
303}
static ? object CreateInstance([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors|DynamicallyAccessedMemberTypes.NonPublicConstructors)] Type type, BindingFlags bindingAttr, Binder? binder, object?[]? args, CultureInfo? culture)
Definition Activator.cs:17
bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value)
static void FailFast(string? message)
static CultureInfo InvariantCulture
static CultureInfo GetCultureInfo(int culture)
static string ComputeDisplayName(string name, Version version, string cultureName, byte[] pkt, AssemblyNameFlags flags=AssemblyNameFlags.None, AssemblyContentType contentType=AssemblyContentType.Default)
virtual AssemblyName GetName()
Definition Assembly.cs:294
static readonly FastResourceComparer Default
readonly ResourceManager.ResourceManagerMediator _mediator
static CultureInfo GetNeutralResourcesLanguage(Assembly a, out UltimateResourceFallbackLocation fallbackLocation)
ManifestBasedResourceGroveler(ResourceManager.ResourceManagerMediator mediator)
ResourceSet CreateResourceSet(Stream store, Assembly assembly)
CultureInfo UltimateFallbackFixup(CultureInfo lookForCulture)
static Assembly InternalGetSatelliteAssembly(Assembly mainAssembly, CultureInfo culture, Version version)
static ResourceSet InternalGetResourceSetFromSerializedData(Stream store, string readerTypeName, string resSetTypeName, ResourceManager.ResourceManagerMediator mediator)
bool CanUseDefaultResourceClasses(string readerTypeName, string resSetTypeName)
Stream GetManifestResourceStream(Assembly satellite, string fileName)
ResourceSet GrovelForResourceSet(CultureInfo culture, Dictionary< string, ResourceSet > localResourceSets, bool tryParents, bool createIfNotExists)
Stream CaseInsensitiveManifestResourceStreamLookup(Assembly satellite, string name)
virtual string GetResourceFileName(CultureInfo culture)
static bool IsDefaultType(string asmTypeName, string typeName)
static readonly int HeaderVersionNumber
static string Arg_InvalidNeutralResourcesLanguage_FallbackLoc
Definition SR.cs:210
static string Arg_InvalidNeutralResourcesLanguage_Asm_Culture
Definition SR.cs:208
static string NotSupported_ObsoleteResourcesFile
Definition SR.cs:1700
static string MissingManifestResource_NoNeutralAsm
Definition SR.cs:1624
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string MissingManifestResource_MultipleBlobs
Definition SR.cs:1622
static string MissingSatelliteAssembly_Culture_Name
Definition SR.cs:1638
static string InvalidOperation_ResMgrBadResSet_Type
Definition SR.cs:1506
static string ResourceManager_ReflectionNotAllowed
Definition SR.cs:2188
Definition SR.cs:7
static ? Type GetType(string typeName, bool throwOnError, bool ignoreCase)
Definition Type.cs:408
static readonly char Delimiter
Definition Type.cs:17