Skip to content

Commit

Permalink
Setup fixes (#113)
Browse files Browse the repository at this point in the history
* Updated and fixed EULA for setup

* Added new setup images

* Simplified URL launch

* Fixed #112

* Improved exception logging

* Updated dependencies

Removed duplicate code
  • Loading branch information
nefarius authored Oct 2, 2024
1 parent b0a2f71 commit 13170c7
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 94 deletions.
5 changes: 3 additions & 2 deletions BthPS3Installer/BthPS3Installer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@
<PackageReference Include="CliWrap" Version="3.6.6" />
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="8.0.0" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Nefarius.Utilities.WixSharp" Version="1.0.0" />
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="6.0.0" />
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.4" />
<PackageReference Include="Nefarius.Utilities.Bluetooth" Version="1.6.1" />
<PackageReference Include="Nefarius.Utilities.DeviceManagement" Version="4.0.0" />
<PackageReference Include="WixSharp_wix4" Version="2.3.2" />
<PackageReference Include="Nefarius.Utilities.DeviceManagement" Version="4.0.1" />
<PackageReference Include="WixSharp_wix4" Version="2.4.0" />
</ItemGroup>

<ItemGroup>
Expand Down
128 changes: 78 additions & 50 deletions BthPS3Installer/InstallScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,18 @@
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

using CliWrap;
using CliWrap.Buffered;

using Microsoft.Win32;
using Microsoft.Win32.SafeHandles;

using Nefarius.BthPS3.Setup.Util;
using Nefarius.BthPS3.Shared;
using Nefarius.Utilities.Bluetooth;
using Nefarius.Utilities.DeviceManagement.Drivers;
using Nefarius.Utilities.DeviceManagement.PnP;
using Nefarius.Utilities.WixSharp.Util;

using PInvoke;

Expand Down Expand Up @@ -83,10 +82,10 @@ private static void Main()
new Dir(driversFeature, "nefcon")
{
Files = new DirFiles(driversFeature, "*.*").GetFiles(nefconDir),
Dirs = GetSubDirectories(driversFeature, nefconDir).ToArray()
Dirs = WixExt.GetSubDirectories(driversFeature, nefconDir).ToArray()
},
// driver binaries
new Dir(driversFeature, "drivers") { Dirs = GetSubDirectories(driversFeature, DriversRoot).ToArray() },
new Dir(driversFeature, "drivers") { Dirs = WixExt.GetSubDirectories(driversFeature, DriversRoot).ToArray() },
// manifest files
new Dir(driversFeature, ManifestsDir,
new File(driversFeature, @"..\BthPS3\BthPS3.man"),
Expand Down Expand Up @@ -165,7 +164,10 @@ private static void Main()
Version = version,
Platform = Platform.x64,
WildCardDedup = Project.UniqueFileNameDedup,
DefaultFeature = driversFeature
DefaultFeature = driversFeature,
LicenceFile = @"..\Setup\BthPS3_EULA.rtf",
BackgroundImage = "left-banner.png",
BannerImage = "top-banner.png"
};

#region Fixes for setups < v2.10.x
Expand Down Expand Up @@ -278,27 +280,6 @@ private static void ProjectOnAfterInstall(SetupEventArgs e)
CustomActions.UninstallDrivers(e.Session);
}
}

/// <summary>
/// Recursively resolves all subdirectories and their containing files.
/// </summary>
private static List<Dir> GetSubDirectories(Feature feature, string directory)
{
List<Dir> subDirectoryInfosCollection = new();

foreach (string subDirectory in Directory.GetDirectories(directory))
{
string subDirectoryName = subDirectory.Remove(0, subDirectory.LastIndexOf('\\') + 1);
Dir newDir =
new(feature, subDirectoryName, new Files(feature, subDirectory + @"\*.*")) { Name = subDirectoryName };
subDirectoryInfosCollection.Add(newDir);

// Recursively traverse nested directories
GetSubDirectories(feature, subDirectory);
}

return subDirectoryInfosCollection;
}
}

public static class CustomActions
Expand All @@ -313,15 +294,14 @@ public static ActionResult OpenArticle(Session session)
return ActionResult.Success;
}

CommandResult? result = Cli.Wrap("explorer")
.WithArguments("https://docs.nefarius.at/projects/BthPS3/Welcome/Installation-Successful/")
.WithValidation(CommandResultValidation.None)
.ExecuteAsync()
.GetAwaiter()
.GetResult();

