示例#1
0
        public static void Main(string[] args)
        {
            bool showHelp = false;

            OptionSet options = new OptionSet()
            {
                {
                    "h|help",
                    "show this message and exit",
                    v => showHelp = v != null
                },
            };

            List <string> extras;

            try
            {
                extras = options.Parse(args);
            }
            catch (OptionException e)
            {
                Console.Write("{0}: ", GetExecutableName());
                Console.WriteLine(e.Message);
                Console.WriteLine("Try `{0} --help' for more information.", GetExecutableName());
                return;
            }

            if (extras.Count != 0 || showHelp == true)
            {
                Console.WriteLine("Usage: {0} [OPTIONS]+", GetExecutableName());
                Console.WriteLine();
                Console.WriteLine("Options:");
                options.WriteOptionDescriptions(Console.Out);
                return;
            }

            Console.WriteLine("Loading project...");

            var manager = ProjectData.Manager.Load();

            if (manager.ActiveProject == null)
            {
                Console.WriteLine("Nothing to do: no active project loaded.");
                return;
            }

            var project     = manager.ActiveProject;
            var fileNames   = manager.LoadListsFileNames();
            var columnNames = manager.LoadListsColumnNames();

            var installPath = project.InstallPath;
            var listsPath   = project.ListsPath;

            if (installPath == null)
            {
                Console.WriteLine("Could not detect install path.");
                return;
            }
            else if (listsPath == null)
            {
                Console.WriteLine("Could not detect lists path.");
                return;
            }

            var inputPath = Path.Combine(installPath, @"packages\core\data\2da.rim");

            Console.WriteLine("Processing...");

            var results = new Dictionary <uint, string>();

            var erf = new EncapsulatedResourceFile();

            using (var input = File.OpenRead(inputPath))
            {
                erf.Deserialize(input);

                var loader = new Loader(erf);
                foreach (var entry in loader)
                {
                    if (entry.TypeHash != EXT)
                    {
                        continue;
                    }

                    string inputName = entry.Name;

                    if (inputName == null)
                    {
                        if (fileNames.Contains(entry.NameHash) == false)
                        {
                            continue;
                        }

                        inputName = fileNames[entry.NameHash];
                    }

                    var outputPath = GetListPath(inputName);
                    outputPath = Path.Combine(listsPath, outputPath);

                    var data = loader.Load(input, entry);

                    var localResults = new Dictionary <uint, string>();

                    var gff = new GenericFile_Data();
                    gff.Deserialize(data);

                    var root    = gff.Export();
                    var columns = root[10002].As <List <KeyValue> >(null);
                    if (columns != null)
                    {
                        foreach (var column in columns)
                        {
                            var id   = column[10001].As <uint>();
                            var name = columnNames[id];
                            localResults.Add(id, name);
                            results[id] = name;
                        }
                    }

                    Directory.CreateDirectory(Path.GetDirectoryName(outputPath));
                    using (var output = new StreamWriter(outputPath))
                    {
                        var breakdown = new Breakdown();
                        breakdown.Known = localResults.Where(r => r.Value != null).Count();
                        breakdown.Total = localResults.Count;

                        output.WriteLine("; {0}", breakdown.ToString());

                        foreach (var kvp in localResults)
                        {
                            if (kvp.Value == null)
                            {
                                output.WriteLine("; {0:X8}", kvp.Key);
                            }
                            else
                            {
                                output.WriteLine("{0}", kvp.Value);
                            }
                        }
                    }
                }
            }

            using (var output = new StreamWriter(Path.Combine(Path.Combine(listsPath, "columns"), "status.txt")))
            {
                var breakdown = new Breakdown();
                breakdown.Known = results.Where(r => r.Value != null).Count();
                breakdown.Total = results.Count;
                output.WriteLine("{0}", breakdown.ToString());
            }

            using (var output = new StreamWriter(Path.Combine(Path.Combine(listsPath, "columns"), "master.columnlist")))
            {
                foreach (var result in results.Where(r => r.Value != null).OrderBy(r => r.Value))
                {
                    output.WriteLine(result.Value);
                }
            }
        }
