Пример #1
0
        public static ActionResult WixSharp_InitRuntime_Action(Session session)
        {
            // Debugger.Launch();
            if (session.Property("FOUNDPREVIOUSVERSION").IsEmpty())
            {
                session["FOUNDPREVIOUSVERSION"] = session.LookupInstalledVersion()?.ToString();
            }

            if (session["MsiLogFileLocation"].IsNotEmpty())
            {
                Environment.SetEnvironmentVariable("MsiLogFileLocation", session.Property("MsiLogFileLocation"));
            }

            return(ManagedProject.Init(session));
        }
Пример #2
0
        /// <summary>
        /// Shows the modal window of the MSI UI. This method is called by the <see cref="T:Microsoft.Deployment.WindowsInstaller.IEmbeddedUI" />
        /// when it is initialized at runtime.
        /// </summary>
        /// <param name="msiRuntime">The MSI runtime.</param>
        /// <param name="ui">The MSI external/embedded UI.</param>
        public void ShowModal(MsiRuntime msiRuntime, IManagedUI ui)
        {
            //Debug.Assert(false);
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            UI         = ui;
            MsiRuntime = msiRuntime;


            ActionResult result = ManagedProject.InvokeClientHandlers(MsiRuntime.Session, "UIInitialized");

            if (result == ActionResult.Success)
            {
                if (MsiRuntime.Session.IsInstalling())
                {
                    Dialogs = ui.InstallDialogs;
                }
                else if (MsiRuntime.Session.IsRepairing())
                {
                    Dialogs = ui.ModifyDialogs;
                }

                if (Dialogs.Any())
                {
                    shellView       = new ShellView();
                    shellView.Load += (s, e) =>
                    {
                        ManagedProject.InvokeClientHandlers(MsiRuntime.Session, "UILoaded", (IShellView)shellView);
                    };
                    GoNext();
                    shellView.ShowDialog();
                }
                else
                {
                    this.StartExecute();
                    while (!finished)
                    {
                        Thread.Sleep(1000);
                    }
                }
            }
            else
            {
                MsiRuntime.Session.Log("UIInitialized returned " + result);
            }
        }
Пример #3
0
        /// <summary>
        /// Shows the modal window of the MSI UI. This method is called by the <see cref="T:Microsoft.Deployment.WindowsInstaller.IEmbeddedUI" />
        /// when it is initialized at runtime.
        /// </summary>
        /// <param name="msiRuntime">The MSI runtime.</param>
        /// <param name="ui">The MSI external/embedded UI.</param>
        public void ShowModal(MsiRuntime msiRuntime, IManagedUI ui)
        {
            // Debug.Assert(false);
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            UI               = ui;
            MsiRuntime       = msiRuntime;
            Tasks.UILocalize = text => text.LocalizeWith(msiRuntime.Localize);

            UACRevealer.Enabled = !MsiRuntime.Session.Property("UAC_REVEALER_ENABLED").IsEmpty();

            if (MsiRuntime.Session.IsInstalling())
            {
                Dialogs = ui.InstallDialogs;
            }
            else if (MsiRuntime.Session.IsRepairing())
            {
                Dialogs = ui.ModifyDialogs;
            }

            if (Dialogs.Any())
            {
                shellView = new ShellView {
                    Shell = this
                }
            }
            ;

            try
            {
                int culture = msiRuntime.Session.Property("ProductLanguage").ToInt();
                if (culture != 0)
                {
                    Thread.CurrentThread.CurrentUICulture = new CultureInfo(culture);
                }
            }
            catch { }

            ActionResult result = ManagedProject.InvokeClientHandlers(MsiRuntime.Session, "UIInitialized", shellView as IShellView);

            MsiRuntime.Data.MergeReplace(MsiRuntime.Session["WIXSHARP_RUNTIME_DATA"]); //data may be changed in the client handler

            if (result != ActionResult.Failure)
            {
                if (shellView != null)
                {
                    shellView.Load += (s, e) =>
                    {
                        MsiRuntime.Session["WIXSHARP_MANAGED_UI_HANDLE"]  =
                            MsiRuntime.Data["WIXSHARP_MANAGED_UI_HANDLE"] = shellView.Handle.ToString();
                        try
                        {
                            var data = MsiRuntime.Session.GetEmbeddedData("ui_shell_icon");
                            using (var stream = new System.IO.MemoryStream(data))
                                shellView.Icon = new Icon(stream);
                        }
                        catch { }

                        result = ManagedProject.InvokeClientHandlers(MsiRuntime.Session, "UILoaded", (IShellView)shellView);
                        if (result != ActionResult.Success)
                        {
                            // aborting UI dialogs sequence from here is not possible as this event is
                            // simply called when Shell is loaded but not when dialogs are progressing in the sequence.
                            MsiRuntime.Session.Log("UILoaded returned " + result);
                        }
                        MsiRuntime.Data.MergeReplace(MsiRuntime.Session["WIXSHARP_RUNTIME_DATA"]);;  //data may be changed in the client handler
                    };

                    if (result == ActionResult.SkipRemainingActions)
                    {
                        result = ActionResult.Success;
                        if (Dialogs.Contains(typeof(UI.Forms.ProgressDialog)))
                        {
                            GoTo <UI.Forms.ProgressDialog>();
                        }
                        else
                        {
                            GoToLast();
                        }
                    }
                    else if (result == ActionResult.UserExit)
                    {
                        GoToLast();
                    }
                    else
                    {
                        GoNext();
                    }

                    shellView.ShowDialog();
                }
                else
                {
                    this.StartExecute();
                    while (!finished)
                    {
                        Thread.Sleep(1000);
                    }
                }
            }
            else
            {
                MsiRuntime.Session.Log("UIInitialized returned " + result);
            }
        }
