Exemplo n.º 1
0
        private static CpkFile PackCpkDoAppend(Options options, string cpkBaseName, string cpkDir)
        {
            CpkFile cpk;

            Console.WriteLine($"Appending to: {options.AppendPath}");
            Console.WriteLine($"Loading CPK: {options.AppendPath}");
            cpk = new CpkFile(options.AppendPath);

            // Create new PAC
            var newPacIndex = options.PacIndex.GetValueOrDefault(cpk.Entries.Select(x => x.PacIndex).Max() + 1);
            var pacName     = FormatPacName($"{GetPacBaseNameFromCpkBaseName( cpkDir, cpkBaseName )}", newPacIndex);

            Console.WriteLine("Creating PAC: {pacName}");
            var pacPath = Path.Combine(cpkDir, pacName);

            var pac = DwPackFile.Pack(options.InputPath, newPacIndex, options.Compress, (e =>
            {
                Console.WriteLine($"Adding {e}");
                return(true);
            }));

            using var packFile = File.Create(pacPath);
            pac.Write(packFile, options.Compress, (e => Console.WriteLine($"Writing {e.Path}")));

            // Add entries to CPK
            for (var i = 0; i < pac.Entries.Count; i++)
            {
                var entry = pac.Entries[i];
                cpk.Entries.Add(new CpkFileEntry(entry.Path, (short)i, (short)newPacIndex));
            }

            return(cpk);
        }
Exemplo n.º 2
0
        private static DwPackFile PackPacDoPack(Options options)
        {
            DwPackFile pack;

            Console.WriteLine($"Creating PAC: {Path.GetFileName( options.OutputPath )}");
            pack = DwPackFile.Pack(options.InputPath, options.PacIndex.GetValueOrDefault(0), options.Compress, (p =>
            {
                Console.WriteLine($"Adding {p}");
                return(true);
            }));
            return(pack);
        }
Exemplo n.º 3
0
        private static DwPackFile PackPacDoAppend(Options options)
        {
            DwPackFile pack;

            Console.WriteLine($"Appending to PAC: { options.OutputPath }");
            pack = new DwPackFile(options.AppendPath);
            pack.AddFiles(options.InputPath, options.Compress, (p =>
            {
                Console.WriteLine($"Adding {p}");
                return(true);
            }));
            return(pack);
        }
Exemplo n.º 4
0
        static int UnpackPac(Options options)
        {
            var pack = new DwPackFile(options.InputPath);

            pack.Unpack(options.OutputPath, (entry =>
            {
                if (!ShouldUnpack(entry.Path))
                {
                    return(false);
                }
                Console.WriteLine($"Extracting {entry.Path}");
                return(true);
            }));
            return(0);
        }
Exemplo n.º 5
0
        static int UnpackCpk(Options options)
        {
            var name = Path.GetFileNameWithoutExtension(options.InputPath);
            var dir  = Path.GetDirectoryName(options.InputPath);

            // Try to detect pac base name
            var pacBaseName = GetPacBaseNameFromCpkBaseName(dir, name);
            var cpk         = new CpkFile(options.InputPath);

            // Load needed pacs
            var packs = new List <DwPackFile>();

            foreach (var pacIdx in cpk.Entries.Select(x => x.PacIndex).Distinct().OrderBy(x => x))
            {
                var pacName = $"{pacBaseName}{pacIdx:D5}.pac";
                var pacPath = Path.Combine(dir, pacName);
                if (!File.Exists(pacPath))
                {
                    Console.WriteLine($"Failed to unpack: Missing {pacName}");
                    return(1);
                }

                var pac          = new DwPackFile(pacPath);
                var refFileCount = cpk.Entries.Where(x => x.PacIndex == pacIdx)
                                   .Select(x => x.FileIndex)
                                   .Max() + 1;
                if (refFileCount > pac.Entries.Count)
                {
                    Console.WriteLine($"Failed to unpack: CPK references {refFileCount} in {pacName} but only {pac.Entries.Count} exist.");
                    return(1);
                }

                packs.Add(pac);
            }

            cpk.Unpack(packs, options.OutputPath, (e =>
            {
                if (!ShouldUnpack(e.Path))
                {
                    return(false);
                }
                Console.WriteLine($"Extracting {e.Path} (pac: {e.PacIndex}, file: {e.FileIndex})");
                return(true);
            }));
            return(0);
        }