checkpoint for real
This commit is contained in:
95
Database.cs
95
Database.cs
@@ -1,4 +1,95 @@
|
||||
$HEADER$namespace $NAMESPACE$
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Foodsoft.Alpm
|
||||
{
|
||||
public class $CLASS$ {$END$}
|
||||
public sealed class Database : IDisposable
|
||||
{
|
||||
private readonly SafeDatabaseHandle _handle;
|
||||
|
||||
internal Database(SafeDatabaseHandle handle) => _handle = handle;
|
||||
|
||||
private readonly struct ServersAccessor : IItemsAccessor<string>
|
||||
{
|
||||
private readonly SafeDatabaseHandle _handle;
|
||||
|
||||
internal ServersAccessor(SafeDatabaseHandle handle)
|
||||
{
|
||||
_handle = handle;
|
||||
}
|
||||
|
||||
public SafeAlpmHandle SafeAlpmHandle => _handle.SafeAlpmHandle;
|
||||
public IntPtr GetItems() => alpm.alpm_db_get_servers(_handle);
|
||||
public int SetItems(IntPtr list) => alpm.alpm_db_set_servers(_handle, list);
|
||||
public int AddItem(string item) => alpm.alpm_db_add_server(_handle, item);
|
||||
public int RemoveItem(string item) => alpm.alpm_db_remove_server(_handle, item);
|
||||
public IntPtr FindItem(string item) => alpm.alpm_list_find_str(GetItems(), item);
|
||||
public string PtrToItem(IntPtr p) => Marshal.PtrToStringUTF8(p)!;
|
||||
}
|
||||
|
||||
public ICollection<string> Servers
|
||||
{
|
||||
get => new CollectionWrapper<ServersAccessor, string>(new ServersAccessor(_handle));
|
||||
set
|
||||
{
|
||||
foreach (var s in value)
|
||||
{
|
||||
API.WrapError(_handle.SafeAlpmHandle, () => alpm.alpm_db_add_server(_handle, s));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public string Name => alpm.alpm_db_get_name(_handle);
|
||||
|
||||
public SigLevel SigLevel => alpm.alpm_db_get_siglevel(_handle);
|
||||
|
||||
public ErrNo Valid =>
|
||||
alpm.alpm_db_get_valid(_handle) != 0 ? alpm.alpm_errno(_handle.SafeAlpmHandle) : ErrNo.ERR_OK;
|
||||
|
||||
public bool Update(bool force)
|
||||
{
|
||||
var err = alpm.alpm_db_update(force ? 1 : 0, _handle);
|
||||
if (err < 0)
|
||||
{
|
||||
throw new Exception(_handle.SafeAlpmHandle);
|
||||
}
|
||||
|
||||
return err == 0;
|
||||
}
|
||||
|
||||
public Package? GetPackage(string name)
|
||||
{
|
||||
var pkgPtr = alpm.alpm_pkg_get_pkg(_handle, name);
|
||||
if (pkgPtr == IntPtr.Zero)
|
||||
{
|
||||
var err = alpm.alpm_errno(_handle.SafeAlpmHandle);
|
||||
if (err == ErrNo.ERR_PKG_NOT_FOUND)
|
||||
return null;
|
||||
throw new Exception(err);
|
||||
}
|
||||
return new CachePackage(new SafeCachePackageHandle(pkgPtr, _handle), this);
|
||||
}
|
||||
|
||||
private readonly struct PkgCacheAccessor : IReadOnlyItemsAccessor<Package>
|
||||
{
|
||||
private readonly SafeDatabaseHandle _handle;
|
||||
public SafeAlpmHandle SafeAlpmHandle => _handle.SafeAlpmHandle;
|
||||
public IntPtr GetItems()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Package PtrToItem(IntPtr p)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_handle.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user