示例#2
0
        public static void Main(string[] args)
        {
            bool showHelp = false;

            OptionSet options = new OptionSet()
            {
                {
                    "h|help",
                    "show this message and exit",
                    v => showHelp = v != null
                },
            };

            List <string> extras;

            try
            {
                extras = options.Parse(args);
            }
            catch (OptionException e)
            {
                Console.Write("{0}: ", GetExecutableName());
                Console.WriteLine(e.Message);
                Console.WriteLine("Try `{0} --help' for more information.", GetExecutableName());
                return;
            }

            if (extras.Count != 0 || showHelp == true)
            {
                Console.WriteLine("Usage: {0} [OPTIONS]+", GetExecutableName());
                Console.WriteLine();
                Console.WriteLine("Options:");
                options.WriteOptionDescriptions(Console.Out);
                return;
            }

            Console.WriteLine("Loading project...");

            var manager = ProjectData.Manager.Load();

            if (manager.ActiveProject == null)
            {
                Console.WriteLine("Nothing to do: no active project loaded.");
                return;
            }

            var project   = manager.ActiveProject;
            var fileNames = project.LoadListsFileNames();
            var typeNames = project.LoadListsTypeNames();

            var installPath = project.InstallPath;
            var listsPath   = project.ListsPath;

            if (installPath == null)
            {
                Console.WriteLine("Could not detect install path.");
                return;
            }
            else if (listsPath == null)
            {
                Console.WriteLine("Could not detect lists path.");
                return;
            }

            Console.WriteLine("Searching for ERFs...");
            var inputPaths = new List <string>();

            /* would have added just the root paths
             * but that nets the addins directory too... */
            /*
             * inputPaths.AddRange(Directory.GetFiles(Path.Combine(installPath, "modules"), "*.erf", SearchOption.AllDirectories));
             * inputPaths.AddRange(Directory.GetFiles(Path.Combine(installPath, "modules"), "*.rim", SearchOption.AllDirectories));
             * inputPaths.AddRange(Directory.GetFiles(Path.Combine(installPath, "packages"), "*.erf", SearchOption.AllDirectories));
             * inputPaths.AddRange(Directory.GetFiles(Path.Combine(installPath, "packages"), "*.rim", SearchOption.AllDirectories));
             */
            inputPaths.AddRange(Directory.GetFiles(installPath, "*.erf", SearchOption.AllDirectories));
            inputPaths.AddRange(Directory.GetFiles(installPath, "*.crf", SearchOption.AllDirectories));
            inputPaths.AddRange(Directory.GetFiles(installPath, "*.rim", SearchOption.AllDirectories));

            var outputPaths = new List <string>();

            var breakdowns = new Breakdowns();

            Console.WriteLine("Processing...");
            foreach (var inputpath in inputPaths)
            {
                var outputPath = GetListPath(installPath, inputpath);
                if (outputPath == null)
                {
                    throw new InvalidOperationException();
                }

                Console.WriteLine(outputPath);
                outputPath = Path.Combine(listsPath, outputPath);

                if (outputPaths.Contains(outputPath) == true)
                {
                    throw new InvalidOperationException();
                }

                outputPaths.Add(outputPath);

                var erf = new EncapsulatedResourceFile();
                using (var input = File.OpenRead(inputpath))
                {
                    erf.Deserialize(input);
                }

                var localBreakdowns = new Breakdowns();

                var names = new List <string>();
                foreach (var entry in erf.Entries)
                {
                    string name = entry.Name;

                    if (name == null)
                    {
                        name = fileNames[entry.NameHash];
                    }

                    var type = typeNames[entry.TypeHash] ?? entry.TypeHash.ToString("X8");

                    if (name != null)
                    {
                        name = name.ToLowerInvariant();
                        if (names.Contains(name) == false)
                        {
                            names.Add(name);

                            localBreakdowns[type].Known++;
                        }
                    }

                    localBreakdowns[type].Total++;
                }

                breakdowns += localBreakdowns;

                names.Sort();

                Directory.CreateDirectory(Path.GetDirectoryName(outputPath));
                using (var output = new StreamWriter(outputPath))
                {
                    var breakdown = localBreakdowns.ToBreakdown();

                    output.WriteLine("; {0}", breakdown);

                    if (breakdown.Known == 0 ||
                        localBreakdowns.Entries.Count != 1)
                    {
                        output.WriteLine("; ");

                        int padding = localBreakdowns.Entries.Max(e => e.Key.Length);
                        foreach (var kvp in localBreakdowns.Entries.OrderBy(e => e.Key))
                        {
                            output.WriteLine("; {0} - {1}",
                                             kvp.Key.PadLeft(padding),
                                             kvp.Value.ToString());
                        }
                        output.WriteLine("; ");
                    }

                    foreach (string name in names)
                    {
                        output.WriteLine(name);
                    }
                }
            }

            using (var output = new StreamWriter(Path.Combine(Path.Combine(listsPath, "files"), "status.txt")))
            {
                output.WriteLine("{0}", breakdowns.ToBreakdown());

                int padding = breakdowns.Entries.Max(e => e.Key.Length);

                var incomplete = breakdowns.Entries.Where(e => e.Value.Percent < 100.0);
                var complete   = breakdowns.Entries.Where(e => e.Value.Percent >= 100.0);

                if (incomplete.Count() > 0)
                {
                    output.WriteLine();
                    foreach (var kvp in incomplete.OrderBy(e => e.Value.Percent))
                    {
                        output.WriteLine("{0} - {1}",
                                         kvp.Key.PadLeft(padding),
                                         kvp.Value.ToString());
                    }
                }

                if (complete.Count() > 0)
                {
                    output.WriteLine();
                    foreach (var kvp in complete.OrderBy(e => e.Key))
                    {
                        output.WriteLine("{0} - {1}",
                                         kvp.Key.PadLeft(padding),
                                         kvp.Value.ToString());
                    }
                }
            }
        }