public override void LoadItems()
        {
            base.LoadItems();
            int         index = this.UseUserDic ? 1 : 0;
            XmlDocument doc   = XmlDicHelper.EnhanceMenusDic[index];

            if (doc?.DocumentElement == null)
            {
                return;
            }
            foreach (XmlNode xn in doc.DocumentElement.ChildNodes)
            {
                try
                {
                    Image  image = null;
                    string text  = null;
                    string path  = xn.SelectSingleNode("RegPath")?.InnerText;
                    foreach (XmlElement textXE in xn.SelectNodes("Text"))
                    {
                        if (XmlDicHelper.JudgeCulture(textXE))
                        {
                            text = ResourceString.GetDirectString(textXE.GetAttribute("Value"));
                        }
                    }
                    if (string.IsNullOrEmpty(path) || string.IsNullOrEmpty(text))
                    {
                        continue;
                    }
                    if (!string.IsNullOrEmpty(this.ScenePath) && !path.Equals(this.ScenePath, StringComparison.OrdinalIgnoreCase))
                    {
                        continue;
                    }

                    string iconLocation = xn.SelectSingleNode("Icon")?.InnerText;
                    using (Icon icon = ResourceIcon.GetIcon(iconLocation))
                    {
                        image = icon?.ToBitmap();
                        image = image ?? AppImage.NotFound;
                    }
                    FoldGroupItem groupItem = new FoldGroupItem(path, ObjectPath.PathType.Registry)
                    {
                        Image = image,
                        Text  = text
                    };
                    this.AddItem(groupItem);
                    XmlNode shellXN   = xn.SelectSingleNode("Shell");
                    XmlNode shellExXN = xn.SelectSingleNode("ShellEx");
                    if (shellXN != null)
                    {
                        LoadShellItems(shellXN, groupItem);
                    }
                    if (shellExXN != null)
                    {
                        LoadShellExItems(shellExXN, groupItem);
                    }
                    groupItem.SetVisibleWithSubItemCount();
                }
                catch { continue; }
            }
        }
Exemple #2
0
 public ChangeIconMenuItem(ITsiIconItem item) : base(AppString.Menu.ChangeIcon)
 {
     this.Click += (sender, e) =>
     {
         using (IconDialog dlg = new IconDialog())
         {
             dlg.IconPath  = item.IconPath;
             dlg.IconIndex = item.IconIndex;
             if (dlg.ShowDialog() != DialogResult.OK)
             {
                 return;
             }
             using (Icon icon = ResourceIcon.GetIcon(dlg.IconPath, dlg.IconIndex))
             {
                 Image image = icon?.ToBitmap();
                 if (image == null)
                 {
                     return;
                 }
                 item.Image        = image;
                 item.IconPath     = dlg.IconPath;
                 item.IconIndex    = dlg.IconIndex;
                 item.IconLocation = $"{dlg.IconPath},{dlg.IconIndex}";
             }
         }
     };
 }
Exemple #3
0
    private void OnNewStack(OSTData.ResourceStack stack)
    {
        ResourceIcon obj = Instantiate <ResourceIcon>(iconPrefab);

        obj.transform.SetParent(iconZone.transform);
        obj.SetData(stack);
    }
 private void LoadShellExItems(XmlElement shellExXE, GroupPathItem groupItem)
 {
     foreach (XmlElement itemXE in shellExXE.SelectNodes("Item"))
     {
         if (!JudgeOSVersion(itemXE))
         {
             continue;
         }
         if (!GuidEx.TryParse(itemXE.GetAttribute("Guid"), out Guid guid))
         {
             continue;
         }
         EnhanceShellExItem item = new EnhanceShellExItem
         {
             FoldGroupItem  = groupItem,
             ShellExPath    = $@"{groupItem.TargetPath}\ShellEx",
             Image          = ResourceIcon.GetIcon(itemXE.GetAttribute("Icon"))?.ToBitmap() ?? AppImage.DllDefaultIcon,
             Text           = ResourceString.GetDirectString(itemXE.GetAttribute("Text")),
             DefaultKeyName = itemXE.GetAttribute("KeyName"),
             Guid           = guid
         };
         if (item.Text.IsNullOrWhiteSpace())
         {
             item.Text = GuidInfo.GetText(guid);
         }
         if (item.DefaultKeyName.IsNullOrWhiteSpace())
         {
             item.DefaultKeyName = guid.ToString("B");
         }
         item.ChkVisible.Checked = item.ItemVisible;
         MyToolTip.SetToolTip(item.ChkVisible, itemXE.GetAttribute("Tip"));
         this.AddItem(item);
     }
 }
Exemple #5
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);
     }
 }
Exemple #6
0
        public ChangeIconMenuItem(ITsiIconItem item) : base(AppString.Menu.ChangeIcon)
        {
            this.Click += (sender, e) =>
            {
                using (IconDialog dlg = new IconDialog())
                {
                    dlg.IconPath  = item.IconPath;
                    dlg.IconIndex = item.IconIndex;
                    if (dlg.ShowDialog() != DialogResult.OK)
                    {
                        return;
                    }
                    item.IconPath     = dlg.IconPath;
                    item.IconIndex    = dlg.IconIndex;
                    item.IconLocation = $"{dlg.IconPath},{dlg.IconIndex}";
                    using (Icon icon = ResourceIcon.GetIcon(dlg.IconPath, dlg.IconIndex))
                    {
                        item.Image = icon.ToBitmap();
                    }
                }
            };
            MyListItem listItem = (MyListItem)item;

            listItem.Disposed         += (sender, e) => item.ItemIcon?.Dispose();
            listItem.ImageDoubleClick += (sender, e) =>
            {
                if (this.Enabled)
                {
                    this.OnClick(null);
                }
            };
        }
