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()); } } }
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; }