66using Serilog ;
77using System ;
88using System . IO ;
9+ using System . Runtime ;
910
1011namespace 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>
0 commit comments