예제 #1
0
        private void PackWadFolders(string wadLocation)
        {
            //Loop through each WAD folder
            foreach (string wadFolder in Directory.EnumerateDirectories(wadLocation))
            {
                char   separator = Pathing.GetPathSeparator(wadFolder);
                string wadName   = wadFolder.Split(separator).Last();

                using (WADFile wad = new WADFile(3, 0))
                {
                    //Add each file to the WAD
                    foreach (string wadFolderFile in Directory.EnumerateFiles(wadFolder, "*", SearchOption.AllDirectories))
                    {
                        string path      = wadFolderFile.Replace(wadFolder + separator, "").Replace('\\', '/');
                        ulong  hash      = XXHash.XXH64(Encoding.ASCII.GetBytes(path.ToLower()));
                        string extension = Path.GetExtension(wadFolderFile);

                        wad.AddEntry(hash, File.ReadAllBytes(wadFolderFile), extension != ".wpk" && extension != ".bnk" ? true : false);
                    }

                    //After WAD creation is finished we can write the WAD to the ZIP
                    ZipArchiveEntry archiveEntry = this.Content.CreateEntry(string.Format(@"WAD\{0}", wadName));
                    wad.Write(archiveEntry.Open());
                }
            }
        }
예제 #2
0
        public static WADFile Merge(WADFile wadBase, WADFile wadMerge)
        {
            //First add new files and then modify changed ones
            foreach (WADEntry entry in wadMerge.Entries)
            {
                WADEntry baseEntry = wadBase.Entries.FirstOrDefault(x => x.XXHash == entry.XXHash);

                if (baseEntry == null)
                {
                    if (entry.Type == EntryType.Uncompressed)
                    {
                        wadBase.AddEntry(entry.XXHash, entry.GetContent(false), false);
                    }
                    else if (entry.Type == EntryType.ZStandardCompressed || entry.Type == EntryType.Compressed)
                    {
                        wadBase.AddEntryCompressed(entry.XXHash, entry.GetContent(false), entry.UncompressedSize, entry.Type);
                    }
                }
                else if (!entry.SHA.SequenceEqual(baseEntry.SHA))
                {
                    if (entry.Type == EntryType.Uncompressed)
                    {
                        wadBase.Entries.Single(x => x.XXHash == entry.XXHash).EditData(entry.GetContent(false));
                    }
                    else if (entry.Type == EntryType.ZStandardCompressed || entry.Type == EntryType.Compressed)
                    {
                        wadBase.Entries.Single(x => x.XXHash == entry.XXHash).EditData(entry.GetContent(false), entry.UncompressedSize);
                    }
                }
            }

            return(wadBase);
        }