コード例 #1
0
        public void Save(bool Override = false, bool clearPhysics = false)
        {
            if (blocks == null)
            {
                return;
            }
            string path = LevelInfo.LevelPath(name);

            if (LevelSave != null)
            {
                LevelSave(this);
            }
            OnLevelSaveEvent.Call(this);
            if (cancelsave1)
            {
                cancelsave1 = false; return;
            }
            if (cancelsave)
            {
                cancelsave = false; return;
            }

            try {
                if (!Directory.Exists("levels"))
                {
                    Directory.CreateDirectory("levels");
                }
                if (!Directory.Exists("levels/level properties"))
                {
                    Directory.CreateDirectory("levels/level properties");
                }
                if (!Directory.Exists("levels/prev"))
                {
                    Directory.CreateDirectory("levels/prev");
                }

                if (changed || !File.Exists(path) || Override || (physicschanged && clearPhysics))
                {
                    lock (saveLock)
                        SaveCore(path);

                    if (clearPhysics)
                    {
                        ClearPhysics();
                    }
                }
                else
                {
                    Server.s.Log("Skipping level save for " + name + ".");
                }
            } catch (Exception e) {
                Server.s.Log("FAILED TO SAVE :" + name);
                Chat.MessageAll("FAILED TO SAVE {0}", ColoredName);
                Server.ErrorLog(e);
            }
            GC.Collect();
            GC.WaitForPendingFinalizers();
        }
コード例 #2
0
ファイル: Level.cs プロジェクト: DiresHosting/MCDire
        public bool Save(bool force = false, bool clearPhysics = false)
        {
            if (blocks == null || IsMuseum)
            {
                return(false);                            // museums do not save properties
            }
            string path = LevelInfo.MapPath(MapName);

            OnLevelSaveEvent.Call(this);
            if (cancelsave)
            {
                cancelsave = false; return(false);
            }

            try {
                if (!Directory.Exists("levels"))
                {
                    Directory.CreateDirectory("levels");
                }
                if (!Directory.Exists("levels/level properties"))
                {
                    Directory.CreateDirectory("levels/level properties");
                }
                if (!Directory.Exists("levels/prev"))
                {
                    Directory.CreateDirectory("levels/prev");
                }

                if (Changed || !File.Exists(path) || force || (physicschanged && clearPhysics))
                {
                    lock (saveLock) SaveCore(path);
                    if (clearPhysics)
                    {
                        ClearPhysics();
                    }
                }
                else
                {
                    Logger.Log(LogType.SystemActivity, "Skipping level save for " + name + ".");
                }
            } catch (Exception e) {
                Logger.Log(LogType.Warning, "FAILED TO SAVE :" + name);
                Chat.MessageGlobal("FAILED TO SAVE {0}", ColoredName);
                Logger.LogError(e);
                return(false);
            }
            Server.DoGC();
            return(true);
        }
コード例 #3
0
        public void Save(bool Override = false, bool clearPhysics = false)
        {
            if (blocks == null)
            {
                return;
            }
            string path = LevelInfo.LevelPath(name);

            if (LevelSave != null)
            {
                LevelSave(this);
            }
            OnLevelSaveEvent.Call(this);
            if (cancelsave1)
            {
                cancelsave1 = false; return;
            }
            if (cancelsave)
            {
                cancelsave = false; return;
            }

            try
            {
                if (!Directory.Exists("levels"))
                {
                    Directory.CreateDirectory("levels");
                }
                if (!Directory.Exists("levels/level properties"))
                {
                    Directory.CreateDirectory("levels/level properties");
                }

                if (changed || !File.Exists(path) || Override || (physicschanged && clearPhysics))
                {
                    if (clearPhysics)
                    {
                        ClearPhysics();
                    }

                    if (File.Exists(path))
                    {
                        if (File.Exists(path + ".prev"))
                        {
                            File.Delete(path + ".prev");
                        }
                        File.Copy(path, path + ".prev");
                        File.Delete(path);
                    }
                    LvlFile.Save(this, path + ".backup");
                    File.Copy(path + ".backup", path);
                    SaveSettings(this);

                    Server.s.Log(string.Format("SAVED: Level \"{0}\". ({1}/{2}/{3})", name, players.Count,
                                               PlayerInfo.Online.Count, Server.players));
                    changed = false;
                }
                else
                {
                    Server.s.Log("Skipping level save for " + name + ".");
                }
            }
            catch (OutOfMemoryException e)
            {
                Server.ErrorLog(e);
                if (Server.mono)
                {
                    Process[] prs = Process.GetProcesses();
                    foreach (Process pr in prs)
                    {
                        if (pr.ProcessName == "MCGalaxy")
                        {
                            pr.Kill();
                        }
                    }
                }
                else
                {
                    Command.all.Find("restart").Use(null, "");
                }
            } catch (Exception e) {
                Server.s.Log("FAILED TO SAVE :" + name);
                Player.GlobalMessage("FAILED TO SAVE :" + name);
                Server.ErrorLog(e);
            }
            GC.Collect();
            GC.WaitForPendingFinalizers();
        }