Esempio n. 1
0
        /// <summary> Saves a backup of the map and associated files. (like bots, .properties) </summary>
        /// <param name="force"> Whether to save a backup, even if nothing changed since last one. </param>
        /// <param name="backup"> Specific name of the backup, or "" to automatically pick a name. </param>
        /// <returns> The name of the backup, or null if no backup was saved. </returns>
        public string Backup(bool force = false, string backup = "")
        {
            if (!backedup || force)
            {
                string backupPath = LevelInfo.BackupBasePath(name);
                if (!Directory.Exists(backupPath))
                {
                    Directory.CreateDirectory(backupPath);
                }
                int next = LevelInfo.LatestBackup(name) + 1;
                if (backup.Length == 0)
                {
                    backup = next.ToString();
                }

                if (!LevelActions.Backup(name, backup))
                {
                    Logger.Log(LogType.Warning, "FAILED TO INCREMENTAL BACKUP :" + name);
                    return(null);
                }
                return(backup);
            }
            Logger.Log(LogType.SystemActivity, "Level unchanged, skipping backup");
            return(null);
        }
Esempio n. 2
0
        public int Backup(bool Forced = false, string backupName = "")
        {
            if (!backedup || Forced)
            {
                string backupPath = LevelInfo.BackupBasePath(name);
                if (!Directory.Exists(backupPath))
                {
                    Directory.CreateDirectory(backupPath);
                }
                int next = LevelInfo.LatestBackup(name) + 1;

                string path = Path.Combine(backupPath, next.ToString());
                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);
                    return(-1);
                }
            }
            Logger.Log(LogType.SystemActivity, "Level unchanged, skipping backup");
            return(-1);
        }
Esempio n. 3
0
        static Level ReadLevel(Player p, string map)
        {
            Level lvl = Level.Load(map);

            if (lvl != null)
            {
                return(lvl);
            }

            string path = LevelInfo.MapPath(map) + ".backup";

            if (!File.Exists(path))
            {
                p.Message("%WBackup of {0} does not exist.", map); return(null);
            }
            Logger.Log(LogType.Warning, "Attempting to load backup map for " + map);

            lvl = Level.Load(map, path);
            if (lvl != null)
            {
                return(lvl);
            }
            p.Message("%WLoading backup of {0} failed too.", map);

            string backupDir = LevelInfo.BackupBasePath(map);

            if (Directory.Exists(backupDir))
            {
                int latest = LevelInfo.LatestBackup(map);
                Logger.Log(LogType.Warning, "Attempting to load latest backup ({1}) of {0} instead", map, latest);

                path = LevelInfo.BackupFilePath(map, latest.ToString());
                lvl  = Level.Load(map, path);
                if (lvl == null)
                {
                    p.Message("%WLoading latest backup failed too.");
                }
            }
            else
            {
                p.Message("%WLatest backup of {0} does not exist.", map);
            }
            return(lvl);
        }
Esempio n. 4
0
        static Level ReadLevel(Player p, string map)
        {
            Level lvl = Level.Load(map);

            if (lvl != null)
            {
                return(lvl);
            }

            string path = LevelInfo.MapPath(map) + ".backup";

            if (!File.Exists(path))
            {
                p.Message("Level \"{0}\" does not exist", map); return(lvl);
            }
            lvl = ReadBackup(p, map, path, "backup copy");
            if (lvl != null)
            {
                return(lvl);
            }

            path = Paths.PrevMapFile(map);
            lvl  = ReadBackup(p, map, path, "previous save");
            if (lvl != null)
            {
                return(lvl);
            }

            string backupDir = LevelInfo.BackupBasePath(map);

            if (Directory.Exists(backupDir))
            {
                int latest = LevelInfo.LatestBackup(map);
                path = LevelInfo.BackupFilePath(map, latest.ToString());
                lvl  = ReadBackup(p, map, path, "latest backup");
            }
            else
            {
                p.Message("&WLatest backup of {0} does not exist.", map);
            }
            return(lvl);
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
        public static void OutputBackups(Player p, string map, LevelConfig cfg)
        {
            map = map.ToLower();
            string root = LevelInfo.BackupBasePath(map);
            string name = cfg.Color + map;

            if (!Directory.Exists(root))
            {
                p.Message(name + " &Shas no backups yet"); return;
            }

            string[] backups = Directory.GetDirectories(root);
            p.Message(name + " &Shas &b" + backups.Length + " &Sbackups");
            int           count  = 0;
            StringBuilder custom = new StringBuilder();

            foreach (string path in backups)
            {
                string restore = LevelInfo.BackupNameFrom(path);
                int    num;
                if (int.TryParse(restore, out num))
                {
                    continue;
                }

                count++;
                custom.Append(", " + restore);
            }

            if (count == 0)
            {
                return;
            }
            p.Message("&b" + count + " &Sof these are custom-named restores:");
            p.Message(custom.ToString(2, custom.Length - 2));
        }