Exemplo n.º 1
0
 private void LoadShellExItems()
 {
     foreach (XmlElement itemXE in shellExXE.GetElementsByTagName("Item"))
     {
         if (!GuidInfo.TryGetGuid(itemXE.GetAttribute("Guid"), out Guid guid))
         {
             continue;
         }
         if (ShellExItem.GetPathAndGuids(ShellExPath).Values.Contains(guid))
         {
             continue;
         }
         ShellExCommonItem item = new ShellExCommonItem
         {
             Image          = ResourceIcon.GetIcon(itemXE.GetAttribute("Icon"))?.ToBitmap() ?? AppImage.DllDefaultIcon,
             Text           = ResourceString.GetDirectString(itemXE.GetAttribute("Text")),
             DefaultKeyName = itemXE.GetAttribute("KeyName"),
             Guid           = guid
         };
         if (string.IsNullOrWhiteSpace(item.Text))
         {
             item.Text = GuidInfo.GetText(guid);
         }
         if (string.IsNullOrWhiteSpace(item.DefaultKeyName))
         {
             item.DefaultKeyName = guid.ToString("B");
         }
         item.SetTip(itemXE.GetAttribute("Tip"));
         list.AddItem(item);
     }
 }
Exemplo n.º 2
0
        private void LoadShellExItems(string shellExPath)
        {
            List <string> names = new List <string>();

            using (RegistryKey shellExKey = RegistryEx.GetRegistryKey(shellExPath))
            {
                if (shellExKey == null)
                {
                    return;
                }
                bool isDragDrop = Scene == Scenes.DragDrop;
                RegTrustedInstaller.TakeRegTreeOwnerShip(shellExKey.Name);
                Dictionary <string, Guid> dic       = ShellExItem.GetPathAndGuids(shellExPath, isDragDrop);
                GroupPathItem             groupItem = null;
                if (isDragDrop)
                {
                    groupItem = GetDragDropGroupItem(shellExPath);
                    this.AddItem(groupItem);
                }
                foreach (string path in dic.Keys)
                {
                    string keyName = RegistryEx.GetKeyName(path);
                    if (!names.Contains(keyName))
                    {
                        ShellExItem item = new ShellExItem(dic[path], path);
                        if (groupItem != null)
                        {
                            item.FoldGroupItem = groupItem;
                        }
                        this.AddItem(item);
                        names.Add(keyName);
                    }
                }
                if (groupItem != null)
                {
                    groupItem.IsFold = true;
                }
            }
        }
Exemplo n.º 3
0
        private void AddNewShellExItem(string scenePath)
        {
            bool isDragDrop = Scene == Scenes.DragDrop;

            using (InputDialog dlg1 = new InputDialog {
                Title = AppString.Dialog.InputGuid
            })
            {
                if (GuidEx.TryParse(Clipboard.GetText(), out Guid guid))
                {
                    dlg1.Text = guid.ToString();
                }
                if (dlg1.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
                if (GuidEx.TryParse(dlg1.Text, out guid))
                {
                    if (isDragDrop)
                    {
                        using (SelectDialog dlg2 = new SelectDialog())
                        {
                            dlg2.Title = AppString.Dialog.SelectGroup;
                            dlg2.Items = new[] { AppString.SideBar.Folder, AppString.SideBar.Directory,
                                                 AppString.SideBar.Drive, AppString.SideBar.AllObjects };
                            dlg2.Selected = dlg2.Items[0];
                            if (dlg2.ShowDialog() != DialogResult.OK)
                            {
                                return;
                            }
                            switch (dlg2.SelectedIndex)
                            {
                            case 0:
                                scenePath = MENUPATH_FOLDER; break;

                            case 1:
                                scenePath = MENUPATH_DIRECTORY; break;

                            case 2:
                                scenePath = MENUPATH_DRIVE; break;

                            case 3:
                                scenePath = MENUPATH_ALLOBJECTS; break;
                            }
                        }
                    }
                    string shellExPath = GetShellExPath(scenePath);
                    if (ShellExItem.GetPathAndGuids(shellExPath, isDragDrop).Values.Contains(guid))
                    {
                        MessageBoxEx.Show(AppString.MessageBox.HasBeenAdded);
                    }
                    else
                    {
                        string part    = isDragDrop ? ShellExItem.DdhParts[0] : ShellExItem.CmhParts[0];
                        string regPath = $@"{shellExPath}\{part}\{guid:B}";
                        Registry.SetValue(regPath, "", guid.ToString("B"));
                        ShellExItem item = new ShellExItem(guid, regPath);
                        for (int i = 0; i < this.Controls.Count; i++)
                        {
                            if (isDragDrop)
                            {
                                if (this.Controls[i] is GroupPathItem groupItem)
                                {
                                    if (groupItem.TargetPath.Equals(shellExPath, StringComparison.OrdinalIgnoreCase))
                                    {
                                        this.InsertItem(item, i + 1);
                                        item.FoldGroupItem = groupItem;
                                        item.Visible       = !groupItem.IsFold;
                                        break;
                                    }
                                }
                            }
                            else
                            {
                                if (this.Controls[i] is NewItem)
                                {
                                    this.InsertItem(item, i + 1);
                                    break;
                                }
                            }
                        }
                    }
                }
                else
                {
                    MessageBoxEx.Show(AppString.MessageBox.MalformedGuid);
                }
            }
        }