public static IModelIconExtractor <IEntryModel> Create(Func <IEntryModel, string> fnameFunc = null) { fnameFunc = fnameFunc == null ? e => e.Label : fnameFunc; Func <IEntryModel, string> keyFunc = (m) => { if (m.IsDirectory) { return("GetFromSystemImageListUsingExtension - Directory"); } else { string fname = fnameFunc(m); string extension = m.Profile.Path.GetExtension(fname).ToLower(); if (String.IsNullOrEmpty(extension)) { //Without extension. return("GetFromSystemImageListUsingExtension - File"); } else { return("GetFromSystemImageListUsingExtension - " + extension); } } }; Func <IEntryModel, byte[]> getIconFunc = em => { if (em.IsDirectory) { return(ResourceUtils.GetResourceAsByteArray(dummy, "/Themes/Resources/FolderIcon.png")); } if (em != null) { string fname = fnameFunc(em); using (Bitmap bitmap = _iconExtractor.GetBitmap(IconSize.large, fname, em.IsDirectory, false)) if (bitmap != null) { return(bitmap.ToByteArray()); } } return(null); }; return(ModelIconExtractor <IEntryModel> .FromFuncCachable( keyFunc, (em) => getIconFunc(em) )); }
public static IModelIconExtractor <IEntryModel> Create() { Func <IEntryModel, string> keyFunc = (m) => { if (m.IsDirectory) { //if (model.FullPath.StartsWith("::")) return("GetFromSystemImageList - " + m.FullPath); } //else return "GetFromSystemImageList - Directory"; else { string extension = m.GetExtension().ToLower(); if (String.IsNullOrEmpty(extension)) { //Without extension. if (m.FullPath.StartsWith("::")) { return("GetFromSystemImageList - " + m.FullPath); } else { return("GetFromSystemImageList - File"); } } else { if (excludedExtensions.Contains(extension)) { return("GetFromSystemImageList - " + m.FullPath); } return("GetFromSystemImageList - " + extension); } } }; Func <IEntryModel, byte[]> getIconFunc = em => { if (em != null && !String.IsNullOrEmpty(em.FullPath)) { using (FileSystemInfoEx fsi = FileSystemInfoEx.FromString(em.FullPath)) { Bitmap bitmap = null; if (fsi != null && fsi.Exists) { return(fsi.RequestPIDL(pidl => { if (pidl != null) { bitmap = _iconExtractor.GetBitmap(QuickZip.Converters.IconSize.extraLarge, pidl.Ptr, em.IsDirectory, false); if (bitmap != null) { return bitmap.ToByteArray(); } } return new byte[] {}; })); } } } return(null); }; return(ModelIconExtractor <IEntryModel> .FromFuncCachable( keyFunc, (em) => getIconFunc(em) )); }