Esempio n. 1
0
        private void BtnFinish_Click(object sender, EventArgs e)
        {
            if (this.forms[Step] is IStep step)
            {
                step.ChangeContext();
            }

            if (context.IsFull && context.IsSuccess)
            {
                if (context.RunWhenFinish)
                {
                    if (!string.IsNullOrEmpty(context.InstInfo.MainEntery))
                    {
                        var mainEntity = context.ConvertPath(context.InstInfo.MainEntery);
                        var pinfo      = new ProcessStartInfo(mainEntity, context.InstInfo.MainEnteryArgs)
                        {
                            WorkingDirectory = context.ConvertPath(context.InstInfo.InstallPath)
                        };
                        Process.Start(pinfo);
                    }
                }

                if (context.RunReadmeWhenFinish)
                {
                    if (!string.IsNullOrEmpty(context.InstInfo.ReadmeFile))
                    {
                        var readme = context.ConvertPath(context.InstInfo.ReadmeFile);
                        Process.Start("notepad.exe", readme);
                    }
                }
            }

            this.Close();
            Application.Exit();
        }
Esempio n. 2
0
        public override void Init()
        {
            var iconDir    = InstallContext.ConvertPath(GlobalPath.IconGroup);
            var mainEntity = InstallContext.ConvertPath(InstallContext.InstInfo.MainEntery);

            regInfo = new RegInfo
            {
                DisplayName     = InstallContext.AppInfo.AppName,
                DisplayIcon     = mainEntity,
                DisplayVersion  = InstallContext.AppInfo.Version,
                ExeArgs         = InstallContext.InstInfo.MainEnteryArgs,
                EstimatedSize   = (int)(InstallContext.NeedSize / 1024),
                ExePath         = mainEntity,
                ExeKey          = new FileInfo(mainEntity).Name,
                IconGroupName   = iconDir,
                InstallPath     = InstallContext.InstInfo.InstallPath,
                Publisher       = InstallContext.AppInfo.Publisher,
                URLInfoAbout    = InstallContext.AppInfo.WebSite,
                AppKey          = InstallContext.AppInfo.AppName,
                UninstallString = InstallContext.CreateUninstall ? InstallContext.UninstallData.UninstallTarget : null
            };
            this.CanRun        = true;
            this.CanRollback   = true;
            this.CommandStatus = CommandStatus.Inited;
        }
Esempio n. 3
0
        public override void Init()
        {
            InstallContext.UninstallData.UninstallTarget =
                Path.Combine(InstallContext.InstInfo.InstallPath, Context.UninstallerKey);

            InstallContext.CreateUninstall = InstallContext.InstInfo.CreateUninstallLnk &&
                                             File.Exists(InstallContext.UninstallData.UninstallTarget);

            this.iconDir = InstallContext.ConvertPath(GlobalPath.IconGroup);

            if (InstallContext.ShortCuts != null && InstallContext.ShortCuts.Any() && InstallContext.CreateShortcuts)
            {
                if (InstallContext.CreateIconGroup && !string.IsNullOrEmpty(InstallContext.InstInfo.IconGroup))
                {
                    if (InstallContext.CreateUninstall)
                    {
                        shortCutInfos.Add(new ShortCutInfo()
                        {
                            Name      = "Uninstall.lnk",
                            TargetDir = iconDir,
                            Target    = InstallContext.UninstallData.UninstallTarget
                        });
                    }

                    if (InstallContext.InstInfo.CreateWebSiteLnk &&
                        !string.IsNullOrEmpty(InstallContext.AppInfo.WebSite))
                    {
                        shortCutInfos.Add(new ShortCutInfo()
                        {
                            Name      = "website.url",
                            TargetDir = iconDir,
                            Target    = InstallContext.AppInfo.WebSite
                        });
                    }
                }
            }

            if (InstallContext.ShortCuts != null)
            {
                shortCutInfos.AddRange(InstallContext.ShortCuts);
            }

            if (shortCutInfos.Any())
            {
                this.CanRun      = true;
                this.CanRollback = true;
            }
            this.CommandStatus = CommandStatus.Inited;
        }
Esempio n. 4
0
        public override bool Run()
        {
            if (!CanRun)
            {
                return(true);
            }
            this.CommandStatus = CommandStatus.Running;
            Watch?.SetStep("创建快捷方式");
            if (!Directory.Exists(iconDir))
            {
                Directory.CreateDirectory(iconDir);
                this.createIconDir = true;
            }

            foreach (var shortcut in shortCutInfos)
            {
                var name = shortcut.Name;
                if (!name.EndsWith(".url", StringComparison.OrdinalIgnoreCase) && !name.EndsWith(".lnk", StringComparison.OrdinalIgnoreCase))
                {
                    name += ".lnk";
                }
                var targetPath = InstallContext.ConvertPath(shortcut.TargetDir);
                if (Directory.Exists(targetPath))
                {
                    var path = Path.Combine(targetPath, name);
                    FileHelper.RemoveReadonly(path);
                    if (name.EndsWith(".url", StringComparison.OrdinalIgnoreCase))
                    {
                        ShortcutHelper.CreateWebShortcutFile(path, shortcut.TargetDir);
                    }
                    else
                    {
                        var target = InstallContext.ConvertPath(shortcut.Target);
                        ShortcutHelper.CreateShortcutFile(path, target, shortcut.Args);
                    }

                    Watch?.Info("-->" + path);
                    Watch?.AddValue(1);
                    InstallContext.UninstallData.Shortcuts.Add(path);
                }
            }

            this.CommandStatus = CommandStatus.Complete;
            return(true);
        }
Esempio n. 5
0
        public static string ConvertVars(this InstallContext context, string var)
        {
            if (var == null)
            {
                return(null);
            }
            var result = rgVar.Replace(var, match =>
            {
                switch (match.Groups[1].Value)
                {
                case GlobalPath.AppName:
                    return(context.AppInfo.AppName);

                case GlobalPath.FullName:
                    return(context.AppInfo.FullName);
                }

                var val = context.GetPageItemValue(match.Groups[1].Value);
                return(val ?? match.Value);
            });

            return(context.ConvertPath(result));
        }