async Task DownloadLatestClient() { Console.Write("Grabbing latest modpack info... "); ModpackInfo latest; try { latest = await OPdater.GetLatestModpackInfo(); } catch { Console.WriteLine("ERROR"); return; } Console.WriteLine("DONE"); var toDownload = new List <Tuple <Mod, Mod> >(); var toDownloadOptional = new List <Mod>(); var toDelete = new List <Mod>(); BuildModUpdateLists(latest, toDownload, toDownloadOptional, toDelete); if (toDownloadOptional.Count > 0) { Console.WriteLine(); SelectOptional(toDownloadOptional); foreach (var mod in toDownloadOptional) { if (mod.Enabled) { toDownload.Add(Tuple.Create(mod, (Mod)null)); } } Console.WriteLine(); } if (toDownload.Count > 0) { Console.WriteLine("Downloading mods..."); await DownloadMods(toDownload); } Console.Write("Updating local git repository... "); await OPdater.CloneOrUpdate(); Console.WriteLine("DONE"); UpdateMods(toDownload, toDelete); }
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(); } }