Fixed SCA warnings

This commit is contained in:
high 2011-08-06 16:49:40 -04:00
parent 72d49d421c
commit 56eca71853
13 changed files with 299 additions and 236 deletions

View file

@ -54,6 +54,7 @@ namespace TShockAPI.DB
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")]
public void ImportOld()
{
String file = Path.Combine(TShock.SavePath, "regions.xml");
@ -62,77 +63,74 @@ namespace TShockAPI.DB
Region region;
Rectangle rect;
using (var sr = new StreamReader(file))
using (var reader = XmlReader.Create(new StreamReader(file), new XmlReaderSettings { CloseInput = true }))
{
using (var reader = XmlReader.Create(sr))
// Parse the file and display each of the nodes.
while (reader.Read())
{
// 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 || reader.Name != "ProtectedRegion")
if (reader.NodeType != XmlNodeType.Element)
continue;
region = new Region();
rect = new Rectangle();
string name = reader.Name;
bool endregion = false;
while (reader.Read() && !endregion)
while (reader.Read() && reader.NodeType != XmlNodeType.Text) ;
switch (name)
{
if (reader.NodeType != XmlNodeType.Element)
continue;
string name = reader.Name;
while (reader.Read() && reader.NodeType != XmlNodeType.Text) ;
switch (name)
{
case "RegionName":
region.Name = reader.Value;
break;
case "Point1X":
int.TryParse(reader.Value, out rect.X);
break;
case "Point1Y":
int.TryParse(reader.Value, out rect.Y);
break;
case "Point2X":
int.TryParse(reader.Value, out rect.Width);
break;
case "Point2Y":
int.TryParse(reader.Value, out rect.Height);
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;
using (var com = database.CreateCommand())
{
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)*/
case "RegionName":
region.Name = reader.Value;
break;
case "Point1X":
int.TryParse(reader.Value, out rect.X);
break;
case "Point1Y":
int.TryParse(reader.Value, out rect.Y);
break;
case "Point2X":
int.TryParse(reader.Value, out rect.Width);
break;
case "Point2Y":
int.TryParse(reader.Value, out rect.Height);
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))

View file

@ -350,6 +350,7 @@ namespace TShockAPI.DB
}
}
[Serializable]
public class UserManagerException : Exception
{
public UserManagerException(string message)
@ -363,6 +364,7 @@ namespace TShockAPI.DB
}
}
[Serializable]
public class UserExistsException : UserManagerException
{
public UserExistsException(string name)
@ -370,6 +372,7 @@ namespace TShockAPI.DB
{
}
}
[Serializable]
public class UserNotExistException : UserManagerException
{
public UserNotExistException(string name)
@ -377,7 +380,7 @@ namespace TShockAPI.DB
{
}
}
[Serializable]
public class GroupNotExistsException : UserManagerException
{
public GroupNotExistsException(string group)

View file

@ -31,12 +31,13 @@ namespace TShockAPI.DB
{
private IDbConnection database;
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")]
public WarpManager(IDbConnection db)
{
database = db;
var table = new SqlTable("Warps",
new SqlColumn("WarpName", MySqlDbType.VarChar, 50) { Primary = true},
new SqlColumn("WarpName", MySqlDbType.VarChar, 50) { Primary = true },
new SqlColumn("X", MySqlDbType.Int32),
new SqlColumn("Y", MySqlDbType.Int32),
new SqlColumn("WorldID", MySqlDbType.Text),
@ -50,78 +51,76 @@ namespace TShockAPI.DB
String world = "";
int x1 = 0;
int y1 = 0;
if (File.Exists(file))
if (!File.Exists(file))
return;
using (var reader = XmlReader.Create(new StreamReader(file), new XmlReaderSettings { CloseInput = true }))
{
XmlReader reader;
using (reader = XmlReader.Create(new StreamReader(file)))
// Parse the file and display each of the nodes.
while (reader.Read())
{
// Parse the file and display each of the nodes.
while (reader.Read())
switch (reader.NodeType)
{
switch (reader.NodeType)
{
case XmlNodeType.Element:
switch (reader.Name)
{
case "Warp":
name = "";
world = "";
x1 = 0;
y1 = 0;
break;
case "WarpName":
while (reader.NodeType != XmlNodeType.Text)
reader.Read();
name = reader.Value;
break;
case "X":
while (reader.NodeType != XmlNodeType.Text)
reader.Read();
int.TryParse(reader.Value, out x1);
break;
case "Y":
while (reader.NodeType != XmlNodeType.Text)
reader.Read();
int.TryParse(reader.Value, out y1);
break;
case "WorldName":
while (reader.NodeType != XmlNodeType.Text)
reader.Read();
world = reader.Value;
break;
}
break;
case XmlNodeType.Text:
case XmlNodeType.Element:
switch (reader.Name)
{
case "Warp":
name = "";
world = "";
x1 = 0;
y1 = 0;
break;
case "WarpName":
while (reader.NodeType != XmlNodeType.Text)
reader.Read();
name = reader.Value;
break;
case "X":
while (reader.NodeType != XmlNodeType.Text)
reader.Read();
int.TryParse(reader.Value, out x1);
break;
case "Y":
while (reader.NodeType != XmlNodeType.Text)
reader.Read();
int.TryParse(reader.Value, out y1);
break;
case "WorldName":
while (reader.NodeType != XmlNodeType.Text)
reader.Read();
world = reader.Value;
break;
}
break;
case XmlNodeType.Text:
break;
case XmlNodeType.XmlDeclaration:
case XmlNodeType.ProcessingInstruction:
break;
case XmlNodeType.Comment:
break;
case XmlNodeType.EndElement:
if (reader.Name.Equals("Warp"))
{
string query = (TShock.Config.StorageType.ToLower() == "sqlite") ?
"INSERT OR IGNORE INTO Warps VALUES (@0, @1,@2, @3);" :
"INSERT IGNORE INTO Warps SET X=@0, Y=@1, WarpName=@2, WorldID=@3;";
database.Query(query, x1, y1, name, world);
}
break;
}
break;
case XmlNodeType.XmlDeclaration:
case XmlNodeType.ProcessingInstruction:
break;
case XmlNodeType.Comment:
break;
case XmlNodeType.EndElement:
if (reader.Name.Equals("Warp"))
{
string query = (TShock.Config.StorageType.ToLower() == "sqlite")
? "INSERT OR IGNORE INTO Warps VALUES (@0, @1,@2, @3);"
: "INSERT IGNORE INTO Warps SET X=@0, Y=@1, WarpName=@2, WorldID=@3;";
database.Query(query, x1, y1, name, world);
}
break;
}
}
reader.Close();
String path = Path.Combine(TShock.SavePath, "old_configs");
String file2 = Path.Combine(path, "warps.xml");
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
if (File.Exists(file2))
File.Delete(file2);
//File.Move(file, file2);
}
String path = Path.Combine(TShock.SavePath, "old_configs");
String file2 = Path.Combine(path, "warps.xml");
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
if (File.Exists(file2))
File.Delete(file2);
File.Move(file, file2);
}
public void ConvertDB()