public override void DoEncoded(IStreamEncoder encoder, Action action) { // Encode the data into a stream Stream encoded = null; using (MemoryStream memStream = new MemoryStream()) { // Stream key string key = CurrentPointer.ToString() + "_decoded"; // Add the stream StreamFile sf = new StreamFile(key, memStream, Context) { Endianness = currentFile.Endianness }; Context.AddFile(sf); DoAt(sf.StartPointer, () => { action(); memStream.Position = 0; encoded = encoder.EncodeStream(memStream); }); Context.RemoveFile(sf); } // Turn stream into array & write bytes if (encoded != null) { using (MemoryStream ms = new MemoryStream()) { encoded.CopyTo(ms); writer.Write(ms.ToArray()); } encoded.Close(); } }
/// <summary> /// Processes a file /// </summary> /// <param name="inputFiles">The input files to process</param> /// <param name="outputDir">The output directory</param> /// <param name="shouldDecode">True if the files should be decoded, or false to encode them</param> private void ProcessFile(IEnumerable <FileSystemPath> inputFiles, FileSystemPath outputDir, bool shouldDecode) { if (IsLoading) { return; } try { IsLoading = true; // Get the encoder IStreamEncoder encoder = SelectedType.Encoder; // Process every file foreach (FileSystemPath file in inputFiles) { // Open the input file using FileStream inputStream = File.OpenRead(file); // Open and create the destination file using FileStream outputStream = File.OpenWrite((outputDir + file.Name).GetNonExistingFileName()); // Process the file data if (shouldDecode) { encoder.DecodeStream(inputStream, outputStream); } else { encoder.EncodeStream(inputStream, outputStream); } } } finally { IsLoading = false; } }