Beispiel #1
0
 public FakeConfiguration(CKAN.KSP instance, string autostart)
     : this(
         new List <Tuple <string, string> >
 {
     new Tuple <string, string>("test", instance.GameDir())
 },
         autostart
         )
 {
 }
Beispiel #2
0
        private static int List()
        {
            CKAN.KSP ksp = KSPManager.CurrentInstance;

            User.WriteLine("\nKSP found at {0}\n", ksp.GameDir());
            User.WriteLine("KSP Version: {0}\n", ksp.Version());

            Registry registry = RegistryManager.Instance(ksp).registry;

            User.WriteLine("Installed Modules:\n");

            var installed = new SortedDictionary <string, Version>(registry.Installed());

            foreach (var mod in installed)
            {
                User.WriteLine("* {0} {1}", mod.Key, mod.Value);
            }

            // Blank line at the end makes for nicer looking output.
            User.WriteLine("");

            return(Exit.OK);
        }
Beispiel #3
0
Datei: Main.cs Projekt: pjf/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");
            }

            // 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;
            }
        }
Beispiel #4
0
Datei: Main.cs Projekt: pjf/CKAN
        private static int List(IUser user, CKAN.KSP current_instance)
        {
            CKAN.KSP ksp = current_instance;

            user.RaiseMessage("\nKSP found at {0}\n", ksp.GameDir());
            user.RaiseMessage("KSP Version: {0}\n", ksp.Version());

            Registry registry = RegistryManager.Instance(ksp).registry;

            user.RaiseMessage("Installed Modules:\n");

            var installed = new SortedDictionary<string, Version>(registry.Installed());

            foreach (KeyValuePair<string, Version> mod in installed)
            {
                Version current_version = mod.Value;

                string bullet = "*";

                if (current_version is ProvidesVersion)
                {
                    // Skip virtuals for now.
                    continue;
                }
                else if (current_version is DllVersion)
                {
                    // Autodetected dll
                    bullet = "-";
                }
                else
                {
                    try
                    {
                        // Check if upgrades are available, and show appropriately.
                        CkanModule latest = registry.LatestAvailable(mod.Key, ksp.Version());

                        log.InfoFormat("Latest {0} is {1}", mod.Key, latest);

                        if (latest == null)
                        {
                            // Not compatible!
                            bullet = "✗";
                        }
                        else if (latest.version.IsEqualTo(current_version))
                        {
                            // Up to date
                            bullet = "✓";
                        }
                        else if (latest.version.IsGreaterThan(mod.Value))
                        {
                            // Upgradable
                            bullet = "↑";
                        }

                    }
                    catch (ModuleNotFoundKraken) {
                        log.InfoFormat("{0} is installed, but no longer in the registry",
                            mod.Key);

                        bullet = "?";
                    }
                }

                user.RaiseMessage("{0} {1} {2}", bullet, mod.Key, mod.Value);
            }

            user.RaiseMessage("\nLegend: ✓ - Up to date. ✗ - Incompatible. ↑ - Upgradable. ? - Unknown ");

            return Exit.OK;
        }
Beispiel #5
0
        public static int RunCommandLine(string[] args, Func <string[], GuiOptions, int> showGuiFunc = null)
        {
            // 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");
                guiCommand.Add("--show-console");
                args = guiCommand.ToArray();
            }

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

            Options cmdline;

            // If we're starting with no options then invoke the GUI instead (if compiled with GUI)
            if (args.Length == 0)
            {
                if (showGuiFunc != null)
                {
                    return(showGuiFunc(args, null));
                }
                args = new[] { "--help" };
            }

            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 CFAN 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 CFAN as root.
This is a bad idea and there is absolutely no good reason to do it. Please run CFAN from a user account (or use --asroot if you are feeling brave).");
                    return(Exit.ERROR);
                }
                user.RaiseMessage("Warning: Running CFAN 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.FactorioDirectory != null && options.FactorioInstallName != null)
            {
                user.RaiseMessage("--factorio and --factorio-dir can't be specified at the same time");
                return(Exit.BADOPT);
            }
            KSPManager manager = new KSPManager(user);

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

                try
                {
                    manager.SetCurrentInstance(options.FactorioInstallName);
                }
                catch (InvalidKSPInstanceKraken)
                {
                    user.RaiseMessage("Invalid Factorio installation specified \"{0}\", use '--factorio-dir' to specify by path, or 'list-installs' to see known Factorio installations", options.FactorioInstallName);
                    return(Exit.BADOPT);
                }
            }
            else if (options.FactorioDirectory != null)
            {
                // Set a KSP directory by its path
                manager.SetCurrentInstanceByPath(options.FactorioDirectory);
            }
            else if (cmdline.action != "factorio" && cmdline.action != "version" && cmdline.action != "gui")
            {
                // 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 Factorio is installed.");
                    user.RaiseMessage("Use 'cfan factorio help' for assistance on setting this.");
                    return(Exit.ERROR);
                }
                log.InfoFormat("Using Factorio install at {0} with data dir set to {1}", ksp.GameDir(), ksp.GameData());

                if (ksp.lacksFactorioAuthData())
                {
                    user.RaiseError(
                        "Your config file located in {0} does not contain Factorio authorization data. Mods from official factorio.com mod portal will not be shown.\n\rYou can fix it by using in-game mod portal once. For headless you can copy values of service-username and service-token from your regular Factorio install.",
                        new object[] { ksp.getFactorioAuthDataPath() }
                        );
                }
            }

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

            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 "factorio":
                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);
            }
        }