Exemple #7
0
    public void OnResourcePointerEnter(ResourceIcon icon)
    {
        if (icon.border)
        {
            icon.border.color = hoveredBorderColor;
        }
        helpPanel.SetActive(true);

        useHelp.SetActive(false);
        equipHelp.SetActive(false);
        unequipHelp.SetActive(false);
        getOne.SetActive(true);
        getTen.SetActive(true);
        giveOne.SetActive(false);
        giveTen.SetActive(false);

        hoveredArmor.transform.parent.gameObject.SetActive(false);
        hoveredDammage.transform.parent.gameObject.SetActive(false);

        if (icon.data)
        {
            helpDescription.text = icon.data.name + "resource";
            hoveredLoad.transform.parent.gameObject.SetActive(true);
            hoveredLoad.text = "1";
        }
        else
        {
            hoveredLoad.transform.parent.gameObject.SetActive(false);
            Debug.LogWarning("No data in ResourceIcon");
        }
    }
Exemple #8
0
        public static Image GetImage(Guid guid)
        {
            if (ItemImageDic.TryGetValue(guid, out Image image))
            {
                return(image);
            }
            IconLocation location  = GetIconLocation(guid);
            string       iconPath  = location.IconPath;
            int          iconIndex = location.IconIndex;

            if (iconPath == null && iconIndex == 0)
            {
                image = AppImage.DllDefaultIcon;
            }
            else if (Path.GetFileName(iconPath).ToLower() == "shell32.dll" && iconIndex == 0)
            {
                image = AppImage.DllDefaultIcon;
            }
            else
            {
                image = ResourceIcon.GetIcon(iconPath, iconIndex)?.ToBitmap() ?? AppImage.DllDefaultIcon;
            }
            ItemImageDic.Add(guid, image);
            return(image);
        }
Exemple #9
0
 public void OnResourcePointerExit(ResourceIcon icon)
 {
     if (icon.border)
     {
         icon.border.color = defaultBorderColor;
     }
     helpPanel.SetActive(false);
 }
 private void LoadShellExItems(XmlNode shellExXN, FoldGroupItem groupItem)
 {
     foreach (XmlNode itemXN in shellExXN.SelectNodes("Item"))
     {
         if (!XmlDicHelper.FileExists(itemXN))
         {
             continue;
         }
         if (!XmlDicHelper.JudgeCulture(itemXN))
         {
             continue;
         }
         if (!XmlDicHelper.JudgeOSVersion(itemXN))
         {
             continue;
         }
         if (!GuidEx.TryParse(itemXN.SelectSingleNode("Guid")?.InnerText, out Guid guid))
         {
             continue;
         }
         EnhanceShellExItem item = new EnhanceShellExItem
         {
             FoldGroupItem  = groupItem,
             ShellExPath    = $@"{groupItem.GroupPath}\ShellEx",
             Image          = ResourceIcon.GetIcon(itemXN.SelectSingleNode("Icon")?.InnerText)?.ToBitmap() ?? AppImage.SystemFile,
             DefaultKeyName = itemXN.SelectSingleNode("KeyName")?.InnerText,
             Guid           = guid
         };
         foreach (XmlNode textXE in itemXN.SelectNodes("Text"))
         {
             if (XmlDicHelper.JudgeCulture(textXE))
             {
                 item.Text = ResourceString.GetDirectString(textXE.InnerText);
             }
         }
         if (item.Text.IsNullOrWhiteSpace())
         {
             item.Text = GuidInfo.GetText(guid);
         }
         if (item.DefaultKeyName.IsNullOrWhiteSpace())
         {
             item.DefaultKeyName = guid.ToString("B");
         }
         string tip = "";
         foreach (XmlElement tipXE in itemXN.SelectNodes("Tip"))
         {
             if (XmlDicHelper.JudgeCulture(tipXE))
             {
                 tip = tipXE.GetAttribute("Text");
             }
         }
         ToolTipBox.SetToolTip(item.ChkVisible, tip);
         this.AddItem(item);
     }
 }
Exemple #11
0
    public void SetZone(OSTData.ResourceHolder zone)
    {
        _zone               = zone;
        zone.onNewStack    += OnNewStack;
        zone.onRemoveStack += OnRemoveStack;

        foreach (OSTData.ResourceStack s in zone.ResourceStacks)
        {
            ResourceIcon obj = Instantiate <ResourceIcon>(iconPrefab);
            obj.transform.SetParent(iconZone.transform);
            obj.SetData(s);
        }
    }
        private void AddDirItem()
        {
            MyListItem item = new MyListItem
            {
                Text  = Path.GetFileNameWithoutExtension(SendToPath),
                Image = ResourceIcon.GetFolderIcon(SendToPath).ToBitmap()
            };
            PictureButton btnPath = new PictureButton(AppImage.Open);

            MyToolTip.SetToolTip(btnPath, AppString.Menu.FileLocation);
            btnPath.MouseDown += (sender, e) => ExternalProgram.JumpExplorer(SendToPath);
            item.AddCtr(btnPath);
            this.InsertItem(item, 1);
        }
