checkpoint

This commit is contained in:
2020-04-29 23:47:06 -04:00
parent 64f7dd4b7d
commit 19a9fc06ba
31 changed files with 678 additions and 360 deletions

View File

@@ -13,7 +13,7 @@ namespace Foodsoft.Alpm
_handle = alpm.alpm_initialize(root, dbpath, out var err);
if (_handle.IsInvalid)
{
throw new Exception(err);
throw new AlpmException(err);
}
}
@@ -28,7 +28,7 @@ namespace Foodsoft.Alpm
// managed by the alpm handle.
if (ptr == IntPtr.Zero)
{
throw new Exception(_handle);
throw new AlpmException(_handle);
}
return new Database(new SafeDatabaseHandle(ptr, _handle));
@@ -36,40 +36,28 @@ namespace Foodsoft.Alpm
public Database LocalDB => ToDatabase(alpm.alpm_get_localdb(_handle));
public Database RegisterSyncDB(string treename, SigLevel sigLevel) =>
public Database RegisterSyncDB(string treename, SigLevel sigLevel = 0) =>
ToDatabase(alpm.alpm_register_syncdb(_handle, treename, sigLevel));
public void AddCacheDir(string dir) => API.WrapError(_handle, () => alpm.alpm_option_add_cachedir(_handle, dir));
public bool RemoveCacheDir(string dir) => API.WrapErrorBool(_handle, () => alpm.alpm_option_add_cachedir(_handle, dir));
private readonly struct CacheDirsAccessor : IItemsAccessor<string>
private readonly struct CacheDirsImpl : ICollectionImpl<string>
{
internal CacheDirsAccessor(SafeAlpmHandle safeAlpmHandle)
{
SafeAlpmHandle = safeAlpmHandle;
}
public SafeAlpmHandle SafeAlpmHandle { get; }
public IntPtr GetItems() => alpm.alpm_option_get_cachedirs(SafeAlpmHandle);
public int SetItems(IntPtr list) => alpm.alpm_option_set_cachedirs(SafeAlpmHandle, list);
public int AddItem(string item) => alpm.alpm_option_add_cachedir(SafeAlpmHandle, item);
public int RemoveItem(string item) => alpm.alpm_option_remove_cachedir(SafeAlpmHandle, item);
public IntPtr FindItem(string item) => alpm.alpm_list_find_str(GetItems(), item);
private readonly SafeAlpmHandle _handle;
internal CacheDirsImpl(SafeAlpmHandle handle) => _handle = handle;
public SafeHandle Handle => _handle;
public IntPtr GetItems() => alpm.alpm_option_get_cachedirs(_handle);
public string PtrToItem(IntPtr p) => Marshal.PtrToStringUTF8(p)!;
}
public ICollection<string> CacheDirs
{
get => new CollectionWrapper<CacheDirsAccessor, string>(new CacheDirsAccessor(_handle));
set
{
foreach (var s in value)
{
API.WrapError(_handle, () => alpm.alpm_option_add_cachedir(_handle, s));
}
}
get =>
EnumerableWrapperEx<string>.Create(_handle, alpm.alpm_option_get_cachedirs, Marshal.PtrToStringUTF8!);
set => Wrapper.SetStringCollection(value, _handle, (s) => alpm.alpm_option_add_cachedir(_handle, s));
}
public bool ShouldIgnorePackage(Package pkg)
{
return alpm.alpm_pkg_should_ignore(_handle, pkg.Handle) == 0;
}
public bool ShouldIgnorePackage(Package pkg) => alpm.alpm_pkg_should_ignore(_handle, pkg.Handle) == 0;
}
}