Exemplo n.º 1
0
        public void Edit(ShortcutDetails edit)
        {
            var shortcuts = JsonParser.DeserializeFromJson <ShortcutContainer>(Properties.Resources.ShortcutInformationFile);
            var index     = shortcuts.ShortcutInformation.FindIndex(x => x.ShortcutId == edit.ShortcutId);

            if (index >= 0)
            {
                shortcuts.ShortcutInformation[index] = edit;
            }
            JsonParser.SerializeToJson(shortcuts, Properties.Resources.ShortcutInformationFile);
        }
Exemplo n.º 2
0
        public void Add(ShortcutDetails create)
        {
            ShortcutContainer shortcuts = null;

            if (File.Exists(Properties.Resources.ShortcutInformationFile))
            {
                shortcuts = JsonParser.DeserializeFromJson <ShortcutContainer>(Properties.Resources.ShortcutInformationFile);
            }
            else
            {
                shortcuts = new ShortcutContainer();
            }

            shortcuts.ShortcutInformation.Add(create);
            JsonParser.SerializeToJson(shortcuts, Properties.Resources.ShortcutInformationFile);
        }
Exemplo n.º 3
0
        //Handle file picker left click
        async Task Listbox_FilePicker_LeftClick()
        {
            try
            {
                if (lb_FilePicker.SelectedItems.Count > 0 && lb_FilePicker.SelectedIndex != -1)
                {
                    DataBindFile SelectedItem = (DataBindFile)lb_FilePicker.SelectedItem;
                    if (SelectedItem.FileType == FileType.Folder || SelectedItem.FileType == FileType.FolderDisc || SelectedItem.FileType == FileType.FolderPre)
                    {
                        await Popup_Show_FilePicker(SelectedItem.PathFile, -1, true, null);
                    }
                    else if (SelectedItem.FileType == FileType.GoUpPre)
                    {
                        await FilePicker_GoFolderUp();
                    }
                    else if (SelectedItem.FileType == FileType.Link)
                    {
                        ShortcutDetails shortcutDetails = ReadShortcutFile(SelectedItem.PathFile);
                        if (Directory.Exists(shortcutDetails.TargetPath))
                        {
                            await Popup_Show_FilePicker(shortcutDetails.TargetPath, -1, true, null);
                        }
                        else if (File.Exists(shortcutDetails.TargetPath))
                        {
                            await Popup_Close_FilePicker(true, false);
                        }
                        else
                        {
                            await Notification_Send_Status("Close", "Link target does not exist");

                            Debug.WriteLine("Link target does not exist");
                        }
                    }
                    else
                    {
                        await Popup_Close_FilePicker(true, false);
                    }
                }
            }
            catch { }
        }
            public CommandBarActionDef(VsShortcutFinder vsShortcutFinder, DTE dte, string actionId,
                                       CommandID commandId, CommandBarControl control,
                                       CommandBarPopup[] parentPopups)
            {
                ActionId = actionId;

                // Lazily initialise. Talking to the command bar objects is SLOOOOOOOWWWWWW.
                backingFields = Lazy.Of(() =>
                {
                    Assertion.AssertNotNull(control, "control != null");

                    var sb = new StringBuilder();
                    foreach (var popup in parentPopups)
                    {
                        sb.AppendFormat("{0} \u2192 ", popup.Caption);
                    }

                    var fields = new BackingFields
                    {
                        Text = MnemonicStore.RemoveMnemonicMark(control.Caption),
                        Path = MnemonicStore.RemoveMnemonicMark(sb.ToString())
                    };

                    var command    = VsCommandHelpers.TryGetVsCommandAutomationObject(commandId, dte);
                    var vsShortcut = vsShortcutFinder.GetVsShortcut(command);
                    if (vsShortcut != null)
                    {
                        var details = new ShortcutDetails[vsShortcut.KeyboardShortcuts.Length];
                        for (int i = 0; i < vsShortcut.KeyboardShortcuts.Length; i++)
                        {
                            var keyboardShortcut = vsShortcut.KeyboardShortcuts[i];
                            details[i]           = new ShortcutDetails(KeyConverter.Convert(keyboardShortcut.Key),
                                                                       keyboardShortcut.Modifiers);
                        }
                        fields.VsShortcut = new ShortcutSequence(details);
                    }

                    return(fields);
                }, true);
            }