Пример #4
0
 public static ActionResult WixSharp_AfterInstall_Action(Session session)
 {
     //Debugger.Launch();
     return(ManagedProject.InvokeClientHandlers(session, "AfterInstall"));
 }
Пример #5
0
 public static ActionResult WixSharp_InitRuntime_Action(Session session)
 {
     // Debugger.Launch();
     return(ManagedProject.Init(session));
 }
Пример #6
0
 /// <summary>
 /// Invokes Client Handlers
 /// </summary>
 /// <param name="eventName"></param>
 /// <param name="UIShell"></param>
 /// <returns></returns>
 public override ActionResult InvokeClientHandlers(string eventName, IShellView UIShell = null)
 {
     return(ManagedProject.InvokeClientHandlers(MsiSession, eventName, UIShell));
 }
Пример #7
0
 public static ActionResult WixSharp_BeforeInstall_Action(Session session)
 {
     return(ManagedProject.InvokeClientHandlers(session, "BeforeInstall"));
 }
Пример #8
0
        static void Main(string[] args)
        {
            try
            {
                WixSharp.File ui = new WixSharp.File(
                    @"cli\WindowsServiceTestClient.exe",
                    new WixSharp.FileShortcut("WindowsServiceTestClient", @"%ProgramMenu%\cocoalix")
                {
                    Advertise = true
                }
                    );
                WixSharp.File service = new WixSharp.File(
                    @"service\WindowsServiceTest.exe"
                    );
                WixSharp.Files uiDepends = new WixSharp.Files(
                    @"cli\*.*"
                    );
                WixSharp.Files serviceDepends = new WixSharp.Files(
                    @"service\*.*"
                    );

                var dir = new WixSharp.Dir(new WixSharp.Id("InstallDir"),
                                           @"%ProgramFiles%\cocoalix",
                                           // インストーラーにインクルードするファイル
                                           ui,
                                           // インストーラーにインクルードするファイル
                                           service,
                                           uiDepends,
                                           serviceDepends
                                           );

                var project = new WixSharp.ManagedProject("ウィンドウズサービステスト", dir);

                project.Platform = Platform.x64;

                // 日本語をインストーラ及びWiXで仕様するためのおまじない
                project.Codepage = "932";
                project.Language = "ja-JP";

                // アップグレードコードを指定 (変更厳禁)
                project.GUID = new Guid("abbb7cf9-19fa-45f2-babc-a35312741772");

                // インストーラーのファイル名
                project.OutFileName = "ウィンドウズサービステストインストーラ";

                service.ServiceInstaller = new WixSharp.ServiceInstaller
                {
                    Account      = @"NT Authority\System",
                    PermissionEx = new WixSharp.PermissionEx()
                    {
                        User = @"Administrator",
                        ServicePauseContinue = false,
                        ServiceStart         = true,
                        ServiceStop          = true,
                    },
                    Name                    = "WindowsServiceTestService",
                    Description             = "ウィンドウズサービステストのサービスです",
                    StartOn                 = WixSharp.SvcEvent.Install,
                    StopOn                  = WixSharp.SvcEvent.InstallUninstall_Wait,
                    RemoveOn                = WixSharp.SvcEvent.Uninstall_Wait,
                    DelayedAutoStart        = true,
                    FirstFailureActionType  = WixSharp.FailureActionType.restart,
                    SecondFailureActionType = WixSharp.FailureActionType.restart,
                    ThirdFailureActionType  = WixSharp.FailureActionType.none,
                    PreShutdownDelay        = 1000 * 60 * 3,
                    ServiceSid              = WixSharp.ServiceSid.none,
                };

                // インストーラで表示するウィンドウ群の指定
                project.ManagedUI = new WixSharp.ManagedUI();
                project.ManagedUI.InstallDialogs.Add(WixSharp.Forms.Dialogs.Welcome)
                .Add(WixSharp.Forms.Dialogs.Licence)
                .Add(WixSharp.Forms.Dialogs.Progress)
                .Add(WixSharp.Forms.Dialogs.Exit);

                project.LicenceFile = @"Eula.rtf";

                // インストール時権限昇格
                project.InstallPrivileges = InstallPrivileges.elevated;
                project.InstallScope      = InstallScope.perMachine;

                project.PreserveTempFiles = true;

                var projectMsi = project.BuildMsi();

                var bootstrapper = new Bundle(
                    "ウィンドウズサービステスト_バンドルインストーラ",
                    new ExePackage()
                {
                    Id               = "DotNet5DesktopRuntime",
                    Name             = "dotnet5-windowsdesktop-runtime-5.0-win-x64.exe",
                    Vital            = true,
                    Permanent        = false,
                    DownloadUrl      = @"https://download.visualstudio.microsoft.com/download/pr/7a5d15ae-0487-428d-8262-2824279ccc00/6a10ce9e632bce818ce6698d9e9faf39/windowsdesktop-runtime-5.0.4-win-x64.exe",
                    InstallCommand   = "/install /quiet",
                    RepairCommand    = "/repair /quiet",
                    UninstallCommand = "/uninstall /quiet",
                    LogPathVariable  = "dotnet5desktopruntime.log",
                    Compressed       = true,

                    // RemotePayloadは以下のコマンドで取得可能
                    // heat payload <バンドルしたいexeのバイナリのパス> -out .\remote.xml
                    RemotePayloads = new[]
                    {
                        new RemotePayload()
                        {
                            ProductName           = "Microsoft Windows Desktop Runtime - 5.0.4 (x64)",
                            Description           = "Microsoft Windows Desktop Runtime - 5.0.4 (x64)",
                            Hash                  = "33FBCDB6B6F052FCC26B4EF850B81ED5F2C10B02",
                            Size                  = 54790696,
                            Version               = "5.0.4.29817".ToRawVersion(),
                            CertificatePublicKey  = "3756E9BBF4461DCD0AA68E0D1FCFFA9CEA47AC18",
                            CertificateThumbprint = "2485A7AFA98E178CB8F30C9838346B514AEA4769"
                        }
                    }
                },
                    new MsiPackage(projectMsi)
                    );

                // ランタイムバンドルインストーラのバージョン
                bootstrapper.Version = new Version("1.0.0.0");

                // ランタイムバンドルインストーラのアップグレードコード (変更厳禁)
                bootstrapper.UpgradeCode = new Guid("bf3b1aeb-12c5-4401-ad23-6a49f905bd55");

                // ランタイムバンドルインストーラのアプリケーションスタイルの定義
                bootstrapper.Application             = new LicenseBootstrapperApplication();
                bootstrapper.Application.LicensePath = @".\Eula.rtf";

                bootstrapper.Application.LocalizationFile = "thm.wxl";

                // インストール時のOption非表示
                bootstrapper.Application.SuppressOptionsUI = true;
                // アンインストール時の修復を非表示
                bootstrapper.Application.SuppressRepair = true;

                // 一次領域を使用するか
                bootstrapper.PreserveTempFiles = true;
                // Wixの必須パラメータの定義?は行わない
                bootstrapper.SuppressWixMbaPrereqVars = false;

                // インストーラ名の定義
                bootstrapper.OutFileName = "ウィンドウズサービステスト_バンドルインストーラ";

                // ランタイムバンドルインストーラの作成
                bootstrapper.Build();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }