internal static void Main() { // Logging LogHelper.LoggerFactory = new LoggerFactory(); var logConfig = new LoggerConfiguration() .WriteTo.Console() .CreateLogger(); LogHelper.LoggerFactory.AddSerilog(logConfig); NefsLog.LoggerFactory = LogHelper.LoggerFactory; // Setup workspace and services var fileSystem = new FileSystem(); var uiService = new UiService(Dispatcher.CurrentDispatcher, fileSystem); var settingsService = new SettingsService(fileSystem, uiService); var progressService = new ProgressService(uiService); var nefsTransformer = new NefsTransformer(fileSystem); var nefsReader = new NefsReader(fileSystem); var nefsWriter = new NefsWriter(TempDirectory, fileSystem, nefsTransformer); var workspace = new NefsEditWorkspace( fileSystem, progressService, uiService, settingsService, nefsReader, nefsWriter, nefsTransformer); // Run application Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new EditorForm(workspace, uiService, settingsService)); }
public async Task DetransformAsync_ExtractedSizeSmallerThanTransformed_DataExtracted() { // There are situations in version 1.6 headers where the extracted size is smaller than // the compressed size, resulting in extra garbage data/padding at the end of an // extracted file. Need to make sure this extra garbage data is ignored. const string Data = "Hello there!"; var dataBytes = Encoding.ASCII.GetBytes(Data); var aesStr = "542E5211BD8A3AE494554DA4A18884B1C546258BCCA4B76D055D52602819525A"; var aes = StringHelper.FromHexString(aesStr); var chunkSize = 0x10000U; var transform = new NefsDataTransform(chunkSize, false, aes); var transformer = new NefsTransformer(this.fileSystem); using (var inputStream = new MemoryStream()) using (var transformedStream = new MemoryStream()) using (var outputStream = new MemoryStream()) { // Copy data to input stream inputStream.Write(dataBytes, 0, dataBytes.Length); // Add some garbage data to end of stream await transformedStream.WriteAsync(Encoding.ASCII.GetBytes("HAHAHAHAHA"), 0, 10); // Transform await transformer.TransformAsync(inputStream, 0, (uint)dataBytes.Length, transformedStream, 0, transform, new NefsProgress()); transformedStream.Seek(0, SeekOrigin.Begin); // Setup chunk info var extractedSize = Data.Length; var transformedSize = transformedStream.Length; var chunk = new NefsDataChunk((uint)transformedSize, (uint)transformedSize, transform); var chunks = new List <NefsDataChunk> { chunk }; // Extract await transformer.DetransformAsync(transformedStream, 0, outputStream, 0, (uint)extractedSize, chunks, new NefsProgress()); outputStream.Seek(0, SeekOrigin.Begin); var outputBytes = new byte[Data.Length]; await outputStream.ReadAsync(outputBytes, 0, (int)outputStream.Length); var outputStr = Encoding.ASCII.GetString(outputBytes); // Verify Assert.Equal(extractedSize, outputStream.Length); Assert.Equal(Data, outputStr); } }
public async Task DetransformFileAsync_NotEncrypted_DataDecompressed() { const string Data = @"Hello. This is the input data. It is not encrypted. Hello. This is the input data. It is not encrypted. Hello. This is the input data. It is not encrypted. Hello. This is the input data. It is not encrypted. Hello. This is the input data. It is not encrypted. Hello. This is the input data. It is not encrypted. Hello. This is the input data. It is not encrypted. Hello. This is the input data. It is not encrypted. Hello. This is the input data. It is not encrypted. Hello. This is the input data. It is not encrypted. Hello. This is the input data. It is not encrypted. Hello. This is the input data. It is not encrypted. Hello. This is the input data. It is not encrypted. Hello. This is the input data. It is not encrypted. Hello. This is the input data. It is not encrypted. Hello. This is the input data. It is not encrypted. Hello. This is the input data. It is not encrypted. Hello. This is the input data. It is not encrypted. Hello. This is the input data. It is not encrypted. Hello. This is the input data. It is not encrypted. Hello. This is the input data. It is not encrypted. Hello. This is the input data. It is not encrypted."; var sourceFilePath = @"C:\source.txt"; var compressedFilePath = @"C:\compressed.dat"; var destFilePath = @"C:\dest.txt"; var chunkSize = 0x10000U; var transform = new NefsDataTransform(chunkSize, true); this.fileSystem.AddFile(sourceFilePath, new MockFileData(Data)); // Compress the source data var transformer = new NefsTransformer(this.fileSystem); var size = await transformer.TransformFileAsync(sourceFilePath, compressedFilePath, transform, new NefsProgress()); // Decompress the data await transformer.DetransformFileAsync(compressedFilePath, 0, destFilePath, 0, (uint)Data.Length, size.Chunks, new NefsProgress()); // Verify var decompressedText = this.fileSystem.File.ReadAllText(destFilePath); Assert.Equal(Data, decompressedText); }
public async Task TransformAsync_VariousData_DataCompressed(CompressAsyncTestData test) { var input = Encoding.ASCII.GetBytes(InputDataString); using (var inputStream = new MemoryStream(input)) using (var outputStream = new MemoryStream()) { var transformer = new NefsTransformer(this.fileSystem); var transform = new NefsDataTransform(test.ChunkSize, true); var size = await transformer.TransformAsync(inputStream, test.Offset, test.Length, outputStream, 0, transform, new NefsProgress()); // Read data from output stream var resultData = new byte[outputStream.Length]; outputStream.Seek(0, SeekOrigin.Begin); await outputStream.ReadAsync(resultData, 0, (int)outputStream.Length); // Verify Assert.Equal(test.Length, size.ExtractedSize); Assert.Equal(test.ExpectedChunks.Count, size.Chunks.Count); Assert.True(test.ExpectedChunks.SequenceEqual(size.Chunks.Select(c => c.CumulativeSize))); Assert.Equal(test.ExpectedData.Length, resultData.Length); Assert.True(test.ExpectedData.SequenceEqual(resultData)); } }