Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public static void downloadOrUpdate(File gamePath, String fileName, String url,
error.printStackTrace();
} finally {
Downloader.currently_updating = false;
Downloader.update_latch.countDown();
}
}).start();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CountDownLatch;

public class Downloader implements Runnable {

Expand All @@ -21,6 +22,7 @@ public class Downloader implements Runnable {

public static boolean offline_start = false;
public static boolean currently_updating = false;
public static CountDownLatch update_latch = new CountDownLatch(1);

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

Expand Down Expand Up @@ -124,5 +126,6 @@ public void run() {
}
ProgressBar.setDownloadProgress(ProgressBar.doneText, ProgressBar.donePercent);
currently_updating = false;
update_latch.countDown();
}
}
39 changes: 33 additions & 6 deletions PC_Launcher/src/main/java/launcher/Utils/ClientLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,41 @@
import java.io.IOException;
import java.io.OutputStreamWriter;

import javax.swing.JOptionPane;

public class ClientLauncher {
// Launch client automatically when updates are complete.
private static String autoPlayServer;
private static final Runnable autoPlayRunnable = new Runnable() {
@Override
public void run() {
try {
Downloader.update_latch.await();
} catch (InterruptedException e) {
return;
}
String serverName = autoPlayServer;
autoPlayServer = null;
try {
launchClientForServer(serverName);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
};

public static void launchClientForServer(String serverName) throws IOException {
if (Downloader.currently_updating) {
JOptionPane.showMessageDialog(null, "Currently updating the client, please wait!");
return;
}
// Wait for updates to complete before launching.
if (autoPlayServer != null || Downloader.currently_updating) {
// Store server name.
boolean threadStarted = autoPlayServer != null;
autoPlayServer = serverName;
// Wait in background.
if (!threadStarted) {
Thread t = new Thread(autoPlayRunnable);
t.start();
}
return;
}
// Launch client.
switch (serverName) {
case "preservation": {
String ip = "game.openrsc.com";
Expand Down