Exemple #13
0
    private void UpdateResources()
    {
        while (resourcesGrid.transform.childCount > 0)
        {
            Destroy(resourcesGrid.transform.GetChild(0).gameObject);
            resourcesGrid.transform.GetChild(0).SetParent(null);
        }

        foreach (int i in _hangar.StacksIDs)
        {
            ResourceIcon  icon = Instantiate(resourceIconPrefab, resourcesGrid.transform);
            ResourceStack r    = LocalDataManager.instance.GetResourceStackInfo(i);
            icon.SetStack(r);
        }
    }
 public static Icon ChangeIcon(ref string iconPath, ref int iconIndex)
 {
     using (IconDialog dlg = new IconDialog {
         IconPath = iconPath, IconIndex = iconIndex
     })
     {
         if (dlg.ShowDialog() != DialogResult.OK)
         {
             return(null);
         }
         iconPath  = dlg.IconPath;
         iconIndex = dlg.IconIndex;
     }
     return(ResourceIcon.GetIcon(iconPath, iconIndex));
 }
 private void SelectIcon()
 {
     using (IconDialog dlg = new IconDialog())
     {
         dlg.IconPath  = this.ItemIconPath;
         dlg.IconIndex = this.ItemIconIndex;
         if (dlg.ShowDialog() != DialogResult.OK)
         {
             return;
         }
         ItemIconPath  = dlg.IconPath;
         ItemIconIndex = dlg.IconIndex;
         picIcon.Image = ResourceIcon.GetIcon(ItemIconPath, ItemIconIndex).ToBitmap();
     }
 }
 private void LoadShellItems(XmlElement shellXE, GroupPathItem groupItem)
 {
     foreach (XmlElement itemXE in shellXE.GetElementsByTagName("Item"))
     {
         XmlElement verXE = (XmlElement)itemXE.SelectSingleNode("OSVersion");
         if (!JudgeOSVersion(verXE))
         {
             continue;
         }
         XmlElement szXE    = (XmlElement)itemXE.SelectSingleNode("Value/REG_SZ");
         string     keyName = itemXE.GetAttribute("KeyName");
         if (keyName.IsNullOrWhiteSpace())
         {
             continue;
         }
         string           regPath = $@"{groupItem.TargetPath}\shell\{keyName}";
         EnhanceShellItem item    = new EnhanceShellItem()
         {
             RegPath       = $@"{groupItem.TargetPath}\shell\{keyName}",
             FoldGroupItem = groupItem,
             ItemXE        = itemXE
         };
         if (szXE != null)
         {
             item.Text = ResourceString.GetDirectString(szXE.GetAttribute("MUIVerb"));
             if (szXE.HasAttribute("Icon"))
             {
                 item.Image = ResourceIcon.GetIcon(szXE.GetAttribute("Icon"))?.ToBitmap();
             }
             else if (szXE.HasAttribute("HasLUAShield"))
             {
                 item.Image = AppImage.Shield;
             }
         }
         if (item.Image == null)
         {
             item.Image = AppImage.NotFound;
         }
         if (item.Text.IsNullOrWhiteSpace())
         {
             item.Text = keyName;
         }
         item.ChkVisible.Checked = item.ItemVisible;
         MyToolTip.SetToolTip(item.ChkVisible, itemXE.GetAttribute("Tip"));
         this.AddItem(item);
     }
 }
 protected override bool RunDialog(IntPtr hwndOwner)
 {
     using (SubItemsForm frm = new SubItemsForm())
         using (DetailedEditList list = new DetailedEditList())
         {
             var location = GuidInfo.GetIconLocation(this.GroupGuid);
             frm.Icon    = ResourceIcon.GetIcon(location.IconPath, location.IconIndex);
             frm.Text    = AppString.Dialog.DetailedEdit.Replace("%s", GuidInfo.GetText(this.GroupGuid));
             frm.TopMost = AppConfig.TopMost;
             frm.AddList(list);
             list.GroupGuid  = this.GroupGuid;
             list.UseUserDic = XmlDicHelper.DetailedEditGuidDic[this.GroupGuid];
             list.LoadItems();
             frm.ShowDialog();
         }
     return(false);
 }
        private void LoadSubDirItems(DirectoryInfo di)
        {
            GroupPathItem groupItem = new GroupPathItem(di.FullName, ObjectPath.PathType.Directory)
            {
                Text  = Path.GetFileNameWithoutExtension(di.FullName),
                Image = ResourceIcon.GetFolderIcon(di.FullName).ToBitmap()
            };

            this.AddItem(groupItem);
            string iniPath = $@"{di.FullName}\desktop.ini";

            DesktopIniReaders.Add(di.FullName, new IniReader(iniPath));
            Array.ForEach(di.GetFiles(), fi =>
            {
                if (fi.Extension.ToLower() == ".lnk")
                {
                    this.AddItem(new WinXItem(fi.FullName, groupItem));
                }
            });
        }
Exemple #19
0
    public void OnResourceClick(ResourceIcon icon)
    {
        if (icon.data && (Input.GetMouseButtonUp(0) || Input.GetMouseButtonUp(1)))
        {
            string         resourceName   = icon.data.name;
            SummarizedItem si             = ResourceDictionary.instance.GetResourceItem(icon.data.interactionType).Summarize();
            int            transfertCount = Input.GetMouseButtonUp(0) ? 1 : 10;
            transfertCount = Mathf.Min(transfertCount, interactionUI.resourceContainer.inventory[resourceName]);
            transfertCount = inventory.TryAddItem(si, transfertCount);

            if (transfertCount > 0)
            {
                interactionUI.resourceContainer.RemoveItem(resourceName, transfertCount);
            }
            else
            {
                PlayerController.MainInstance.interactionController.ThrowHelp("Container", "full");
            }
        }
    }
Exemple #20
0
 private void LoadShellItems()
 {
     foreach (XmlElement itemXE in shellXE.GetElementsByTagName("Item"))
     {
         XmlElement szXE    = (XmlElement)itemXE.SelectSingleNode("Value/REG_SZ");
         string     keyName = itemXE.GetAttribute("KeyName");
         if (string.IsNullOrWhiteSpace(keyName))
         {
             continue;
         }
         ShellCommonItem item = new ShellCommonItem
         {
             DefaultKeyName = keyName,
             ItemXE         = itemXE
         };
         if (szXE != null)
         {
             item.Text = ResourceString.GetDirectString(szXE.GetAttribute("MUIVerb"));
             if (szXE.HasAttribute("Icon"))
             {
                 item.Image = ResourceIcon.GetIcon(szXE.GetAttribute("Icon"))?.ToBitmap();
             }
             else if (szXE.HasAttribute("HasLUAShield"))
             {
                 item.Image = AppImage.Shield;
             }
         }
         if (item.Image == null)
         {
             item.Image = AppImage.NotFound;
         }
         if (string.IsNullOrWhiteSpace(item.Text))
         {
             item.Text = item.DefaultKeyName;
         }
         item.SetTip(itemXE.GetAttribute("Tip"));
         list.AddItem(item);
     }
 }
 private void SelectIcon()
 {
     using (IconDialog dlg = new IconDialog())
     {
         dlg.IconPath  = this.ItemIconPath;
         dlg.IconIndex = this.ItemIconIndex;
         if (dlg.ShowDialog() != DialogResult.OK)
         {
             return;
         }
         using (Icon icon = ResourceIcon.GetIcon(dlg.IconPath, dlg.IconIndex))
         {
             Image image = icon?.ToBitmap();
             if (image == null)
             {
                 return;
             }
             picIcon.Image      = image;
             this.ItemIconPath  = dlg.IconPath;
             this.ItemIconIndex = dlg.IconIndex;
         }
     }
 }
