Esempio n. 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());
     }
   }
 }
Esempio n. 2
0
 ArrayList<Mod> getSelected() {
   ArrayList<Mod> list = new ArrayList<Mod>();
   for (Mod mod : modsByIndex) {
     if (mod.okToApply() && mod.isEnabled()) {
       list.add(mod);
     }
   }
   return list;
 }
Esempio n. 3
0
 void enableValidMods(boolean enableAll) {
   for (int i = modsByIndex.size() - 1; i >= 0; i--) {
     Mod mod = modsByIndex.get(i);
     boolean enabled = mod.okToApply();
     if (enabled) {
       if (enableAll) {
         selectMod(mod, true);
       }
     } else {
       selectMod(mod, false);
     }
   }
 }
Esempio n. 4
0
 private void enableMod(HashMap<Mod, Boolean> inst, Mod mod, boolean recursive)
     throws ModDependencyException {
   if (mod == null) {
     return;
   }
   // Logger.log(Logger.LOG_MOD, "%senabling %s", (recursive ? " " : ""), mod.getName());
   if (!mod.okToApply()) {
     throw new ModDependencyException(mod.getName() + " cannot be applied");
   }
   if (inst.containsKey(mod)) {
     if (!inst.get(mod)) {
       throw new ModDependencyException(mod.getName() + " is both conflicting and required");
     }
     return;
   } else {
     inst.put(mod, true);
   }
   for (Mod.Dependency dep : mod.dependencies) {
     Mod dmod = modsByName.get(dep.name);
     if (dep.required) {
       if (dmod == null) {
         throw new ModDependencyException("dependent mod " + dep.name + " not available");
       } else {
         enableMod(inst, dmod, true);
       }
     } else {
       disableMod(inst, dmod, true);
     }
   }
   for (Mod dmod : modsByIndex) {
     if (dmod != mod) {
       for (Mod.Dependency dep : dmod.dependencies) {
         if (dep.name.equals(mod.getName()) && !dep.required) {
           disableMod(inst, dmod, true);
         }
       }
     }
   }
 }