diff --git a/Aaru.Images/AaruFormat/AaruFormat.cs b/Aaru.Images/AaruFormat/AaruFormat.cs index 405f20649..a2da9d7ce 100644 --- a/Aaru.Images/AaruFormat/AaruFormat.cs +++ b/Aaru.Images/AaruFormat/AaruFormat.cs @@ -6,7 +6,7 @@ namespace Aaru.Images; /// /// Implements reading and writing AaruFormat media images -public sealed partial class AaruFormat : IWritableOpticalImage, IVerifiableImage, IWritableTapeImage +public sealed partial class AaruFormat : IWritableOpticalImage, IVerifiableImage, IWritableTapeImage, IDisposable { const string MODULE_NAME = "Aaru Format plugin"; diff --git a/Aaru.Images/AaruFormat/Close.cs b/Aaru.Images/AaruFormat/Close.cs new file mode 100644 index 000000000..3d3ab8c7c --- /dev/null +++ b/Aaru.Images/AaruFormat/Close.cs @@ -0,0 +1,55 @@ +using System; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +namespace Aaru.Images; + +public sealed partial class AaruFormat +{ +#region IDisposable Members + + /// + public void Dispose() + { + ReleaseUnmanagedResources(); + GC.SuppressFinalize(this); + } + +#endregion + +#region IWritableOpticalImage Members + + /// + public bool Close() + { + if(_context == IntPtr.Zero) return false; + + int res = aaruf_close(_context); + + _context = IntPtr.Zero; + + return res == 0; + } + +#endregion + + void ReleaseUnmanagedResources() + { + if(_context == IntPtr.Zero) return; + + aaruf_close(_context); + + _context = IntPtr.Zero; + } + + /// + ~AaruFormat() + { + ReleaseUnmanagedResources(); + } + + // AARU_EXPORT int AARU_CALL aaruf_close(void *context) + [LibraryImport("libaaruformat", EntryPoint = "aaruf_close", SetLastError = true)] + [UnmanagedCallConv(CallConvs = [typeof(CallConvStdcall)])] + private static partial int aaruf_close(IntPtr context); +} \ No newline at end of file diff --git a/Aaru.Images/AaruFormat/Unimplemented.cs b/Aaru.Images/AaruFormat/Unimplemented.cs index 75f6f2d48..c26f75bcd 100644 --- a/Aaru.Images/AaruFormat/Unimplemented.cs +++ b/Aaru.Images/AaruFormat/Unimplemented.cs @@ -50,9 +50,6 @@ public sealed partial class AaruFormat public bool Create(string path, MediaType mediaType, Dictionary options, ulong sectors, uint sectorSize) => throw new NotImplementedException(); - /// - public bool Close() => throw new NotImplementedException(); - /// public bool SetMetadata(Metadata metadata) => throw new NotImplementedException();