mirror of
https://github.com/2006-Scape/Parabot.git
synced 2026-07-06 16:50:39 +00:00
Merge pull request #42 from Parabot/development
[MERGE] Development into master
This commit is contained in:
@@ -33,7 +33,7 @@ public class Environment {
|
||||
libs.add(new Naga());
|
||||
|
||||
for(Library lib : libs) {
|
||||
if(!lib.hasJar()) {
|
||||
if(!lib.hasJar() && lib.requiresJar()) {
|
||||
Core.verbose("Downloading " + lib.getLibraryName() + "...");
|
||||
VerboseLoader.setState("Downloading " + lib.getLibraryName() + "...");
|
||||
WebUtil.downloadFile(lib.getDownloadLink(), lib.getJarFile(), VerboseLoader.get());
|
||||
@@ -43,8 +43,7 @@ public class Environment {
|
||||
lib.init();
|
||||
}
|
||||
|
||||
|
||||
Core.verbose("Loading server: " + desc.toString());
|
||||
Core.verbose("Loading server: " + desc.toString() + "...");
|
||||
|
||||
ServerParser.SERVER_CACHE.get(desc).run();
|
||||
|
||||
|
||||
@@ -2,7 +2,9 @@ package org.parabot.environment.api.utils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
@@ -65,4 +67,25 @@ public class FileUtil {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void copyFile(File sourceFile, File destFile)
|
||||
throws IOException {
|
||||
if (!sourceFile.exists()) {
|
||||
return;
|
||||
}
|
||||
if (!destFile.exists()) {
|
||||
destFile.createNewFile();
|
||||
}
|
||||
FileChannel source = null;
|
||||
FileChannel destination = null;
|
||||
source = new FileInputStream(sourceFile).getChannel();
|
||||
destination = new FileOutputStream(destFile).getChannel();
|
||||
if (source != null) {
|
||||
destination.transferFrom(source, 0, source.size());
|
||||
}
|
||||
if (source != null) {
|
||||
source.close();
|
||||
}
|
||||
destination.close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package org.parabot.environment.api.utils;
|
||||
|
||||
/**
|
||||
* @author JKetelaar
|
||||
*/
|
||||
public class JavaUtil {
|
||||
public static double JAVA_VERSION = getVersion();
|
||||
|
||||
static double getVersion () {
|
||||
String version = System.getProperty("java.version");
|
||||
int pos = version.indexOf('.');
|
||||
pos = version.indexOf('.', pos+1);
|
||||
return Double.parseDouble (version.substring (0, pos));
|
||||
}
|
||||
}
|
||||
@@ -156,6 +156,7 @@ public class Script implements Runnable {
|
||||
if(state < 0 || state > 2) {
|
||||
throw new IllegalArgumentException("Illegal state");
|
||||
}
|
||||
Core.setBugsnagInformation("Script", "State", String.valueOf(state));
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
@@ -180,5 +181,6 @@ public class Script implements Runnable {
|
||||
|
||||
public void setScriptID(int scriptID){
|
||||
this.scriptID = scriptID;
|
||||
Core.setBugsnagInformation("Script", "State", String.valueOf(scriptID));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,8 @@ import java.net.MalformedURLException;
|
||||
* @author Everel
|
||||
*
|
||||
*/
|
||||
@SuppressWarnings("Duplicates")
|
||||
@Deprecated
|
||||
public class LocalServerExecuter extends ServerExecuter {
|
||||
private final ServerProvider serverProvider;
|
||||
private ClassPath classPath;
|
||||
|
||||
+134
@@ -0,0 +1,134 @@
|
||||
package org.parabot.environment.servers.executers;
|
||||
|
||||
import org.parabot.core.Configuration;
|
||||
import org.parabot.core.Context;
|
||||
import org.parabot.core.Core;
|
||||
import org.parabot.core.Directories;
|
||||
import org.parabot.core.build.BuildPath;
|
||||
import org.parabot.core.classpath.ClassPath;
|
||||
import org.parabot.core.desc.ServerProviderInfo;
|
||||
import org.parabot.core.forum.AccountManager;
|
||||
import org.parabot.core.forum.AccountManagerAccess;
|
||||
import org.parabot.core.ui.components.VerboseLoader;
|
||||
import org.parabot.core.ui.utils.UILog;
|
||||
import org.parabot.environment.api.utils.FileUtil;
|
||||
import org.parabot.environment.api.utils.WebUtil;
|
||||
import org.parabot.environment.servers.ServerProvider;
|
||||
import org.parabot.environment.servers.loader.ServerLoader;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.net.URL;
|
||||
|
||||
/**
|
||||
*
|
||||
* Fetches a server provider from the local config file
|
||||
*
|
||||
* @author JKetelaar
|
||||
*
|
||||
*/
|
||||
public class LocalPublicServerExecuter extends ServerExecuter {
|
||||
private String serverName;
|
||||
private String serverUrl;
|
||||
private String providerUrl;
|
||||
private ServerProviderInfo serverProviderInfo;
|
||||
|
||||
public LocalPublicServerExecuter(final String serverName, final ServerProviderInfo serverProviderInfo, String serverUrl, String providerUrl) {
|
||||
this.serverName = serverName;
|
||||
this.serverUrl = serverUrl;
|
||||
this.providerUrl = providerUrl;
|
||||
this.serverProviderInfo = serverProviderInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
final File destination = new File(Directories.getCachePath(),
|
||||
serverProviderInfo.getCRC32() + ".jar");
|
||||
|
||||
Core.verbose("Downloading: " + providerUrl + " ...");
|
||||
|
||||
if(destination.exists()) {
|
||||
Core.verbose("Found cached server provider [CRC32: " + serverProviderInfo.getCRC32() + "]");
|
||||
} else {
|
||||
File local;
|
||||
if ((local = new File(providerUrl)).exists()){
|
||||
FileUtil.copyFile(local, destination);
|
||||
Core.verbose("Server provider copied...");
|
||||
}else {
|
||||
WebUtil.downloadFile(new URL(providerUrl), destination, VerboseLoader.get());
|
||||
Core.verbose("Server provider downloaded...");
|
||||
}
|
||||
}
|
||||
|
||||
final File clientDestination = new File(Directories.getCachePath(),
|
||||
serverProviderInfo.getClientCRC32() + ".jar");
|
||||
|
||||
Core.verbose("Downloading: " + serverUrl + " ...");
|
||||
|
||||
if(clientDestination.exists()) {
|
||||
Core.verbose("Found cached client [CRC32: " + serverProviderInfo.getClientCRC32() + "]");
|
||||
} else {
|
||||
File local;
|
||||
if ((local = new File(serverUrl)).exists()){
|
||||
FileUtil.copyFile(local, clientDestination);
|
||||
Core.verbose("Server client copied...");
|
||||
}else {
|
||||
WebUtil.downloadFile(new URL(serverUrl), clientDestination, VerboseLoader.get());
|
||||
Core.verbose("Server client downloaded...");
|
||||
}
|
||||
}
|
||||
|
||||
final ClassPath classPath = new ClassPath();
|
||||
classPath.addJar(destination);
|
||||
|
||||
BuildPath.add(destination.toURI().toURL());
|
||||
|
||||
ServerLoader serverLoader = new ServerLoader(classPath);
|
||||
final String[] classNames = serverLoader.getServerClassNames();
|
||||
if (classNames.length == 0) {
|
||||
UILog.log(
|
||||
"Error",
|
||||
"Failed to load server provider, error: [No provider found in jar file.]",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
return;
|
||||
} else if (classNames.length > 1) {
|
||||
UILog.log(
|
||||
"Error",
|
||||
"Failed to load server provider, error: [Multiple providers found in jar file.]");
|
||||
return;
|
||||
}
|
||||
|
||||
final String className = classNames[0];
|
||||
try {
|
||||
final Class<?> providerClass = serverLoader
|
||||
.loadClass(className);
|
||||
final Constructor<?> con = providerClass.getConstructor();
|
||||
final ServerProvider serverProvider = (ServerProvider) con
|
||||
.newInstance();
|
||||
Context.getInstance(serverProvider).setProviderInfo(serverProviderInfo);
|
||||
super.finalize(serverProvider, this.serverName);
|
||||
} catch (NoClassDefFoundError | ClassNotFoundException ignored) {
|
||||
UILog.log(
|
||||
"Error",
|
||||
"Failed to load server provider, error: [This server provider is not compatible with this version of parabot]",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
UILog.log(
|
||||
"Error",
|
||||
"Failed to load server provider.",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
UILog.log(
|
||||
"Error",
|
||||
"Failed to load server provider, post the stacktrace/error on the parabot forums.",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -58,7 +58,6 @@ public class PublicServerExecuter extends ServerExecuter {
|
||||
+ this.serverName;
|
||||
|
||||
Core.verbose("Downloading: " + jarUrl + " ...");
|
||||
|
||||
|
||||
if(destination.exists()) {
|
||||
Core.verbose("Found cached server provider [CRC32: " + serverProviderInfo.getCRC32() + "]");
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
package org.parabot.environment.servers.executers;
|
||||
|
||||
import org.parabot.core.Context;
|
||||
import org.parabot.core.Core;
|
||||
import org.parabot.core.parsers.randoms.RandomParser;
|
||||
import org.parabot.core.ui.components.PaintComponent;
|
||||
import org.parabot.environment.servers.ServerProvider;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
/**
|
||||
*
|
||||
* Executes a server provider
|
||||
@@ -21,11 +24,7 @@ public abstract class ServerExecuter {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
try{
|
||||
org.parabot.environment.api.utils.WindowsPreferences.userRoot().remove("Software\\JavaSoft\\Prefs");
|
||||
}catch (Exception e){
|
||||
// Ikov likes to creates preference keys, doesn't it?
|
||||
}
|
||||
Core.setBugsnagServer(serverName);
|
||||
|
||||
Context context = Context.getInstance(provider);
|
||||
context.load();
|
||||
|
||||
Reference in New Issue
Block a user