Search in sources :

Example 6 with Mod

use of mod.Mod in project ParadoxosModManager by ThibautSF.

the class MyXML method modifyList.

/**
 * @param list
 * @param listName
 * @throws Exception
 */
public void modifyList(ModList list, String listName) throws Exception {
    Element oneListElement = null, listDescrElement, listArgsElement, listLangElement, listModElement;
    List<Mod> listMods;
    boolean isNew = (listName != null) ? false : true;
    if (!isNew) {
        List<Element> modLists = root.getChildren(LIST);
        Iterator<Element> i = modLists.iterator();
        while (i.hasNext()) {
            Element oneListElementIterated = (Element) i.next();
            String listElementName = oneListElementIterated.getAttribute(NAME).getValue();
            if (listElementName.equals(listName)) {
                oneListElement = oneListElementIterated;
                break;
            }
        }
    }
    if (oneListElement != null) {
        oneListElement.removeChildren(MOD);
    } else {
        oneListElement = new Element(LIST);
        root.addContent(oneListElement);
    }
    listDescrElement = oneListElement.getChild(DESCR);
    if (listDescrElement == null) {
        listDescrElement = new Element(DESCR);
        oneListElement.addContent(listDescrElement);
    }
    listLangElement = oneListElement.getChild(LANG);
    if (listLangElement == null) {
        listLangElement = new Element(LANG);
        oneListElement.addContent(listLangElement);
    }
    listArgsElement = oneListElement.getChild(LAUNCHARGS);
    if (listArgsElement == null) {
        listArgsElement = new Element(LAUNCHARGS);
        oneListElement.addContent(listArgsElement);
    }
    oneListElement.setAttribute(NAME, list.getName());
    oneListElement.setAttribute(CUSTOM_ORDER, list.isCustomOrder() + "");
    listDescrElement.setText(list.getDescription());
    listArgsElement.setText(list.getLaunchArgs());
    listLangElement.setText(list.getLanguageName());
    listMods = list.getModlist();
    for (int i = 0; i < listMods.size(); i++) {
        Mod mod = listMods.get(i);
        listModElement = new Element(MOD);
        listModElement.setAttribute(MOD_NAME, mod.getName());
        listModElement.setAttribute(FILE_NAME, mod.getFileName());
        listModElement.setAttribute(REMOTE_ID, mod.getRemoteFileID());
        listModElement.setAttribute(MOD_ORDER, i + "");
        oneListElement.addContent(listModElement);
    }
    this.saveFile();
}
Also used : Mod(mod.Mod) Element(org.jdom2.Element) ErrorPrint(debug.ErrorPrint)

Example 7 with Mod

use of mod.Mod in project ParadoxosModManager by ThibautSF.

the class ListManager method modPrint.

/**
 * @param applyMods
 * @param writer
 * @throws IOException
 */
private void modPrint(List<Mod> applyMods, BufferedWriter writer) throws IOException {
    for (Mod mod : applyMods) {
        String addLine = "\t\"mod/" + mod.getFileName() + "\"";
        writer.write(addLine + System.getProperty("line.separator"));
    }
}
Also used : Mod(mod.Mod)

Example 8 with Mod

use of mod.Mod in project ParadoxosModManager by ThibautSF.

the class ListCreator method readMods.

private void readMods(String trimmedLine) {
    while (trimmedLine.indexOf("/") >= 0) {
        String oneModStr = trimmedLine.substring(trimmedLine.indexOf("/") + 1, trimmedLine.indexOf(".mod") + 4);
        Mod oneMod = availableMods.get(oneModStr);
        if (oneMod == null) {
            oneMod = new Mod(oneModStr);
            if (!missingMods.contains(oneMod)) {
                missingMods.add(oneMod);
                list.addMod(oneMod);
            }
        } else {
            if (!selectedModsList.contains(oneMod)) {
                selectedModsList.add(oneMod);
                list.addMod(oneMod);
            }
        }
        trimmedLine = trimmedLine.substring(trimmedLine.indexOf(".mod") + 4, trimmedLine.length());
    }
}
Also used : Mod(mod.Mod)

