Search in sources :

Example 1 with ModFolder

use of io.xol.chunkstories.content.mods.ModFolder in project chunkstories by Hugobros3.

the class ModsSelection method buildModsList.

private void buildModsList() {
    modsContainer.elements.clear();
    Collection<String> currentlyEnabledMods = Arrays.asList(Client.getInstance().getContent().modsManager().getEnabledModsString());
    Set<String> uniqueMods = new HashSet<String>();
    // First put in already loaded mods
    for (Mod mod : Client.getInstance().getContent().modsManager().getCurrentlyLoadedMods()) {
        // Should use md5 hash instead ;)
        if (uniqueMods.add(mod.getModInfo().getName().toLowerCase()))
            modsContainer.elements.add(modsContainer.new ModItem(mod, true));
    }
    // Then look for mods in folder fashion
    for (File f : new File(GameDirectory.getGameFolderPath() + "/mods/").listFiles()) {
        if (f.isDirectory()) {
            File txt = new File(f.getAbsolutePath() + "/mod.txt");
            if (txt.exists()) {
                try {
                    ModFolder mod = new ModFolder(f);
                    // Should use md5 hash instead ;)
                    if (uniqueMods.add(mod.getModInfo().getName().toLowerCase()))
                        modsContainer.elements.add(modsContainer.new ModItem(mod, currentlyEnabledMods.contains(mod.getModInfo().getName())));
                    System.out.println("mod:" + mod.getModInfo().getName() + " // " + currentlyEnabledMods.contains(mod.getModInfo().getName()));
                } catch (ModLoadFailureException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    // First look for mods in folder fashion
    for (File f : new File(GameDirectory.getGameFolderPath() + "/mods/").listFiles()) {
        if (f.getName().endsWith(".zip")) {
            try {
                ModZip mod = new ModZip(f);
                // Should use md5 hash instead ;)
                if (uniqueMods.add(mod.getModInfo().getName().toLowerCase()))
                    modsContainer.elements.add(modsContainer.new ModItem(mod, currentlyEnabledMods.contains(mod.getModInfo().getName())));
            } catch (ModLoadFailureException e) {
                e.printStackTrace();
            }
        }
    }
}
Also used : ModLoadFailureException(io.xol.chunkstories.api.exceptions.content.mods.ModLoadFailureException) Mod(io.xol.chunkstories.api.content.mods.Mod) ModItem(io.xol.chunkstories.gui.layer.config.ModsSelection.ModsScrollableContainer.ModItem) ModFolder(io.xol.chunkstories.content.mods.ModFolder) File(java.io.File) HashSet(java.util.HashSet) ModZip(io.xol.chunkstories.content.mods.ModZip)

Aggregations

Mod (io.xol.chunkstories.api.content.mods.Mod)1 ModLoadFailureException (io.xol.chunkstories.api.exceptions.content.mods.ModLoadFailureException)1 ModFolder (io.xol.chunkstories.content.mods.ModFolder)1 ModZip (io.xol.chunkstories.content.mods.ModZip)1 ModItem (io.xol.chunkstories.gui.layer.config.ModsSelection.ModsScrollableContainer.ModItem)1 File (java.io.File)1 HashSet (java.util.HashSet)1