mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
[AaruFormat] Implement Create.
This commit is contained in:
@@ -1,16 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Aaru.CommonTypes;
|
||||
|
||||
namespace Aaru.Images;
|
||||
|
||||
public sealed partial class AaruFormat
|
||||
{
|
||||
#region IWritableOpticalImage Members
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool Create(string path, MediaType mediaType, Dictionary<string, string> options, ulong sectors,
|
||||
uint sectorSize) => throw new NotImplementedException();
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -1,6 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using Aaru.CommonTypes;
|
||||
using Aaru.CommonTypes.Enums;
|
||||
|
||||
namespace Aaru.Images;
|
||||
@@ -106,6 +109,45 @@ public sealed partial class AaruFormat
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool Create(string path, MediaType mediaType, Dictionary<string, string> options, ulong sectors,
|
||||
uint sectorSize)
|
||||
{
|
||||
// Get application major and minor version
|
||||
Version version = typeof(AaruFormat).Assembly.GetName().Version;
|
||||
var majorVersion = (byte)(version?.Major ?? 0);
|
||||
var minorVersion = (byte)(version?.Minor ?? 0);
|
||||
|
||||
// Convert options dictionary to string format
|
||||
string optionsString = options is { Count: > 0 }
|
||||
? string.Join(";", options.Select(kvp => $"{kvp.Key}={kvp.Value}"))
|
||||
: null;
|
||||
|
||||
const string applicationName = "Aaru";
|
||||
|
||||
// Create the image context
|
||||
_context = aaruf_create(path,
|
||||
mediaType,
|
||||
sectorSize,
|
||||
sectors,
|
||||
0,
|
||||
0,
|
||||
optionsString,
|
||||
applicationName,
|
||||
(byte)applicationName.Length,
|
||||
majorVersion,
|
||||
minorVersion,
|
||||
IsTape);
|
||||
|
||||
if(_context != IntPtr.Zero) return true;
|
||||
|
||||
int errno = Marshal.GetLastWin32Error();
|
||||
var status = (Status)errno;
|
||||
ErrorMessage = StatusToErrorMessage(status);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
// AARU_EXPORT int32_t AARU_CALL aaruf_write_sector(void *context, uint64_t sector_address, bool negative,
|
||||
@@ -138,4 +180,21 @@ public sealed partial class AaruFormat
|
||||
private static partial Status aaruf_write_sector_tag(IntPtr context, ulong sectorAddress,
|
||||
[MarshalAs(UnmanagedType.I4)] bool negative, [In] byte[] data,
|
||||
ulong length, SectorTagType tag);
|
||||
|
||||
// AARU_EXPORT void AARU_CALL *aaruf_create(const char *filepath, const uint32_t media_type, const uint32_t sector_size,
|
||||
// const uint64_t user_sectors, const uint64_t negative_sectors,
|
||||
// const uint64_t overflow_sectors, const char *options,
|
||||
// const uint8_t *application_name, const uint8_t application_name_length,
|
||||
// const uint8_t application_major_version,
|
||||
// const uint8_t application_minor_version, const bool is_tape)
|
||||
[LibraryImport("libaaruformat",
|
||||
EntryPoint = "aaruf_create",
|
||||
SetLastError = true,
|
||||
StringMarshalling = StringMarshalling.Utf8)]
|
||||
[UnmanagedCallConv(CallConvs = [typeof(CallConvStdcall)])]
|
||||
private static partial IntPtr aaruf_create(string filepath, MediaType mediaType, uint sectorSize, ulong userSectors,
|
||||
ulong negativeSectors, ulong overflowSectors, string options,
|
||||
string applicationName, byte applicationNameLength,
|
||||
byte applicationMajorVersion, byte applicationMinorVersion,
|
||||
[MarshalAs(UnmanagedType.I4)] bool isTape);
|
||||
}
|
||||
Reference in New Issue
Block a user