Пример #1
0
 internal void AddUserShortcutsDef(ShortcutFileInfo shortcutFileInfo)
 {
     // Remove any item with the same display name
     if (HasUserShortcuts(shortcutFileInfo.DisplayName))
     {
         DeleteUserShortcutsDef(shortcutFileInfo.DisplayName);
     }
     UserShortcutsRegistry.Add(shortcutFileInfo);
     UpdateShortcutsDefInSettingsStore(shortcutFileInfo);
 }
        public bool ScanForMappingSchemes()
        {
            List <ShortcutFileInfo> vskCopyList = new List <ShortcutFileInfo>();
            // Scan All-Users and local-user extension directories for VSK files
            List <string> vskFilesInExtDirs = GetFilesFromFolder(AllUsersExtensionsPath, "*.vsk");

            vskFilesInExtDirs.AddRange(GetFilesFromFolder(LocalUserExtensionsPath, "*.vsk"));

            List <ShortcutFileInfo> vskImportsRegistry = userShortcutsManager.GetVskImportsRegistry();

            // Check each VSK against VSK registry to see if it's new or updated.
            foreach (string vskFilePath in vskFilesInExtDirs)
            {
                FileInfo fileInfo = new FileInfo(vskFilePath);

                // Check existing VSK registry
                ShortcutFileInfo vskMappingInfo = vskImportsRegistry.FirstOrDefault(x => x.Filepath.Equals(vskFilePath));
                if (vskMappingInfo != null)
                {
                    // Compare date/time to existing datetime of VSK. If dates same, skip.
                    if (vskMappingInfo.LastWriteTimeEquals(fileInfo.LastWriteTime))
                    {
                        // This entry is already registered and has not changed.
                        continue;
                    }
                    else
                    {
                        // This entry has been updated.
                        // Update the LastWriteTime
                        vskMappingInfo.LastWriteTime = fileInfo.LastWriteTime;
                        // Update the Registry
                        userShortcutsManager.UpdateVskImportInfoInSettingsStore(vskMappingInfo);
                    }
                }
                else
                {
                    // Create new VskImports entry
                    vskMappingInfo = new ShortcutFileInfo(vskFilePath);
                    // Add it to the registry
                    userShortcutsManager.AddVskImportFile(vskMappingInfo);
                }
                // Add to VSK copy list (consider name)
                vskCopyList.Add(vskMappingInfo);
            }

            // Copy VSK files if VSKCopyList is not empty
            if (vskCopyList.Count > 0)
            {
                MessageBox.Show($"There are {vskCopyList.Count} new VSKs to copy.");
                ConfirmAndCopyVSKs(vskCopyList);
            }

            return(vskCopyList.Count > 0);
        }
Пример #3
0
        private void SaveShortcutFileInfoToSettingsStore(string collectionPrefix, ShortcutFileInfo shortcutFileInfo)
        {
            // Store values in UserSettingsStore. Use the "Name" property as the Collection key
            string collectionPath = $"{collectionPrefix}\\{shortcutFileInfo.DisplayName}";

            UserSettingsStore.CreateCollection(collectionPath);
            UserSettingsStore.SetString(collectionPath, NAME, shortcutFileInfo.DisplayName);
            UserSettingsStore.SetString(collectionPath, FILEPATH, shortcutFileInfo.Filepath);
            UserSettingsStore.SetString(collectionPath, EXTENSION_NAME, shortcutFileInfo.ExtensionName);
            UserSettingsStore.SetString(collectionPath, LAST_WRITE_TIME, shortcutFileInfo.LastWriteTime.ToString(ShortcutFileInfo.DATETIME_FORMAT));
            UserSettingsStore.SetInt32(collectionPath, FLAGS, shortcutFileInfo.NotifyFlag);
        }
