/// <summary> /// Initializes a new instance of the <see cref="ToggleViewAction"/> class. /// </summary> /// <param name="caption">Caption</param> /// <param name="beginGroup">Group indicator</param> /// <param name="execute">Execution method (delegate)</param> /// <param name="canExecute">Can-Execute delegate</param> /// <param name="visualResourceKey">Key for XAML resource used for visual representation</param> /// <param name="category">Top level category (ID) assigned to this item</param> /// <param name="categoryCaption">Display text assigned to the top level category</param> /// <param name="categoryOrder">The display order of the category (used for sorting)</param> /// <param name="isDefault">Indicates if this is the default action</param> /// <param name="isCancel">Indicates if this is the action triggered if the user hits ESC</param> /// <param name="significance">General significance of the action.</param> /// <param name="userRoles">User roles with access to this action</param> /// <param name="brushResourceKey">Resource key for a visual derived from a brush.</param> /// <param name="logoBrushResourceKey">Resource key for a visual (used for Logo1) derived from a brush.</param> /// <param name="groupTitle">The group title.</param> /// <param name="order">The order of the view action (within a group)</param> /// <param name="accessKey">The access key for this action (such as the underlined character in a menu if the action is linked to a menu).</param> /// <param name="shortcutKey">The shortcut key for the action (usually a hot key that can be pressed without a menu being opened or anything along those lines).</param> /// <param name="shortcutKeyModifiers">Modifier for the shortcut key (typically CTRL).</param> /// <param name="categoryAccessKey">Access key for the category (only used if a category is assigned).</param> /// <param name="isDefaultSelection">Indicates whether this action shall be selected by default</param> /// <param name="isPinned">Indicates whether this action is considered to be pinned</param> /// <param name="id">Optional unique identifier for the view action (caption is assumed as the ID if no ID is provided)</param> /// <param name="standardIcon">The standard icon to be used as a brush resource.</param> public ToggleViewAction(string caption = "", bool beginGroup = false, Action <IViewAction, object> execute = null, Func <IViewAction, object, bool> canExecute = null, string visualResourceKey = "", string category = "", string categoryCaption = "", int categoryOrder = 0, bool isDefault = false, bool isCancel = false, ViewActionSignificance significance = ViewActionSignificance.Normal, string[] userRoles = null, string brushResourceKey = "", string logoBrushResourceKey = "", string groupTitle = "", int order = 10000, char accessKey = ' ', Key shortcutKey = Key.None, ModifierKeys shortcutKeyModifiers = ModifierKeys.None, char categoryAccessKey = ' ', bool isDefaultSelection = false, bool isPinned = false, string id = "", StandardIcons standardIcon = StandardIcons.None) : base(caption, beginGroup, null, canExecute, visualResourceKey, category, categoryCaption, categoryOrder, isDefault, isCancel, significance, userRoles, brushResourceKey, logoBrushResourceKey, groupTitle, order, accessKey, shortcutKey, shortcutKeyModifiers, categoryAccessKey, isDefaultSelection, isPinned, id, standardIcon) { ViewActionType = ViewActionTypes.Toggle; SetExecutionDelegate((a, o) => { a.IsChecked = !a.IsChecked; execute?.Invoke(a, o); }); }
/// <summary> /// Returns a standard icon string/key from the provided enum value (or string.Empty, if the key is not valid) /// </summary> /// <param name="icon">The icon key.</param> /// <returns>Standard icon resource key name</returns> public static string GetStandardIconKeyFromEnum(StandardIcons icon) { if (StandardIconMaps.ContainsKey(icon)) { return(StandardIconMaps[icon]); } return(string.Empty); }
/// <summary>Initializes a new instance of the <see cref="ApplicationShutdownViewAction"/> class.</summary> /// <param name="caption">The caption.</param> /// <param name="beginGroup">If represented visually, should this action be placed in a new group?</param> /// <param name="category">The category.</param> /// <param name="standardIcon">The standard icon to be used as a brush resource.</param> /// <param name="significance">General significance of the action.</param> public ApplicationShutdownViewAction(string caption = "Shutdown", bool beginGroup = false, string category = "", StandardIcons standardIcon = StandardIcons.None, ViewActionSignificance significance = ViewActionSignificance.Normal) : base(caption, beginGroup, ExecuteCommand, category: category, standardIcon: standardIcon, significance: significance) { BrushResourceKey = "CODE.Framework-Icon-ClosePane"; }
public static ISimpleShellItem CreateRootView(StandardIcons iconSize = StandardIcons.Icon48) { var d = new DirectoryObject(); //d.Add(New DirectoryObject("QuickAccessFolder", True, True)) d.Add(new DirectoryObject("MyComputerFolder", true, true, iconSize)); d.Add(new DirectoryObject("NetworkPlacesFolder", true, false, iconSize)); //d.Add(New DirectoryObject("ControlPanelFolder", True, True)) return(d); }
/// <summary> /// Finds an icon by standard size. /// </summary> /// <param name="StandardIconType"></param> /// <returns></returns> /// <remarks></remarks> public IconImageEntry FindIcon(StandardIcons StandardIconType) { foreach (var e in _entries) { if (e.StandardIconType == StandardIconType) { return(e); } } return(null); }
public IconSnooper() { InitializeComponent(); var flds = typeof(StandardIcons).GetFields(BindingFlags.Public | BindingFlags.Static); foreach (var f in flds) { StandardIcons si = (StandardIcons)f.GetValue(null); var s = si.ToString().Replace("Icon", ""); int d = int.Parse(s); string n; switch (d) { case 16: n = "Small"; break; case 32: n = "Large"; break; case 48: n = "Extra Large"; break; case 64: n = "Extra Extra Large"; break; case 128: n = "Jumbo"; break; case 256: n = "Super Jumbo"; break; default: n = ""; break; } IconSizes.Add(new IconSize($"{d}x{d} {n} Icon", si)); } cbIconSizes.ItemsSource = IconSizes; _Close.Click += _Close_Click; _Quit.Click += _Quit_Click; }
/// <summary> /// Initializes a new instance of the <see cref="ApplicationShutdownViewAction"/> class. /// </summary> /// <param name="model">The model associated with the view.</param> /// <param name="caption">The caption.</param> /// <param name="beginGroup">If represented visually, should this action be placed in a new group?</param> /// <param name="category">The category.</param> /// <param name="standardIcon">The standard icon to be used as a brush resource.</param> /// <param name="significance">General significance of the action.</param> public CloseCurrentViewAction(object model, string caption = "Close", bool beginGroup = false, string category = "", StandardIcons standardIcon = StandardIcons.ClosePane, ViewActionSignificance significance = ViewActionSignificance.Normal) : base(caption, beginGroup, category: category, standardIcon: standardIcon, significance: significance) { _model = model; SetExecutionDelegate(ExecuteCommand); BrushResourceKey = "CODE.Framework-Icon-ClosePane"; IsPinned = true; }
/// <summary> /// Initializes a new instance of the <see cref="ApplicationShutdownViewAction"/> class. /// </summary> /// <param name="model">The model associated with the view.</param> /// <param name="moveToElementName">Name of the element to move the cursor to.</param> /// <param name="caption">The caption.</param> /// <param name="beginGroup">If represented visually, should this action be placed in a new group?</param> /// <param name="category">The category.</param> /// <param name="standardIcon">The standard icon to be used as a brush resource.</param> /// <param name="significance">General significance of the action.</param> public MoveFocusViewAction(IHaveViewInformation model, string moveToElementName, string caption = "", bool beginGroup = false, string category = "", StandardIcons standardIcon = StandardIcons.None, ViewActionSignificance significance = ViewActionSignificance.Normal) : base(caption, beginGroup, category: category, standardIcon: standardIcon, significance: significance) { _model = model; _targetElementName = moveToElementName; BrushResourceKey = "CODE.Framework-Icon-ClosePane"; SetExecutionDelegate(ExecuteCommand); }
/// <summary> /// Initializes a new instance of the <see cref="ApplicationShutdownViewAction" /> class. /// </summary> /// <param name="theme">The theme to switch to.</param> /// <param name="caption">The caption.</param> /// <param name="beginGroup">If represented visually, should this action be placed in a new group?</param> /// <param name="category">The category.</param> /// <param name="categoryAccessKey">The category access key.</param> /// <param name="accessKey">The access key.</param> /// <param name="standardIcon">The standard icon to be used as a brush resource.</param> /// <param name="significance">General significance of the action.</param> public SwitchThemeViewAction(string theme, string caption = "", bool beginGroup = false, string category = "", char categoryAccessKey = ' ', char accessKey = ' ', StandardIcons standardIcon = StandardIcons.None, ViewActionSignificance significance = ViewActionSignificance.Normal) : base(!string.IsNullOrEmpty(caption) ? caption : theme, beginGroup, category: category, standardIcon: standardIcon, significance: significance, categoryAccessKey: categoryAccessKey, accessKey: accessKey) { _theme = theme; BrushResourceKey = "CODE.Framework-Icon-Switch"; SetExecutionDelegate(ExecuteCommand); }
/// <summary> /// Initialize a new raw icon image from a standard image with the specified size as either a bitmap or PNG icon. /// </summary> /// <param name="Image">Image from which to construct the icon.</param> /// <param name="size">The standard size of the new icon.</param> /// <param name="asBmp">Whether to create a bitmap icon (if false, a PNG icon is created).</param> /// <remarks></remarks> public IconImageEntry(Image Image, StandardIcons size, bool asBmp = false) { int sz = (int)size != 0 ? (int)(size) & 0xFF : 256; Bitmap im = (Bitmap)Image; if (Image.Width != sz | Image.Height != sz) { im = new Bitmap(sz, sz, System.Drawing.Imaging.PixelFormat.Format32bppArgb); var g = System.Drawing.Graphics.FromImage(im); g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality; g.DrawImage(Image, new Rectangle(0, 0, sz, sz)); g.Dispose(); } var s = new MemoryStream(); im.Save(s, System.Drawing.Imaging.ImageFormat.Png); _entry.wIconType = size; _entry.wBitsPixel = 32; _entry.wColorPlanes = 1; _image = new byte[(int)(s.Length - 1L) + 1]; _image = s.ToArray(); if (asBmp) { _image = _makeBitmap(); } _entry.dwImageSize = _image.Length; s.Close(); }
/// <summary> /// Constructor /// </summary> /// <param name="caption">Caption</param> /// <param name="controller">Controller name</param> /// <param name="action">Action name (method on the controller)</param> /// <param name="routeValues">Optional route values (parameters) to be passed to the controller</param> /// <param name="standardIcon">The standard icon to be used as a brush resource.</param> /// <param name="category">Top level category (ID) assigned to this item</param> /// <param name="significance">General significance of the action.</param> public OnDemandLoadCustomViewViewAction(string caption, string controller, string action, dynamic routeValues = null, string category = "", StandardIcons standardIcon = StandardIcons.Switch, ViewActionSignificance significance = ViewActionSignificance.Normal) : base(caption, standardIcon: standardIcon, significance: significance, category: category) { Controller = controller; Action = action; RouteValues = routeValues; }
/// <summary> /// Advanced initialization of FileObject. Use this for items in special folders. /// </summary> /// <param name="parsingName">The shell parsing name of the file.</param> /// <param name="isSpecial">Is the file known to be special?</param> /// <param name="initialize">True to get file info and load icons.</param> /// <param name="iconSize">Default icon size. This can be changed with the <see cref="IconSize"/> property.</param> public FileObject(string parsingName, bool isSpecial, bool initialize, StandardIcons iconSize = StandardIcons.Icon48) { this.isSpecial = isSpecial; filename = parsingName; try { var mm = new MemPtr(); var riid = Guid.Parse(ShellIIDGuid.IShellItem); HResult res; if (this.isSpecial) { // let's see if we can parse it. IShellItem shitem = null; IShellItemPS pssh = null; IShellItem2 shitem2 = null; res = NativeShell.SHCreateItemFromParsingName(parsingName, IntPtr.Zero, ref riid, ref shitem); string fp = null; if (res == HResult.Ok) { NativeShell.SHCreateItemFromParsingName(parsingName, IntPtr.Zero, ref riid, ref pssh); psshellObj = pssh; riid = Guid.Parse(ShellIIDGuid.IShellItem2); NativeShell.SHCreateItemFromParsingName(parsingName, IntPtr.Zero, ref riid, ref shitem2); psshellObj2 = shitem2; shitem.GetDisplayName(ShellItemDesignNameOptions.DesktopAbsoluteParsing, out mm.handle); fp = (string)mm; ParsingName = fp; CanonicalName = fp; mm.CoTaskMemFree(); shitem.GetDisplayName(ShellItemDesignNameOptions.Normal, out mm.handle); DisplayName = (string)mm; mm.CoTaskMemFree(); this.isSpecial = true; if (initialize) { Refresh(); } shellObj = shitem; return; } HResult localSHCreateItemFromParsingName() { riid = Guid.Parse(ShellIIDGuid.IShellItem); var ret = NativeShell.SHCreateItemFromParsingName("shell:" + (fp ?? parsingName), IntPtr.Zero, ref riid, ref shitem); return(ret); } res = localSHCreateItemFromParsingName(); if (res == HResult.Ok) { shitem.GetDisplayName(ShellItemDesignNameOptions.DesktopAbsoluteParsing, out mm.handle); CanonicalName = (string)mm; if (ParsingName is null) { ParsingName = (string)mm; } filename = ParsingName; mm.CoTaskMemFree(); shitem.GetDisplayName(ShellItemDesignNameOptions.Normal, out mm.handle); DisplayName = (string)mm; mm.CoTaskMemFree(); } shellObj = shitem; shitem = null; if (!string.IsNullOrEmpty(DisplayName) && !string.IsNullOrEmpty(ParsingName)) { this.isSpecial = true; if (initialize) { Refresh(this.iconSize); } return; } } if (File.Exists(parsingName) == false) { if (!this.isSpecial) { throw new FileNotFoundException("File Not Found: " + parsingName); } } else if (initialize) { Refresh(this.iconSize); } } catch { } }
/// <summary> /// Create a new file-system-linked directory object /// </summary> /// <param name="path"></param> public DirectoryObject(string parsingName, bool isSpecial = false, bool initialize = true, StandardIcons iconSize = StandardIcons.Icon48) { if (string.IsNullOrEmpty(parsingName)) { throw new ArgumentNullException(nameof(Path), "Path is null or not found."); } _IsSpecial = isSpecial; _IconSize = iconSize; // Dim mm As New MemPtr // Dim res As HResult = SHCreateItemFromParsingName(path, Nothing, Guid.Parse(ShellIIDGuid.IShellItem), shitem) // Dim fp As String = Nothing // Dim parts As String() = Nothing // If (res = HResult.Ok) Then // shitem.GetDisplayName(ShellItemDesignNameOptions.DesktopAbsoluteParsing, mm) // fp = mm // ParsingName = fp // mm.CoTaskMemFree() // ElseIf (path.Substring(0, 2) = "::") Then // parts = path.Split("\") // res = SHCreateItemFromParsingName(parts(parts.Length - 1), Nothing, Guid.Parse(ShellIIDGuid.IShellItem), shitem) // If res = HResult.Ok Then // shitem.GetDisplayName(ShellItemDesignNameOptions.DesktopAbsoluteParsing, mm) // fp = mm // ParsingName = fp // mm.CoTaskMemFree() // End If // End If // res = SHCreateItemFromParsingName("shell:" + If(parts IsNot Nothing, parts(parts.Length - 1), If(fp, path)), Nothing, Guid.Parse(ShellIIDGuid.IShellItem), shitem) // If (res = HResult.Ok) Then // Dim ip As IntPtr // res = shitem.GetDisplayName(ShellItemDesignNameOptions.DesktopAbsoluteParsing, ip) // mm = ip // If (res = HResult.Ok) Then // CanonicalName = If(fp Is Nothing, "shell:" + path, mm.ToString()) // If (ParsingName Is Nothing) Then ParsingName = mm // _Path = ParsingName // mm.CoTaskMemFree() // shitem.GetDisplayName(ShellItemDesignNameOptions.Normal, mm) // DisplayName = mm // mm.CoTaskMemFree() // End If // End If // shitem = Nothing if (_IsSpecial) { // let's see if we can parse it. IShellItem shitem = null; var mm = new MemPtr(); var argriid = Guid.Parse(ShellIIDGuid.IShellItem); var res = NativeShell.SHCreateItemFromParsingName(parsingName, IntPtr.Zero, ref argriid, ref shitem); string fp = null; if (res == HResult.Ok) { shitem.GetDisplayName(ShellItemDesignNameOptions.DesktopAbsoluteParsing, out mm.handle); fp = (string)mm; ParsingName = fp; CanonicalName = fp; mm.CoTaskMemFree(); shitem.GetDisplayName(ShellItemDesignNameOptions.Normal, out mm.handle); DisplayName = (string)mm; mm.CoTaskMemFree(); _IsSpecial = true; if (initialize) { Refresh(_IconSize); } else { _Folders.Add(new DirectoryObject()); OnPropertyChanged(nameof(Folders)); } return; } HResult localSHCreateItemFromParsingName() { var argriid = Guid.Parse(ShellIIDGuid.IShellItem); var ret = NativeShell.SHCreateItemFromParsingName("shell:" + (fp ?? parsingName), IntPtr.Zero, ref argriid, ref shitem); return(ret); } res = localSHCreateItemFromParsingName(); if (res == HResult.Ok) { shitem.GetDisplayName(ShellItemDesignNameOptions.DesktopAbsoluteParsing, out mm.handle); CanonicalName = (string)mm; if (ParsingName is null) { ParsingName = (string)mm; } _Path = ParsingName; mm.CoTaskMemFree(); shitem.GetDisplayName(ShellItemDesignNameOptions.Normal, out mm.handle); DisplayName = (string)mm; mm.CoTaskMemFree(); } shitem = null; if (!string.IsNullOrEmpty(DisplayName) && !string.IsNullOrEmpty(parsingName)) { _IsSpecial = true; if (initialize) { Refresh(_IconSize); } else { _Folders.Add(new DirectoryObject()); OnPropertyChanged(nameof(Folders)); } return; } } if (!string.IsNullOrEmpty(ParsingName)) { _Path = ParsingName; } else { _Path = parsingName; ParsingName = parsingName; } if (System.IO.Directory.Exists(_Path) == false) { return; } // Throw New DirectoryNotFoundException("Directory Not Found: " & _Path) else { DisplayName = Path.GetFileName(_Path); CanonicalName = _Path; parsingName = _Path; } if (initialize) { Refresh(_IconSize); } else { _Folders.Add(new DirectoryObject()); OnPropertyChanged(nameof(Folders)); } }
public IconSize(string name, StandardIcons value) { Name = name; Value = value; }
/// <summary>Loads a resource brush to be shared across all instances of this view model and assigns it to Logo2</summary> /// <param name="standardIcon">Standard icon to be used as the brush.</param> /// <param name="sharingContextCollection">Sharing context collection (can be used to differentiate brush context between different subclasses of standard view models).</param> public void LoadSharedLogo2FromBrushResource(StandardIcons standardIcon, Dictionary <string, Brush> sharingContextCollection = null) => LoadSharedLogo2FromBrushResource(StandardIconHelper.GetStandardIconKeyFromEnum(standardIcon), sharingContextCollection);
/// <summary> /// Assigns a standard icon as a brush /// </summary> /// <param name="icon">The icon.</param> public virtual void AssignLogo2Icon(StandardIcons icon) { Logo2 = GetBrushFromResource(StandardIconHelper.GetStandardIconKeyFromEnum(icon)); }
/// <summary> /// Assigns a standard icon as a brush /// </summary> /// <param name="icon">The icon.</param> public virtual void AssignImage5Icon(StandardIcons icon) { Image5 = GetBrushFromResource(StandardIconHelper.GetStandardIconKeyFromEnum(icon)); }
/// <summary> /// Refresh the contents of the directory. /// </summary> public void Refresh(StandardIcons?iconSize = default) { if (iconSize is null) { iconSize = _IconSize; } _Children.Clear(); _Folders.Clear(); FileObject fobj; DirectoryObject dobj; IShellItem shitem = null; IShellFolder shfld; IEnumIDList enumer; MemPtr mm; var mm2 = new MemPtr(); string fp; string pname = ParsingName; if (pname is object && pname.LastIndexOf(@"\") == pname.Length - 1) { pname = pname.Substring(0, pname.Length - 1); } var argriid = Guid.Parse(ShellIIDGuid.IShellItem); var res = NativeShell.SHCreateItemFromParsingName(ParsingName, IntPtr.Zero, ref argriid, ref shitem); _IconSize = (StandardIcons)iconSize; int?argiIndex = null; _Icon = Resources.GetFileIcon(ParsingName, FileObject.StandardToSystem(_IconSize), iIndex: ref argiIndex); _IconImage = Resources.GetFileIconWPF(ParsingName, FileObject.StandardToSystem(_IconSize)); if (res == HResult.Ok) { var argbhid = Guid.Parse(ShellBHIDGuid.ShellFolderObject); var argriid1 = Guid.Parse(ShellIIDGuid.IShellFolder2); shitem.BindToHandler(IntPtr.Zero, ref argbhid, ref argriid1, out shfld); _SysInterface = shfld; shfld.EnumObjects(IntPtr.Zero, ShellFolderEnumerationOptions.Folders | ShellFolderEnumerationOptions.IncludeHidden | ShellFolderEnumerationOptions.NonFolders | ShellFolderEnumerationOptions.InitializeOnFirstNext, out enumer); if (enumer != null) { var glist = new List <string>(); uint cf; var x = IntPtr.Zero; string pout; // mm.AllocCoTaskMem((MAX_PATH * 2) + 8) mm2.Alloc(NativeShell.MAX_PATH * 2 + 8); do { cf = 0U; mm2.ZeroMemory(0L, NativeShell.MAX_PATH * 2 + 8); res = enumer.Next(1U, out x, out cf); mm = x; if (cf == 0L) { break; } if (res != HResult.Ok) { break; } mm2.IntAt(0L) = 2; // shfld.GetAttributesOf(1, mm, attr) shfld.GetDisplayNameOf(mm, (uint)ShellItemDesignNameOptions.ParentRelativeParsing, mm2.handle); MemPtr inv; if (IntPtr.Size == 4) { inv = (IntPtr)mm2.IntAt(1L); } else { inv = (IntPtr)mm2.LongAt(1L); } if (inv.Handle != IntPtr.Zero) { if (inv.CharAt(0L) != '\0') { fp = (string)inv; var lpInfo = new SHFILEINFO(); // Dim sgfin As ShellFileGetAttributesOptions = 0, // sgfout As ShellFileGetAttributesOptions = 0 int iFlags = User32.SHGFI_PIDL | User32.SHGFI_ATTRIBUTES; lpInfo.dwAttributes = 0; x = User32.SHGetItemInfo(mm.Handle, 0, ref lpInfo, Marshal.SizeOf(lpInfo), iFlags); if (ParsingName is object) { if (pname.LastIndexOf(@"\") == pname.Length - 1) { pname = pname.Substring(0, pname.Length - 1); } pout = $@"{pname}\{fp}"; } else { pout = fp; } if (lpInfo.dwAttributes == 0) { lpInfo.dwAttributes = (int)FileTools.GetFileAttributes(pout); } FileAttributes drat = (FileAttributes)(int)(lpInfo.dwAttributes); if ((lpInfo.dwAttributes & (int)FileAttributes.Directory) == (int)FileAttributes.Directory && !File.Exists(pout)) { dobj = new DirectoryObject(pout, _IsSpecial, false); dobj.Parent = this; dobj.IconSize = _IconSize; _Children.Add(dobj); _Folders.Add(dobj); } else { fobj = new FileObject(pout, _IsSpecial, true, _IconSize); fobj.Parent = this; fobj.IconSize = _IconSize; _Children.Add(fobj); } } inv.CoTaskMemFree(); } mm.CoTaskMemFree(); }while (res == HResult.Ok); mm2.Free(); } } OnPropertyChanged(nameof(Folders)); OnPropertyChanged(nameof(Icon)); OnPropertyChanged(nameof(IconImage)); OnPropertyChanged(nameof(IconSize)); OnPropertyChanged(nameof(ParsingName)); OnPropertyChanged(nameof(DisplayName)); }
/// <summary> /// Creates a new <see cref="System.Windows.Media.Imaging.BitmapSource"/> object from the given extension with the specified parameters. /// </summary> /// <param name="ext">The file extension.</param> /// <param name="size">The default icon size.</param> /// <returns></returns> public static System.Windows.Media.Imaging.BitmapSource ImageFromExtension(string ext, StandardIcons size = StandardIcons.Icon48) { var sft = FromExtension(ext, size: size); if (sft is null) { return(null); } return(sft.DefaultImage); }
/// <summary> /// Creates a new <see cref="SystemFileType"/> object from the given extension with the specified parameters. /// </summary> /// <param name="ext">The file extension.</param> /// <param name="parent">The parent <see cref="AllSystemFileTypes"/> object.</param> /// <param name="size">The default icon size.</param> /// <returns></returns> public static SystemFileType FromExtension(string ext, AllSystemFileTypes parent = null, StandardIcons size = StandardIcons.Icon48) { var c = new SystemFileType(ext); if (parent is object) { c.Parent = parent; } var assoc = NativeShell.EnumFileHandlers(ext); if (assoc is null || assoc.Count() == 0) { return(null); } c.Populate(assoc, size); if (c.Handlers.Count == 0) { return(null); } else { return(c); } }
internal bool Populate(IAssocHandler[] assoc = null, StandardIcons size = StandardIcons.Icon48) { if (assoc is null) { assoc = NativeShell.EnumFileHandlers(_Ext); } if (assoc is null) { return(false); } _Col.Clear(); string p = null; if (_Parent is null) { foreach (var a in assoc) { p = null; a.GetName(out p); if (File.Exists(p) == false) { continue; } _Col.Add(new UIHandler(a, _Parent)); } } else { foreach (var a in assoc) { p = null; a.GetName(out p); if (File.Exists(p) == false) { continue; } _Col.Add(_Parent.HandlerFromAssocHandler(a, _Ext)); } } OnPropertyChanged("Handlers"); try { var pk = Registry.ClassesRoot.OpenSubKey(_Ext); RegistryKey pk2; if (pk is object && (string)(pk.GetValue(null)) is object) { pk2 = Registry.ClassesRoot.OpenSubKey((string)(pk.GetValue(null))); if (pk2 is object) { string d = (string)(pk2.GetValue(null)); if (string.Equals(d, _Desc) == false) { _Desc = (string)(pk2.GetValue(null)); OnPropertyChanged("Description"); } pk2.Close(); pk2 = Registry.ClassesRoot.OpenSubKey((string)(pk.GetValue(null)) + @"\DefaultIcon"); pk.Close(); if (pk2 is object) { d = (string)(pk2.GetValue(null)); pk2.Close(); if (d is object) { int i = d.LastIndexOf(","); int c; if (i == -1) { c = 0; } else { c = int.Parse(d.Substring(i + 1)); d = d.Substring(0, i); } _DefaultIcon = Resources.LoadLibraryIcon(d, c, size); if (_DefaultIcon is object) { _DefaultImage = Resources.MakeWPFImage(_DefaultIcon); OnPropertyChanged("DefaultImage"); OnPropertyChanged("DefaultIcon"); } } } } } if (_Desc is null || string.IsNullOrEmpty(_Desc)) { _Desc = _Ext + " file"; } } catch { } var cn = _Col.ToArray(); _Col.Clear(); Array.Sort(cn, new UIHandlerComp()); foreach (var cxn in cn) { _Col.Add(cxn); } return(true); }