Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
VersionConverter126To127.cs
浏览该文件的文档.
1using System.Xml.Linq;
2using Engine;
3using XmlUtilities;
4
5namespace Game {
7 public override string SourceVersion => "1.26";
8
9 public override string TargetVersion => "1.27";
10
11 public override void ConvertProjectXml(XElement projectNode) {
12 XmlUtils.SetAttributeValue(projectNode, "Version", TargetVersion);
13 ConvertTypesToEngine(projectNode);
14 }
15
16 public override 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
29#if !ANDROID
30 try {
31 if (Storage.DirectoryExists("app:/.config/.isolated-storage")) {
32 Log.Information("1.26 data found, starting migration to 1.27.");
33 BusyDialog dialog = new("Please wait", "Migrating 1.26 data to 1.27 format...");
34 DialogsManager.ShowDialog(null, dialog);
35 Task.Run(
36 delegate {
37 string empty;
38 string empty2;
39 try {
40 int num = MigrateFolder("app:/.config/.isolated-storage", "data:");
41 empty = "Migration Successful";
42 empty2 = $"{num} file(s) were migrated from 1.26 to 1.27.";
43 }
44 catch (Exception ex2) {
45 empty = "Migration Failed";
46 empty2 = ex2.Message;
47 Log.Error("Migration to 1.27 failed, reason: {0}", ex2.Message);
48 }
50 DialogsManager.ShowDialog(null, new MessageDialog(empty, empty2, "OK", null, null));
52 }
53 );
54 }
55 }
56 catch (Exception ex) {
57 Log.Error("Failed to migrate data. Reason: {0}", ex.Message);
58 }
59#endif
60 }
61
62 public void ConvertTypesToEngine(XElement node) {
63 foreach (XElement item in node.DescendantsAndSelf("Value")) {
64 XAttribute xAttribute = item.Attribute("Type");
65 if (xAttribute != null) {
66 if (xAttribute.Value == "Microsoft.Xna.Framework.Vector2") {
67 xAttribute.Value = "Engine.Vector2";
68 }
69 else if (xAttribute.Value == "Microsoft.Xna.Framework.Vector3") {
70 xAttribute.Value = "Engine.Vector3";
71 }
72 else if (xAttribute.Value == "Microsoft.Xna.Framework.Vector4") {
73 xAttribute.Value = "Engine.Vector4";
74 }
75 else if (xAttribute.Value == "Microsoft.Xna.Framework.Quaternion") {
76 xAttribute.Value = "Engine.Quaternion";
77 }
78 else if (xAttribute.Value == "Microsoft.Xna.Framework.Matrix") {
79 xAttribute.Value = "Engine.Matrix";
80 }
81 else if (xAttribute.Value == "Microsoft.Xna.Framework.Point") {
82 xAttribute.Value = "Engine.Point2";
83 }
84 else if (xAttribute.Value == "Microsoft.Xna.Framework.Color") {
85 xAttribute.Value = "Engine.Color";
86 }
87 else if (xAttribute.Value == "Game.Point3") {
88 xAttribute.Value = "Engine.Point3";
89 }
90 }
91 }
92 }
93
94 public static int MigrateFolder(string sourceFolderName, string targetFolderName) {
95 int num = 0;
96 Storage.CreateDirectory(targetFolderName);
97 foreach (string item in Storage.ListDirectoryNames(sourceFolderName)) {
98 num += MigrateFolder(Storage.CombinePaths(sourceFolderName, item), Storage.CombinePaths(targetFolderName, item));
99 }
100 foreach (string item2 in Storage.ListFileNames(sourceFolderName)) {
101 MigrateFile(Storage.CombinePaths(sourceFolderName, item2), targetFolderName);
102 num++;
103 }
104 Storage.DeleteDirectory(sourceFolderName);
105 Log.Information("Migrated {0}", sourceFolderName);
106 return num;
107 }
108
109 public static void MigrateFile(string sourceFileName, string targetFolderName) {
110 Storage.CopyFile(sourceFileName, Storage.CombinePaths(targetFolderName, Storage.GetFileName(sourceFileName)));
111 Storage.DeleteFile(sourceFileName);
112 Log.Information("Migrated {0}", sourceFileName);
113 }
114 }
115}
static void Dispatch(Action action, bool waitUntilCompleted=false)
static void Error(object message)
定义 Log.cs:80
static void Information(object message)
定义 Log.cs:56
static void CreateDirectory(string path)
static bool DirectoryExists(string path)
static IEnumerable< string > ListDirectoryNames(string path)
static IEnumerable< string > ListFileNames(string path)
static Stream OpenFile(string path, OpenFileMode openFileMode)
static string GetFileName(string path)
static void DeleteDirectory(string path)
static void DeleteFile(string path)
static string CombinePaths(params string[] paths)
static void CopyFile(string sourcePath, string destinationPath)
static void HideDialog(Dialog dialog)
static void ShowDialog(ContainerWidget parentWidget, Dialog dialog)
static bool LoadSettings()
文件存在则读取并返回真否则返回假
override void ConvertWorld(string directoryName)
static void MigrateFile(string sourceFileName, string targetFolderName)
static int MigrateFolder(string sourceFolderName, string targetFolderName)
override void ConvertProjectXml(XElement projectNode)
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)