Exemplo n.º 5
0
        //Get details from a shortcut file
        ShortcutDetails ReadShortcutFile(string shortcutPath)
        {
            ShortcutDetails shortcutDetails = new ShortcutDetails();

            try
            {
                Thread thread = new Thread(delegate()
                {
                    try
                    {
                        string folderString   = Path.GetDirectoryName(shortcutPath);
                        string filenameString = Path.GetFileName(shortcutPath);
                        //Debug.WriteLine("Reading shortcut: " + shortcutPath);

                        Shell shell                     = new Shell();
                        Folder folder                   = shell.NameSpace(folderString);
                        FolderItem folderItem           = folder.ParseName(filenameString);
                        ShellLinkObject shellLinkObject = folderItem.GetLink;

                        int iconIndex   = 0;
                        string iconPath = string.Empty;
                        try
                        {
                            iconIndex = shellLinkObject.GetIconLocation(out iconPath);
                            iconPath  = iconPath.Replace("file:///", string.Empty);
                            iconPath  = WebUtility.UrlDecode(iconPath);
                        }
                        catch { }

                        string argumentString = string.Empty;
                        try
                        {
                            argumentString = shellLinkObject.Arguments;
                        }
                        catch { }

                        //Expand environment variables
                        string targetPath  = Environment.ExpandEnvironmentVariables(shellLinkObject.Target.Path);
                        string workingPath = Environment.ExpandEnvironmentVariables(shellLinkObject.WorkingDirectory);
                        iconPath           = Environment.ExpandEnvironmentVariables(iconPath);
                        shortcutPath       = Environment.ExpandEnvironmentVariables(shortcutPath);

                        //Set shortcut details
                        shortcutDetails.Title        = StripShortcutFilename(Path.GetFileNameWithoutExtension(shortcutPath));
                        shortcutDetails.TargetPath   = targetPath;
                        shortcutDetails.WorkingPath  = workingPath;
                        shortcutDetails.NameExe      = Path.GetFileName(shortcutDetails.TargetPath);
                        shortcutDetails.IconIndex    = iconIndex;
                        shortcutDetails.IconPath     = iconPath;
                        shortcutDetails.ShortcutPath = shortcutPath;
                        shortcutDetails.Type         = folderItem.Type;
                        shortcutDetails.Argument     = argumentString;
                        shortcutDetails.Comment      = shellLinkObject.Description;
                        shortcutDetails.TimeModify   = folderItem.ModifyDate;
                    }
                    catch { }
                });

                thread.SetApartmentState(ApartmentState.STA);
                thread.Start();
                thread.Join();
            }
            catch { }
            return(shortcutDetails);
        }
