Improve DTF samples.
Sean Hall committed
Jul 19, 2022 at 15:15 UTC
93bb820eff547f8de304f05249f572da861256fb
9 files changed
+100
-43
src/test/dtf/EmbeddedUI/AssemblyInfo.cs
deleted
-3
@@ -1,3 +0,0 @@
1
-using System.Reflection;
2
-
3
-[assembly: AssemblyDescription("Sample managed embedded external UI")]
src/test/dtf/EmbeddedUI/EmbeddedUI.config
new
+10
@@ -0,0 +1,10 @@
1
+<?xml version="1.0" encoding="utf-8" ?>
2
+<!-- Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. -->
3
+
4
+
5
+<configuration>
6
+ <startup useLegacyV2RuntimeActivationPolicy="true">
7
+ <supportedRuntime version="v4.0" />
8
+ <supportedRuntime version="v2.0.50727" />
9
+ </startup>
10
+</configuration>
src/test/dtf/EmbeddedUI/EmbeddedUI.csproj
+9
-34
@@ -1,49 +1,24 @@
1
-<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
1
+<Project Sdk="Microsoft.NET.Sdk">
2
<PropertyGroup>
3
- <ProjectGuid>{864B8C50-7895-4485-AC89-900D86FD8C0D}</ProjectGuid>
4
- <OutputType>Library</OutputType>
5
- <RootNamespace>WixToolset.Samples.EmbeddedUI</RootNamespace>
6
- <AssemblyName>WixToolset.Samples.EmbeddedUI</AssemblyName>
7
- <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
8
- <FileAlignment>512</FileAlignment>
3
+ <TargetFramework>net35</TargetFramework>
4
+ <Description>Sample managed embedded external UI</Description>
5
+ <UseWPF>true</UseWPF>
6
</PropertyGroup>
7
8
<ItemGroup>
12
- <Compile Include="AssemblyInfo.cs" />
13
- <Compile Include="InstallProgressCounter.cs" />
14
- <Compile Include="SampleEmbeddedUI.cs" />
15
- <Compile Include="SetupWizard.xaml.cs">
16
- <DependentUpon>SetupWizard.xaml</DependentUpon>
17
- </Compile>
9
+ <Content Include="EmbeddedUI.config" CopyToOutputDirectory="PreserveNewest" />
10
</ItemGroup>
11
12
<ItemGroup>
21
- <Page Include="SetupWizard.xaml">
22
- <Generator>MSBuild:Compile</Generator>
23
- <SubType>Designer</SubType>
24
- </Page>
25
- </ItemGroup>
26
-
27
- <ItemGroup>
28
- <Reference Include="PresentationCore">
29
- <RequiredTargetFramework>3.0</RequiredTargetFramework>
30
- </Reference>
31
- <Reference Include="PresentationFramework">
32
- <RequiredTargetFramework>3.0</RequiredTargetFramework>
33
- </Reference>
13
+ <Reference Include="PresentationCore" />
14
+ <Reference Include="PresentationFramework" />
15
<Reference Include="System" />
35
- <Reference Include="System.Core">
36
- <RequiredTargetFramework>3.5</RequiredTargetFramework>
37
- </Reference>
16
+ <Reference Include="System.Core" />
17
<Reference Include="System.Xml" />
39
- <Reference Include="WindowsBase">
40
- <RequiredTargetFramework>3.0</RequiredTargetFramework>
41
- </Reference>
18
+ <Reference Include="WindowsBase" />
19
</ItemGroup>
20
21
<ItemGroup>
22
<PackageReference Include="WixToolset.Dtf.CustomAction" />
23
</ItemGroup>
47
-
48
- <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
24
</Project>
src/test/dtf/EmbeddedUI/SampleEmbeddedUI.cs
+15
-4
@@ -11,6 +11,7 @@ namespace WixToolset.Samples.EmbeddedUI
11
12
public class SampleEmbeddedUI : IEmbeddedUI
13
{
14
+ private bool isMaintenance;
15
private Thread appThread;
16
private Application app;
17
private SetupWizard setupWizard;
@@ -46,11 +47,11 @@ namespace WixToolset.Samples.EmbeddedUI
47
48
if (String.Equals(session["REMOVE"], "All", StringComparison.OrdinalIgnoreCase))
49
{
49
- // Don't show custom UI when uninstalling.
50
+ // Don't show custom UI when uninstall was specified on the command line.
51
return false;
51
-
52
- // An embedded UI could display an uninstall wizard, it's just not imlemented here.
52
}
53
+
54
+ this.isMaintenance = session.EvaluateCondition("Installed");
55
}
56
57
// Start the setup wizard on a separate thread.
@@ -69,6 +70,16 @@ namespace WixToolset.Samples.EmbeddedUI
70
}
71
else
72
{
73
+ switch (this.setupWizard.Operation)
74
+ {
75
+ case SetupOperationType.Repair:
76
+ session["REINSTALL"] = "ALL";
77
+ break;
78
+ case SetupOperationType.Uninstall:
79
+ session["REMOVE"] = "ALL";
80
+ break;
81
+ }
82
+
83
// Start the installation with a silenced internal UI.
84
// This "embedded external UI" will handle message types except for source resolution.
85
internalUILevel = InstallUIOptions.NoChange | InstallUIOptions.SourceResolutionOnly;
@@ -121,7 +132,7 @@ namespace WixToolset.Samples.EmbeddedUI
132
private void Run()
133
{
134
this.app = new Application();
124
- this.setupWizard = new SetupWizard(this.installStartEvent);
135
+ this.setupWizard = new SetupWizard(this.installStartEvent, this.isMaintenance);
136
this.setupWizard.InitializeComponent();
137
this.app.Run(this.setupWizard);
138
this.installExitEvent.Set();
src/test/dtf/EmbeddedUI/SetupWizard.xaml
+2
@@ -8,6 +8,8 @@
8
Title="Sample Embedded UI" Height="400" Width="540" Visibility="Visible">
9
<Grid>
10
<TextBox Margin="8,8,8,63" Name="messagesTextBox" IsReadOnly="True" VerticalScrollBarVisibility="Visible" HorizontalScrollBarVisibility="Auto" FontFamily="Lucida Console" FontSize="10" />
11
+ <Button Height="23" HorizontalAlignment="Left" Name="repairButton" VerticalAlignment="Bottom" Width="75" Visibility="Hidden" Click="repairButton_Click" Margin="8,0,0,8">Repair</Button>
12
+ <Button Height="23" HorizontalAlignment="Left" Name="uninstallButton" VerticalAlignment="Bottom" Width="75" Visibility="Hidden" Click="uninstallButton_Click" Margin="91,0,0,8">Uninstall</Button>
13
<Button Height="23" HorizontalAlignment="Right" Name="installButton" VerticalAlignment="Bottom" Width="75" Click="installButton_Click" Margin="0,0,91,8">Install</Button>
14
<Button Height="23" HorizontalAlignment="Right" Name="exitButton" VerticalAlignment="Bottom" Width="75" Visibility="Hidden" Click="exitButton_Click" Margin="0,0,8,8">Exit</Button>
15
<Button Height="23" Margin="0,0,8,8" Name="cancelButton" VerticalAlignment="Bottom" Width="75" HorizontalAlignment="Right" Click="cancelButton_Click">Cancel</Button>
src/test/dtf/EmbeddedUI/SetupWizard.xaml.cs
+46
-1
@@ -16,19 +16,44 @@ namespace WixToolset.Samples.EmbeddedUI
16
using System.Windows.Shapes;
17
using WixToolset.Dtf.WindowsInstaller;
18
19
+ public enum SetupOperationType
20
+ {
21
+ Install,
22
+ Repair,
23
+ Uninstall
24
+ }
25
+
26
/// <summary>
27
/// Interaction logic for SetupWizard.xaml
28
/// </summary>
29
public partial class SetupWizard : Window
30
{
31
+ private bool isMaintenance;
32
private ManualResetEvent installStartEvent;
33
private InstallProgressCounter progressCounter;
34
private bool canceled;
35
28
- public SetupWizard(ManualResetEvent installStartEvent)
36
+ public SetupOperationType Operation { get; private set; }
37
+
38
+ public SetupWizard(ManualResetEvent installStartEvent, bool isMaintenance)
39
{
40
this.installStartEvent = installStartEvent;
41
this.progressCounter = new InstallProgressCounter(0.5);
42
+ this.isMaintenance = isMaintenance;
43
+
44
+ this.Loaded += this.SetupWizard_Loaded;
45
+ }
46
+
47
+ private void SetupWizard_Loaded(object sender, RoutedEventArgs e)
48
+ {
49
+ this.Loaded -= this.SetupWizard_Loaded;
50
+
51
+ if (this.isMaintenance)
52
+ {
53
+ this.installButton.Visibility = Visibility.Hidden;
54
+ this.repairButton.Visibility = Visibility.Visible;
55
+ this.uninstallButton.Visibility = Visibility.Visible;
56
+ }
57
}
58
59
public MessageResult ProcessMessage(InstallMessage messageType, Record messageRecord,
@@ -81,8 +106,28 @@ namespace WixToolset.Samples.EmbeddedUI
106
}
107
108
private void installButton_Click(object sender, RoutedEventArgs e)
109
+ {
110
+ this.Operation = SetupOperationType.Install;
111
+ this.StartInstall();
112
+ }
113
+
114
+ private void repairButton_Click(object sender, RoutedEventArgs e)
115
+ {
116
+ this.Operation = SetupOperationType.Repair;
117
+ this.StartInstall();
118
+ }
119
+
120
+ private void uninstallButton_Click(object sender, RoutedEventArgs e)
121
+ {
122
+ this.Operation = SetupOperationType.Uninstall;
123
+ this.StartInstall();
124
+ }
125
+
126
+ private void StartInstall()
127
{
128
this.installButton.Visibility = Visibility.Hidden;
129
+ this.repairButton.Visibility = Visibility.Hidden;
130
+ this.uninstallButton.Visibility = Visibility.Hidden;
131
this.progressBar.Visibility = Visibility.Visible;
132
this.progressLabel.Visibility = Visibility.Visible;
133
this.installStartEvent.Set();
src/test/dtf/SampleCA/CustomAction.config
new
+10
@@ -0,0 +1,10 @@
1
+<?xml version="1.0" encoding="utf-8" ?>
2
+<!-- Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. -->
3
+
4
+
5
+<configuration>
6
+ <startup useLegacyV2RuntimeActivationPolicy="true">
7
+ <supportedRuntime version="v4.0" />
8
+ <supportedRuntime version="v2.0.50727" />
9
+ </startup>
10
+</configuration>
src/test/dtf/SampleCA/SampleCA.csproj
+7
-1
@@ -1,9 +1,15 @@
1
<Project Sdk="Microsoft.NET.Sdk">
2
<PropertyGroup>
3
- <TargetFramework>net472</TargetFramework>
3
+ <TargetFramework>net20</TargetFramework>
4
<Description>Sample managed custom actions</Description>
5
</PropertyGroup>
6
7
+ <ItemGroup>
8
+ <Content Include="CustomAction.config" CopyToOutputDirectory="PreserveNewest" />
9
+ <None Include="testsub\testfile.txt" CopyToOutputDirectory="PreserveNewest" />
10
+ <CustomActionContents Include="testsub\SampleCAs.cs=$(OutputDirectory)testsub\testfile.txt" />
11
+ </ItemGroup>
12
+
13
<ItemGroup>
14
<PackageReference Include="WixToolset.Dtf.CustomAction" />
15
</ItemGroup>
src/test/dtf/SampleCA/testsub/testfile.txt
new
+1
@@ -0,0 +1 @@
1
+test file for testing subdirectory support and binary stream reading