예제 #1
0
        // This decompiler is a test bed for our library,
        // don't expect to see any quality code in here
        public static void Main(string[] args)
        {
            Options = new Options();
            CommandLine.Parser.Default.ParseArgumentsStrict(args, Options);

            Options.InputFile = Path.GetFullPath(Options.InputFile);

            if (Options.OutputFile != null)
            {
                Options.OutputFile = Path.GetFullPath(Options.OutputFile);
                Options.OutputFile = FixPathSlahes(Options.OutputFile);
            }

            var paths = new List<string>();

            if (Directory.Exists(Options.InputFile))
            {
                if (Options.OutputFile != null && File.Exists(Options.OutputFile))
                {
                    Console.Error.WriteLine("Output path is an existing file, but input is a folder.");

                    return;
                }

                paths.AddRange(Directory.GetFiles(Options.InputFile, "*.*_c", Options.RecursiveSearch ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly));
            }
            else if (File.Exists(Options.InputFile))
            {
                Options.RecursiveSearch = false;

                paths.Add(Options.InputFile);
            }

            if (paths.Count == 0)
            {
                Console.Error.WriteLine("No such file \"{0}\" or directory is empty. Did you mean to include --recursive parameter?", Options.InputFile);

                return;
            }

            var stats = new Dictionary<string, ResourceStat>();
            var uniqueSpecialDependancies = new Dictionary<string, string>();
            CurrentFile = 0;
            TotalFiles = paths.Count;

            if (Options.MaxParallelismThreads > 1)
            {
                Console.WriteLine("Will use {0} threads concurrently.", Options.MaxParallelismThreads);

                Parallel.ForEach(paths, new ParallelOptions { MaxDegreeOfParallelism = Options.MaxParallelismThreads }, (path, state) =>
                {
                    ProcessFile(path, stats, uniqueSpecialDependancies);
                });
            }
            else
            {
                foreach (var path in paths)
                {
                    ProcessFile(path, stats, uniqueSpecialDependancies);
                }
            }

            if (Options.CollectStats)
            {
                Console.WriteLine();
                Console.WriteLine("Processed resource stats:");

                foreach (var stat in stats.OrderByDescending(x => x.Value.Count).ThenBy(x => x.Key))
                {
                    Console.WriteLine("{0,5} resources of version {2} and type {1}{3}", stat.Value.Count, stat.Value.Type, stat.Value.Version,
                        stat.Value.Info != "" ? string.Format(" ({0})", stat.Value.Info) : ""
                    );
                }

                Console.WriteLine();
                Console.WriteLine("Unique special dependancies:");

                foreach (var stat in uniqueSpecialDependancies)
                {
                    Console.WriteLine("{0} in {1}", stat.Key, stat.Value);
                }
            }
        }
예제 #2
0
        // This decompiler is a test bed for our library,
        // don't expect to see any quality code in here
        public static void Main(string[] args)
        {
            Options = new Options();
            CommandLine.Parser.Default.ParseArgumentsStrict(args, Options);

            Options.InputFile = Path.GetFullPath(Options.InputFile);

            if (Options.OutputFile != null)
            {
                Options.OutputFile = Path.GetFullPath(Options.OutputFile);
                Options.OutputFile = FixPathSlashes(Options.OutputFile);
            }

            if (Options.FileFilter != null)
            {
                Options.FileFilter = FixPathSlashes(Options.FileFilter);
            }

            var paths = new List <string>();

            if (Directory.Exists(Options.InputFile))
            {
                if (Options.OutputFile != null && File.Exists(Options.OutputFile))
                {
                    Console.Error.WriteLine("Output path is an existing file, but input is a folder.");

                    return;
                }

                paths.AddRange(Directory.EnumerateFiles(Options.InputFile, "*.*", Options.RecursiveSearch ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly).Where(s => s.EndsWith("_c") || s.EndsWith(".vcs")));
            }
            else if (File.Exists(Options.InputFile))
            {
                Options.RecursiveSearch = false;

                paths.Add(Options.InputFile);
            }

            if (paths.Count == 0)
            {
                Console.Error.WriteLine("No such file \"{0}\" or directory is empty. Did you mean to include --recursive parameter?", Options.InputFile);

                return;
            }

            CurrentFile = 0;
            TotalFiles  = paths.Count;

            if (Options.MaxParallelismThreads > 1)
            {
                Console.WriteLine("Will use {0} threads concurrently.", Options.MaxParallelismThreads);

                Parallel.ForEach(paths, new ParallelOptions {
                    MaxDegreeOfParallelism = Options.MaxParallelismThreads
                }, (path, state) =>
                {
                    ProcessFile(path);
                });
            }
            else
            {
                foreach (var path in paths)
                {
                    ProcessFile(path);
                }
            }

            if (Options.CollectStats)
            {
                Console.WriteLine();
                Console.WriteLine("Processed resource stats:");

                foreach (var stat in stats.OrderByDescending(x => x.Value.Count).ThenBy(x => x.Key))
                {
                    Console.WriteLine("{0,5} resources of version {2} and type {1}{3} - {4}", stat.Value.Count, stat.Value.Type, stat.Value.Version,
                                      stat.Value.Info != "" ? string.Format(" ({0})", stat.Value.Info) : "", stat.Value.FilePath
                                      );
                }

                Console.WriteLine();
                Console.WriteLine("Unique special dependancies:");

                foreach (var stat in uniqueSpecialDependancies)
                {
                    Console.WriteLine("{0} in {1}", stat.Key, stat.Value);
                }
            }
        }