Exemplo n.º 6
0
        //Add shortcut to the shortcuts list
        async Task ShortcutAddToListWithDetails(ShortcutDetails shortcutDetails)
        {
            try
            {
                //Check if the shortcut name is set
                if (string.IsNullOrWhiteSpace(shortcutDetails.Title))
                {
                    Debug.WriteLine("Shortcut name is not set, skipping shortcut.");
                    return;
                }

                //Get the shortcut target file name
                string      targetPathLower      = shortcutDetails.TargetPath.ToLower();
                string      targetExtensionLower = Path.GetExtension(targetPathLower).Replace(".", string.Empty);
                Visibility  shortcutUrlProtocol  = Visibility.Collapsed;
                Visibility  shortcutWindowStore  = Visibility.Collapsed;
                Visibility  shortcutAvailable    = Visibility.Collapsed;
                ProcessType shortcutProcessType  = ProcessType.Win32;
                BitmapImage launcherImage        = null;

                //Check if executable or UrlProtocol app shortcut
                if (targetPathLower.EndsWith(".exe"))
                {
                    //Check if the executable still exists
                    if (!File.Exists(targetPathLower))
                    {
                        shortcutAvailable = Visibility.Visible;
                    }
                }
                else if (targetPathLower.EndsWith(".bat"))
                {
                    //Check if the bat file still exists
                    if (!File.Exists(targetPathLower))
                    {
                        shortcutAvailable = Visibility.Visible;
                    }
                    else
                    {
                        shortcutUrlProtocol = Visibility.Visible;
                    }
                }
                else if (targetPathLower.Contains("://"))
                {
                    //Check if shortcut is url protocol
                    shortcutUrlProtocol = Visibility.Visible;

                    //Check if url protocol is a launcher and set icon
                    if (targetPathLower.Contains("steam://"))
                    {
                        launcherImage = vImagePreloadSteam;
                    }
                    else if (targetPathLower.Contains("com.epicgames.launcher://"))
                    {
                        launcherImage = vImagePreloadEpic;
                    }
                    else if (targetPathLower.Contains("uplay://"))
                    {
                        launcherImage = vImagePreloadUbisoft;
                    }
                    else if (targetPathLower.Contains("battlenet://"))
                    {
                        launcherImage = vImagePreloadBattleNet;
                    }
                    else if (targetPathLower.Contains("bethesdanet://"))
                    {
                        launcherImage = vImagePreloadBethesda;
                    }
                    else if (targetPathLower.Contains("origin://"))
                    {
                        launcherImage = vImagePreloadEADesktop;
                    }
                    else if (targetPathLower.Contains("link2ea://"))
                    {
                        launcherImage = vImagePreloadEADesktop;
                    }
                    else if (targetPathLower.Contains("amazon-games://"))
                    {
                        launcherImage = vImagePreloadAmazon;
                    }
                }
                else if (!targetPathLower.Contains("/") && targetPathLower.Contains("!") && targetPathLower.Contains("_"))
                {
                    //Check if shortcut is windows store app
                    shortcutProcessType = ProcessType.UWP;
                    shortcutWindowStore = Visibility.Visible;

                    //Get basic application information
                    Package appPackage = UwpGetAppPackageByAppUserModelId(shortcutDetails.TargetPath);

                    //Check if the app still exists
                    if (appPackage == null)
                    {
                        shortcutAvailable = Visibility.Visible;
                    }
                    else
                    {
                        //Get detailed application information
                        AppxDetails appxDetails = UwpGetAppxDetailsFromAppPackage(appPackage);

                        //Set the application icon path
                        shortcutDetails.IconPath = appxDetails.SquareLargestLogoPath;

                        //Set the applicaton exe name
                        shortcutDetails.NameExe = appxDetails.ExecutableName;
                    }
                }
                else
                {
                    //Debug.WriteLine("Unknown shortcut: " + TargetPathLower);
                    return;
                }

                //Get icon image from the path
                BitmapImage iconBitmapImage = null;
                if (shortcutAvailable == Visibility.Visible)
                {
                    iconBitmapImage = FileToBitmapImage(new string[] { "Unknown" }, vImageSourceFolders, vImageBackupSource, IntPtr.Zero, 90, 0);
                }
                else
                {
                    iconBitmapImage = FileToBitmapImage(new string[] { shortcutDetails.Title, shortcutDetails.IconPath, targetPathLower, "Assets/Default/Extensions/" + targetExtensionLower + ".png" }, vImageSourceFolders, vImageBackupSource, IntPtr.Zero, 90, shortcutDetails.IconIndex);
                }

                //Add the shortcut to the list
                DataBindApp dataBindApp = new DataBindApp()
                {
                    Type = shortcutProcessType, Category = AppCategory.Shortcut, Name = shortcutDetails.Title, NameExe = shortcutDetails.NameExe, ImageBitmap = iconBitmapImage, PathExe = shortcutDetails.TargetPath, PathLaunch = shortcutDetails.WorkingPath, ShortcutPath = shortcutDetails.ShortcutPath, Argument = shortcutDetails.Argument, StatusStore = shortcutWindowStore, StatusUrlProtocol = shortcutUrlProtocol, StatusLauncher = launcherImage, TimeCreation = shortcutDetails.TimeModify, StatusAvailable = shortcutAvailable
                };
                await ListBoxAddItem(lb_Shortcuts, List_Shortcuts, dataBindApp, false, false);
            }
            catch
            {
                //Debug.WriteLine("Failed to add shortcut to list: " + shortcutDetails.ShortcutPath);
            }
        }
