basic implementation, tabling for now

This commit is contained in:
2020-05-01 06:44:48 -04:00
committed by John K. Luebs
parent 1a394ddb31
commit 60d093dbad
11 changed files with 210 additions and 140 deletions

View File

@@ -1,14 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Nullable>enable</Nullable>
<RootNamespace>Foodsoft.Alpm</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="2020.1.0" />
</ItemGroup>
</Project>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Nullable>enable</Nullable>
<RootNamespace>Foodsoft.Alpm</RootNamespace>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageId>DotNetAlpm</PackageId>
<PackageVersion />
<Title>DotNetAlpm</Title>
<Copyright>(C) 2020 The DotNetAlpm authors</Copyright>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="2020.1.0" />
</ItemGroup>
</Project>

3
Alpm/AssemblyInfo.cs Normal file
View File

@@ -0,0 +1,3 @@
using System;
[assembly: CLSCompliant(true)]

12
Alpm/Capabilities.cs Normal file
View File

@@ -0,0 +1,12 @@
using System;
namespace Foodsoft.Alpm
{
[Flags]
public enum Capabilities
{
Nls = (1 << 0),
Downloader = (1 << 1),
Signatures = (1 << 2)
}
}

View File

@@ -11,14 +11,14 @@ namespace Foodsoft.Alpm
Name = Marshal.PtrToStringUTF8(native->name)!;
Version = Marshal.PtrToStringUTF8(native->version)!;
Description = Marshal.PtrToStringUTF8(native->description)!;
NameHash = native->name_hash;
NameHash = (long)native->name_hash;
Mod = native->mod;
}
public string Name { get; }
public string Version { get; }
public string Description { get; }
public ulong NameHash { get; }
public Int64 NameHash { get; }
public ModType Mod { get; }
public bool Equals(Depend? other)

View File

@@ -44,7 +44,7 @@ namespace Foodsoft.Alpm
{
return handle.UseHandle(handle.DangerousGetHandle(), op);
}
internal static void SetStringCollection(IEnumerable<string> value, SafeAlpmHandle safeAlpmHandle,
Func<string, int> op)
{

View File

@@ -8,7 +8,7 @@ namespace Foodsoft.Alpm
public string Name { get; }
public long Size { get; }
public uint Mode { get; }
public int Mode { get; }
[StructLayout(LayoutKind.Sequential)]
internal readonly unsafe struct NativeFile
@@ -23,7 +23,7 @@ namespace Foodsoft.Alpm
var native = (NativeFile*) ptr;
Name = new string(native->Name);
Size = native->size;
Mode = native->mode;
Mode = (int) native->mode;
}
}
}

View File

