示例#1
0
文件: Main.cs 项目: zicrog/CKAN
        /// <summary>
        /// Run whatever action the user has provided
        /// </summary>
        /// <returns>The exit status that should be returned to the system.</returns>
        private static int RunSimpleAction(Options cmdline, CommonOptions options, string[] args, IUser user, KSPManager manager)
        {
            try
            {
                switch (cmdline.action)
                {
                case "gui":
                    return(Gui(manager, (GuiOptions)options, args));

                case "consoleui":
                    return(ConsoleUi(manager, options, args));

                case "prompt":
                    return(new Prompt().RunCommand(manager, cmdline.options));

                case "version":
                    return(Version(user));

                case "update":
                    return((new Update(manager, user)).RunCommand(GetGameInstance(manager), cmdline.options));

                case "available":
                    return((new Available(user)).RunCommand(GetGameInstance(manager), cmdline.options));

                case "add":
                case "install":
                    Scan(GetGameInstance(manager), user, cmdline.action);
                    return((new Install(manager, user)).RunCommand(GetGameInstance(manager), cmdline.options));

                case "scan":
                    return(Scan(GetGameInstance(manager), user));

                case "list":
                    return((new List(user)).RunCommand(GetGameInstance(manager), cmdline.options));

                case "show":
                    return((new Show(user)).RunCommand(GetGameInstance(manager), cmdline.options));

                case "replace":
                    Scan(GetGameInstance(manager), user, cmdline.action);
                    return((new Replace(manager, user)).RunCommand(GetGameInstance(manager), (ReplaceOptions)cmdline.options));

                case "upgrade":
                    Scan(GetGameInstance(manager), user, cmdline.action);
                    return((new Upgrade(manager, user)).RunCommand(GetGameInstance(manager), cmdline.options));

                case "search":
                    return((new Search(user)).RunCommand(GetGameInstance(manager), options));

                case "uninstall":
                case "remove":
                    return((new Remove(manager, user)).RunCommand(GetGameInstance(manager), cmdline.options));

                case "import":
                    return((new Import(manager, user)).RunCommand(GetGameInstance(manager), options));

                case "clean":
                    return(Clean(manager.Cache));

                case "compare":
                    return((new Compare(user)).RunCommand(cmdline.options));

                default:
                    user.RaiseMessage("Unknown command, try --help");
                    return(Exit.BADOPT);
                }
            }
            catch (NoGameInstanceKraken)
            {
                return(printMissingInstanceError(user));
            }
            finally
            {
                RegistryManager.DisposeAll();
            }
        }
示例#2
0
文件: KSP.cs 项目: zicrog/CKAN
        // This is required by ISubCommand
        public int RunSubCommand(KSPManager manager, CommonOptions opts, SubCommandOptions unparsed)
        {
            string[] args = unparsed.options.ToArray();

            #region Aliases

            for (int i = 0; i < args.Length; i++)
            {
                switch (args[i])
                {
                case "use":
                    args[i] = "default";
                    break;

                default:
                    break;
                }
            }

            #endregion

            int exitCode = Exit.OK;
            // Parse and process our sub-verbs
            Parser.Default.ParseArgumentsStrict(args, new KSPSubOptions(), (string option, object suboptions) =>
            {
                // ParseArgumentsStrict calls us unconditionally, even with bad arguments
                if (!string.IsNullOrEmpty(option) && suboptions != null)
                {
                    CommonOptions options = (CommonOptions)suboptions;
                    options.Merge(opts);
                    User     = new ConsoleUser(options.Headless);
                    Manager  = manager ?? new KSPManager(User);
                    exitCode = options.Handle(Manager, User);
                    if (exitCode != Exit.OK)
                    {
                        return;
                    }

                    switch (option)
                    {
                    case "list":
                        exitCode = ListInstalls();
                        break;

                    case "add":
                        exitCode = AddInstall((AddOptions)suboptions);
                        break;

                    case "clone":
                        exitCode = CloneInstall((CloneOptions)suboptions);
                        break;

                    case "rename":
                        exitCode = RenameInstall((RenameOptions)suboptions);
                        break;

                    case "forget":
                        exitCode = ForgetInstall((ForgetOptions)suboptions);
                        break;

                    case "use":
                    case "default":
                        exitCode = SetDefaultInstall((DefaultOptions)suboptions);
                        break;

                    case "fake":
                        exitCode = FakeNewKSPInstall((FakeOptions)suboptions);
                        break;

                    default:
                        User.RaiseMessage("Unknown command: ksp {0}", option);
                        exitCode = Exit.BADOPT;
                        break;
                    }
                }
            }, () => { exitCode = MainClass.AfterHelp(); });
            return(exitCode);
        }
示例#3
0
 public KSP(KSPManager manager, IUser user)
 {
     Manager = manager;
     User    = user;
 }
示例#4
0
文件: Repo.cs 项目: trakos/CFAN
 public Repo(KSPManager manager, IUser user)
 {
     Manager = manager;
     User    = user;
 }