session.Log(
$"Post-installation article launch {(result.IsSuccess ? "succeeded" : "failed")}, exit code: {result.ExitCode}");
try
{
Process.Start("https://docs.nefarius.at/projects/BthPS3/Welcome/Installation-Successful/");
}
catch (Exception ex)
{
session.Log($"Spawning article process failed with {ex}");
}

return ActionResult.Success;
}
Expand Down Expand Up @@ -412,24 +392,50 @@ public static ActionResult InstallDrivers(Session session)

#region Restart radio

AutoResetEvent waitEvent = new(false);
DeviceNotificationListener listener = new();

try
{

listener.RegisterDeviceArrived(RadioDeviceArrived, HostRadio.DeviceInterface);

void RadioDeviceArrived(DeviceEventArgs obj)
{
session.Log("Radio arrival event, path: {0}", obj.SymLink);
waitEvent.Set();
}

session.Log("Restarting radio device");
// restart device, filter is loaded afterward
HostRadio.RestartRadioDevice();
session.Log("Restarted radio device");
// safety margin
Thread.Sleep(1000);
session.Log("Waiting for radio device to come online...");

// wait until either event fired OR the timeout has been reached
if (!HostRadio.IsAvailable && !waitEvent.WaitOne(TimeSpan.FromSeconds(30)))
{
session.Log("Timeout reached while waiting for radio to come online");
return ActionResult.Failure;
}

session.Log("Radio device online");
}
catch (Exception ex)
{
session.Log($"Restarting radio device failed with error {ex}");
}
finally
{
listener.Dispose();
}

#endregion

#region Profile driver

session.Log("Installing profile driver");

if (!Devcon.Install(bthPs3InfPath, out bool profileRebootRequired))
{
int error = Marshal.GetLastWin32Error();
Expand All @@ -439,6 +445,8 @@ public static ActionResult InstallDrivers(Session session)
return ActionResult.Failure;
}

session.Log("Installed profile driver");

if (profileRebootRequired)
{
rebootRequired = true;
Expand All @@ -448,6 +456,8 @@ public static ActionResult InstallDrivers(Session session)

#region NULL driver

session.Log("Installing NULL driver");

if (!Devcon.Install(bthPs3NullInfPath, out bool nullRebootRequired))
{
int error = Marshal.GetLastWin32Error();
Expand All @@ -457,6 +467,8 @@ public static ActionResult InstallDrivers(Session session)
return ActionResult.Failure;
}

session.Log("Installed NULL driver");

if (nullRebootRequired)
{
rebootRequired = true;
Expand All @@ -466,31 +478,47 @@ public static ActionResult InstallDrivers(Session session)

#region Profile driver service

HostRadio radio = new();

try
{
session.Log("Enabling BthPS3 service");
// enable service, spawns profile driver PDO
radio.EnableService(InstallScript.BthPs3ServiceGuid, InstallScript.BthPs3ServiceName);
session.Log("Enabled BthPS3 service");
HostRadio radio = new();

try
{
session.Log("Enabling BthPS3 service");
// enable service, spawns profile driver PDO
radio.EnableService(InstallScript.BthPs3ServiceGuid, InstallScript.BthPs3ServiceName);
session.Log("Enabled BthPS3 service");
}
catch (Exception ex)
{
session.Log($"Enabling service failed with error {ex}");
return ActionResult.Failure;
}
finally
{
radio.Dispose();
}
}
catch (Exception ex)
{
session.Log($"Enabling service or radio failed with error {ex}");
session.Log($"Enabling radio failed with error {ex}");
return ActionResult.Failure;
}
finally
{
radio.Dispose();
}

#endregion

#region Filter settings

// make sure patching is enabled, might not be in the registry
FilterDriver.IsFilterEnabled = true;
try
{
// make sure patching is enabled, might not be in the registry
FilterDriver.IsFilterEnabled = true;
}
catch (Exception ex)
{
session.Log($"Enabling filter failed with {ex}");
return ActionResult.Failure;
}

#endregion

Expand Down
31 changes: 0 additions & 31 deletions BthPS3Installer/Util/ArchitectureInfo.cs

This file was deleted.

11 changes: 0 additions & 11 deletions BthPS3Installer/Util/StringExtensions.cs

This file was deleted.

Binary file added BthPS3Installer/left-banner.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added BthPS3Installer/top-banner.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Setup/BthPS3_EULA.rtf
Binary file not shown.

0 comments on commit 13170c7

Please sign in to comment.