Skip to content

Commit

Permalink
support kotlin 1.9.22
Browse files Browse the repository at this point in the history
This fetches the Kotlin std lib and adds it to the client classpath so that you may use kotlin classes/features at runtime.

The way this is done will likely be improved as we will likely have to fetch other dependencies eventually.
  • Loading branch information
zeruth committed Dec 29, 2023
1 parent 3c2b39d commit 0cba970
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 11 deletions.
60 changes: 51 additions & 9 deletions src/main/java/net/runelite/launcher/Launcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,12 @@
import com.google.common.hash.HashingOutputStream;
import com.google.common.io.ByteStreams;
import com.google.gson.Gson;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;

import java.io.*;
import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.nio.file.Files;
Expand Down Expand Up @@ -86,6 +81,8 @@
import net.runelite.launcher.beans.Platform;
import org.slf4j.LoggerFactory;

import static net.runelite.launcher.SplashScreen.INSTANCE;

@Slf4j
public class Launcher
{
Expand Down Expand Up @@ -946,7 +943,51 @@ private static void initDllBlacklist()

static native String regQueryString(String subKey, String value);

public static void classpathSwap(List<File> classpath, OptionSet options, boolean checkClassPathOption) {
private static int getFileSize(URL url) {
URLConnection conn = null;
try {
conn = url.openConnection();
if(conn instanceof HttpURLConnection) {
((HttpURLConnection)conn).setRequestMethod("HEAD");
}
conn.getInputStream();
return conn.getContentLength();
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
if(conn instanceof HttpURLConnection) {
((HttpURLConnection)conn).disconnect();
}
}
}

public static void updateKotlinSTD() throws IOException {
URL stdJarURL = new URL("https://repo1.maven.org/maven2/org/jetbrains/kotlin/kotlin-stdlib/1.9.22/kotlin-stdlib-1.9.22.jar");
File localStdJar = new File(hotlitePatchDir, "kotlin-stdlib-1.9.22.jar");
boolean shouldUpdate = true;
if (localStdJar.exists()) {
long remoteJarSize = getFileSize(stdJarURL);
long localFileSize = localStdJar.length();
if (remoteJarSize == localFileSize)
shouldUpdate = false;
}

if (shouldUpdate) {
INSTANCE.actionText = "Updating Kotlin STD lib";
try (BufferedInputStream in = new BufferedInputStream(stdJarURL.openStream());
FileOutputStream fileOutputStream = new FileOutputStream(localStdJar)) {
byte[] dataBuffer = new byte[1024];
int bytesRead;
while ((bytesRead = in.read(dataBuffer, 0, 1024)) != -1) {
fileOutputStream.write(dataBuffer, 0, bytesRead);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}

public static void classpathSwap(List<File> classpath, OptionSet options, boolean checkClassPathOption) throws IOException {
if (rlVersion == null) {
log.info("HotLite Launcher " + LauncherProperties.getVersion());
rlVersion = classpath.stream().filter(artifact -> (artifact.getName().startsWith("client-") && !artifact.getName().contains("client-patch"))).findFirst().map(artifact -> artifact.getName().replace("client-", "").replace(".jar", "")).orElse("");
Expand All @@ -955,6 +996,7 @@ public static void classpathSwap(List<File> classpath, OptionSet options, boolea
}

if (hotlitePatchDir.exists()) {
updateKotlinSTD();
log.info("HotLite swapping");
ArrayList<File> swaps = new ArrayList<>();
classpath.forEach(file -> {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/runelite/launcher/SplashScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ public class SplashScreen extends JFrame implements ActionListener
private static final int WIDTH = 200;
private static final int PAD = 10;

private static SplashScreen INSTANCE;
public static SplashScreen INSTANCE;

private final JLabel action = new JLabel("Loading");
private final JProgressBar progress = new JProgressBar();
private final JLabel subAction = new JLabel();
private final Timer timer;

private volatile double overallProgress = 0;
private volatile String actionText = "Loading";
public volatile String actionText = "Loading";
private volatile String subActionText = "";
private volatile String progressText = null;

Expand Down

0 comments on commit 0cba970

Please sign in to comment.