Exemplo n.º 1
0
        private static string DumpCollection <T>(IEnumerable <T> collection, DumpDelegate <T> dumpMethod)
        {
            string result = "";

            foreach (var item in collection)
            {
                result += dumpMethod.Invoke(item) + "\r\n";
            }

            return(result);
        }
Exemplo n.º 2
0
        public void Main(string[] args, string defaultOutputPath, DumpDelegate callback)
        {
            if (callback == null)
            {
                throw new ArgumentNullException("callback");
            }

            int  logLevelOrdinal = 3;
            bool noPatch         = false;
            bool showHelp        = false;

            var options = new OptionSet()
            {
                { "no-patch", "don't use patch data", v => noPatch = v != null },
                { "v|verbose", "increase log level (-v/-vv/-vvv)", v => IncreaseLogLevel(v, ref logLevelOrdinal) },
                { "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 (this._LoadPartitionMap == false)
            {
                if (extras.Count < 1 || extras.Count > 2 || showHelp == true)
                {
                    Console.WriteLine("Usage: {0} [OPTIONS]+ game_dir [output_json]", GetExecutableName());
                    Console.WriteLine();
                    Console.WriteLine("Options:");
                    options.WriteOptionDescriptions(Console.Out);
                    return;
                }
            }
            else
            {
                if (extras.Count < 2 || extras.Count > 3 || showHelp == true)
                {
                    Console.WriteLine("Usage: {0} [OPTIONS]+ game_dir partition_map [output_json]", GetExecutableName());
                    Console.WriteLine();
                    Console.WriteLine("Options:");
                    options.WriteOptionDescriptions(Console.Out);
                    return;
                }
            }

            LogHelper.SetConfiguration(NLog.LogLevel.FromOrdinal(logLevelOrdinal));

            var dataBasePath = extras[0];
            Dictionary <Guid, PartitionMap.PartitionInfo> partitionMap;
            string outputPath;

            if (this._LoadPartitionMap == false)
            {
                partitionMap = null;
                outputPath   = extras.Count > 1 ? extras[1] : Path.Combine(dataBasePath, defaultOutputPath);
            }
            else
            {
                var partitionMapPath = extras[1];
                partitionMap = PartitionMap.Load(partitionMapPath);
                outputPath   = extras.Count > 2 ? extras[2] : Path.Combine(dataBasePath, defaultOutputPath);
            }

            var dataManager = DataManager.Initialize(dataBasePath, noPatch);

            if (dataManager == null)
            {
                Logger.Fatal("Could not initialize superbundle manager.");
                return;
            }

            foreach (var superbundleName in this._RequiredSuperbundleNames.Distinct())
            {
                if (dataManager.MountSuperbundle(superbundleName) == null)
                {
                    Logger.Fatal("Failed to mount '{0}'.", superbundleName);
                    return;
                }
            }

            this._DataManager = dataManager;
            callback(this, partitionMap, outputPath);
        }