コード例 #1
0
ファイル: IeExtend.cs プロジェクト: zghnzch/RightMenus
        public new string BackUp(string str, bool isDelete = false)
        {
            string sourcePath = str;
            string backupPath = String.Empty;

            if (CanEdit(str))
            {
                if (str.Contains(MenusLib.BackUpName))
                {
                    backupPath = DelBackupName(str);
                }
                else
                {
                    backupPath = AddBackupName(str);;
                }
                if (isDelete)
                {
                    RegHelper.BackUpByBranch(sourcePath, backupPath, true);
                }
                else
                {
                    RegHelper.BackUpByBranch(sourcePath, backupPath);
                }
            }
            return(backupPath);
        }
コード例 #2
0
ファイル: New.cs プロジェクト: zghnzch/RightMenus
        public List <OneMenu> GetMenuList()
        {
            //读取缓存区域
            string sourcePath = @"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Discardable\PostSetup\ShellNew";

            string[]       sourceNameArr     = (string[])RegHelper.GetValueData(sourcePath, "Classes");
            List <OneMenu> sourceOneMenuList = new List <OneMenu>();

            foreach (string name in sourceNameArr)
            {
                string path         = "HKEY_CLASSES_ROOT" + @"\" + name;
                string shellNewPath = string.Empty;
                bool   keyExist     = RegHelper.ExistBranchName(path, "ShellNew", out shellNewPath);
                if (keyExist)
                {
                    OneMenu oneMenu = new OneMenu();
                    if (!path.Contains(MenusLib.BackUpName))
                    {
                        oneMenu.Checked = true;
                    }
                    oneMenu.RegPath = shellNewPath;
                    oneMenu.Name    = name;
                    sourceOneMenuList.Add(oneMenu);
                }
            }

            string sourcePath2 = "HKEY_CLASSES_ROOT" + @"\New" + MenusLib.BackUpName;

            string[] backupNameArr = RegHelper.GetBranchNames(sourcePath2);

            List <OneMenu> sourceOneMenuList2 = new List <OneMenu>();

            if (backupNameArr != null)
            {
                foreach (string name in backupNameArr)
                {
                    string path         = sourcePath2 + "\\" + name;
                    string shellNewPath = string.Empty;
                    bool   keyExist     = RegHelper.ExistBranchName(path, "ShellNew", out shellNewPath);

                    if (keyExist)
                    {
                        OneMenu oneMenu = new OneMenu();
                        oneMenu.RegPath = shellNewPath;
                        oneMenu.Name    = name;
                        sourceOneMenuList2.Add(oneMenu);
                    }
                }
            }

            List <OneMenu> oneMenuList = sourceOneMenuList.AddOneMenuList(sourceOneMenuList2);

            GetFilePath(oneMenuList);
            GetVersionInfo(oneMenuList);
            return(oneMenuList);
        }
コード例 #3
0
ファイル: RightMenus.cs プロジェクト: zghnzch/RightMenus
        private void ConMenuDel_Click(object sender, EventArgs e)
        {
            ListViewItem lv = GetListViewSelected();

            _regCopyPath = lv.ToolTipText;
            if (string.IsNullOrEmpty(_regCopyPath))
            {
                MessageBox.Show("请选择有效的节点!", "提示");
                return;
            }
            else
            {
                RegHelper.DeleteBranchName(_regCopyPath);
                Refresh();
            }
        }
コード例 #4
0
        public List <OneMenu> GetMenuList(string fileType)
        {
            if (string.IsNullOrEmpty(fileType))
            {
                return(null);
            }
            string type    = @"HKEY_CLASSES_ROOT\" + fileType;
            string regPath = RegHelper.GetValueData(type, "").ToString();

            string[] strArr = new[]
            {
                @"HKEY_CLASSES_ROOT\" + regPath + @"\shell",
                @"HKEY_CLASSES_ROOT\" + regPath + @"\shellex\ContextMenuHandlers"
            };
            List <OneMenu> oneMenuList = GetMenuList(strArr);

            return(oneMenuList);
        }
