Перенос initModules

This commit is contained in:
Gravit 2018-09-19 20:29:31 +07:00
parent 75cc2156a0
commit 8f76bfdf03
4 changed files with 37 additions and 15 deletions

View file

@ -4,6 +4,7 @@
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.Set;
import java.util.jar.JarInputStream; import java.util.jar.JarInputStream;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream; import java.util.zip.ZipOutputStream;
@ -29,4 +30,16 @@ public void pushJarFile(JarInputStream input) throws IOException {
e = input.getNextEntry(); e = input.getNextEntry();
} }
} }
public void pushJarFile(JarInputStream input, Set<String> blacklist) throws IOException {
ZipEntry e = input.getNextEntry();
while (e != null) {
if(blacklist.contains(e.getName())){
e = input.getNextEntry();
continue;
}
output.putNextEntry(e);
IOHelper.transfer(input,output);
e = input.getNextEntry();
}
}
} }

View file

@ -2,36 +2,35 @@
import java.io.IOException; import java.io.IOException;
import javassist.CannotCompileException; import javassist.*;
import javassist.ClassPool;
import javassist.CtClass;
import javassist.CtConstructor;
import javassist.NotFoundException;
public class JAConfigurator implements AutoCloseable { public class JAConfigurator implements AutoCloseable {
ClassPool pool = ClassPool.getDefault(); ClassPool pool = ClassPool.getDefault();
CtClass ctClass; CtClass ctClass;
CtConstructor ctConstructor; CtConstructor ctConstructor;
CtMethod initModuleMethod;
String classname; String classname;
StringBuilder body; StringBuilder body;
StringBuilder moduleBody;
int autoincrement; int autoincrement;
public JAConfigurator(Class<?> configclass) throws NotFoundException { public JAConfigurator(Class<?> configclass) throws NotFoundException {
classname = configclass.getName(); classname = configclass.getName();
ctClass = pool.get(classname); ctClass = pool.get(classname);
ctConstructor = ctClass.getDeclaredConstructor(null); ctConstructor = ctClass.getDeclaredConstructor(null);
body = new StringBuilder("{"); initModuleMethod = ctClass.getDeclaredMethod("initModules");
body = new StringBuilder("{ isInitModules = false; ");
autoincrement = 0; autoincrement = 0;
} }
public void addModuleClass(String fullName) public void addModuleClass(String fullName)
{ {
body.append("ru.gravit.launcher.modules.Module mod"); moduleBody.append("ru.gravit.launcher.modules.Module mod");
body.append(autoincrement); moduleBody.append(autoincrement);
body.append(" = new "); moduleBody.append(" = new ");
body.append(fullName); moduleBody.append(fullName);
body.append("();"); moduleBody.append("();");
body.append("ru.gravit.launcher.Launcher.modulesManager.registerModule( mod"); moduleBody.append("ru.gravit.launcher.Launcher.modulesManager.registerModule( mod");
body.append(autoincrement); moduleBody.append(autoincrement);
body.append(" , true );"); moduleBody.append(" , true );");
autoincrement++; autoincrement++;
} }
@Override @Override
@ -41,6 +40,7 @@ public void close() {
public byte[] getBytecode() throws IOException, CannotCompileException { public byte[] getBytecode() throws IOException, CannotCompileException {
body.append("}"); body.append("}");
ctConstructor.setBody(body.toString()); ctConstructor.setBody(body.toString());
initModuleMethod.insertAfter(moduleBody.toString());
return ctClass.toBytecode(); return ctClass.toBytecode();
} }
public String getZipEntryPath() public String getZipEntryPath()
@ -60,4 +60,8 @@ public void setPort(int port)
body.append(port); body.append(port);
body.append(";"); body.append(";");
} }
public ClassPool getPool()
{
return pool;
}
} }

View file

@ -381,7 +381,7 @@ public static Process launch(
@LauncherAPI @LauncherAPI
public static void main(String... args) throws Throwable { public static void main(String... args) throws Throwable {
Launcher.modulesManager = new ClientModuleManager(null); Launcher.modulesManager = new ClientModuleManager(null);
LauncherConfig.getAutogenConfig(); //INIT LauncherConfig.getAutogenConfig().initModules(); //INIT
Launcher.modulesManager.preInitModules(); Launcher.modulesManager.preInitModules();
if (JVMHelper.OS_TYPE == OS.MUSTDIE) { if (JVMHelper.OS_TYPE == OS.MUSTDIE) {
AvanguardStarter.loadVared(); AvanguardStarter.loadVared();

View file

@ -4,7 +4,12 @@ public class AutogenConfig {
public String projectname; public String projectname;
public String address; public String address;
public int port; public int port;
private boolean isInitModules;
AutogenConfig() { AutogenConfig() {
} }
public void initModules()
{
if(isInitModules) return;
}
} }