Example #1
0
        void Run()
        {
            Console.WriteLine("Pack[OP]dater - Easy modpack syncing using GitHub");
            Console.WriteLine("For more information see: http://github.com/copygirl/PackOPdater");
            Console.WriteLine();

            if (OPdater.Settings.Owner == null)
            {
                EnterSettings();
            }

            DisplayModpackInfo();

            if (IsServer)
            {
                Wrapper         = new ServerWrapper(WorkingDir, ServerJar, Arguments);
                Wrapper.Output += Console.WriteLine;

                ServerUpdateCheckerLoop().Wait();

                throw new Exception("Good job, you managed to kill the poor update checker.");
                // TODO: Figure out how to gracefully shut down this thing.
            }
            else
            {
                if (OPdater.IsUpdateAvailable().Result)
                {
                    Console.Write("> Update available, download now? ");
                    if (SelectYesNo())
                    {
                        DownloadLatestClient().Wait();
                    }
                }
                else
                {
                    Console.WriteLine("No update available.");
                }

                Console.WriteLine();
                CheckForMissingMods();
            }

            Console.WriteLine("Press any key to continue ...");
            Console.ReadKey();
        }
Example #2
0
        async Task ServerUpdateCheckerLoop(CancellationToken ct = default(CancellationToken))
        {
            while (!ct.IsCancellationRequested)
            {
                if (await OPdater.IsUpdateAvailable())
                {
                    ModpackInfo latest = await OPdater.GetLatestModpackInfo();

                    var toDownload = new List <Tuple <Mod, Mod> >();
                    var toDelete   = new List <Mod>();
                    BuildModUpdateLists(latest, toDownload, null, toDelete);

                    if (Wrapper.Running && (Wrapper.Players.Count > 0))
                    {
                        // Write a nice message to the players telling them about the new update.

                        var url = "https://github.com/" + OPdater.Settings.Owner + "/" +
                                  OPdater.Settings.Repository + "/commits/" + OPdater.Settings.Branch;

                        var lines = new List <string>();
                        lines.Add(
                            @"{""text"":""[ UPDATE!! ]"",""color"":""red"",""bold"":""true""},"" ""," +
                            @"{""text"":"" Version " + latest.Version + @""",""color"":""yellow"",""bold"":""false""},"" ""," +
                            @"{""text"":""("",""color"":""yellow"",""bold"":""false""},{""text"":""View Online"",""color"":""aqua"",""underlined"":""true"",""clickEvent"":{""action"":""open_url"",""value"":""" + url + @"""}},{""text"":"")"",""color"":""yellow"",""underlined"":""false""}");

                        var newMods     = toDownload.Where(pair => (pair.Item2 == null)).Select(pair => pair.Item1.Name).ToList();
                        var changedMods = toDownload.Where(pair => (pair.Item2 != null)).Select(pair => pair.Item1.Name).ToList();

                        if (newMods.Count > 0)
                        {
                            lines.Add(@"{""text"":""[+]"",""color"":""green"",""bold"":""true""},"" ""," +
                                      @"{""text"":""" + string.Join(", ", newMods) + @""",""color"":""yellow"",""bold"":""false""}");
                        }
                        if (changedMods.Count > 0)
                        {
                            lines.Add(@"{""text"":""[:]"",""color"":""gray"",""bold"":""true""},"" ""," +
                                      @"{""text"":""" + string.Join(", ", changedMods) + @""",""color"":""yellow"",""bold"":""false""}");
                        }
                        if (toDelete.Count > 0)
                        {
                            lines.Add(@"{""text"":""[-]"",""color"":""green"",""bold"":""true""},"" ""," +
                                      @"{""text"":""" + string.Join(", ", toDelete) + @""",""color"":""yellow"",""bold"":""false""}");
                        }

                        foreach (var line in lines)
                        {
                            Wrapper.Input("/tellraw @a [" + line + "]");
                        }
                    }

                    if (toDownload.Count > 0)
                    {
                        await OPdater.Download(toDownload.Select(x => x.Item1), null);
                    }

                    if (Wrapper.Running)
                    {
                        Wrapper.AutoRestart = false;
                        await Wrapper.Stop();
                    }

                    await OPdater.CloneOrUpdate();

                    UpdateMods(toDownload, toDelete);
                }

                if (!Wrapper.Running)
                {
                    Wrapper.AutoRestart = true;
                    Wrapper.Start();
                }

                await Task.Delay(TimeSpan.FromMinutes(2), ct);
            }

            if (Wrapper.Running)
            {
                await Wrapper.Stop();
            }
        }