Skip to content

Commit

Permalink
cleanup lib loading
Browse files Browse the repository at this point in the history
this should also fix any lib related loading issue
  • Loading branch information
zeruth committed Jan 10, 2024
1 parent 0cba970 commit 0e939d1
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions src/main/java/net/runelite/launcher/Launcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
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 @@ -81,8 +80,6 @@
import net.runelite.launcher.beans.Platform;
import org.slf4j.LoggerFactory;

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

@Slf4j
public class Launcher
{
Expand All @@ -95,11 +92,12 @@ public class Launcher
static final String LAUNCHER_EXECUTABLE_NAME_OSX = "RuneLite";

private static final File HOTLITE_DIR = new File(RUNELITE_DIR, "hotlite");

private static final File LIBS_DIR = new File(HOTLITE_DIR, "libs");
public static String rlVersion;
public static File hotlitePatchDir;

public static void main(String[] args)
{
public static void main(String[] args) throws IOException {
OptionParser parser = new OptionParser(false);
parser.allowsUnrecognizedOptions();
parser.accepts("postinstall", "Perform post-install tasks");
Expand Down Expand Up @@ -192,6 +190,7 @@ public static void main(String[] args)
.map(name -> new File(REPO_DIR, name))
.collect(Collectors.toList());

updateLibs();
classpathSwap(classpath, options, false);

try
Expand Down Expand Up @@ -389,7 +388,7 @@ public static void main(String[] args)
var classpath = artifacts.stream()
.map(dep -> new File(REPO_DIR, dep.getName()))
.collect(Collectors.toList());

updateLibs();
classpathSwap(classpath, options, true);

List<String> jvmParams = new ArrayList<>();
Expand Down Expand Up @@ -963,19 +962,22 @@ private static int getFileSize(URL url) {

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");
File localStdJar = new File(LIBS_DIR, "kotlin-stdlib-1.9.22.jar");
downloadFile(stdJarURL, localStdJar);
}

public static void downloadFile(URL url, File file) {
boolean shouldUpdate = true;
if (localStdJar.exists()) {
long remoteJarSize = getFileSize(stdJarURL);
long localFileSize = localStdJar.length();
if (file.exists()) {
long remoteJarSize = getFileSize(url);
long localFileSize = file.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)) {
try (BufferedInputStream in = new BufferedInputStream(url.openStream());
FileOutputStream fileOutputStream = new FileOutputStream(file)) {
byte[] dataBuffer = new byte[1024];
int bytesRead;
while ((bytesRead = in.read(dataBuffer, 0, 1024)) != -1) {
Expand All @@ -987,6 +989,12 @@ public static void updateKotlinSTD() throws IOException {
}
}

public static void updateLibs() throws IOException {
if (!LIBS_DIR.exists())
LIBS_DIR.mkdirs();
updateKotlinSTD();
}

public static void classpathSwap(List<File> classpath, OptionSet options, boolean checkClassPathOption) throws IOException {
if (rlVersion == null) {
log.info("HotLite Launcher " + LauncherProperties.getVersion());
Expand All @@ -996,7 +1004,6 @@ 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 All @@ -1010,6 +1017,9 @@ public static void classpathSwap(List<File> classpath, OptionSet options, boolea
}
});
swaps.forEach(classpath::remove);
//Add libs like kotlin etc
classpath.addAll(List.of(LIBS_DIR.listFiles()));
//Add runelite module swaps
classpath.addAll(List.of(Objects.requireNonNull(hotlitePatchDir.listFiles())));
} else {
if (checkClassPathOption && !options.has("classpath"))
Expand Down

0 comments on commit 0e939d1

Please sign in to comment.