예제 #1
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);
        }
예제 #2
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);
        }
예제 #3
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)
                {
                }
            }
        }
예제 #4
0
        /// <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;
            }
        }
예제 #5
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();
                        }
                    }
                }
            }
        }