Skip to content

Commit

Permalink
Better logging and exception handling for verification
Browse files Browse the repository at this point in the history
  • Loading branch information
jvyden committed Apr 17, 2024
1 parent 26b6a7b commit efd200e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 15 deletions.
3 changes: 3 additions & 0 deletions Refresher/Patching/EbootPatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ public List<Message> Verify(string url, bool patchDigest)

this.Stream.Position = 0;

Program.Log($"URL: {url}", "Verify");
// Check url
if (url.EndsWith('/'))
messages.Add(new Message(MessageLevel.Error,
Expand All @@ -330,6 +331,8 @@ public List<Message> Verify(string url, bool patchDigest)
messages.Add(new Message(MessageLevel.Error, "URI is not valid"));

Class output = ELFReader.CheckELFType(this.Stream);

Program.Log($"ELF class: {output}", "Verify");
if (output == Class.NotELF)
{
messages.Add(new Message(MessageLevel.Error, "File is not a valid ELF file."));
Expand Down
52 changes: 37 additions & 15 deletions Refresher/UI/PatchForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,9 @@ protected void LogMessage(string message)
this._messages.Items.Add(message);
}

protected void Reverify(object? sender, EventArgs e)
protected void Reverify(object? sender, EventArgs args)
{
Program.Log("Reverify triggered");
Program.Log($"Reverify triggered for patcher {this.Patcher?.GetType().Name}");
if (this.Patcher == null) return;

// Cancel the current task, and wait for it to complete
Expand All @@ -287,23 +287,45 @@ protected void Reverify(object? sender, EventArgs e)
// Start a new task to verify the URL
this._latestTask = Task.Factory.StartNew(delegate
{
this._latestToken.Value.ThrowIfCancellationRequested();

// Verify the URL
List<Message> messages = this.Patcher.Verify(url, patchDigest);

this._latestToken.Value.ThrowIfCancellationRequested();
Program.App.AsyncInvoke(() =>
try
{
this._messages.Items.Clear();
foreach (Message message in messages) this._messages.Items.Add(message.ToString());
this._patchButton.Enabled = messages.All(m => m.Level != MessageLevel.Error);
this._patchButton.Text = "Patch!";
});
this._latestToken.Value.ThrowIfCancellationRequested();

// Verify the URL
List<Message> messages = this.Patcher.Verify(url, patchDigest);
this.ResetAfterPatch(messages);

this._latestToken.Value.ThrowIfCancellationRequested();
}
catch (Exception e)
{
SentrySdk.CaptureException(e);
SentrySdk.Flush();
Program.App.AsyncInvoke(() =>
{
MessageBox.Show("An exception occured while verifying.\n" + e, "Verification Failed");
});
List<Message> messages =
[
new Message(MessageLevel.Error, "An exception occured while verifying."),
];
this.ResetAfterPatch(messages);
}
}, this._latestToken.Value);
}

private void ResetAfterPatch(List<Message> messages)
{
Program.App.AsyncInvoke(() =>
{
this._messages.Items.Clear();
foreach (Message message in messages) this.LogMessage(message.ToString());
this._patchButton.Enabled = messages.All(m => m.Level != MessageLevel.Error);
this._patchButton.Text = "Patch!";
});
}

protected override void OnClosing(CancelEventArgs e)
{
Environment.Exit(0);
Expand Down

0 comments on commit efd200e

Please sign in to comment.