/// <summary> /// Extracts the KIFINT entry file from the the entry's open KIFINT archive stream and saves it to the output /// <paramref name="directory"/>. /// </summary> /// <param name="kifintStream">The stream to the open KIFINT archive.</param> /// <param name="entry">The KIFINT entry used to locate the file.</param> /// <param name="directory"> /// The directory to save the file to. The file name will be <see cref="KifintEntry.FileName"/>. /// </param> /// /// <exception cref="ArgumentNullException"> /// <paramref name="kifintStream"/>, <paramref name="entry"/>, or <paramref name="directory"/> is null. /// </exception> public static void ExtractToDirectory(KifintStream kifintStream, KifintEntry entry, string directory) { if (kifintStream == null) { throw new ArgumentNullException(nameof(kifintStream)); } if (entry == null) { throw new ArgumentNullException(nameof(entry)); } if (directory == null) { throw new ArgumentNullException(nameof(directory)); } var kifint = entry.Kifint; kifintStream.Open(kifint); BinaryReader reader = new BinaryReader(kifintStream); kifintStream.Position = entry.Offset; byte[] buffer = reader.ReadBytes(entry.Length); if (kifint.IsEncrypted) { DecryptData(buffer, entry.Length, kifint.FileKey); } File.WriteAllBytes(Path.Combine(directory, entry.FileName), buffer); }
/// <summary> /// Extracts the KIFINT entry file from the the entry's KIFINT archive. /// </summary> /// <param name="kifintStream">The stream to the open KIFINT archive.</param> /// <param name="entry">The KIFINT entry used to locate the file.</param> /// <returns>A byte array containing the extracted KIFINT entry's file data.</returns> /// /// <exception cref="ArgumentNullException"> /// <paramref name="kifintStream"/> or <paramref name="entry"/> is null. /// </exception> public static byte[] Extract(KifintStream kifintStream, KifintEntry entry) { if (kifintStream == null) { throw new ArgumentNullException(nameof(kifintStream)); } if (entry == null) { throw new ArgumentNullException(nameof(entry)); } var kifint = entry.Kifint; kifintStream.Open(kifint); BinaryReader reader = new BinaryReader(kifintStream); kifintStream.Position = entry.Offset; byte[] buffer = reader.ReadBytes(entry.Length); if (kifint.IsEncrypted) { DecryptData(buffer, entry.Length, kifint.FileKey); } return(buffer); }