Exemplo n.º 7
0
        //Get all the shortcuts and update the list
        async Task RefreshListShortcuts(bool showStatus)
        {
            try
            {
                //Check if shortcuts need to be updated
                if (!Convert.ToBoolean(Setting_Load(vConfigurationCtrlUI, "ShowOtherShortcuts")))
                {
                    //Debug.WriteLine("Shortcuts don't need to be updated, cancelling.");
                    return;
                }

                //Check if already refreshing
                if (vBusyRefreshingShortcuts)
                {
                    Debug.WriteLine("Shortcuts are already refreshing, cancelling.");
                    return;
                }

                //Update the refreshing status
                vBusyRefreshingShortcuts = true;

                //Show the loading gif
                AVActions.ActionDispatcherInvoke(delegate
                {
                    gif_Shortcuts_Loading.Show();
                });

                //Show refresh status message
                if (showStatus)
                {
                    await Notification_Send_Status("Refresh", "Refreshing shortcuts");
                }

                //Get all files from the shortcut directories
                IEnumerable <FileInfo> directoryShortcuts = Enumerable.Empty <FileInfo>();
                foreach (ProfileShared shortcutFolder in vCtrlLocationsShortcut)
                {
                    try
                    {
                        string editedShortcutFolder = shortcutFolder.String1;
                        editedShortcutFolder = editedShortcutFolder.Replace("%DESKTOPUSER%", Environment.GetFolderPath(Environment.SpecialFolder.Desktop));
                        editedShortcutFolder = editedShortcutFolder.Replace("%DESKTOPPUBLIC%", Environment.GetFolderPath(Environment.SpecialFolder.CommonDesktopDirectory));
                        if (Directory.Exists(editedShortcutFolder))
                        {
                            DirectoryInfo          directoryInfo   = new DirectoryInfo(editedShortcutFolder);
                            IEnumerable <FileInfo> filterShortcuts = directoryInfo.GetFiles("*", SearchOption.TopDirectoryOnly).Where(x => x.Name.ToLower().EndsWith(".url") || x.Name.ToLower().EndsWith(".lnk"));
                            directoryShortcuts = directoryShortcuts.Concat(filterShortcuts);
                        }
                    }
                    catch { }
                }

                //Sort and filter the list by shortcut name
                directoryShortcuts = directoryShortcuts.OrderBy(x => x.Name);

                //Remove shortcuts that are no longer available from the list
                Func <DataBindApp, bool> filterShortcutApp = x => x.Category == AppCategory.Shortcut && !directoryShortcuts.Any(y => StripShortcutFilename(y.Name) == x.Name);
                await ListBoxRemoveAll(lb_Shortcuts, List_Shortcuts, filterShortcutApp);
                await ListBoxRemoveAll(lb_Search, List_Search, filterShortcutApp);

                //Get shortcut information and add it to the list
                foreach (FileInfo file in directoryShortcuts)
                {
                    try
                    {
                        //Read shortcut file information
                        ShortcutDetails shortcutDetails     = ReadShortcutFile(file.FullName);
                        string          targetTitleLower    = shortcutDetails.Title.ToLower();
                        string          targetPathLower     = shortcutDetails.TargetPath.ToLower();
                        string          targetArgumentLower = shortcutDetails.Argument.ToLower();

                        //Check if already in combined list and remove it
                        if (CombineAppLists(false, false, true).Any(x => x.Name.ToLower() == targetTitleLower || x.PathExe.ToLower() == targetPathLower))
                        {
                            //Debug.WriteLine("Shortcut is in the combined list skipping: " + fileNameStripped.ToLower());
                            await ListBoxRemoveAll(lb_Shortcuts, List_Shortcuts, x => x.PathExe.ToLower() == targetPathLower);

                            continue;
                        }

                        //Check if shortcut name is in shortcut blacklist
                        if (vCtrlIgnoreShortcutName.Any(x => x.String1.ToLower() == targetTitleLower))
                        {
                            //Debug.WriteLine("Shortcut is on the blacklist skipping: " + fileNameStripped.ToLower());
                            await ListBoxRemoveAll(lb_Shortcuts, List_Shortcuts, x => x.PathExe.ToLower() == targetPathLower);

                            continue;
                        }

                        //Check if shortcut uri is in shortcut uri blacklist
                        if (vCtrlIgnoreShortcutUri.Any(x => targetPathLower.Contains(x.String1.ToLower())))
                        {
                            //Debug.WriteLine("Shortcut uri is on the uri blacklist skipping: " + targetPathLower);
                            await ListBoxRemoveAll(lb_Shortcuts, List_Shortcuts, x => x.PathExe.ToLower() == targetPathLower);

                            continue;
                        }

                        //Check if shortcut is already in the shortcut list
                        DataBindApp shortcutExistCheck = List_Shortcuts.Where(x => x.PathExe.ToLower() == targetPathLower && x.Argument.ToLower() == targetArgumentLower).FirstOrDefault();
                        if (shortcutExistCheck != null)
                        {
                            //Debug.WriteLine("Shortcut is already in list, updating: " + targetPathLower);
                            shortcutExistCheck.Name         = shortcutDetails.Title;
                            shortcutExistCheck.ShortcutPath = shortcutDetails.ShortcutPath;
                            continue;
                        }

                        //Add shortcut to the shortcuts list
                        await ShortcutAddToListWithDetails(shortcutDetails);
                    }
                    catch { }
                }

                //Hide the loading gif
                AVActions.ActionDispatcherInvoke(delegate
                {
                    gif_Shortcuts_Loading.Hide();
                });
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Failed loading shortcuts: " + ex.Message);
            }
            //Update the refreshing status
            vBusyRefreshingShortcuts = false;
        }