Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
RuntimeLicenseContext.cs
Go to the documentation of this file.
4using System.IO;
6
8
9internal sealed class RuntimeLicenseContext : LicenseContext
10{
12
13 [UnconditionalSuppressMessage("SingleFile", "IL3000: Avoid accessing Assembly file path when publishing as a single file", Justification = "Suppressing the warning until gets fixed, see https://github.com/dotnet/runtime/issues/50821")]
14 public override string GetSavedLicenseKey(Type type, Assembly resourceAssembly)
15 {
16 if (_savedLicenseKeys == null || _savedLicenseKeys[type.AssemblyQualifiedName] == null)
17 {
18 if (_savedLicenseKeys == null)
19 {
21 }
22 if (resourceAssembly == null)
23 {
24 resourceAssembly = Assembly.GetEntryAssembly();
25 }
26 if (resourceAssembly == null)
27 {
28 Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
29 foreach (Assembly assembly in assemblies)
30 {
31 string location = assembly.Location;
32 if (!(location == string.Empty))
33 {
34 string name = new FileInfo(location).Name;
35 Stream stream = assembly.GetManifestResourceStream(name + ".licenses");
36 if (stream == null)
37 {
38 stream = CaseInsensitiveManifestResourceStreamLookup(assembly, name + ".licenses");
39 }
40 if (stream != null)
41 {
42 DesigntimeLicenseContextSerializer.Deserialize(stream, name.ToUpperInvariant(), this);
43 break;
44 }
45 }
46 }
47 }
48 else
49 {
50 string location2 = resourceAssembly.Location;
51 if (location2 != string.Empty)
52 {
53 string fileName = Path.GetFileName(location2);
54 string text = fileName + ".licenses";
55 Stream manifestResourceStream = resourceAssembly.GetManifestResourceStream(text);
56 if (manifestResourceStream == null)
57 {
58 string text2 = null;
59 CompareInfo compareInfo = CultureInfo.InvariantCulture.CompareInfo;
60 string name2 = resourceAssembly.GetName().Name;
61 string[] manifestResourceNames = resourceAssembly.GetManifestResourceNames();
62 foreach (string text3 in manifestResourceNames)
63 {
64 if (compareInfo.Compare(text3, text, CompareOptions.IgnoreCase) == 0 || compareInfo.Compare(text3, name2 + ".exe.licenses", CompareOptions.IgnoreCase) == 0 || compareInfo.Compare(text3, name2 + ".dll.licenses", CompareOptions.IgnoreCase) == 0)
65 {
66 text2 = text3;
67 break;
68 }
69 }
70 if (text2 != null)
71 {
72 manifestResourceStream = resourceAssembly.GetManifestResourceStream(text2);
73 }
74 }
75 if (manifestResourceStream != null)
76 {
77 DesigntimeLicenseContextSerializer.Deserialize(manifestResourceStream, fileName.ToUpperInvariant(), this);
78 }
79 }
80 }
81 }
82 return (string)_savedLicenseKeys[type.AssemblyQualifiedName];
83 }
84
86 {
87 CompareInfo compareInfo = CultureInfo.InvariantCulture.CompareInfo;
88 string name2 = satellite.GetName().Name;
89 string[] manifestResourceNames = satellite.GetManifestResourceNames();
90 foreach (string text in manifestResourceNames)
91 {
92 if (compareInfo.Compare(text, name, CompareOptions.IgnoreCase) == 0 || compareInfo.Compare(text, name2 + ".exe.licenses") == 0 || compareInfo.Compare(text, name2 + ".dll.licenses") == 0)
93 {
94 name = text;
95 break;
96 }
97 }
98 return satellite.GetManifestResourceStream(name);
99 }
100}
static AppDomain CurrentDomain
Definition AppDomain.cs:28
static void Deserialize(Stream o, string cryptoKey, RuntimeLicenseContext context)
override string GetSavedLicenseKey(Type type, Assembly resourceAssembly)
Stream CaseInsensitiveManifestResourceStreamLookup(Assembly satellite, string name)
static CultureInfo InvariantCulture
static ? string GetFileName(string? path)
Definition Path.cs:200
virtual AssemblyName GetName()
Definition Assembly.cs:294
virtual ? Stream GetManifestResourceStream(string name)
Definition Assembly.cs:284
static ? Assembly GetEntryAssembly()
Definition Assembly.cs:486
virtual string[] GetManifestResourceNames()
Definition Assembly.cs:279
virtual string Location
Definition Assembly.cs:92