/// <summary> /// Builds the system file type cache. /// </summary> /// <returns>The number of system file type entries enumerated.</returns> /// <remarks></remarks> public int Populate(bool fireEvent = true) { _Col.Clear(); _UICol.Clear(); var n = Registry.ClassesRoot.GetSubKeyNames(); SystemFileType sf; int x = 0; int y; var sn2 = new List <string>(); foreach (var sn in n) { if (sn.Substring(0, 1) == ".") { sn2.Add(sn); } } y = sn2.Count; foreach (var sn in sn2) { sf = SystemFileType.FromExtension(sn, this); if (sf is object) { _Col.Add(sf); x += 1; if (fireEvent) { // If fireEvent AndAlso x Mod 10 = 0 Then Populating?.Invoke(this, new FileTypeEnumEventArgs(sf, x, y)); System.Windows.Forms.Application.DoEvents(); } } } var c = _Col.ToArray(); Array.Sort(c, new SysFileTypeComp()); _Col.Clear(); foreach (var cu in c) { _Col.Add(cu); } var d = _UICol.ToArray(); Array.Sort(d, new UIHandlerComp()); _UICol.Clear(); foreach (var du in d) { _UICol.Add(du); } OnPropertyChanged("UICollection"); OnPropertyChanged("FileTypes"); return(x); }
/// <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); } }
/// <summary> /// Create a new event object consisting of these variables. /// </summary> /// <param name="sf">The <see cref="SystemFileType"/> object</param> /// <param name="index">The current index</param> /// <param name="count">The total number of file types</param> internal FileTypeEnumEventArgs(SystemFileType sf, int index, int count) { _sft = sf; _index = index; _count = count; }