5
5
import java .util .MissingResourceException ;
6
6
import java .util .ResourceBundle ;
7
7
8
- import javax .swing .JOptionPane ;
9
8
import javax .swing .SwingUtilities ;
10
9
11
10
import com .superzanti .serversync .ClientWorker ;
12
11
import com .superzanti .serversync .ServerSetup ;
13
12
import com .superzanti .serversync .SyncConfig ;
14
13
import com .superzanti .serversync .gui .GUI_Client ;
15
- import com .superzanti .serversync .gui .GUI_Client .SyncPressedListener ;
16
14
import com .superzanti .serversync .gui .GUI_Server ;
15
+ import com .superzanti .serversync .util .ProgramArguments ;
17
16
import com .superzanti .serversync .util .enums .EConfigType ;
18
17
19
18
@@ -31,9 +30,13 @@ public class Main {
31
30
32
31
public static SyncConfig CONFIG ;
33
32
33
+ public static ProgramArguments arguments ;
34
+
34
35
35
36
public static void main (String [] args ) throws InterruptedException , IOException {
37
+ arguments = new ProgramArguments (args );
36
38
CONFIG = new SyncConfig (EConfigType .COMMON );
39
+
37
40
try {
38
41
// TODO left off here, fix locale use and other main references
39
42
System .out .println ("Loading language file: " + CONFIG .LOCALE );
@@ -48,16 +51,10 @@ public void run() {
48
51
strings = ResourceBundle .getBundle ("assets.serversync.lang.MessagesBundle" , new Locale ("en" , "US" ));
49
52
}
50
53
51
- if (args == null || args .length == 0 ) {
54
+ if (arguments .isServer ) {
55
+ runInServerMode ();
56
+ } else {
52
57
runInClientMode ();
53
- return ;
54
- }
55
-
56
- for (String string : args ) {
57
- switch (string ) {
58
- case "server" :
59
- runInServerMode ();
60
- }
61
58
}
62
59
}
63
60
@@ -70,49 +67,31 @@ private static void runInServerMode() {
70
67
71
68
private static void runInClientMode () {
72
69
CONFIG = new SyncConfig (EConfigType .CLIENT );
73
-
74
- clientGUI = new GUI_Client ();
75
-
76
- clientGUI .setSyncPressedListener (new SyncPressedListener () {
70
+ Thread clientThread ;
71
+ if (arguments .syncSilent ) {
72
+ new Thread (new ClientWorker ()).start ();
73
+ } else if (arguments .syncProgressOnly ) {
74
+ //TODO setup a progress only version of the GUI
75
+ clientGUI = new GUI_Client ();
76
+ clientGUI .setIPAddress (CONFIG .SERVER_IP );
77
+ clientGUI .setPort (CONFIG .SERVER_PORT );
78
+ clientGUI .build (CONFIG .LOCALE );
77
79
78
- @ Override
79
- public void onSyncPressed () {
80
- int port = clientGUI .getPort ();
81
- String ip = clientGUI .getIPAddress ();
82
- boolean error = false ;
83
-
84
- if (ip .equals ("" ) || port == 90000 ) {
85
- clientGUI .updateText ("No config found, requesting details" );
86
-
87
- if (ip .equals ("" )) {
88
- String serverIP = (String ) JOptionPane .showInputDialog ("Server IP address" );
89
- ip = serverIP ;
90
- clientGUI .setIPAddress (ip );
91
- }
92
-
93
- if (port == 90000 ) {
94
- String serverPort = (String ) JOptionPane .showInputDialog ("Server Port (numbers only)" );
95
- port = Integer .parseInt (serverPort );
96
-
97
- if (clientGUI .setPort (port )) {
98
- error = true ;
99
- }
100
- }
101
-
102
- SyncConfig .pullServerConfig = true ;
103
- }
104
-
105
- if (!error ) {
106
- CONFIG .SERVER_IP = ip ;
107
- CONFIG .SERVER_PORT = port ;
108
- clientGUI .updateText ("Starting update process..." );
109
- new Thread (new ClientWorker ()).start ();
110
- }
80
+ clientThread = new Thread (new ClientWorker ());
81
+ clientThread .start ();
82
+ try {
83
+ clientThread .join ();
84
+ } catch (InterruptedException e ) {
85
+ // TODO Auto-generated catch block
86
+ e .printStackTrace ();
87
+ System .exit (1 );
111
88
}
112
- });
113
- System .out .println (CONFIG .SERVER_PORT );
114
- clientGUI .setIPAddress (CONFIG .SERVER_IP );
115
- clientGUI .setPort (CONFIG .SERVER_PORT );
116
- clientGUI .build (CONFIG .LOCALE );
89
+ System .exit (0 );
90
+ } else {
91
+ clientGUI = new GUI_Client ();
92
+ clientGUI .setIPAddress (CONFIG .SERVER_IP );
93
+ clientGUI .setPort (CONFIG .SERVER_PORT );
94
+ clientGUI .build (CONFIG .LOCALE );
95
+ }
117
96
}
118
97
}
0 commit comments