Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
VersionConverter.cs
浏览该文件的文档.
1using System.Xml.Linq;
2using Engine;
3using XmlUtilities;
4
5namespace Game {
6 public abstract class VersionConverter {
7 public abstract string SourceVersion { get; }
8
9 public abstract string TargetVersion { get; }
10
11 //如果没有重写就直接转换
12 public virtual void ConvertProjectXml(XElement projectNode) {
13 XmlUtils.SetAttributeValue(projectNode, "Version", TargetVersion);
14 }
15
16 public virtual void ConvertWorld(string directoryName) {
17 string path = Storage.CombinePaths(directoryName, "Project.xml");
18 XElement xElement;
19 using (Stream stream = Storage.OpenFile(path, OpenFileMode.Read)) {
20 xElement = XmlUtils.LoadXmlFromStream(stream, null, true);
21 }
22 ConvertProjectXml(xElement);
23 using (Stream stream2 = Storage.OpenFile(path, OpenFileMode.Create)) {
24 XmlUtils.SaveXmlToStream(xElement, stream2, null, true);
25 }
26 }
27 }
28
29 /*
30 public class GenericVersionConverter(string sourceVersion,string targetVersion) : VersionConverter
31 {
32 private string _sourceVersion = sourceVersion;
33 private string _targetVersion = targetVersion;
34
35 public override string SourceVersion => _sourceVersion;
36
37 public override string TargetVersion => _targetVersion;
38
39 public override void ConvertProjectXml(XElement projectNode)
40 {
41 XmlUtils.SetAttributeValue(projectNode,"Version",TargetVersion);
42 }
43
44 public override void ConvertWorld(string directoryName)
45 {
46 string path = Storage.CombinePaths(directoryName,"Project.xml");
47 XElement xElement;
48 using(Stream stream = Storage.OpenFile(path,OpenFileMode.Read))
49 {
50 xElement = XmlUtils.LoadXmlFromStream(stream,null,throwOnError: true);
51 }
52 ConvertProjectXml(xElement);
53 using(Stream stream2 = Storage.OpenFile(path,OpenFileMode.Create))
54 {
55 XmlUtils.SaveXmlToStream(xElement,stream2,null,throwOnError: true);
56 }
57 }
58 // Example usage:
59 // var converter = new GenericVersionConverter("1.11", "1.12");
60 // converter.ConvertWorld("path_to_world_directory");
61}*/
63 public override string SourceVersion => "1.4";
64
65 public override string TargetVersion => "1.5";
66 }
67
69 public override string SourceVersion => "1.5";
70
71 public override string TargetVersion => "1.6";
72 }
73
75 public override string SourceVersion => "1.6";
76
77 public override string TargetVersion => "1.7";
78 }
79
81 public override string SourceVersion => "1.7";
82
83 public override string TargetVersion => "1.8";
84 }
85
87 public override string SourceVersion => "1.8";
88
89 public override string TargetVersion => "1.9";
90 }
91
93 public override string SourceVersion => "1.9";
94
95 public override string TargetVersion => "1.10";
96 }
97
99 public override string SourceVersion => "1.10";
100
101 public override string TargetVersion => "1.11";
102 }
103
105 public override string SourceVersion => "1.11";
106
107 public override string TargetVersion => "1.12";
108 }
109
111 public override string SourceVersion => "1.14";
112
113 public override string TargetVersion => "1.15";
114 }
115
117 public override string SourceVersion => "1.15";
118
119 public override string TargetVersion => "1.16";
120 }
121
123 public override string SourceVersion => "1.16";
124
125 public override string TargetVersion => "1.17";
126 }
127
129 public override string SourceVersion => "1.17";
130
131 public override string TargetVersion => "1.18";
132 }
133
135 public override string SourceVersion => "1.18";
136
137 public override string TargetVersion => "1.19";
138 }
139
141 public override string SourceVersion => "1.19";
142
143 public override string TargetVersion => "1.20";
144 }
145
147 public override string SourceVersion => "1.22";
148
149 public override string TargetVersion => "1.23";
150 }
151
153 public override string SourceVersion => "1.23";
154
155 public override string TargetVersion => "1.24";
156 }
157
159 public override string SourceVersion => "1.24";
160
161 public override string TargetVersion => "1.25";
162 }
163
165 public override string SourceVersion => "1.25";
166
167 public override string TargetVersion => "1.26";
168 }
169
171 public override string SourceVersion => "1.27";
172
173 public override string TargetVersion => "1.28";
174 }
175
177 public override string SourceVersion => "1.29";
178
179 public override string TargetVersion => "1.30";
180 }
181
183 public override string SourceVersion => "1.30";
184
185 public override string TargetVersion => "2.0";
186 }
187}
static Stream OpenFile(string path, OpenFileMode openFileMode)
static string CombinePaths(params string[] paths)
virtual void ConvertProjectXml(XElement projectNode)
virtual void ConvertWorld(string directoryName)
static void SetAttributeValue(XElement node, string attributeName, object value)
static XElement LoadXmlFromStream(Stream stream, Encoding encoding, bool throwOnError)
static void SaveXmlToStream(XElement node, Stream stream, Encoding encoding, bool throwOnError)