Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
VersioningHelper.cs
Go to the documentation of this file.
1using System.Text;
2
4
5public static class VersioningHelper
6{
7 public static string MakeVersionSafeName(string? name, ResourceScope from, ResourceScope to)
8 {
9 return MakeVersionSafeName(name, from, to, null);
10 }
11
12 public static string MakeVersionSafeName(string? name, ResourceScope from, ResourceScope to, Type? type)
13 {
14 ResourceScope resourceScope = from & (ResourceScope.Machine | ResourceScope.Process | ResourceScope.AppDomain | ResourceScope.Library);
15 ResourceScope resourceScope2 = to & (ResourceScope.Machine | ResourceScope.Process | ResourceScope.AppDomain | ResourceScope.Library);
16 if (resourceScope > resourceScope2)
17 {
18 throw new ArgumentException(SR.Format(SR.Argument_ResourceScopeWrongDirection, resourceScope, resourceScope2), "from");
19 }
20 SxSRequirements requirements = GetRequirements(to, from);
21 if ((requirements & (SxSRequirements.AssemblyName | SxSRequirements.TypeName)) != 0 && type == null)
22 {
24 }
25 StringBuilder stringBuilder = new StringBuilder(name);
26 char value = '_';
27 if ((requirements & SxSRequirements.ProcessID) != 0)
28 {
29 stringBuilder.Append(value);
30 stringBuilder.Append('p');
31 stringBuilder.Append(Environment.ProcessId);
32 }
33 if ((requirements & SxSRequirements.CLRInstanceID) != 0)
34 {
35 string cLRInstanceString = GetCLRInstanceString();
36 stringBuilder.Append(value);
37 stringBuilder.Append('r');
38 stringBuilder.Append(cLRInstanceString);
39 }
40 if ((requirements & SxSRequirements.AppDomainID) != 0)
41 {
42 stringBuilder.Append(value);
43 stringBuilder.Append("ad");
44 stringBuilder.Append(AppDomain.CurrentDomain.Id);
45 }
46 if ((requirements & SxSRequirements.TypeName) != 0)
47 {
48 stringBuilder.Append(value);
49 stringBuilder.Append(type.Name);
50 }
51 if ((requirements & SxSRequirements.AssemblyName) != 0)
52 {
53 stringBuilder.Append(value);
54 stringBuilder.Append(type.Assembly.FullName);
55 }
56 return stringBuilder.ToString();
57 }
58
59 private static string GetCLRInstanceString()
60 {
61 return "3";
62 }
63
64 private static SxSRequirements GetRequirements(ResourceScope consumeAsScope, ResourceScope calleeScope)
65 {
66 SxSRequirements sxSRequirements = SxSRequirements.None;
67 switch (calleeScope & (ResourceScope.Machine | ResourceScope.Process | ResourceScope.AppDomain | ResourceScope.Library))
68 {
69 case ResourceScope.Machine:
70 switch (consumeAsScope & (ResourceScope.Machine | ResourceScope.Process | ResourceScope.AppDomain | ResourceScope.Library))
71 {
72 case ResourceScope.Process:
73 sxSRequirements |= SxSRequirements.ProcessID;
74 break;
75 case ResourceScope.AppDomain:
76 sxSRequirements |= SxSRequirements.AppDomainID | SxSRequirements.ProcessID | SxSRequirements.CLRInstanceID;
77 break;
78 default:
79 throw new ArgumentException(SR.Format(SR.Argument_BadResourceScopeTypeBits, consumeAsScope), "consumeAsScope");
80 case ResourceScope.Machine:
81 break;
82 }
83 break;
84 case ResourceScope.Process:
85 if ((consumeAsScope & ResourceScope.AppDomain) != 0)
86 {
87 sxSRequirements |= SxSRequirements.AppDomainID | SxSRequirements.CLRInstanceID;
88 }
89 break;
90 default:
91 throw new ArgumentException(SR.Format(SR.Argument_BadResourceScopeTypeBits, calleeScope), "calleeScope");
92 case ResourceScope.AppDomain:
93 break;
94 }
95 switch (calleeScope & (ResourceScope.Private | ResourceScope.Assembly))
96 {
97 case ResourceScope.None:
98 switch (consumeAsScope & (ResourceScope.Private | ResourceScope.Assembly))
99 {
100 case ResourceScope.Assembly:
101 sxSRequirements |= SxSRequirements.AssemblyName;
102 break;
103 case ResourceScope.Private:
104 sxSRequirements |= SxSRequirements.AssemblyName | SxSRequirements.TypeName;
105 break;
106 default:
107 throw new ArgumentException(SR.Format(SR.Argument_BadResourceScopeVisibilityBits, consumeAsScope), "consumeAsScope");
108 case ResourceScope.None:
109 break;
110 }
111 break;
112 case ResourceScope.Assembly:
113 if ((consumeAsScope & ResourceScope.Private) != 0)
114 {
115 sxSRequirements |= SxSRequirements.TypeName;
116 }
117 break;
118 default:
119 throw new ArgumentException(SR.Format(SR.Argument_BadResourceScopeVisibilityBits, calleeScope), "calleeScope");
120 case ResourceScope.Private:
121 break;
122 }
123 return sxSRequirements;
124 }
125}
static AppDomain CurrentDomain
Definition AppDomain.cs:28
static int ProcessId
static string MakeVersionSafeName(string? name, ResourceScope from, ResourceScope to, Type? type)
static SxSRequirements GetRequirements(ResourceScope consumeAsScope, ResourceScope calleeScope)
static string MakeVersionSafeName(string? name, ResourceScope from, ResourceScope to)
static string Argument_ResourceScopeWrongDirection
Definition SR.cs:2140
static string ArgumentNull_TypeRequiredByResourceScope
Definition SR.cs:2142
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string Argument_BadResourceScopeTypeBits
Definition SR.cs:2144
static string Argument_BadResourceScopeVisibilityBits
Definition SR.cs:2146
Definition SR.cs:7
override string ToString()
StringBuilder Append(char value, int repeatCount)