-
-
Notifications
You must be signed in to change notification settings - Fork 29
/
InstallScript.cs
287 lines (244 loc) · 11.2 KB
/
InstallScript.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
using System;
using System.Buffers;
using System.Diagnostics;
using System.IO;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using CliWrap;
using Microsoft.Win32;
using Microsoft.Win32.SafeHandles;
using Nefarius.BthPS3.Shared;
using Nefarius.Utilities.Bluetooth;
using Nefarius.Utilities.DeviceManagement.PnP;
using Nefarius.Utilities.WixSharp.Util;
using PInvoke;
using WixSharp;
using WixSharp.CommonTasks;
using WixSharp.Forms;
using WixToolset.Dtf.WindowsInstaller;
using File = WixSharp.File;
using RegistryHive = WixSharp.RegistryHive;
namespace Nefarius.BthPS3.Setup;
internal class InstallScript
{
public const string ProductName = "Nefarius BthPS3 Bluetooth Drivers";
public const string ArtifactsDir = @"..\setup\artifacts";
public const string DriversRoot = @"..\setup\drivers";
public const string ManifestsDir = "manifests";
public static string BthPs3ServiceName => "BthPS3Service";
public static Guid BthPs3ServiceGuid => Guid.Parse("{1cb831ea-79cd-4508-b0fc-85f7c85ae8e0}");
private static void Main()
{
Version version = Version.Parse(BuildVariables.SetupVersion);
string driverPath = Path.Combine(DriversRoot, @"BthPS3_x64\BthPS3.sys");
Version driverVersion = Version.Parse(FileVersionInfo.GetVersionInfo(driverPath).FileVersion);
string filterPath = Path.Combine(DriversRoot, @"BthPS3PSM_x64\BthPS3PSM.sys");
Version filterVersion = Version.Parse(FileVersionInfo.GetVersionInfo(filterPath).FileVersion);
const string nefconDir = @".\nefcon";
Console.WriteLine($"Setup version: {version}");
Console.WriteLine($"Driver version: {driverVersion}");
Console.WriteLine($"Filter version: {filterVersion}");
Feature driversFeature = new("BthPS3 Bluetooth Drivers", true, false)
{
Description = "Installs the Nefarius BthPS3 drivers for PS3 peripherals. " +
"This is a mandatory core component and can't be de-selected."
};
Feature postInstallArticleFeature = new("Open post-installation article", true, true)
{
Id = "PostInstArticle",
Description = "When setup has finished successfully, open the post-installation web article."
};
driversFeature.Add(postInstallArticleFeature);
driversFeature.Display = FeatureDisplay.expand;
ManagedProject project = new(ProductName,
new Dir(driversFeature, @"%ProgramFiles%\Nefarius Software Solutions\BthPS3",
// nefcon
new Dir(driversFeature, "nefcon")
{
Files = new DirFiles(driversFeature, "*.*").GetFiles(nefconDir),
Dirs = WixExt.GetSubDirectories(driversFeature, nefconDir).ToArray()
},
// driver binaries
new Dir(driversFeature, "drivers")
{
Dirs = WixExt.GetSubDirectories(driversFeature, DriversRoot).ToArray()
},
// manifest files
new Dir(driversFeature, ManifestsDir,
new File(driversFeature, @"..\BthPS3\BthPS3.man"),
new File(driversFeature, @"..\BthPS3PSM\BthPS3PSM.man")
),
// config tool
new File(driversFeature, Path.Combine(ArtifactsDir, @"bin\BthPS3CfgUI.exe"),
new FileShortcut("BthPS3 Driver Configuration Tool") { WorkingDirectory = "[INSTALLDIR]" }
),
new Dir(@"%ProgramMenu%\Nefarius Software Solutions\BthPS3",
new ExeFileShortcut("Uninstall BthPS3", "[System64Folder]msiexec.exe", "/x [ProductCode]"),
new ExeFileShortcut("BthPS3 Driver Configuration Tool", "[INSTALLDIR]BthPS3CfgUI.exe", "")
),
new File(driversFeature, "nefarius_BthPS3_Updater.exe")
),
// registry values
new RegKey(driversFeature, RegistryHive.LocalMachine,
$@"Software\Nefarius Software Solutions e.U.\{ProductName}",
new RegValue("Path", "[INSTALLDIR]") { Win64 = true },
new RegValue("Version", version.ToString()) { Win64 = true },
new RegValue("DriverVersion", driverVersion.ToString()) { Win64 = true },
new RegValue("FilterVersion", filterVersion.ToString()) { Win64 = true }
) { Win64 = true },
// install drivers
new ElevatedManagedAction(CustomActions.InstallDrivers, Return.check,
When.After,
Step.InstallFiles,
Condition.NOT_Installed
),
// install manifests
new ElevatedManagedAction(CustomActions.InstallManifest, Return.check,
When.After,
Step.InstallFiles,
Condition.NOT_Installed
),
// remove manifests
new ElevatedManagedAction(CustomActions.UninstallManifest, Return.check,
When.Before,
Step.RemoveFiles,
Condition.Installed
),
// register updater
new ManagedAction(CustomActions.RegisterUpdater, Return.check,
When.After,
Step.InstallFinalize,
Condition.NOT_Installed
),
// remove updater cleanly
new ManagedAction(CustomActions.DeregisterUpdater, Return.check,
When.Before,
Step.RemoveFiles,
Condition.Installed
),
new ManagedAction(CustomActions.OpenArticle, Return.check,
When.After,
Step.InstallFinalize,
Condition.NOT_Installed
),
// custom reboot prompt message
new Error("9000",
"Driver installation succeeded but a reboot is required to be fully operational. " +
"After the setup is finished, please reboot the system before using the software."
),
new Error("9001",
"No Bluetooth host radio was found. " +
"This machine has to have working Bluetooth set up for some of the installation/removal steps to succeed. " +
"Setup will now exit."
),
new Error("9002",
"Radio online detection timed out. " +
"This error can be misleading on some systems (using Intel Wireless). " +
"You can ignore the detection error and setup might be able to finish successfully. " +
"You can retry the same operation again, which might fix it. " +
"If you choose to abort, setup will end with an error."
)
)
{
GUID = new Guid("CC32A6ED-BDFE-4D51-9FFF-2AB51D9ECE18"),
CAConfigFile = "CustomActions.config",
OutFileName = $"Nefarius_BthPS3_Drivers_x64_arm64_v{version}",
//custom set of standard UI dialogs
ManagedUI = new ManagedUI(),
Version = version,
Platform = Platform.x64,
WildCardDedup = Project.UniqueFileNameDedup,
DefaultFeature = driversFeature,
LicenceFile = @"..\Setup\BthPS3_EULA.rtf",
BackgroundImage = "left-banner.png",
BannerImage = "top-banner.png"
};
#region Fixes for setups < v2.10.x
// override radio check with success
project.AddProperty(new Property("RADIOFOUND", "1"));
// override old detection check with absent
project.AddProperty(new Property("FILTERNOTFOUND", "1"));
// suppresses reboot dialogs from removing older versions
project.AddProperty(new Property("REBOOT", "ReallySuppress"));
#endregion
project.MajorUpgrade = new MajorUpgrade
{
Schedule = UpgradeSchedule.afterInstallInitialize,
DowngradeErrorMessage = "A later version of [ProductName] is already installed. Setup will now exit."
};
/*
project.Load +=
e =>
{
MessageBox.Show(e.Session.GetMainWindow(), e.ToString(),
"Before (Install/Uninstall) - " + new Version(e.Session["FOUNDPREVIOUSVERSION"]));
};
*/
project.Load += ProjectOnLoad;
project.ManagedUI.InstallDialogs.Add(Dialogs.Welcome)
.Add(Dialogs.Licence)
.Add(Dialogs.Features)
.Add(Dialogs.Progress)
.Add(Dialogs.Exit);
project.ManagedUI.ModifyDialogs.Add(Dialogs.MaintenanceType)
.Add(Dialogs.Features)
.Add(Dialogs.Progress)
.Add(Dialogs.Exit);
project.AfterInstall += ProjectOnAfterInstall;
#region Embed types of dependencies
project.DefaultRefAssemblies.Add(typeof(Devcon).Assembly.Location);
project.DefaultRefAssemblies.Add(typeof(HostRadio).Assembly.Location);
project.DefaultRefAssemblies.Add(typeof(Cli).Assembly.Location);
project.DefaultRefAssemblies.Add(typeof(RegistryKey).Assembly.Location);
project.DefaultRefAssemblies.Add(typeof(ValueTask).Assembly.Location);
project.DefaultRefAssemblies.Add(typeof(IAsyncDisposable).Assembly.Location);
project.DefaultRefAssemblies.Add(typeof(Unsafe).Assembly.Location);
project.DefaultRefAssemblies.Add(typeof(BuffersExtensions).Assembly.Location);
project.DefaultRefAssemblies.Add(typeof(ArrayPool<>).Assembly.Location);
project.DefaultRefAssemblies.Add(typeof(Kernel32.SafeObjectHandle).Assembly.Location);
project.DefaultRefAssemblies.Add(typeof(FilterDriver).Assembly.Location);
project.DefaultRefAssemblies.Add(typeof(BluetoothHelper).Assembly.Location);
project.DefaultRefAssemblies.Add(typeof(SafeRegistryHandle).Assembly.Location);
project.DefaultRefAssemblies.Add(typeof(WixExt).Assembly.Location);
#endregion
#region Control Panel
project.ControlPanelInfo.ProductIcon = @"..\Setup\Icons\B3.ico";
project.ControlPanelInfo.Manufacturer = "Nefarius Software Solutions e.U.";
project.ControlPanelInfo.HelpLink = "https://docs.nefarius.at/Community-Support/";
project.ControlPanelInfo.UrlInfoAbout = "https://github.com/nefarius/BthPS3";
project.ControlPanelInfo.NoModify = true;
#endregion
project.ResolveWildCards();
project.BuildMsi();
}
private static void ProjectOnLoad(SetupEventArgs e)
{
if (HostRadio.IsAvailable)
{
return;
}
Session? session = e.Session;
if (session is null)
{
e.Result = ActionResult.Failure;
return;
}
Record record = new(1);
record[1] = "9001";
session.Message(
InstallMessage.User | (InstallMessage)MessageButtons.OK | (InstallMessage)MessageIcon.Error,
record);
e.Result = ActionResult.UserExit;
}
/// <summary>
/// Put uninstall logic that doesn't access packaged files in here.
/// </summary>
/// <remarks>Runs with elevated privileges.</remarks>
private static void ProjectOnAfterInstall(SetupEventArgs e)
{
if (e.IsUninstalling)
{
CustomActions.UninstallDrivers(e.Session);
}
}
}