コード例 #5
0
ファイル: New.cs プロジェクト: zghnzch/RightMenus
        public new void GetFilePath(List <OneMenu> oneMenuList)
        {
            if (oneMenuList == null || oneMenuList.Count <= 0)
            {
                return;
            }
            foreach (OneMenu oneMenu in oneMenuList)
            {
                try
                {
                    string regPathTemp = oneMenu.RegPath;
                    if (regPathTemp.Contains(MenusLib.BackUpName))
                    {
                        regPathTemp = regPathTemp.Replace("\\New" + MenusLib.BackUpName, "");
                    }
                    string[] namePathArr = regPathTemp.Split('\\');
                    string   regPath     = namePathArr[0] + "\\" + namePathArr[1];
                    string   des         = RegHelper.GetValueData(regPath, "").ToString();
                    oneMenu.Description = des;
                    string rootSid     = RegHelper.GetValueData(regPath, "").ToString();
                    string rootPath    = @"HKEY_CLASSES_ROOT\" + rootSid + @"\shell\open\command";
                    bool   existBranch = RegHelper.ExistBranchName(rootPath);
                    if (existBranch)
                    {
                        string filePath = RegHelper.GetValueData(rootPath, "").ToString();
                        oneMenu.FilePath = filePath;
                    }
                    else
                    {
                    }


                    string defaultIcon     = @"HKEY_CLASSES_ROOT\" + rootSid + @"\DefaultIcon";
                    string defaultIconPath = RegHelper.GetValueData(defaultIcon, "").ToString();
                    oneMenu.DefaultIcon = defaultIconPath;
                }
                catch (Exception)
                {
                }
            }
        }
コード例 #6
0
ファイル: MenusLib.cs プロジェクト: zghnzch/RightMenus
        public static List <OneMenu> GetMenuList(string path)
        {
            string[] nameArr = RegHelper.GetBranchNames(path);
            if (nameArr == null)
            {
                return(null);
            }
            List <OneMenu> oneMenuList = new List <OneMenu>();

            foreach (string name in nameArr)
            {
                OneMenu oneMenu = new OneMenu();
                if (!path.Contains(MenusLib.BackUpName))
                {
                    oneMenu.Checked = true;
                }
                oneMenu.RegPath = path + "\\" + name;
                oneMenu.Name    = name;
                oneMenuList.Add(oneMenu);
            }
            return(oneMenuList);
        }
コード例 #7
0
        public new string CopyBranch(string sourceBranch)
        {
            string shellPath   = @"HKEY_CLASSES_ROOT\txtfile\shell";
            string shellExPath = @"HKEY_CLASSES_ROOT\txtfile\shellex\ContextMenuHandlers";

            string[]      strArr = sourceBranch.Split('\\');
            StringBuilder sb     = new StringBuilder();
            string        result = string.Empty;

            for (int i = 0; i < strArr.Length; i++)
            {
                if (strArr[i].ToLower() == "shell".ToLower())
                {
                    for (int j = i + 1; j < strArr.Length; j++)
                    {
                        sb.Append("\\" + strArr[j]);
                    }
                    result = shellPath + sb.ToString();
                }
            }

            for (int i = 0; i < strArr.Length; i++)
            {
                if (strArr[i].ToLower() == "ContextMenuHandlers".ToLower())
                {
                    for (int j = i + 1; j < strArr.Length; j++)
                    {
                        sb.Append("\\" + strArr[j]);
                    }
                }
                result = shellExPath + sb.ToString();
            }
            if (!string.IsNullOrEmpty(result))
            {
                RegHelper.BackUpByBranch(sourceBranch, result);
            }
            return(result);
        }
