Пример #1
0
 static void DeleteFiles(params string[] paths)
 {
     foreach (string path in paths)
     {
         AtomicIO.TryDelete(path);
     }
 }
Пример #2
0
        static string FindOldHashPath(string name)
        {
            string path = PASS_FOLDER + name + ".dat";

            if (File.Exists(path))
            {
                return(path);
            }

            // Have to fallback on this for case sensitive file systems
            string[] files = AtomicIO.TryGetFiles(PASS_FOLDER, "*.dat");
            if (files == null)
            {
                return(null);
            }

            foreach (string file in files)
            {
                if (file.CaselessEq(path))
                {
                    return(file);
                }
            }
            return(null);
        }
Пример #3
0
        public static void PerformUpdate()
        {
            try {
                try {
                    DeleteFiles("Changelog.txt", "MCGalaxy_.update", "MCGalaxy.update", "MCGalaxyCLI.update",
                                "prev_MCGalaxy_.dll", "prev_MCGalaxy.exe", "prev_MCGalaxyCLI.exe");
                } catch {
                }

                WebClient client = HttpUtil.CreateWebClient();
                client.DownloadFile(dllURL, "MCGalaxy_.update");
                client.DownloadFile(guiURL, "MCGalaxy.update");
                client.DownloadFile(cliURL, "MCGalaxyCLI.update");
                client.DownloadFile(changelogURL, "Changelog.txt");

                Level[] levels = LevelInfo.Loaded.Items;
                foreach (Level lvl in levels)
                {
                    if (!lvl.SaveChanges)
                    {
                        continue;
                    }
                    lvl.Save();
                    lvl.SaveBlockDBChanges();
                }

                Player[] players = PlayerInfo.Online.Items;
                foreach (Player pl in players)
                {
                    pl.SaveStats();
                }

                // Move current files to previous files (by moving instead of copying,
                //  can overwrite original the files without breaking the server)
                AtomicIO.TryMove("MCGalaxy_.dll", "prev_MCGalaxy_.dll");
                AtomicIO.TryMove("MCGalaxy.exe", "prev_MCGalaxy.exe");
                AtomicIO.TryMove("MCGalaxyCLI.exe", "prev_MCGalaxyCLI.exe");

                // Move update files to current files
                File.Move("MCGalaxy_.update", "MCGalaxy_.dll");
                File.Move("MCGalaxy.update", "MCGalaxy.exe");
                File.Move("MCGalaxyCLI.update", "MCGalaxyCLI.exe");

                Server.Stop(true, "Updating server.");
            } catch (Exception ex) {
                Logger.LogError("Error performing update", ex);
            }
        }