/// <summary> /// Loads header part 5 from a file stream. /// </summary> /// <param name="file">The file stream to load from.</param> /// <param name="offset">The absolute offset into the file where part 5 starts.</param> /// <param name="size">The size of part 5 in bytes.</param> /// <param name="p">Progress info.</param> public NefsHeaderPt5(FileStream file, UInt32 offset, UInt32 size, NefsProgressInfo p) { _offset = offset; _size = size; /* Validate inputs */ if (size == 0) { log.Warn("Header part 5 has a size of 0."); return; } /* Read the archive size */ FileData.ReadData(file, offset, this); /* Item entries begin after the archive size entry */ UInt32 firstEntryOffset = off_0x00_archive_size.Size; UInt32 entrySize = NefsHeaderPt5Entry.SIZE; UInt32 numEntries = (size - off_0x00_archive_size.Size) / entrySize; for (UInt32 i = 0; i < numEntries; i++) { _entries.Add(new NefsHeaderPt5Entry(file, this, firstEntryOffset + (i * entrySize))); } }
/// <summary> /// Writes header part 3 to a file stream. /// </summary> /// <param name="file">The file stream to write to.</param> public void Write(FileStream file, NefsProgressInfo p) { FileData.WriteData(file, _offset, this); /* Update size */ _size = (uint)data.Size; }
/// <summary> /// Loads header part 1 from a file stream. /// </summary> /// <param name="file">The file stream to load from.</param> /// <param name="offset">The absolute offset into the file where part 1 starts.</param> /// <param name="size">The size of part 1 in bytes.</param> /// <param name="p">Progress info.</param> internal NefsHeaderPt1(FileStream file, UInt32 offset, UInt32 size, NefsProgressInfo p) { _offset = offset; _size = size; /* Validate inputs */ if (size == 0) { log.Warn("Header part 1 has a size of 0."); return; } UInt32 nextEntry = offset; UInt32 lastEntry = offset + size - NefsHeaderPt1Entry.SIZE; UInt32 numEntries = size / NefsHeaderPt1Entry.SIZE; /* Load each entry */ while (nextEntry <= lastEntry) { p.BeginTask(1.0f / (float)numEntries); var entry = new NefsHeaderPt1Entry(file, nextEntry); _entries.Add(entry); nextEntry += NefsHeaderPt1Entry.SIZE; p.EndTask(); } }
void extractNEFS() { NefsProgressInfo _progressInfo = new NefsProgressInfo(); _progressInfo.Progress = new Progress <NefsProgress>(); DirectoryInfo di = new DirectoryInfo(PathToCars); foreach (FileInfo fi in di.GetFiles("*.nefs")) { try { NefsArchive archive = new NefsArchive(fi.FullName, _progressInfo); NefsItem item = archive.GetItem(13); string car3 = fi.Name.Replace(fi.Extension, ""); FileInfo fi2 = new FileInfo(PathToCars + "\\" + car3 + "\\" + item.Filename + ".bin.xml"); item.Extract(fi2.FullName, _progressInfo); string filename = PathToCars + "\\" + car3 + "\\" + item.Filename; ConvertBinXMLToPlainXML(fi2.FullName, filename); } catch (Exception) { } } }
/// <summary> /// Writes header part 6 to a file stream. /// </summary> /// <param name="file">The file stream to write to.</param> /// <param name="p">Progress info.</param> public void Write(FileStream file, NefsProgressInfo p) { foreach (var entry in _entries) { p.BeginTask(1.0f / (float)_entries.Count); entry.Write(file); p.EndTask(); } /* Update size */ _size = (uint)_entries.Count * NefsHeaderPt6Entry.SIZE; }
/// <summary> /// Writes header part 2 to a file stream. /// </summary> /// <param name="file">The file stream to write to.</param> /// <param name="p">Progress info.</param> internal void Write(FileStream file, NefsProgressInfo p) { /* Write the data for each entry. Entries must be written in order. */ foreach (var e in _entries) { p.BeginTask(1.0f / (float)_entries.Count); e.Write(file); p.EndTask(); } /* Update size */ _size = (uint)_entries.Count * NefsHeaderPt2Entry.SIZE; }
/// <summary> /// Writes header part 1 to a file stream. /// </summary> /// <param name="file">The file stream to write to.</param> /// <param name="p">Progress info.</param> public void Write(FileStream file, NefsProgressInfo p) { /* Write the data for each entry. Entries must be written in order. */ foreach (var e in _entries) { p.BeginTask(1.0f / (float)_entries.Count); e.Write(file); p.EndTask(); } /* Update size (offset of part 1 doesn't change) */ _size = (uint)_entries.Count * NefsHeaderPt1Entry.SIZE; }
/// <summary> /// Parses the introductory section of the NeFS header. /// </summary> /// <param name="file">NeFS file to parse.</param> /// <param name="p">Progress reporting info.</param> public NefsHeaderIntro(FileStream file, NefsProgressInfo p) { /* Read the file data as defined by [FileData] fields */ FileData.ReadData(file, OFFSET, this); /* Calculate the sizes of the different header parts */ _part1_size = _hdr_008c_offset_to_part_2.Value - _hdr_0084_offset_to_part_1.Value; _part2_size = _hdr_0094_offset_to_part_3_strings.Value - _hdr_008c_offset_to_part_2.Value; _part3_size = _hdr_0098_offset_to_part_4.Value - _hdr_0094_offset_to_part_3_strings.Value; _part4_size = _hdr_009c_offset_to_part_5.Value - _hdr_0098_offset_to_part_4.Value; _part5_size = _hdr_0090_offset_to_part_6.Value - _hdr_009c_offset_to_part_5.Value; _part6_size = _hdr_00a0_offset_to_data.Value - _hdr_0090_offset_to_part_6.Value; // TODO : Verify hash?? }
public ProgressDialogForm() { InitializeComponent(); /* Create a progress reporter */ _progress = new Progress <NefsProgress>(); _progress.ProgressChanged += onProgress; /* Create a cancellation source */ _ctSource = new CancellationTokenSource(); /* Create the nefs progress info */ _progressInfo = new NefsProgressInfo(); _progressInfo.CancellationToken = _ctSource.Token; _progressInfo.Progress = _progress; }
/// <summary> /// Writes header part 5 to a file stream. /// </summary> /// <param name="file">The file stream to write to.</param> /// <param name="p">Progress info.</param> public void Write(FileStream file, NefsProgressInfo p) { /* Write the file size entry first */ FileData.WriteData(file, _offset, this); /* Write the item entries */ foreach (var entry in _entries) { p.BeginTask(1.0f / (float)_entries.Count); entry.Write(file); p.EndTask(); } /* Update size */ _size = off_0x00_archive_size.Size; _size += (uint)_entries.Count * NefsHeaderPt5Entry.SIZE; }
/// <summary> /// Loads header part 3 from a file stream. /// </summary> /// <param name="file">The file stream to load from.</param> /// <param name="offset">The absolute offset into the file where part 3 starts.</param> /// <param name="size">The size of part 3 in bytes.</param> /// <param name="p">Progress info.</param> internal NefsHeaderPt3(FileStream file, UInt32 offset, UInt32 size, NefsProgressInfo p) { _offset = offset; _size = size; /* Validate inputs */ if (size == 0) { log.Warn("Header part 3 has a size of 0."); return; } // Currently we are just storing all the strings from the file as-is and // not manipulating them. data = new ByteArrayType(0x0, size); FileData.ReadData(file, offset, this); }
internal NefsHeader(FileStream file, NefsArchive archive, NefsProgressInfo p) { _archive = archive; p.BeginTask(0.15f, "Reading header intro..."); _intro = new NefsHeaderIntro(file, p); p.EndTask(); p.BeginTask(0.15f, "Reading header part 1..."); _part1 = new NefsHeaderPt1(file, _intro.Part1Offset, _intro.Part1Size, p); p.EndTask(); p.BeginTask(0.15f, "Reading header part 2..."); _part2 = new NefsHeaderPt2(file, _intro.Part2Offset, _intro.Part2Size, p); p.EndTask(); p.BeginTask(0.10f, "Reading header part 3..."); _part3 = new NefsHeaderPt3(file, _intro.Part3Offset, _intro.Part3Size, p); p.EndTask(); p.BeginTask(0.15f, "Reading header part 4..."); _part4 = new NefsHeaderPt4(file, _intro.Part4Offset, _intro.Part4Size, p); p.EndTask(); p.BeginTask(0.10f, "Reading header part 5..."); _part5 = new NefsHeaderPt5(file, _intro.Part5Offset, _intro.Part5Size, p); p.EndTask(); p.BeginTask(0.10f, "Reading header part 6..."); _part6 = new NefsHeaderPt6(file, _intro.Part6Offset, _intro.Part6Size, p); p.EndTask(); p.BeginTask(0.10f, "Reading header part 7..."); // Theres a section of data after header part 6 and the first section of compressed data. // I'm not sure what it is. Just copying for now. var firstItemOffset = _part1.FirstItemDataOffset; if (firstItemOffset > 0 && firstItemOffset > _intro.DataOffset) { _part7 = new NefsHeaderPt7(file, _intro.DataOffset, (uint)firstItemOffset - _intro.DataOffset); } p.EndTask(); }
/// <summary> /// Loads header part 4 from a file stream. /// </summary> /// <param name="file">The file stream to load from.</param> /// <param name="offset">The absolute offset into the file where part 4 starts.</param> /// <param name="size">The size of part 4 in bytes.</param> /// <param name="p">Progress info.</param> internal NefsHeaderPt4(FileStream file, UInt32 offset, UInt32 size, NefsProgressInfo p) { _offset = offset; _size = size; /* Validate inputs */ if (size == 0) { log.Warn("Header part 4 has a size of 0."); return; } // The entries for each item in chunk 4 are read when creating the NefsItem // since the offset into part 4 are stored in part 1. // The last four bytes of header 4 is some unknown value. // For now, just copy the data that was already there. last_four_bytes = new UInt32Type((int)size - 0x4); FileData.ReadData(file, offset, this); }
/// <summary> /// Loads header part 6 from a file stream. /// </summary> /// <param name="file">The file stream to load from.</param> /// <param name="offset">The absolute offset into the file where part 6 starts.</param> /// <param name="size">The size of part 6 in bytes.</param> /// <param name="p">Progress info.</param> public NefsHeaderPt6(FileStream file, UInt32 offset, UInt32 size, NefsProgressInfo p) { _offset = offset; _size = size; /* Validate inputs */ if (size == 0) { log.Warn("Header part 6 has a size of 0."); return; } /* Load part 6 entries */ uint entrySize = NefsHeaderPt6Entry.SIZE; uint numEntries = size / entrySize; for (uint i = 0; i < numEntries; i++) { _entries.Add(new NefsHeaderPt6Entry(file, this, (i * 8))); } }
/// <summary> /// Loads header part 2 from a file stream. /// </summary> /// <param name="file">The file stream to load from.</param> /// <param name="offset">The absolute offset into the file where part 2 begins.</param> /// <param name="size">The size of part 2 in bytes.</param> /// <param name="p">Progress info.</param> public NefsHeaderPt2(FileStream file, UInt32 offset, UInt32 size, NefsProgressInfo p) { _offset = offset; _size = size; /* Validate inputs */ if (size == 0) { log.Warn("Header part 2 has a size of 0."); return; } UInt32 next_entry = offset; UInt32 last_entry = offset + size - NefsHeaderPt2Entry.SIZE; while (next_entry <= last_entry) { var entry = new NefsHeaderPt2Entry(file, next_entry); _entries.Add(entry); next_entry += NefsHeaderPt2Entry.SIZE; } }
/// <summary> /// Writes header part 4 to a file stream. /// </summary> /// <param name="file">The file stream to write to.</param> /// <param name="items">The list of NefsItems in this archive.</param> /// <param name="p">Progress info.</param> public void Write(FileStream file, List <NefsItem> items, NefsProgressInfo p) { int numChunkSizes = 0; /* * An item entry in part 4 is a list of compressed chunk sizes. These * sizes are cumulative: * - The first entry is the size of the first chunk. * - The second entry is the size of the second chunk + the first chunk. * - The last entry is the size of all compressed chunks together. */ foreach (var item in items) { file.Seek(item.Archive.Header.Part4.Offset, SeekOrigin.Begin); file.Seek(item.OffsetIntoPt4, SeekOrigin.Current); foreach (var cs in item.ChunkSizes) { file.Write(BitConverter.GetBytes(cs), 0, 4); numChunkSizes++; } } /* Update size */ _size = (uint)numChunkSizes * 4; _size += last_four_bytes.Size; /* Write the unknown section of this header part */ //FileData.WriteData(file, _offset, this); if (items.Count > 0) { file.Seek(items[0].Archive.Header.Part4.Offset, SeekOrigin.Begin); file.Seek(_size - 4, SeekOrigin.Current); file.Write(BitConverter.GetBytes(last_four_bytes.Value), 0, 4); } }
/// <summary> /// Writes the header to a file stream. /// </summary> /// <param name="file">The file stream to write to.</param> /// <param name="p">Progress info.</param> public void Write(FileStream file, NefsProgressInfo p) { /* PART 1 */ p.BeginTask(0.15f, "Writing header part 1..."); { _part1.Write(file, p); Intro.Part1Size = Part1.Size; Part2.Offset = Part1.Offset + Part1.Size; Intro.Part2Offset = Part2.Offset; } p.EndTask(); /* PART 2 */ p.BeginTask(0.15f, "Writing header part 2..."); { _part2.Write(file, p); Intro.Part2Size = Part2.Size; Part3.Offset = Part2.Offset + Part2.Size; Intro.Part3Offset = Part3.Offset; } p.EndTask(); /* PART 3 */ p.BeginTask(0.10f, "Writing header part 3..."); { _part3.Write(file, p); Intro.Part3Size = Part3.Size; Part4.Offset = Part3.Offset + Part3.Size; Intro.Part4Offset = Part4.Offset; } p.EndTask(); /* PART 4 */ p.BeginTask(0.15f, "Writing header part 4..."); { _part4.Write(file, _archive.Items, p); Intro.Part4Size = Part4.Size; Part5.Offset = Part4.Offset + Part4.Size; Intro.Part5Offset = Part5.Offset; Intro.OffsetIntoPart5 = Part5.Offset + 0x10; // Not sure what this offset is for yet } p.EndTask(); /* PART 5 */ p.BeginTask(0.10f, "Writing header part 5..."); { _part5.Write(file, p); Intro.Part5Size = Part5.Size; Part6.Offset = Part5.Offset + Part5.Size; Intro.Part6Offset = Part6.Offset; } p.EndTask(); /* PART 6 */ p.BeginTask(0.10f, "Writing header part 6..."); { _part6.Write(file, p); Intro.Part6Size = Part6.Size; Intro.DataOffset = Part6.Offset + Part6.Size; // Part7.Offset = Part6.Offset + Part6.Size; //Intro.Part7Offset = Part7.Offset; } p.EndTask(); /* PART 7 */ p.BeginTask(0.10f, "Writing header part 7..."); { // _part7.Write(file); //Intro.Part7Size = Part7.Size; } p.EndTask(); /* INTRO - Header intro must be written last */ p.BeginTask(0.15f, "Writing header intro..."); { _intro.Write(file); } p.EndTask(); }