예제 #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
 int addLast(Mod mod) {
   String name = mod.getName();
   Mod oldMod = modsByName.get(name);
   if (oldMod != null) {
     remove(oldMod);
   }
   modsByIndex.add(mod);
   modsByName.put(name, mod);
   mod.setRefs();
   return indexOfVisible(mod);
 }
예제 #3
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);
         }
       }
     }
   }
 }
예제 #4
0
 private boolean dependsOn(Mod mod1, Mod mod2) {
   if (mod1 == null || mod2 == null) {
     return false;
   }
   if (mod1 == mod2) {
     return true;
   }
   for (Mod.Dependency dep : mod1.dependencies) {
     if (dep.required
         && !dep.name.equals(mod1.getName())
         && dependsOn(modsByName.get(dep.name), mod2)) {
       return true;
     }
   }
   return false;
 }
예제 #5
0
 private void disableMod(HashMap<Mod, Boolean> inst, Mod mod, boolean recursive)
     throws ModDependencyException {
   if (mod == null) {
     return;
   }
   // Logger.log(Logger.LOG_MOD, "%sdisabling %s", (recursive ? " " : ""), mod.getName());
   if (inst.containsKey(mod)) {
     if (inst.get(mod)) {
       throw new ModDependencyException(mod.getName() + " is both conflicting and required");
     }
     return;
   } else {
     inst.put(mod, false);
   }
   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);
         }
       }
     }
   }
 }
예제 #6
0
 Mod get(String name) {
   return modsByName.get(name);
 }