Client loader, pull from the repo.
This commit is contained in:
55
src/main/java/net/runelite/client/ClientLoader.java
Normal file
55
src/main/java/net/runelite/client/ClientLoader.java
Normal file
@@ -0,0 +1,55 @@
|
||||
package net.runelite.client;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import java.applet.Applet;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.List;
|
||||
import net.runelite.launcher.ArtifactResolver;
|
||||
import net.runelite.launcher.Launcher;
|
||||
import org.eclipse.aether.artifact.Artifact;
|
||||
import org.eclipse.aether.artifact.DefaultArtifact;
|
||||
import org.eclipse.aether.resolution.ArtifactResult;
|
||||
import org.eclipse.aether.resolution.DependencyResolutionException;
|
||||
|
||||
public class ClientLoader
|
||||
{
|
||||
private static final String CLIENT_ARTIFACT_URL = "http://192.168.1.2/rs/client.json";
|
||||
|
||||
public Applet load() throws MalformedURLException, ClassNotFoundException, IOException, InstantiationException, IllegalAccessException, DependencyResolutionException
|
||||
{
|
||||
ConfigLoader config = new ConfigLoader();
|
||||
|
||||
config.fetch();
|
||||
|
||||
ArtifactResolver resolver = new ArtifactResolver(Launcher.REPO_DIR);
|
||||
List<ArtifactResult> results = resolver.resolveArtifacts(getClientArtifact());
|
||||
File client = results.get(0).getArtifact().getFile();
|
||||
|
||||
String initialClass = config.getProperty(ConfigLoader.INITIAL_CLASS).replace(".class", "");
|
||||
|
||||
URLClassLoader loader = new URLClassLoader(new URL[]{ client.toURI().toURL() }, this.getClass().getClassLoader());
|
||||
Class<?> clientClass = loader.loadClass(initialClass);
|
||||
|
||||
Applet rs = (Applet) clientClass.newInstance();
|
||||
|
||||
rs.setStub(new RSStub(config, rs));
|
||||
|
||||
return rs;
|
||||
}
|
||||
|
||||
private static Artifact getClientArtifact() throws MalformedURLException, IOException
|
||||
{
|
||||
URL u = new URL(CLIENT_ARTIFACT_URL);
|
||||
try (InputStream i = u.openStream())
|
||||
{
|
||||
Gson g = new Gson();
|
||||
return g.fromJson(new InputStreamReader(i), DefaultArtifact.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,11 +3,8 @@ package net.runelite.client.ui;
|
||||
import java.applet.Applet;
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import javax.swing.JPanel;
|
||||
import net.runelite.client.ConfigLoader;
|
||||
import net.runelite.client.RSStub;
|
||||
import net.runelite.client.ClientLoader;
|
||||
|
||||
final class ClientPanel extends JPanel
|
||||
{
|
||||
@@ -19,29 +16,12 @@ final class ClientPanel extends JPanel
|
||||
setPreferredSize(new Dimension(ClientUI.PANEL_WIDTH, ClientUI.PANEL_HEIGHT));
|
||||
setBackground(Color.black);
|
||||
|
||||
Applet rs = dl();
|
||||
ClientLoader loader = new ClientLoader();
|
||||
|
||||
Applet rs = loader.load();
|
||||
rs.setSize(this.getSize());
|
||||
rs.init();
|
||||
rs.start();
|
||||
this.add(rs);
|
||||
}
|
||||
|
||||
private Applet dl() throws Exception
|
||||
{
|
||||
ConfigLoader config = new ConfigLoader();
|
||||
|
||||
config.fetch();
|
||||
|
||||
//URL clientUrl = new URL(config.getProperty(ConfigLoader.CODEBASE) + config.getProperty(ConfigLoader.INITIAL_JAR));
|
||||
URL clientUrl = new URL("http://192.168.1.2/rs/" + config.getProperty(ConfigLoader.INITIAL_JAR));
|
||||
String initialClass = config.getProperty(ConfigLoader.INITIAL_CLASS).replace(".class", "");
|
||||
|
||||
URLClassLoader loader = new URLClassLoader(new URL[]{ clientUrl });
|
||||
Class<?> clientClass = loader.loadClass(initialClass);
|
||||
|
||||
Applet rs = (Applet) clientClass.newInstance();
|
||||
|
||||
rs.setStub(new RSStub(config, rs));
|
||||
return rs;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user