Skip to content

Commit 37cb15d

Browse files
#65 Add silent running for client
1 parent 312b194 commit 37cb15d

File tree

5 files changed

+93
-55
lines changed

5 files changed

+93
-55
lines changed

gradle.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
ssversion = 2.6.12
1+
ssversion = 2.6.13
22
ssname = serversync

src/main/java/com/superzanti/lib/RefStrings.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
public class RefStrings {
88
public static final String MODID = "serversync";
99
public static final String NAME = "Server Sync";
10-
public static final String VERSION = "2.6.12";
10+
public static final String VERSION = "2.6.13";
1111
}

src/main/java/com/superzanti/serversync/gui/GUI_Client.java

+41
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import javax.swing.JButton;
1717
import javax.swing.JFrame;
1818
import javax.swing.JLabel;
19+
import javax.swing.JOptionPane;
1920
import javax.swing.JPanel;
2021
import javax.swing.JProgressBar;
2122
import javax.swing.JScrollPane;
@@ -31,6 +32,8 @@
3132
import javax.swing.border.TitledBorder;
3233

3334
import com.superzanti.lib.RefStrings;
35+
import com.superzanti.serversync.ClientWorker;
36+
import com.superzanti.serversync.SyncConfig;
3437

3538
import runme.Main;
3639

@@ -182,6 +185,44 @@ public void keyPressed(java.awt.event.KeyEvent e) {
182185
return;
183186
}
184187
});
188+
189+
B_sync.addActionListener(new ActionListener() {
190+
191+
@Override
192+
public void actionPerformed(ActionEvent e) {
193+
int port = getPort();
194+
String ip = getIPAddress();
195+
boolean error = false;
196+
197+
if (ip.equals("") || port == 90000) {
198+
updateText("No config found, requesting details");
199+
200+
if (ip.equals("")) {
201+
String serverIP = (String) JOptionPane.showInputDialog("Server IP address");
202+
ip = serverIP;
203+
setIPAddress(ip);
204+
}
205+
206+
if (port == 90000) {
207+
String serverPort = (String) JOptionPane.showInputDialog("Server Port (numbers only)");
208+
port = Integer.parseInt(serverPort);
209+
210+
if(setPort(port)) {
211+
error = true;
212+
}
213+
}
214+
215+
SyncConfig.pullServerConfig = true;
216+
}
217+
218+
if (!error) {
219+
Main.CONFIG.SERVER_IP = ip;
220+
Main.CONFIG.SERVER_PORT = port;
221+
updateText("Starting update process...");
222+
new Thread(new ClientWorker()).start();
223+
}
224+
}
225+
});
185226
}
186227

187228
public void build(Locale loc) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.superzanti.serversync.util;
2+
3+
import java.util.Arrays;
4+
import java.util.List;
5+
6+
public class ProgramArguments {
7+
8+
public final boolean isServer;
9+
public final boolean syncSilent;
10+
public final boolean syncProgressOnly;
11+
12+
public ProgramArguments(String[] arguments) {
13+
List<String> args = Arrays.asList(arguments);
14+
this.isServer = args.contains("server");
15+
this.syncSilent = args.contains("silent");
16+
this.syncProgressOnly = args.contains("progress-only");
17+
}
18+
}

src/main/java/runme/Main.java

+32-53
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@
55
import java.util.MissingResourceException;
66
import java.util.ResourceBundle;
77

8-
import javax.swing.JOptionPane;
98
import javax.swing.SwingUtilities;
109

1110
import com.superzanti.serversync.ClientWorker;
1211
import com.superzanti.serversync.ServerSetup;
1312
import com.superzanti.serversync.SyncConfig;
1413
import com.superzanti.serversync.gui.GUI_Client;
15-
import com.superzanti.serversync.gui.GUI_Client.SyncPressedListener;
1614
import com.superzanti.serversync.gui.GUI_Server;
15+
import com.superzanti.serversync.util.ProgramArguments;
1716
import com.superzanti.serversync.util.enums.EConfigType;
1817

1918

@@ -31,9 +30,13 @@ public class Main {
3130

3231
public static SyncConfig CONFIG;
3332

33+
public static ProgramArguments arguments;
34+
3435

3536
public static void main(String[] args) throws InterruptedException, IOException {
37+
arguments = new ProgramArguments(args);
3638
CONFIG = new SyncConfig(EConfigType.COMMON);
39+
3740
try {
3841
// TODO left off here, fix locale use and other main references
3942
System.out.println("Loading language file: " + CONFIG.LOCALE);
@@ -48,16 +51,10 @@ public void run() {
4851
strings = ResourceBundle.getBundle("assets.serversync.lang.MessagesBundle", new Locale("en", "US"));
4952
}
5053

51-
if (args == null || args.length == 0) {
54+
if (arguments.isServer) {
55+
runInServerMode();
56+
} else {
5257
runInClientMode();
53-
return;
54-
}
55-
56-
for (String string : args) {
57-
switch(string) {
58-
case "server":
59-
runInServerMode();
60-
}
6158
}
6259
}
6360

@@ -70,49 +67,31 @@ private static void runInServerMode() {
7067

7168
private static void runInClientMode() {
7269
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);
7779

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);
11188
}
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+
}
11796
}
11897
}

0 commit comments

Comments
 (0)