mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 18:27:23 +01:00
Miscellaneous fixes
This commit is contained in:
parent
6116508c57
commit
12e2fd3f60
2 changed files with 109 additions and 56 deletions
|
|
@ -212,7 +212,7 @@ public sealed class UiBuilder : IDisposable
|
||||||
/// <code>
|
/// <code>
|
||||||
/// fontAtlas.NewDelegateFontHandle(
|
/// fontAtlas.NewDelegateFontHandle(
|
||||||
/// e => e.OnPreBuild(
|
/// e => e.OnPreBuild(
|
||||||
/// tk => tk.AddDalamudDefaultFont(UiBuilder.DefaultFontSizePt)));
|
/// tk => tk.AddDalamudDefaultFont(UiBuilder.DefaultFontSizePx)));
|
||||||
/// </code>
|
/// </code>
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public IFontHandle DefaultFontHandle =>
|
public IFontHandle DefaultFontHandle =>
|
||||||
|
|
@ -231,6 +231,8 @@ public sealed class UiBuilder : IDisposable
|
||||||
/// fontAtlas.NewDelegateFontHandle(
|
/// fontAtlas.NewDelegateFontHandle(
|
||||||
/// e => e.OnPreBuild(
|
/// e => e.OnPreBuild(
|
||||||
/// tk => tk.AddFontAwesomeIconFont(new() { SizePt = UiBuilder.DefaultFontSizePt })));
|
/// tk => tk.AddFontAwesomeIconFont(new() { SizePt = UiBuilder.DefaultFontSizePt })));
|
||||||
|
/// // or use
|
||||||
|
/// tk => tk.AddFontAwesomeIconFont(new() { SizePx = UiBuilder.DefaultFontSizePx })));
|
||||||
/// </code>
|
/// </code>
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public IFontHandle IconFontHandle =>
|
public IFontHandle IconFontHandle =>
|
||||||
|
|
@ -251,6 +253,8 @@ public sealed class UiBuilder : IDisposable
|
||||||
/// tk => tk.AddDalamudAssetFont(
|
/// tk => tk.AddDalamudAssetFont(
|
||||||
/// DalamudAsset.InconsolataRegular,
|
/// DalamudAsset.InconsolataRegular,
|
||||||
/// new() { SizePt = UiBuilder.DefaultFontSizePt })));
|
/// new() { SizePt = UiBuilder.DefaultFontSizePt })));
|
||||||
|
/// // or use
|
||||||
|
/// new() { SizePx = UiBuilder.DefaultFontSizePx })));
|
||||||
/// </code>
|
/// </code>
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public IFontHandle MonoFontHandle =>
|
public IFontHandle MonoFontHandle =>
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,9 @@ public static class DisposeSafety
|
||||||
public static IDisposable ToDisposableIgnoreExceptions<T>(this Task<T> task)
|
public static IDisposable ToDisposableIgnoreExceptions<T>(this Task<T> task)
|
||||||
where T : IDisposable
|
where T : IDisposable
|
||||||
{
|
{
|
||||||
return Disposable.Create(() => task.ContinueWith(r =>
|
return Disposable.Create(
|
||||||
|
() => task.ContinueWith(
|
||||||
|
r =>
|
||||||
{
|
{
|
||||||
_ = r.Exception;
|
_ = r.Exception;
|
||||||
if (r.IsCompleted)
|
if (r.IsCompleted)
|
||||||
|
|
@ -102,7 +104,8 @@ public static class DisposeSafety
|
||||||
if (disposables is not T[] array)
|
if (disposables is not T[] array)
|
||||||
array = disposables?.ToArray() ?? Array.Empty<T>();
|
array = disposables?.ToArray() ?? Array.Empty<T>();
|
||||||
|
|
||||||
return Disposable.Create(() =>
|
return Disposable.Create(
|
||||||
|
() =>
|
||||||
{
|
{
|
||||||
List<Exception?> exceptions = null;
|
List<Exception?> exceptions = null;
|
||||||
foreach (var d in array)
|
foreach (var d in array)
|
||||||
|
|
@ -137,7 +140,11 @@ public static class DisposeSafety
|
||||||
public event Action<IDisposeCallback, Exception?>? AfterDispose;
|
public event Action<IDisposeCallback, Exception?>? AfterDispose;
|
||||||
|
|
||||||
/// <inheritdoc cref="Stack{T}.EnsureCapacity"/>
|
/// <inheritdoc cref="Stack{T}.EnsureCapacity"/>
|
||||||
public void EnsureCapacity(int capacity) => this.objects.EnsureCapacity(capacity);
|
public void EnsureCapacity(int capacity)
|
||||||
|
{
|
||||||
|
lock (this.objects)
|
||||||
|
this.objects.EnsureCapacity(capacity);
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="Stack{T}.Push"/>
|
/// <inheritdoc cref="Stack{T}.Push"/>
|
||||||
/// <returns>The parameter.</returns>
|
/// <returns>The parameter.</returns>
|
||||||
|
|
@ -145,7 +152,10 @@ public static class DisposeSafety
|
||||||
public T? Add<T>(T? d) where T : IDisposable
|
public T? Add<T>(T? d) where T : IDisposable
|
||||||
{
|
{
|
||||||
if (d is not null)
|
if (d is not null)
|
||||||
|
{
|
||||||
|
lock (this.objects)
|
||||||
this.objects.Add(this.CheckAdd(d));
|
this.objects.Add(this.CheckAdd(d));
|
||||||
|
}
|
||||||
|
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
@ -155,7 +165,10 @@ public static class DisposeSafety
|
||||||
public Action? Add(Action? d)
|
public Action? Add(Action? d)
|
||||||
{
|
{
|
||||||
if (d is not null)
|
if (d is not null)
|
||||||
|
{
|
||||||
|
lock (this.objects)
|
||||||
this.objects.Add(this.CheckAdd(d));
|
this.objects.Add(this.CheckAdd(d));
|
||||||
|
}
|
||||||
|
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
@ -165,7 +178,10 @@ public static class DisposeSafety
|
||||||
public Func<Task>? Add(Func<Task>? d)
|
public Func<Task>? Add(Func<Task>? d)
|
||||||
{
|
{
|
||||||
if (d is not null)
|
if (d is not null)
|
||||||
|
{
|
||||||
|
lock (this.objects)
|
||||||
this.objects.Add(this.CheckAdd(d));
|
this.objects.Add(this.CheckAdd(d));
|
||||||
|
}
|
||||||
|
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
@ -174,7 +190,10 @@ public static class DisposeSafety
|
||||||
public GCHandle Add(GCHandle d)
|
public GCHandle Add(GCHandle d)
|
||||||
{
|
{
|
||||||
if (d != default)
|
if (d != default)
|
||||||
|
{
|
||||||
|
lock (this.objects)
|
||||||
this.objects.Add(this.CheckAdd(d));
|
this.objects.Add(this.CheckAdd(d));
|
||||||
|
}
|
||||||
|
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
@ -183,40 +202,55 @@ public static class DisposeSafety
|
||||||
/// Queue all the given <see cref="IDisposable"/> to be disposed later.
|
/// Queue all the given <see cref="IDisposable"/> to be disposed later.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="ds">Disposables.</param>
|
/// <param name="ds">Disposables.</param>
|
||||||
public void AddRange(IEnumerable<IDisposable?> ds) =>
|
public void AddRange(IEnumerable<IDisposable?> ds)
|
||||||
|
{
|
||||||
|
lock (this.objects)
|
||||||
this.objects.AddRange(ds.Where(d => d is not null).Select(d => (object)this.CheckAdd(d)));
|
this.objects.AddRange(ds.Where(d => d is not null).Select(d => (object)this.CheckAdd(d)));
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Queue all the given <see cref="IDisposable"/> to be run later.
|
/// Queue all the given <see cref="IDisposable"/> to be run later.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="ds">Actions.</param>
|
/// <param name="ds">Actions.</param>
|
||||||
public void AddRange(IEnumerable<Action?> ds) =>
|
public void AddRange(IEnumerable<Action?> ds)
|
||||||
|
{
|
||||||
|
lock (this.objects)
|
||||||
this.objects.AddRange(ds.Where(d => d is not null).Select(d => (object)this.CheckAdd(d)));
|
this.objects.AddRange(ds.Where(d => d is not null).Select(d => (object)this.CheckAdd(d)));
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Queue all the given <see cref="Func{T}"/> returning <see cref="Task"/> to be run later.
|
/// Queue all the given <see cref="Func{T}"/> returning <see cref="Task"/> to be run later.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="ds">Func{Task}s.</param>
|
/// <param name="ds">Func{Task}s.</param>
|
||||||
public void AddRange(IEnumerable<Func<Task>?> ds) =>
|
public void AddRange(IEnumerable<Func<Task>?> ds)
|
||||||
|
{
|
||||||
|
lock (this.objects)
|
||||||
this.objects.AddRange(ds.Where(d => d is not null).Select(d => (object)this.CheckAdd(d)));
|
this.objects.AddRange(ds.Where(d => d is not null).Select(d => (object)this.CheckAdd(d)));
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Queue all the given <see cref="GCHandle"/> to be disposed later.
|
/// Queue all the given <see cref="GCHandle"/> to be disposed later.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="ds">GCHandles.</param>
|
/// <param name="ds">GCHandles.</param>
|
||||||
public void AddRange(IEnumerable<GCHandle> ds) =>
|
public void AddRange(IEnumerable<GCHandle> ds)
|
||||||
|
{
|
||||||
|
lock (this.objects)
|
||||||
this.objects.AddRange(ds.Select(d => (object)this.CheckAdd(d)));
|
this.objects.AddRange(ds.Select(d => (object)this.CheckAdd(d)));
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Cancel all pending disposals.
|
/// Cancel all pending disposals.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>Use this after successful initialization of multiple disposables.</remarks>
|
/// <remarks>Use this after successful initialization of multiple disposables.</remarks>
|
||||||
public void Cancel()
|
public void Cancel()
|
||||||
|
{
|
||||||
|
lock (this.objects)
|
||||||
{
|
{
|
||||||
foreach (var o in this.objects)
|
foreach (var o in this.objects)
|
||||||
this.CheckRemove(o);
|
this.CheckRemove(o);
|
||||||
this.objects.Clear();
|
this.objects.Clear();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="Stack{T}.EnsureCapacity"/>
|
/// <inheritdoc cref="Stack{T}.EnsureCapacity"/>
|
||||||
/// <returns>This for method chaining.</returns>
|
/// <returns>This for method chaining.</returns>
|
||||||
|
|
@ -264,10 +298,16 @@ public static class DisposeSafety
|
||||||
this.BeforeDispose?.InvokeSafely(this);
|
this.BeforeDispose?.InvokeSafely(this);
|
||||||
|
|
||||||
List<Exception>? exceptions = null;
|
List<Exception>? exceptions = null;
|
||||||
while (this.objects.Any())
|
while (true)
|
||||||
{
|
{
|
||||||
var obj = this.objects[^1];
|
object obj;
|
||||||
|
lock (this.objects)
|
||||||
|
{
|
||||||
|
if (this.objects.Count == 0)
|
||||||
|
break;
|
||||||
|
obj = this.objects[^1];
|
||||||
this.objects.RemoveAt(this.objects.Count - 1);
|
this.objects.RemoveAt(this.objects.Count - 1);
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
@ -294,6 +334,7 @@ public static class DisposeSafety
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lock (this.objects)
|
||||||
this.objects.TrimExcess();
|
this.objects.TrimExcess();
|
||||||
|
|
||||||
if (exceptions is not null)
|
if (exceptions is not null)
|
||||||
|
|
@ -318,10 +359,16 @@ public static class DisposeSafety
|
||||||
this.BeforeDispose?.InvokeSafely(this);
|
this.BeforeDispose?.InvokeSafely(this);
|
||||||
|
|
||||||
List<Exception>? exceptions = null;
|
List<Exception>? exceptions = null;
|
||||||
while (this.objects.Any())
|
while (true)
|
||||||
{
|
{
|
||||||
var obj = this.objects[^1];
|
object obj;
|
||||||
|
lock (this.objects)
|
||||||
|
{
|
||||||
|
if (this.objects.Count == 0)
|
||||||
|
break;
|
||||||
|
obj = this.objects[^1];
|
||||||
this.objects.RemoveAt(this.objects.Count - 1);
|
this.objects.RemoveAt(this.objects.Count - 1);
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
@ -351,6 +398,7 @@ public static class DisposeSafety
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lock (this.objects)
|
||||||
this.objects.TrimExcess();
|
this.objects.TrimExcess();
|
||||||
|
|
||||||
if (exceptions is not null)
|
if (exceptions is not null)
|
||||||
|
|
@ -386,6 +434,7 @@ public static class DisposeSafety
|
||||||
private void OnItemDisposed(IDisposeCallback obj)
|
private void OnItemDisposed(IDisposeCallback obj)
|
||||||
{
|
{
|
||||||
obj.BeforeDispose -= this.OnItemDisposed;
|
obj.BeforeDispose -= this.OnItemDisposed;
|
||||||
|
lock (this.objects)
|
||||||
this.objects.Remove(obj);
|
this.objects.Remove(obj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue