Remove flat file conversion code

This commit is contained in:
Lucas Nicodemus 2012-01-01 02:48:15 -07:00
parent f47ce942f4
commit 2bfdaaaabc
3 changed files with 2 additions and 122 deletions

View file

@ -55,117 +55,9 @@ namespace TShockAPI.DB
: new MysqlQueryCreator());
creator.EnsureExists(table);
ImportOld();
ReloadAllRegions();
}
[SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")]
public void ImportOld()
{
String file = Path.Combine(TShock.SavePath, "regions.xml");
if (!File.Exists(file))
return;
Region region;
Rectangle rect;
using (var reader = XmlReader.Create(new StreamReader(file), new XmlReaderSettings {CloseInput = true}))
{
// Parse the file and display each of the nodes.
while (reader.Read())
{
if (reader.NodeType != XmlNodeType.Element || reader.Name != "ProtectedRegion")
continue;
region = new Region();
rect = new Rectangle();
bool endregion = false;
while (reader.Read() && !endregion)
{
if (reader.NodeType != XmlNodeType.Element)
continue;
string name = reader.Name;
while (reader.Read() && reader.NodeType != XmlNodeType.Text) ;
int t = 0;
switch (name)
{
case "RegionName":
region.Name = reader.Value;
break;
case "Point1X":
int.TryParse(reader.Value, out t);
rect.X = t;
break;
case "Point1Y":
int.TryParse(reader.Value, out t);
rect.Y = t;
break;
case "Point2X":
int.TryParse(reader.Value, out t);
rect.Width = t;
break;
case "Point2Y":
int.TryParse(reader.Value, out t);
rect.Height = t;
break;
case "Protected":
region.DisableBuild = reader.Value.ToLower().Equals("true");
break;
case "WorldName":
region.WorldID = reader.Value;
break;
case "AllowedUserCount":
break;
case "IP":
region.AllowedIDs.Add(int.Parse(reader.Value));
break;
default:
endregion = true;
break;
}
}
region.Area = rect;
string query = (TShock.Config.StorageType.ToLower() == "sqlite")
? "INSERT OR IGNORE INTO Regions VALUES (@0, @1, @2, @3, @4, @5, @6, @7);"
: "INSERT IGNORE INTO Regions SET X1=@0, Y1=@1, height=@2, width=@3, RegionName=@4, WorldID=@5, UserIds=@6, Protected=@7;";
database.Query(query, region.Area.X, region.Area.Y, region.Area.Width, region.Area.Height, region.Name,
region.WorldID, "", region.DisableBuild);
//Todo: What should this be? We don't really have a way to go from ips to userids
/*string.Join(",", region.AllowedIDs)*/
}
}
String path = Path.Combine(TShock.SavePath, "old_configs");
String file2 = Path.Combine(path, "regions.xml");
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
if (File.Exists(file2))
File.Delete(file2);
File.Move(file, file2);
ReloadAllRegions();
}
public void ConvertDB()
{
try
{
database.Query("UPDATE Regions SET WorldID=@0, UserIds=''", Main.worldID.ToString());
ReloadAllRegions();
}
catch (Exception ex)
{
Log.Error(ex.ToString());
}
}
public void ReloadAllRegions()
{
try