Exemple #22
0
        private void AddDirItem()
        {
            MyListItem item = new MyListItem
            {
                Text  = Path.GetFileNameWithoutExtension(SendToPath),
                Image = ResourceIcon.GetFolderIcon(SendToPath).ToBitmap()
            };
            PictureButton btnPath = new PictureButton(AppImage.Open);

            ToolTipBox.SetToolTip(btnPath, AppString.Menu.FileLocation);
            btnPath.MouseDown += (sender, e) => ExternalProgram.OpenDirectory(SendToPath);
            item.AddCtr(btnPath);
            this.InsertItem(item, 1);
            item.ContextMenuStrip = new ContextMenuStrip();
            ToolStripMenuItem tsiRestoreDefault = new ToolStripMenuItem(AppString.Menu.RestoreDefault);

            item.ContextMenuStrip.Items.Add(tsiRestoreDefault);
            tsiRestoreDefault.Enabled = Directory.Exists(DefaultSendToPath);
            tsiRestoreDefault.Click  += (sender, e) =>
            {
                if (AppMessageBox.Show(AppString.Message.RestoreDefault, MessageBoxButtons.OKCancel) == DialogResult.OK)
                {
                    File.SetAttributes(SendToPath, FileAttributes.Normal);
                    Directory.Delete(SendToPath, true);
                    Directory.CreateDirectory(SendToPath);
                    File.SetAttributes(SendToPath, File.GetAttributes(DefaultSendToPath));
                    foreach (string srcPath in Directory.GetFiles(DefaultSendToPath))
                    {
                        string dstPath = $@"{SendToPath}\{Path.GetFileName(srcPath)}";
                        File.Copy(srcPath, dstPath);
                    }
                    this.ClearItems();
                    this.LoadItems();
                }
            };
        }
        public override void Construct()
        {
            Font = "font8";

            var currentEquipPanel = AddChild(new Widget
            {
                Transparent = true,
                AutoLayout  = AutoLayout.DockLeft,
                MinimumSize = new Point(128, 0)
            });

            ContentsPanel = AddChild(new ContentsPanel
            {
                AutoLayout        = AutoLayout.DockFill,
                MinimumSize       = new Point(128, 0),
                Border            = "border-one",
                EnableDragAndDrop = false,
                Resources         = new ResourceSet(),
                OnIconClicked     = (sender, args) =>
                {
                    SelectedEquipIcon.Resource = (sender as ResourceIcon).Resource;
                    EquipButton.Hidden         = false;
                    EquipButton.Invalidate();
                }
            }) as ContentsPanel;

            var equipmentSlotPanel = currentEquipPanel.AddChild(new Widget
            {
                MinimumSize = new Point(104, 104),
                MaximumSize = new Point(104, 104),
                AutoLayout  = AutoLayout.DockTopCentered
            });

            equipmentSlotPanel.AddChild(new Widget
            {
                Background  = new TileReference("equipment_sheet", 0),
                MinimumSize = new Point(32, 32),
                MaximumSize = new Point(32, 32),
                AutoLayout  = AutoLayout.FloatCenter
            });

            var comparisonPanel = currentEquipPanel.AddChild(new Widget
            {
                AutoLayout = AutoLayout.DockFill,
                Border     = "border-one"
            });

            var bottomBar = comparisonPanel.AddChild(new Widget
            {
                AutoLayout  = AutoLayout.DockBottom,
                MinimumSize = new Point(0, 32)
            });

            RemoveButton = bottomBar.AddChild(new Widget
            {
                Text = "REMOVE",
                TextVerticalAlign  = VerticalAlign.Center,
                MinimumSize        = new Point(64, 32),
                MaximumSize        = new Point(64, 32),
                AutoLayout         = AutoLayout.DockLeft,
                ChangeColorOnHover = true,
                OnClick            = (_sender, args) =>
                {
                    if (SelectedSlotIcon.Resource != null)
                    {
                        Employee.AssignTask(new UnequipTask(SelectedSlotIcon.Resource));
                    }
                },
                Hidden = true
            });

            EquipButton = bottomBar.AddChild(new Widget
            {
                Text = "EQUIP",
                TextVerticalAlign  = VerticalAlign.Center,
                MinimumSize        = new Point(64, 32),
                MaximumSize        = new Point(64, 32),
                AutoLayout         = AutoLayout.DockRight,
                ChangeColorOnHover = true,
                OnClick            = (_sender, args) =>
                {
                    if (SelectedEquipIcon.Resource != null)
                    {
                        Employee.AssignTask(new FindAndEquipTask(SelectedEquipIcon.Resource.DisplayName)); // Todo: Since we had to enumerate to build the list - couldn't we save the location?
                    }
                },
                Hidden = true
            });

            foreach (var slot in Library.EnumerateEquipmentSlotTypes())
            {
                var slotIcon = AddChild(new ResourceIcon
                {
                    OnLayout          = (_) => _.Rect = new Rectangle(equipmentSlotPanel.Rect.X + slot.GuiOffset.X, equipmentSlotPanel.Rect.Y + slot.GuiOffset.Y, 32, 32),
                    EnableDragAndDrop = false,
                    Tag     = slot,
                    OnClick = (sender, args) =>
                    {
                        SelectedSlot = sender.Tag as EquipmentSlotType;
                        SelectedEquipIcon.Resource = null;
                        EquipButton.Hidden         = true;
                    },
                    OverrideTooltip = true
                }) as ResourceIcon;

                ResourceIcons.Add(slot.Name, slotIcon);
            }

            SelectedSlotIcon = comparisonPanel.AddChild(new ResourceIcon
            {
                AutoLayout = AutoLayout.FloatTopLeft
            }) as ResourceIcon;

            SelectedEquipIcon = comparisonPanel.AddChild(new ResourceIcon
            {
                AutoLayout  = AutoLayout.FloatTopRight,
                MinimumSize = new Point(32, 32)
            }) as ResourceIcon;


            base.Construct();
        }
