Ejemplo n.º 1
0
 internal void Delete(ListBox lstBoxSendTo, Message message)
 {
     if (lstBoxSendTo.SelectedItems.Count == 0) {
         message.Error(_window.FindResource("SelectedOnItem") as string);
         return;
     }
     FileItem[] sendToListItems = new FileItem[lstBoxSendTo.SelectedItems.Count];
     lstBoxSendTo.SelectedItems.CopyTo(sendToListItems, 0);
     string msg = sendToListItems.Length == 1
         ? _window.FindResource("SureToDelete") + " \"" + sendToListItems[0].Name + "\" " + _window.FindResource("FromSendToMenu")
         : _window.FindResource("SureToDeleteMultiple") + " " + sendToListItems.Length + " " + _window.FindResource("FromSendToMenuMultiple");
     InfoBox infoBox = new InfoBox(msg, _window.FindResource("Delete").ToString(),
         _window.FindResource("WarningMsgTitle").ToString(), InfoBox.DialogType.Question);
     if (infoBox.ShowDialog() != true) return;
     List<string> failedFiles = new List<string>();
     foreach (FileItem sendToFileItem in sendToListItems) {
         string filePath = sendToFileItem.FullName;
         try {
             if (Path.GetExtension(filePath).Equals(".lnk", StringComparison.InvariantCultureIgnoreCase) ||
                 Path.GetExtension(filePath).Equals(".pif", StringComparison.InvariantCultureIgnoreCase)) {
                 if (!System.IO.File.Exists(filePath)) {
                     failedFiles.Add(sendToFileItem.Name);
                     continue;
                 }
             }
             else {
                 failedFiles.Add(sendToFileItem.Name);
                 continue;
             }
             System.IO.File.Delete(filePath);
         }
         catch (IOException) {
             failedFiles.Add(sendToFileItem.Name);
         }
         catch (NullReferenceException) {
             failedFiles.Add(sendToFileItem.Name);
         }
     }
     if (!failedFiles.Any()) return;
     string failedMsg = failedFiles.Count > 1
         ? _window.FindResource("FailedToDelete") + " " + failedFiles.SentenceJoin() +
           " " + _window.FindResource("AreNotShortcutsMultiple")
         : _window.FindResource("FailedToDelete") + " " + failedFiles.SentenceJoin() +
           " " + _window.FindResource("AreNotShortcuts");
     message.Error(failedMsg);
 }
        internal static ObservableCollection<FileItem> All()
        {
            ObservableCollection<FileItem> rightClickListItems = new ObservableCollection<FileItem>();
            using (RegistryKey hkcrDirShell = Registry.ClassesRoot.OpenSubKey(@"Directory\Background\Shell")) {
                if (hkcrDirShell == null)
                   return null;
                foreach (string subKeyName in hkcrDirShell.GetSubKeyNames()) {
                    if (subKeyName.Equals("cmd", StringComparison.InvariantCultureIgnoreCase))
                        continue;

                    RegistryKey regKey = hkcrDirShell.OpenSubKey(subKeyName + @"\command");
                    if (regKey == null) continue;
                    string val = regKey.GetValue("") as string;
                    if (String.IsNullOrEmpty(val)) continue;

                    if (val.ToLower().Contains(Constants.InternetExplorer)) {
                        val = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles),
                            @"Internet Explorer\" + Constants.InternetExplorer);
                    } else if (val.Contains(" ")) {
                        string[] valSplit = val.Split(' ');
                        if (valSplit.Length == 2) {
                            val = valSplit[0];
                        }
                    }
                    if (!File.Exists(val))
                        continue;
                    System.Drawing.Icon icon = System.Drawing.Icon.ExtractAssociatedIcon(val);
                    ImageSource imgSource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHIcon(
                        icon.Handle, new Int32Rect(0, 0, icon.Width, icon.Height), BitmapSizeOptions.FromEmptyOptions());
                    FileItem fileItem = new FileItem(val, imgSource, subKeyName);
                    fileItem.Name = subKeyName;
                    rightClickListItems.Add(fileItem);
                }
            }
            return rightClickListItems;
        }
 public static void Toggle(FileItem fileItem, bool newState)
 {
     using (RegistryKey hkcrApplications = Registry.ClassesRoot.CreateSubKey("Applications"))
     {
         string fileName = System.IO.Path.GetFileName(fileItem.FullName);
         if (fileName == null) return;
         RegistryKey regKey = hkcrApplications.OpenSubKey(fileName, true);
         if (regKey == null) return;
         if (newState) {
             regKey.DeleteValue(Constants.NoOpenWith);
         }
         else {
             regKey.SetValue(Constants.NoOpenWith, "");
         }
     }
 }
 public static void Toggle(FileItem fileItem, bool newState)
 {
     RegistryKey hkcrRun = Registry.CurrentUser.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run");
     RegistryKey hkcrRunDisabled =
         Registry.CurrentUser.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run-");
     bool isSuccess = newState ? hkcrRunDisabled.Move(hkcrRun, fileItem.Name)
         : hkcrRun.Move(hkcrRunDisabled, fileItem.Name);
     if (!isSuccess) {
         RegistryKey hklmRun =
             Registry.LocalMachine.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run");
         RegistryKey hklmRunDisabled =
             Registry.LocalMachine.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run-");
         if (newState) {
             hklmRunDisabled.Move(hklmRun, fileItem.Name);
         }
         else {
             hklmRun.Move(hklmRunDisabled, fileItem.Name);
         }
         hklmRun.Close();
         hklmRunDisabled.Close();
     }
     hkcrRun.Close();
     hkcrRunDisabled.Close();
 }
 internal static void Delete(FileItem fileItem, ObservableCollection<FileItem> rightClickFileItems)
 {
     using (RegistryKey hkcrFrndlyTxt = Registry.ClassesRoot.CreateSubKey(@"Directory\Background\Shell")) {
         if (hkcrFrndlyTxt == null && hkcrFrndlyTxt.OpenSubKey(fileItem.Tag.ToString()) != null) return;
         hkcrFrndlyTxt.DeleteSubKeyTree(fileItem.Tag.ToString());
         rightClickFileItems.Remove(fileItem);
     }
 }