@@ -9,7 +9,7 @@ namespace Foodsoft.Alpm
private readonly object _eventLock = new object();
private readonly SafeAlpmHandle _handle;
private EventHandler<LogEventArgs> _logEvent;
private EventHandler<LogEventArgs>? _logEvent;
public Handle(string root, string dbPath)
{
@@ -26,7 +26,7 @@ namespace Foodsoft.Alpm
set => Detail.SetStringCollection(value, _handle, s => alpm.alpm_option_add_cachedir(_handle, s));
}
public LogLevel LogLevel { get; set; }
public LogLevel LogLevel { get; set; } = LogLevel.Error;
public void Dispose()
{
@@ -54,7 +54,7 @@ namespace Foodsoft.Alpm
public bool RemoveCacheDir(string dir)
{
return Detail.WrapErrorBool(_handle, () => alpm.alpm_option_add_cachedir(_handle, dir));
return Detail.WrapErrorBool(_handle, () => alpm.alpm_option_remove_cachedir(_handle, dir));
}
public bool ShouldIgnorePackage(Package pkg)

View File

@@ -2,8 +2,8 @@ using System;
using System.Runtime.InteropServices;
namespace Foodsoft.Alpm
{
{
/*
* Hooks
*/
@@ -158,33 +158,6 @@ namespace Foodsoft.Alpm
public readonly uint mode;
}
public enum caps
{
ALPM_CAPABILITY_NLS = (1 << 0),
ALPM_CAPABILITY_DOWNLOADER = (1 << 1),
ALPM_CAPABILITY_SIGNATURES = (1 << 2)
}
/** Package filelist container */
public struct _alpm_filelist_t
{
public UIntPtr count;
private IntPtr files;
/* FIXME: This is broken as shit */
public alpm_file_t[] Unmarshal()
{
var iCount = (int) this.count;
var byteCount = Marshal.SizeOf<alpm_file_t>() * iCount;
var byteBuffer = new byte[byteCount];
Marshal.Copy(files, byteBuffer, 0, byteBuffer.Length);
var result = new alpm_file_t[iCount];
Buffer.BlockCopy(byteBuffer, 0, result, 0, byteBuffer.Length);
return result;
}
}
/** Local package or package file backup entry */
public struct _alpm_backup_t
{

View File

@@ -14,273 +14,272 @@ namespace Foodsoft.Alpm
}
// ReSharper disable once InconsistentNaming
// ReSharper disable IdentifierTypo
internal static class alpm
{
public delegate void alpm_fn_free(IntPtr ptr);
[DllImport(nameof(alpm))]
[DllImport(nameof(alpm), CallingConvention = CallingConvention.Cdecl)]
public static extern int alpm_pkg_should_ignore(SafeAlpmHandle handle, SafePackageHandle pkg);
[DllImport(nameof(alpm))]
[DllImport(nameof(alpm), CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(UTF8Return))]
public static extern string alpm_pkg_get_filename(SafePackageHandle pkg);
[DllImport(nameof(alpm))]
[DllImport(nameof(alpm), CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(UTF8Return))]
public static extern string alpm_pkg_get_base(SafePackageHandle pkg);
[DllImport(nameof(alpm))]
[DllImport(nameof(alpm), CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(UTF8Return))]
public static extern string alpm_pkg_get_name(SafePackageHandle pkg);
[DllImport(nameof(alpm))]
[DllImport(nameof(alpm), CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(UTF8Return))]
public static extern string alpm_pkg_get_name(IntPtr pkg);
[DllImport(nameof(alpm))]
[DllImport(nameof(alpm), CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(UTF8Return))]
public static extern string alpm_pkg_get_version(SafePackageHandle pkg);
[DllImport(nameof(alpm))]
[DllImport(nameof(alpm), CallingConvention = CallingConvention.Cdecl)]
public static extern PackageOrigin alpm_pkg_get_origin(SafePackageHandle pkg);
[DllImport(nameof(alpm))]
[DllImport(nameof(alpm), CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(UTF8Return))]
public static extern string alpm_pkg_get_desc(SafePackageHandle pkg);
[DllImport(nameof(alpm))]
[DllImport(nameof(alpm), CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(UTF8Return))]
public static extern string alpm_pkg_get_url(SafePackageHandle pkg);
[DllImport(nameof(alpm))]
[DllImport(nameof(alpm), CallingConvention = CallingConvention.Cdecl)]
public static extern long alpm_pkg_get_builddate(SafePackageHandle pkg);
[DllImport(nameof(alpm))]
[DllImport(nameof(alpm), CallingConvention = CallingConvention.Cdecl)]
public static extern long alpm_pkg_get_installdate(SafePackageHandle pkg);
[DllImport(nameof(alpm))]
[DllImport(nameof(alpm), CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(UTF8Return))]
public static extern string alpm_pkg_get_packager(SafePackageHandle pkg);
[DllImport(nameof(alpm))]
[DllImport(nameof(alpm), CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(UTF8Return))]
public static extern string alpm_pkg_get_md5sum(SafePackageHandle pkg);
[DllImport(nameof(alpm))]
[DllImport(nameof(alpm), CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(UTF8Return))]
public static extern string alpm_pkg_get_sha256sum(SafePackageHandle pkg);
[DllImport(nameof(alpm))]
[DllImport(nameof(alpm), CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(UTF8Return))]
public static extern string alpm_pkg_get_arch(SafePackageHandle pkg);
[DllImport(nameof(alpm))]
[DllImport(nameof(alpm), CallingConvention = CallingConvention.Cdecl)]
public static extern long alpm_pkg_get_size(SafePackageHandle pkg);
[DllImport(nameof(alpm))]
[DllImport(nameof(alpm), CallingConvention = CallingConvention.Cdecl)]
public static extern long alpm_pkg_get_isize(SafePackageHandle pkg);
[DllImport(nameof(alpm))]
[DllImport(nameof(alpm), CallingConvention = CallingConvention.Cdecl)]
public static extern InstallReason alpm_pkg_get_reason(SafePackageHandle pkg);
[DllImport(nameof(alpm))]
[DllImport(nameof(alpm), CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr alpm_pkg_get_licenses(SafePackageHandle pkg);
[DllImport(nameof(alpm))]
[DllImport(nameof(alpm), CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr alpm_pkg_get_groups(SafePackageHandle pkg);
[DllImport(nameof(alpm))]
[DllImport(nameof(alpm), CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr alpm_pkg_get_depends(SafePackageHandle pkg);
[DllImport(nameof(alpm))]
[DllImport(nameof(alpm), CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr alpm_pkg_get_optdepends(SafePackageHandle pkg);
[DllImport(nameof(alpm))]
[DllImport(nameof(alpm), CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr alpm_pkg_get_checkdepends(SafePackageHandle pkg);
[DllImport(nameof(alpm))]
[DllImport(nameof(alpm), CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr alpm_pkg_get_makedepends(SafePackageHandle pkg);
[DllImport(nameof(alpm))]
[DllImport(nameof(alpm), CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr alpm_pkg_get_conflicts(SafePackageHandle pkg);
[DllImport(nameof(alpm))]
[DllImport(nameof(alpm), CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr alpm_pkg_get_provides(SafePackageHandle pkg);
[DllImport(nameof(alpm))]
[DllImport(nameof(alpm), CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr alpm_pkg_get_replaces(SafePackageHandle pkg);
[DllImport(nameof(alpm))]
[DllImport(nameof(alpm), CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr alpm_pkg_get_files(SafePackageHandle pkg);
[DllImport(nameof(alpm))]
[DllImport(nameof(alpm), CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr alpm_pkg_get_backup(SafePackageHandle pkg);
[DllImport(nameof(alpm))]
[DllImport(nameof(alpm), CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr alpm_filelist_contains(IntPtr fileList,
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(UTF8In))]
string path);
[DllImport(nameof(alpm))]
[DllImport(nameof(alpm), CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(UTF8Return))]
public static extern string alpm_pkg_get_base64_sig(SafePackageHandle pkg);
[DllImport(nameof(alpm))]
[DllImport(nameof(alpm), CallingConvention = CallingConvention.Cdecl)]
public static extern ValidationType alpm_pkg_get_validation(SafePackageHandle pkg);
[DllImport(nameof(alpm))]
[DllImport(nameof(alpm), CallingConvention = CallingConvention.Cdecl)]
public static extern bool alpm_pkg_has_scriptlet(SafePackageHandle pkg);
[DllImport(nameof(alpm))]
[DllImport(nameof(alpm), CallingConvention = CallingConvention.Cdecl)]
public static extern long alpm_pkg_download_size(SafePackageHandle pkg);
[DllImport(nameof(alpm))]
[DllImport(nameof(alpm), CallingConvention = CallingConvention.Cdecl)]
public static extern int alpm_pkg_set_reason(SafePackageHandle pkg, InstallReason reason);
[DllImport(nameof(alpm))]
[DllImport(nameof(alpm), CallingConvention = CallingConvention.Cdecl)]
public static extern int alpm_pkg_checkmd5sum(SafePackageHandle pkg);
[DllImport(nameof(alpm))]
[DllImport(nameof(alpm), CallingConvention = CallingConvention.Cdecl)]
public static extern int alpm_pkg_free(IntPtr ptr);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate void LogFuncCallBack(LogLevel level, IntPtr format, IntPtr argsAddress);
[DllImport(nameof(alpm))]
[DllImport(nameof(alpm), CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr alpm_option_set_logcb(SafeAlpmHandle handle, LogFuncCallBack? cb);
[DllImport(nameof(alpm))]
[DllImport(nameof(alpm), CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr alpm_option_get_cachedirs(SafeAlpmHandle handle);
[DllImport(nameof(alpm))]
[DllImport(nameof(alpm), CallingConvention = CallingConvention.Cdecl)]
public static extern int alpm_option_add_cachedir(SafeAlpmHandle handle,
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(UTF8In))]
string cachedir);
[DllImport(nameof(alpm))]
[DllImport(nameof(alpm), CallingConvention = CallingConvention.Cdecl)]
public static extern int alpm_option_remove_cachedir(SafeAlpmHandle handle,
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(UTF8In))]
string cachedir);
[DllImport(nameof(alpm))]
[DllImport(nameof(alpm), CallingConvention = CallingConvention.Cdecl)]
public static extern ErrorCode alpm_errno(SafeAlpmHandle handle);
[DllImport(nameof(alpm))]
[DllImport(nameof(alpm), CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(UTF8Return))]
public static extern string alpm_strerror(ErrorCode err);
[DllImport(nameof(alpm))]
[DllImport(nameof(alpm), CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr alpm_get_localdb(SafeAlpmHandle handle);
[DllImport(nameof(alpm))]
[DllImport(nameof(alpm), CallingConvention = CallingConvention.Cdecl)]
public static extern unsafe alpm_list_t* alpm_option_get_syncdbs();
[DllImport(nameof(alpm))]
[DllImport(nameof(alpm), CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr alpm_register_syncdb(SafeAlpmHandle handle,
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(UTF8In))]
string treename, SigLevel sigLevel);
[DllImport(nameof(alpm))]
[DllImport(nameof(alpm), CallingConvention = CallingConvention.Cdecl)]
public static extern int alpm_db_unregister_all_syncdbs(SafeAlpmHandle handle);
[DllImport(nameof(alpm))]
[DllImport(nameof(alpm), CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr alpm_list_append(ref IntPtr list, IntPtr item);
[DllImport(nameof(alpm))]
[DllImport(nameof(alpm), CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr alpm_list_append_strdup(ref IntPtr list,
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(UTF8In))]
string str);
[DllImport(nameof(alpm))]
public static extern IntPtr alpm_list_next(IntPtr list);
[DllImport(nameof(alpm))]
[DllImport(nameof(alpm), CallingConvention = CallingConvention.Cdecl)]
public static extern UIntPtr alpm_list_count(IntPtr list);
[DllImport(nameof(alpm))]
[DllImport(nameof(alpm), CallingConvention = CallingConvention.Cdecl)]
public static extern void alpm_list_free(IntPtr list);
[DllImport(nameof(alpm))]
public static extern void alpm_list_free_inner(IntPtr list, alpm_fn_free freeFn);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void AlpmFnFree(IntPtr ptr);
[DllImport(nameof(alpm), CallingConvention = CallingConvention.Cdecl)]
public static extern void alpm_list_free_inner(IntPtr list, AlpmFnFree freeFn);
[DllImport(nameof(alpm))]
[DllImport(nameof(alpm), CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr alpm_list_find_str(IntPtr list,
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(UTF8In))]
string needle);
[DllImport(nameof(alpm))]
[DllImport(nameof(alpm), CallingConvention = CallingConvention.Cdecl)]
public static extern int alpm_unlock(Handle handle);
[DllImport(nameof(alpm))]
[DllImport(nameof(alpm), CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(UTF8Return))]
public static extern string alpm_version();
[DllImport(nameof(alpm))]
public static extern caps alpm_capabilities();
[DllImport(nameof(alpm), CallingConvention = CallingConvention.Cdecl)]
public static extern Capabilities alpm_capabilities();
[DllImport(nameof(alpm))]
[DllImport(nameof(alpm), CallingConvention = CallingConvention.Cdecl)]
public static extern SafeAlpmHandle alpm_initialize(
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(UTF8In))]
string root, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(UTF8In))]
string dbpath, out ErrorCode err);
[DllImport(nameof(alpm))]
[DllImport(nameof(alpm), CallingConvention = CallingConvention.Cdecl)]
public static extern int alpm_release(IntPtr handle);
[DllImport(nameof(alpm))]
[DllImport(nameof(alpm), CallingConvention = CallingConvention.Cdecl)]
public static extern int alpm_db_remove_server(SafeDatabaseHandle db,
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(UTF8In))]
string url);
[DllImport(nameof(alpm))]
[DllImport(nameof(alpm), CallingConvention = CallingConvention.Cdecl)]
public static extern int alpm_db_unregister(IntPtr db);
[DllImport(nameof(alpm))]
[DllImport(nameof(alpm), CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(UTF8Return))]
public static extern string alpm_db_get_name(SafeDatabaseHandle db);
[DllImport(nameof(alpm))]
[DllImport(nameof(alpm), CallingConvention = CallingConvention.Cdecl)]
public static extern SigLevel alpm_db_get_siglevel(SafeDatabaseHandle db);
[DllImport(nameof(alpm))]
[DllImport(nameof(alpm), CallingConvention = CallingConvention.Cdecl)]
public static extern int alpm_db_get_valid(SafeDatabaseHandle db);
[DllImport(nameof(alpm))]
[DllImport(nameof(alpm), CallingConvention = CallingConvention.Cdecl)]
public static extern int alpm_db_update(int force, SafeDatabaseHandle db);
[DllImport(nameof(alpm))]
[DllImport(nameof(alpm), CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr alpm_db_get_servers(SafeDatabaseHandle db);
[DllImport(nameof(alpm))]
[DllImport(nameof(alpm), CallingConvention = CallingConvention.Cdecl)]
public static extern int alpm_db_set_servers(SafeDatabaseHandle db, IntPtr list);
[DllImport(nameof(alpm))]
[DllImport(nameof(alpm), CallingConvention = CallingConvention.Cdecl)]
public static extern int alpm_db_add_server(SafeDatabaseHandle db,
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(UTF8In))]
string url);
[DllImport(nameof(alpm))]
[DllImport(nameof(alpm), CallingConvention = CallingConvention.Cdecl)]
public static extern int alpm_db_get_usage(SafeDatabaseHandle db, out Database.UsageFlags usage);
[DllImport(nameof(alpm))]
[DllImport(nameof(alpm), CallingConvention = CallingConvention.Cdecl)]
public static extern int alpm_db_set_usage(SafeDatabaseHandle db, Database.UsageFlags usage);
[DllImport(nameof(alpm))]
[DllImport(nameof(alpm), CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr alpm_db_search(SafeDatabaseHandle db, IntPtr needles);
[DllImport(nameof(alpm))]
[DllImport(nameof(alpm), CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr alpm_pkg_get_pkg(SafeDatabaseHandle db,
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(UTF8In))]
string name);
[DllImport(nameof(alpm))]
[DllImport(nameof(alpm), CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr alpm_db_get_pkgcache(SafeDatabaseHandle db);
[DllImport(nameof(alpm))]
[DllImport(nameof(alpm), CallingConvention = CallingConvention.Cdecl)]
public static extern int alpm_pkg_vercmp(string v1, string v2);
[DllImport(nameof(alpm))]
[DllImport(nameof(alpm), CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr alpm_find_satisfier(IntPtr pkgList, string depstring);
}
}