示例#5
0
        /// <summary>
        /// Initialize the screen
        /// </summary>
        /// <param name="mgr">KSP manager object containing the current instance</param>
        /// <param name="dbg">True if debug options should be available, false otherwise</param>
        public ModListScreen(KSPManager mgr, bool dbg)
        {
            debug    = dbg;
            manager  = mgr;
            registry = RegistryManager.Instance(manager.CurrentInstance).registry;

            moduleList = new ConsoleListBox <CkanModule>(
                1, 4, -1, -2,
                GetAllMods(),
                new List <ConsoleListBoxColumn <CkanModule> >()
            {
                new ConsoleListBoxColumn <CkanModule>()
                {
                    Header   = "",
                    Width    = 1,
                    Renderer = StatusSymbol
                }, new ConsoleListBoxColumn <CkanModule>()
                {
                    Header   = "Name",
                    Width    = 44,
                    Renderer = m => m.name ?? ""
                }, new ConsoleListBoxColumn <CkanModule>()
                {
                    Header   = "Version",
                    Width    = 10,
                    Renderer = m => ModuleInstaller.StripEpoch(m.version?.ToString() ?? ""),
                    Comparer = (a, b) => a.version.CompareTo(b.version)
                }, new ConsoleListBoxColumn <CkanModule>()
                {
                    Header   = "Max KSP version",
                    Width    = 17,
                    Renderer = m => registry.LatestCompatibleKSP(m.identifier)?.ToString() ?? "",
                    Comparer = (a, b) => registry.LatestCompatibleKSP(a.identifier).CompareTo(registry.LatestCompatibleKSP(b.identifier))
                }
            },
                1, 0, ListSortDirection.Descending,
                (CkanModule m, string filter) => {
                if (filter.StartsWith("@"))
                {
                    string authorFilt = filter.Substring(1);
                    if (string.IsNullOrEmpty(authorFilt))
                    {
                        return(true);
                    }
                    else if (m.author != null)
                    {
                        foreach (string auth in m.author)
                        {
                            if (auth.IndexOf(authorFilt, StringComparison.CurrentCultureIgnoreCase) == 0)
                            {
                                return(true);
                            }
                        }
                    }
                    return(false);
                }
                else if (filter.StartsWith("~"))
                {
                    if (filter.Length <= 1)
                    {
                        // Don't blank the list for just "~" by itself
                        return(true);
                    }
                    else
                    {
                        switch (filter.Substring(1, 1))
                        {
                        case "i":
                            return(registry.IsInstalled(m.identifier, false));

                        case "u":
                            return(registry.HasUpdate(m.identifier, manager.CurrentInstance.VersionCriteria()));

                        case "n":
                            // Filter new
                            return(recent.Contains(m.identifier));

                        case "c":
                            if (m.conflicts != null)
                            {
                                string conflictsWith = filter.Substring(2);
                                // Search for mods depending on a given mod
                                foreach (var rel in m.conflicts)
                                {
                                    if (rel.name.IndexOf(conflictsWith, StringComparison.CurrentCultureIgnoreCase) == 0)
                                    {
                                        return(true);
                                    }
                                }
                            }
                            return(false);

                        case "d":
                            if (m.depends != null)
                            {
                                string dependsOn = filter.Substring(2);
                                // Search for mods depending on a given mod
                                foreach (var rel in m.depends)
                                {
                                    if (rel.name.IndexOf(dependsOn, StringComparison.CurrentCultureIgnoreCase) == 0)
                                    {
                                        return(true);
                                    }
                                }
                            }
                            return(false);
                        }
                    }
                    return(false);
                }
                else
                {
                    return(m.identifier.IndexOf(filter, StringComparison.CurrentCultureIgnoreCase) >= 0 ||
                           m.name.IndexOf(filter, StringComparison.CurrentCultureIgnoreCase) >= 0 ||
                           [email protected](filter, StringComparison.CurrentCultureIgnoreCase) >= 0);
                }
            }
                );

            searchBox = new ConsoleField(-searchWidth, 2, -1)
            {
                GhostText = () => Focused() == searchBox
                    ? "<Type to search>"
                    : "<Ctrl+F to search>"
            };
            searchBox.OnChange += (ConsoleField sender, string newValue) => {
                moduleList.FilterString = newValue;
            };

            AddObject(new ConsoleLabel(
                          1, 2, -searchWidth - 2,
                          () => $"{moduleList.VisibleRowCount()} mods"
                          ));
            AddObject(searchBox);
            AddObject(moduleList);

            AddBinding(Keys.CtrlQ, (object sender) => false);
            AddBinding(Keys.AltX, (object sender) => false);
            AddBinding(Keys.F1, (object sender) => Help());
            AddBinding(Keys.AltH, (object sender) => Help());
            AddBinding(Keys.F5, (object sender) => UpdateRegistry());
            AddBinding(Keys.CtrlR, (object sender) => UpdateRegistry());
            AddBinding(Keys.CtrlU, (object sender) => UpgradeAll());

            // Now a bunch of convenience shortcuts so you don't get stuck in the search box
            searchBox.AddBinding(Keys.PageUp, (object sender) => {
                SetFocus(moduleList);
                return(true);
            });
            searchBox.AddBinding(Keys.PageDown, (object sender) => {
                SetFocus(moduleList);
                return(true);
            });
            searchBox.AddBinding(Keys.Enter, (object sender) => {
                SetFocus(moduleList);
                return(true);
            });

            moduleList.AddBinding(Keys.CtrlF, (object sender) => {
                SetFocus(searchBox);
                return(true);
            });
            moduleList.AddBinding(Keys.Escape, (object sender) => {
                searchBox.Clear();
                return(true);
            });

            moduleList.AddTip("Enter", "Details",
                              () => moduleList.Selection != null
                              );
            moduleList.AddBinding(Keys.Enter, (object sender) => {
                if (moduleList.Selection != null)
                {
                    LaunchSubScreen(new ModInfoScreen(manager, plan, moduleList.Selection, debug));
                }
                return(true);
            });

            // Conditionally show only one of these based on selected mod status

            moduleList.AddTip("+", "Install",
                              () => moduleList.Selection != null &&
                              !registry.IsInstalled(moduleList.Selection.identifier, false)
                              );
            moduleList.AddTip("+", "Upgrade",
                              () => moduleList.Selection != null &&
                              registry.HasUpdate(moduleList.Selection.identifier, manager.CurrentInstance.VersionCriteria())
                              );
            moduleList.AddBinding(Keys.Plus, (object sender) => {
                if (moduleList.Selection != null)
                {
                    if (!registry.IsInstalled(moduleList.Selection.identifier, false))
                    {
                        plan.ToggleInstall(moduleList.Selection);
                    }
                    else if (registry.IsInstalled(moduleList.Selection.identifier, false) &&
                             registry.HasUpdate(moduleList.Selection.identifier, manager.CurrentInstance.VersionCriteria()))
                    {
                        plan.ToggleUpgrade(moduleList.Selection);
                    }
                }
                return(true);
            });

            moduleList.AddTip("-", "Remove",
                              () => moduleList.Selection != null &&
                              (registry.IsInstalled(moduleList.Selection.identifier, false))
                              );
            moduleList.AddBinding(Keys.Minus, (object sender) => {
                if (moduleList.Selection != null && registry.IsInstalled(moduleList.Selection.identifier, false))
                {
                    plan.ToggleRemove(moduleList.Selection);
                }
                return(true);
            });

            AddTip("F9", "Apply changes", plan.NonEmpty);
            AddBinding(Keys.F9, (object sender) => {
                ApplyChanges();
                return(true);
            });

            // Show total download size of all installed mods
            AddObject(new ConsoleLabel(
                          1, -1, searchWidth,
                          () => $"{CkanModule.FmtSize(totalInstalledDownloadSize())} installed",
                          null,
                          () => ConsoleTheme.Current.DimLabelFg
                          ));

            AddObject(new ConsoleLabel(
                          -searchWidth, -1, -2,
                          () => {
                int days = daysSinceUpdated(registryFilePath());
                return(days < 1 ? ""
                        :  days == 1 ? $"Updated at least {days} day ago"
                        :              $"Updated at least {days} days ago");
            },
                          null,
                          () => {
                int daysSince = daysSinceUpdated(registryFilePath());
                if (daysSince < daysTillStale)
                {
                    return(ConsoleTheme.Current.RegistryUpToDate);
                }
                else if (daysSince < daystillVeryStale)
                {
                    return(ConsoleTheme.Current.RegistryStale);
                }
                else
                {
                    return(ConsoleTheme.Current.RegistryVeryStale);
                }
            }
                          ));

            List <ConsoleMenuOption> opts = new List <ConsoleMenuOption>()
            {
                new ConsoleMenuOption("Sort...", "",
                                      "Change the sorting of the list of mods",
                                      true, null, null, moduleList.SortMenu()),
                null,
                new ConsoleMenuOption("Refresh mod list", "F5, Ctrl+R",
                                      "Refresh the list of mods",
                                      true, UpdateRegistry),
                new ConsoleMenuOption("Upgrade all", "Ctrl+U",
                                      "Mark all available updates for installation",
                                      true, UpgradeAll),
                new ConsoleMenuOption("Audit recommendations", "",
                                      "List mods suggested and recommended by installed mods",
                                      true, ViewSuggestions),
                new ConsoleMenuOption("Scan KSP dir", "",
                                      "Check for manually installed mods",
                                      true, ScanForMods),
                new ConsoleMenuOption("Import downloads...", "",
                                      "Select manually downloaded mods to import into CKAN",
                                      true, ImportDownloads),
                new ConsoleMenuOption("Export installed...", "",
                                      "Save your mod list",
                                      true, ExportInstalled),
                null,
                new ConsoleMenuOption("Select KSP install...", "",
                                      "Switch to a different game instance",
                                      true, SelectInstall),
                new ConsoleMenuOption("Authentication tokens...", "",
                                      "Edit authentication tokens sent to download servers",
                                      true, EditAuthTokens),
                null,
                new ConsoleMenuOption("Help", helpKey,
                                      "Tips & tricks",
                                      true, Help),
                null,
                new ConsoleMenuOption("Quit", "Ctrl+Q",
                                      "Exit to DOS",
                                      true, () => false)
            };

            if (debug)
            {
                opts.Add(null);
                opts.Add(new ConsoleMenuOption("DEBUG: Capture key...", "",
                                               "Print details of how your system reports a keystroke for debugging",
                                               true, CaptureKey));
            }
            mainMenu = new ConsolePopupMenu(opts);

            LeftHeader   = () => $"CKAN {Meta.GetVersion()}";
            CenterHeader = () => $"KSP {manager.CurrentInstance.Version()} ({manager.CurrentInstance.Name})";
        }
示例#6
0
文件: MainClass.cs 项目: dexen/CKAN
        internal static NetFileCache FindCache(CmdLineOptions options, KSPManager ksp_manager, IUser user)
        {
            if (options.CacheDir != null)
            {
                log.InfoFormat("Using user-supplied cache at {0}", options.CacheDir);
                return new NetFileCache(options.CacheDir);
            }

            try
            {
                KSP ksp = ksp_manager.GetPreferredInstance();
                log.InfoFormat("Using CKAN cache at {0}",ksp.Cache.GetCachePath());
                return ksp.Cache;
            }
            catch
            {
                // Meh, can't find KSP. 'Scool, bro.
            }

            string tempdir = Path.GetTempPath();
            log.InfoFormat("Using tempdir for cache: {0}", tempdir);

            return new NetFileCache(tempdir);
        }