Beispiel #6
0
        public int RunCommand(CKAN.KSP ksp, object raw_options)
        {
            ListOptions options = (ListOptions)raw_options;

            IRegistryQuerier registry = RegistryManager.Instance(ksp).registry;


            ExportFileType?exportFileType = null;

            if (!string.IsNullOrWhiteSpace(options.export))
            {
                exportFileType = GetExportFileType(options.export);

                if (exportFileType == null)
                {
                    user.RaiseError("Unknown export format: {0}", options.export);
                }
            }

            if (!(options.porcelain) && exportFileType == null)
            {
                user.RaiseMessage("\r\nKSP found at {0}\r\n", ksp.GameDir());
                user.RaiseMessage("KSP Version: {0}\r\n", ksp.Version());

                user.RaiseMessage("Installed Modules:\r\n");
            }

            if (exportFileType == null)
            {
                var installed = new SortedDictionary <string, Version>(registry.Installed());

                foreach (KeyValuePair <string, Version> mod in installed)
                {
                    Version current_version = mod.Value;

                    string bullet = "*";

                    if (current_version is ProvidesVersion)
                    {
                        // Skip virtuals for now.
                        continue;
                    }
                    else if (current_version is DllVersion)
                    {
                        // Autodetected dll
                        bullet = "-";
                    }
                    else
                    {
                        try
                        {
                            // Check if upgrades are available, and show appropriately.
                            CkanModule latest = registry.LatestAvailable(mod.Key, ksp.VersionCriteria());

                            log.InfoFormat("Latest {0} is {1}", mod.Key, latest);

                            if (latest == null)
                            {
                                // Not compatible!
                                bullet = "X";
                            }
                            else if (latest.version.IsEqualTo(current_version))
                            {
                                // Up to date
                                bullet = "-";
                            }
                            else if (latest.version.IsGreaterThan(mod.Value))
                            {
                                // Upgradable
                                bullet = "^";
                            }
                        }
                        catch (ModuleNotFoundKraken)
                        {
                            log.InfoFormat("{0} is installed, but no longer in the registry", mod.Key);
                            bullet = "?";
                        }
                    }

                    user.RaiseMessage("{0} {1} {2}", bullet, mod.Key, mod.Value);
                }
            }
            else
            {
                var stream = Console.OpenStandardOutput();
                new Exporter(exportFileType.Value).Export(registry, stream);
                stream.Flush();
            }

            if (!(options.porcelain) && exportFileType == null)
            {
                user.RaiseMessage("\r\nLegend: -: Up to date. X: Incompatible. ^: Upgradable. ?: Unknown. *: Broken. ");
                // Broken mods are in a state that CKAN doesn't understand, and therefore can't handle automatically
            }

            return(Exit.OK);
        }
Beispiel #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();
            }

            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);
            }
        }
Beispiel #8
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));
            }
        }
Beispiel #9
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);
            }
        }
Beispiel #10
0
        public int RunCommand(CKAN.KSP ksp, object raw_options)
        {
            ListOptions options = (ListOptions)raw_options;

            Registry registry = RegistryManager.Instance(ksp).registry;

            if (!(options.porcelain))
            {
                user.RaiseMessage("\nKSP found at {0}\n", ksp.GameDir());
                user.RaiseMessage("KSP Version: {0}\n", ksp.Version());

                user.RaiseMessage("Installed Modules:\n");
            }

            var installed = new SortedDictionary <string, Version>(registry.Installed());

            foreach (KeyValuePair <string, Version> mod in installed)
            {
                Version current_version = mod.Value;

                string bullet = "*";

                if (current_version is ProvidesVersion)
                {
                    // Skip virtuals for now.
                    continue;
                }
                else if (current_version is DllVersion)
                {
                    // Autodetected dll
                    bullet = "-";
                }
                else
                {
                    try
                    {
                        // Check if upgrades are available, and show appropriately.
                        CkanModule latest = registry.LatestAvailable(mod.Key, ksp.Version());

                        log.InfoFormat("Latest {0} is {1}", mod.Key, latest);

                        if (latest == null)
                        {
                            // Not compatible!
                            bullet = "X";
                        }
                        else if (latest.version.IsEqualTo(current_version))
                        {
                            // Up to date
                            bullet = "-";
                        }
                        else if (latest.version.IsGreaterThan(mod.Value))
                        {
                            // Upgradable
                            bullet = "^";
                        }
                    }
                    catch (ModuleNotFoundKraken)
                    {
                        log.InfoFormat("{0} is installed, but no longer in the registry", mod.Key);
                        bullet = "?";
                    }
                }

                user.RaiseMessage("{0} {1} {2}", bullet, mod.Key, mod.Value);
            }

            if (!(options.porcelain))
            {
                user.RaiseMessage("\nLegend: -: Up to date. X: Incompatible. ^: Upgradable. ?: Unknown ");
            }

            return(Exit.OK);
        }