summaryrefslogtreecommitdiff
path: root/StardewModdingAPI
diff options
context:
space:
mode:
authorZoryn Aaron <zoryn4163@gmail.com>2016-02-29 13:39:21 -0500
committerZoryn Aaron <zoryn4163@gmail.com>2016-02-29 13:39:21 -0500
commit150e2000cec5949a17506aa7bb47da9bcf4eb93d (patch)
treec44c8054b02bfafdcf6c3119fe46389ad4deaa13 /StardewModdingAPI
parent9f1ecbcd27bd1376d4968fc2b590ada9c3cff335 (diff)
downloadSMAPI-150e2000cec5949a17506aa7bb47da9bcf4eb93d.tar.gz
SMAPI-150e2000cec5949a17506aa7bb47da9bcf4eb93d.tar.bz2
SMAPI-150e2000cec5949a17506aa7bb47da9bcf4eb93d.zip
error catching
Diffstat (limited to 'StardewModdingAPI')
-rw-r--r--StardewModdingAPI/Program.cs26
1 files changed, 14 insertions, 12 deletions
diff --git a/StardewModdingAPI/Program.cs b/StardewModdingAPI/Program.cs
index 583fc451..c9375322 100644
--- a/StardewModdingAPI/Program.cs
+++ b/StardewModdingAPI/Program.cs
@@ -27,6 +27,7 @@ namespace StardewModdingAPI
public static string ExecutionPath { get; private set; }
public static string DataPath = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "StardewValley"));
public static string ModPath = Path.Combine(Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "StardewValley")), "Mods");
+ public static string LogPath = Path.Combine(Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "StardewValley")), "ErrorLogs");
public static SGame gamePtr;
public static bool ready;
@@ -48,7 +49,9 @@ namespace StardewModdingAPI
{
Console.Title = "Stardew Modding API Console";
- AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
+ Application.ThreadException += Application_ThreadException;
+ Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
+ AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
if (File.Exists(ModPath))
File.Delete(ModPath);
@@ -97,6 +100,8 @@ namespace StardewModdingAPI
Events.InvokeGameLoaded();
}
+
+
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -193,19 +198,16 @@ namespace StardewModdingAPI
StardewForm.Invoke(a);
}
- public static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
+ static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
- string dllName = args.Name.Contains(',') ? args.Name.Substring(0, args.Name.IndexOf(',')) : args.Name.Replace(".dll", "");
-
- dllName = dllName.Replace(".", "_");
-
- if (dllName.EndsWith("_resources")) return null;
-
- System.Resources.ResourceManager rm = new System.Resources.ResourceManager(typeof(Program).Namespace + ".Properties.Resources", System.Reflection.Assembly.GetExecutingAssembly());
-
- byte[] bytes = (byte[])rm.GetObject(dllName);
+ Console.WriteLine("An exception has been caught");
+ File.WriteAllText(Program.LogPath + "\\MODDED_ErrorLog_" + Extensions.Random.Next(100000000, 999999999) + ".txt", e.ExceptionObject.ToString());
+ }
- return System.Reflection.Assembly.Load(bytes);
+ static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
+ {
+ Console.WriteLine("A thread exception has been caught");
+ File.WriteAllText(Program.LogPath + "\\MODDED_ErrorLog_" + Extensions.Random.Next(100000000, 999999999) + ".txt", e.Exception.ToString());
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////