/// <summary> /// Creates an item for testing. /// </summary> /// <param name="id">The item id.</param> /// <param name="dirId">The directory id.</param> /// <param name="fileName">The item name.</param> /// <param name="dataOffset">Data offset.</param> /// <param name="extractedSize">Extracted size.</param> /// <param name="chunkSizes">Compressed chunks sizes.</param> /// <param name="type">The item type.</param> /// <returns>The new item.</returns> internal static NefsItem CreateItem( uint id, uint dirId, string fileName, UInt64 dataOffset, UInt32 extractedSize, IReadOnlyList <UInt32> chunkSizes, NefsItemType type) { var attributes = new NefsItemAttributes( isDirectory: type == NefsItemType.Directory, v16IsTransformed: true); var transform = TestTransform; var chunks = NefsDataChunk.CreateChunkList(chunkSizes, transform); var size = new NefsItemSize(extractedSize, chunks); var dataSource = new NefsFileDataSource(@"C:\source.txt", dataOffset, size, extractedSize != chunkSizes.LastOrDefault()); return(new NefsItem( Guid.NewGuid(), new NefsItemId(id), fileName, new NefsItemId(dirId), dataSource, transform, attributes)); }
/// <summary> /// Initializes a new instance of the <see cref="NefsFileDataSource"/> class. /// </summary> /// <param name="filePath">The path of the file that contain's the data.</param> /// <param name="offset">The offset in the source file where the data begins.</param> /// <param name="size">Size information about the item's data.</param> /// <param name="shouldCompress"> /// A value indicating whether to compress the data when putting into the archive. /// </param> public NefsFileDataSource(string filePath, UInt64 offset, NefsItemSize size, bool shouldCompress) { this.FilePath = filePath ?? throw new ArgumentNullException(nameof(filePath)); this.Offset = offset; this.Size = size; this.ShouldCompress = shouldCompress; }
/// <inheritdoc/> public bool ReplaceItemByDialog(NefsItem item) { if (item == null) { Log.LogError($"Cannot replace item. Item is null."); return(false); } // Have user pick file (var result, var fileName) = this.UiService.ShowOpenFileDialog(); if (result != DialogResult.OK) { return(false); } // Check file exists if (!this.FileSystem.File.Exists(fileName)) { Log.LogError($"Cannot replace item. Replacement file does not exist: {fileName}."); return(false); } var fileSize = this.FileSystem.FileInfo.FromFileName(fileName).Length; var itemSize = new NefsItemSize((uint)fileSize); var newDataSource = new NefsFileDataSource(fileName, 0, itemSize, false); var cmd = new ReplaceFileCommand(item, item.DataSource, item.State, newDataSource); this.UndoBuffer.Execute(cmd); return(true); }
/// <summary> /// Initializes a new instance of the <see cref="NefsFileDataSource"/> class. /// </summary> /// <param name="filePath">The path of the file that contain's the data.</param> /// <param name="offset">The offset in the source file where the data begins.</param> /// <param name="size">Size information about the item's data.</param> /// <param name="isTransformed"> /// Whether the data in this data source has already been transformed (encrypted, /// compressed, etc). /// </param> public NefsFileDataSource(string filePath, UInt64 offset, NefsItemSize size, bool isTransformed) { this.FilePath = filePath ?? throw new ArgumentNullException(nameof(filePath)); this.Offset = offset; this.Size = size; this.IsTransformed = isTransformed; }
/// <summary> /// Initializes a new instance of the <see cref="NefsItemListDataSource"/> class. /// </summary> /// <param name="items"> /// The items list that specifies the file the item's data is stored in. /// </param> /// <param name="offset">The offset in the source file where the data begins.</param> /// <param name="size">The size of the item's data in bytes.</param> public NefsItemListDataSource( NefsItemList items, UInt64 offset, NefsItemSize size) { this.Items = items ?? throw new ArgumentNullException(nameof(items)); this.Offset = offset; this.Size = size; }
/// <inheritdoc/> public NefsItem CreateItemInfo(Guid guid, NefsItemList dataSourceList) { var p1 = this.Part1.EntriesByGuid[guid]; var p2 = this.Part2.EntriesByIndex[(int)p1.IndexPart2]; var p6 = this.Part6.EntriesByGuid[guid]; var id = p1.Id; // Gather attributes var attributes = p6.CreateAttributes(); // Find parent var parentId = this.GetItemDirectoryId(p1.IndexPart2); // Offset and size var dataOffset = p1.Data0x00_OffsetToData.Value; var extractedSize = p2.Data0x0c_ExtractedSize.Value; // Transform var transform = new NefsDataTransform(this.TableOfContents.BlockSize, true, this.Intro.IsEncrypted ? this.Intro.GetAesKey() : null); // Data source INefsDataSource dataSource; if (attributes.IsDirectory) { // Item is a directory dataSource = new NefsEmptyDataSource(); transform = null; } else if (p1.IndexPart4 == 0xFFFFFFFFU) { // Item is not compressed var size = new NefsItemSize(extractedSize); dataSource = new NefsItemListDataSource(dataSourceList, dataOffset, size); } else { // Item is compressed var numChunks = this.TableOfContents.ComputeNumChunks(p2.ExtractedSize); var chunkSize = this.TableOfContents.BlockSize; var chunks = this.Part4.CreateChunksList(p1.IndexPart4, numChunks, chunkSize, this.Intro.GetAesKey()); var size = new NefsItemSize(extractedSize, chunks); dataSource = new NefsItemListDataSource(dataSourceList, dataOffset, size); } // File name and path var fileName = this.GetItemFileName(p1.IndexPart2); // Create item return(new NefsItem(p1.Guid, id, fileName, parentId, dataSource, transform, attributes)); }
/// <summary> /// Creates an item for testing. /// </summary> /// <param name="id">The item id.</param> /// <param name="dirId">The directory id.</param> /// <param name="fileName">The item name.</param> /// <param name="dataOffset">Data offset.</param> /// <param name="extractedSize">Extracted size.</param> /// <param name="chunkSizes">Compressed chunks sizes.</param> /// <param name="type">The item type.</param> /// <returns>The new item.</returns> internal static NefsItem CreateItem( uint id, uint dirId, string fileName, UInt64 dataOffset, UInt32 extractedSize, IReadOnlyList <UInt32> chunkSizes, NefsItemType type) { var size = new NefsItemSize(extractedSize, chunkSizes); var dataSource = new NefsFileDataSource(@"C:\source.txt", dataOffset, size, extractedSize != chunkSizes.LastOrDefault()); return(new NefsItem( new NefsItemId(id), fileName, new NefsItemId(dirId), type, dataSource, CreateUnknownData())); }