Exemple #24
0
 private static Image GetIconImage(string dllName, int iconIndex)
 {
     using (Icon icon = ResourceIcon.GetIcon(dllName, iconIndex)) return(icon?.ToBitmap());
 }
        public override void LoadItems()
        {
            base.LoadItems();
            int         index = this.UseUserDic ? 1 : 0;
            XmlDocument doc   = XmlDicHelper.DetailedEditDic[index];

            if (doc?.DocumentElement == null)
            {
                return;
            }
            foreach (XmlNode groupXN in doc.DocumentElement.ChildNodes)
            {
                try
                {
                    List <Guid> guids    = new List <Guid>();
                    XmlNodeList guidList = groupXN.SelectNodes("Guid");
                    foreach (XmlNode guidXN in guidList)
                    {
                        if (!GuidEx.TryParse(guidXN.InnerText, out Guid guid))
                        {
                            continue;
                        }
                        if (!File.Exists(GuidInfo.GetFilePath(guid)))
                        {
                            continue;
                        }
                        if (this.GroupGuid != Guid.Empty && this.GroupGuid != guid)
                        {
                            continue;
                        }
                        guids.Add(guid);
                    }
                    if (guidList.Count > 0 && guids.Count == 0)
                    {
                        continue;
                    }

                    FoldGroupItem       groupItem;
                    bool                isIniGroup = groupXN.SelectSingleNode("IsIniGroup") != null;
                    string              attribute  = isIniGroup ? "FilePath" : "RegPath";
                    ObjectPath.PathType pathType   = isIniGroup ? ObjectPath.PathType.File : ObjectPath.PathType.Registry;
                    groupItem = new FoldGroupItem(groupXN.SelectSingleNode(attribute)?.InnerText, pathType);
                    foreach (XmlElement textXE in groupXN.SelectNodes("Text"))
                    {
                        if (XmlDicHelper.JudgeCulture(textXE))
                        {
                            groupItem.Text = ResourceString.GetDirectString(textXE.GetAttribute("Value"));
                        }
                    }
                    if (guids.Count > 0)
                    {
                        groupItem.Tag = guids;
                        if (groupItem.Text.IsNullOrWhiteSpace())
                        {
                            groupItem.Text = GuidInfo.GetText(guids[0]);
                        }
                        groupItem.Image = GuidInfo.GetImage(guids[0]);
                        string filePath  = GuidInfo.GetFilePath(guids[0]);
                        string clsidPath = GuidInfo.GetClsidPath(guids[0]);
                        if (filePath != null || clsidPath != null)
                        {
                            groupItem.ContextMenuStrip.Items.Add(new ToolStripSeparator());
                        }
                        if (filePath != null)
                        {
                            ToolStripMenuItem tsi = new ToolStripMenuItem(AppString.Menu.FileLocation);
                            tsi.Click += (sender, e) => ExternalProgram.JumpExplorer(filePath, AppConfig.OpenMoreExplorer);
                            groupItem.ContextMenuStrip.Items.Add(tsi);
                        }
                        if (clsidPath != null)
                        {
                            ToolStripMenuItem tsi = new ToolStripMenuItem(AppString.Menu.ClsidLocation);
                            tsi.Click += (sender, e) => ExternalProgram.JumpRegEdit(clsidPath, null, AppConfig.OpenMoreRegedit);
                            groupItem.ContextMenuStrip.Items.Add(tsi);
                        }
                    }
                    XmlNode iconXN = groupXN.SelectSingleNode("Icon");
                    using (Icon icon = ResourceIcon.GetIcon(iconXN?.InnerText))
                    {
                        if (icon != null)
                        {
                            groupItem.Image = icon.ToBitmap();
                        }
                    }
                    this.AddItem(groupItem);

                    string GetRuleFullRegPath(string regPath)
                    {
                        if (string.IsNullOrEmpty(regPath))
                        {
                            regPath = groupItem.GroupPath;
                        }
                        else if (regPath.StartsWith("\\"))
                        {
                            regPath = groupItem.GroupPath + regPath;
                        }
                        return(regPath);
                    };

                    foreach (XmlElement itemXE in groupXN.SelectNodes("Item"))
                    {
                        try
                        {
                            if (!XmlDicHelper.JudgeOSVersion(itemXE))
                            {
                                continue;
                            }
                            RuleItem ruleItem;
                            ItemInfo info = new ItemInfo();
                            foreach (XmlElement textXE in itemXE.SelectNodes("Text"))
                            {
                                if (XmlDicHelper.JudgeCulture(textXE))
                                {
                                    info.Text = ResourceString.GetDirectString(textXE.GetAttribute("Value"));
                                }
                            }
                            foreach (XmlElement tipXE in itemXE.SelectNodes("Tip"))
                            {
                                if (XmlDicHelper.JudgeCulture(tipXE))
                                {
                                    info.Tip = ResourceString.GetDirectString(tipXE.GetAttribute("Value"));
                                }
                            }
                            info.RestartExplorer = itemXE.SelectSingleNode("RestartExplorer") != null;

                            int defaultValue = 0, maxValue = 0, minValue = 0;
                            if (itemXE.SelectSingleNode("IsNumberItem") != null)
                            {
                                XmlElement ruleXE = (XmlElement)itemXE.SelectSingleNode("Rule");
                                defaultValue = ruleXE.HasAttribute("Default") ? Convert.ToInt32(ruleXE.GetAttribute("Default")) : 0;
                                maxValue     = ruleXE.HasAttribute("Max") ? Convert.ToInt32(ruleXE.GetAttribute("Max")) : int.MaxValue;
                                minValue     = ruleXE.HasAttribute("Min") ? Convert.ToInt32(ruleXE.GetAttribute("Min")) : int.MinValue;
                            }

                            if (isIniGroup)
                            {
                                XmlElement ruleXE  = (XmlElement)itemXE.SelectSingleNode("Rule");
                                string     iniPath = ruleXE.GetAttribute("FilePath");
                                if (iniPath.IsNullOrWhiteSpace())
                                {
                                    iniPath = groupItem.GroupPath;
                                }
                                string section = ruleXE.GetAttribute("Section");
                                string keyName = ruleXE.GetAttribute("KeyName");
                                if (itemXE.SelectSingleNode("IsNumberItem") != null)
                                {
                                    var rule = new NumberIniRuleItem.IniRule
                                    {
                                        IniPath      = iniPath,
                                        Section      = section,
                                        KeyName      = keyName,
                                        DefaultValue = defaultValue,
                                        MaxValue     = maxValue,
                                        MinValue     = maxValue
                                    };
                                    ruleItem = new NumberIniRuleItem(rule, info);
                                }
                                else if (itemXE.SelectSingleNode("IsStringItem") != null)
                                {
                                    var rule = new StringIniRuleItem.IniRule
                                    {
                                        IniPath  = iniPath,
                                        Secation = section,
                                        KeyName  = keyName
                                    };
                                    ruleItem = new StringIniRuleItem(rule, info);
                                }
                                else
                                {
                                    var rule = new VisbleIniRuleItem.IniRule
                                    {
                                        IniPath      = iniPath,
                                        Section      = section,
                                        KeyName      = keyName,
                                        TurnOnValue  = ruleXE.HasAttribute("On") ? ruleXE.GetAttribute("On") : null,
                                        TurnOffValue = ruleXE.HasAttribute("Off") ? ruleXE.GetAttribute("Off") : null,
                                    };
                                    ruleItem = new VisbleIniRuleItem(rule, info);
                                }
                            }
                            else
                            {
                                if (itemXE.SelectSingleNode("IsNumberItem") != null)
                                {
                                    XmlElement ruleXE = (XmlElement)itemXE.SelectSingleNode("Rule");
                                    var        rule   = new NumberRegRuleItem.RegRule
                                    {
                                        RegPath      = GetRuleFullRegPath(ruleXE.GetAttribute("RegPath")),
                                        ValueName    = ruleXE.GetAttribute("ValueName"),
                                        ValueKind    = XmlDicHelper.GetValueKind(ruleXE.GetAttribute("ValueKind"), RegistryValueKind.DWord),
                                        DefaultValue = defaultValue,
                                        MaxValue     = maxValue,
                                        MinValue     = minValue
                                    };
                                    ruleItem = new NumberRegRuleItem(rule, info);
                                }
                                else if (itemXE.SelectSingleNode("IsStringItem") != null)
                                {
                                    XmlElement ruleXE = (XmlElement)itemXE.SelectSingleNode("Rule");
                                    var        rule   = new StringRegRuleItem.RegRule
                                    {
                                        RegPath   = GetRuleFullRegPath(ruleXE.GetAttribute("RegPath")),
                                        ValueName = ruleXE.GetAttribute("ValueName"),
                                    };
                                    ruleItem = new StringRegRuleItem(rule, info);
                                }
                                else
                                {
                                    XmlNodeList ruleXNList = itemXE.SelectNodes("Rule");
                                    var         rules      = new VisibleRegRuleItem.RegRule[ruleXNList.Count];
                                    for (int i = 0; i < ruleXNList.Count; i++)
                                    {
                                        XmlElement ruleXE = (XmlElement)ruleXNList[i];
                                        rules[i] = new VisibleRegRuleItem.RegRule
                                        {
                                            RegPath   = GetRuleFullRegPath(ruleXE.GetAttribute("RegPath")),
                                            ValueName = ruleXE.GetAttribute("ValueName"),
                                            ValueKind = XmlDicHelper.GetValueKind(ruleXE.GetAttribute("ValueKind"), RegistryValueKind.DWord)
                                        };
                                        string turnOn  = ruleXE.HasAttribute("On") ? ruleXE.GetAttribute("On") : null;
                                        string turnOff = ruleXE.HasAttribute("Off") ? ruleXE.GetAttribute("Off") : null;
                                        switch (rules[i].ValueKind)
                                        {
                                        case RegistryValueKind.Binary:
                                            rules[i].TurnOnValue = turnOn != null?XmlDicHelper.ConvertToBinary(turnOn) : null;

                                            rules[i].TurnOffValue = turnOff != null?XmlDicHelper.ConvertToBinary(turnOff) : null;

                                            break;

                                        case RegistryValueKind.DWord:
                                            if (turnOn == null)
                                            {
                                                rules[i].TurnOnValue = null;
                                            }
                                            else
                                            {
                                                rules[i].TurnOnValue = Convert.ToInt32(turnOn);
                                            }
                                            if (turnOff == null)
                                            {
                                                rules[i].TurnOffValue = null;
                                            }
                                            else
                                            {
                                                rules[i].TurnOffValue = Convert.ToInt32(turnOff);
                                            }
                                            break;

                                        default:
                                            rules[i].TurnOnValue  = turnOn;
                                            rules[i].TurnOffValue = turnOff;
                                            break;
                                        }
                                    }
                                    ruleItem = new VisibleRegRuleItem(rules, info);
                                }
                            }
                            this.AddItem(ruleItem);
                            ruleItem.FoldGroupItem = groupItem;
                            ruleItem.HasImage      = ruleItem.Image != null;
                            ruleItem.Indent();
                        }
                        catch { continue; }
                    }
                    groupItem.SetVisibleWithSubItemCount();
                }
                catch { continue; }
            }
        }
        private GroupPathItem GetGroupPathItem(XmlNode xn)
        {
            string path;
            string text;
            Image  image;

            switch (xn.Name)
            {
            case "File":
                path  = ShellList.MENUPATH_FILE;
                text  = AppString.SideBar.File;
                image = AppImage.File;
                break;

            case "Folder":
                path  = ShellList.MENUPATH_FOLDER;
                text  = AppString.SideBar.Folder;
                image = AppImage.Folder;
                break;

            case "Directory":
                path  = ShellList.MENUPATH_FOLDER;
                text  = AppString.SideBar.Directory;
                image = AppImage.Directory;
                break;

            case "Background":
                path  = ShellList.MENUPATH_BACKGROUND;
                text  = AppString.SideBar.Background;
                image = AppImage.Background;
                break;

            case "Desktop":
                path = ShellList.MENUPATH_DESKTOP;
                //Vista没有桌面右键菜单的独立注册表项
                if (WindowsOsVersion.IsEqualVista)
                {
                    path = ShellList.MENUPATH_BACKGROUND;
                }
                text  = AppString.SideBar.Desktop;
                image = AppImage.Desktop;
                break;

            case "Drive":
                path  = ShellList.MENUPATH_DRIVE;
                text  = AppString.SideBar.Drive;
                image = AppImage.Drive;
                break;

            case "AllObjects":
                path  = ShellList.MENUPATH_ALLOBJECTS;
                text  = AppString.SideBar.AllObjects;
                image = AppImage.AllObjects;
                break;

            case "Computer":
                path  = ShellList.MENUPATH_COMPUTER;
                text  = AppString.SideBar.Computer;
                image = AppImage.Computer;
                break;

            case "RecycleBin":
                path  = ShellList.MENUPATH_RECYCLEBIN;
                text  = AppString.SideBar.RecycleBin;
                image = AppImage.RecycleBin;
                break;

            default:
                XmlElement xe = (XmlElement)xn;
                path = xe.GetAttribute("RegPath");
                text = ResourceString.GetDirectString(xe.GetAttribute("Text"));
                if (string.IsNullOrEmpty(path) || string.IsNullOrEmpty(text))
                {
                    return(null);
                }
                image = ResourceIcon.GetIcon(xe.GetAttribute("Icon"))?.ToBitmap() ?? AppImage.NotFound;
                break;
            }
            GroupPathItem groupItem = new GroupPathItem(path, ObjectPath.PathType.Registry)
            {
                Image = image, Text = text
            };

            return(groupItem);
        }
 private void LoadShellItems(XmlElement shellXE, GroupPathItem groupItem)
 {
     foreach (XmlElement itemXE in shellXE.SelectNodes("Item"))
     {
         if (!JudgeOSVersion(itemXE))
         {
             continue;
         }
         if (!FileExists(itemXE))
         {
             continue;
         }
         XmlElement szXE    = (XmlElement)itemXE.SelectSingleNode("Value/REG_SZ");
         string     keyName = itemXE.GetAttribute("KeyName");
         if (keyName.IsNullOrWhiteSpace())
         {
             continue;
         }
         EnhanceShellItem item = new EnhanceShellItem()
         {
             RegPath       = $@"{groupItem.TargetPath}\shell\{keyName}",
             FoldGroupItem = groupItem,
             ItemXE        = itemXE
         };
         if (szXE != null)
         {
             item.Text = ResourceString.GetDirectString(szXE.GetAttribute("MUIVerb"));
             if (szXE.HasAttribute("Icon"))
             {
                 item.Image = ResourceIcon.GetIcon(szXE.GetAttribute("Icon"))?.ToBitmap();
             }
             else if (szXE.HasAttribute("HasLUAShield"))
             {
                 item.Image = AppImage.Shield;
             }
             else
             {
                 XmlElement cmdXE = (XmlElement)itemXE.SelectSingleNode("SubKey/Command");
                 if (cmdXE != null)
                 {
                     Icon icon = null;
                     if (cmdXE.HasAttribute("Default"))
                     {
                         string filePath = ObjectPath.ExtractFilePath(cmdXE.GetAttribute("Default"));
                         icon = ResourceIcon.GetIcon(filePath);
                     }
                     item.Image = icon?.ToBitmap();
                     icon?.Dispose();
                 }
             }
         }
         if (item.Image == null)
         {
             item.Image = AppImage.NotFound;
         }
         if (item.Text.IsNullOrWhiteSpace())
         {
             item.Text = keyName;
         }
         item.ChkVisible.Checked = item.ItemVisible;
         string tip = itemXE.GetAttribute("Tip");
         if (itemXE.GetElementsByTagName("CreateFile").Count > 0)
         {
             if (!tip.IsNullOrWhiteSpace())
             {
                 tip += "\n";
             }
             tip += AppString.Tip.CommandFiles;
             if (System.Diagnostics.Debugger.IsAttached)
             {
                 item.ChkVisible.Checked = item.ItemVisible = true;
             }
         }
         MyToolTip.SetToolTip(item.ChkVisible, tip);
         this.AddItem(item);
     }
 }
 private void LoadShellItems(XmlNode shellXN, FoldGroupItem groupItem)
 {
     foreach (XmlElement itemXE in shellXN.SelectNodes("Item"))
     {
         if (!XmlDicHelper.FileExists(itemXE))
         {
             continue;
         }
         if (!XmlDicHelper.JudgeCulture(itemXE))
         {
             continue;
         }
         if (!XmlDicHelper.JudgeOSVersion(itemXE))
         {
             continue;
         }
         string keyName = itemXE.GetAttribute("KeyName");
         if (keyName.IsNullOrWhiteSpace())
         {
             continue;
         }
         EnhanceShellItem item = new EnhanceShellItem()
         {
             RegPath       = $@"{groupItem.GroupPath}\shell\{keyName}",
             FoldGroupItem = groupItem,
             ItemXE        = itemXE
         };
         foreach (XmlElement szXE in itemXE.SelectNodes("Value/REG_SZ"))
         {
             if (!XmlDicHelper.JudgeCulture(szXE))
             {
                 continue;
             }
             if (szXE.HasAttribute("MUIVerb"))
             {
                 item.Text = ResourceString.GetDirectString(szXE.GetAttribute("MUIVerb"));
             }
             if (szXE.HasAttribute("Icon"))
             {
                 item.Image = ResourceIcon.GetIcon(szXE.GetAttribute("Icon"))?.ToBitmap();
             }
             else if (szXE.HasAttribute("HasLUAShield"))
             {
                 item.Image = AppImage.Shield;
             }
         }
         if (item.Image == null)
         {
             XmlElement cmdXE = (XmlElement)itemXE.SelectSingleNode("SubKey/Command");
             if (cmdXE != null)
             {
                 Icon icon = null;
                 if (cmdXE.HasAttribute("Default"))
                 {
                     string filePath = ObjectPath.ExtractFilePath(cmdXE.GetAttribute("Default"));
                     icon = ResourceIcon.GetIcon(filePath);
                 }
                 else
                 {
                     XmlNode fileXE = cmdXE.SelectSingleNode("FileName");
                     if (fileXE != null)
                     {
                         string filePath = ObjectPath.ExtractFilePath(fileXE.InnerText);
                         icon = ResourceIcon.GetIcon(filePath);
                     }
                 }
                 item.Image = icon?.ToBitmap();
                 icon?.Dispose();
             }
         }
         if (item.Image == null)
         {
             item.Image = AppImage.NotFound;
         }
         if (item.Text.IsNullOrWhiteSpace())
         {
             item.Text = keyName;
         }
         string tip = "";
         foreach (XmlElement tipXE in itemXE.SelectNodes("Tip"))
         {
             if (XmlDicHelper.JudgeCulture(tipXE))
             {
                 tip = tipXE.GetAttribute("Value");
             }
         }
         if (itemXE.GetElementsByTagName("CreateFile").Count > 0)
         {
             if (!tip.IsNullOrWhiteSpace())
             {
                 tip += "\n";
             }
             tip += AppString.Tip.CommandFiles;
         }
         ToolTipBox.SetToolTip(item.ChkVisible, tip);
         this.AddItem(item);
     }
 }
