コード例 #1
0
            public override void CreateShortcut(CreateShortcut action)
            {
                string shortcutFileName = Runner.InvokeExpression<string>(
                    action.ShortcutFileName
                );

                AddToInstallLog(new InstallLogCreateFile
                {
                    Path = shortcutFileName
                });

                _form.RaiseProgressChanged(String.Format(UILabels.CreatingShortcut, shortcutFileName));

                var shellLink = new ShellLink
                {
                    Target = Runner.InvokeExpression<string>(action.TargetFileName),
                };

                if (action.IconFileName != null)
                    shellLink.IconPath = Runner.InvokeExpression<string>(action.IconFileName);

                if (action.IconIndex != null)
                    shellLink.IconIndex = Runner.InvokeExpression<int>(action.IconIndex);

                if (action.StartOptions != null)
                    shellLink.Arguments = Runner.InvokeExpression<string>(action.StartOptions);

                if (action.Description != null)
                    shellLink.Description = Runner.ParseTemplate(action.Description);

                Directory.CreateDirectory(Path.GetDirectoryName(shortcutFileName));

                shellLink.Save(shortcutFileName);
            }
コード例 #2
0
            private void CreateUninstallShortCut(string targetPath)
            {
                bool createShortcuts = Runner.Variables.GetOptional<bool>(
                    Constants.ScriptVariables.CreateShortcuts
                );

                if (!createShortcuts)
                    return;

                string startMenuPath = Runner.Variables.GetRequired<string>(
                    Constants.ScriptVariables.StartMenuPath
                );

                string startMenuBase = NativeMethods.SHGetFolderPath(
                    IntPtr.Zero,
                    NativeMethods.SpecialFolderCSIDL.CSIDL_STARTMENU,
                    IntPtr.Zero,
                    0
                );

                startMenuPath = Path.Combine(startMenuBase, startMenuPath);

                AddToInstallLog(new InstallLogCreateDirectory
                {
                    Path = startMenuPath,
                    Force = false
                });

                Directory.CreateDirectory(startMenuPath);

                string shortcutFileName = Path.Combine(
                    startMenuPath,
                    UILabels.Uninstall + ".lnk"
                );

                AddToInstallLog(new InstallLogCreateFile
                {
                    Path = shortcutFileName
                });

                _form.RaiseProgressChanged(String.Format(UILabels.CreatingShortcut, shortcutFileName));

                var shellLink = new ShellLink
                {
                    Target = Path.Combine(targetPath, Constants.NuGetUpdateFileName),
                    IconIndex = 1,
                    IconPath = Path.Combine(targetPath, Constants.NuGetUpdateFileName),
                    Arguments = String.Format("-r -p {0}", Escaping.ShellEncode(Runner.Environment.Config.PackageCode))
                };

                shellLink.SetPropertyValue(PropertyStoreProperty.AppUserModel_StartPinOption, 1 /* APPUSERMODEL_STARTPINOPTION_NOPINONINSTALL */);
                shellLink.SetPropertyValue(PropertyStoreProperty.AppUserModel_ExcludeFromShowInNewInstall, true);

                shellLink.Save(shortcutFileName);
            }