コード例 #8
0
ファイル: RightMenus.cs プロジェクト: zghnzch/RightMenus
        /// <summary>
        ///
        /// </summary>
        /// <param name="source">要备份的注册表路径</param>
        /// <param name="isBackUp">false是获取扩展项,true是进行备份,默认是false</param>
        private void BackUp(string source, bool isBackUp = false, bool isCopy = false)
        {
            switch (_typeStr)
            {
            //case "IeExtend":RegEdit.InternetExplorer.IeExtend.Name
            case "IeExtend":
                IeExtend ieExtend = new IeExtend();
                if (isCopy && !string.IsNullOrEmpty(_regCopyPath))
                {
                    string result = ieExtend.CopyBranch(source);
                    if (string.IsNullOrEmpty(result))
                    {
                        MessageBox.Show("修改失败!");
                    }
                }
                if (isBackUp)
                {
                    _regPath = ieExtend.BackUp(source, true);
                    listV.Items[_listIndex].ToolTipText = _regPath;
                }
                else
                {
                    _winOneMenuList = ieExtend.GetMenuList();
                }
                break;

            case "Computer":
                Computer computer = new Computer();
                if (isBackUp)
                {
                    _regPath = computer.BackUp(source, true);
                    if (string.IsNullOrEmpty(_regPath))
                    {
                        MessageBox.Show("修改失败!");
                    }
                    listV.Items[_listIndex].ToolTipText = _regPath;
                }
                else
                {
                    _winOneMenuList = computer.GetMenuList();
                }
                break;

            case "LocalDisk":
                LocalDisk localDisk = new LocalDisk();
                if (isBackUp)
                {
                    _regPath = localDisk.BackUp(source, true);
                    listV.Items[_listIndex].ToolTipText = _regPath;
                }
                else
                {
                    _winOneMenuList = localDisk.GetMenuList();
                }
                break;

            case "AllFiles":
                AllFiles allFiles = new AllFiles();
                if (isBackUp)
                {
                    _regPath = allFiles.BackUp(source, true);
                    listV.Items[_listIndex].ToolTipText = _regPath;
                }
                else
                {
                    _winOneMenuList = allFiles.GetMenuList();
                }
                break;

            case "Contents":
                Contents contents = new Contents();
                if (isBackUp)
                {
                    _regPath = contents.BackUp(source, true);
                    listV.Items[_listIndex].ToolTipText = _regPath;
                }
                else
                {
                    _winOneMenuList = contents.GetMenuList();
                }
                break;

            case "Desktop":
                Desktop desktop = new Desktop();
                if (isBackUp)
                {
                    _regPath = desktop.BackUp(source, true);
                    listV.Items[_listIndex].ToolTipText = _regPath;
                }
                else
                {
                    _winOneMenuList = desktop.GetMenuList();
                }
                break;

            case "RecycleBin":
                RecycleBin recycleBin = new RecycleBin();
                if (isBackUp)
                {
                    _regPath = recycleBin.BackUp(source, true);
                    if (string.IsNullOrEmpty(_regPath))
                    {
                        MessageBox.Show("修改失败!");
                    }
                    listV.Items[_listIndex].ToolTipText = _regPath;
                }
                else
                {
                    _winOneMenuList = recycleBin.GetMenuList();
                }
                break;

            case "SendTo":
                SendTo SendTo = new SendTo();
                if (isBackUp)
                {
                    _regPath = SendTo.BackUp(source, true);
                    if (string.IsNullOrEmpty(_regPath))
                    {
                        MessageBox.Show("修改失败!");
                    }
                    listV.Items[_listIndex].ToolTipText = _regPath;
                }
                else
                {
                    _winOneMenuList = SendTo.GetMenuList();
                }
                break;

            case "Others":
                Others others = new Others();
                if (isBackUp)
                {
                    _regPath = others.BackUp(source, true);
                    if (string.IsNullOrEmpty(_regPath))
                    {
                        MessageBox.Show("修改失败!");
                    }
                    listV.Items[_listIndex].ToolTipText = _regPath;
                }
                else
                {
                    _winOneMenuList = others.GetMenuList();
                }
                break;

            case "Folders":
                Folders folders = new Folders();
                if (isBackUp)
                {
                    _regPath = folders.BackUp(source, true);
                    listV.Items[_listIndex].ToolTipText = _regPath;
                }
                else
                {
                    _winOneMenuList = folders.GetMenuList();
                }
                break;

            case "New":
                New _new = new New();
                if (isBackUp)
                {
                    _regPath = _new.BackUp(source, true);
                    listV.Items[_listIndex].ToolTipText = _regPath;
                }
                else
                {
                    _winOneMenuList = _new.GetMenuList();
                }
                break;

            case "LnkFile":
                LnkFile lnkFile = new LnkFile();
                if (isBackUp)
                {
                    _regPath = lnkFile.BackUp(source, true);
                    listV.Items[_listIndex].ToolTipText = _regPath;
                }
                else
                {
                    _winOneMenuList = lnkFile.GetMenuList();
                }
                break;

            case "TxtType":
                TxtType txtType = new TxtType();
                if (isCopy && !string.IsNullOrEmpty(_regCopyPath))
                {
                    string result = txtType.CopyBranch(source);
                    if (string.IsNullOrEmpty(result))
                    {
                        MessageBox.Show("复制失败!");
                    }
                    _winOneMenuList = txtType.GetMenuList();
                    break;
                }
                if (isBackUp)
                {
                    _regPath = txtType.BackUp(source, true);
                    listV.Items[_listIndex].ToolTipText = _regPath;
                }
                else
                {
                    _winOneMenuList = txtType.GetMenuList();
                }
                break;

            case "ExeType":
                ExeType exeType = new ExeType();
                if (isBackUp)
                {
                    _regPath = exeType.BackUp(source, true);
                    listV.Items[_listIndex].ToolTipText = _regPath;
                }
                else
                {
                    _winOneMenuList = exeType.GetMenuList();
                }
                break;

            case "FileType":
                string typeName = string.Empty;
                foreach (XmlNode item in _xml)
                {
                    string typeText = item.Attributes["Text"].Value;
                    if (typeText == _fileNameStr)
                    {
                        typeName = item.Attributes["Name"].Value;
                    }
                }

                FileType fileType = new FileType();
                if (isCopy && !string.IsNullOrEmpty(_regCopyPath))
                {
                    string openWithExe = RegHelper.GetValueData(@"HKEY_CLASSES_ROOT\" + typeName, "").ToString();
                    string result      = fileType.CopyBranch(source, openWithExe);
                    if (string.IsNullOrEmpty(result))
                    {
                        MessageBox.Show("复制失败!");
                    }
                    _winOneMenuList = fileType.GetMenuList(typeName);
                    break;
                }
                if (isBackUp)
                {
                    _regPath = fileType.BackUp(source, true);
                    listV.Items[_listIndex].ToolTipText = _regPath;
                }
                else
                {
                    if (!string.IsNullOrEmpty(typeName))
                    {
                        _winOneMenuList = fileType.GetMenuList(typeName);
                    }
                }
                break;

            default:

                _winOneMenuList = null;
                break;
            }
        }
コード例 #9
0
        public new void GetFilePath(List <OneMenu> oneMenuList)
        {
            if (oneMenuList == null || oneMenuList.Count <= 0)
            {
                return;
            }
            foreach (OneMenu oneMenu in oneMenuList)
            {
                string   regPath   = oneMenu.RegPath;
                string[] branchArr = RegHelper.GetBranchNames(regPath);

                if (branchArr.Length > 0)
                {
                    foreach (string branch in branchArr)
                    {
                        if (branch.ToLower() == "command".ToLower())
                        {
                            string   valuePath    = regPath + @"\command";
                            string[] valueNameArr = RegHelper.GetValueNames(valuePath);
                            foreach (string value in valueNameArr)
                            {
                                if (value.ToLower() == "DelegateExecute".ToLower())
                                {
                                    string cLSID = RegHelper.GetValueData(valuePath, "DelegateExecute").ToString();
                                    string path  = @"HKEY_CLASSES_ROOT\CLSID\" + cLSID + @"\InProcServer32";
                                    bool   b     = RegHelper.ExistBranchName(path);
                                    if (!b)
                                    {
                                        path = @"HKEY_CLASSES_ROOT\Wow6432Node\CLSID\" + cLSID + @"\InProcServer32";
                                    }
                                    string s = RegHelper.GetValueData(path, "").ToString();
                                    oneMenu.FilePath = s;

                                    string   desPath       = path.Replace(@"\InProcServer32", "");
                                    string[] valueNamesArr = RegHelper.GetValueNames(desPath);
                                    foreach (string valueName in valueNamesArr)
                                    {
                                        if (valueName == string.Empty)
                                        {
                                            oneMenu.Description = RegHelper.GetValueData(desPath, "").ToString();
                                        }
                                    }
                                }
                                if (value == string.Empty)
                                {
                                    string s = RegHelper.GetValueData(valuePath, "").ToString();
                                    oneMenu.FilePath = s;
                                    break;
                                }
                            }
                        }
                    }
                }
                else
                {
                    string cLSID = RegHelper.GetValueData(regPath, "").ToString();
                    string path  = @"HKEY_CLASSES_ROOT\CLSID\" + cLSID + @"\InProcServer32";
                    bool   b     = RegHelper.ExistBranchName(path);
                    if (!b)
                    {
                        path = @"HKEY_CLASSES_ROOT\Wow6432Node\CLSID\" + cLSID + @"\InProcServer32";
                    }
                    string s = RegHelper.GetValueData(path, "").ToString();
                    oneMenu.FilePath = s;

                    string   desPath       = path.Replace(@"\InProcServer32", "");
                    string[] valueNamesArr = RegHelper.GetValueNames(desPath);
                    foreach (string valueName in valueNamesArr)
                    {
                        if (valueName == string.Empty)
                        {
                            oneMenu.Description = RegHelper.GetValueData(desPath, "").ToString();
                        }
                    }
                }
            }
        }
コード例 #10
0
 /// <summary>
 /// 删除项
 /// </summary>
 /// <param name="sourceName">删除项的完全路径</param>
 public void DelBranch(string sourceName)
 {
     RegHelper.DeleteBranchName(sourceName);
 }