Exemple #29
0
 public static BitmapImage GetResourceImage(ResourceIcon r)
 {
     return(icons[r]);
 }
        public void LoadItems()
        {
            try
            {
                foreach (XmlNode xn in ReadXml().DocumentElement.ChildNodes)
                {
                    string path  = null;
                    string text  = null;
                    Image  image = null;
                    switch (xn.Name)
                    {
                    case "File":
                        path  = ShellList.MENUPATH_FILE;
                        text  = AppString.SideBar.File;
                        image = AppImage.File;
                        break;

                    case "Folder":
                        path  = ShellList.MENUPATH_FOLDER;
                        text  = AppString.SideBar.Folder;
                        image = AppImage.Folder;
                        break;

                    case "Directory":
                        path  = ShellList.MENUPATH_FOLDER;
                        text  = AppString.SideBar.Directory;
                        image = AppImage.Directory;
                        break;

                    case "Background":
                        path  = ShellList.MENUPATH_BACKGROUND;
                        text  = AppString.SideBar.Background;
                        image = AppImage.Background;
                        break;

                    case "Desktop":
                        path = ShellList.MENUPATH_DESKTOP;
                        //Vista没有桌面右键菜单的独立注册表项
                        if (WindowsOsVersion.IsEqualVista)
                        {
                            path = ShellList.MENUPATH_BACKGROUND;
                        }
                        text  = AppString.SideBar.Desktop;
                        image = AppImage.Desktop;
                        break;

                    case "Drive":
                        path  = ShellList.MENUPATH_DRIVE;
                        text  = AppString.SideBar.Drive;
                        image = AppImage.Drive;
                        break;

                    case "AllObjects":
                        path  = ShellList.MENUPATH_ALLOBJECTS;
                        text  = AppString.SideBar.AllObjects;
                        image = AppImage.AllObjects;
                        break;

                    case "Computer":
                        path  = ShellList.MENUPATH_COMPUTER;
                        text  = AppString.SideBar.Computer;
                        image = AppImage.Computer;
                        break;

                    case "RecycleBin":
                        path  = ShellList.MENUPATH_RECYCLEBIN;
                        text  = AppString.SideBar.RecycleBin;
                        image = AppImage.RecycleBin;
                        break;

                    default:
                        XmlElement xe = (XmlElement)xn;
                        path  = xe.GetAttribute("RegPath");
                        text  = ResourceString.GetDirectString(xe.GetAttribute("Text"));
                        image = ResourceIcon.GetIcon(xe.GetAttribute("Icon"))?.ToBitmap() ?? AppImage.NotFound;
                        break;
                    }
                    if (string.IsNullOrEmpty(path) || string.IsNullOrEmpty(text))
                    {
                        continue;
                    }
                    GroupPathItem groupItem = new GroupPathItem(path, ObjectPath.PathType.Registry)
                    {
                        Image = image,
                        Text  = text,
                    };
                    this.AddItem(groupItem);
                    XmlElement shellXE   = (XmlElement)xn.SelectSingleNode("Shell");
                    XmlElement shellExXE = (XmlElement)xn.SelectSingleNode("ShellEx");
                    if (shellXE != null)
                    {
                        LoadShellItems(shellXE, groupItem);
                    }
                    if (shellExXE != null)
                    {
                        LoadShellExItems(shellExXE, groupItem);
                    }
                    groupItem.IsFold = true;
                }
            }
            catch { }
        }