internal StreamWrapper(Stream stream) { _Stream = stream ?? throw new ArgumentNullException(); _Buffer = new byte[0]; Interop = new InteropStream { Read = Read, Write = Write, Seek = Seek }; }
private void Unload() { if (this.currentHandler != null) { this.currentHandler.Unload(); Marshal.FinalReleaseComObject(this.currentHandler); this.currentHandler = null; } if (this.stream != null) { this.stream.Dispose(); this.stream = null; } }
internal static extern int DecompressSlices(InteropStream inputStream, InteropSliceWriter outputStream, ushort index, ushort count);
internal static extern int DecompressVolume(InteropStream inputStream, InteropSliceWriter outputStream);
internal static extern int CompressVolume(InteropSliceReader inputStream, InteropStream outputStream, ushort width, ushort height, [MarshalAs(UnmanagedType.LPStr)] string encoderName, [MarshalAs(UnmanagedType.LPStr)] string pixelFormat, [MarshalAs(UnmanagedType.LPStr)] string options, int bitrate);
public void AttachPreview(IntPtr handler, Rect viewRect, string extension, string filePath, Stream sourceStream) { this.Unload(); var classKey = GetPreviewHandlerKey(extension); if (classKey == null) { return; } var guid = new Guid(classKey.GetValue(string.Empty).ToString()); var type = Type.GetTypeFromCLSID(guid, true); var instance = Activator.CreateInstance(type); var fileInit = instance as IInitializeWithFile; var streamInit = instance as IInitializeWithStream; if (streamInit != null && sourceStream != null) { this.stream = new InteropStream(sourceStream); streamInit.Initialize(this.stream, 0); } else if (fileInit != null) { if (filePath != null) { fileInit.Initialize(filePath, 0); } else if (sourceStream != null) { using (var tempFile = new TempFile()) { using (var fileStream = File.Create(tempFile.Path)) sourceStream.CopyTo(fileStream); fileInit.Initialize(tempFile.Path, 0); } } else { return; } } else { return; } this.currentHandler = instance as IPreviewHandler; if (this.currentHandler == null) { this.Unload(); return; } var rect = new ShellRect(viewRect); this.currentHandler.SetWindow(handler, ref rect); this.currentHandler.SetRect(ref rect); try { this.currentHandler.DoPreview(); } catch { this.Unload(); throw; } }