Пример #4
0
        private void ExecuteUserShortcutsCommand(object sender, EventArgs args)
        {
            DynamicItemMenuCommand invokedCommand = (DynamicItemMenuCommand)sender;
            string           shortcutDefName      = invokedCommand.Text.Replace("&", "");// Remove the & (keyboard accelerator) from of the menu text
            ShortcutFileInfo userShortcutsDef     = userShortcutsManager.GetUserShortcutsInfo(shortcutDefName);
            string           importFilePath       = userShortcutsDef.Filepath;

            if (!File.Exists(importFilePath))
            {
                if (MessageBox.Show($"File does not exist: {importFilePath}\nRemove from shortcuts registry?", MSG_CAPTION_IMPORT, MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    userShortcutsManager.DeleteUserShortcutsDef(shortcutDefName);
                }
                return;
            }
            LoadKeyboardShortcutsFromVSSettingsFile(importFilePath);
        }
        /// <summary>
        /// Handler for the Load User Shortcuts menu items.
        /// </summary>
        private void ExecuteUserShortcutsCommand(object sender, EventArgs args)
        {
            // Get the name of shortcuts file from the invoked menu item (Dynamic menu - can't know at compile time)
            DynamicItemMenuCommand invokedCommand = (DynamicItemMenuCommand)sender;
            string shortcutDefName = invokedCommand.Text.Replace("&", "");  // Remove the & (keyboard accelerator) from the menu text

            // Lookup the cache of known keyoard import files and get the full filepath
            ShortcutFileInfo userShortcutsDef = userShortcutsManager.GetUserShortcutsInfo(shortcutDefName);
            string           importFilePath   = userShortcutsDef.Filepath;

            // If file is not available on the drive, abort and offer to remove it from the list.
            if (!File.Exists(importFilePath))
            {
                if (MessageBox.Show($"File does not exist: {importFilePath}\nRemove from shortcuts registry?", MSG_CAPTION_IMPORT, MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    userShortcutsManager.DeleteUserShortcutsDef(shortcutDefName);
                }
                return;
            }

            // Load the user shortcuts from the VSSettings file.
            var success = LoadKeyboardShortcutsFromVSSettingsFile(importFilePath);
        }
Пример #6
0
        private void AddUserShortcutsFileToRegistry(string importFilePath)
        {
            ShortcutFileInfo userShortcutsDef = new ShortcutFileInfo(importFilePath);

            userShortcutsManager.AddUserShortcutsDef(userShortcutsDef);
        }
        public bool ScanForNewShortcutsDefs()
        {
            // Process VSSettings files

            // Scan All-Users and local-user extension directories for VSSettings files
            List <string> vsSettingsFilesInExtDirs = GetFilesFromFolder(AllUsersExtensionsPath, "*.vssettings");

            vsSettingsFilesInExtDirs.AddRange(GetFilesFromFolder(LocalUserExtensionsPath, "*.vssettings"));

            List <ShortcutFileInfo> userShortcutsRegistry = userShortcutsManager.GetUserShortcutsRegistry();

            // For each VSSettings found, check VSSettings registry
            List <string> newVsSettings     = new List <string>();
            List <string> updatedVsSettings = new List <string>();

            foreach (string vsSettingsFile in vsSettingsFilesInExtDirs)
            {
                ShortcutFileInfo shortcutFileInfo = userShortcutsRegistry.Find(x => x.Filepath.Equals(vsSettingsFile));
                if (shortcutFileInfo == null)
                {
                    // - New VSSettings file
                    // Add to VSSettings registry (update: prompt)
                    shortcutFileInfo = new ShortcutFileInfo(vsSettingsFile);
                    // Add to NewVSSettingsList (to alert users)
                    newVsSettings.Add(vsSettingsFile);
                    // Update the VSSettingsRegsitry
                    userShortcutsManager.AddUserShortcutsDef(shortcutFileInfo);
                }
                else
                {
                    // We already know about this file. Check update flag.
                    if (shortcutFileInfo.NotifyFlag == UPDATE_NEVER)
                    {
                        continue;
                    }

                    FileInfo vsSettingsFileInfo = new FileInfo(vsSettingsFile);
                    if (shortcutFileInfo.LastWriteTimeEquals(vsSettingsFileInfo.LastWriteTime))
                    {
                        continue;
                    }
                    // This entry has been updated since it was added to the registry. Update the entry.
                    shortcutFileInfo.LastWriteTime = vsSettingsFileInfo.LastWriteTime;
                    // Add to UpdatedVSSettingsList (to alert users)
                    updatedVsSettings.Add(vsSettingsFile);
                    // Update the SettingsStore
                    userShortcutsManager.UpdateShortcutsDefInSettingsStore(shortcutFileInfo);
                }
            }

            // Alert user of new and updated shortcut defs
            if (newVsSettings.Count == 1)
            {
                // Prompt to load the new VSSettings
                if (MessageBox.Show($"One new user shortcut definition was found.\n\n{PrintList(newVsSettings)}\n\nWould you like to load these shortcuts now?", MSG_CAPTION_IMPORT, MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    // Load the settings
                    VSShortcutsManager.LoadKeyboardShortcutsFromVSSettingsFile(newVsSettings.First());
                }
            }
            else if (newVsSettings.Count > 1)
            {
                MessageBox.Show($"There were {newVsSettings.Count} new user shortcut files found.\n\n{PrintList(newVsSettings)}\n\nYou can load these shortcuts from Tools->Keyboard Shortcuts->Load Shortcuts");
            }
            // Updated settings files
            if (updatedVsSettings.Count > 0)
            {
                MessageBox.Show($"There were {updatedVsSettings.Count} updated user shortcut files found.\n\n{PrintList(updatedVsSettings)}\n\nYou might want to reapply these shortcuts.\nTool->Keyboard Shortcuts");
            }

            return(newVsSettings.Count > 0 || updatedVsSettings.Count > 0);
        }
Пример #8
0
 public void UpdateVskImportInfoInSettingsStore(ShortcutFileInfo shortcutFileInfo)
 {
     SaveShortcutFileInfoToSettingsStore(IMPORTED_MAPPING_SCHEMES, shortcutFileInfo);
 }
Пример #9
0
 internal void AddVskImportFile(ShortcutFileInfo shortcutFileInfo)
 {
     GetVskImportsRegistry().Add(shortcutFileInfo);
     UpdateVskImportInfoInSettingsStore(shortcutFileInfo);
 }
Пример #10
0
        public ShortcutFileInfo GetUserShortcutsInfo(string shortcutDefName)
        {
            ShortcutFileInfo userShortcutsDef = UserShortcutsRegistry.First(x => x.DisplayName.Equals(shortcutDefName));

            return(userShortcutsDef);
        }
Пример #11
0
 public void UpdateShortcutsDefInSettingsStore(ShortcutFileInfo userShortcutsDef)
 {
     SaveShortcutFileInfoToSettingsStore(USER_SHORTCUTS_DEFS, userShortcutsDef);
 }