private void LoadCommonItems() { List <string> extensions = new List <string> { "Folder" }; using (RegistryKey root = Registry.ClassesRoot) { extensions.AddRange(Array.FindAll(root.GetSubKeyNames(), keyName => keyName.StartsWith("."))); if (Environment.OSVersion.Version.Major <= 6 && Environment.OSVersion.Version.Minor <= 1) { extensions.Add("Briefcase"); //Win7公文包 } foreach (string extension in extensions) { string typeName = FileExtensionDialog.GetTypeName(extension, false); if (typeName == null) { continue; } using (RegistryKey extKey = root.OpenSubKey(extension)) using (RegistryKey tKey = extKey.OpenSubKey(typeName)) { foreach (string part in ShellNewItem.SnParts) { string snPart = part; if (tKey != null) { snPart = $@"{typeName}\{snPart}"; } using (RegistryKey snKey = extKey.OpenSubKey(snPart)) { if (ValueNames.Any(valueName => snKey?.GetValue(valueName) != null)) { ShellNewItem item = new ShellNewItem(snKey.Name); if (item.ItemText != null) { this.AddItem(item); break; } else { item.Dispose(); } } } } } } } }
private void LoadItems(List <string> extensions) { foreach (string extension in ShellNewItem.UnableSortExtensions) { string str = extensions.Find(ext => ext.Equals(extension, StringComparison.OrdinalIgnoreCase)); if (str != null) { extensions.Remove(str); extensions.Insert(0, str); } } foreach (string extension in extensions) { using (RegistryKey extKey = Registry.ClassesRoot.OpenSubKey(extension)) { string typeName = extKey.GetValue("")?.ToString(); if (typeName == null) { continue; } using (RegistryKey tKey = extKey.OpenSubKey(typeName)) { foreach (string part in ShellNewItem.SnParts) { string snPart = part; if (tKey != null) { snPart = $@"{typeName}\{snPart}"; } using (RegistryKey snKey = extKey.OpenSubKey(snPart)) { if (ValueNames.Any(valueName => snKey?.GetValue(valueName) != null)) { ShellNewItem item = new ShellNewItem(this, snKey.Name); if (item.ItemText != null) { this.AddItem(item); break; } else { item.Dispose(); } } } } } } } }