From d83513ca961c67af1867249081236412cf6bd4dc Mon Sep 17 00:00:00 2001 From: Steven French Date: Tue, 5 Jul 2011 21:34:10 +1200 Subject: [PATCH] Reads old Warps.xml into sql if it exists, then deletes --- TShockAPI/WarpsManager.cs | 81 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/TShockAPI/WarpsManager.cs b/TShockAPI/WarpsManager.cs index 8e1cd805..35a539fa 100644 --- a/TShockAPI/WarpsManager.cs +++ b/TShockAPI/WarpsManager.cs @@ -21,6 +21,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Data; +using System.IO; using Community.CsharpSqlite.SQLiteClient; using Microsoft.Xna.Framework; using System.Xml; @@ -44,6 +45,12 @@ namespace TShockAPI "CREATE TABLE IF NOT EXISTS \"Warps\" (\"X\" VARCHAR(4) NOT NULL UNIQUE, \"Y\" VARCHAR(4) NOT NULL UNIQUE , \"WarpName\" VARCHAR(32) NOT NULL , \"WorldName\" VARCHAR(255) NOT NULL );"; com.ExecuteNonQuery(); } + + if(!File.Exists(FileTools.WarpsPath)) + { + ReadWarps(); + File.Delete(FileTools.WarpsPath); + } } static IDbDataParameter AddParameter(IDbCommand command, string name, object data) @@ -116,6 +123,80 @@ namespace TShockAPI } return new Warp(); } + + public static void ReadWarps() + { + try + { + XmlReaderSettings xmlReaderSettings = new XmlReaderSettings(); + xmlReaderSettings.IgnoreWhitespace = true; + + using (XmlReader settingr = XmlReader.Create(FileTools.WarpsPath, xmlReaderSettings)) + { + while (settingr.Read()) + { + if (settingr.IsStartElement()) + { + switch (settingr.Name) + { + case "Warps": + { + break; + } + case "Warp": + { + if (settingr.Read()) + { + string name = string.Empty; + int x = 0; + int y = 0; + string worldname = string.Empty; + + settingr.Read(); + if (settingr.Value != "" || settingr.Value != null) + name = settingr.Value; + else + Log.Warn("Warp name is empty, This warp will not work"); + + settingr.Read(); + settingr.Read(); + settingr.Read(); + if (settingr.Value != "" || settingr.Value != null) + Int32.TryParse(settingr.Value, out x); + else + Log.Warn("x for warp " + name + " is empty"); + + settingr.Read(); + settingr.Read(); + settingr.Read(); + if (settingr.Value != "" || settingr.Value != null) + Int32.TryParse(settingr.Value, out y); + else + Log.Warn("y for warp " + name + " is empty"); + + settingr.Read(); + settingr.Read(); + settingr.Read(); + if (settingr.Value != "" || settingr.Value != null) + worldname = settingr.Value; + else + Log.Warn("Worldname for warp " + name + " is empty"); + + TShock.Warps.AddWarp(x, y, name, worldname); + } + break; + } + } + } + } + } + Log.Info("Read Warps"); + } + catch + { + Log.Info("Could not read Warps"); + } + } } public class Warp