[AaruFormat] Implement Close.

This commit is contained in:
2025-10-11 17:03:30 +01:00
parent 57b60bc7dd
commit 2074181ee6
3 changed files with 56 additions and 4 deletions

View File

@@ -6,7 +6,7 @@ namespace Aaru.Images;
/// <inheritdoc cref="Aaru.CommonTypes.Interfaces.IWritableOpticalImage" />
/// <summary>Implements reading and writing AaruFormat media images</summary>
public sealed partial class AaruFormat : IWritableOpticalImage, IVerifiableImage, IWritableTapeImage
public sealed partial class AaruFormat : IWritableOpticalImage, IVerifiableImage, IWritableTapeImage, IDisposable
{
const string MODULE_NAME = "Aaru Format plugin";

View File

@@ -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
/// <inheritdoc />
public void Dispose()
{
ReleaseUnmanagedResources();
GC.SuppressFinalize(this);
}
#endregion
#region IWritableOpticalImage Members
/// <inheritdoc />
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;
}
/// <inheritdoc />
~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);
}

View File

@@ -50,9 +50,6 @@ public sealed partial class AaruFormat
public bool Create(string path, MediaType mediaType, Dictionary<string, string> options, ulong sectors,
uint sectorSize) => throw new NotImplementedException();
/// <inheritdoc />
public bool Close() => throw new NotImplementedException();
/// <inheritdoc />
public bool SetMetadata(Metadata metadata) => throw new NotImplementedException();