Skip to content

Commit 8eb0d83

Browse files
committed
Launch client automatically when updates are complete
1 parent 97362ee commit 8eb0d83

File tree

3 files changed

+38
-6
lines changed

3 files changed

+38
-6
lines changed

PC_Launcher/src/main/java/launcher/Gameupdater/ClientDownloader.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public static void downloadOrUpdate(File gamePath, String fileName, String url,
3838
error.printStackTrace();
3939
} finally {
4040
Downloader.currently_updating = false;
41+
Downloader.update_latch.countDown();
4142
}
4243
}).start();
4344
}

PC_Launcher/src/main/java/launcher/Gameupdater/Downloader.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import java.net.UnknownHostException;
1313
import java.util.ArrayList;
1414
import java.util.List;
15+
import java.util.concurrent.CountDownLatch;
1516

1617
public class Downloader implements Runnable {
1718

@@ -21,6 +22,8 @@ public class Downloader implements Runnable {
2122

2223
public static boolean offline_start = false;
2324
public static boolean currently_updating = false;
25+
public static CountDownLatch update_latch = new CountDownLatch(1);
26+
2427

2528
private List<File> FILE_LIST = new ArrayList<>();
2629

@@ -124,5 +127,6 @@ public void run() {
124127
}
125128
ProgressBar.setDownloadProgress(ProgressBar.doneText, ProgressBar.donePercent);
126129
currently_updating = false;
130+
update_latch.countDown();
127131
}
128132
}

PC_Launcher/src/main/java/launcher/Utils/ClientLauncher.java

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,41 @@
1212
import java.io.IOException;
1313
import java.io.OutputStreamWriter;
1414

15-
import javax.swing.JOptionPane;
16-
1715
public class ClientLauncher {
16+
// Launch client automatically when updates are complete.
17+
private static String autoPlayServer;
18+
private static final Runnable autoPlayRunnable = new Runnable() {
19+
@Override
20+
public void run() {
21+
try {
22+
Downloader.update_latch.await();
23+
} catch (InterruptedException e) {
24+
return;
25+
}
26+
String serverName = autoPlayServer;
27+
autoPlayServer = null;
28+
try {
29+
launchClientForServer(serverName);
30+
} catch (IOException e) {
31+
throw new RuntimeException(e);
32+
}
33+
}
34+
};
35+
1836
public static void launchClientForServer(String serverName) throws IOException {
19-
if (Downloader.currently_updating) {
20-
JOptionPane.showMessageDialog(null, "Currently updating the client, please wait!");
21-
return;
22-
}
37+
// Wait for updates to complete before launching.
38+
if (autoPlayServer != null || Downloader.currently_updating) {
39+
// Store server name.
40+
boolean threadStarted = autoPlayServer != null;
41+
autoPlayServer = serverName;
42+
// Wait in background.
43+
if (!threadStarted) {
44+
Thread t = new Thread(autoPlayRunnable);
45+
t.start();
46+
}
47+
return;
48+
}
49+
// Launch client.
2350
switch (serverName) {
2451
case "preservation": {
2552
String ip = "game.openrsc.com";

0 commit comments

Comments
 (0)