Skip to content
This repository was archived by the owner on Sep 9, 2023. It is now read-only.

Commit ea3cb09

Browse files
no crash when no versions dir found
1 parent 5746ce7 commit ea3cb09

4 files changed

Lines changed: 43 additions & 8 deletions

File tree

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,28 @@ You will find modpack/mod name with some numbers after it. That is totally inten
5757

5858
Installing a modpack will also generate a profile. However, the profile doesn't use the correct mod loader. Please install the mod loader yourself as instructed.
5959

60+
## Compiling
61+
To compile the program yourself, some libraries are needed:
62+
- [Apache Commons IO](https://commons.apache.org/proper/commons-io/)
63+
- [jansi](https://github.com/fusesource/jansi)
64+
- [JSON Simple](https://code.google.com/archive/p/json-simple)
65+
66+
Download them and put them somewhere.
67+
68+
This program is compiled with IntelliJ, so I don't know how to compile it outside of IntelliJ.
69+
Anyway, follow the steps:
70+
1. Download the repository by `git clone` or downloading as ZIP and extract it.
71+
2. Launch IntelliJ IDEA if you haven't.
72+
3. Open the directory where the files are extracted into.
73+
4. In the top bar, go to File->Project Structure.
74+
5. On the left side, go to Global Libraries.
75+
6. Click the + symbol and choose Java.
76+
7. In the file chooser, choose the Java libraries you downloaded.
77+
8. Click OK on everything.
78+
9. In the top bar, go to Build->Build Artifacts.
79+
10. In the little window, choose Build.
80+
11. The `.jar` file should be built inside `out/artifacts`.
81+
6082
## Support
6183
If you want to support me, please consider becoming [my Patron](https://www.patreon.com/nww).
6284

src/ml/northwestwind/Constants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
public class Constants {
88
public static final String CURSEFORGE_API = "https://northwestwind.ml/api/curseforge/mods/";
9-
public static final String VERSION = "1.4.0";
9+
public static final String VERSION = "1.4.1";
1010
private static final String OS = System.getProperty("os.name").toLowerCase();
1111
public static final boolean IS_WINDOWS = (OS.contains("win"));
1212
public static final boolean IS_MAC = (OS.contains("mac"));

src/ml/northwestwind/Modpack.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -199,18 +199,28 @@ private static String getModVersion(JSONObject manifest) {
199199
String[] splitted = id.split("-");
200200
String loader = splitted[0].toLowerCase();
201201
String modVer = Arrays.stream(splitted).skip(1).collect(Collectors.joining("-"));
202-
List<String> versions = Arrays.stream(new File(Utils.getMinecraftPath() + File.separator + "versions").listFiles()).map(File::getName).collect(Collectors.toList());
203-
Optional<String> found = versions.stream().filter(name -> name.contains(loader) && name.contains(modVer) && name.contains(version)).findFirst();
204-
if (found.isPresent()) return found.get();
202+
File versionsDir = new File(Utils.getMinecraftPath() + File.separator + "versions");
203+
if (versionsDir.exists()) {
204+
System.out.println(Ansi.ansi().fg(Ansi.Color.MAGENTA).a("Looking into versions directory: ").a(versionsDir.getAbsolutePath()).reset());
205+
String[] versionNames = versionsDir.list();
206+
if (versionNames != null) {
207+
Optional<String> found = Arrays.stream(versionNames).filter(name -> name.contains(loader) && name.contains(modVer) && name.contains(version)).findFirst();
208+
if (found.isPresent()) return found.get();
209+
}
210+
}
205211
System.out.println(Ansi.ansi().fg(Ansi.Color.YELLOW).a("We couldn't find the mod launcher version required for your modpack!"));
206212
System.out.println(Ansi.ansi().a("Please download the required mod launcher version from the link below. Enter y after you have that installed, or enter n to skip it for now [y/n]"));
207213
if (loader.equalsIgnoreCase("forge")) System.out.println(Ansi.ansi().a("https://files.minecraftforge.net/net/minecraftforge/forge/").reset());
208214
else if (loader.equalsIgnoreCase("fabric")) System.out.println((Ansi.ansi().a("https://fabricmc.net/use/installer/")).reset());
209215
else if (loader.equalsIgnoreCase("quilt")) System.out.println(Ansi.ansi().a("https://quiltmc.org/en/install/").reset());
210216
if (Utils.readYesNo()) {
211-
versions = Arrays.stream(new File(Utils.getMinecraftPath() + File.separator + "versions").listFiles()).map(f -> f.getName().toLowerCase()).collect(Collectors.toList());
212-
found = versions.stream().filter(name -> name.contains(loader) && name.contains(modVer) && name.contains(version)).findFirst();
213-
if (found.isPresent()) return found.get();
217+
if (versionsDir.exists()) {
218+
String[] versionNames = versionsDir.list();
219+
if (versionNames != null) {
220+
Optional<String> found = Arrays.stream(versionNames).filter(name -> name.contains(loader) && name.contains(modVer) && name.contains(version)).findFirst();
221+
if (found.isPresent()) return found.get();
222+
}
223+
}
214224
System.out.println(Ansi.ansi().fg(Ansi.Color.YELLOW).a("We still couldn't find the mod launcher version required! The installation will continue anyway. You may have to change the profile settings after this."));
215225
}
216226
if (loader.equalsIgnoreCase("forge")) id = version + "-forge-" + modVer;

update.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
{
2+
"1.4.1": {
3+
"title": "Prevent crashing when no versions directory is found"
4+
},
25
"1.4.0": {
36
"title": "Quilt support"
47
},
@@ -83,5 +86,5 @@
8386
"1.2.0": {
8487
"title": "Update Checker & Profile Generator"
8588
},
86-
"latest": "1.4.0"
89+
"latest": "1.4.1"
8790
}

0 commit comments

Comments
 (0)