private void AddNewItem() { NewItem newItem = new NewItem(); this.AddItem(newItem); newItem.NewItemAdd += (sender, e) => { using (FileExtensionDialog dlg = new FileExtensionDialog()) { if (dlg.ShowDialog() != DialogResult.OK) { return; } string extension = dlg.Extension; string typeName = FileExtensionDialog.GetTypeName(extension, false); using (RegistryKey exKey = Registry.ClassesRoot.OpenSubKey(extension, true)) { exKey.SetValue("", typeName); using (RegistryKey snKey = exKey.CreateSubKey("ShellNew", true)) { snKey.SetValue("NullFile", string.Empty); this.InsertItem(new ShellNewItem(snKey.Name), GetItemIndex(newItem) + 1); } } } }; }
private void AddNewItem() { NewItem newItem = new NewItem(); this.AddItem(newItem); newItem.AddNewItem += (sender, e) => { using (FileExtensionDialog dlg = new FileExtensionDialog()) { if (dlg.ShowDialog() != DialogResult.OK) { return; } string extension = dlg.Extension; string openMode = FileExtension.GetOpenMode(extension); if (string.IsNullOrEmpty(openMode)) { MessageBoxEx.Show(AppString.MessageBox.NoOpenModeExtension); return; } foreach (Control ctr in this.Controls) { if (ctr is ShellNewItem item) { if (item.Extension.Equals(extension, StringComparison.OrdinalIgnoreCase)) { MessageBoxEx.Show(AppString.MessageBox.HasBeenAdded); return; } } } using (RegistryKey exKey = Registry.ClassesRoot.OpenSubKey(extension, true)) using (RegistryKey snKey = exKey.CreateSubKey("ShellNew", true)) { string defaultOpenMode = exKey.GetValue("")?.ToString(); if (string.IsNullOrEmpty(defaultOpenMode)) { exKey.SetValue("", openMode); } snKey.SetValue("NullFile", string.Empty); ShellNewItem item = new ShellNewItem(this, snKey.Name); this.AddItem(item); item.Focus(); if (item.ItemText.IsNullOrWhiteSpace()) { item.ItemText = $"{extension.Substring(1)} file"; } if (ShellNewLockItem.IsLocked) { this.SaveSorting(); } } } }; }
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 AddNewItem() { NewItem newItem = new NewItem(); this.AddItem(newItem); newItem.AddNewItem += (sender, e) => { using (FileExtensionDialog dlg = new FileExtensionDialog()) { if (dlg.ShowDialog() != DialogResult.OK) { return; } string extension = dlg.Extension; foreach (Control ctr in this.Controls) { if (ctr.GetType() == typeof(ShellNewItem)) { if (((ShellNewItem)ctr).Extension.Equals(extension, StringComparison.OrdinalIgnoreCase)) { MessageBoxEx.Show(AppString.MessageBox.HasBeenAdded); return; } } } string typeName = FileExtensionDialog.GetTypeName(extension, false); using (RegistryKey exKey = Registry.ClassesRoot.OpenSubKey(extension, true)) { exKey.SetValue("", typeName); using (RegistryKey snKey = exKey.CreateSubKey("ShellNew", true)) { snKey.SetValue("NullFile", string.Empty); this.AddItem(new ShellNewItem(this, snKey.Name)); if (LockNewItem.IsLocked()) { this.WriteRegistry(); } } } } }; }
private void AddNewItem() { NewItem newItem = new NewItem(); this.AddItem(newItem); newItem.AddNewItem += () => { using (FileExtensionDialog dlg = new FileExtensionDialog()) { if (dlg.ShowDialog() != DialogResult.OK) { return; } string extension = dlg.Extension; if (extension == ".") { return; } string openMode = FileExtension.GetOpenMode(extension); if (string.IsNullOrEmpty(openMode)) { if (AppMessageBox.Show(AppString.Message.NoOpenModeExtension, MessageBoxButtons.OKCancel) == DialogResult.OK) { ExternalProgram.ShowOpenWithDialog(extension); } return; } foreach (Control ctr in this.Controls) { if (ctr is ShellNewItem item) { if (item.Extension.Equals(extension, StringComparison.OrdinalIgnoreCase)) { AppMessageBox.Show(AppString.Message.HasBeenAdded); return; } } } using (RegistryKey root = Registry.ClassesRoot) using (RegistryKey exKey = root.OpenSubKey(extension, true)) using (RegistryKey snKey = exKey.CreateSubKey("ShellNew", true)) { string defaultOpenMode = exKey.GetValue("")?.ToString(); if (string.IsNullOrEmpty(defaultOpenMode)) { exKey.SetValue("", openMode); } byte[] bytes = GetWebShellNewData(extension); if (bytes != null) { snKey.SetValue("Data", bytes, RegistryValueKind.Binary); } else { snKey.SetValue("NullFile", "", RegistryValueKind.String); } ShellNewItem item = new ShellNewItem(this, snKey.Name); this.AddItem(item); item.Focus(); if (item.ItemText.IsNullOrWhiteSpace()) { item.ItemText = FileExtension.GetExtentionInfo(FileExtension.AssocStr.FriendlyDocName, extension); } if (ShellNewLockItem.IsLocked) { this.SaveSorting(); } } } }; }