Skip to content

Commit

Permalink
Clean up logging
Browse files Browse the repository at this point in the history
  • Loading branch information
ManlyMarco committed Oct 21, 2020
1 parent e7972c1 commit 1073862
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 28 deletions.
32 changes: 10 additions & 22 deletions src/KKManager.Core/Data/Plugins/PluginLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public static void CancelReload()
/// <param name="pluginDirectory">Directory containing the plugins to gather info from. Usually BepInEx directory inside game root.</param>
private static void TryLoadPlugins(string pluginDirectory, ReplaySubject<PluginInfo> subject)
{
Console.WriteLine("Start loading plugins");

_cancelSource?.Dispose();
_cancelSource = new CancellationTokenSource();
var token = _cancelSource.Token;
Expand Down Expand Up @@ -99,38 +101,24 @@ void ReadPluginsAsync()
Console.WriteLine($"Failed to load plugin from \"{file}\" with error: {ex}");
}
}

subject.OnCompleted();
Console.WriteLine("Finished loading plugins");
}
catch (OperationCanceledException ex)
{
subject.OnCompleted();
}
catch (UnauthorizedAccessException ex)
{
MessageBox.Show("Could not load information about plugins because access to the plugins folder was denied. Check the permissions of your plugins folder and try again.\n\n" + ex.Message,
"Load plugins", MessageBoxButtons.OK, MessageBoxIcon.Warning);

Console.WriteLine(ex);
subject.OnError(ex);
}
catch (SecurityException ex)
catch (OperationCanceledException)
{
MessageBox.Show("Could not load information about plugins because access to the plugins folder was denied. Check the permissions of your plugins folder and try again.\n\n" + ex.Message,
"Load plugins", MessageBoxButtons.OK, MessageBoxIcon.Warning);

Console.WriteLine(ex);
subject.OnError(ex);
}
catch (Exception ex)
{
Console.WriteLine(ex);
if (ex is SecurityException || ex is UnauthorizedAccessException)
MessageBox.Show("Could not load information about plugins because access to the plugins folder was denied. Check the permissions of your plugins folder and try again.\n\n" + ex.Message,
"Load plugins", MessageBoxButtons.OK, MessageBoxIcon.Warning);

Console.WriteLine("Crash when loading plugins: " + ex);
subject.OnError(ex);
}
finally
{
_isUpdating = false;
Console.WriteLine("Finished loading plugins");
subject.OnCompleted();
}
}

Expand Down
18 changes: 12 additions & 6 deletions src/KKManager.Core/Data/Zipmods/SideloaderModLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
using System.IO;
using System.Linq;
using System.Reactive.Subjects;
using System.Security;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml.Linq;
using KKManager.Functions;
using KKManager.Util;
Expand Down Expand Up @@ -53,6 +55,8 @@ public static void CancelReload()
/// <param name="searchOption">Where to search</param>
private static void TryReadSideloaderMods(string modDirectory, ReplaySubject<SideloaderModInfo> subject, SearchOption searchOption = SearchOption.AllDirectories)
{
Console.WriteLine("Start loading zipmods");

_cancelSource?.Dispose();
_cancelSource = new CancellationTokenSource();
var token = _cancelSource.Token;
Expand Down Expand Up @@ -88,25 +92,27 @@ void ReadSideloaderModsAsync()
}
catch (Exception ex)
{
Console.WriteLine($"Failed to load mod from \"{file}\" with error: {ex}");
Console.WriteLine($"Failed to load zipmod from \"{file}\" with error: {ex}");
}
}

subject.OnCompleted();
Console.WriteLine("Finished loading zipmods");
}
catch (OperationCanceledException)
{
subject.OnCompleted();
}
catch (Exception ex)
{
Console.WriteLine(ex);
if (ex is SecurityException || ex is UnauthorizedAccessException)
MessageBox.Show("Could not load information about zipmods because access to the plugins folder was denied. Check the permissions of your mods folder and try again.\n\n" + ex.Message,
"Load zipmods", MessageBoxButtons.OK, MessageBoxIcon.Warning);

Console.WriteLine("Crash when loading zipmods: " + ex);
subject.OnError(ex);
}
finally
{
_isUpdating = false;
Console.WriteLine("Finished loading zipmods");
subject.OnCompleted();
}
}

Expand Down

0 comments on commit 1073862

Please sign in to comment.