public ArchiveAccessor CreateDescriptor(ArchiveEntry entry) { ArchiveAccessor result = new ArchiveAccessor(null, _binaryFile, entry); result._level = _level + 1; return(result); }
private void ParseEntries(ArchiveListingEntryInfoV2[] entries, ArchiveListingCompressedData data, ArchiveListing result) { byte[] buff = new byte[0]; for (int currentBlock = -1, i = 0; i < entries.Length; i++) { ArchiveListingEntryInfoV2 entryInfoV2 = entries[i]; if (entryInfoV2.BlockNumber != currentBlock) { currentBlock = entryInfoV2.BlockNumber; buff = data.AcquireData(currentBlock); } string name; long sector, uncompressedSize, compressedSize; ParseInfo(entryInfoV2, buff, out sector, out uncompressedSize, out compressedSize, out name); ArchiveEntry entry = new ArchiveEntry(name, sector, compressedSize, uncompressedSize) { UnknownNumber = entryInfoV2.UnknownNumber, UnknownValue = entryInfoV2.UnknownValue, UnknownData = entryInfoV2.UnknownData }; result.Add(entry); _progressIncrement.NullSafeInvoke(1); } }
public ArchiveAccessor CreateDescriptor(string binaryFile, ArchiveEntry entry) { ArchiveAccessor result = new ArchiveAccessor(new SharedMemoryMappedFile(binaryFile), _binaryFile, entry); result._level = _level + 1; return(result); }
public void Show(ArchiveListing listing, ArchiveEntry entry) { _listing = listing; _entry = entry; if (listing == null || entry == null) { _textBox.Text = null; return; } FFXIIITextEncoding encoding = InteractionService.TextEncoding.Provide().Encoding; ZtrFileEntry[] entries; using (Stream data = listing.Accessor.ExtractBinary(entry)) { ZtrFileUnpacker unpacker = new ZtrFileUnpacker(data, encoding); entries = unpacker.Unpack(); } if (entries.IsNullOrEmpty()) return; using (MemoryStream ms = new MemoryStream(4096)) { ZtrTextWriter writer = new ZtrTextWriter(ms, StringsZtrFormatter.Instance); writer.Write(entry.Name, entries); ms.Position = 0; using (StreamReader sr = new StreamReader(ms, System.Text.Encoding.UTF8, false)) _textBox.Text = sr.ReadToEnd(); } Visibility = Visibility.Visible; }
public UiDataTableNode(ArchiveListing listing, UiArchiveExtension extension, ArchiveEntry indices) : base(indices.Name, UiNodeType.DataTable) { _listing = listing; _extension = extension; _indices = indices; }
private void ParseEntries(ArchiveListingEntryInfoV1[] entries, ArchiveListingCompressedData data, ArchiveListing result) { byte[] buff = new byte[0]; for (int currentBlock = -1, i = 0; i < entries.Length; i++) { ArchiveListingEntryInfoV1 entryInfoV1 = entries[i]; if (entryInfoV1.BlockNumber != currentBlock) { currentBlock = entryInfoV1.BlockNumber; buff = data.AcquireData(currentBlock); } string name; long sector, uncompressedSize, compressedSize; ParseInfo(entryInfoV1, buff, out sector, out uncompressedSize, out compressedSize, out name); ArchiveEntry entry = new ArchiveEntry(name, sector, compressedSize, uncompressedSize) { UnknownNumber = entryInfoV1.UnknownNumber, UnknownValue = entryInfoV1.UnknownValue }; result.Add(entry); _progressIncrement.NullSafeInvoke(1); } }
public UiFileTableNode(ArchiveListing listing, UiArchiveExtension extension, ArchiveEntry indices, ArchiveEntry binary) : base(indices.Name, UiNodeType.FileTable) { _listing = listing; _extension = extension; _indices = indices; _binary = binary; }
public UiArchiveExtractor(ArchiveListing listing, ArchiveEntry[] leafs, bool? conversion, IUiExtractionTarget target) { _listing = listing; _leafs = leafs; _target = target; _conversion = conversion; _extractors = ProvideExtractors(); }
public void Extract(ArchiveEntry entry, StreamSequence output, Stream input, Byte[] buff) { int size = (int)entry.UncompressedSize; if (size == 0) return; input.CopyToStream(output, size, buff); }
public ArchiveAccessor(string binaryFile, string listingFile) { _binaryFile = new SharedMemoryMappedFile(binaryFile); _listingFile = new SharedMemoryMappedFile(listingFile); FileInfo listingFileInfo = new FileInfo(listingFile); ListingEntry = new ArchiveEntry(listingFileInfo.Name, 0, listingFileInfo.Length, listingFileInfo.Length); }
public void Write(ArchiveListing listing, out ArchiveListingBlockInfo[] blocksInfo, out ArchiveListingEntryInfoV2[] entriesInfoV2) { using (MemoryStream ms = new MemoryStream(32768)) { int blockNumber = 0, unpackedBlockOffset = 0; entriesInfoV2 = new ArchiveListingEntryInfoV2[listing.Count]; List <ArchiveListingBlockInfo> blocks = new List <ArchiveListingBlockInfo>(128); using (FormattingStreamWriter sw = new FormattingStreamWriter(ms, Encoding.ASCII, 4096, true, CultureInfo.InvariantCulture)) { sw.AutoFlush = true; for (int i = 0; i < listing.Count; i++) { ArchiveEntry entry = listing[i]; ArchiveListingEntryInfoV2 info = new ArchiveListingEntryInfoV2 { BlockNumber = (short)(ms.Position / 8192) }; info.Flag = (info.BlockNumber % 2 != 0); entriesInfoV2[i] = info; if (blockNumber != info.BlockNumber) { int blockSize = (int)(ms.Position - unpackedBlockOffset); ms.Position = unpackedBlockOffset; ArchiveListingBlockInfo block = new ArchiveListingBlockInfo { Offset = (int)_output.Position, UncompressedSize = blockSize }; block.CompressedSize = ZLibHelper.Compress(ms, _output, block.UncompressedSize); blocks.Add(block); blockNumber++; unpackedBlockOffset = (int)ms.Position; sw.Write("{0:x}:{1:x}:{2:x}:{3}\0", entry.Sector, entry.UncompressedSize, entry.Size, entry.Name); } else if (i == listing.Count - 1) { info.Offset = (short)(ms.Position - unpackedBlockOffset); sw.Write("{0:x}:{1:x}:{2:x}:{3}\0end\0", entry.Sector, entry.UncompressedSize, entry.Size, entry.Name); int blockSize = (int)(ms.Position - unpackedBlockOffset); ms.Position = unpackedBlockOffset; ArchiveListingBlockInfo block = new ArchiveListingBlockInfo { Offset = (int)_output.Position, UncompressedSize = blockSize }; block.CompressedSize = ZLibHelper.Compress(ms, _output, block.UncompressedSize); blocks.Add(block); } else { info.Offset = (short)(ms.Position - unpackedBlockOffset); sw.Write("{0:x}:{1:x}:{2:x}:{3}\0", entry.Sector, entry.UncompressedSize, entry.Size, entry.Name); } } } blocksInfo = blocks.ToArray(); } }
public UiArchiveInjector(ArchiveListing listing, ArchiveEntry[] leafs, bool? conversion, bool? compression, IUiInjectionSource source) { _listing = listing; _leafs = leafs; _source = source; _conversion = conversion; _compression = compression; _injectionData = new ArchiveEntryInjectionData(_listing, OpenOutputStream); _injectors = ProvideInjectors(); }
public void Write() { using (MemoryStream headerBuff = new MemoryStream(32768)) using (MemoryStream textBuff = new MemoryStream(32768)) { ArchiveListingBlockInfo[] blocksInfo; ArchiveListingEntryInfoV2[] entriesInfoV2; ArchiveListingTextWriterV2 textWriter = new ArchiveListingTextWriterV2(textBuff); textWriter.Write(_listing, out blocksInfo, out entriesInfoV2); for (int i = 0; i < entriesInfoV2.Length; i++) { ArchiveListingEntryInfoV2 info = entriesInfoV2[i]; ArchiveEntry entry = _listing[i]; info.UnknownNumber = entry.UnknownNumber; info.UnknownValue = entry.UnknownValue; info.UnknownData = entry.UnknownData; } byte[] buff = new byte[8192]; int blocksSize = (int)textBuff.Position; textBuff.Position = 0; ArchiveListingHeaderV2 header = (ArchiveListingHeaderV2)_listing.Header; header.EntriesCount = entriesInfoV2.Length; header.RawBlockOffset = entriesInfoV2.Length * 8 + 12; header.RawInfoOffset = header.RawBlockOffset + blocksInfo.Length * 12; headerBuff.WriteContent(header); foreach (ArchiveListingEntryInfoV2 entry in entriesInfoV2) { headerBuff.WriteContent(entry); } foreach (ArchiveListingBlockInfo block in blocksInfo) { headerBuff.WriteStruct(block); } int hederSize = (int)headerBuff.Length; headerBuff.Position = 0; if (header.IsEncrypted) { RecreateEncryptedListing(headerBuff, hederSize, textBuff, blocksSize, buff); } else { using (Stream output = _accessor.RecreateListing(hederSize + blocksSize)) { headerBuff.CopyToStream(output, hederSize, buff); textBuff.CopyToStream(output, blocksSize, buff); } } } }
public void Extract(ArchiveEntry entry, StreamSequence output, Stream input, Byte[] buff) { int size = (int)entry.UncompressedSize; if (size == 0) return; ZtrFileUnpacker unpacker = new ZtrFileUnpacker(input, InteractionService.TextEncoding.Provide().Encoding); ZtrFileEntry[] entries = unpacker.Unpack(); ZtrTextWriter writer = new ZtrTextWriter(output, StringsZtrFormatter.Instance); writer.Write(entry.Name, entries); }
public bool TryInject(IUiInjectionSource source, string sourceFullPath, ArchiveEntryInjectionData data, ArchiveEntry entry) { using (Stream input = source.TryOpen(sourceFullPath)) { if (input == null) return false; using (Stream output = data.OuputStreamFactory(entry)) input.CopyToStream(output, (int)input.Length, data.Buffer); return true; } }
private IArchiveEntryExtractor GetExtractor(ArchiveEntry entry, out String targetExtension) { IArchiveEntryExtractor result; targetExtension = PathEx.GetMultiDotComparableExtension(entry.Name); if (entry.Name.Contains("_jp") || entry.Name.Contains("_kr")) result = DefaultExtractor; else if (_extractors.TryGetValue(targetExtension, out result)) targetExtension = result.TargetExtension; else if (_conversion != true) result = DefaultExtractor; return result; }
public bool TryAdd(ArchiveListing listing, ArchiveEntry entry, string entryPath, string entryName) { if (TryAddZoneListing(listing, entry, entryPath)) return true; // ������ ��� ������ ��� ����������� �� ������� //if (TryAddSoundListing(listing, entry, entryName)) // return true; if (TryAddImgbPair(listing, entry, entryPath, entryName)) return true; return false; }
public static Stream BackgroundExtractIfCompressed(Stream input, ArchiveEntry entry) { if (!entry.IsCompressed) return input; int uncompressedSize = (int)entry.UncompressedSize; if (uncompressedSize == 0) return new MemoryStream(0); Stream writer, reader; Flute.CreatePipe(uncompressedSize, out writer, out reader); //if (!ThreadPool.QueueUserWorkItem((o) => ZLibHelper.UncompressAndDisposeStreams(input, writer, uncompressedSize, CancellationToken.None))) ThreadHelper.StartBackground("UncompressAndDisposeSourceAsync", () => ZLibHelper.UncompressAndDisposeStreams(input, writer, uncompressedSize, CancellationToken.None)); return reader; }
public void Show(ArchiveListing listing, ArchiveEntry entry) { _listing = listing; _entry = entry; Visibility = Visibility.Visible; using (Stream input = listing.Accessor.ExtractBinary(entry)) { ScdFileReader reader = new ScdFileReader(input); WaveStream[] waveProviders = reader.Read(); ListItem[] items = new ListItem[waveProviders.Length]; for (int i = 0; i < items.Length; i++) items[i] = new ListItem(i.ToString("D3"), waveProviders[i]); _listView.ItemsSource = items; if (items.Length > 0) _listView.SelectedIndex = 0; } }
public Stream OpenOrAppendBinary(ArchiveEntry entry, int newSize) { try { long capacity = MathEx.RoundUp(entry.Size, 0x800); if (newSize <= capacity) { return(_binaryFile.CreateViewStream(entry.Offset, newSize, MemoryMappedFileAccess.Write)); } long offset; Stream result = _binaryFile.IncreaseSize(MathEx.RoundUp(newSize, 0x800), out offset); entry.Sector = (int)(offset / 0x800); return(result); } finally { entry.Size = newSize; } }
public void OnWritingCompleted(ArchiveEntry entry, MemoryStream ms, bool?compression) { ms.Position = 0; int compressedSize = 0; int uncompressedSize = (int)ms.Length; byte[] copyBuff = new byte[Math.Min(uncompressedSize, 32 * 1024)]; try { bool compress = uncompressedSize > 256 && (compression ?? entry.IsCompressed); if (compress) { using (SafeUnmanagedArray buff = new SafeUnmanagedArray(uncompressedSize + 256)) using (UnmanagedMemoryStream buffStream = buff.OpenStream(FileAccess.ReadWrite)) { compressedSize = ZLibHelper.Compress(ms, buffStream, uncompressedSize); if (uncompressedSize - compressedSize > 256) { using (Stream output = OpenOrAppendBinary(entry, compressedSize)) { buffStream.Position = 0; buffStream.CopyToStream(output, compressedSize, copyBuff); } return; } } } ms.Position = 0; compressedSize = uncompressedSize; using (Stream output = OpenOrAppendBinary(entry, uncompressedSize)) ms.CopyToStream(output, uncompressedSize, copyBuff); } finally { entry.Size = compressedSize; entry.UncompressedSize = uncompressedSize; } }
public void Extract(ArchiveEntry entry, StreamSequence output, Stream input, Byte[] buff) { int size = (int)entry.UncompressedSize; if (size == 0) return; ScdFileReader reader = new ScdFileReader(input); WaveStream[] waveStreams = reader.Read(); if (waveStreams.Length == 0) return; Extract(output, waveStreams[0], buff); for (int i = 1; i < waveStreams.Length; i++) { if (!output.TryCreateNextStream(i.ToString("D3"))) throw new InvalidDataException(); Extract(output, waveStreams[i], buff); } }
public static Stream BackgroundExtractIfCompressed(Stream input, ArchiveEntry entry) { if (!entry.IsCompressed) { return(input); } int uncompressedSize = (int)entry.UncompressedSize; if (uncompressedSize == 0) { return(new MemoryStream(0)); } Stream writer, reader; Flute.CreatePipe(uncompressedSize, out writer, out reader); //if (!ThreadPool.QueueUserWorkItem((o) => ZLibHelper.UncompressAndDisposeStreams(input, writer, uncompressedSize, CancellationToken.None))) ThreadHelper.StartBackground("UncompressAndDisposeSourceAsync", () => ZLibHelper.UncompressAndDisposeStreams(input, writer, uncompressedSize, CancellationToken.None)); return(reader); }
private bool TryAddSoundListing(ArchiveListing parentListing, ArchiveEntry entry, String entryName) { switch (entryName) { case "filelist_sound_pack.win32.bin": case "filelist_sound_pack.win32_us.bin": break; default: return false; } ArchiveAccessor accessor = parentListing.Accessor.CreateDescriptor(entry); ConcurrentBag<UiNode> container = ProvideRootNodeChilds(UiArchiveExtension.Bin); container.Add(new UiArchiveNode(accessor, parentListing)); return true; }
public ImgbArchiveAccessor(ArchiveListing parent, ArchiveEntry headersEntry, ArchiveEntry contentEntry) : base(parent, headersEntry) { ContentEntry = contentEntry; }
private ArchiveAccessor(SharedMemoryMappedFile binaryFile, SharedMemoryMappedFile listingFile, ArchiveEntry listingEntry) { _binaryFile = binaryFile; _listingFile = listingFile; ListingEntry = listingEntry; }
private Stream OpenOutputStream(ArchiveEntry entry) { MemoryStream ms = new MemoryStream((int)(entry.UncompressedSize * 1.3)); DisposableStream writer = new DisposableStream(ms); writer.BeforeDispose.Add(new DisposableAction(() => _listing.Accessor.OnWritingCompleted(entry, ms, _compression))); return writer; }
public Stream ExtractBinary(ArchiveEntry entry) { Stream compressed = _binaryFile.CreateViewStream(entry.Offset, entry.Size, MemoryMappedFileAccess.Read); return BackgroundExtractIfCompressed(compressed, entry); }
private void Inject(ArchiveEntry entry, String sourcePath) { string sourceExtension = PathEx.GetMultiDotComparableExtension(entry.Name); string sourceFullPath = sourcePath + sourceExtension; IArchiveEntryInjector injector; if (_injectors.TryGetValue(sourceExtension, out injector)) { sourceFullPath = sourcePath + injector.SourceExtension; if (injector.TryInject(_source, sourceFullPath, _injectionData, entry)) { _injected = true; return; } } if (_conversion != true) { if (DefaultInjector.TryInject(_source, sourceFullPath, _injectionData, entry)) _injected = true; } }
public ArchiveAccessor CreateDescriptor(string binaryFile, ArchiveEntry entry) { ArchiveAccessor result = new ArchiveAccessor(new SharedMemoryMappedFile(binaryFile), _binaryFile, entry); result._level = _level + 1; return result; }
public ArchiveAccessor CreateDescriptor(ArchiveEntry entry) { ArchiveAccessor result = new ArchiveAccessor(null, _binaryFile, entry); result._level = _level + 1; return result; }
public bool TryInject(IUiInjectionSource source, string sourceFullPath, ArchiveEntryInjectionData data, ArchiveEntry entry) { Dictionary<string, string> sourceEntries; using (Stream input = source.TryOpen(sourceFullPath)) { if (input != null) { string entryName; ZtrTextReader reader = new ZtrTextReader(input, StringsZtrFormatter.Instance); sourceEntries = reader.Read(out entryName).ToDictionary(e => e.Key, e => e.Value); using (Stream output = data.OuputStreamFactory(entry)) Inject(data.Listing, entry, sourceEntries, output); return true; } } MemoryInjectionSource memorySource = source as MemoryInjectionSource; if (memorySource == null) return false; sourceEntries = memorySource.TryProvideStrings(); if (sourceEntries == null) return false; using (Stream output = data.OuputStreamFactory(entry)) Inject(data.Listing, entry, sourceEntries, output); return true; }
public Stream OpenBinary(ArchiveEntry entry) { return(_binaryFile.CreateViewStream(entry.Offset, entry.Size, MemoryMappedFileAccess.ReadWrite)); }
public UiArchiveLeaf(string name, ArchiveEntry entry, ArchiveListing listing) : base(name, UiNodeType.ArchiveLeaf) { Entry = entry; Listing = listing; }
public Stream ExtractBinary(ArchiveEntry entry) { Stream compressed = _binaryFile.CreateViewStream(entry.Offset, entry.Size, MemoryMappedFileAccess.Read); return(BackgroundExtractIfCompressed(compressed, entry)); }
public void OnWritingCompleted(ArchiveEntry entry, MemoryStream ms, bool? compression) { ms.Position = 0; int compressedSize = 0; int uncompressedSize = (int)ms.Length; byte[] copyBuff = new byte[Math.Min(uncompressedSize, 32 * 1024)]; try { bool compress = uncompressedSize > 256 && (compression ?? entry.IsCompressed); if (compress) { using (SafeUnmanagedArray buff = new SafeUnmanagedArray(uncompressedSize + 256)) using (UnmanagedMemoryStream buffStream = buff.OpenStream(FileAccess.ReadWrite)) { compressedSize = ZLibHelper.Compress(ms, buffStream, uncompressedSize); if (uncompressedSize - compressedSize > 256) { using (Stream output = OpenOrAppendBinary(entry, compressedSize)) { buffStream.Position = 0; buffStream.CopyToStream(output, compressedSize, copyBuff); } return; } } } ms.Position = 0; compressedSize = uncompressedSize; using (Stream output = OpenOrAppendBinary(entry, uncompressedSize)) ms.CopyToStream(output, uncompressedSize, copyBuff); } finally { entry.Size = compressedSize; entry.UncompressedSize = uncompressedSize; } }
private bool TryAddZoneListing(ArchiveListing parentListing, ArchiveEntry entry, string entryPath) { if (_areasDirectory == null) return false; if (!entryPath.StartsWith("zone/filelist")) return false; // ���������� ������ ������ if (entryPath.EndsWith("2")) return false; string binaryName; switch (InteractionService.GamePart) { case FFXIIIGamePart.Part1: binaryName = $"white_{entryPath.Substring(14, 5)}_img{(entryPath.EndsWith("2") ? "2" : string.Empty)}.win32.bin"; break; case FFXIIIGamePart.Part2: binaryName = $"white_{entryPath.Substring(14, 6)}_img{(entryPath.EndsWith("2") ? "2" : string.Empty)}.win32.bin"; break; default: throw new NotSupportedException("InteractionService.GamePart"); } string binaryPath = Path.Combine(_areasDirectory, binaryName); if (!File.Exists(binaryPath)) return false; ArchiveAccessor accessor = parentListing.Accessor.CreateDescriptor(binaryPath, entry); ConcurrentBag<UiNode> container = ProvideRootNodeChilds(UiArchiveExtension.Bin); container.Add(new UiArchiveNode(accessor, parentListing)); return true; }
public Stream OpenBinary(ArchiveEntry entry) { return _binaryFile.CreateViewStream(entry.Offset, entry.Size, MemoryMappedFileAccess.ReadWrite); }
public Stream OpenOrAppendBinary(ArchiveEntry entry, int newSize) { try { long capacity = MathEx.RoundUp(entry.Size, 0x800); if (newSize <= capacity) return _binaryFile.CreateViewStream(entry.Offset, newSize, MemoryMappedFileAccess.Write); long offset; Stream result = _binaryFile.IncreaseSize(MathEx.RoundUp(newSize, 0x800), out offset); entry.Sector = (int)(offset / 0x800); return result; } finally { entry.Size = newSize; } }
private void Inject(ArchiveListing listing, ArchiveEntry entry, Dictionary<String, String> sourceEntries, Stream output) { ZtrFileEntry[] targetEntries; using (Stream original = listing.Accessor.ExtractBinary(entry)) { ZtrFileUnpacker unpacker = new ZtrFileUnpacker(original, InteractionService.TextEncoding.Provide().Encoding); targetEntries = unpacker.Unpack(); } MergeEntries(sourceEntries, targetEntries); ZtrFilePacker packer = new ZtrFilePacker(output, InteractionService.TextEncoding.Provide().Encoding); packer.Pack(targetEntries); }
public DbArchiveAccessor(ArchiveListing parent, ArchiveEntry headersEntry) { Parent = parent; HeadersEntry = headersEntry; }