void BuildModUpdateLists(ModpackInfo latest, List <Tuple <Mod, Mod> > toDownload, List <Mod> toDownloadOptional, List <Mod> toDelete) { var compare = latest.Compare(OPdater.CurrentModpackInfo); foreach (var newOldPair in compare) { var newMod = newOldPair.Item1; var oldMod = newOldPair.Item2; if ((newMod != null) && (IsServer ? newMod.Server : newMod.Client)) { if ((oldMod == null) || (newMod.URL != oldMod.URL)) { if (!newMod.Optional) { toDownload.Add(Tuple.Create(newMod, oldMod)); } else if ((oldMod == null) && (toDownloadOptional != null)) { toDownloadOptional.Add(newMod); } } } else if ((oldMod != null) && oldMod.Exists) { toDelete.Add(oldMod); } } }
public async Task <ModpackInfo> GetLatestModpackInfo() { if (Repository == null) { return(await DownloadLatestModpackInfo()); } return(await Task.Run(() => { var id = Repository.Resolve("origin/" + Settings.Branch); ObjectReader reader = null; try { reader = Repository.NewObjectReader(); var walk = new RevWalk(reader); var commit = walk.ParseCommit(id); var treeWalk = TreeWalk.ForPath(reader, ModpackInfo.FileName, commit.Tree); if (treeWalk == null) { return null; } byte[] data = reader.Open(treeWalk.GetObjectId(0)).GetBytes(); var modpackJson = Encoding.UTF8.GetString(data); return ModpackInfo.Parse(modpackJson); } finally { if (reader != null) { reader.Release(); } } })); }
public override int UninstallModWithTask(Service service, GenericMod gameMod) { var provider = new TCAdminCustomMods.Providers.MinecraftModpacksProvider(); var modpack = (MinecraftModpacksBrowser)gameMod; var task = new TCAdmin.TaskScheduler.ModuleApi.TaskInfo(); task.DisplayName = string.Format("Uninstall {0} on {1}", modpack.Name, service.ConnectionInfo); task.CreatedBy = TCAdmin.SDK.Session.GetCurrentUser().UserId; task.UserId = service.UserId; task.Source = service.GetType().ToString(); task.SourceId = service.ServiceId.ToString(); task.RunNow = true; var arguments = new ModpackInfo() { ServiceId = service.ServiceId, ModpackId = int.Parse(modpack.Id), VersionId = int.Parse(provider.GetInstalledPlugins(service).SingleOrDefault(mp => mp.StartsWith(string.Format("MCMP{0}:", modpack.Id))).Split(':')[1]), Type = System.Web.HttpContext.Current.Request.Form["type"] ?? "ftb", RedirectUrl = System.Web.HttpContext.Current.Request.Form["redirect"] }; var taskstep = new TCAdmin.TaskScheduler.ModuleApi.StepInfo(); taskstep.ModuleId = "b48cfbc9-7acc-4980-89c4-2b6a1f784aa0"; taskstep.ProcessId = 2; taskstep.ServerId = service.ServerId; taskstep.DisplayName = string.Empty; taskstep.Arguments = TCAdmin.SDK.Misc.ObjectXml.ObjectToXml(arguments); task.AddStep(taskstep); return(task.CreateTask(service.ServerId).TaskId); }
public async Task <ModpackInfo> DownloadLatestModpackInfo() { var client = new GitHubClient(new ProductHeaderValue("PackOPdater")); var path = ModpackInfo.FileName + "?ref=" + Settings.Branch; var contents = await client.Repository.Content.GetAllContents(Settings.Owner, Settings.Repository, path); return(ModpackInfo.Parse(contents[0].Content)); }
public override int InstallModWithTask(Service service, GenericMod gameMod) { var game = new TCAdmin.GameHosting.SDK.Objects.Game(service.GameId); var providers = CustomModBase.GetCustomModBases(); var provider = providers.SingleOrDefault(p => p.Id == 3); var config = provider.GetConfigurationForGame(game).ToObject <Configurations.MinecraftModpacksConfiguration>(); var modpack = (MinecraftModpacksBrowser)gameMod; var installed = this.GetInstalledPlugins(service); if (installed.Count > 0) { var mpid = installed[0].Replace("MCMP", string.Empty); mpid = mpid.Substring(0, mpid.IndexOf(":")); var other = MinecraftModpacksBrowser.GetPack(int.Parse(mpid)); if (other.Id != modpack.Id) { //Get it from the if (other.Status == "error") { other = MinecraftModpacksBrowser.GetCurseforgePack(int.Parse(mpid)); } throw new Exception(string.Format("Only one modpack can be installed at a time. Please uninstall {0}.", other.Name)); } } var task = new TCAdmin.TaskScheduler.ModuleApi.TaskInfo(); task.DisplayName = string.Format("Install {0} on {1}", modpack.Name, service.ConnectionInfo); task.CreatedBy = TCAdmin.SDK.Session.GetCurrentUser().UserId; task.UserId = service.UserId; task.Source = service.GetType().ToString(); task.SourceId = service.ServiceId.ToString(); task.RunNow = true; var arguments = new ModpackInfo() { ServiceId = service.ServiceId, ModpackId = int.Parse(modpack.Id), VersionId = int.Parse(System.Web.HttpContext.Current.Request.Form["version"]), Type = System.Web.HttpContext.Current.Request.Form["type"] ?? "ftb", ModLoader = System.Web.HttpContext.Current.Request.Form["modloader"] ?? "auto", RedirectUrl = System.Web.HttpContext.Current.Request.Form["redirect"], JarVariable = config.JarVariableName ?? "customjar" }; var taskstep = new TCAdmin.TaskScheduler.ModuleApi.StepInfo(); taskstep.ModuleId = "b48cfbc9-7acc-4980-89c4-2b6a1f784aa0"; taskstep.ProcessId = 1; taskstep.ServerId = service.ServerId; taskstep.DisplayName = string.Empty; taskstep.Arguments = TCAdmin.SDK.Misc.ObjectXml.ObjectToXml(arguments); task.AddStep(taskstep); return(task.CreateTask(service.ServerId).TaskId); }
public OPdater(string directory) { Location = directory; Settings = AppSettings.Load(); CurrentModpackInfo = ModpackInfo.Load(directory); if (Directory.Exists(Path.Combine(Location, ".git"))) { Repository = Git.Open(Location).GetRepository(); } }
public async Task CloneOrUpdate() { await((Repository == null) ? Clone() : Update()); CurrentModpackInfo = ModpackInfo.Load(Location); }
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(); } }