private static int?PerformServiceShellTasksFor <T>(T instance, CommandlineOptions cli) where T : Shell, new() { if (cli.ExitCode == CommandlineOptions.ExitCodes.ShowedHelp) { return((int)cli.ExitCode); } var task = ShellTasks.FirstOrDefault(t => t.Selector(cli)); return(task?.Logic.Invoke(cli, instance)); }
private void handleModDownload(bool install = false) { using (var tasker = new Tasks.Tasker(parentForm)) using (var taskerForm = new TaskerForm()) { tasker.AttachViews(new TaskerTaskbar(), taskerForm); tasker.SetStatusImage(Resources.sign_cogs); tasker.SetTitle(Resources.Processing); List <string> selectedMods = new List <string>(); foreach (ListViewItem item in modList.SelectedItems) { var mod = (Repository.Repository.Item)(item.Tag); tasker.AddTasks(GetItemDownloadTask(mod)); if (mod.Kind == Repository.Repository.ItemKind.Hmod) { selectedMods.Add(mod.RawName); } } if (install && selectedMods.Count > 0) { tasker.AddTasks(new MembootTasks(MembootTasks.MembootTaskType.MembootRecovery, forceRecoveryReload: false)); tasker.AddTask(ShellTasks.ShellCommand("touch /user-recovery.flag")); tasker.AddTask(ShellTasks.ShellCommand("touch /mod-recovery.flag")); tasker.AddTask(ShellTasks.MountBase); tasker.AddTask((Tasker innerTasker, object syncObject) => { tasker.AddTasks(new MembootTasks(MembootTasks.MembootTaskType.ProcessMods, selectedMods.ToArray())); return(Conclusion.Success); }); } tasker.Start(); foreach (var mod in selectedMods) { var found = installedMods.Where((o) => o.RawName.Equals(mod, System.StringComparison.CurrentCultureIgnoreCase)).ToArray(); foreach (var foundMod in found) { installedMods.Remove(foundMod); } } installedMods.AddRange(Hmod.Hmod.GetMods(true, selectedMods.ToArray(), parentForm)); CoreCollection.HmodInfo = installedMods.ToArray(); CoreCollection.Load(); } }