16
16
17
17
package com .heliosdecompiler .helios ;
18
18
19
- import com .google .common .collect .Iterables ;
20
19
import com .google .common .eventbus .AsyncEventBus ;
21
20
import com .google .common .eventbus .EventBus ;
22
21
import com .google .inject .AbstractModule ;
23
22
import com .google .inject .Guice ;
24
23
import com .google .inject .Injector ;
24
+ import com .heliosdecompiler .helios .controller .LanguageController ;
25
25
import com .heliosdecompiler .helios .controller .PathController ;
26
- import com .heliosdecompiler .helios .controller .RecentFileController ;
27
26
import com .heliosdecompiler .helios .controller .UpdateController ;
28
27
import com .heliosdecompiler .helios .controller .files .OpenedFileController ;
29
28
import com .heliosdecompiler .helios .controller .ui .UserInterfaceController ;
30
29
import com .heliosdecompiler .helios .controller .ui .impl .UnsupportedUIController ;
31
- import com .heliosdecompiler .helios .gui .JavaFXGuiLauncher ;
32
- import com .heliosdecompiler .helios .gui .model .Message ;
33
- import com .heliosdecompiler .helios .ui .GuiLauncher ;
30
+ import com .heliosdecompiler .helios .ui .GraphicsProvider ;
34
31
import com .heliosdecompiler .helios .ui .MessageHandler ;
35
32
import com .heliosdecompiler .helios .utils .OSUtils ;
36
- import com .heliosdecompiler .transformerapi .PackagedLibraryHelper ;
37
33
import org .apache .commons .cli .*;
38
34
import org .apache .commons .configuration2 .Configuration ;
39
35
import org .apache .commons .configuration2 .XMLConfiguration ;
51
47
import java .nio .charset .Charset ;
52
48
import java .nio .charset .StandardCharsets ;
53
49
import java .util .ArrayList ;
54
- import java .util .Collections ;
55
50
import java .util .List ;
56
51
import java .util .concurrent .Executors ;
57
52
58
53
public class Helios {
59
- private static LocalSocket socket ;
60
-
61
54
public static void main (String [] args ) {
62
- System .setProperty ("file.encoding" , "UTF-8" );
63
-
64
55
try {
56
+ LanguageController languageController = new LanguageController (); // blehhhhhh
57
+ Message .init (languageController );
58
+
59
+ GraphicsProvider launcher = getGraphicsProvider ().newInstance ();
60
+
61
+ launcher .startSplash ();
62
+ launcher .updateSplash (Message .STARTUP_PREPARING_ENVIRONMENT );
63
+
65
64
Field defaultCharset = Charset .class .getDeclaredField ("defaultCharset" );
66
65
defaultCharset .setAccessible (true );
67
- defaultCharset .set (null , null );
68
-
66
+ defaultCharset .set (null , StandardCharsets .UTF_8 );
69
67
if (!Charset .defaultCharset ().equals (StandardCharsets .UTF_8 ))
70
- throw new RuntimeException ("Charset" );
68
+ throw new RuntimeException ("Charset: " + Charset . defaultCharset () );
71
69
if (!Constants .DATA_DIR .exists () && !Constants .DATA_DIR .mkdirs ())
72
70
throw new RuntimeException ("Could not create data directory" );
73
71
if (!Constants .ADDONS_DIR .exists () && !Constants .ADDONS_DIR .mkdirs ())
74
72
throw new RuntimeException ("Could not create addons directory" );
75
- if (!Constants .SETTINGS_FILE .exists () && !Constants .SETTINGS_FILE .createNewFile ())
76
- throw new RuntimeException ("Could not create settings file" );
77
73
if (Constants .DATA_DIR .isFile ())
78
74
throw new RuntimeException ("Data directory is file" );
79
75
if (Constants .ADDONS_DIR .isFile ())
80
76
throw new RuntimeException ("Addons directory is file" );
81
- if (Constants .SETTINGS_FILE .isDirectory ())
82
- throw new RuntimeException ("Settings file is directory" );
83
-
84
- UIManager .setLookAndFeel (UIManager .getSystemLookAndFeelClassName ());
85
-
86
- Splash splashScreen = new Splash ();
87
- splashScreen .updateState (BootSequence .CHECKING_LIBRARIES );
88
- PackagedLibraryHelper .checkPackagedLibrary ("enjarify" , Constants .ENJARIFY_VERSION );
89
77
90
- splashScreen .updateState (BootSequence .CLEANING_UPDATES );
91
-
92
- String thisVersion = "helios-dev.jar" ;
93
-
94
- for (File file : Constants .DATA_DIR .listFiles ()) {
95
- if (file .getName ().startsWith ("helios-" ) && !file .getName ().equals (thisVersion )) {
96
- file .delete ();
97
- }
98
- }
78
+ EventBus eventBus = new AsyncEventBus (Executors .newCachedThreadPool ());
99
79
100
- splashScreen .updateState (BootSequence .LOADING_SETTINGS );
101
80
Configuration configuration = loadConfiguration ();
102
- splashScreen .updateState (BootSequence .LOADING_ADDONS );
103
- // AddonHandler.registerPreloadedAddons();
104
- // for (File file : Constants.ADDONS_DIR.listFiles()) {
105
- // AddonHandler
106
- // .getAllHandlers()
107
- // .stream()
108
- // .filter(handler -> handler.accept(file))
109
- // .findFirst()
110
- // .ifPresent(handler -> {
111
- // handler.run(file);
112
- // });
113
- // }
114
- try {
115
- socket = new LocalSocket ();
116
- } catch (IOException e ) { // Maybe allow the user to force open a second instance?
117
- // ExceptionHandler.handle(e);
118
- }
119
-
120
- splashScreen .updateState (BootSequence .COMPLETE );
81
+ Class <? extends UserInterfaceController > uiController = getUIControllerImpl ();
121
82
122
- EventBus eventBus = new AsyncEventBus (Executors .newCachedThreadPool ());
123
-
124
- GuiLauncher launcher = new JavaFXGuiLauncher ();
83
+ Injector mainInjector = Guice .createInjector (
84
+ new AbstractModule () {
85
+ @ Override
86
+ protected void configure () {
87
+ bind (MessageHandler .class ).to (launcher .getMessageHandlerImpl ());
88
+ bind (UserInterfaceController .class ).to (uiController );
89
+ bind (Configuration .class ).toInstance (configuration );
90
+ bind (EventBus .class ).toInstance (eventBus );
91
+ }
92
+ }
93
+ );
125
94
126
- Class <? extends UserInterfaceController > uiController = UnsupportedUIController .class ;
95
+ mainInjector . getInstance ( UserInterfaceController .class ). initialize () ;
127
96
128
- if (OSUtils .getOS () == OSUtils .OS .WINDOWS ) {
129
- uiController = (Class <? extends UserInterfaceController >) Class .forName ("com.heliosdecompiler.helios.controller.ui.impl.WindowsUIController" );
130
- }
97
+ launcher .updateSplash (Message .STARTUP_LOADING_GRAPHICS );
98
+ launcher .prepare (mainInjector );
131
99
132
- Class <? extends UserInterfaceController > uiControllerFinal = uiController ;
100
+ launcher .updateSplash (Message .STARTUP_DONE );
101
+ launcher .start ();
133
102
134
- Injector mainInjector = Guice .createInjector (
135
- Iterables .concat (
136
- launcher .getModules (),
137
- Collections .singleton (new AbstractModule () {
138
- @ Override
139
- protected void configure () {
140
- bind (UserInterfaceController .class ).to (uiControllerFinal );
141
- bind (RecentFileController .class );
142
- bind (PathController .class );
143
- bind (Configuration .class ).toInstance (configuration );
144
- bind (EventBus .class ).toInstance (eventBus );
145
- }
146
- })
147
- )
148
- );
149
- launcher .start (mainInjector , () -> {
150
- mainInjector .getInstance (PathController .class ).reload ();
151
- mainInjector .getInstance (UpdateController .class ).doUpdate ();
152
- handleCommandLine (args , mainInjector );
153
- });
103
+ mainInjector .getInstance (PathController .class ).reload ();
104
+ mainInjector .getInstance (UpdateController .class ).doUpdate ();
105
+ handleCommandLine (args , mainInjector );
154
106
} catch (Throwable t ) {
155
107
displayError (t );
156
108
System .exit (1 );
157
109
}
158
110
}
159
111
112
+ public static Class <? extends GraphicsProvider > getGraphicsProvider () throws ClassNotFoundException {
113
+ return Class .forName (System .getProperty ("com.heliosdecompiler.standaloneapp.GraphicsProvider" , "com.heliosdecompiler.helios.gui.JavaFXGraphicsProvider" )).asSubclass (GraphicsProvider .class );
114
+ }
115
+
160
116
public static void displayError (Throwable t ) {
161
117
t .printStackTrace ();
162
118
StringWriter writer = new StringWriter ();
@@ -165,6 +121,14 @@ public static void displayError(Throwable t) {
165
121
JOptionPane .INFORMATION_MESSAGE );
166
122
}
167
123
124
+ public static Class <? extends UserInterfaceController > getUIControllerImpl () throws ClassNotFoundException {
125
+ if (OSUtils .getOS () == OSUtils .OS .WINDOWS ) {
126
+ return Class .forName ("com.heliosdecompiler.helios.controller.ui.impl.WindowsUIController" ).asSubclass (UserInterfaceController .class );
127
+ }
128
+
129
+ return UnsupportedUIController .class ;
130
+ }
131
+
168
132
private static Configuration loadConfiguration () throws IOException , ConfigurationException {
169
133
Configurations configurations = new Configurations ();
170
134
File file = Constants .SETTINGS_FILE_XML ;
@@ -201,8 +165,9 @@ public static void handleCommandLine(String[] args, Injector injector) {
201
165
202
166
for (File file : open )
203
167
injector .getInstance (OpenedFileController .class ).openFile (file );
168
+
204
169
} catch (ParseException e ) {
205
- injector .getInstance (MessageHandler .class ).handleException (Message .UNKNOWN_ERROR , e );
170
+ injector .getInstance (MessageHandler .class ).handleException (Message .ERROR_UNKNOWN_ERROR . format () , e );
206
171
}
207
172
}
208
173
}
0 commit comments