protected async Task Initialize() { var headers = new ExeFsHeader[10]; var fileData = new byte[10][]; var hashes = new byte[10][]; await Task.WhenAll(Enumerable.Range(0, 10).Select(async i => { headers[i] = new ExeFsHeader(await ExeFsData.ReadArrayAsync(i * 16, 16).ConfigureAwait(false)); hashes[i] = await ExeFsData.ReadArrayAsync(0xC0 + ((9 - i) * 32), 32).ConfigureAwait(false); // Hashes are stored in reverse order from headers if (headers[i].FileSize > 0) { fileData[i] = await ExeFsData.Slice(headers[i].Offset + 0x200, headers[i].FileSize).ReadArrayAsync().ConfigureAwait(false); } })).ConfigureAwait(false); for (int i = 0; i < headers.Length; i++) { var header = headers[i]; var data = fileData[i]; var hash = hashes[i]; if (header.FileSize > 0) { Files.Add(header.Filename, new ExeFsEntry(data, hash)); } } }
public async Task Initialize() { Headers = new ExeFsHeader[10]; Hashes = new byte[10][]; await Task.WhenAll(Enumerable.Range(0, 10).Select(async i => { Headers[i] = new ExeFsHeader(await ExeFsData.ReadArrayAsync(i * 16, 16)); Hashes[i] = await ExeFsData.ReadArrayAsync(0xC0 + ((9 - i) * 32), 32); // Hashes are stored in reverse order from headers })); }
public IBinaryDataAccessor GetDataReference(string filename) { var file = Headers?.FirstOrDefault(h => string.Compare(h.Filename, filename, false) == 0); if (file == null) { return(null); } return(ExeFsData.GetDataReference(file.Offset, file.FileSize)); }
public async Task Initialize() { var headers = new ExeFsHeader[10]; var hashes = new byte[10][]; await Task.WhenAll(Enumerable.Range(0, 10).Select(async i => { headers[i] = new ExeFsHeader(await ExeFsData.ReadArrayAsync(i * 16, 16).ConfigureAwait(false)); hashes[i] = await ExeFsData.ReadArrayAsync(0xC0 + ((9 - i) * 32), 32).ConfigureAwait(false); // Hashes are stored in reverse order from headers })).ConfigureAwait(false); this.Headers = new List <ExeFsHeader>(10); this.Hashes = new List <byte[]>(10); for (int i = 0; i < headers.Length; i++) { var header = headers[i]; var hash = hashes[i]; if (header.FileSize > 0) { this.Headers.Add(header); this.Hashes.Add(hash); } } }
public async Task ExtractFiles(string directoryName, IFileSystem fileSystem, ExtractionProgressedToken progressReportToken = null) { if (progressReportToken != null) { progressReportToken.TotalFileCount = Headers.Count(h => h != null && !string.IsNullOrEmpty(h.Filename)); } if (!fileSystem.DirectoryExists(directoryName)) { fileSystem.CreateDirectory(directoryName); } var a = new AsyncFor(); await a.RunForEach(Headers, async (header) => { if (string.IsNullOrEmpty(header.Filename)) { return; } fileSystem.WriteAllBytes(Path.Combine(directoryName, header.Filename), await ExeFsData.ReadArrayAsync(0x200 + header.Offset, header.FileSize)); if (progressReportToken != null) { progressReportToken.IncrementExtractedFileCount(); } }); }
public IReadOnlyBinaryDataAccessor GetDataReference(ExeFsHeader header) { return(ExeFsData.GetReadOnlyDataReference(header.Offset + 0x200, header.FileSize)); }