public ThumbnailPreloader() { iIdIShellItem = new Guid("43826d1e-e718-42ee-bc55-a1e261c37bfe"); Guid CLSIDLocalThumbnailCache = new Guid("50ef4544-ac9f-4a8e-b21b-8a26180db13f"); var TBCacheType = Type.GetTypeFromCLSID(CLSIDLocalThumbnailCache); TBCache = (IThumbnailCache)Activator.CreateInstance(TBCacheType); }
public bool LoadDirectories(IEnumerable <string> paths) { IsLoading = false; MainDispatcher = Dispatcher.CurrentDispatcher; cancellationTokenSource = new CancellationTokenSource(); cancellationToken = cancellationTokenSource.Token; cache = DefaultFactory.GetDefaultThumbnailCache(); userSettings = DefaultFactory.GetDefaultUserSettings(); renderType = (RenderAspectEnum)userSettings.GetSettingInt(UserSettingEnum.Thumbnails3DAspect); logger.Info("Loading paths: Received: [{0}]", string.Join("] [", paths)); paths = paths.Where(p1 => !paths.Any(p2 => !p1.Equals(p2) && p1.Contains(p2))).ToArray(); // Remove selected subdirectories of other selected paths. logger.Info("Loading paths: After removed subdirs: [{0}]", string.Join("] [", paths)); try { IEnumerable <string> pathsFound = new List <string>(); for (int i = 0; i < SupportedExtensionsFilter.Length; i++) { foreach (string path in paths) { pathsFound = pathsFound.Concat(UtilMethods.EnumerateFiles(path, SupportedExtensionsFilter[i], SearchOption.AllDirectories, cancellationToken)); } } pathsFound = pathsFound.ToArray(); if (cancellationToken.IsCancellationRequested) { return(false); } if (pathsFound.Count() > 0) { CalculateThumnailSizes(pathsFound.Count()); InitializeFoundFilesObjects(pathsFound); return(true); } else { FilesFound = new ModelFileData[0]; } } catch (Exception ex) { logger.Trace(ex, "Unable to load: {ex}", ex.Message); } return(false); }
public HResult ExtractAndDrawThumbnail(IntPtr hdc, uint iconSize, out WTS_CACHEFLAGS flags, User32.RECT iconBounds, out bool retrieved, bool isHidden, bool isRefresh = false) { IThumbnailCache thumbCache = null; if (this.ComInterface != null) { var IID_IUnknown = new Guid("00000000-0000-0000-C000-000000000046"); var CLSID_LocalThumbnailCache = new Guid("50EF4544-AC9F-4A8E-B21B-8A26180DB13F"); IntPtr cachePointer; Ole32.CoCreateInstance(ref CLSID_LocalThumbnailCache, IntPtr.Zero, Ole32.CLSCTX.INPROC, ref IID_IUnknown, out cachePointer); thumbCache = (IThumbnailCache)Marshal.GetObjectForIUnknown(cachePointer); } var res = HResult.S_OK; ISharedBitmap bmp = null; flags = WTS_CACHEFLAGS.WTS_DEFAULT; var thumbId = default(WTS_THUMBNAILID); try { retrieved = false; res = thumbCache.GetThumbnail(this._Item.ComInterface, iconSize, isRefresh ? (WTS_FLAGS.WTS_FORCEEXTRACTION | WTS_FLAGS.WTS_SCALETOREQUESTEDSIZE) : (WTS_FLAGS.WTS_INCACHEONLY | WTS_FLAGS.WTS_SCALETOREQUESTEDSIZE), out bmp, flags, thumbId); var hBitmap = IntPtr.Zero; if (bmp != null) { bmp.GetSharedBitmap(out hBitmap); retrieved = true; int width; int height; Gdi32.ConvertPixelByPixel(hBitmap, out width, out height); Gdi32.NativeDraw(hdc, hBitmap, iconBounds.Left + (iconBounds.Right - iconBounds.Left - width) / 2, iconBounds.Top + (iconBounds.Bottom - iconBounds.Top - height) / 2, width, height, isHidden); Gdi32.DeleteObject(hBitmap); } } finally { if (bmp != null) { Marshal.ReleaseComObject(bmp); } } return(res); }
/// <summary> /// Internal constructor that takes in a parent ShellObject. /// </summary> /// <param name="shellObject"></param> internal ShellThumbnail(ShellItem shellObject) { if (shellObject != null && shellObject.ComInterface != null) { _Item = shellObject; shellItemNative = shellObject.ComInterface; if (ThumbnailCache == null) { Guid IID_IUnknown = new Guid("00000000-0000-0000-C000-000000000046"); Guid CLSID_LocalThumbnailCache = new Guid("50EF4544-AC9F-4A8E-B21B-8A26180DB13F"); IntPtr cachePointer; Ole32.CoCreateInstance(ref CLSID_LocalThumbnailCache, IntPtr.Zero, Ole32.CLSCTX.INPROC, ref IID_IUnknown, out cachePointer); ThumbnailCache = (IThumbnailCache)Marshal.GetObjectForIUnknown(cachePointer); } } }
private static ImageData LoadThumbnail(string path, DateTime dtLastWriteTime, out Size sizeRaw, out Size sizeActual, out string toolTipText, out bool fCached) { sizeRaw = sizeActual = Size.Empty; toolTipText = null; fCached = false; IntPtr zero = IntPtr.Zero; IShellItem ppsi = null; ISharedBitmap ppvThumb = null; LocalThumbnailCache o = null; try { zero = PInvoke.ILCreateFromPath(path); if ((zero != IntPtr.Zero) && (PInvoke.SHCreateShellItem(IntPtr.Zero, null, zero, out ppsi) == 0)) { o = new LocalThumbnailCache(); IThumbnailCache cache2 = (IThumbnailCache)o; uint flags = 0; uint pOutFlags = 0; WTS_THUMBNAILID pThumbnailID = new WTS_THUMBNAILID(); uint cxyRequestedThumbSize = (uint)Math.Min(0x400, Math.Min(QTUtility.PreviewMaxWidth, QTUtility.PreviewMaxHeight)); if (cache2.GetThumbnail(ppsi, cxyRequestedThumbSize, flags, out ppvThumb, ref pOutFlags, ref pThumbnailID) == 0) { IntPtr ptr2; if ((pOutFlags & 2) == 2) { fCached = true; } if (ppvThumb.Detach(out ptr2) == 0) { Bitmap bmp = Image.FromHbitmap(ptr2); Size size = bmp.Size; sizeRaw = sizeActual = size; ImageData data = new ImageData(bmp, null, path, dtLastWriteTime, size, size); data.Thumbnail = true; try { toolTipText = data.TooltipText = ShellMethods.GetShellInfoTipText(zero, false); } catch { } return(data); } } } } catch (Exception exception) { QTUtility2.MakeErrorLog(exception, null); } finally { if (zero != IntPtr.Zero) { PInvoke.CoTaskMemFree(zero); } if (ppsi != null) { Marshal.ReleaseComObject(ppsi); } if (ppvThumb != null) { Marshal.ReleaseComObject(ppvThumb); } if (o != null) { Marshal.ReleaseComObject(o); } } return(null); }
/// <summary> /// Internal constructor that takes in a parent ShellObject. /// </summary> /// <param name="shellObject"></param> internal ShellThumbnail(ShellItem shellObject) { if (shellObject != null && shellObject.ComInterface != null) { _Item = shellObject; shellItemNative = shellObject.ComInterface; if (ThumbnailCache == null) { Guid IID_IUnknown = new Guid("00000000-0000-0000-C000-000000000046"); Guid CLSID_LocalThumbnailCache = new Guid("50EF4544-AC9F-4A8E-B21B-8A26180DB13F"); IntPtr cachePointer; Ole32.CoCreateInstance(ref CLSID_LocalThumbnailCache, IntPtr.Zero, Ole32.CLSCTX.INPROC, ref IID_IUnknown, out cachePointer); ThumbnailCache = (IThumbnailCache)Marshal.GetObjectForIUnknown(cachePointer); } } }