//not ready yet. Investigation is in progress internal static Project InjectClrDialogInFeatureTreeUI(this Project project, string showDialogMethod, string prevDialog, string nextDialog) { string wixSharpAsm = typeof(Project).Assembly.Location; string wixSharpUIAsm = IO.Path.ChangeExtension(wixSharpAsm, ".UI.dll"); var showClrDialog = new ManagedAction(showDialogMethod) { Sequence = Sequence.NotInSequence, RefAssemblies = new[] { wixSharpAsm, wixSharpUIAsm } }; project.UI = WUI.WixUI_FeatureTree; if (project.CustomUI != null) throw new ApplicationException("Project.CustomUI is already initialized. Ensure InjectClrDialog is invoked before any adjustments made to CustomUI."); project.CustomUI = new DialogSequence(); project.Actions = project.Actions.Add(showClrDialog); //disconnect prev and next dialogs project.CustomUI.UISequence.RemoveAll(x => (x.Dialog == prevDialog && x.Control == Buttons.Next) || (x.Dialog == nextDialog && x.Control == Buttons.Back)); //create new dialogs connection with showAction in between project.CustomUI.On(prevDialog, Buttons.Next, new ExecuteCustomAction(showClrDialog)) .On(prevDialog, Buttons.Next, new ShowDialog(nextDialog, Condition.ClrDialog_NextPressed)) .On(prevDialog, Buttons.Next, new CloseDialog("Exit", Condition.ClrDialog_CancelPressed) { Order = 2 }) .On(nextDialog, Buttons.Back, new ExecuteCustomAction(showClrDialog)) .On(nextDialog, Buttons.Back, new ShowDialog(prevDialog, Condition.ClrDialog_BackPressed)); return project; }
/// <summary> /// Injects CLR dialog between MSI dialogs 'prevDialog' and 'nextDialog'. /// Passes custom action CLR method name (showDialogMethod) for instantiating and popping up the CLR dialog. /// </summary> /// <param name="project">The project.</param> /// <param name="showDialogMethod">The show dialog method.</param> /// <param name="prevDialog">The previous dialog.</param> /// <param name="nextDialog">The next dialog.</param> /// <returns></returns> /// <example>The following is an example of inserting CustomDialog dialog into the UI sequence between MSI dialogs InsallDirDlg and VerifyReadyDlg. /// <code> /// public class static Script /// { /// public static void Main() /// { /// var project = new Project("CustomDialogTest"); /// /// project.InjectClrDialog("ShowCustomDialog", Dialogs.InstallDirDlg, Dialogs.VerifyReadyDlg); /// Compiler.BuildMsi(project); /// } /// /// [CustomAction] /// public static ActionResult ShowCustomDialog(Session session) /// { /// return WixCLRDialog.ShowAsMsiDialog(new CustomDialog(session)); /// } ///} /// </code> /// </example> public static Project InjectClrDialog(this Project project, string showDialogMethod, string prevDialog, string nextDialog) { string wixSharpAsm = typeof(Project).Assembly.Location; string wixSharpUIAsm = IO.Path.ChangeExtension(wixSharpAsm, ".UI.dll"); var showClrDialog = new ManagedAction(showDialogMethod) { Sequence = Sequence.NotInSequence, }; project.DefaultRefAssemblies.Add(wixSharpAsm); project.DefaultRefAssemblies.Add(wixSharpUIAsm); //Must use WixUI_Common as other UI type has predefined dialogs already linked between each other and WiX does not allow overriding events //http://stackoverflow.com/questions/16961493/override-publish-within-uiref-in-wix project.UI = WUI.WixUI_Common; if (project.CustomUI != null) throw new ApplicationException("Project.CustomUI is already initialized. Ensure InjectClrDialog is invoked before any adjustments made to CustomUI."); project.CustomUI = new CommomDialogsUI(); project.Actions = project.Actions.Add(showClrDialog); //disconnect prev and next dialogs project.CustomUI.UISequence.ForEach(x => { if ((x.Dialog == prevDialog && x.Control == Buttons.Next) || (x.Dialog == nextDialog && x.Control == Buttons.Back)) x.Actions.RemoveAll(a => a is ShowDialog); }); project.CustomUI.UISequence.RemoveAll(x => x.Actions.Count == 0); //create new dialogs connection with showAction in between project.CustomUI.On(prevDialog, Buttons.Next, new ExecuteCustomAction(showClrDialog)) .On(prevDialog, Buttons.Next, new ShowDialog(nextDialog, Condition.ClrDialog_NextPressed)) .On(prevDialog, Buttons.Next, new CloseDialog("Exit", Condition.ClrDialog_CancelPressed) { Order = 2 }) .On(nextDialog, Buttons.Back, new ExecuteCustomAction(showClrDialog)) .On(nextDialog, Buttons.Back, new ShowDialog(prevDialog, Condition.ClrDialog_BackPressed)); var installDir = project.AllDirs.FirstOrDefault(d => d.HastemsToInstall()); if (installDir != null && project.CustomUI.Properties.ContainsKey("WIXUI_INSTALLDIR")) project.CustomUI.Properties["WIXUI_INSTALLDIR"] = installDir.RawId ?? Compiler.AutoGeneration.InstallDirDefaultId; return project; }