Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
LicFileLicenseProvider.cs
Go to the documentation of this file.
3using System.IO;
4
6
8{
9 private sealed class LicFileLicense : License
10 {
12
13 public override string LicenseKey { get; }
14
16 {
17 _owner = owner;
19 }
20
21 public override void Dispose()
22 {
23 GC.SuppressFinalize(this);
24 }
25 }
26
27 protected virtual bool IsKeyValid(string? key, Type type)
28 {
29 return key?.StartsWith(GetKey(type)) ?? false;
30 }
31
32 protected virtual string GetKey(Type type)
33 {
34 return type.FullName + " is a licensed component.";
35 }
36
37 [UnconditionalSuppressMessage("SingleFile", "IL3002:RequiresAssemblyFiles", Justification = "Only used for when Location is non-empty")]
38 [UnconditionalSuppressMessage("SingleFile", "IL3000:RequiresAssemblyFiles", Justification = "Location is checked for empty")]
39 public override License? GetLicense(LicenseContext context, Type type, object? instance, bool allowExceptions)
40 {
41 LicFileLicense licFileLicense = null;
42 if (context != null)
43 {
44 if (context.UsageMode == LicenseUsageMode.Runtime)
45 {
46 string savedLicenseKey = context.GetSavedLicenseKey(type, null);
47 if (savedLicenseKey != null && IsKeyValid(savedLicenseKey, type))
48 {
49 licFileLicense = new LicFileLicense(this, savedLicenseKey);
50 }
51 }
52 if (licFileLicense == null)
53 {
54 string text = null;
55 if (context != null)
56 {
58 if (typeResolutionService != null)
59 {
60 text = typeResolutionService.GetPathOfAssembly(type.Assembly.GetName());
61 }
62 }
63 if (type.Assembly.Location.Length != 0)
64 {
65 if (text == null)
66 {
67 text = type.Module.FullyQualifiedName;
68 }
69 string directoryName = Path.GetDirectoryName(text);
70 string path = directoryName + "\\" + type.FullName + ".lic";
71 if (File.Exists(path))
72 {
73 Stream stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read);
74 StreamReader streamReader = new StreamReader(stream);
75 string key = streamReader.ReadLine();
76 streamReader.Close();
77 if (IsKeyValid(key, type))
78 {
79 licFileLicense = new LicFileLicense(this, GetKey(type));
80 }
81 }
82 if (licFileLicense != null)
83 {
84 context.SetSavedLicenseKey(type, licFileLicense.LicenseKey);
85 }
86 }
87 }
88 }
89 return licFileLicense;
90 }
91}
override? License GetLicense(LicenseContext context, Type type, object? instance, bool allowExceptions)
virtual bool IsKeyValid(string? key, Type type)
virtual LicenseUsageMode UsageMode
virtual ? object GetService(Type type)
virtual void SetSavedLicenseKey(Type type, string key)
virtual ? string GetSavedLicenseKey(Type type, Assembly? resourceAssembly)
static void SuppressFinalize(object obj)
Definition GC.cs:202
Definition GC.cs:8
static bool Exists([NotNullWhen(true)] string? path)
Definition File.cs:97
static ? string GetDirectoryName(string? path)
Definition Path.cs:121
override void Close()
override? string ReadLine()