Ejemplo n.º 1
0
        public static void CheckForUpdates(Action <bool> callback)
        {
            if (!Directory.Exists("Restarter"))
            {
                Directory.CreateDirectory("Restarter");
            }
            UpdateInformation information = GetInformation();

            if (!information.needsUpdate)
            {
                Logger.LogInfo($"Oxide is up to date.\n * Found Version: {information.currentVersion}\n * Latest Version: {information.latestVersion}");
                callback.Invoke(false);
                return;
            }
            Logger.LogWarning($"Oxide is out of date.\n * Found Version: {information.currentVersion}\n * Latest Version: {information.latestVersion}");
            SlackManager.SendSlackMessage("Check", $"Oxide is out of date.\n * Found Version: {information.currentVersion}\n * Latest Version: {information.latestVersion}", "Updating");
            Thread thread = new Thread(() =>
            {
                using (WebClient wc = new WebClient())
                {
                    wc.DownloadProgressChanged += DownloadChanged;
                    wc.DownloadFileCompleted   += DownloadCompleted;
                    wc.DownloadFileAsync(new Uri("https://github.com/OxideMod/Oxide/releases/download/latest/Oxide-Rust.zip"), "Restarter/OxideRecent.zip");
                }
            });

            thread.Start();
            ProgressManager.CreateBar("Downloading Oxide", () => {
                Logger.LogInfo("\nDownload Completed");
                thread.Abort();
                thread = new Thread(() =>
                {
                    using (ZipFile zip = ZipFile.Read("Restarter/OxideRecent.zip"))
                    {
                        int run = 0;
                        foreach (ZipEntry e in zip)
                        {
                            if (e.FileName.Contains("start-example"))
                            {
                                continue;
                            }
                            run++;
                            ProgressManager.UpdateBar(zip.EntryFileNames.Count() / run * 100);
                            e.Extract(Directory.GetCurrentDirectory(), ExtractExistingFileAction.OverwriteSilently);
                        }
                        ProgressManager.StopBar();
                    }
                });
                thread.Start();
                ProgressManager.CreateBar("Extracting Files", () =>
                {
                    Logger.LogInfo("\nUpdate completed.Starting server.");
                    callback.Invoke(true);
                    thread.Abort();
                });
            });
        }
Ejemplo n.º 2
0
        public static void StartServer()
        {
            IniFile file = new IniFile("restarter.ini");

            ServerThread = new Thread(() =>
            {
                Server = Process.GetProcessesByName("RustDedicated").FirstOrDefault();
                if (Server == null)
                {
                    Server = new Process();
                    Server.StartInfo.WorkingDirectory = file.Read("ServerPath", "ServerInformation");
                    Server.StartInfo.FileName         = file.Read("BatchFile", "ServerInformation");
                    Server.Start();
                    CPUHelper.StartCounting();
                    SlackManager.SendSlackMessage("Started", $"The server has successfully started at {DateTime.Now.ToString("h: mm:ss tt")}.", "Information");
                    Logger.LogInfo("Server Started Successfully.");
                }
                Server.WaitForExit();
                SlackManager.SendSlackMessage("Shutdown", $"The server has shutdown at {DateTime.Now.ToString("h: mm:ss tt")}. Restarting.", "Information");
                Logger.LogWarning("Server Shut Down - Ending task and restarting.");
                RestartServer();
            });
            ServerThread.Start();
        }