Reads old Warps.xml into sql if it exists, then deletes
This commit is contained in:
parent
b090b1fe96
commit
d83513ca96
1 changed files with 81 additions and 0 deletions
|
|
@ -21,6 +21,7 @@ using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
|
using System.IO;
|
||||||
using Community.CsharpSqlite.SQLiteClient;
|
using Community.CsharpSqlite.SQLiteClient;
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using System.Xml;
|
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 );";
|
"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();
|
com.ExecuteNonQuery();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!File.Exists(FileTools.WarpsPath))
|
||||||
|
{
|
||||||
|
ReadWarps();
|
||||||
|
File.Delete(FileTools.WarpsPath);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static IDbDataParameter AddParameter(IDbCommand command, string name, object data)
|
static IDbDataParameter AddParameter(IDbCommand command, string name, object data)
|
||||||
|
|
@ -116,6 +123,80 @@ namespace TShockAPI
|
||||||
}
|
}
|
||||||
return new Warp();
|
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
|
public class Warp
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue