Пример #1
0
        public void LoadShortcutsFromRegistry()
        {
            RegistryKey rootKey = RegistryHelper.OpenAppPaths();

            string [] keyNames = rootKey.GetSubKeyNames();

            foreach (string keyName in keyNames)
            {
                if (Regex.Match(keyName, @"\.exe$", RegexOptions.IgnoreCase).Success)
                {
                    RegistryKey key      = rootKey.OpenSubKey(keyName, true);
                    Shortcut    shortcut = null;

                    //figure out the shortcut type from the type key
                    ShortcutType type = (ShortcutType)Enum.Parse(typeof(ShortcutType), key.GetValue(Shortcut.TypeKeyName).ToString());

                    //create appropriate shortcut instance based on type
                    if (type == ShortcutType.Batch)
                    {
                        shortcut = new BatchShortcut(key);
                    }
                    else if (type == ShortcutType.File)
                    {
                        shortcut = new FileShortcut(key);
                    }
                    else if (type == ShortcutType.Folder)
                    {
                        shortcut = new FolderShortcut(key);
                    }
                    else if (type == ShortcutType.WebPage)
                    {
                        shortcut = new WebPageShortcut(key);
                    }
                    else if (type == ShortcutType.MSEdge)
                    {
                        shortcut = new MSEdgeShortcut(key);
                    }

                    this.Add(shortcut);
                }
            }

            rootKey.Close();
        }
Пример #2
0
        private void ChooseFileClicked(object sender, RoutedEventArgs e)
        {
            this.shortcut = (FolderShortcut)this.Shortcut;

            //use fancy Ookii vista browser dialog
            VistaFolderBrowserDialog dialog = new VistaFolderBrowserDialog();

            //set the starting path
            dialog.SelectedPath = this.shortcut.Path;

            //show the dialog
            bool?result = dialog.ShowDialog();

            //if a folder was selected
            if (result.HasValue && result.Value)
            {
                //set the shortcut's path to the selected folder path
                this.shortcut.Path = dialog.SelectedPath;
            }
        }