コード例 #1
0
        public static void Main(string[] args)
        {
            var showHelp = false;

            var 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 < 1 || extras.Count > 2 || showHelp == true)
            {
                Console.WriteLine("Usage: {0} [OPTIONS]+ input.toc_group [output_dir]", GetExecutableName());
                Console.WriteLine();
                Console.WriteLine("Options:");
                options.WriteOptionDescriptions(Console.Out);
                return;
            }

            var inputPath      = Path.GetFullPath(extras[0]);
            var outputBasePath = extras.Count > 1 ? extras[1] : Path.ChangeExtension(inputPath, null) + "_unpack";

            FileFormats.TableOfContentsGroupFile toc;
            using (var input = File.OpenRead(inputPath))
            {
                toc = new FileFormats.TableOfContentsGroupFile();
                toc.Deserialize(input, Endian.Little);
            }

            if (toc.InternalEntries.Count == 0)
            {
                return;
            }

            var inputBasePath = inputPath;

            string inputDataPath = null;

            while (inputBasePath != null)
            {
                inputBasePath = Path.GetDirectoryName(inputBasePath);
                var candidatePath = Path.Combine(inputBasePath ?? "", toc.InternalDataPath);
                if (File.Exists(candidatePath) == true)
                {
                    inputDataPath = candidatePath;
                    break;
                }
            }

            if (inputDataPath == null)
            {
                Console.WriteLine("Could not find packfile.");
                return;
            }

            using (var input = File.OpenRead(inputDataPath))
            {
                foreach (var entry in toc.InternalEntries)
                {
                    var outputPath       = Path.Combine(outputBasePath, entry.Name);
                    var outputParentPath = Path.GetDirectoryName(outputPath);
                    if (string.IsNullOrEmpty(outputParentPath) == false)
                    {
                        Directory.CreateDirectory(outputParentPath);
                    }
                    using (var output = File.Create(outputPath))
                    {
                        input.Position = entry.Offset;
                        output.WriteFromStream(input, entry.Size);
                    }
                }
            }
        }
コード例 #2
0
        public static void Main(string[] args)
        {
            var showHelp = false;
            var dataPath = "pc_media";

            var options = new OptionSet()
            {
                { "d|data-path=", "set data path", v => dataPath = v },
                { "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 < 1 || extras.Count > 2 || showHelp == true)
            {
                Console.WriteLine("Usage: {0} [OPTIONS]+ input.toc_group [output.toc_group]", GetExecutableName());
                Console.WriteLine();
                Console.WriteLine("Options:");
                options.WriteOptionDescriptions(Console.Out);
                return;
            }

            var inputPath  = Path.GetFullPath(extras[0]);
            var outputPath = extras.Count > 1
                                 ? extras[1]
                                 : Path.ChangeExtension(inputPath, null) + "_convert.toc_group";

            FileFormats.TableOfContentsGroupFile toc;
            using (var input = File.OpenRead(inputPath))
            {
                toc = new FileFormats.TableOfContentsGroupFile();
                toc.Deserialize(input, Endian.Little);
            }

            foreach (var entry in toc.InternalEntries)
            {
                toc.ExternalEntries.Add(new FileFormats.TableOfContentsGroupFile.ExternalEntry()
                {
                    Name = entry.Name,
                    Size = entry.Size,
                    Path = Path.Combine(dataPath, entry.Name)
                });
            }

            toc.InternalPriority = 0;
            toc.InternalDataPath = null;
            toc.InternalEntries.Clear();

            using (var output = File.Create(outputPath))
            {
                toc.Serialize(output, Endian.Little);
            }
        }