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
 int replace(Mod oldMod, Mod newMod) {
   int index = indexOf(oldMod);
   if (index >= 0 && oldMod.getName().equals(newMod.getName())) {
     modsByIndex.set(index, newMod);
     modsByName.put(newMod.getName(), newMod);
     oldMod.close();
     return indexOfVisible(newMod);
   } else {
     remove(oldMod);
     return addFirst(newMod);
   }
 }
Esempio n. 3
0
 void remove(Mod mod) {
   String name = mod.getName();
   for (int i = 0; i < modsByIndex.size(); i++) {
     if (modsByIndex.get(i) == mod) {
       modsByIndex.remove(i);
       modsByName.remove(name);
     }
   }
   mod.close();
 }
Esempio n. 4
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;
 }
Esempio n. 5
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);
 }
Esempio n. 6
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);
         }
       }
     }
   }
 }
Esempio n. 7
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);
         }
       }
     }
   }
 }
Esempio n. 8
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;
 }
Esempio n. 9
0
 private boolean addNoReplace(Mod mod) {
   if (mod == null) {
     return false;
   }
   String name = mod.getName();
   if (modsByName.containsKey(name)) {
     Logger.log(Logger.LOG_MOD, "WARNING: duplicate mod %s ignored", name);
     return false;
   }
   mod.setRefs();
   modsByName.put(name, mod);
   modsByIndex.add(mod);
   mod.setEnabled(mod.defaultEnabled);
   mod.loadOptions();
   return true;
 }