mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-24 05:03:34 -04:00
Backups also save associated file with map (bots/blockdefs/env)
This commit is contained in:
parent
42bcb10c68
commit
50c2140734
@ -215,7 +215,7 @@ namespace MCGalaxy.Commands.Info {
|
|||||||
Width = dims.X; Height = dims.Y; Length = dims.Z;
|
Width = dims.X; Height = dims.Y; Length = dims.Z;
|
||||||
BlockDBEntries = BlockDBFile.CountEntries(name);
|
BlockDBEntries = BlockDBFile.CountEntries(name);
|
||||||
|
|
||||||
path = LevelInfo.PropertiesPath(name);
|
path = LevelInfo.PropsPath(name);
|
||||||
LevelConfig cfg = new LevelConfig();
|
LevelConfig cfg = new LevelConfig();
|
||||||
cfg.Reset(Height);
|
cfg.Reset(Height);
|
||||||
LevelConfig.Load(path, cfg);
|
LevelConfig.Load(path, cfg);
|
||||||
|
@ -53,7 +53,7 @@ namespace MCGalaxy.Commands.Info {
|
|||||||
build = LevelPermission.Guest;
|
build = LevelPermission.Guest;
|
||||||
loadOnGoto = true;
|
loadOnGoto = true;
|
||||||
|
|
||||||
string propsPath = LevelInfo.PropertiesPath(level);
|
string propsPath = LevelInfo.PropsPath(level);
|
||||||
SearchArgs args = new SearchArgs();
|
SearchArgs args = new SearchArgs();
|
||||||
if (!PropertiesFile.Read(propsPath, ref args, ProcessLine)) return;
|
if (!PropertiesFile.Read(propsPath, ref args, ProcessLine)) return;
|
||||||
|
|
||||||
|
@ -264,7 +264,7 @@ namespace MCGalaxy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Update(Level lvl) {
|
void Update(Level lvl) {
|
||||||
cfg.Save(LevelInfo.PropertiesPath(lvlName));
|
cfg.Save(LevelInfo.PropsPath(lvlName));
|
||||||
if (lvl == null) return;
|
if (lvl == null) return;
|
||||||
if (IsVisit && lvl == Server.mainLevel) return;
|
if (IsVisit && lvl == Server.mainLevel) return;
|
||||||
Player[] players = PlayerInfo.Online.Items;
|
Player[] players = PlayerInfo.Online.Items;
|
||||||
|
@ -219,7 +219,7 @@ namespace MCGalaxy {
|
|||||||
|
|
||||||
public static void SaveSettings(Level lvl) {
|
public static void SaveSettings(Level lvl) {
|
||||||
if (lvl.IsMuseum) return; // museums do not save properties
|
if (lvl.IsMuseum) return; // museums do not save properties
|
||||||
string path = LevelInfo.PropertiesPath(lvl.MapName);
|
string path = LevelInfo.PropsPath(lvl.MapName);
|
||||||
lvl.Config.Save(path);
|
lvl.Config.Save(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -278,24 +278,15 @@ namespace MCGalaxy {
|
|||||||
public int Backup(bool Forced = false, string backupName = "") {
|
public int Backup(bool Forced = false, string backupName = "") {
|
||||||
if (!backedup || Forced) {
|
if (!backedup || Forced) {
|
||||||
string backupPath = LevelInfo.BackupBasePath(name);
|
string backupPath = LevelInfo.BackupBasePath(name);
|
||||||
if (!Directory.Exists(backupPath)) Directory.CreateDirectory(backupPath);
|
if (!Directory.Exists(backupPath)) Directory.CreateDirectory(backupPath);
|
||||||
int next = LevelInfo.LatestBackup(name) + 1;
|
int next = LevelInfo.LatestBackup(name) + 1;
|
||||||
|
if (backupName.Length == 0) backupName = next.ToString();
|
||||||
|
|
||||||
string path = Path.Combine(backupPath, next.ToString());
|
if (!LevelActions.Backup(name, backupName)) {
|
||||||
if (backupName.Length > 0) path = Path.Combine(backupPath, backupName);
|
|
||||||
Directory.CreateDirectory(path);
|
|
||||||
|
|
||||||
string backup = Path.Combine(path, name + ".lvl");
|
|
||||||
string current = LevelInfo.MapPath(name);
|
|
||||||
try {
|
|
||||||
File.Copy(current, backup, true);
|
|
||||||
backedup = true;
|
|
||||||
return next;
|
|
||||||
} catch (Exception e) {
|
|
||||||
Logger.LogError(e);
|
|
||||||
Logger.Log(LogType.Warning, "FAILED TO INCREMENTAL BACKUP :" + name);
|
Logger.Log(LogType.Warning, "FAILED TO INCREMENTAL BACKUP :" + name);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
return next;
|
||||||
}
|
}
|
||||||
Logger.Log(LogType.SystemActivity, "Level unchanged, skipping backup");
|
Logger.Log(LogType.SystemActivity, "Level unchanged, skipping backup");
|
||||||
return -1;
|
return -1;
|
||||||
@ -343,7 +334,7 @@ namespace MCGalaxy {
|
|||||||
|
|
||||||
public static void LoadMetadata(Level lvl) {
|
public static void LoadMetadata(Level lvl) {
|
||||||
try {
|
try {
|
||||||
string propsPath = LevelInfo.PropertiesPath(lvl.MapName);
|
string propsPath = LevelInfo.PropsPath(lvl.MapName);
|
||||||
bool propsExisted = LevelConfig.Load(propsPath, lvl.Config);
|
bool propsExisted = LevelConfig.Load(propsPath, lvl.Config);
|
||||||
|
|
||||||
if (propsExisted) {
|
if (propsExisted) {
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using MCGalaxy.Blocks;
|
||||||
using MCGalaxy.Bots;
|
using MCGalaxy.Bots;
|
||||||
using MCGalaxy.DB;
|
using MCGalaxy.DB;
|
||||||
using MCGalaxy.SQL;
|
using MCGalaxy.SQL;
|
||||||
@ -26,6 +27,26 @@ namespace MCGalaxy {
|
|||||||
|
|
||||||
public static class LevelActions {
|
public static class LevelActions {
|
||||||
|
|
||||||
|
static string BlockPropsLvlPath(string map) { return BlockProps.PropsPath("_" + map); }
|
||||||
|
static string BlockPropsOldPath(string map) { return BlockProps.PropsPath("lvl" + map); }
|
||||||
|
static string BlockDefsPath(string map) { return "blockdefs/lvl_" + map + ".json"; }
|
||||||
|
|
||||||
|
public static bool Backup(string map, string backupName) {
|
||||||
|
string basePath = LevelInfo.BackupBasePath(map);
|
||||||
|
if (!Directory.Exists(basePath)) Directory.CreateDirectory(basePath);
|
||||||
|
string path = Path.Combine(basePath, backupName);
|
||||||
|
Directory.CreateDirectory(path);
|
||||||
|
|
||||||
|
bool lvl = DoAction(LevelInfo.MapPath(map), Path.Combine(path, map + ".lvl"), action_copy);
|
||||||
|
bool props = DoAction(LevelInfo.PropsPath(map), Path.Combine(path, "map.properties"), action_copy);
|
||||||
|
bool defs = DoAction(BlockDefsPath(map), Path.Combine(path, "blockdefs.json"), action_copy);
|
||||||
|
bool blkOld = DoAction(BlockPropsOldPath(map), Path.Combine(path, "blockprops.txt"), action_copy);
|
||||||
|
bool blkCur = DoAction(BlockPropsLvlPath(map), Path.Combine(path, "blockprops.txt"), action_copy);
|
||||||
|
bool bots = DoAction(BotsFile.BotsPath(map), Path.Combine(path, "bots.json"), action_copy);
|
||||||
|
|
||||||
|
return lvl && props && defs && blkOld && blkCur && bots;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary> Renames the .lvl (and related) files and database tables. Does not unload. </summary>
|
/// <summary> Renames the .lvl (and related) files and database tables. Does not unload. </summary>
|
||||||
public static void Rename(string src, string dst) {
|
public static void Rename(string src, string dst) {
|
||||||
File.Move(LevelInfo.MapPath(src), LevelInfo.MapPath(dst));
|
File.Move(LevelInfo.MapPath(src), LevelInfo.MapPath(dst));
|
||||||
@ -88,42 +109,42 @@ namespace MCGalaxy {
|
|||||||
|
|
||||||
public const string DeleteFailedMessage = "Unable to delete the level, because it could not be unloaded. A game may currently be running on it.";
|
public const string DeleteFailedMessage = "Unable to delete the level, because it could not be unloaded. A game may currently be running on it.";
|
||||||
/// <summary> Deletes the .lvl (and related) files and database tables. Unloads level if it is loaded. </summary>
|
/// <summary> Deletes the .lvl (and related) files and database tables. Unloads level if it is loaded. </summary>
|
||||||
public static bool Delete(string name) {
|
public static bool Delete(string map) {
|
||||||
Level lvl = LevelInfo.FindExact(name);
|
Level lvl = LevelInfo.FindExact(map);
|
||||||
if (lvl != null && !lvl.Unload()) return false;
|
if (lvl != null && !lvl.Unload()) return false;
|
||||||
|
|
||||||
if (!Directory.Exists("levels/deleted"))
|
if (!Directory.Exists("levels/deleted"))
|
||||||
Directory.CreateDirectory("levels/deleted");
|
Directory.CreateDirectory("levels/deleted");
|
||||||
|
|
||||||
if (File.Exists(LevelInfo.DeletedPath(name))) {
|
if (File.Exists(LevelInfo.DeletedPath(map))) {
|
||||||
int num = 0;
|
int num = 0;
|
||||||
while (File.Exists(LevelInfo.DeletedPath(name + num))) num++;
|
while (File.Exists(LevelInfo.DeletedPath(map + num))) num++;
|
||||||
|
|
||||||
File.Move(LevelInfo.MapPath(name), LevelInfo.DeletedPath(name + num));
|
File.Move(LevelInfo.MapPath(map), LevelInfo.DeletedPath(map + num));
|
||||||
} else {
|
} else {
|
||||||
File.Move(LevelInfo.MapPath(name), LevelInfo.DeletedPath(name));
|
File.Move(LevelInfo.MapPath(map), LevelInfo.DeletedPath(map));
|
||||||
}
|
}
|
||||||
|
|
||||||
DoAll(name, "", action_delete);
|
DoAll(map, "", action_delete);
|
||||||
DeleteDatabaseTables(name);
|
DeleteDatabaseTables(map);
|
||||||
BlockDBFile.DeleteBackingFile(name);
|
BlockDBFile.DeleteBackingFile(map);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void DeleteDatabaseTables(string name) {
|
static void DeleteDatabaseTables(string map) {
|
||||||
if (Database.Backend.TableExists("Block" + name))
|
if (Database.Backend.TableExists("Block" + map))
|
||||||
Database.Backend.DeleteTable("Block" + name);
|
Database.Backend.DeleteTable("Block" + map);
|
||||||
|
|
||||||
object locker = ThreadSafeCache.DBCache.GetLocker(name);
|
object locker = ThreadSafeCache.DBCache.GetLocker(map);
|
||||||
lock (locker) {
|
lock (locker) {
|
||||||
if (Database.TableExists("Portals" + name)) {
|
if (Database.TableExists("Portals" + map)) {
|
||||||
Database.Backend.DeleteTable("Portals" + name);
|
Database.Backend.DeleteTable("Portals" + map);
|
||||||
}
|
}
|
||||||
if (Database.TableExists("Messages" + name)) {
|
if (Database.TableExists("Messages" + map)) {
|
||||||
Database.Backend.DeleteTable("Messages" + name);
|
Database.Backend.DeleteTable("Messages" + map);
|
||||||
}
|
}
|
||||||
if (Database.TableExists("Zone" + name)) {
|
if (Database.TableExists("Zone" + map)) {
|
||||||
Database.Backend.DeleteTable("Zone" + name);
|
Database.Backend.DeleteTable("Zone" + map);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -203,22 +224,22 @@ namespace MCGalaxy {
|
|||||||
static void DoAll(string src, string dst, byte action) {
|
static void DoAll(string src, string dst, byte action) {
|
||||||
DoAction(LevelInfo.MapPath(src) + ".backup",
|
DoAction(LevelInfo.MapPath(src) + ".backup",
|
||||||
LevelInfo.MapPath(dst) + ".backup", action);
|
LevelInfo.MapPath(dst) + ".backup", action);
|
||||||
DoAction("levels/level properties/" + src + ".properties",
|
DoAction(LevelInfo.PropsPath(src),
|
||||||
"levels/level properties/" + dst + ".properties", action);
|
LevelInfo.PropsPath(dst), action);
|
||||||
DoAction("levels/level properties/" + src,
|
DoAction("levels/level properties/" + src,
|
||||||
"levels/level properties/" + dst + ".properties", action);
|
LevelInfo.PropsPath(dst), action);
|
||||||
DoAction("blockdefs/lvl_" + src + ".json",
|
DoAction(BlockDefsPath(src),
|
||||||
"blockdefs/lvl_" + dst + ".json", action);
|
BlockDefsPath(dst), action);
|
||||||
DoAction("blockprops/lvl_" + src + ".txt",
|
DoAction(BlockPropsOldPath(src),
|
||||||
"blockprops/lvl_" + dst + ".txt", action);
|
BlockPropsOldPath(dst), action);
|
||||||
DoAction("blockprops/_" + src + ".txt", "" +
|
DoAction(BlockPropsLvlPath(src),
|
||||||
"blockprops/_" + dst + ".txt", action);
|
BlockPropsLvlPath(dst), action);
|
||||||
DoAction(BotsFile.BotsPath(src),
|
DoAction(BotsFile.BotsPath(src),
|
||||||
BotsFile.BotsPath(dst), action);
|
BotsFile.BotsPath(dst), action);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void DoAction(string src, string dst, byte action) {
|
static bool DoAction(string src, string dst, byte action) {
|
||||||
if (!File.Exists(src)) return;
|
if (!File.Exists(src)) return true;
|
||||||
try {
|
try {
|
||||||
if (action == action_delete) {
|
if (action == action_delete) {
|
||||||
File.Delete(src);
|
File.Delete(src);
|
||||||
@ -227,8 +248,10 @@ namespace MCGalaxy {
|
|||||||
} else if (action == action_copy) {
|
} else if (action == action_copy) {
|
||||||
File.Copy(src, dst, true);
|
File.Copy(src, dst, true);
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
Logger.LogError(ex);
|
Logger.LogError(ex);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -113,7 +113,7 @@ namespace MCGalaxy {
|
|||||||
|
|
||||||
|
|
||||||
/// <summary> Relative path of a level's property file </summary>
|
/// <summary> Relative path of a level's property file </summary>
|
||||||
public static string PropertiesPath(string name) {
|
public static string PropsPath(string name) {
|
||||||
return "levels/level properties/" + name + ".properties";
|
return "levels/level properties/" + name + ".properties";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,7 +121,7 @@ namespace MCGalaxy {
|
|||||||
lvl = FindExact(map);
|
lvl = FindExact(map);
|
||||||
if (lvl != null) return lvl.Config;
|
if (lvl != null) return lvl.Config;
|
||||||
|
|
||||||
string propsPath = PropertiesPath(map);
|
string propsPath = PropsPath(map);
|
||||||
LevelConfig cfg = new LevelConfig();
|
LevelConfig cfg = new LevelConfig();
|
||||||
cfg.Reset(0);
|
cfg.Reset(0);
|
||||||
LevelConfig.Load(propsPath, cfg);
|
LevelConfig.Load(propsPath, cfg);
|
||||||
|
@ -79,7 +79,7 @@ namespace MCGalaxy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool LoadOfflineLevel(Player p, string name) {
|
static bool LoadOfflineLevel(Player p, string name) {
|
||||||
string propsPath = LevelInfo.PropertiesPath(name);
|
string propsPath = LevelInfo.PropsPath(name);
|
||||||
LevelConfig cfg = new LevelConfig();
|
LevelConfig cfg = new LevelConfig();
|
||||||
LevelConfig.Load(propsPath, cfg);
|
LevelConfig.Load(propsPath, cfg);
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ namespace MCGalaxy.Tasks {
|
|||||||
|
|
||||||
if (names.Count > 0) {
|
if (names.Count > 0) {
|
||||||
string lvlName = Path.GetFileNameWithoutExtension(files[i]);
|
string lvlName = Path.GetFileNameWithoutExtension(files[i]);
|
||||||
string propsPath = LevelInfo.PropertiesPath(lvlName);
|
string propsPath = LevelInfo.PropsPath(lvlName);
|
||||||
using (StreamWriter w = new StreamWriter(propsPath, true)) {
|
using (StreamWriter w = new StreamWriter(propsPath, true)) {
|
||||||
w.WriteLine("VisitBlacklist = " + names.Join());
|
w.WriteLine("VisitBlacklist = " + names.Join());
|
||||||
}
|
}
|
||||||
@ -116,7 +116,7 @@ namespace MCGalaxy.Tasks {
|
|||||||
|
|
||||||
static void Combine(string envFile) {
|
static void Combine(string envFile) {
|
||||||
string name = Path.GetFileNameWithoutExtension(envFile);
|
string name = Path.GetFileNameWithoutExtension(envFile);
|
||||||
string propsPath = LevelInfo.PropertiesPath(name);
|
string propsPath = LevelInfo.PropsPath(name);
|
||||||
|
|
||||||
List<string> lines = new List<string>();
|
List<string> lines = new List<string>();
|
||||||
if (File.Exists(propsPath)) {
|
if (File.Exists(propsPath)) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user