示例#7
0
        public static int Main(string[] args)
        {
            // Launch debugger if the "--debugger" flag is present in the command line arguments.
            // We want to do this as early as possible so just check the flag manually, rather than doing the
            // more robust argument parsing.
            if (args.Any(i => i == "--debugger"))
            {
                Debugger.Launch();
            }

            if (args.Length == 1 && args.Any(i => i == "--verbose" || i == "--debug"))
            {
                // Start the gui with logging enabled #437
                var guiCommand = args.ToList();
                guiCommand.Insert(0, "gui");
                args = guiCommand.ToArray();
            }

            Logging.Initialize();
            log.Debug("CKAN started");

            Options cmdline;

            // If we're starting with no options then invoke the GUI instead.
            if (args.Length == 0)
            {
                return(Gui(new GuiOptions(), args));
            }

            IUser user;

            try
            {
                cmdline = new Options(args);
            }
            catch (BadCommandKraken)
            {
                // Our help screen will already be shown. Let's add some extra data.
                user = new ConsoleUser(false);
                user.RaiseMessage("You are using CKAN version {0}", Meta.GetVersion(VersionFormat.Full));

                return(Exit.BADOPT);
            }

            // Process commandline options.

            var options = (CommonOptions)cmdline.options;

            user = new ConsoleUser(options.Headless);
            CheckMonoVersion(user, 3, 1, 0);

            // Processes in Docker containers normally run as root.
            // If we are running in a Docker container, do not require --asroot.
            // Docker creates a .dockerenv file in the root of each container.
            if ((Platform.IsUnix || Platform.IsMac) && CmdLineUtil.GetUID() == 0 && !File.Exists("/.dockerenv"))
            {
                if (!options.AsRoot)
                {
                    user.RaiseError(@"You are trying to run CKAN as root.
This is a bad idea and there is absolutely no good reason to do it. Please run CKAN from a user account (or use --asroot if you are feeling brave).");
                    return(Exit.ERROR);
                }
                else
                {
                    user.RaiseMessage("Warning: Running CKAN as root!");
                }
            }

            if (options.Debug)
            {
                LogManager.GetRepository().Threshold = Level.Debug;
                log.Info("Debug logging enabled");
            }
            else if (options.Verbose)
            {
                LogManager.GetRepository().Threshold = Level.Info;
                log.Info("Verbose logging enabled");
            }

            // Assign user-agent string if user has given us one
            if (options.NetUserAgent != null)
            {
                Net.UserAgentString = options.NetUserAgent;
            }

            // User provided KSP instance

            if (options.KSPdir != null && options.KSP != null)
            {
                user.RaiseMessage("--ksp and --kspdir can't be specified at the same time");
                return(Exit.BADOPT);
            }

            var manager = new KSPManager(user);

            if (options.KSP != null)
            {
                // Set a KSP directory by its alias.

                try
                {
                    manager.SetCurrentInstance(options.KSP);
                }
                catch (InvalidKSPInstanceKraken)
                {
                    user.RaiseMessage("Invalid KSP installation specified \"{0}\", use '--kspdir' to specify by path, or 'list-installs' to see known KSP installations", options.KSP);
                    return(Exit.BADOPT);
                }
            }
            else if (options.KSPdir != null)
            {
                // Set a KSP directory by its path
                manager.SetCurrentInstanceByPath(options.KSPdir);
            }
            else if (!(cmdline.action == "ksp" || cmdline.action == "version" || cmdline.action == "gui"))
            {
                // Find whatever our preferred instance is.
                // We don't do this on `ksp/version/gui` commands, they don't need it.
                CKAN.KSP ksp = manager.GetPreferredInstance();

                if (ksp == null)
                {
                    user.RaiseMessage("I don't know where KSP is installed.");
                    user.RaiseMessage("Use 'ckan ksp help' for assistance on setting this.");
                    return(Exit.ERROR);
                }
                else
                {
                    log.InfoFormat("Using KSP install at {0}", ksp.GameDir());
                }
            }

            #region Aliases

            switch (cmdline.action)
            {
            case "add":
                cmdline.action = "install";
                break;

            case "uninstall":
                cmdline.action = "remove";
                break;
            }

            #endregion

            //If we have found a preferred KSP instance, try to lock the registry
            if (manager.CurrentInstance != null)
            {
                try
                {
                    using (var registry = RegistryManager.Instance(manager.CurrentInstance))
                    {
                        log.InfoFormat("About to run action {0}", cmdline.action);
                        return(RunAction(cmdline, options, args, user, manager));
                    }
                }
                catch (RegistryInUseKraken kraken)
                {
                    log.Info("Registry in use detected");
                    user.RaiseMessage(kraken.ToString());
                    return(Exit.ERROR);
                }
            }
            else // we have no preferred KSP instance, so no need to lock the registry
            {
                return(RunAction(cmdline, options, args, user, manager));
            }
        }
示例#8
0
        public static int Main(string[] args)
        {
            BasicConfigurator.Configure();
            LogManager.GetRepository().Threshold = Level.Warn;
            log.Debug("CKAN started");

            // If we're starting with no options, and this isn't
            // a stable build, then invoke the GUI instead.

            if (args.Length == 0)
            {
                if (Meta.IsStable())
                {
                    args = new string[] { "--help" };
                }
                else
                {
                    return(Gui());
                }
            }

            Options cmdline;

            try
            {
                cmdline = new Options(args);
            }
            catch (BadCommandKraken)
            {
                // Our help screen will already be shown. Let's add some extra data.
                User.WriteLine("You are using CKAN version {0}", Meta.Version());

                return(Exit.BADOPT);
            }

            // Process commandline options.

            var options = (CommonOptions)cmdline.options;

            if (options.Debug)
            {
                LogManager.GetRepository().Threshold = Level.Debug;
                log.Info("Debug logging enabled");
            }
            else if (options.Verbose)
            {
                LogManager.GetRepository().Threshold = Level.Info;
                log.Info("Verbose logging enabled");
            }

            // TODO: Allow the user to specify just a directory.
            // User provided KSP instance

            if (options.KSPdir != null && options.KSP != null)
            {
                User.WriteLine("--ksp and --kspdir can't be specified at the same time");
                return(Exit.BADOPT);
            }

            if (options.KSP != null)
            {
                // Set a KSP directory by its alias.

                try
                {
                    KSPManager.SetCurrentInstance(options.KSP);
                }
                catch (InvalidKSPInstanceKraken)
                {
                    User.WriteLine("Invalid KSP installation specified \"{0}\", use '--kspdir' to specify by path, or 'list-installs' to see known KSP installations", options.KSP);
                    return(Exit.BADOPT);
                }
            }
            else if (options.KSPdir != null)
            {
                // Set a KSP directory by its path

                KSPManager.SetCurrentInstanceByPath(options.KSPdir);
            }
            else if (!(cmdline.action == "ksp" || cmdline.action == "version"))
            {
                // Find whatever our preferred instance is.
                // We don't do this on `ksp/version` commands, they don't need it.
                CKAN.KSP ksp = KSPManager.GetPreferredInstance();

                if (ksp == null)
                {
                    User.WriteLine("I don't know where KSP is installed.");
                    User.WriteLine("Use 'ckan ksp help' for assistance on setting this.");
                    return(Exit.ERROR);
                }
                else
                {
                    log.InfoFormat("Using KSP install at {0}", ksp.GameDir());
                }
            }

            switch (cmdline.action)
            {
            case "gui":
                return(Gui());

            case "version":
                return(Version());

            case "update":
                return(Update((UpdateOptions)options));

            case "available":
                return(Available());

            case "install":
                return(Install((InstallOptions)cmdline.options));

            case "scan":
                return(Scan());

            case "list":
                return(List());

            case "show":
                return(Show((ShowOptions)cmdline.options));

            case "remove":
                return(Remove((RemoveOptions)cmdline.options));

            case "upgrade":
                return(Upgrade((UpgradeOptions)cmdline.options));

            case "clean":
                return(Clean());

            case "repair":
                return(RunSubCommand <Repair>((SubCommandOptions)cmdline.options));

            case "ksp":
                return(RunSubCommand <KSP>((SubCommandOptions)cmdline.options));

            default:
                User.WriteLine("Unknown command, try --help");
                return(Exit.BADOPT);
            }
        }
示例#9
0
        private static NetFileCache FindCache(KSPManager kspManager)
        {
            if (Options.CacheDir != null)
            {
                Log.InfoFormat("Using user-supplied cache at {0}", Options.CacheDir);
                return new NetFileCache(Options.CacheDir);
            }

            try
            {
                var ksp = kspManager.GetPreferredInstance();
                Log.InfoFormat("Using CKAN cache at {0}", ksp.Cache.GetCachePath());
                return ksp.Cache;
            }
            catch
            {
                // Meh, can't find KSP. 'Scool, bro.
            }

            var tempdir = Path.GetTempPath();
            Log.InfoFormat("Using tempdir for cache: {0}", tempdir);

            return new NetFileCache(tempdir);
        }
示例#10
0
文件: Upgrade.cs 项目: waralper1/CKAN
 /// <summary>
 /// Initialize the upgrade command object
 /// </summary>
 /// <param name="mgr">KSPManager containing our instances</param>
 /// <param name="user">IUser object for interaction</param>
 public Upgrade(KSPManager mgr, IUser user)
 {
     manager = mgr;
     User    = user;
 }
示例#11
0
 public CompatSubCommand(KSPManager kspManager, IUser user)
 {
     _kspManager = kspManager;
     _user = user;
 }
示例#12
0
文件: Main.cs 项目: adamhomer88/CKAN
        public static int Main(string[] args)
        {
            // Launch debugger if the "--debugger" flag is present in the command line arguments.
            // We want to do this as early as possible so just check the flag manually, rather than doing the
            // more robust argument parsing.
            if (args.Any(i => i == "--debugger"))
            {
                Debugger.Launch();
            }

            if (args.Length == 1 && args.Any(i => i == "--verbose" || i == "--debug"))
            {
                // Start the gui with logging enabled #437 
                List<string> guiCommand = args.ToList();
                guiCommand.Insert(0, "gui");
                args = guiCommand.ToArray();
            }

            BasicConfigurator.Configure();
            LogManager.GetRepository().Threshold = Level.Warn;
            log.Debug("CKAN started");

            Options cmdline;

            // If we're starting with no options then invoke the GUI instead.
            if (args.Length == 0)
            {
                return Gui(new GuiOptions(), args);
            }

            IUser user;
            try
            {
                cmdline = new Options(args);
            }
            catch (BadCommandKraken)
            {
                // Our help screen will already be shown. Let's add some extra data.
                user = new ConsoleUser(false);
                user.RaiseMessage("You are using CKAN version {0}", Meta.Version());

                return Exit.BADOPT;
            }

            // Process commandline options.

            var options = (CommonOptions)cmdline.options;
            user = new ConsoleUser(options.Headless);
            CheckMonoVersion(user, 3, 1, 0);

            if ((Platform.IsUnix || Platform.IsMac) && CmdLineUtil.GetUID() == 0)
            {
                if (!options.AsRoot)
                {
                    user.RaiseError(@"You are trying to run CKAN as root.
This is a bad idea and there is absolutely no good reason to do it. Please run CKAN from a user account (or use --asroot if you are feeling brave).");
                    return Exit.ERROR;
                }
                else
                {
                    user.RaiseMessage("Warning: Running CKAN as root!");
                }
            }

            if (options.Debug)
            {
                LogManager.GetRepository().Threshold = Level.Debug;
                log.Info("Debug logging enabled");
            }
            else if (options.Verbose)
            {
                LogManager.GetRepository().Threshold = Level.Info;
                log.Info("Verbose logging enabled");
            }

            // Assign user-agent string if user has given us one
            if (options.NetUserAgent != null)
            {
                Net.UserAgentString = options.NetUserAgent;
            }

            // User provided KSP instance

            if (options.KSPdir != null && options.KSP != null)
            {
                user.RaiseMessage("--ksp and --kspdir can't be specified at the same time");
                return Exit.BADOPT;
            }
            KSPManager manager= new KSPManager(user);
            if (options.KSP != null)
            {
                // Set a KSP directory by its alias.

                try
                {
                    manager.SetCurrentInstance(options.KSP);
                }
                catch (InvalidKSPInstanceKraken)
                {
                    user.RaiseMessage("Invalid KSP installation specified \"{0}\", use '--kspdir' to specify by path, or 'list-installs' to see known KSP installations", options.KSP);
                    return Exit.BADOPT;
                }
            }
            else if (options.KSPdir != null)
            {
                // Set a KSP directory by its path
                manager.SetCurrentInstanceByPath(options.KSPdir);
            }
            else if (! (cmdline.action == "ksp" || cmdline.action == "version"))
            {
                // Find whatever our preferred instance is.
                // We don't do this on `ksp/version` commands, they don't need it.
                CKAN.KSP ksp = manager.GetPreferredInstance();

                if (ksp == null)
                {
                    user.RaiseMessage("I don't know where KSP is installed.");
                    user.RaiseMessage("Use 'ckan ksp help' for assistance on setting this.");
                    return Exit.ERROR;
                }
                else
                {
                    log.InfoFormat("Using KSP install at {0}",ksp.GameDir());
                }
            }

            #region Aliases

            switch (cmdline.action)
            {
                case "add":
                    cmdline.action = "install";
                    break;

                case "uninstall":
                    cmdline.action = "remove";
                    break;
            }

            #endregion

            switch (cmdline.action)
            {
                case "gui":
                    return Gui((GuiOptions)options, args);

                case "version":
                    return Version(user);

                case "update":
                    return (new Update(user)).RunCommand(manager.CurrentInstance, (UpdateOptions)cmdline.options);

                case "available":
                    return Available(manager.CurrentInstance, user);

                case "install":
                    Scan(manager.CurrentInstance, user, cmdline.action);
                    return (new Install(user)).RunCommand(manager.CurrentInstance, (InstallOptions)cmdline.options);

                case "scan":
                    return Scan(manager.CurrentInstance,user);

                case "list":
                    return (new List(user)).RunCommand(manager.CurrentInstance, (ListOptions)cmdline.options);

                case "show":
                    return (new Show(user)).RunCommand(manager.CurrentInstance, (ShowOptions)cmdline.options);

                case "search":
                    return (new Search(user)).RunCommand(manager.CurrentInstance, options);

                case "remove":
                    return (new Remove(user)).RunCommand(manager.CurrentInstance, cmdline.options);

                case "upgrade":
                    Scan(manager.CurrentInstance, user, cmdline.action);
                    return (new Upgrade(user)).RunCommand(manager.CurrentInstance, cmdline.options);

                case "clean":
                    return Clean(manager.CurrentInstance);

                case "repair":
                    var repair = new Repair(manager.CurrentInstance,user);
                    return repair.RunSubCommand((SubCommandOptions) cmdline.options);

                case "ksp":
                    var ksp = new KSP(manager, user);
                    return ksp.RunSubCommand((SubCommandOptions) cmdline.options);

                case "repo":
                    var repo = new Repo (manager, user);
                    return repo.RunSubCommand((SubCommandOptions) cmdline.options);

                case "compare":
                    return (new Compare(user)).RunCommand(manager.CurrentInstance, cmdline.options);

                default:
                    user.RaiseMessage("Unknown command, try --help");
                    return Exit.BADOPT;
            }
        }
示例#13
0
 /// <summary>
 /// Initialize the remove command object
 /// </summary>
 /// <param name="mgr">KSPManager containing our instances</param>
 /// <param name="user">IUser object for interaction</param>
 public Remove(KSPManager mgr, IUser user)
 {
     manager   = mgr;
     this.user = user;
 }
示例#14
0
        public void UninstallEmptyDirs()
        {
            string emptyFolderName = "DogeCoinFlag";

            // Create a new disposable KSP instance to run the test on.
            using (var ksp = new DisposableKSP())
            {
                var config = new FakeConfiguration(ksp.KSP, ksp.KSP.Name);

                KSPManager manager = new KSPManager(
                    new NullUser(),
                    config
                    )
                {
                    CurrentInstance = ksp.KSP
                };

                string directoryPath = Path.Combine(ksp.KSP.GameData(), emptyFolderName);

                // Install the base test mod.

                var registry = CKAN.RegistryManager.Instance(ksp.KSP).registry;
                manager.Cache.Store(TestData.DogeCoinFlag_101_module(), TestData.DogeCoinFlagZip());
                registry.AddAvailable(TestData.DogeCoinFlag_101_module());

                List <string> modules = new List <string> {
                    TestData.DogeCoinFlag_101_module().identifier
                };

                HashSet <string> possibleConfigOnlyDirs = null;
                CKAN.ModuleInstaller.GetInstance(manager.CurrentInstance, manager.Cache, nullUser).InstallList(modules, new RelationshipResolverOptions(), CKAN.RegistryManager.Instance(manager.CurrentInstance), ref possibleConfigOnlyDirs);

                modules.Clear();

                // Install the plugin test mod.
                manager.Cache.Store(TestData.DogeCoinPlugin_module(), TestData.DogeCoinPluginZip());
                registry.AddAvailable(TestData.DogeCoinPlugin_module());

                modules.Add(TestData.DogeCoinPlugin_module().identifier);

                CKAN.ModuleInstaller.GetInstance(manager.CurrentInstance, manager.Cache, nullUser).InstallList(modules, new RelationshipResolverOptions(), CKAN.RegistryManager.Instance(manager.CurrentInstance), ref possibleConfigOnlyDirs);

                modules.Clear();

                // Check that the directory is installed.
                Assert.IsTrue(Directory.Exists(directoryPath));

                // Uninstall both mods.

                modules.Add(TestData.DogeCoinFlag_101_module().identifier);
                modules.Add(TestData.DogeCoinPlugin_module().identifier);

                CKAN.ModuleInstaller.GetInstance(manager.CurrentInstance, manager.Cache, nullUser).UninstallList(modules, ref possibleConfigOnlyDirs, CKAN.RegistryManager.Instance(manager.CurrentInstance));

                // Check that the directory has been deleted.
                Assert.IsFalse(Directory.Exists(directoryPath));

                manager.Dispose();
                config.Dispose();
            }
        }
示例#15
0
文件: Main.cs 项目: zicrog/CKAN
        public static int Execute(KSPManager manager, CommonOptions opts, string[] args)
        {
            // We shouldn't instantiate Options if it's a subcommand.
            // It breaks command-specific help, for starters.
            try
            {
                switch (args[0])
                {
                case "repair":
                    return((new Repair()).RunSubCommand(manager, opts, new SubCommandOptions(args)));

                case "ksp":
                    return((new KSP()).RunSubCommand(manager, opts, new SubCommandOptions(args)));

                case "compat":
                    return((new Compat()).RunSubCommand(manager, opts, new SubCommandOptions(args)));

                case "repo":
                    return((new Repo()).RunSubCommand(manager, opts, new SubCommandOptions(args)));

                case "authtoken":
                    return((new AuthToken()).RunSubCommand(manager, opts, new SubCommandOptions(args)));

                case "cache":
                    return((new Cache()).RunSubCommand(manager, opts, new SubCommandOptions(args)));

                case "mark":
                    return((new Mark()).RunSubCommand(manager, opts, new SubCommandOptions(args)));
                }
            }
            catch (NoGameInstanceKraken)
            {
                return(printMissingInstanceError(new ConsoleUser(false)));
            }
            finally
            {
                log.Info("CKAN exiting.");
            }

            Options cmdline;

            try
            {
                cmdline = new Options(args);
            }
            catch (BadCommandKraken)
            {
                return(AfterHelp());
            }
            finally
            {
                log.Info("CKAN exiting.");
            }

            // Process commandline options.
            CommonOptions options = (CommonOptions)cmdline.options;

            options.Merge(opts);
            IUser user = new ConsoleUser(options.Headless);

            if (manager == null)
            {
                manager = new KSPManager(user);
            }
            else
            {
                manager.User = user;
            }

            try
            {
                int exitCode = options.Handle(manager, user);
                if (exitCode != Exit.OK)
                {
                    return(exitCode);
                }
                // Don't bother with instances or registries yet because some commands don't need them.
                return(RunSimpleAction(cmdline, options, args, user, manager));
            }
            finally
            {
                log.Info("CKAN exiting.");
            }
        }
示例#16
0
        // This is required by ISubCommand
        public int RunSubCommand(SubCommandOptions unparsed)
        {
            string[] args = unparsed.options.ToArray();

            #region Aliases

            for (int i = 0; i < args.Length; i++)
            {
                switch (args[i])
                {
                case "remove":
                    args[i] = "forget";
                    break;
                }
            }

            #endregion

            int exitCode = Exit.OK;

            // Parse and process our sub-verbs
            Parser.Default.ParseArgumentsStrict(args, new RepoSubOptions(), (string option, object suboptions) =>
            {
                // ParseArgumentsStrict calls us unconditionally, even with bad arguments
                if (!string.IsNullOrEmpty(option) && suboptions != null)
                {
                    CommonOptions options = (CommonOptions)suboptions;
                    User     = new ConsoleUser(options.Headless);
                    Manager  = new KSPManager(User);
                    exitCode = options.Handle(Manager, User);
                    if (exitCode != Exit.OK)
                    {
                        return;
                    }

                    switch (option)
                    {
                    case "available":
                        exitCode = AvailableRepositories();
                        break;

                    case "list":
                        exitCode = ListRepositories();
                        break;

                    case "add":
                        exitCode = AddRepository((AddOptions)suboptions);
                        break;

                    case "remove":
                    case "forget":
                        exitCode = ForgetRepository((ForgetOptions)suboptions);
                        break;

                    case "default":
                        exitCode = DefaultRepository((DefaultOptions)suboptions);
                        break;

                    default:
                        User.RaiseMessage("Unknown command: repo {0}", option);
                        exitCode = Exit.BADOPT;
                        break;
                    }
                }
            }, () => { exitCode = MainClass.AfterHelp(); });
            RegistryManager.DisposeAll();
            return(exitCode);
        }
示例#17
0
 public CompatSubCommand(KSPManager kspManager, IUser user)
 {
     _kspManager = kspManager;
     _user       = user;
 }
示例#18
0
文件: Update.cs 项目: starllv/CKAN
 /// <summary>
 /// Initialize the update command object
 /// </summary>
 /// <param name="mgr">KSPManager containing our instances</param>
 /// <param name="user">IUser object for interaction</param>
 public Update(KSPManager mgr, IUser user)
 {
     manager   = mgr;
     this.user = user;
 }
示例#19
0
        /// <summary>
        /// Run whatever action the user has provided
        /// </summary>
        /// <returns>The exit status that should be returned to the system.</returns>
        private static int RunAction(Options cmdline, CommonOptions options, string[] args, IUser user, KSPManager manager)
        {
            switch (cmdline.action)
            {
            case "gui":
                return(Gui((GuiOptions)options, args));

            case "version":
                return(Version(user));

            case "update":
                return((new Update(user)).RunCommand(manager.CurrentInstance, (UpdateOptions)cmdline.options));

            case "available":
                return((new Available(user)).RunCommand(manager.CurrentInstance, (AvailableOptions)cmdline.options));

            //return Available(manager.CurrentInstance, user);

            case "install":
                Scan(manager.CurrentInstance, user, cmdline.action);
                return((new Install(user)).RunCommand(manager.CurrentInstance, (InstallOptions)cmdline.options));

            case "scan":
                return(Scan(manager.CurrentInstance, user));

            case "list":
                return((new List(user)).RunCommand(manager.CurrentInstance, (ListOptions)cmdline.options));

            case "show":
                return((new Show(user)).RunCommand(manager.CurrentInstance, (ShowOptions)cmdline.options));

            case "search":
                return((new Search(user)).RunCommand(manager.CurrentInstance, options));

            case "remove":
                return((new Remove(user)).RunCommand(manager.CurrentInstance, cmdline.options));

            case "upgrade":
                Scan(manager.CurrentInstance, user, cmdline.action);
                return((new Upgrade(user)).RunCommand(manager.CurrentInstance, cmdline.options));

            case "clean":
                return(Clean(manager.CurrentInstance));

            case "repair":
                var repair = new Repair(manager.CurrentInstance, user);
                return(repair.RunSubCommand((SubCommandOptions)cmdline.options));

            case "ksp":
                var ksp = new KSP(manager, user);
                return(ksp.RunSubCommand((SubCommandOptions)cmdline.options));

            case "compat":
                var compat = new CompatSubCommand(manager, user);
                return(compat.RunSubCommand((SubCommandOptions)cmdline.options));

            case "repo":
                var repo = new Repo(manager, user);
                return(repo.RunSubCommand((SubCommandOptions)cmdline.options));

            case "compare":
                return((new Compare(user)).RunCommand(manager.CurrentInstance, cmdline.options));

            default:
                user.RaiseMessage("Unknown command, try --help");
                return(Exit.BADOPT);
            }
        }
示例#20
0
        /// <summary>
        /// Initialize the Screen
        /// </summary>
        /// <param name="mgr">KSP manager containing the instances</param>
        /// <param name="k">Instance to edit</param>
        public KSPEditScreen(KSPManager mgr, KSP k)
            : base(mgr, KSPListScreen.InstallName(mgr, k), k.GameDir())
        {
            ksp = k;
            try {
                // If we can't parse the registry, just leave the repo list blank
                registry = RegistryManager.Instance(ksp).registry;
            } catch { }

            // Show the repositories if we can
            if (registry != null)
            {
                // Need to edit a copy of the list so it doesn't save on cancel
                repoEditList = new SortedDictionary <string, Repository>();
                foreach (var kvp in registry.Repositories)
                {
                    repoEditList.Add(kvp.Key, new Repository(
                                         kvp.Value.name,
                                         kvp.Value.uri.ToString(),
                                         kvp.Value.priority
                                         ));
                }

                // Also edit copy of the compatible versions
                compatEditList = new List <KspVersion>(ksp.GetCompatibleVersions());

                // I'm not a huge fan of this layout, but I think it's better than just a label
                AddObject(new ConsoleDoubleFrame(
                              1, repoFrameTop, -1, compatFrameBottom, compatFrameTop,
                              () => $"Mod List Sources",
                              () => $"Additional Compatible Versions",
                              () => ConsoleTheme.Current.LabelFg
                              ));

                repoList = new ConsoleListBox <Repository>(
                    3, repoListTop, -3, repoListBottom,
                    new List <Repository>(repoEditList.Values),
                    new List <ConsoleListBoxColumn <Repository> >()
                {
                    new ConsoleListBoxColumn <Repository>()
                    {
                        Header   = "Index",
                        Renderer = r => r.priority.ToString(),
                        Width    = 7
                    }, new ConsoleListBoxColumn <Repository>()
                    {
                        Header   = "Name",
                        Renderer = r => r.name,
                        Width    = 16
                    }, new ConsoleListBoxColumn <Repository>()
                    {
                        Header   = "URL",
                        Renderer = r => r.uri.ToString(),
                        Width    = 50
                    }
                },
                    1, 0, ListSortDirection.Ascending
                    );
                AddObject(repoList);
                repoList.AddTip("A", "Add");
                repoList.AddBinding(Keys.A, (object sender) => {
                    LaunchSubScreen(new RepoAddScreen(repoEditList));
                    repoList.SetData(new List <Repository>(repoEditList.Values));
                    return(true);
                });
                repoList.AddTip("R", "Remove");
                repoList.AddBinding(Keys.R, (object sender) => {
                    int oldPrio = repoList.Selection.priority;
                    repoEditList.Remove(repoList.Selection.name);
                    // Reshuffle the priorities to fill
                    foreach (Repository r in repoEditList.Values)
                    {
                        if (r.priority > oldPrio)
                        {
                            --r.priority;
                        }
                    }
                    repoList.SetData(new List <Repository>(repoEditList.Values));
                    return(true);
                });
                repoList.AddTip("E", "Edit");
                repoList.AddBinding(Keys.E, (object sender) => {
                    LaunchSubScreen(new RepoEditScreen(repoEditList, repoList.Selection));
                    repoList.SetData(new List <Repository>(repoEditList.Values));
                    return(true);
                });
                repoList.AddTip("-", "Up");
                repoList.AddBinding(Keys.Minus, (object sender) => {
                    if (repoList.Selection.priority > 0)
                    {
                        Repository prev = SortedDictFind(repoEditList,
                                                         r => r.priority == repoList.Selection.priority - 1);
                        if (prev != null)
                        {
                            ++prev.priority;
                        }
                        --repoList.Selection.priority;
                        repoList.SetData(new List <Repository>(repoEditList.Values));
                    }
                    return(true);
                });
                repoList.AddTip("+", "Down");
                repoList.AddBinding(Keys.Plus, (object sender) => {
                    Repository next = SortedDictFind(repoEditList,
                                                     r => r.priority == repoList.Selection.priority + 1);
                    if (next != null)
                    {
                        --next.priority;
                    }
                    ++repoList.Selection.priority;
                    repoList.SetData(new List <Repository>(repoEditList.Values));
                    return(true);
                });

                compatList = new ConsoleListBox <KspVersion>(
                    3, compatListTop, -3, compatListBottom,
                    compatEditList,
                    new List <ConsoleListBoxColumn <KspVersion> >()
                {
                    new ConsoleListBoxColumn <KspVersion>()
                    {
                        Header   = "Version",
                        Width    = 10,
                        Renderer = v => v.ToString(),
                        Comparer = (a, b) => a.CompareTo(b)
                    }
                },
                    0, 0, ListSortDirection.Descending
                    );
                AddObject(compatList);

                compatList.AddTip("A", "Add");
                compatList.AddBinding(Keys.A, (object sender) => {
                    CompatibleVersionDialog vd = new CompatibleVersionDialog();
                    KspVersion newVersion      = vd.Run();
                    DrawBackground();
                    if (newVersion != null && !compatEditList.Contains(newVersion))
                    {
                        compatEditList.Add(newVersion);
                        compatList.SetData(compatEditList);
                    }
                    return(true);
                });
                compatList.AddTip("R", "Remove", () => compatList.Selection != null);
                compatList.AddBinding(Keys.R, (object sender) => {
                    compatEditList.Remove(compatList.Selection);
                    compatList.SetData(compatEditList);
                    return(true);
                });
            }
            else
            {
                // Notify the user that the registry doesn't parse
                AddObject(new ConsoleLabel(
                              1, repoFrameTop, -1,
                              () => $"Failed to extract mod list sources from {KSPListScreen.InstallName(manager, ksp)}."
                              ));
            }
        }
示例#21
0
文件: Install.cs 项目: zilti/CKAN
 /// <summary>
 /// Initialize the install command object
 /// </summary>
 /// <param name="mgr">KSPManager containing our instances</param>
 /// <param name="user">IUser object for interaction</param>
 public Install(KSPManager mgr, IUser user)
 {
     manager   = mgr;
     this.user = user;
 }
示例#22
0
        /// <summary>
        /// Initialize the screen.
        /// </summary>
        /// <param name="mgr">KSP manager object for getting hte Instances</param>
        /// <param name="first">If true, this is the first screen after the splash, so Ctrl+Q exits, else Esc exits</param>
        public KSPListScreen(KSPManager mgr, bool first = false)
        {
            manager = mgr;

            AddObject(new ConsoleLabel(
                          1, 2, -1,
                          () => "Select a game instance:"
                          ));

            kspList = new ConsoleListBox <KSP>(
                1, 4, -1, -2,
                manager.Instances.Values,
                new List <ConsoleListBoxColumn <KSP> >()
            {
                new ConsoleListBoxColumn <KSP>()
                {
                    Header   = "Default",
                    Width    = 7,
                    Renderer = StatusSymbol
                }, new ConsoleListBoxColumn <KSP>()
                {
                    Header   = "Name",
                    Width    = 20,
                    Renderer = k => InstallName(manager, k)
                }, new ConsoleListBoxColumn <KSP>()
                {
                    Header   = "Version",
                    Width    = 12,
                    Renderer = k => k.Version()?.ToString() ?? noVersion,
                    Comparer = (a, b) => a.Version()?.CompareTo(b.Version() ?? KspVersion.Any) ?? 1
                }, new ConsoleListBoxColumn <KSP>()
                {
                    Header   = "Path",
                    Width    = 70,
                    Renderer = k => k.GameDir()
                }
            },
                1, 0, ListSortDirection.Descending
                );

            if (first)
            {
                AddTip("Ctrl+Q", "Quit");
                AddBinding(Keys.AltX, (object sender) => false);
                AddBinding(Keys.CtrlQ, (object sender) => false);
            }
            else
            {
                AddTip("Esc", "Quit");
                AddBinding(Keys.Escape, (object sender) => false);
            }

            AddTip("Enter", "Select");
            AddBinding(Keys.Enter, (object sender) => {
                ConsoleMessageDialog d = new ConsoleMessageDialog(
                    $"Loading instance {InstallName(manager, kspList.Selection)}...",
                    new List <string>()
                    );

                if (TryGetInstance(kspList.Selection, () => { d.Run(() => {}); }))
                {
                    try {
                        manager.SetCurrentInstance(InstallName(manager, kspList.Selection));
                    } catch (Exception ex) {
                        // This can throw if the previous current instance had an error,
                        // since it gets destructed when it's replaced.
                        RaiseError(ex.Message);
                    }
                    return(false);
                }
                else
                {
                    return(true);
                }
            });

            kspList.AddTip("A", "Add");
            kspList.AddBinding(Keys.A, (object sender) => {
                LaunchSubScreen(new KSPAddScreen(manager));
                kspList.SetData(manager.Instances.Values);
                return(true);
            });
            kspList.AddTip("R", "Remove");
            kspList.AddBinding(Keys.R, (object sender) => {
                manager.RemoveInstance(InstallName(manager, kspList.Selection));
                kspList.SetData(manager.Instances.Values);
                return(true);
            });
            kspList.AddTip("E", "Edit");
            kspList.AddBinding(Keys.E, (object sender) => {
                ConsoleMessageDialog d = new ConsoleMessageDialog(
                    $"Loading instance {InstallName(manager, kspList.Selection)}...",
                    new List <string>()
                    );
                TryGetInstance(kspList.Selection, () => { d.Run(() => {}); });
                // Still launch the screen even if the load fails,
                // because you need to be able to fix the name/path.
                LaunchSubScreen(new KSPEditScreen(manager, kspList.Selection));

                return(true);
            });

            kspList.AddTip("D", "Default");
            kspList.AddBinding(Keys.D, (object sender) => {
                string name = InstallName(manager, kspList.Selection);
                if (name == manager.AutoStartInstance)
                {
                    manager.ClearAutoStart();
                }
                else
                {
                    try {
                        manager.SetAutoStart(name);
                    } catch (NotKSPDirKraken k) {
                        ConsoleMessageDialog errd = new ConsoleMessageDialog(
                            $"Error loading {k.path}:\n{k.Message}",
                            new List <string>()
                        {
                            "OK"
                        }
                            );
                        errd.Run();
                    }
                }
                return(true);
            });

            AddObject(kspList);

            LeftHeader   = () => $"CKAN {Meta.GetVersion()}";
            CenterHeader = () => "KSP Instances";
            mainMenu     = kspList.SortMenu();
        }
示例#23
0
        public static int Main(string[] args)
        {
            // Launch debugger if the "--debugger" flag is present in the command line arguments.
            // We want to do this as early as possible so just check the flag manually, rather than doing the
            // more robust argument parsing.
            if (args.Any(i => i == "--debugger"))
            {
                Debugger.Launch();
            }

            if (args.Length == 1 && args.Any(i => i == "--verbose" || i == "--debug"))
            {
                // Start the gui with logging enabled #437
                List <string> guiCommand = args.ToList();
                guiCommand.Insert(0, "gui");
                args = guiCommand.ToArray();
            }

            BasicConfigurator.Configure();
            LogManager.GetRepository().Threshold = Level.Warn;
            log.Debug("CKAN started");

            Options cmdline;

            // If we're starting with no options then invoke the GUI instead.
            if (args.Length == 0)
            {
                return(Gui(new GuiOptions(), args));
            }

            IUser user;

            try
            {
                cmdline = new Options(args);
            }
            catch (BadCommandKraken)
            {
                // Our help screen will already be shown. Let's add some extra data.
                user = new ConsoleUser(false);
                user.RaiseMessage("You are using CKAN version {0}", Meta.Version());

                return(Exit.BADOPT);
            }

            // Process commandline options.

            var options = (CommonOptions)cmdline.options;

            user = new ConsoleUser(options.Headless);
            CheckMonoVersion(user, 3, 1, 0);

            if ((Platform.IsUnix || Platform.IsMac) && CmdLineUtil.GetUID() == 0)
            {
                if (!options.AsRoot)
                {
                    user.RaiseError(@"You are trying to run CKAN as root.
This is a bad idea and there is absolutely no good reason to do it. Please run CKAN from a user account (or use --asroot if you are feeling brave).");
                    return(Exit.ERROR);
                }
                else
                {
                    user.RaiseMessage("Warning: Running CKAN as root!");
                }
            }

            if (options.Debug)
            {
                LogManager.GetRepository().Threshold = Level.Debug;
                log.Info("Debug logging enabled");
            }
            else if (options.Verbose)
            {
                LogManager.GetRepository().Threshold = Level.Info;
                log.Info("Verbose logging enabled");
            }

            // Assign user-agent string if user has given us one
            if (options.NetUserAgent != null)
            {
                Net.UserAgentString = options.NetUserAgent;
            }

            // User provided KSP instance

            if (options.KSPdir != null && options.KSP != null)
            {
                user.RaiseMessage("--ksp and --kspdir can't be specified at the same time");
                return(Exit.BADOPT);
            }
            KSPManager manager = new KSPManager(user);

            if (options.KSP != null)
            {
                // Set a KSP directory by its alias.

                try
                {
                    manager.SetCurrentInstance(options.KSP);
                }
                catch (InvalidKSPInstanceKraken)
                {
                    user.RaiseMessage("Invalid KSP installation specified \"{0}\", use '--kspdir' to specify by path, or 'list-installs' to see known KSP installations", options.KSP);
                    return(Exit.BADOPT);
                }
            }
            else if (options.KSPdir != null)
            {
                // Set a KSP directory by its path
                manager.SetCurrentInstanceByPath(options.KSPdir);
            }
            else if (!(cmdline.action == "ksp" || cmdline.action == "version"))
            {
                // Find whatever our preferred instance is.
                // We don't do this on `ksp/version` commands, they don't need it.
                CKAN.KSP ksp = manager.GetPreferredInstance();

                if (ksp == null)
                {
                    user.RaiseMessage("I don't know where KSP is installed.");
                    user.RaiseMessage("Use 'ckan ksp help' for assistance on setting this.");
                    return(Exit.ERROR);
                }
                else
                {
                    log.InfoFormat("Using KSP install at {0}", ksp.GameDir());
                }
            }

            #region Aliases

            switch (cmdline.action)
            {
            case "add":
                cmdline.action = "install";
                break;

            case "uninstall":
                cmdline.action = "remove";
                break;
            }

            #endregion

            switch (cmdline.action)
            {
            case "gui":
                return(Gui((GuiOptions)options, args));

            case "version":
                return(Version(user));

            case "update":
                return((new Update(user)).RunCommand(manager.CurrentInstance, (UpdateOptions)cmdline.options));

            case "available":
                return(Available(manager.CurrentInstance, user));

            case "install":
                Scan(manager.CurrentInstance, user, cmdline.action);
                return((new Install(user)).RunCommand(manager.CurrentInstance, (InstallOptions)cmdline.options));

            case "scan":
                return(Scan(manager.CurrentInstance, user));

            case "list":
                return((new List(user)).RunCommand(manager.CurrentInstance, (ListOptions)cmdline.options));

            case "show":
                return((new Show(user)).RunCommand(manager.CurrentInstance, (ShowOptions)cmdline.options));

            case "search":
                return((new Search(user)).RunCommand(manager.CurrentInstance, options));

            case "remove":
                return((new Remove(user)).RunCommand(manager.CurrentInstance, cmdline.options));

            case "upgrade":
                Scan(manager.CurrentInstance, user, cmdline.action);
                return((new Upgrade(user)).RunCommand(manager.CurrentInstance, cmdline.options));

            case "clean":
                return(Clean(manager.CurrentInstance));

            case "repair":
                var repair = new Repair(manager.CurrentInstance, user);
                return(repair.RunSubCommand((SubCommandOptions)cmdline.options));

            case "ksp":
                var ksp = new KSP(manager, user);
                return(ksp.RunSubCommand((SubCommandOptions)cmdline.options));

            case "repo":
                var repo = new Repo(manager, user);
                return(repo.RunSubCommand((SubCommandOptions)cmdline.options));

            case "compare":
                return((new Compare(user)).RunCommand(manager.CurrentInstance, cmdline.options));

            default:
                user.RaiseMessage("Unknown command, try --help");
                return(Exit.BADOPT);
            }
        }
示例#24
0
 /// <summary>
 /// Initialize the screen
 /// </summary>
 /// <param name="mgr">KSP manager object for getting instances</param>
 public SplashScreen(KSPManager mgr)
 {
     manager = mgr;
 }
示例#25
0
 /// <summary>
 /// Initialize the command
 /// </summary>
 /// <param name="user">IUser object for user interaction</param>
 public Import(KSPManager mgr, IUser user)
 {
     manager   = mgr;
     this.user = user;
 }
示例#26
0
文件: Main.cs 项目: godefroi/CKAN
        public static int Main(string[] args)
        {
            BasicConfigurator.Configure();
            LogManager.GetRepository().Threshold = Level.Warn;
            log.Debug("CKAN started");

            // If we're starting with no options then invoke the GUI instead.

            if (args.Length == 0)
            {
                return(Gui());
            }

            IUser   user = new ConsoleUser();
            Options cmdline;

            try
            {
                cmdline = new Options(args);
            }
            catch (BadCommandKraken)
            {
                // Our help screen will already be shown. Let's add some extra data.
                user.RaiseMessage("You are using CKAN version {0}", Meta.Version());

                return(Exit.BADOPT);
            }

            // Process commandline options.

            var options = (CommonOptions)cmdline.options;

            if (options.Debug)
            {
                LogManager.GetRepository().Threshold = Level.Debug;
                log.Info("Debug logging enabled");
            }
            else if (options.Verbose)
            {
                LogManager.GetRepository().Threshold = Level.Info;
                log.Info("Verbose logging enabled");
            }

            // Assign user-agent string if user has given us one
            if (options.NetUserAgent != null)
            {
                Net.UserAgentString = options.NetUserAgent;
            }

            // TODO: Allow the user to specify just a directory.
            // User provided KSP instance

            if (options.KSPdir != null && options.KSP != null)
            {
                user.RaiseMessage("--ksp and --kspdir can't be specified at the same time");
                return(Exit.BADOPT);
            }
            KSPManager manager = new KSPManager(user);

            if (options.KSP != null)
            {
                // Set a KSP directory by its alias.

                try
                {
                    manager.SetCurrentInstance(options.KSP);
                }
                catch (InvalidKSPInstanceKraken)
                {
                    user.RaiseMessage("Invalid KSP installation specified \"{0}\", use '--kspdir' to specify by path, or 'list-installs' to see known KSP installations", options.KSP);
                    return(Exit.BADOPT);
                }
            }
            else if (options.KSPdir != null)
            {
                // Set a KSP directory by its path

                manager.SetCurrentInstanceByPath(options.KSPdir);
            }
            else if (!(cmdline.action == "ksp" || cmdline.action == "version"))
            {
                // Find whatever our preferred instance is.
                // We don't do this on `ksp/version` commands, they don't need it.
                CKAN.KSP ksp = manager.GetPreferredInstance();

                if (ksp == null)
                {
                    user.RaiseMessage("I don't know where KSP is installed.");
                    user.RaiseMessage("Use 'ckan ksp help' for assistance on setting this.");
                    return(Exit.ERROR);
                }
                else
                {
                    log.InfoFormat("Using KSP install at {0}", ksp.GameDir());
                }
            }

            #region Aliases

            switch (cmdline.action)
            {
            case "add":
                cmdline.action = "install";
                break;

            case "uninstall":
                cmdline.action = "remove";
                break;

            default:
                break;
            }

            #endregion

            switch (cmdline.action)
            {
            case "gui":
                return(Gui());

            case "version":
                return(Version(user));

            case "update":
                return(Update((UpdateOptions)options, RegistryManager.Instance(manager.CurrentInstance), manager.CurrentInstance, user));

            case "available":
                return(Available(manager.CurrentInstance, user));

            case "install":
                return(Install((InstallOptions)cmdline.options, manager.CurrentInstance, user));

            case "scan":
                return(Scan(manager.CurrentInstance));

            case "list":
                return(List(user, manager.CurrentInstance));

            case "show":
                return(Show((ShowOptions)cmdline.options, manager.CurrentInstance, user));

            case "remove":
                return(Remove((RemoveOptions)cmdline.options, manager.CurrentInstance, user));

            case "upgrade":
                var upgrade = new Upgrade(user);
                return(upgrade.RunCommand(manager.CurrentInstance, cmdline.options));

            case "clean":
                return(Clean(manager.CurrentInstance));

            case "repair":
                var repair = new Repair(manager.CurrentInstance, user);
                return(repair.RunSubCommand((SubCommandOptions)cmdline.options));

            case "ksp":
                var ksp = new KSP(manager, user);
                return(ksp.RunSubCommand((SubCommandOptions)cmdline.options));

            default:
                user.RaiseMessage("Unknown command, try --help");
                return(Exit.BADOPT);
            }
        }
示例#27
0
        /// <summary>
        /// Initialize the screen
        /// </summary>
        /// <param name="mgr">KSP manager containing instances</param>
        /// <param name="cp">Plan of mods to add and remove</param>
        /// <param name="rej">Mods that the user saw and did not select, in this pass or a previous pass</param>
        /// <param name="dbg">True if debug options should be available, false otherwise</param>
        public DependencyScreen(KSPManager mgr, ChangePlan cp, HashSet <string> rej, bool dbg) : base()
        {
            debug    = dbg;
            manager  = mgr;
            plan     = cp;
            registry = RegistryManager.Instance(manager.CurrentInstance).registry;
            rejected = rej;

            AddObject(new ConsoleLabel(
                          1, 2, -1,
                          () => "Additional mods are recommended or suggested:"
                          ));

            generateList(plan.Install);

            dependencyList = new ConsoleListBox <Dependency>(
                1, 4, -1, -2,
                new List <Dependency>(dependencies.Values),
                new List <ConsoleListBoxColumn <Dependency> >()
            {
                new ConsoleListBoxColumn <Dependency>()
                {
                    Header   = "Install",
                    Width    = 7,
                    Renderer = (Dependency d) => StatusSymbol(d.module)
                },
                new ConsoleListBoxColumn <Dependency>()
                {
                    Header   = "Name",
                    Width    = 36,
                    Renderer = (Dependency d) => d.module.ToString()
                },
                new ConsoleListBoxColumn <Dependency>()
                {
                    Header   = "Sources",
                    Width    = 42,
                    Renderer = (Dependency d) => string.Join(", ", d.dependents)
                }
            },
                1, 0, ListSortDirection.Descending
                );
            dependencyList.AddTip("+", "Toggle");
            dependencyList.AddBinding(Keys.Plus, (object sender) => {
                ChangePlan.toggleContains(accepted, dependencyList.Selection.module);
                return(true);
            });

            dependencyList.AddTip("Ctrl+A", "Select all");
            dependencyList.AddBinding(Keys.CtrlA, (object sender) => {
                foreach (var kvp in dependencies)
                {
                    if (!accepted.Contains(kvp.Key))
                    {
                        ChangePlan.toggleContains(accepted, kvp.Key);
                    }
                }
                return(true);
            });

            dependencyList.AddTip("Ctrl+D", "Deselect all", () => accepted.Count > 0);
            dependencyList.AddBinding(Keys.CtrlD, (object sender) => {
                accepted.Clear();
                return(true);
            });

            dependencyList.AddTip("Enter", "Details");
            dependencyList.AddBinding(Keys.Enter, (object sender) => {
                if (dependencyList.Selection != null)
                {
                    LaunchSubScreen(new ModInfoScreen(
                                        manager, plan,
                                        dependencyList.Selection.module,
                                        debug
                                        ));
                }
                return(true);
            });

            AddObject(dependencyList);

            AddTip("Esc", "Cancel");
            AddBinding(Keys.Escape, (object sender) => {
                // Add everything to rejected
                foreach (var kvp in dependencies)
                {
                    rejected.Add(kvp.Key.identifier);
                }
                return(false);
            });

            AddTip("F9", "Accept");
            AddBinding(Keys.F9, (object sender) => {
                foreach (CkanModule mod in accepted)
                {
                    plan.Install.Add(mod);
                }
                // Add the rest to rejected
                foreach (var kvp in dependencies)
                {
                    if (!accepted.Contains(kvp.Key))
                    {
                        rejected.Add(kvp.Key.identifier);
                    }
                }
                return(false);
            });
        }
示例#28
0
文件: Compat.cs 项目: zilti/CKAN
        public int RunSubCommand(KSPManager manager, CommonOptions opts, SubCommandOptions options)
        {
            var exitCode = Exit.OK;

            Parser.Default.ParseArgumentsStrict(options.options.ToArray(), new CompatOptions(), (string option, object suboptions) =>
            {
                // ParseArgumentsStrict calls us unconditionally, even with bad arguments
                if (!string.IsNullOrEmpty(option) && suboptions != null)
                {
                    CommonOptions comOpts = (CommonOptions)suboptions;
                    comOpts.Merge(opts);
                    _user       = new ConsoleUser(comOpts.Headless);
                    _kspManager = manager ?? new KSPManager(_user);
                    exitCode    = comOpts.Handle(_kspManager, _user);
                    if (exitCode != Exit.OK)
                    {
                        return;
                    }

                    switch (option)
                    {
                    case "list":
                        {
                            var ksp = MainClass.GetGameInstance(_kspManager);

                            const string versionHeader = "Version";
                            const string actualHeader  = "Actual";

                            var output = ksp
                                         .GetCompatibleVersions()
                                         .Select(i => new
                            {
                                Version = i,
                                Actual  = false
                            })
                                         .ToList();

                            output.Add(new
                            {
                                Version = ksp.Version(),
                                Actual  = true
                            });

                            output = output
                                     .OrderByDescending(i => i.Actual)
                                     .ThenByDescending(i => i.Version)
                                     .ToList();

                            var versionWidth = Enumerable
                                               .Repeat(versionHeader, 1)
                                               .Concat(output.Select(i => i.Version.ToString()))
                                               .Max(i => i.Length);

                            var actualWidth = Enumerable
                                              .Repeat(actualHeader, 1)
                                              .Concat(output.Select(i => i.Actual.ToString()))
                                              .Max(i => i.Length);

                            const string columnFormat = "{0}  {1}";

                            _user.RaiseMessage(string.Format(columnFormat,
                                                             versionHeader.PadRight(versionWidth),
                                                             actualHeader.PadRight(actualWidth)
                                                             ));

                            _user.RaiseMessage(string.Format(columnFormat,
                                                             new string('-', versionWidth),
                                                             new string('-', actualWidth)
                                                             ));

                            foreach (var line in output)
                            {
                                _user.RaiseMessage(string.Format(columnFormat,
                                                                 line.Version.ToString().PadRight(versionWidth),
                                                                 line.Actual.ToString().PadRight(actualWidth)
                                                                 ));
                            }
                        }
                        break;

                    case "add":
                        {
                            var ksp        = MainClass.GetGameInstance(_kspManager);
                            var addOptions = (CompatAddOptions)suboptions;

                            KspVersion kspVersion;
                            if (KspVersion.TryParse(addOptions.Version, out kspVersion))
                            {
                                var newCompatibleVersion = ksp.GetCompatibleVersions();
                                newCompatibleVersion.Add(kspVersion);
                                ksp.SetCompatibleVersions(newCompatibleVersion);
                            }
                            else
                            {
                                _user.RaiseError("ERROR: Invalid KSP version.");
                                exitCode = Exit.ERROR;
                            }
                        }
                        break;

                    case "forget":
                        {
                            var ksp        = MainClass.GetGameInstance(_kspManager);
                            var addOptions = (CompatForgetOptions)suboptions;

                            KspVersion kspVersion;
                            if (KspVersion.TryParse(addOptions.Version, out kspVersion))
                            {
                                if (kspVersion != ksp.Version())
                                {
                                    var newCompatibleVersion = ksp.GetCompatibleVersions();
                                    newCompatibleVersion.RemoveAll(i => i == kspVersion);
                                    ksp.SetCompatibleVersions(newCompatibleVersion);
                                }
                                else
                                {
                                    _user.RaiseError("ERROR: Cannot forget actual KSP version.");
                                    exitCode = Exit.ERROR;
                                }
                            }
                            else
                            {
                                _user.RaiseError("ERROR: Invalid KSP version.");
                                exitCode = Exit.ERROR;
                            }
                        }
                        break;

                    default:
                        exitCode = Exit.BADOPT;
                        break;
                    }
                }
            }, () => { exitCode = MainClass.AfterHelp(); });
            return(exitCode);
        }
示例#29
0
 public void SetUp()
 {
     tidy      = new DisposableKSP();
     win32_reg = GetTestWin32Reg(nameInReg);
     manager   = new KSPManager(new NullUser(), win32_reg);
 }
示例#30
0
 public void SetUp()
 {
     tidy    = new DisposableKSP();
     cfg     = GetTestCfg(nameInReg);
     manager = new KSPManager(new NullUser(), cfg);
 }
示例#31
0
文件: Main.cs 项目: zicrog/CKAN
 private static int ConsoleUi(KSPManager manager, CommonOptions opts, string[] args)
 {
     // Debug/verbose output just messes up the screen
     LogManager.GetRepository().Threshold = Level.Warn;
     return(CKAN.ConsoleUI.ConsoleUI.Main_(args, manager, opts.Debug));
 }
示例#32
0
        /// <summary>
        /// Initialize the Screen
        /// </summary>
        /// <param name="mgr">KSP manager containing game instances</param>
        /// <param name="cp">Plan of other mods to be added or removed</param>
        /// <param name="m">The module to display</param>
        /// <param name="dbg">True if debug options should be available, false otherwise</param>
        public ModInfoScreen(KSPManager mgr, ChangePlan cp, CkanModule m, bool dbg)
        {
            debug    = dbg;
            mod      = m;
            manager  = mgr;
            plan     = cp;
            registry = RegistryManager.Instance(manager.CurrentInstance).registry;

            int midL = Console.WindowWidth / 2 - 1;

            AddObject(new ConsoleLabel(
                          1, 1, -1,
                          () => mod.name == mod.identifier ? mod.name : $"{mod.name} ({mod.identifier})",
                          null,
                          () => ConsoleTheme.Current.ActiveFrameFg
                          ));
            AddObject(new ConsoleLabel(
                          1, 2, -1,
                          () => $"By {string.Join(", ", mod.author)}"
                          ));

            AddObject(new ConsoleFrame(
                          1, 3, midL, 7,
                          () => "",
                          () => ConsoleTheme.Current.NormalFrameFg,
                          false
                          ));
            AddObject(new ConsoleLabel(
                          3, 4, 11,
                          () => "License:",
                          null,
                          () => ConsoleTheme.Current.DimLabelFg
                          ));
            AddObject(new ConsoleLabel(
                          13, 4, midL - 2,
                          () => string.Join(", ", Array.ConvertAll <License, string>(
                                                mod.license.ToArray(), (l => l.ToString())))
                          ));
            AddObject(new ConsoleLabel(
                          3, 5, 12,
                          () => "Download:",
                          null,
                          () => ConsoleTheme.Current.DimLabelFg
                          ));
            AddObject(new ConsoleLabel(
                          13, 5, midL - 2,
                          () => CkanModule.FmtSize(mod.download_size)
                          ));
            AddObject(new ConsoleLabel(
                          3, 6, midL - 2,
                          HostedOn
                          ));

            int depsBot = addDependencies();
            int versBot = addVersionDisplay();

            AddObject(new ConsoleFrame(
                          1, Math.Max(depsBot, versBot) + 1, -1, -1,
                          () => "Description",
                          () => ConsoleTheme.Current.NormalFrameFg,
                          false
                          ));
            ConsoleTextBox tb = new ConsoleTextBox(
                3, Math.Max(depsBot, versBot) + 2, -3, -2, false,
                TextAlign.Left,
                () => ConsoleTheme.Current.MainBg,
                () => ConsoleTheme.Current.LabelFg
                );

            tb.AddLine(mod.@abstract);
            if (!string.IsNullOrEmpty(mod.description) &&
                mod.description != mod.@abstract)
            {
                tb.AddLine(mod.description);
            }
            AddObject(tb);
            if (!ChangePlan.IsAnyAvailable(registry, mod.identifier))
            {
                tb.AddLine("\r\nNOTE: This mod is installed but no longer available.");
                tb.AddLine("If you uninstall it, CKAN will not be able to re-install it.");
            }
            tb.AddScrollBindings(this);

            AddTip("Esc", "Back");
            AddBinding(Keys.Escape, (object sender) => false);

            AddTip("Ctrl+D", "Download",
                   () => !manager.CurrentInstance.Cache.IsMaybeCachedZip(mod)
                   );
            AddBinding(Keys.CtrlD, (object sender) => {
                Download();
                return(true);
            });

            if (mod.resources != null)
            {
                List <ConsoleMenuOption> opts = new List <ConsoleMenuOption>();

                if (mod.resources.homepage != null)
                {
                    opts.Add(new ConsoleMenuOption(
                                 "Home page", "", "Open the home page URL in a browser",
                                 true,
                                 () => LaunchURL(mod.resources.homepage)
                                 ));
                }
                if (mod.resources.repository != null)
                {
                    opts.Add(new ConsoleMenuOption(
                                 "Repository", "", "Open the repository URL in a browser",
                                 true,
                                 () => LaunchURL(mod.resources.repository)
                                 ));
                }
                if (mod.resources.bugtracker != null)
                {
                    opts.Add(new ConsoleMenuOption(
                                 "Bugtracker", "", "Open the bug tracker URL in a browser",
                                 true,
                                 () => LaunchURL(mod.resources.bugtracker)
                                 ));
                }
                if (mod.resources.spacedock != null)
                {
                    opts.Add(new ConsoleMenuOption(
                                 "SpaceDock", "", "Open the SpaceDock URL in a browser",
                                 true,
                                 () => LaunchURL(mod.resources.spacedock)
                                 ));
                }
                if (mod.resources.curse != null)
                {
                    opts.Add(new ConsoleMenuOption(
                                 "Curse", "", "Open the Curse URL in a browser",
                                 true,
                                 () => LaunchURL(mod.resources.curse)
                                 ));
                }
                if (debug)
                {
                    opts.Add(null);
                    opts.Add(new ConsoleMenuOption(
                                 "DEBUG: View metadata", "", "Display the full registry data for this mod",
                                 true,
                                 ViewMetadata
                                 ));
                }

                if (opts.Count > 0)
                {
                    mainMenu = new ConsolePopupMenu(opts);
                }
            }

            LeftHeader   = () => $"CKAN {Meta.GetVersion()}";
            CenterHeader = () => "Mod Details";
        }
示例#33
0
文件: KSP.cs 项目: adamhomer88/CKAN
 public KSP(KSPManager manager, IUser user)
 {
     Manager = manager;
     User = user;
 }
示例#34
0
 /// <summary>
 /// Initialize the Screen
 /// </summary>
 /// <param name="mgr">KSP manager containing the instances</param>
 public KSPAddScreen(KSPManager mgr) : base(mgr)
 {
 }