コード例 #1
0
        void IUtilityCommand.Run(Utility utility, string[] args)
        {
            // HACK: The engine code assumes that Game.modData is set.
            var modData = Game.ModData = utility.ModData;

            IEnumerable <UpdateRule> rules = null;

            if (args.Length > 1)
            {
                rules = UpdatePath.FromSource(modData.ObjectCreator, args[1]);
            }

            if (rules == null)
            {
                Console.WriteLine("--update-mod SOURCE [--detailed] [--apply] [--skip-maps]");

                if (args.Length > 1)
                {
                    Console.WriteLine("Unknown source: " + args[1]);
                }

                Console.WriteLine("Valid sources are:");

                var ruleGroups = new Dictionary <string, List <string> >();

                // Print known tags
                Console.WriteLine("   Update Paths:");
                foreach (var p in UpdatePath.KnownPaths)
                {
                    Console.WriteLine("      " + p);
                    ruleGroups[p] = UpdatePath.FromSource(modData.ObjectCreator, p, false)
                                    .Select(r => r.GetType().Name)
                                    .Where(r => !ruleGroups.Values.Any(g => g.Contains(r)))
                                    .ToList();
                }

                // Print known rules
                Console.WriteLine("   Individual Rules:");
                foreach (var kv in ruleGroups)
                {
                    if (!kv.Value.Any())
                    {
                        continue;
                    }

                    Console.WriteLine("      " + kv.Key + ":");
                    foreach (var r in kv.Value)
                    {
                        Console.WriteLine("         " + r);
                    }
                }

                var other = UpdatePath.KnownRules(modData.ObjectCreator)
                            .Where(r => !ruleGroups.Values.Any(g => g.Contains(r)));

                if (other.Any())
                {
                    Console.WriteLine("      Other:");
                    foreach (var r in other)
                    {
                        Console.WriteLine("         " + r);
                    }
                }

                return;
            }

            if (args.Contains("--apply"))
            {
                if (!args.Contains("--yes"))
                {
                    Console.WriteLine("WARNING: This command will automatically rewrite your mod rules.");
                    Console.WriteLine();
                    Console.WriteLine("We strongly recommend that you have a backup of your mod rules, and ");
                    Console.WriteLine("for best results, to use a Git client to review the line-by-line ");
                    Console.WriteLine("changes and discard any unwanted side effects.");
                    Console.WriteLine();
                    Console.Write("Press y to continue, or any other key to cancel: ");

                    var confirmKey = Console.ReadKey().KeyChar;
                    Console.WriteLine();

                    if (confirmKey != 'y')
                    {
                        Console.WriteLine("Update cancelled.");
                        return;
                    }
                }

                ApplyRules(modData, rules, args.Contains("--skip-maps"));
            }
            else
            {
                PrintSummary(rules, args.Contains("--detailed"));
            }
        }
コード例 #2
0
        void IUtilityCommand.Run(Utility utility, string[] args)
        {
            // HACK: The engine code assumes that Game.modData is set.
            var modData = Game.ModData = utility.ModData;

            // HACK: We know that maps can only be oramap or folders, which are ReadWrite
            var package = new Folder(Platform.EngineDir).OpenPackage(args[1], modData.ModFiles) as IReadWritePackage;

            if (package == null)
            {
                throw new FileNotFoundException(args[1]);
            }

            IEnumerable <UpdateRule> rules = null;

            if (args.Length > 2)
            {
                rules = UpdatePath.FromSource(modData.ObjectCreator, args[2]);
            }

            if (rules == null)
            {
                Console.WriteLine("--update-map MAP SOURCE [--detailed] [--apply]");

                if (args.Length > 2)
                {
                    Console.WriteLine("Unknown source: " + args[2]);
                }

                Console.WriteLine("Valid sources are:");

                var ruleGroups = new Dictionary <string, List <string> >();

                // Print known tags
                Console.WriteLine("   Update Paths:");
                foreach (var p in UpdatePath.KnownPaths)
                {
                    Console.WriteLine("      " + p);
                    ruleGroups[p] = UpdatePath.FromSource(modData.ObjectCreator, p, false)
                                    .Select(r => r.GetType().Name)
                                    .Where(r => !ruleGroups.Values.Any(g => g.Contains(r)))
                                    .ToList();
                }

                // Print known rules
                Console.WriteLine("   Individual Rules:");
                foreach (var kv in ruleGroups)
                {
                    if (!kv.Value.Any())
                    {
                        continue;
                    }

                    Console.WriteLine("      " + kv.Key + ":");
                    foreach (var r in kv.Value)
                    {
                        Console.WriteLine("         " + r);
                    }
                }

                var other = UpdatePath.KnownRules(modData.ObjectCreator)
                            .Where(r => !ruleGroups.Values.Any(g => g.Contains(r)));

                if (other.Any())
                {
                    Console.WriteLine("      Other:");
                    foreach (var r in other)
                    {
                        Console.WriteLine("         " + r);
                    }
                }

                return;
            }

            if (args.Contains("--apply"))
            {
                ApplyRules(modData, package, rules);
            }
            else
            {
                UpdateModCommand.PrintSummary(rules, args.Contains("--detailed"));
            }
        }