Example #1
0
 private void loadCustomModsFromJar(File file)
     throws IOException, ClassNotFoundException, IllegalAccessException, InstantiationException {
   Logger.log(Logger.LOG_JAR, "Opening %s", file.getPath());
   final JarFile jar = new JarFile(file);
   URLClassLoader loader =
       new URLClassLoader(new URL[] {file.toURI().toURL()}, getClass().getClassLoader());
   for (JarEntry entry : Collections.list(jar.entries())) {
     if (!entry.isDirectory() && MinecraftJar.isClassFile(entry.getName())) {
       Mod mod = loadCustomMod(loader, ClassMap.filenameToClassName(entry.getName()));
       if (addNoReplace(mod)) {
         Logger.log(Logger.LOG_MOD, "new %s()", mod.getClass().getName());
         mod.customJar = file;
       }
     }
   }
 }
Example #2
0
 void loadSavedMods() {
   Config config = MCPatcherUtils.config;
   Element mods = config.getMods();
   if (mods == null) {
     return;
   }
   NodeList list = mods.getElementsByTagName(Config.TAG_MOD);
   ArrayList<Element> invalidEntries = new ArrayList<Element>();
   for (int i = 0; i < list.getLength(); i++) {
     Element element = (Element) list.item(i);
     String name = config.getText(element, Config.TAG_NAME);
     String type = config.getText(element, Config.TAG_TYPE);
     String enabled = config.getText(element, Config.TAG_ENABLED);
     Mod mod = null;
     if (name == null || type == null) {
       invalidEntries.add(element);
     } else if (type.equals(Config.VAL_BUILTIN)) {
       for (BuiltInMod builtInMod : builtInMods) {
         if (name.equals(builtInMod.name)
             && (MCPatcher.experimentalMods || !builtInMod.experimental)) {
           mod = newModInstance(builtInMod.modClass);
         }
       }
       if (mod == null) {
         invalidEntries.add(element);
       }
     } else if (type.equals(Config.VAL_EXTERNAL_ZIP)) {
       String path = config.getText(element, Config.TAG_PATH);
       Element files = config.getElement(element, Config.TAG_FILES);
       if (path != null && files != null) {
         File file = new File(path);
         if (file.exists()) {
           HashMap<String, String> fileMap = new HashMap<String, String>();
           NodeList fileNodes = files.getElementsByTagName(Config.TAG_FILE);
           for (int j = 0; j < fileNodes.getLength(); j++) {
             Element fileElem = (Element) fileNodes.item(j);
             String from = config.getText(fileElem, Config.TAG_FROM);
             String to = config.getText(fileElem, Config.TAG_TO);
             if (from != null && to != null) {
               fileMap.put(to, from);
             }
           }
           try {
             mod = new ExternalMod(new ZipFile(file), fileMap);
           } catch (IOException e) {
             Logger.log(e);
           }
         }
       } else {
         invalidEntries.add(element);
       }
     } else if (type.equals(Config.VAL_EXTERNAL_JAR)) {
       String path = config.getText(element, Config.TAG_PATH);
       String className = config.getText(element, Config.TAG_CLASS);
       if (path != null && className != null) {
         File file = new File(path);
         if (file.exists()) {
           mod = loadCustomMod(file, className);
           if (mod != null) {
             mod.customJar = file;
           }
         }
       } else {
         invalidEntries.add(element);
       }
     } else {
       invalidEntries.add(element);
     }
     if (mod != null) {
       if (addNoReplace(mod)) {
         if (enabled != null) {
           mod.setEnabled(Boolean.parseBoolean(enabled));
         }
       }
     }
   }
   for (Element element : invalidEntries) {
     mods.removeChild(element);
   }
   refreshInternalMods();
 }