mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-22 03:55:18 -04:00
Make /server restore actually sort of work.
This commit is contained in:
parent
367cefa97b
commit
f2d6b6c283
@ -96,8 +96,8 @@ namespace MCGalaxy {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
PackagePart part = package.CreatePart(loc, "");
|
PackagePart part = package.CreatePart(loc, "");
|
||||||
using (Stream stream = new FileStream("./" + file, FileMode.Open, FileAccess.Read))
|
using (Stream src = new FileStream("./" + file, FileMode.Open, FileAccess.Read))
|
||||||
CopyStream(stream, part.GetStream());
|
CopyStream(src, part.GetStream());
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
Server.s.Log("Failed to save file: " + file);
|
Server.s.Log("Failed to save file: " + file);
|
||||||
Server.ErrorLog(ex);
|
Server.ErrorLog(ex);
|
||||||
@ -124,31 +124,44 @@ namespace MCGalaxy {
|
|||||||
|
|
||||||
public static void ExtractPackage(object p) {
|
public static void ExtractPackage(object p) {
|
||||||
int errors = 0;
|
int errors = 0;
|
||||||
using (ZipPackage zip = (ZipPackage)ZipPackage.Open(File.OpenRead(path))) {
|
using (FileStream src = File.OpenRead(path))
|
||||||
PackagePartCollection pc = zip.GetParts();
|
using (ZipPackage zip = (ZipPackage)ZipPackage.Open(src))
|
||||||
foreach (ZipPackagePart item in pc) {
|
{
|
||||||
try {
|
PackagePartCollection parts = zip.GetParts();
|
||||||
CopyStream(item.GetStream(), File.Create("./" + Uri.UnescapeDataString(item.Uri.ToString())));
|
foreach (ZipPackagePart item in parts) {
|
||||||
} catch {
|
ExtractItem(item, ref errors);
|
||||||
try {
|
if (item.Uri.ToString().ToLower().Contains("sql.sql")) {
|
||||||
Directory.CreateDirectory("./" + item.Uri.ToString().Substring(0, item.Uri.ToString().LastIndexOfAny("\\/".ToCharArray())));
|
// If it's in there, they backed it up, meaning they want it restored
|
||||||
CopyStream(item.GetStream(), File.Create("./" + Uri.UnescapeDataString(item.Uri.ToString())));
|
|
||||||
} catch (IOException e) {
|
|
||||||
Server.ErrorLog(e);
|
|
||||||
Server.s.Log("Caught ignoreable Error. See log for more details. Will continue with rest of files.");
|
|
||||||
errors++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// To make life easier, we reload settings now, to maker it less likely to need restart
|
|
||||||
Command.all.Find("server").Use(null, "reload"); //Reload, as console
|
|
||||||
if (item.Uri.ToString().ToLower().Contains("sql.sql"))
|
|
||||||
{ // If it's in there, they backed it up, meaning they want it restored
|
|
||||||
Backup.fillDatabase(item.GetStream());
|
Backup.fillDatabase(item.GetStream());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// To make life easier, we reload settings now, to maker it less likely to need restart
|
||||||
|
Command.all.Find("server").Use(null, "reload"); // Reload, as console
|
||||||
Player.Message((Player)p, "Server restored" + (errors > 0 ? " with errors. May be a partial restore" : "") + ". Restart is reccommended, though not required.");
|
Player.Message((Player)p, "Server restored" + (errors > 0 ? " with errors. May be a partial restore" : "") + ". Restart is reccommended, though not required.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void ExtractItem(ZipPackagePart item, ref int errors) {
|
||||||
|
string entry = item.Uri.ToString();
|
||||||
|
string file = "./" + Uri.UnescapeDataString(entry);
|
||||||
|
|
||||||
|
using (Stream src = item.GetStream()) {
|
||||||
|
try {
|
||||||
|
using (Stream dst = File.Create(file))
|
||||||
|
CopyStream(src, dst);
|
||||||
|
} catch {
|
||||||
|
try {
|
||||||
|
Directory.CreateDirectory("./" + entry.Substring(0, entry.LastIndexOfAny("\\/".ToCharArray())));
|
||||||
|
using (Stream dst = File.Create(file))
|
||||||
|
CopyStream(src, dst);
|
||||||
|
} catch (IOException e) {
|
||||||
|
Server.ErrorLog(e);
|
||||||
|
Server.s.Log("Caught ignoreable Error. See log for more details. Will continue with rest of files.");
|
||||||
|
errors++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user