Beispiel #1
0
        private List <string> GetDrives()
        {
            var driveList = new List <string>();

            DriveInfo[] drives = DriveInfo.GetDrives();
            foreach (var drive in drives)
            {
                // TODO: 当isReady改变的时候,应该重新初始化一次
                if (!drive.IsReady)
                {
                    continue;
                }
                string caption = drive.Name;
                if (drive.VolumeLabel.Trim() != "")
                {
                    caption += " (" + drive.VolumeLabel + ")";
                }
                string directory = drive.RootDirectory.Name;
                driveList.Add(caption);
                if (!m_driveInited)
                {
                    CommonShortcuts.Add(caption);
                    CommonShortcutsPath.Add(caption, directory);
                    m_driveInited = true;
                }
            }

            return(driveList);
        }
Beispiel #2
0
        private void FillSysEnvPATHShortcutsInfo()
        {
            var envPaths = Environment.GetEnvironmentVariable("path").Split(';');

            foreach (var p in envPaths)
            {
                try
                {
                    foreach (var fullpath in Directory.GetFiles(p, "*.exe"))
                    {
                        if (!CommonShortcuts.Contains(fullpath))
                        {
                            string filename = Path.GetFileNameWithoutExtension(fullpath).ToLower();
                            if (!CommonShortcutsPath.ContainsValue(fullpath))
                            {
                                CommonShortcuts.Add(filename);
                                CommonShortcutsPath.Add(filename, fullpath);
                            }
                        }
                    }
                }
                catch { }
            }
        }
Beispiel #3
0
        private void FillAllProgramInfo()
        {
            string path = Environment.GetFolderPath(Environment.SpecialFolder.CommonPrograms);

            string[] allPrograms = Directory.GetFiles(path, "*.lnk", SearchOption.AllDirectories);
            foreach (var link in allPrograms)
            {
                WshShell     shell      = new WshShell();
                IWshShortcut sc         = (IWshShortcut)shell.CreateShortcut(link);
                string       targetPath = sc.TargetPath;
                if (Path.GetExtension(targetPath).ToLower() == ".exe")
                {
                    string filename = Path.GetFileNameWithoutExtension(link).ToLower();
                    if (!CommonShortcuts.Contains(filename))
                    {
                        CommonShortcuts.Add(filename);
                    }
                    if (!CommonShortcutsPath.ContainsKey(filename))
                    {
                        CommonShortcutsPath.Add(filename, link);
                    }
                }
            }
        }
Beispiel #4
0
        private void FillCommonShortcutsInfo(RegistryKey key)
        {
            var names = key.GetSubKeyNames();

            foreach (var name in names)
            {
                var subkey   = key.OpenSubKey(name);
                var value    = subkey.GetValue("");
                var fullpath = value == null ? "" : value.ToString();
                if (fullpath.Trim() == "")
                {
                    continue;
                }

                // 只加载有效项
                try
                {
                    fullpath = Path.GetFullPath(fullpath.Replace("\"", ""));
                }
                catch
                {
                    continue;
                }
                if (!System.IO.File.Exists(fullpath) || Path.GetExtension(fullpath).ToLower() != ".exe")
                {
                    continue;
                }

                CommonShortcuts.Add(name);
                string pathKey = RemoveExeExtension(name);
                if (!CommonShortcutsPath.ContainsKey(pathKey.ToLower()))
                {
                    CommonShortcutsPath.Add(pathKey.ToLower(), fullpath);
                }
            }
        }