diff --git a/Laerdal.Dfu/Laerdal.Dfu.csproj.DotSettings b/Laerdal.Dfu/Laerdal.Dfu.csproj.DotSettings
index e304b59..74fc16c 100644
--- a/Laerdal.Dfu/Laerdal.Dfu.csproj.DotSettings
+++ b/Laerdal.Dfu/Laerdal.Dfu.csproj.DotSettings
@@ -3,6 +3,7 @@
True
True
True
+ True
True
True
True
diff --git a/Laerdal.Dfu/Platforms.Droid/DfuInstallation.cs b/Laerdal.Dfu/Platforms.Droid/DfuInstallation.cs
index d751140..7ce470d 100644
--- a/Laerdal.Dfu/Platforms.Droid/DfuInstallation.cs
+++ b/Laerdal.Dfu/Platforms.Droid/DfuInstallation.cs
@@ -13,101 +13,83 @@ namespace Laerdal.Dfu
{
public partial class DfuInstallation
{
- public Func CustomDfuServiceInitiatorConfiguration { get; set; } = (dfuInitiator) => dfuInitiator;
+ public Func CustomDfuServiceInitiatorConfiguration { get; set; } = dfuInitiator => dfuInitiator;
private void SetInitiator()
{
- DfuProgressListener = new DfuProgressListener(this);
DfuLogger = new DfuLogger(DeviceId);
+ DfuProgressListener = new DfuProgressListener(this);
- Initiator = new Laerdal.Dfu.Bindings.Android.DfuServiceInitiator(DeviceId).SetZip(FileUrl);
-
- // PacketsReceiptNotifications
- Initiator = Initiator.SetPacketsReceiptNotificationsEnabled(PacketReceiptNotificationParameter.HasValue);
- Initiator = Initiator.SetPacketsReceiptNotificationsValue(PacketReceiptNotificationParameter ?? Laerdal.Dfu.Bindings.Android.DfuServiceInitiator.DefaultPrnValue);
-
- // DataObjectPreparationDelay
- Initiator = Initiator.SetPrepareDataObjectDelay((long) (DataObjectPreparationDelay ?? 0));
+ Initiator = new Laerdal.Dfu.Bindings.Android.DfuServiceInitiator(DeviceId).SetZip(FileUrl)!;
+ Initiator = Initiator.SetPacketsReceiptNotificationsEnabled(PacketReceiptNotificationParameter.HasValue)!; // PacketsReceiptNotifications
+ Initiator = Initiator.SetPacketsReceiptNotificationsValue(PacketReceiptNotificationParameter ?? Laerdal.Dfu.Bindings.Android.DfuServiceInitiator.DefaultPrnValue)!;
+ Initiator = Initiator.SetPrepareDataObjectDelay((long) (DataObjectPreparationDelay ?? 0))!; // DataObjectPreparationDelay
- // DisableResume
if (DisableResume ?? false)
{
- Initiator = Initiator.DisableResume();
+ Initiator = Initiator.DisableResume()!;
}
- // AlternativeAdvertisingName
if (!string.IsNullOrEmpty(AlternativeAdvertisingName))
{
- Initiator = Initiator.SetDeviceName(AlternativeAdvertisingName);
+ Initiator = Initiator.SetDeviceName(AlternativeAdvertisingName)!;
}
- // ForceScanningForNewAddressInLegacyDfu
if (ForceScanningForNewAddressInLegacyDfu.HasValue)
{
- Initiator = Initiator.SetForceScanningForNewAddressInLegacyDfu(ForceScanningForNewAddressInLegacyDfu.Value);
+ Initiator = Initiator.SetForceScanningForNewAddressInLegacyDfu(ForceScanningForNewAddressInLegacyDfu.Value)!;
}
- // EnableUnsafeExperimentalButtonlessServiceInSecureDfu
if (EnableUnsafeExperimentalButtonlessServiceInSecureDfu.HasValue)
{
- Initiator = Initiator.SetUnsafeExperimentalButtonlessServiceInSecureDfuEnabled(EnableUnsafeExperimentalButtonlessServiceInSecureDfu.Value);
+ Initiator = Initiator.SetUnsafeExperimentalButtonlessServiceInSecureDfuEnabled(EnableUnsafeExperimentalButtonlessServiceInSecureDfu.Value)!;
}
-
- // ForceDfu
+
if (ForceDfu.HasValue)
{
- Initiator = Initiator.SetForceDfu(ForceDfu.Value);
+ Initiator = Initiator.SetForceDfu(ForceDfu.Value)!;
}
- // DisableMtuRequest
if (DisableMtuRequest ?? false)
{
- Initiator = Initiator.DisableMtuRequest();
+ Initiator = Initiator.DisableMtuRequest()!;
}
- // DisableNotification
if (DisableNotification.HasValue)
{
- Initiator = Initiator.SetDisableNotification(DisableNotification.Value);
+ Initiator = Initiator.SetDisableNotification(DisableNotification.Value)!;
}
- // MbrSize
- Initiator = Initiator.SetMbrSize(MbrSize ?? Laerdal.Dfu.Bindings.Android.DfuServiceInitiator.DefaultMbrSize);
+ Initiator = Initiator.SetMbrSize(MbrSize ?? Laerdal.Dfu.Bindings.Android.DfuServiceInitiator.DefaultMbrSize)!;
- // Scope
if (Scope.HasValue)
{
- Initiator = Initiator.SetScope((int) Scope.Value);
+ Initiator = Initiator.SetScope((int) Scope.Value)!;
}
- // Foreground
if (Foreground.HasValue)
{
- Initiator = Initiator.SetForeground(Foreground.Value);
+ Initiator = Initiator.SetForeground(Foreground.Value)!;
}
-
- // KeepBond
+
if (KeepBond.HasValue)
{
- Initiator = Initiator.SetKeepBond(KeepBond.Value);
+ Initiator = Initiator.SetKeepBond(KeepBond.Value)!;
}
- // RestoreBond
if (RestoreBond.HasValue)
{
- Initiator = Initiator.SetRestoreBond(RestoreBond.Value);
+ Initiator = Initiator.SetRestoreBond(RestoreBond.Value)!;
}
- // Mtu
if (Mtu.HasValue)
{
- Initiator = Initiator.SetMtu(Mtu.Value);
+ Initiator = Initiator.SetMtu(Mtu.Value)!;
}
-
- // NumberOfRetries
+
if (NumberOfRetries.HasValue)
{
- Initiator = Initiator.SetNumberOfRetries(NumberOfRetries.Value);
+ Initiator = Initiator.SetNumberOfRetries(NumberOfRetries.Value)!;
}
// For Oreo progress
@@ -116,7 +98,7 @@ private void SetInitiator()
Laerdal.Dfu.Bindings.Android.DfuServiceInitiator.CreateDfuNotificationChannel(Android.App.Application.Context);
}
- Initiator = CustomDfuServiceInitiatorConfiguration?.Invoke(Initiator);
+ Initiator = CustomDfuServiceInitiatorConfiguration?.Invoke(Initiator)!;
// public DfuServiceInitiator SetCurrentMtu(int mtu)
// public DfuServiceInitiator SetCustomUuidsForButtonlessDfuWithBondSharing(UUID buttonlessDfuServiceUuid, UUID buttonlessDfuControlPointUuid)
@@ -126,28 +108,24 @@ private void SetInitiator()
// public DfuServiceInitiator SetCustomUuidsForSecureDfu(UUID dfuServiceUuid, UUID dfuControlPointUuid, UUID dfuPacketUuid)
}
+ private DfuLogger DfuLogger { get; set;}
+ private DfuProgressListener DfuProgressListener { get; set;}
+
public Laerdal.Dfu.Bindings.Android.DfuServiceInitiator Initiator { get; private set; }
-
public Laerdal.Dfu.Bindings.Android.DfuServiceController Controller { get; private set; }
- private DfuProgressListener DfuProgressListener { get; set;}
-
- private DfuLogger DfuLogger { get; set;}
-
public DfuInstallation(string deviceId, string fileUrl) : base(deviceId, fileUrl)
{
}
- public DfuInstallation() : base()
+ public DfuInstallation()
{
}
public override void Start()
{
if (Controller != null)
- {
throw new System.Exception("Controller is already set.");
- }
SetInitiator();
Controller = Initiator.Start(Android.App.Application.Context, Class.FromType(typeof(DfuService)));
@@ -170,26 +148,31 @@ public override void Abort()
protected override void Dispose(bool disposing)
{
+ if (!disposing)
+ return;
+
DfuProgressListener?.Dispose();
- if (disposing)
- {
- Initiator?.Dispose();
- Controller?.Dispose();
- DfuLogger?.Dispose();
- }
+ DfuProgressListener = null;
+
+ Initiator?.Dispose();
+ Initiator = null;
+
+ Controller?.Dispose();
+ Controller = null;
+
+ DfuLogger?.Dispose();
+ DfuLogger = null;
}
public bool CheckDeviceAddress(string deviceAddress)
{
if (deviceAddress == DeviceId)
- {
return true;
- }
var parsed = DeviceId.Split(':').Select(p => int.Parse(p, NumberStyles.HexNumber)).ToList();
parsed[^1] += 1;
+
var deviceAddressPlusOne = string.Join(":", parsed.Select(p => p.ToString("X2")));
-
if (deviceAddress == deviceAddressPlusOne)
{
return true;
diff --git a/Laerdal.Dfu/Platforms.iOSandMacCatalyst/DfuInstallation.cs b/Laerdal.Dfu/Platforms.iOSandMacCatalyst/DfuInstallation.cs
index 56518d1..ddbb10e 100644
--- a/Laerdal.Dfu/Platforms.iOSandMacCatalyst/DfuInstallation.cs
+++ b/Laerdal.Dfu/Platforms.iOSandMacCatalyst/DfuInstallation.cs
@@ -7,19 +7,18 @@ namespace Laerdal.Dfu
public partial class DfuInstallation
{
public static Func Queue { get; set; } = () => DispatchQueue.GetGlobalQueue(DispatchQueuePriority.Default);
+ public static Func LoggerQueue { get; set; } = () => DispatchQueue.GetGlobalQueue(DispatchQueuePriority.Default);
public static Func DelegateQueue { get; set; } = () => DispatchQueue.GetGlobalQueue(DispatchQueuePriority.Default);
public static Func ProgressQueue { get; set; } = () => DispatchQueue.GetGlobalQueue(DispatchQueuePriority.Default);
- public static Func LoggerQueue { get; set; } = () => DispatchQueue.GetGlobalQueue(DispatchQueuePriority.Default);
-
- public Func CustomDfuServiceInitiatorConfiguration { get; set; } = (dfuInitiator) => dfuInitiator;
+ public Func CustomDfuServiceInitiatorConfiguration { get; set; } = dfuInitiator => dfuInitiator;
private void SetInitiator()
{
- DfuProgressDelegate = new DfuProgressDelegate(this);
DfuServiceDelegate = new DfuServiceDelegate(this);
+ DfuProgressDelegate = new DfuProgressDelegate(this);
DfuPeripheralSelectorDelegate = new DfuPeripheralSelectorDelegate(this);
- Firmware = new Laerdal.Dfu.Bindings.iOS.DFUFirmware(new NSUrl(FileUrl, false), out NSError error);
+ Firmware = new Laerdal.Dfu.Bindings.iOS.DFUFirmware(new NSUrl(FileUrl, isDir: false), out _);
Initiator = new Laerdal.Dfu.Bindings.iOS.DFUServiceInitiator(
queue: Queue.Invoke(),
@@ -30,74 +29,75 @@ private void SetInitiator()
)
{
Logger = new DfuLogger(),
- WeakProgressDelegate = DfuProgressDelegate,
WeakDelegate = DfuServiceDelegate,
+ WeakProgressDelegate = DfuProgressDelegate,
};
+
Initiator = Initiator.WithFirmware(Firmware);
- // PacketsReceiptNotifications
if (PacketReceiptNotificationParameter.HasValue)
+ {
Initiator.PacketReceiptNotificationParameter = PacketReceiptNotificationParameter.Value;
- // DataObjectPreparationDelay
+ }
if (DataObjectPreparationDelay.HasValue)
+ {
Initiator.DataObjectPreparationDelay = DataObjectPreparationDelay.Value;
+ }
- // DisableResume
if (DisableResume.HasValue)
+ {
Initiator.DisableResume = DisableResume.Value;
+ }
- // AlternativeAdvertisingName
- Initiator.AlternativeAdvertisingNameEnabled = !string.IsNullOrEmpty(AlternativeAdvertisingName);
Initiator.AlternativeAdvertisingName = AlternativeAdvertisingName;
- // ForceScanningForNewAddressInLegacyDfu
+ Initiator.AlternativeAdvertisingNameEnabled = !string.IsNullOrEmpty(AlternativeAdvertisingName);
if (ForceScanningForNewAddressInLegacyDfu.HasValue)
+ {
Initiator.ForceScanningForNewAddressInLegacyDfu = ForceScanningForNewAddressInLegacyDfu.Value;
- // EnableUnsafeExperimentalButtonlessServiceInSecureDfu
+ }
if (EnableUnsafeExperimentalButtonlessServiceInSecureDfu.HasValue)
+ {
Initiator.ForceScanningForNewAddressInLegacyDfu = EnableUnsafeExperimentalButtonlessServiceInSecureDfu.Value;
- // ForceDfu
+ }
if (ForceDfu.HasValue)
+ {
Initiator.ForceDfu = ForceDfu.Value;
+ }
- // ConnectionTimeout
if (ConnectionTimeout.HasValue)
+ {
Initiator.ConnectionTimeout = ConnectionTimeout.Value;
+ }
Initiator = CustomDfuServiceInitiatorConfiguration?.Invoke(Initiator);
-
- // public DFUUuidHelper UuidHelper {get; set;}
}
- public Laerdal.Dfu.Bindings.iOS.DFUServiceInitiator Initiator { get; private set; }
-
+ public Laerdal.Dfu.Bindings.iOS.DFUFirmware Firmware { get; private set; }public Laerdal.Dfu.Bindings.iOS.DFUServiceInitiator Initiator { get; private set; }
public Laerdal.Dfu.Bindings.iOS.DFUServiceController Controller { get; private set; }
- public Laerdal.Dfu.Bindings.iOS.DFUFirmware Firmware { get; private set; }
+ private DfuServiceDelegate DfuServiceDelegate { get;set; }
private DfuProgressDelegate DfuProgressDelegate { get; set; }
- private DfuServiceDelegate DfuServiceDelegate { get; set; }
+
private DfuPeripheralSelectorDelegate DfuPeripheralSelectorDelegate { get; set; }
-
public DfuInstallation(string deviceId, string fileUrl) : base(deviceId, fileUrl)
{
}
- public DfuInstallation() : base()
+ public DfuInstallation()
{
}
public override void Start()
{
if (Controller != null)
- {
throw new System.Exception("Controller is already set.");
- }
SetInitiator();
Controller = Initiator.StartWithTargetWithIdentifier(new NSUuid(DeviceId));
@@ -120,12 +120,26 @@ public override void Abort()
protected override void Dispose(bool disposing)
{
- if (disposing)
- {
- Initiator?.Dispose();
- Controller?.Dispose();
- Firmware?.Dispose();
- }
+ if (!disposing)
+ return;
+
+ DfuServiceDelegate?.Dispose();
+ DfuServiceDelegate = null;
+
+ DfuProgressDelegate?.Dispose();
+ DfuProgressDelegate = null;
+
+ DfuPeripheralSelectorDelegate?.Dispose();
+ DfuPeripheralSelectorDelegate = null;
+
+ Firmware?.Dispose();
+ Firmware = null;
+
+ Initiator?.Dispose();
+ Initiator = null;
+
+ Controller?.Dispose();
+ Controller = null;
}
}
}
\ No newline at end of file