Files
LuaCsForBarotraumaEP/Subsurface/Source/Program.cs

106 lines
3.7 KiB
C#

#region Using Statements
using System;
using System.IO;
using System.Reflection;
using System.Text;
#if WINDOWS
using System.Management;
using System.Windows.Forms;
#endif
#endregion
namespace Barotrauma
{
#if WINDOWS || LINUX
/// <summary>
/// The main class.
/// </summary>
public static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
using (var game = new GameMain())
{
#if !DEBUG
try
{
#endif
game.Run();
#if !DEBUG
}
catch (Exception e)
{
CrashDump(game, "crashreport.txt", e);
}
#endif
}
}
public static void CrashMessageBox(string message)
{
#if WINDOWS
MessageBox.Show(message, "Oops! Barotrauma just crashed.", MessageBoxButtons.OK, MessageBoxIcon.Error);
#endif
Sounds.SoundManager.Dispose();
}
static void CrashDump(GameMain game, string filePath, Exception exception)
{
StreamWriter sw = new StreamWriter(filePath);
StringBuilder sb = new StringBuilder();
sb.AppendLine("Barotrauma crash report (generated on " + DateTime.Now + ")");
sb.AppendLine("\n");
sb.AppendLine("Barotrauma seems to have crashed. Sorry for the inconvenience! ");
sb.AppendLine("If you'd like to help fix the bug that caused the crash, please send this file to the developers on the Undertow Games forums.");
sb.AppendLine("\n");
sb.AppendLine("Game version " + GameMain.Version);
sb.AppendLine("Selected content package: " + GameMain.SelectedPackage.Name);
sb.AppendLine("Level seed: "+ ((Level.Loaded == null) ? "no level loaded" : Level.Loaded.Seed));
sb.AppendLine("Loaded submarine: " + ((Submarine.Loaded == null) ? "none" : Submarine.Loaded.Name +" ("+Submarine.Loaded.MD5Hash+")"));
sb.AppendLine("Selected screen: " + (Screen.Selected == null ? "None" : Screen.Selected.ToString()));
if (GameMain.Server != null)
{
sb.AppendLine("Server (" + (GameMain.Server.GameStarted ? "Round had started)" : "Round hand't been started)"));
}
else if (GameMain.Client != null)
{
sb.AppendLine("Client (" + (GameMain.Client.GameStarted ? "Round had started)" : "Round hand't been started)"));
}
sb.AppendLine("\n");
sb.AppendLine("System info:");
sb.AppendLine(" Operating system: " + System.Environment.OSVersion + (System.Environment.Is64BitOperatingSystem ? " 64 bit" : " x86"));
sb.AppendLine("\n");
sb.AppendLine("Exception: "+exception.Message);
sb.AppendLine("Target site: " +exception.TargetSite.ToString());
sb.AppendLine("Stack trace: ");
sb.AppendLine(exception.StackTrace);
sb.AppendLine("\n");
sb.AppendLine("Last debug messages:");
for (int i = DebugConsole.Messages.Count - 1; i > 0 && i > DebugConsole.Messages.Count - 10; i-- )
{
sb.AppendLine(" "+DebugConsole.Messages[i].Time+" - "+DebugConsole.Messages[i].Text);
}
sw.WriteLine(sb.ToString());
sw.Close();
CrashMessageBox( "A crash report (''crashreport.txt'') was saved in the root folder of the game."+
" If you'd like to help fix this bug, please post the report on the Undertow Games forums.");
}
}
#endif
}