using System; using System.Linq; using System.Windows.Forms; using Microsoft.Deployment.WindowsInstaller; using WixSharp; using WixSharp.Forms; // This uses the WixSharp ManagedProject class. namespace PowerThrottle.Setup { class Setup { static void Main() { try { Compiler.WixLocation = @"..\packages\WixSharp.wix.bin.3.10.1\tools\bin"; var project = new ManagedProject( "DesignForge Throttle", new Dir( @"%ProgramFiles%\DesignForge\Throttle", new Files( @"Files\Bin\*.*", f => !f.EndsWith( ".xml" ) && !f.EndsWith( ".pdb" ) ) ), new Property( "INSTALLDESKTOPSHORTCUT", "no" ), new ManagedAction( CustomActions.MyAction, Return.ignore, When.Before, Step.LaunchConditions, Condition.NOT_Installed, Sequence.InstallUISequence ) ); project.GUID = new Guid( "6fe30b47-2577-43ad-9095-1861ba25889b" ); //project.ManagedUI = ManagedUI.Empty; //no standard UI dialogs //project.ManagedUI = ManagedUI.Default; //all standard UI dialogs // Include a custom set of standard UI dialogs. project.ManagedUI = new ManagedUI(); project.ManagedUI.InstallDialogs.Add( Dialogs.Welcome ) .Add( Dialogs.Licence ) //.Add( Dialogs.SetupType ) //.Add( Dialogs.Features ) .Add( Dialogs.InstallDir ) .Add( Dialogs.Progress ) .Add( Dialogs.Exit ); project.ManagedUI.ModifyDialogs.Add( Dialogs.MaintenanceType ) .Add( Dialogs.Features ) .Add( Dialogs.Progress ) .Add( Dialogs.Exit ); // This worked in the Project class, but does not yield the same behavior with this ManagedProject. //project.BackgroundImage = @"Images\InstallerBackgroundImage.jpg"; //project.BannerImage = @"Images\Exit.png"; project.Description = "Description"; project.ControlPanelInfo.NoModify = true; project.ControlPanelInfo.HelpLink = @"http:\\www.DesignForge.com\products\WachugotOnDisk\Help"; project.ControlPanelInfo.Manufacturer = "DesignForge, Inc."; project.OutDir = "MediaFiles"; project.OutFileName = "Setup Throttle"; var desktopShortcut = new FileShortcut( "Throttle", "%Desktop%" ); desktopShortcut.IconFile = @"Images\App.ico"; var programMenuShortcut = new FileShortcut( "Throttle", @"%ProgramMenu%\DesignForge" ); programMenuShortcut.IconFile = @"Images\App.ico"; // Without this, project does not yet contain all the deployment files. project.ResolveWildCards(); project .FindFile( ( f ) => f.Name.EndsWith( "PowerThrottle.exe" ) ) .First() .Shortcuts = new[] { desktopShortcut, programMenuShortcut }; project.Dirs.Add( new Dir( @"%ProgramMenu%\DesignForge" ) ); // These are not working yet. project.Load += Msi_Load; project.BeforeInstall += Msi_BeforeInstall; project.AfterInstall += Msi_AfterInstall; project.BuildMsi(); } catch (Exception x) { Console.WriteLine( "Exception {0} within Setup.Main: {1}", x.GetType(), x.Message ); } } static void Msi_Load( SetupEventArgs e ) { if (!e.IsUISupressed && !e.IsUninstalling) MessageBox.Show( e.ToString(), "Load" ); } static void Msi_BeforeInstall( SetupEventArgs e ) { if (!e.IsUISupressed && !e.IsUninstalling) MessageBox.Show( e.ToString(), "BeforeInstall" ); } static void Msi_AfterInstall( SetupEventArgs e ) { if (!e.IsUISupressed && !e.IsUninstalling) MessageBox.Show( e.ToString(), "AfterExecute" ); } } public class CustomActions { [CustomAction] public static ActionResult MyAction( Session session ) { if (DialogResult.Yes == MessageBox.Show( "Do you want to install desktop shortcut", "Installation", MessageBoxButtons.YesNo )) session["INSTALLDESKTOPSHORTCUT"] = "yes"; return ActionResult.Success; } } }