@@ -18,42 +18,56 @@ public static class Bootstrap
18
18
private static readonly CancellationTokenSource CancellationTokenSource = new ( ) ;
19
19
20
20
[ UnmanagedCallersOnly ]
21
- public static void InitializeSourceSharp ( )
22
- => Initialize ( ) ;
21
+ public static int InitializeSourceSharp ( ) => Initialize ( ) ;
23
22
24
23
[ UnmanagedCallersOnly ]
25
24
public static void ShutdownSourceSharp ( ) => CancellationTokenSource . Cancel ( false ) ;
26
25
27
- public static void InitializeTest ( ) => Initialize ( ) ;
26
+ public static int InitializeTest ( ) => Initialize ( ) ;
28
27
29
- private static void Initialize ( )
28
+ private static int Initialize ( )
30
29
{
31
- // bin
32
- var dir = Path . GetDirectoryName ( System . Reflection . Assembly . GetExecutingAssembly ( ) . Location ) ! ;
33
- // root
34
- var parent = Directory . GetParent ( dir ) ! . Name ;
35
- // config
36
- var path = Path . Combine ( parent , "configs" , "core.json" ) ;
30
+ try
31
+ {
32
+ // bin
33
+ var dir = Path . GetDirectoryName ( System . Reflection . Assembly . GetExecutingAssembly ( ) . Location ) ! ;
34
+ // root
35
+ var parent = Directory . GetParent ( dir ) ! . Name ;
36
+ // config
37
+ var path = Path . Combine ( parent , "configs" , "core.json" ) ;
37
38
38
39
#if DEBUG
39
- if ( ! File . Exists ( path ) )
40
- {
41
- path = Path . Combine ( dir , "config.json" ) ;
42
- }
40
+ if ( ! File . Exists ( path ) )
41
+ {
42
+ path = Path . Combine ( dir , "config.json" ) ;
43
+ }
43
44
#endif
44
45
45
- var services = new ServiceCollection ( ) ;
46
- var configuration = new ConfigurationBuilder ( ) . AddJsonFile ( path ) . Build ( ) ;
46
+ var services = new ServiceCollection ( ) ;
47
+ var configuration = new ConfigurationBuilder ( ) . AddJsonFile ( path ) . Build ( ) ;
47
48
48
- ConfigureServices ( services , configuration ) ;
49
+ ConfigureServices ( services , configuration ) ;
49
50
50
- var serviceProvider = services . BuildServiceProvider ( options : new ServiceProviderOptions
51
- {
52
- ValidateOnBuild = true ,
53
- ValidateScopes = true
54
- } ) ;
51
+ var serviceProvider = services . BuildServiceProvider ( options : new ( )
52
+ {
53
+ ValidateOnBuild = true ,
54
+ ValidateScopes = true
55
+ } ) ;
56
+
57
+ Boot ( serviceProvider ) ;
55
58
56
- Boot ( serviceProvider ) ;
59
+ return 0 ;
60
+ }
61
+ catch ( Exception ex )
62
+ {
63
+ var color = Console . ForegroundColor ;
64
+ Console . ForegroundColor = ConsoleColor . Cyan ;
65
+ Console . WriteLine ( $ "{ DateTime . Now : yyyy/MM/dd HH:mm:ss} [SourceSharp] Failed to init SourceSharp.") ;
66
+ Console . ForegroundColor = color ;
67
+ Console . WriteLine ( ex . ToString ( ) ) ;
68
+ Console . WriteLine ( Environment . NewLine ) ;
69
+ return 1 ;
70
+ }
57
71
}
58
72
59
73
private static void ConfigureServices ( IServiceCollection services , IConfiguration configuration )
@@ -75,7 +89,6 @@ private static void ConfigureServices(IServiceCollection services, IConfiguratio
75
89
76
90
private static void Boot ( IServiceProvider services )
77
91
{
78
-
79
92
// Init IModuleBase
80
93
foreach ( var module in services . GetAllServices < IModuleBase > ( ) )
81
94
{
@@ -84,13 +97,11 @@ private static void Boot(IServiceProvider services)
84
97
85
98
// Plugin Manager should be the LAST!
86
99
services . GetRequiredService < IPluginManager > ( ) . Initialize ( ) ;
100
+
101
+ // export caller invoker
87
102
Invoker . Initialize ( services ) ;
88
103
89
104
Task . Run ( async ( ) => await SignalThread ( services ) ) ;
90
-
91
- #if DEBUG
92
- Console . WriteLine ( "Boot!" ) ;
93
- #endif
94
105
}
95
106
96
107
private static async Task SignalThread ( IServiceProvider services )
0 commit comments