Example 9 with Mod

use of mod.Mod in project ParadoxosModManager by ThibautSF.

the class ListManager method loadModFilesArray.

/**
 */
private void loadModFilesArray() {
    String workLabel = ModManager.isConflictComputed() ? "Generate mods and conflicts..." : "Generate mods...";
    wd = new WorkIndicatorDialog<String>(window.getScene().getWindow(), workLabel);
    wd.addTaskEndNotification(result -> {
        try {
            updateList();
        } catch (Exception eCreate) {
            ErrorPrint.printError(eCreate, "When update ListView of ModLists on window creation");
            eCreate.printStackTrace();
        }
        refreshTexts();
        // don't keep the object, cleanup
        wd = null;
    });
    wd.exec("LoadMods", inputParam -> {
        // String sep = File.separator;
        File userDir = new File(absolutePath);
        File[] childs = userDir.listFiles();
        for (int i = 0; i < childs.length; i++) {
            File modDir = childs[i];
            // if (modDir.isDirectory() && ListManager.modFileNames.contains(modDir.getName().toLowerCase())) {
            if (modDir.isDirectory() && modDir.getName().toLowerCase().equals("mod")) {
                // Clean customModFiles
                deleteCustomModFiles();
                String[] modFiles = modDir.list(new FilenameFilter() {

                    @Override
                    public boolean accept(File dir, String name) {
                        return name.toLowerCase().endsWith(".mod");
                    }
                });
                wd.maxProgress = modFiles.length;
                int j = 0;
                for (String modFile : modFiles) {
                    availableMods.put(modFile, new Mod(modFile, ModManager.isConflictComputed()));
                    j++;
                    wd.currentProgress = j;
                }
            } else {
            // throw new FileNotFoundException("The folder '"+modFile.getAbsolutePath()+"' is missing, please check the path.\nBe sure to have started the game launcher once !");
            }
        }
        return new Integer(1);
    });
}
Also used : FilenameFilter(java.io.FilenameFilter) Mod(mod.Mod) File(java.io.File) URISyntaxException(java.net.URISyntaxException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) ErrorPrint(debug.ErrorPrint)

Example 10 with Mod

use of mod.Mod in project ParadoxosModManager by ThibautSF.

the class ListManager method modPrint.

/**
 * @param applyMods
 * @param writer
 * @param prefix
 * @param modfolder
 * @throws IOException
 */
private void modPrint(List<Mod> applyMods, BufferedWriter writer, String prefix, String modfolder) throws IOException {
    if (!(modfolder.lastIndexOf("/") == modfolder.length() - 1))
        modfolder += "/";
    for (Mod mod : applyMods) {
        String addLine = "\t\"" + modfolder + prefix + mod.getFileName() + "\"";
        writer.write(addLine + System.getProperty("line.separator"));
    }
}
Also used : Mod(mod.Mod)

Aggregations

Mod (mod.Mod)14 ErrorPrint (debug.ErrorPrint)5 File (java.io.File)5 FileReader (java.io.FileReader)4 FileWriter (java.io.FileWriter)4 BufferedReader (java.io.BufferedReader)3 BufferedWriter (java.io.BufferedWriter)3 IOException (java.io.IOException)3 Element (org.jdom2.Element)3 FilenameFilter (java.io.FilenameFilter)2 ArrayList (java.util.ArrayList)2 TreeMap (java.util.TreeMap)2 ModList (mod.ModList)2 Attribute (org.jdom2.Attribute)2 DataConversionException (org.jdom2.DataConversionException)2 Gson (com.google.gson.Gson)1 JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 FileNotFoundException (java.io.FileNotFoundException)1 URISyntaxException (java.net.URISyntaxException)1