mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-24 05:03:34 -04:00
Fix /server backup lite for windows.
This commit is contained in:
parent
49a7a1ab03
commit
367cefa97b
@ -68,13 +68,15 @@ namespace MCGalaxy {
|
|||||||
Server.s.Log("Server backed up!");
|
Server.s.Log("Server backed up!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const string undo1 = "extra/undo/", undo2 = @"extra\undo\";
|
||||||
|
const string prev1 = "extra/undoPrevious/", prev2 = @"extra\undoPrevious\";
|
||||||
static List<Uri> GetAllFiles(DirectoryInfo dir, Uri baseUri, bool lite) {
|
static List<Uri> GetAllFiles(DirectoryInfo dir, Uri baseUri, bool lite) {
|
||||||
List<Uri> list = new List<Uri>();
|
List<Uri> list = new List<Uri>();
|
||||||
foreach (FileSystemInfo entry in dir.GetFileSystemInfos()) {
|
foreach (FileSystemInfo entry in dir.GetFileSystemInfos()) {
|
||||||
if (entry is FileInfo) {
|
if (entry is FileInfo) {
|
||||||
string path = ((FileInfo)entry).FullName;
|
string path = ((FileInfo)entry).FullName;
|
||||||
if (lite && path.Contains("extra/undo/")) continue;
|
if (lite && (path.Contains(undo1) || path.Contains(undo2))) continue;
|
||||||
if (lite && path.Contains("extra/undoPrevious")) continue;
|
if (lite && (path.Contains(prev1) || path.Contains(prev2))) continue;
|
||||||
|
|
||||||
// Make a relative URI
|
// Make a relative URI
|
||||||
Uri uri = baseUri.MakeRelativeUri(new Uri(path));
|
Uri uri = baseUri.MakeRelativeUri(new Uri(path));
|
||||||
|
@ -38,7 +38,7 @@ namespace MCGalaxy {
|
|||||||
sql.WriteLine("-- http://mcgalaxy.ml");
|
sql.WriteLine("-- http://mcgalaxy.ml");
|
||||||
sql.WriteLine("--");
|
sql.WriteLine("--");
|
||||||
sql.WriteLine("-- Host: {0}", Server.MySQLHost);
|
sql.WriteLine("-- Host: {0}", Server.MySQLHost);
|
||||||
sql.WriteLine("-- Generation Time: {0} at {1}", DateTime.Now.Date, DateTime.Now.TimeOfDay);
|
sql.WriteLine("-- Generation Time: {0:d} at {0:HH:mm:ss}", DateTime.Now, DateTime.Now);
|
||||||
sql.WriteLine("-- MCGalaxy Version: {0}", Server.Version);
|
sql.WriteLine("-- MCGalaxy Version: {0}", Server.Version);
|
||||||
sql.WriteLine();
|
sql.WriteLine();
|
||||||
sql.WriteLine();
|
sql.WriteLine();
|
||||||
@ -52,13 +52,11 @@ namespace MCGalaxy {
|
|||||||
|
|
||||||
public static void BackupTable(string tableName, StreamWriter sql) {
|
public static void BackupTable(string tableName, StreamWriter sql) {
|
||||||
//For each table, we iterate through all rows, (and save them)
|
//For each table, we iterate through all rows, (and save them)
|
||||||
|
sql.WriteLine();
|
||||||
sql.WriteLine("-- --------------------------------------------------------");
|
sql.WriteLine("-- --------------------------------------------------------");
|
||||||
sql.WriteLine();
|
|
||||||
sql.WriteLine("--");
|
|
||||||
sql.WriteLine("-- Table structure for table `{0}`", tableName);
|
sql.WriteLine("-- Table structure for table `{0}`", tableName);
|
||||||
sql.WriteLine("--");
|
|
||||||
sql.WriteLine();
|
sql.WriteLine();
|
||||||
List<string[]> tableSchema = WriteTableSchema(tableName, sql);
|
List<string[]> schema = WriteTableSchema(tableName, sql);
|
||||||
|
|
||||||
using (DataTable data = Database.Fill("SELECT * FROM `" + tableName + "`")) {
|
using (DataTable data = Database.Fill("SELECT * FROM `" + tableName + "`")) {
|
||||||
if (data.Rows.Count == 0) {
|
if (data.Rows.Count == 0) {
|
||||||
@ -78,9 +76,9 @@ namespace MCGalaxy {
|
|||||||
foreach (DataRow row in data.Rows) { //We rely on the correct datatype being given here.
|
foreach (DataRow row in data.Rows) { //We rely on the correct datatype being given here.
|
||||||
sql.WriteLine();
|
sql.WriteLine();
|
||||||
sql.Write("INSERT INTO `{0}` (`", tableName);
|
sql.Write("INSERT INTO `{0}` (`", tableName);
|
||||||
foreach (string[] rParams in tableSchema) {
|
foreach (string[] rParams in schema) {
|
||||||
sql.Write(rParams[0]);
|
sql.Write(rParams[0]);
|
||||||
sql.Write((tableSchema[tableSchema.Count - 1].Equals(rParams) ? "`) VALUES" : "`, `"));
|
sql.Write((schema[schema.Count - 1].Equals(rParams) ? "`) VALUES" : "`, `"));
|
||||||
}
|
}
|
||||||
|
|
||||||
sql.WriteLine();
|
sql.WriteLine();
|
||||||
@ -217,26 +215,35 @@ namespace MCGalaxy {
|
|||||||
foreach (string cmd in cmds) {
|
foreach (string cmd in cmds) {
|
||||||
string newCmd = cmd.Trim(" \r\n\t".ToCharArray());
|
string newCmd = cmd.Trim(" \r\n\t".ToCharArray());
|
||||||
int index = newCmd.ToUpper().IndexOf("CREATE TABLE");
|
int index = newCmd.ToUpper().IndexOf("CREATE TABLE");
|
||||||
if (index > -1) {
|
if (index > -1) ParseCreate(ref newCmd, index);
|
||||||
|
//Run the command in the transaction.
|
||||||
|
helper.Execute(newCmd.Replace(" unsigned", "").Replace(" UNSIGNED", "") + ";");
|
||||||
|
}
|
||||||
|
helper.Commit();
|
||||||
|
}
|
||||||
|
//Not sure if order matters.
|
||||||
|
//AUTO_INCREMENT is changed to AUTOINCREMENT for MySQL -> SQLite
|
||||||
|
//AUTOINCREMENT is changed to AUTO_INCREMENT for SQLite -> MySQL
|
||||||
|
// All we should have in the script file is CREATE TABLE and INSERT INTO commands.
|
||||||
|
//executeQuery(sb.ToString().Replace(" unsigned", "").Replace(" UNSIGNED", ""));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ParseCreate(ref string newCmd, int index) {
|
||||||
newCmd = newCmd.Remove(0, index);
|
newCmd = newCmd.Remove(0, index);
|
||||||
//Do we have a primary key?
|
//Do we have a primary key?
|
||||||
try
|
try {
|
||||||
{
|
if (Server.useMySQL) {
|
||||||
if (Server.useMySQL)
|
|
||||||
{
|
|
||||||
int priIndex = newCmd.ToUpper().IndexOf(" PRIMARY KEY AUTOINCREMENT");
|
int priIndex = newCmd.ToUpper().IndexOf(" PRIMARY KEY AUTOINCREMENT");
|
||||||
int priCount = " PRIMARY KEY AUTOINCREMENT".Length;
|
int priCount = " PRIMARY KEY AUTOINCREMENT".Length;
|
||||||
int attIdx = newCmd.Substring(0, newCmd.Substring(0, priIndex - 1).LastIndexOfAny("` \n".ToCharArray())).LastIndexOfAny("` \n".ToCharArray()) + 1;
|
int attIdx = newCmd.Substring(0, newCmd.Substring(0, priIndex - 1).LastIndexOfAny("` \n".ToCharArray())).LastIndexOfAny("` \n".ToCharArray()) + 1;
|
||||||
int attIdxEnd = newCmd.IndexOfAny("` \n".ToCharArray(), attIdx) - 1;
|
int attIdxEnd = newCmd.IndexOfAny("` \n".ToCharArray(), attIdx) - 1;
|
||||||
string attName = newCmd.Substring(attIdx, attIdxEnd - attIdx + 1).Trim(' ', '\n', '`', '\r');
|
string attName = newCmd.Substring(attIdx, attIdxEnd - attIdx + 1).Trim(' ', '\n', '`', '\r');
|
||||||
|
|
||||||
//For speed, we just delete this, and add it to the attribute name, then delete the auto_increment clause.
|
//For speed, we just delete this, and add it to the attribute name, then delete the auto_increment clause.
|
||||||
newCmd = newCmd.Remove(priIndex, priCount);
|
newCmd = newCmd.Remove(priIndex, priCount);
|
||||||
newCmd = newCmd.Insert(newCmd.LastIndexOf(")"), ", PRIMARY KEY (`" + attName + "`)");
|
newCmd = newCmd.Insert(newCmd.LastIndexOf(")"), ", PRIMARY KEY (`" + attName + "`)");
|
||||||
newCmd = newCmd.Insert(newCmd.IndexOf(',', priIndex), " AUTO_INCREMENT");
|
newCmd = newCmd.Insert(newCmd.IndexOf(',', priIndex), " AUTO_INCREMENT");
|
||||||
|
} else {
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
int priIndex = newCmd.ToUpper().IndexOf(",\r\nPRIMARY KEY");
|
int priIndex = newCmd.ToUpper().IndexOf(",\r\nPRIMARY KEY");
|
||||||
int priIndexEnd = newCmd.ToUpper().IndexOf(')', priIndex);
|
int priIndexEnd = newCmd.ToUpper().IndexOf(')', priIndex);
|
||||||
int attIdx = newCmd.IndexOf("(", priIndex) + 1;
|
int attIdx = newCmd.IndexOf("(", priIndex) + 1;
|
||||||
@ -252,17 +259,5 @@ namespace MCGalaxy {
|
|||||||
}
|
}
|
||||||
catch (ArgumentOutOfRangeException) { } // If we don't, just ignore it.
|
catch (ArgumentOutOfRangeException) { } // If we don't, just ignore it.
|
||||||
}
|
}
|
||||||
//Run the command in the transaction.
|
|
||||||
helper.Execute(newCmd.Replace(" unsigned", "").Replace(" UNSIGNED", "") + ";");
|
|
||||||
// sb.Append(newCmd).Append(";\n");
|
|
||||||
}
|
|
||||||
helper.Commit();
|
|
||||||
}
|
|
||||||
//Not sure if order matters.
|
|
||||||
//AUTO_INCREMENT is changed to AUTOINCREMENT for MySQL -> SQLite
|
|
||||||
//AUTOINCREMENT is changed to AUTO_INCREMENT for SQLite -> MySQL
|
|
||||||
// All we should have in the script file is CREATE TABLE and INSERT INTO commands.
|
|
||||||
//executeQuery(sb.ToString().Replace(" unsigned", "").Replace(" UNSIGNED", ""));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user