mirror of
https://github.com/2006-Scape/Parabot.git
synced 2026-07-07 08:39:12 +00:00
Resources dump support
This commit is contained in:
@@ -5,6 +5,7 @@ import org.objectweb.asm.ClassWriter;
|
|||||||
import org.objectweb.asm.tree.ClassNode;
|
import org.objectweb.asm.tree.ClassNode;
|
||||||
import org.parabot.core.classpath.ClassPath;
|
import org.parabot.core.classpath.ClassPath;
|
||||||
|
|
||||||
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.security.AllPermission;
|
import java.security.AllPermission;
|
||||||
import java.security.CodeSource;
|
import java.security.CodeSource;
|
||||||
@@ -36,7 +37,12 @@ public class ASMClassLoader extends ClassLoader {
|
|||||||
protected URL findResource(String name) {
|
protected URL findResource(String name) {
|
||||||
if (getSystemResource(name) == null) {
|
if (getSystemResource(name) == null) {
|
||||||
if (classPath.resources.containsKey(name)) {
|
if (classPath.resources.containsKey(name)) {
|
||||||
return classPath.resources.get(name);
|
try {
|
||||||
|
return classPath.resources.get(name).toURI().toURL();
|
||||||
|
} catch (MalformedURLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,9 +10,11 @@ import java.io.OutputStream;
|
|||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
|
import java.nio.file.Files;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
import java.util.jar.JarEntry;
|
import java.util.jar.JarEntry;
|
||||||
import java.util.jar.JarOutputStream;
|
import java.util.jar.JarOutputStream;
|
||||||
import java.util.zip.ZipEntry;
|
import java.util.zip.ZipEntry;
|
||||||
@@ -38,7 +40,7 @@ import org.parabot.core.ui.components.VerboseLoader;
|
|||||||
public class ClassPath {
|
public class ClassPath {
|
||||||
public final ArrayList<String> classNames;
|
public final ArrayList<String> classNames;
|
||||||
public final HashMap<String, ClassNode> classes;
|
public final HashMap<String, ClassNode> classes;
|
||||||
public final Map<String, URL> resources;
|
public final Map<String, File> resources;
|
||||||
public URL lastParsed;
|
public URL lastParsed;
|
||||||
private ClassRemapper classRemapper;
|
private ClassRemapper classRemapper;
|
||||||
private boolean isJar;
|
private boolean isJar;
|
||||||
@@ -53,7 +55,7 @@ public class ClassPath {
|
|||||||
public ClassPath(final boolean isJar) {
|
public ClassPath(final boolean isJar) {
|
||||||
this.classNames = new ArrayList<String>();
|
this.classNames = new ArrayList<String>();
|
||||||
this.classes = new HashMap<String, ClassNode>();
|
this.classes = new HashMap<String, ClassNode>();
|
||||||
this.resources = new HashMap<String, URL>();
|
this.resources = new HashMap<String, File>();
|
||||||
this.classRemapper = new ClassRemapper();
|
this.classRemapper = new ClassRemapper();
|
||||||
this.parseJar = true;
|
this.parseJar = true;
|
||||||
this.jarFiles = new ArrayList<URL>();
|
this.jarFiles = new ArrayList<URL>();
|
||||||
@@ -247,7 +249,7 @@ public class ClassPath {
|
|||||||
out.write(buffer, 0, len);
|
out.write(buffer, 0, len);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
}
|
}
|
||||||
this.resources.put(name, f.toURI().toURL());
|
this.resources.put(name, f);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -293,6 +295,11 @@ public class ClassPath {
|
|||||||
cn.accept(cw);
|
cn.accept(cw);
|
||||||
out.write(cw.toByteArray());
|
out.write(cw.toByteArray());
|
||||||
}
|
}
|
||||||
|
for(Entry<String, File> entry : this.resources.entrySet()) {
|
||||||
|
JarEntry je = new JarEntry(entry.getKey());
|
||||||
|
out.putNextEntry(je);
|
||||||
|
out.write(Files.readAllBytes(entry.getValue().toPath()));
|
||||||
|
}
|
||||||
out.close();
|
out.close();
|
||||||
stream.close();
|
stream.close();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user