Skip to content
This repository was archived by the owner on Mar 26, 2021. It is now read-only.

Commit a3ecb29

Browse files
committed
Catch libbass and gtk init errors
1 parent dec8eed commit a3ecb29

2 files changed

Lines changed: 39 additions & 7 deletions

File tree

OpenChart/src/App.cs

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Serilog;
77
using System;
88
using System.IO;
9+
using System.Runtime;
910

1011
namespace OpenChart
1112
{
@@ -37,7 +38,7 @@ public static class App
3738
/// <summary>
3839
/// Initializes the app.
3940
/// </summary>
40-
public static void Init()
41+
public static bool Init()
4142
{
4243
// Get the path to the folder where the executable is.
4344
AppFolder = Path.GetDirectoryName(
@@ -62,16 +63,40 @@ public static void Init()
6263
Log.Information("Initializing...");
6364
Log.Debug($"Set current directory to {AppFolder}");
6465

65-
// Initialize libbass
66-
if (!Bass.Init())
66+
try
6767
{
68-
Log.Fatal("Failed to initialize libbass.");
69-
Environment.Exit(1);
68+
// Initialize libbass
69+
if (!Bass.Init())
70+
{
71+
var error = Enum.GetName(typeof(ManagedBass.Errors), Bass.LastError);
72+
73+
Log.Fatal($"Failed to initialize libbass. ({error}, code = {Bass.LastError})");
74+
return false;
75+
}
76+
}
77+
catch (DllNotFoundException e)
78+
{
79+
Log.Fatal(e, "Failed to initialize libbass (DLL not found).");
80+
return false;
7081
}
7182

7283
Log.Information("libbass init OK.");
7384

74-
Gtk.Application.Init();
85+
try
86+
{
87+
Gtk.Application.Init();
88+
}
89+
catch (TypeInitializationException e)
90+
{
91+
var msg = "Failed to initialize Gtk";
92+
93+
if (e.InnerException is DllNotFoundException)
94+
msg += " (DLL not found)";
95+
96+
Log.Fatal(e, msg);
97+
return false;
98+
}
99+
75100
Log.Information("Gtk init OK.");
76101

77102
Formats = new FormatManager();
@@ -83,6 +108,8 @@ public static void Init()
83108
NoteSkins.LoadAll();
84109

85110
Log.Information("OpenChart init OK.");
111+
112+
return true;
86113
}
87114

88115
/// <summary>

OpenChart/src/Program.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ public static void Main()
1212
{
1313
try
1414
{
15-
App.Init();
15+
if (!App.Init())
16+
{
17+
Log.Fatal("Initialization failed, quitting...");
18+
Environment.Exit(1);
19+
}
20+
1621
App.Run();
1722
}
1823
catch (Exception e)

0 commit comments

Comments
 (0)