예제 #1
0
파일: Level.cs 프로젝트: 8cta/MCGalaxy
        /// <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);
        }
예제 #2
0
파일: Level.cs 프로젝트: ProtheanGod/KingMC
        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);
        }
예제 #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);
        }
예제 #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);
        }