Program(string[] args) { WorkingDir = Environment.CurrentDirectory; OPdater = new OPdater(WorkingDir); ParseArguments(args); }
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(); }
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 DownloadMods(List <Tuple <Mod, Mod> > toDownload) { await OPdater.Download(toDownload.Select(x => x.Item1), (mod, recv, total) => { var index = toDownload.IndexOf(x => (mod == x.Item1)); var oldMod = toDownload[index].Item2; var version = ((oldMod != null) ? string.Format("{0} -> {1}", oldMod.Version, mod.Version) : mod.Version); var progress = ((total > 0) ? ((double)recv / total) : 0); progress = (index + progress) / toDownload.Count * 100; lock (OPdater) { Console.Write("{0," + (1 - Console.WindowWidth) + "}", string.Format("[{0,3:0}%] {1} ({2}) [{3}/{4} KiB]", (int)progress, mod.Name, version, recv / 1024, ((total > 0) ? (total / 1024).ToString() : "???"))); Console.SetCursorPosition(0, Console.CursorTop); } }); Console.WriteLine(); }
void EnterSettings() { Console.WriteLine("Couldn't find '{0}', creating from scratch.", AppSettings.FileName); while (true) { string owner, repo; var branches = EnterRepository(out owner, out repo); OPdater.Settings.Branch = SelectBranch(branches); OPdater.Settings.Owner = owner; OPdater.Settings.Repository = repo; if (OPdater.VerifyRepository().Result) { break; } Console.WriteLine("Repository no worky! Missing '{0}' file...", ModpackInfo.FileName); Console.WriteLine(); } Console.WriteLine(); OPdater.Settings.Save(); }
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(); } }