示例#1
0
 internal StreamWrapper(Stream stream)
 {
     _Stream = stream ?? throw new ArgumentNullException();
     _Buffer = new byte[0];
     Interop = new InteropStream
     {
         Read  = Read,
         Write = Write,
         Seek  = Seek
     };
 }
示例#2
0
        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;
            }
        }
示例#3
0
 internal static extern int DecompressSlices(InteropStream inputStream, InteropSliceWriter outputStream, ushort index, ushort count);
示例#4
0
 internal static extern int DecompressVolume(InteropStream inputStream, InteropSliceWriter outputStream);
示例#5
0
 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);
示例#6
0
        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;
            }
        }