Skip to content

Commit 7e0aaf2

Browse files
Merge pull request #8 from DazedNConfused-/latest_world_fix
2 parents 72c2378 + 66b73e0 commit 7e0aaf2

File tree

4 files changed

+75
-4
lines changed

4 files changed

+75
-4
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,5 @@ saves
4242
backups
4343
.macatalauncher
4444
trashed
45-
userdir
45+
userdir
46+
mods

src/main/java/com/dazednconfused/catalauncher/helper/Constants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public class Constants {
99
public static final String CUSTOM_SAVE_PATH = LAUNCHER_ROOT_FOLDER + "/saves/";
1010
public static final String CUSTOM_USER_DIR = LAUNCHER_ROOT_FOLDER + "/userdir/";
1111
public static final String CUSTOM_SOUNDPACKS_DIR = CUSTOM_USER_DIR + "sound/";
12+
public static final String CUSTOM_MODS_DIR = CUSTOM_USER_DIR + "mods/";
1213
public static final String CUSTOM_TRASHED_SAVE_PATH = LAUNCHER_ROOT_FOLDER + "/trashed/saves/";
1314
public static final String SAVE_BACKUP_PATH = LAUNCHER_ROOT_FOLDER + "/backups";
1415

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package com.dazednconfused.catalauncher.mod;
2+
3+
4+
import static com.dazednconfused.catalauncher.helper.Constants.CUSTOM_MODS_DIR;
5+
6+
import io.vavr.control.Try;
7+
8+
import java.io.File;
9+
import java.nio.file.Path;
10+
import java.util.Arrays;
11+
import java.util.List;
12+
import java.util.Objects;
13+
import java.util.function.Consumer;
14+
import java.util.stream.Collectors;
15+
16+
import org.apache.commons.io.FileUtils;
17+
import org.slf4j.Logger;
18+
import org.slf4j.LoggerFactory;
19+
20+
public class ModManager {
21+
22+
private static final Logger LOGGER = LoggerFactory.getLogger(ModManager.class);
23+
24+
/**
25+
* Returns all mods currently found in {@link com.dazednconfused.catalauncher.helper.Constants#CUSTOM_MODS_DIR}.
26+
* */
27+
public static List<File> listAllMods() {
28+
LOGGER.debug("Listing all mods...");
29+
return Arrays.stream(Objects.requireNonNull(getModsFolder().listFiles()))
30+
.filter(file -> !file.getName().equals(".DS_Store"))
31+
.collect(Collectors.toList());
32+
}
33+
34+
/**
35+
* Deletes given {@code toBeDeleted} mod.
36+
* */
37+
public static void deleteMod(File toBeDeleted) {
38+
LOGGER.info("Deleting mod [{}]...", toBeDeleted);
39+
Try.run(() -> FileUtils.deleteDirectory(toBeDeleted)).onFailure(t -> LOGGER.error("There was an error deleting mod [{}]", toBeDeleted, t));
40+
}
41+
42+
/**
43+
* Installs given {@code toBeInstalled} mod inside {@link com.dazednconfused.catalauncher.helper.Constants#CUSTOM_MODS_DIR}.
44+
* */
45+
public static void installMod(File toBeInstalled, Consumer<Path> onDoneCallback) {
46+
LOGGER.info("Installing mod [{}]...", toBeInstalled);
47+
File installInto = new File(getModsFolder().getPath() + "/" + toBeInstalled.getName());
48+
49+
Try.run(() -> {
50+
LOGGER.debug("Copying [{}] into [{}]...", toBeInstalled, installInto);
51+
FileUtils.copyDirectory(toBeInstalled, installInto);
52+
}).onFailure(t -> LOGGER.error("There was an error installing mod [{}]", toBeInstalled, t)).andThen(() -> onDoneCallback.accept(installInto.toPath()));
53+
}
54+
55+
/**
56+
* Retrieves the {@link com.dazednconfused.catalauncher.helper.Constants#CUSTOM_MODS_DIR} as a {@link File}.
57+
* */
58+
private static File getModsFolder() {
59+
File modsPath = new File(CUSTOM_MODS_DIR);
60+
if (!modsPath.exists()) {
61+
LOGGER.debug("Mods folder [{}] not found. Creating...", modsPath);
62+
Try.of(modsPath::mkdirs).onFailure(t -> LOGGER.error("Could not create mods destination folder [{}]", modsPath, t));
63+
}
64+
65+
return modsPath;
66+
}
67+
}

src/main/resources/osx_launcher_wrapper.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ fi
2424
# (keep arguments here without quotes - also, "$@" doesn't work)
2525
# ${2} is --savedir
2626
# ${3} is the custom save directory, in quotes in case there are spaces in the path
27-
# ${4} is --world
28-
# ${5} is the latest world's name, in quotes because it may have spaces (which is fairly common in randomized world names)
29-
./cataclysm-tiles ${2} "${3}" ${4} "${5}"
27+
# ${4} is --userdir
28+
# ${5} is the custom user directory, in quotes in case there are spaces in the path
29+
# ${5} is --world
30+
# ${6} is the latest world's name, in quotes because it may have spaces (which is fairly common in randomized world names)
31+
./cataclysm-tiles ${2} "${3}" ${4} "${5}" ${6} "${7}"

0 commit comments

Comments
 (0)