Пример #1
0
        /// <summary>
        /// Check if a specified shortcut file exists.
        /// </summary>
        /// <param name="shortcutPath">Shortcut file path</param>
        /// <param name="targetPath">Target file path of shortcut</param>
        /// <param name="arguments">Arguments of shortcut</param>
        /// <param name="comment">Comment of shortcut</param>
        /// <param name="workingFolder">Working folder of shortcut</param>
        /// <param name="windowState">Window state of shortcut</param>
        /// <param name="iconPath">Icon file path of shortcut</param>
        /// <param name="appId">AppUserModelID of shortcut</param>
        /// <param name="activatorId">AppUserModelToastActivatorCLSID of shortcut</param>
        /// <returns>True if exists</returns>
        public bool CheckShortcut(
            string shortcutPath,
            string targetPath,
            string arguments,
            string comment,
            string workingFolder,
            ShortcutWindowState windowState,
            string iconPath,
            string appId,
            Guid activatorId)
        {
            if (!File.Exists(shortcutPath))
            {
                return(false);
            }

            using (var shellLink = new ShellLink(shortcutPath))
            {
                // File path casing may be different from that when installed the shortcut file.
                return(shellLink.TargetPath.IsNullOrEmptyOrEquals(targetPath, StringComparison.OrdinalIgnoreCase) &&
                       shellLink.Arguments.IsNullOrEmptyOrEquals(arguments, StringComparison.Ordinal) &&
                       shellLink.Description.IsNullOrEmptyOrEquals(comment, StringComparison.Ordinal) &&
                       shellLink.WorkingDirectory.IsNullOrEmptyOrEquals(workingFolder, StringComparison.OrdinalIgnoreCase) &&
                       (shellLink.WindowStyle == ConvertToWindowStyle(windowState)) &&
                       shellLink.IconPath.IsNullOrEmptyOrEquals(iconPath, StringComparison.OrdinalIgnoreCase) &&
                       shellLink.AppUserModelID.IsNullOrEmptyOrEquals(appId, StringComparison.Ordinal) &&
                       ((activatorId == Guid.Empty) || (shellLink.AppUserModelToastActivatorCLSID == activatorId)));
            }
        }
Пример #2
0
        /// <summary>
        /// Check if a specified shortcut file exists.
        /// </summary>
        /// <param name="shortcutPath">Shortcut file path</param>
        /// <param name="targetPath">Target file path of shortcut</param>
        /// <param name="arguments">Arguments of shortcut</param>
        /// <param name="comment">Comment of shortcut</param>
        /// <param name="workingFolder">Working folder of shortcut</param>
        /// <param name="windowState">Window state of shortcut</param>
        /// <param name="iconPath">Icon file path of shortcut</param>
        /// <param name="appId">AppUserModelID of shortcut</param>
        /// <returns>True if exists</returns>
        public bool CheckShortcut(
            string shortcutPath,
            string targetPath,
            string arguments,
            string comment,
            string workingFolder,
            ShortcutWindowState windowState,
            string iconPath,
            string appId)
        {
            if (!File.Exists(shortcutPath))
                return false;

            using (var shellLink = new ShellLink(shortcutPath))
            {
                // File path casing may be different from that when installed the shortcut file.
                return (shellLink.TargetPath.IsNullOrEmptyOrEquals(targetPath, StringComparison.OrdinalIgnoreCase) &&
                    shellLink.Arguments.IsNullOrEmptyOrEquals(arguments, StringComparison.Ordinal) &&
                    shellLink.Description.IsNullOrEmptyOrEquals(comment, StringComparison.Ordinal) &&
                    shellLink.WorkingDirectory.IsNullOrEmptyOrEquals(workingFolder, StringComparison.OrdinalIgnoreCase) &&
                    (shellLink.WindowStyle == ConvertWindowState(windowState)) &&
                    shellLink.IconPath.IsNullOrEmptyOrEquals(iconPath, StringComparison.OrdinalIgnoreCase) &&
                    shellLink.AppUserModelID.IsNullOrEmptyOrEquals(appId, StringComparison.Ordinal));
            }
        }
Пример #3
0
        public static (string AumId, Guid activatorId) ReadShortcut(string shortcutPath)
        {
            if (!File.Exists(shortcutPath))
            {
                throw new FileNotFoundException("Shortcut File is not Exists.", shortcutPath);
            }

            using (var shellLink = new ShellLink(shortcutPath))
            {
                return(shellLink.AppUserModelID, shellLink.AppUserModelToastActivatorCLSID);
            }
        }
Пример #4
0
        /// <summary>
        /// Install a specified shortcut file.
        /// </summary>
        /// <param name="shortcutPath">Shortcut file path</param>
        /// <param name="targetPath">Target file path of shortcut</param>
        /// <param name="arguments">Arguments of shortcut</param>
        /// <param name="comment">Comment of shortcut</param>
        /// <param name="workingFolder">Working folder of shortcut</param>
        /// <param name="windowState">Window state of shortcut</param>
        /// <param name="iconPath">Icon file path of shortcut</param>
        /// <param name="appId">AppUserModelID of shortcut</param>
        /// <param name="activatorId">AppUserModelToastActivatorCLSID of shortcut</param>
        public void InstallShortcut(
            string shortcutPath,
            string targetPath,
            string arguments,
            string comment,
            string workingFolder,
            ShortcutWindowState windowState,
            string iconPath,
            string appId,
            Guid activatorId)
        {
            if (string.IsNullOrWhiteSpace(shortcutPath))
            {
                throw new ArgumentNullException(nameof(shortcutPath));
            }

            logger.Log(LogLevel.Debug, "Creating {0}", shortcutPath);

            using (var shellLink = new ShellLink
            {
                TargetPath = targetPath,
                Arguments = arguments,
                Description = comment,
                WorkingDirectory = workingFolder,
                WindowStyle = ConvertToWindowStyle(windowState),
                IconPath = iconPath,
                IconIndex = 0,                 // The first icon in the file
                AppUserModelID = appId,
            })
            {
                if (activatorId != Guid.Empty)
                {
                    shellLink.AppUserModelToastActivatorCLSID = activatorId;
                }

                shellLink.Save(shortcutPath);
            }
        }
Пример #5
0
        /// <summary>
        /// Install a specified shortcut file.
        /// </summary>
        /// <param name="shortcutPath">Shortcut file path</param>
        /// <param name="targetPath">Target file path of shortcut</param>
        /// <param name="arguments">Arguments of shortcut</param>
        /// <param name="comment">Comment of shortcut</param>
        /// <param name="workingFolder">Working folder of shortcut</param>
        /// <param name="windowState">Window state of shortcut</param>
        /// <param name="iconPath">Icon file path of shortcut</param>
        /// <param name="appId">AppUserModelID of shortcut</param>
        public void InstallShortcut(
            string shortcutPath,
            string targetPath,
            string arguments,
            string comment,
            string workingFolder,
            ShortcutWindowState windowState,
            string iconPath,
            string appId)
        {
            if (String.IsNullOrWhiteSpace(shortcutPath))
                throw new ArgumentNullException("shortcutPath");

            using (var shellLink = new ShellLink
            {
                TargetPath = targetPath,
                Arguments = arguments,
                Description = comment,
                WorkingDirectory = workingFolder,
                WindowStyle = ConvertWindowState(windowState),
                IconPath = iconPath,
                IconIndex = 0, // 1st icon in the file
                AppUserModelID = appId,
            })
            {
                shellLink.Save(shortcutPath);
            }
        }