public List <IsoTableEntryInfo> GetEntriesInfo(IList <IsoTableEntry> entries) { ProgressTotalChanged.NullSafeInvoke(entries.Count); List <IsoTableEntryInfo> result = new List <IsoTableEntryInfo>(entries.Count); int counter = 0; for (int i = 0; i < entries.Count - 1; i++) { IsoTableEntry entry = entries[i]; long compressedSize = (entries[i + 1].Sector - entry.Sector) * _isoInfo.SectorSize - entry.Left; if (compressedSize < 1) { ProgressIncrement.NullSafeInvoke(1); continue; } long offset = entry.Sector * _isoInfo.SectorSize; IsoTableEntryInfo info = new IsoTableEntryInfo(i, counter++, offset, compressedSize, entry.Flags); result.Add(info); ProgressIncrement.NullSafeInvoke(1); } return(result); }
private void SafeReadAdditionalEntryInfo(IsoTableEntryInfo info) { try { if (info.CompressedSize < 4) { return; } byte[] signature; using (Stream input = OpenStream(info.Offset, info.CompressedSize)) using (MemoryStream output = new MemoryStream(4)) { if (!info.IsCompressed) { info.IsCompressed = (input.ReadByte() == 0x01); input.Seek(-1, SeekOrigin.Current); } if (info.IsCompressed) { input.Seek(1, SeekOrigin.Current); int uncompressedSize = input.ReadStruct <int>(); if (uncompressedSize < 4) { return; } LZSStream decompressStream = new LZSStream(input, output); decompressStream.Decompress(4); output.Flush(); signature = output.ToArray(); if (signature.Length == 0) { return; } } else { signature = new byte[4]; input.EnsureRead(signature, 0, 4); } } info.Signature = (FFXFileSignatures)BitConverter.ToInt32(signature, 0); } catch (Exception ex) { Log.Error(ex, "Failed to read additional info of entry '{0}'", info.GetFileName()); } finally { ProgressIncrement.NullSafeInvoke(1); } }
public void FillKnownFileInformation(List <IsoTableEntryInfo> infos) { Dictionary <int, IsoTableEntryInfo> dic = new Dictionary <int, IsoTableEntryInfo>(infos.Count); foreach (IsoTableEntryInfo info in infos) { dic.Add(info.Index, info); } using (Stream input = Assembly.GetExecutingAssembly().GetManifestResourceStream("Spira.ISO." + ExecutableFileName.Replace(".", "._") + ".AdditionalFileInformation.bin")) { if (input == null) { return; } using (BinaryReader br = new BinaryReader(input)) { while (!input.IsEndOfStream()) { int index = br.ReadInt32(); int defective = br.ReadInt32(); IsoTableEntryInfo info = dic[index]; info.AdditionalInfo = (IsoAdditionalInfo)br.ReadInt32(); if ((info.AdditionalInfo & IsoAdditionalInfo.PS2KnownSignature) == IsoAdditionalInfo.PS2KnownSignature) { info.Signature = (FFXFileSignatures)br.ReadInt32(); } if ((info.AdditionalInfo & IsoAdditionalInfo.PS2KnownName) == IsoAdditionalInfo.PS2KnownName) { info.PS2KnownName = br.ReadString(); } if ((info.AdditionalInfo & IsoAdditionalInfo.PS3KnownPath) == IsoAdditionalInfo.PS3KnownPath) { info.PS3KnownPath = br.ReadString(); } } } } }
public void ExtractFile(IsoTableEntryInfo info, string outputPath) { Directory.CreateDirectory(Path.GetDirectoryName(outputPath)); using (Stream input = OpenStream(info.Offset, info.CompressedSize)) using (Stream output = File.Create(outputPath)) { if (!info.IsCompressed) { input.CopyTo(output); } else { input.Seek(1, SeekOrigin.Current); int uncompressedSize = input.ReadStruct <int>(); LZSStream decompressStream = new LZSStream(input, output); decompressStream.Decompress(uncompressedSize); } } }