mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-12 23:37:07 +00:00
Better catch program init exceptions (plugins)
Discard plugins that fail to load, rather than aborting the entire plugin load operation Add friendly message for unzipping fail (no PKHeX.Core.dll self-extracted).
This commit is contained in:
parent
b187633ec6
commit
9479e8cb5f
2 changed files with 30 additions and 5 deletions
|
@ -280,8 +280,20 @@ public partial class Main : Form
|
|||
WinFormsUtil.Error(MsgPluginFailLoad, c);
|
||||
return;
|
||||
}
|
||||
foreach (var p in Plugins.OrderBy(z => z.Priority))
|
||||
p.Initialize(C_SAV, PKME_Tabs, menuStrip1, Program.CurrentVersion);
|
||||
|
||||
var list = Plugins.OrderBy(z => z.Priority).ToList();
|
||||
foreach (var p in list)
|
||||
{
|
||||
try
|
||||
{
|
||||
p.Initialize(C_SAV, PKME_Tabs, menuStrip1, Program.CurrentVersion);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
WinFormsUtil.Error(MsgPluginFailLoad, ex);
|
||||
Plugins.Remove(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Main Menu Strip UI Functions
|
||||
|
|
|
@ -83,9 +83,13 @@ internal static class Program
|
|||
|
||||
private static string GetErrorMessage(Exception e)
|
||||
{
|
||||
return IsPluginError<IPlugin>(e, out var pluginName)
|
||||
? $"An error occurred in a PKHeX plugin. Please report this error to the plugin author/maintainer.\n{pluginName}"
|
||||
: "An error occurred in PKHeX. Please report this error to the PKHeX author.";
|
||||
try
|
||||
{
|
||||
if (IsPluginError<IPlugin>(e, out var pluginName))
|
||||
return $"An error occurred in a PKHeX plugin. Please report this error to the plugin author/maintainer.\n{pluginName}";
|
||||
}
|
||||
catch { }
|
||||
return "An error occurred in PKHeX. Please report this error to the PKHeX author.";
|
||||
}
|
||||
|
||||
// Handle the UI exceptions by showing a dialog box, and asking the user if they wish to abort execution.
|
||||
|
@ -100,6 +104,10 @@ internal static class Program
|
|||
{
|
||||
Error("You have upgraded PKHeX incorrectly. Please delete PKHeX.Core.dll.");
|
||||
}
|
||||
else if (IsPkhexCoreMissing(ex))
|
||||
{
|
||||
Error("You have installed PKHeX incorrectly. Please ensure you have unzipped all files before running.");
|
||||
}
|
||||
else if (ex != null)
|
||||
{
|
||||
var msg = GetErrorMessage(ex);
|
||||
|
@ -185,5 +193,10 @@ internal static class Program
|
|||
&& File.Exists("PKHeX.Core.dll")
|
||||
&& AssemblyName.GetAssemblyName("PKHeX.Core.dll").Version < CurrentVersion;
|
||||
}
|
||||
|
||||
private static bool IsPkhexCoreMissing(Exception? ex)
|
||||
{
|
||||
return ex is FileNotFoundException { FileName: {} n } && n.Contains("PKHeX.Core");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue