diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 030ebc2..01d7550 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,8 +1,6 @@ name: main on: - push: - branches: [ main ] pull_request: branches: [ main ] diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 566cca4..107f641 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -14,7 +14,7 @@ jobs: fetch-depth: 0 - name: Build - run: (cd source && dotnet build Burntime.MonoGl -c Release /p:DebugSymbols=false /p:PublishReadyToRun=false /p:TieredCompilation=false --self-contained /p:PublishSingleFile=true && cd ..) + run: (cd source && dotnet publish Burntime.MonoGl -c Release /p:DebugSymbols=false /p:PublishReadyToRun=false /p:TieredCompilation=false --self-contained /p:PublishSingleFile=true && cd ..) - name: Package run: | diff --git a/source/Burntime.Core/Log.cs b/source/Burntime.Core/Log.cs index 3eed588..0bd38c8 100644 --- a/source/Burntime.Core/Log.cs +++ b/source/Burntime.Core/Log.cs @@ -2,7 +2,7 @@ public class Log { - static StreamWriter file; + public static StreamWriter? File { get; private set; } public static bool DebugOut; public static string FormatPercentage(float factor) => System.Math.Round(factor * 100) + "%"; @@ -10,33 +10,33 @@ public class Log static public void Initialize(String file) { - Log.file = new StreamWriter(file, false); + Log.File = new StreamWriter(file, false); } static public void Info(String str) { - if (file != null) + if (File != null) { - file.WriteLine("[info] " + str); - file.Flush(); + File.WriteLine("[info] " + str); + File.Flush(); } } static public void Warning(String str) { - if (file != null) + if (File != null) { - file.WriteLine("[warning] " + str); - file.Flush(); + File.WriteLine("[warning] " + str); + File.Flush(); } } static public void Debug(String str) { - if (file != null && DebugOut) + if (File != null && DebugOut) { - file.WriteLine("[debug] " + str); - file.Flush(); + File.WriteLine("[debug] " + str); + File.Flush(); } } } diff --git a/source/Burntime.MonoGl/BurntimeGame.cs b/source/Burntime.MonoGl/BurntimeGame.cs index 87eedc6..d25f3d6 100644 --- a/source/Burntime.MonoGl/BurntimeGame.cs +++ b/source/Burntime.MonoGl/BurntimeGame.cs @@ -75,8 +75,11 @@ public BurntimeGame() protected override void Initialize() { Log.Initialize("log.txt"); + Log.Info(System.DateTime.Now.ToLocalTime().ToString()); + string version = FileVersionInfo.GetVersionInfo(System.IO.Path.Combine(System.AppContext.BaseDirectory, "burntime.exe")).ProductVersion ?? "?"; + Log.Info("Burntime version " + version); - Window.Title = "Burntime " + FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).ProductVersion ?? "?"; + Window.Title = "Burntime " + version; FileSystem.BasePath = ""; FileSystem.AddPackage("system", "system"); diff --git a/source/Burntime.MonoGl/CustomExceptionHandler.cs b/source/Burntime.MonoGl/CustomExceptionHandler.cs new file mode 100644 index 0000000..a391016 --- /dev/null +++ b/source/Burntime.MonoGl/CustomExceptionHandler.cs @@ -0,0 +1,72 @@ +using System; +//using System.Windows.Forms; +using System.IO; +using System.Threading; + +namespace Burntime +{ + //public class CustomExceptionHandler + //{ + // public void OnThreadException(object sender, UnhandledExceptionEventArgs args) + // { + // Exception e = args.ExceptionObject as Exception; + // if (e == null) + // { + // MessageBox.Show("Error: Unknown", "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop); + // } + // else + // { + // ErrorMsg.LogException(e); + + // MessageBox.Show("Error: " + e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop); + // } + + // // close + // Environment.Exit(1); + // } + //}; + + static class ErrorMsg + { + //public static void ShowError(string msg) + //{ + // MessageBox.Show("Error: " + msg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); + //} + + //public static void ShowError(string msg, Exception e) + //{ + // MessageBox.Show("Error: " + msg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); + // LogException(e); + //} + + // add exception to errorlog.txt + public static void LogException(Exception exception) + { + var log = (StreamWriter writer, Exception e) => + { + writer.WriteLine(); + writer.WriteLine("----------------------------------------------------------------------"); + writer.WriteLine(System.DateTime.Now.ToLocalTime().ToString()); + writer.WriteLine("exception: " + e.Message); + writer.WriteLine("trace:"); + writer.Write(e.StackTrace); + writer.WriteLine(); + + writer.Flush(); + writer.Close(); + }; + + try + { + if (Platform.Log.File is not null) + log(Platform.Log.File, exception); + } + catch { } + + using StreamWriter writer = new("crash.txt", true); + log(writer, exception); + +#warning TODO message box? + } + } +} diff --git a/source/Burntime.MonoGl/Program.cs b/source/Burntime.MonoGl/Program.cs index 4176505..ba2ac21 100644 --- a/source/Burntime.MonoGl/Program.cs +++ b/source/Burntime.MonoGl/Program.cs @@ -1,3 +1,21 @@  +using Burntime; + +#if (DEBUG) + using var game = new Burntime.MonoGl.BurntimeGame(); game.Run(); + +#else + +try +{ + using var game = new Burntime.MonoGl.BurntimeGame(); + game.Run(); +} +catch (System.Exception exception) +{ + ErrorMsg.LogException(exception); +} + +#endif \ No newline at end of file