Пример #1
0
 void updateProperties() {
   Config config = MCPatcherUtils.config;
   Element mods = config.getMods();
   if (mods == null) {
     return;
   }
   HashMap<String, Element> oldElements = new HashMap<String, Element>();
   while (mods.hasChildNodes()) {
     Node node = mods.getFirstChild();
     if (node instanceof Element) {
       Element element = (Element) node;
       String name = config.getText(element, Config.TAG_NAME);
       if (name != null) {
         oldElements.put(name, element);
       }
     }
     mods.removeChild(node);
   }
   for (Mod mod : modsByIndex) {
     if (mod.internal) {
       continue;
     }
     Element element = oldElements.get(mod.getName());
     if (element == null) {
       defaultModElement(mod);
     } else {
       config.setText(
           element, Config.TAG_ENABLED, Boolean.toString(mod.isEnabled() && mod.okToApply()));
       updateModElement(mod, element);
       mods.appendChild(element);
       oldElements.remove(mod.getName());
     }
   }
 }
Пример #2
0
 private Element defaultModElement(Mod mod) {
   Config config = MCPatcherUtils.config;
   Element mods = config.getMods();
   if (mods == null) {
     return null;
   }
   Element element = config.getMod(mod.getName());
   config.setText(element, Config.TAG_ENABLED, Boolean.toString(mod.defaultEnabled));
   updateModElement(mod, element);
   return element;
 }
Пример #3
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();
 }