public override bool UnInstallMod(Service service, GenericMod gameMod)
 {
     try
     {
         var server             = Server.GetSelectedServer();
         var modIoConfiguration = ModIoBrowser.GetModIoConfigurationForCurrentGame();
         var modForGame         = MMod.GetModForGame(modIoConfiguration.SelectedGameId, int.Parse(gameMod.Id));
         var script             = GenerateScript(service, modIoConfiguration, false);
         var modJson            = JsonConvert.SerializeObject(modForGame);
         var type = gameMod.GetType();
         server.ServerUtilitiesService.ExecuteScript(script, 1, new[]
         {
             new JsonSerializedScriptVariable
             {
                 Name  = "Mod",
                 Value = modJson,
                 Type  = type.FullNameWithAssembly()
             }
         });
         return(true);
     }
     catch (Exception e)
     {
         _logger.LogException(e);
         return(false);
     }
 }
            private async Task ForceDisable([CanBeNull] GenericMod mod, CancellationToken token)
            {
                if (mod == null || !mod.IsEnabled)
                {
                    return;
                }

                if (mod.DependsOn != null)
                {
                    foreach (var dependancy in mod.DependsOn)
                    {
                        await ForceDisable(Enabler.GetByName(dependancy), token);

                        if (token.IsCancellationRequested)
                        {
                            return;
                        }
                    }
                }

                await Enabler.DisableAsync(mod, cancellation : token);

                if (!token.IsCancellationRequested)
                {
                    _disabled.Add(mod.DisplayName);
                }
            }
            public Task EnableMod(GenericMod mod)
            {
                return(_busy.Task(async() => {
                    if (_enabler == null || mod.IsEnabled)
                    {
                        return;
                    }

                    var conflicts = await _enabler.CheckConflictsAsync(mod);
                    if (conflicts.Length > 0 && ModernDialog.ShowMessage(
                            conflicts.Select(x => $@"• “{Path.GetFileName(x.RelativeName)}” has already been altered by the “{x.ModName}” mod;")
                            .JoinToString("\n").ToSentence
                                () + $"\n\nEnabling {BbCodeBlock.Encode(mod.DisplayName)} may have adverse effects. Are you sure you want to enable this mod?",
                            "Conflict", MessageBoxButton.YesNo, "genericMods.conflict") != MessageBoxResult.Yes)
                    {
                        return;
                    }

                    try {
                        using (var waiting = WaitingDialog.Create("Enabling mod…")) {
                            await _enabler.EnableAsync(mod, waiting, waiting.CancellationToken);
                            Changed?.Invoke(this, EventArgs.Empty);

                            if (waiting.CancellationToken.IsCancellationRequested)
                            {
                                waiting.Report(AsyncProgressEntry.FromStringIndetermitate("Cancellation…"));
                                await _enabler.DisableAsync(mod);
                            }
                        }
                    } catch (Exception e) {
                        NonfatalError.Notify("Can’t enable mod", e);
                    }
                }));
            }
        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 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);
        }
示例#6
0
        public override bool UnInstallMod(Service service, GenericMod gameMod)
        {
            var server          = Server.GetSelectedServer();
            var fileSystem      = server.FileSystemService;
            var detailedModData = DetailedModData.GetDetailedModData(gameMod.Id);
            var combinePath     = TCAdmin.SDK.Misc.FileSystem.CombinePath(server.OperatingSystem, service.RootDirectory,
                                                                          "oxide", "plugins", detailedModData.Name + ".cs");

            fileSystem.DeleteFile(combinePath);

            return(true);
        }
示例#7
0
        public override bool UnInstallMod(Service service, GenericMod gameMod)
        {
            var server     = new Server(service.ServerId);
            var fileSystem = server.FileSystemService;
            var mod        = CurseBrowser.GetMod(int.Parse(gameMod.Id));
            var file       = mod.LatestFiles.FirstOrDefault(x => x.FileName.EndsWith(".jar"));

            if (file == null)
            {
                throw new NullReferenceException("Could not find mod file compatible with installed minecraft version");
            }
            var modsDirectory = FileSystem.CombinePath(server.OperatingSystem, service.RootDirectory, "mods");
            var saveTo        = FileSystem.CombinePath(server.OperatingSystem, modsDirectory, file.FileName);

            fileSystem.DeleteFile(saveTo);
            return(true);
        }
            public Task DisableMod(GenericMod mod)
            {
                return(_busy.Task(async() => {
                    if (_enabler == null || !mod.IsEnabled)
                    {
                        return;
                    }

                    try {
                        using (var waiting = WaitingDialog.Create("Disabling mod…")) {
                            await _enabler.DisableAsync(mod, waiting, waiting.CancellationToken);
                            Changed?.Invoke(this, EventArgs.Empty);

                            if (waiting.CancellationToken.IsCancellationRequested)
                            {
                                waiting.Report(AsyncProgressEntry.FromStringIndetermitate("Cancellation…"));
                                await _enabler.EnableAsync(mod);
                            }
                        }
                    } catch (Exception e) {
                        NonfatalError.Notify("Can’t disable mod", e);
                    }
                }));
            }
 public override int UninstallModWithTask(Service service, GenericMod gameMod)
 {
     throw new NotImplementedException();
 }
 public abstract int UninstallModWithTask(Service service, GenericMod gameMod);
 public abstract bool UnInstallMod(Service service, GenericMod gameMod);
 public virtual void PostUninstallMod(Service service, GenericMod gameMod)
 {
 }
 public override bool InstallMod(Service service, GenericMod gameMod)
 {
     throw new NotImplementedException();
 }