Exemplo n.º 1
0
    static public void Main(string[] args)
    {
        var project = new ManagedProject("ManagedSetup",
                                         new Dir(@"%ProgramFiles%\My Company\My Product",
                                                 new File(@"..\Files\bin\MyApp.exe"),
                                                 new Dir("Docs",
                                                         new File("readme.txt"),
                                                         new File(@"..\Files\Docs\tutorial.txt"))));

        project.ManagedUI            = ManagedUI.Default;
        project.ManagedUI.Icon       = "app.ico";
        project.MinimalCustomDrawing = true;

        project.GUID = new Guid("6f330b47-2577-43ad-9095-1861ba25889b");

        project.ControlPanelInfo.InstallLocation = "[INSTALLDIR]";

        project.SetNetFxPrerequisite(Condition.Net45_Installed, "Please install .Net 4.5 First");

        // project.PreserveTempFiles = true;
        project.SourceBaseDir = @"..\..\";

        project.Localize();

        project.BuildMsi();
    }
Exemplo n.º 2
0
        static void Main()
        {
            string appVersion = "1.0.0.0";

            string OutputFile() // get the executable file name and the version from it..
            {
                try
                {
                    var info = FileVersionInfo.GetVersionInfo(@"..\ScriptNotepad\bin\net6.0-windows\" + Executable);
                    appVersion = string.Concat(info.FileMajorPart, ".", info.FileMinorPart, ".", info.FileBuildPart);
                    return(string.Concat(AppName, "_", info.FileMajorPart, ".", info.FileMinorPart, ".", info.FileBuildPart));
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    return(AppName);
                }
            }

            var project = new ManagedProject("ScriptNotepad",
                                             new Dir(InstallDirectory,
                                                     new WixSharp.Files(@"..\ScriptNotepad\bin\net6.0-windows\*.*"),
                                                     new File("Program.cs")),
                                             new Dir($@"%ProgramMenu%\{Company}\{AppName}",
                                                     // ReSharper disable three times StringLiteralTypo
                                                     new ExeFileShortcut(AppName, $"[INSTALLDIR]{Executable}", "")
            {
                WorkingDirectory = "[INSTALLDIR]", IconFile = ApplicationIcon
            }),
#if InstallLocalAppData
                                             new Dir($@"%LocalAppDataFolder%\{AppName}",
                                                     new File(@"..\ScriptNotepad\Localization\SQLiteDatabase\lang.sqlite"),
                                                     new Dir(@"Dictionaries\en", new File(@"..\dictionaries\en\en_US.dic"),
                                                             new File(@"..\dictionaries\en\en_US.aff")),
                                                     new Dir("Plugins", new File(@"..\PluginTemplate\bin\net6.0-windows\PluginTemplate.dll"))),
#endif
                                             new CloseApplication($"[INSTALLDIR]{Executable}", true),
                                             new Property("Executable", Executable),
                                             new Property("AppName", AppName),
                                             new Property("Company", Company))
            {
                GUID             = new Guid("E142C7BA-2A0E-48B1-BB4E-CDC759AEBF91"),
                ManagedUI        = new ManagedUI(),
                ControlPanelInfo =
                {
                    Manufacturer = Company,
                    UrlInfoAbout = "https://www.vpksoft.net",
                    Name         = $"Installer for the {AppName} application",
                    HelpLink     = "https://www.vpksoft.net",
                },
                Platform    = Platform.x64,
                OutFileName = OutputFile(),
            };

            #region Upgrade
            // the application update process..
            project.Version      = Version.Parse(appVersion);
            project.MajorUpgrade = MajorUpgrade.Default;
            #endregion

            project.Package.Name = $"Installer for the {AppName} application";

            //project.ManagedUI = ManagedUI.Empty;    //no standard UI dialogs
            //project.ManagedUI = ManagedUI.Default;  //all standard UI dialogs

            //custom set of standard UI dialogs

            project.ManagedUI.InstallDialogs.Add(Dialogs.Welcome)
            .Add(Dialogs.Licence)
#if UseRunProgramDialog
            .Add <RunProgramDialog>()
#endif
#if UseAssociationDialog
            .Add <AssociationsDialog>()
#endif
            .Add <ProgressDialog>()
            .Add(Dialogs.Exit);

            project.ManagedUI.ModifyDialogs.Add(Dialogs.MaintenanceType)
            .Add(Dialogs.Features)
            .Add(Dialogs.Progress)
            .Add(Dialogs.Exit);

            project.ControlPanelInfo.ProductIcon = ApplicationIcon;

            AutoElements.UACWarning = "";


            project.BannerImage     = @"Files\install_top.png";
            project.BackgroundImage = @"Files\install_side.png";
            project.LicenceFile     = @"Files\MIT.License.rtf";

            RegistryFileAssociation.ReportExceptionAction = delegate(Exception ex)
            {
                MessageBox.Show(ex.Message);
            };

            project.AfterInstall += delegate(SetupEventArgs args)
            {
                string locale = "en-US";
                if (args.IsInstalling)
                {
                    try
                    {
                        locale = args.Session.Property("LANGNAME");
                    }
                    catch
                    {
                        // ignored..
                    }
                }

                try
                {
                    locale = CommonCalls.GetKeyValue(Company, AppName, "LOCALE");
                    CommonCalls.DeleteValue(Company, AppName, "LOCALE");
                }
                catch
                {
                    // ignored..
                }

                var sideLocalization = new TabDeliLocalization();
                sideLocalization.GetLocalizedTexts(Properties.Resources.tabdeli_messages);

                if (args.IsUninstalling)
                {
                    RegistryFileAssociation.UnAssociateFiles(Company, AppName);
                    CommonCalls.DeleteCompanyKeyIfEmpty(Company);

                    #if ShellStarAssociate
                    try
                    {
                        var openWithMessage = sideLocalization.GetMessage("txtOpenWithShellMenu",
                                                                          "Open with ", locale);

                        RegistryStarAssociation.UnRegisterStarAssociation(openWithMessage);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                    #endif

                    #if InstallLocalAppData
                    var messageCaption = sideLocalization.GetMessage("txtDeleteLocalApplicationData",
                                                                     "Delete application data", locale);

                    var messageText = sideLocalization.GetMessage("txtDeleteApplicationDataQuery",
                                                                  "Delete application settings and other data?", locale);

                    if (MessageBox.Show(messageText,
                                        messageCaption, MessageBoxButtons.YesNo,
                                        MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
                    {
                        try
                        {
                            Directory.Delete(
                                Path.Combine(Environment.GetEnvironmentVariable("LOCALAPPDATA") ?? string.Empty,
                                             AppName), true);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                        }
                    }
                    #endif
                }

                if (args.IsInstalling)
                {
                    #if ShellStarAssociate
                    var messageCaption = sideLocalization.GetMessage("txtStarAssociation",
                                                                     "Add open with menu", locale);

                    var messageText = sideLocalization.GetMessage("txtStarAssociationQuery",
                                                                  "Add an open with this application to the file explorer menu?", locale);

                    if (MessageBox.Show(messageText,
                                        messageCaption, MessageBoxButtons.YesNo,
                                        MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
                    {
                        try
                        {
                            var openWithMessage = sideLocalization.GetMessage("txtOpenWithShellMenu",
                                                                              "Open with ScriptNotepad", locale);

                            RegistryStarAssociation.RegisterStarAssociation(args.Session.Property("EXENAME"), AppName,
                                                                            openWithMessage);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                        }
                    }
                    #endif

                    RegistryFileAssociation.AssociateFiles(Company, AppName, args.Session.Property("EXENAME"),
                                                           args.Session.Property("ASSOCIATIONS"), true);

                    try
                    {
                        CommonCalls.SetKeyValue(Company, AppName, "LOCALE", args.Session.Property("LANGNAME"));
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
            };

            project.Load          += Msi_Load;
            project.BeforeInstall += Msi_BeforeInstall;
            project.AfterInstall  += Msi_AfterInstall;


            //project.SourceBaseDir = "<input dir path>";
            //project.OutDir = "<output dir path>";

            ValidateAssemblyCompatibility();

            project.DefaultDeferredProperties += ",RUNEXE,PIDPARAM,ASSOCIATIONS,LANGNAME,EXENAME";

            project.Localize();

            project.BuildMsi();
        }