Reuse same list for warnings and exceptions.

This commit is contained in:
Ottermandias 2024-01-27 18:58:26 +01:00
parent e9628afaf8
commit 076dab924f

View file

@ -28,8 +28,8 @@ public partial class ModEditWindow
private bool _dirty; private bool _dirty;
public bool PendingIo { get; private set; } public bool PendingIo { get; private set; }
public List<Exception> IoExceptions { get; private set; } = []; public List<Exception> IoExceptions { get; } = [];
public List<string> IoWarnings { get; private set; } = []; public List<string> IoWarnings { get; } = [];
public MdlTab(ModEditWindow edit, byte[] bytes, string path) public MdlTab(ModEditWindow edit, byte[] bytes, string path)
{ {
@ -92,10 +92,7 @@ public partial class ModEditWindow
.ToList(); .ToList();
}); });
task.ContinueWith(t => task.ContinueWith(t => { GamePaths = FinalizeIo(task); });
{
GamePaths = FinalizeIo(task);
});
} }
private EstManipulation[] GetCurrentEstManipulations() private EstManipulation[] GetCurrentEstManipulations()
@ -246,8 +243,8 @@ public partial class ModEditWindow
private void BeginIo() private void BeginIo()
{ {
PendingIo = true; PendingIo = true;
IoWarnings = []; IoWarnings.Clear();
IoExceptions = []; IoExceptions.Clear();
} }
private void FinalizeIo(Task<IoNotifier> task) private void FinalizeIo(Task<IoNotifier> task)
@ -264,8 +261,9 @@ public partial class ModEditWindow
{ {
result = getResult(task.Result); result = getResult(task.Result);
if (getNotifier != null) if (getNotifier != null)
IoWarnings = getNotifier(task.Result).GetWarnings().ToList(); IoWarnings.AddRange(getNotifier(task.Result).GetWarnings());
} }
PendingIo = false; PendingIo = false;
return result; return result;
@ -273,12 +271,16 @@ public partial class ModEditWindow
private void RecordIoExceptions(Exception? exception) private void RecordIoExceptions(Exception? exception)
{ {
IoExceptions = exception switch switch (exception)
{ {
null => [], case null: break;
AggregateException ae => [.. ae.Flatten().InnerExceptions], case AggregateException ae:
_ => [exception], IoExceptions.AddRange(ae.Flatten().InnerExceptions);
}; break;
default:
IoExceptions.Add(exception);
break;
}
} }
/// <summary> Read a file from the active collection or game. </summary> /// <summary> Read a file from the active collection or game. </summary>