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

Commit

Permalink
no crash when no versions dir found
Browse files Browse the repository at this point in the history
  • Loading branch information
North-West-Wind committed Dec 2, 2022
1 parent 5746ce7 commit ea3cb09
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 8 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,28 @@ You will find modpack/mod name with some numbers after it. That is totally inten

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.

## Compiling
To compile the program yourself, some libraries are needed:
- [Apache Commons IO](https://commons.apache.org/proper/commons-io/)
- [jansi](https://github.com/fusesource/jansi)
- [JSON Simple](https://code.google.com/archive/p/json-simple)

Download them and put them somewhere.

This program is compiled with IntelliJ, so I don't know how to compile it outside of IntelliJ.
Anyway, follow the steps:
1. Download the repository by `git clone` or downloading as ZIP and extract it.
2. Launch IntelliJ IDEA if you haven't.
3. Open the directory where the files are extracted into.
4. In the top bar, go to File->Project Structure.
5. On the left side, go to Global Libraries.
6. Click the + symbol and choose Java.
7. In the file chooser, choose the Java libraries you downloaded.
8. Click OK on everything.
9. In the top bar, go to Build->Build Artifacts.
10. In the little window, choose Build.
11. The `.jar` file should be built inside `out/artifacts`.

## Support
If you want to support me, please consider becoming [my Patron](https://www.patreon.com/nww).

Expand Down
2 changes: 1 addition & 1 deletion src/ml/northwestwind/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

public class Constants {
public static final String CURSEFORGE_API = "https://northwestwind.ml/api/curseforge/mods/";
public static final String VERSION = "1.4.0";
public static final String VERSION = "1.4.1";
private static final String OS = System.getProperty("os.name").toLowerCase();
public static final boolean IS_WINDOWS = (OS.contains("win"));
public static final boolean IS_MAC = (OS.contains("mac"));
Expand Down
22 changes: 16 additions & 6 deletions src/ml/northwestwind/Modpack.java
Original file line number Diff line number Diff line change
Expand Up @@ -199,18 +199,28 @@ private static String getModVersion(JSONObject manifest) {
String[] splitted = id.split("-");
String loader = splitted[0].toLowerCase();
String modVer = Arrays.stream(splitted).skip(1).collect(Collectors.joining("-"));
List<String> versions = Arrays.stream(new File(Utils.getMinecraftPath() + File.separator + "versions").listFiles()).map(File::getName).collect(Collectors.toList());
Optional<String> found = versions.stream().filter(name -> name.contains(loader) && name.contains(modVer) && name.contains(version)).findFirst();
if (found.isPresent()) return found.get();
File versionsDir = new File(Utils.getMinecraftPath() + File.separator + "versions");
if (versionsDir.exists()) {
System.out.println(Ansi.ansi().fg(Ansi.Color.MAGENTA).a("Looking into versions directory: ").a(versionsDir.getAbsolutePath()).reset());
String[] versionNames = versionsDir.list();
if (versionNames != null) {
Optional<String> found = Arrays.stream(versionNames).filter(name -> name.contains(loader) && name.contains(modVer) && name.contains(version)).findFirst();
if (found.isPresent()) return found.get();
}
}
System.out.println(Ansi.ansi().fg(Ansi.Color.YELLOW).a("We couldn't find the mod launcher version required for your modpack!"));
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]"));
if (loader.equalsIgnoreCase("forge")) System.out.println(Ansi.ansi().a("https://files.minecraftforge.net/net/minecraftforge/forge/").reset());
else if (loader.equalsIgnoreCase("fabric")) System.out.println((Ansi.ansi().a("https://fabricmc.net/use/installer/")).reset());
else if (loader.equalsIgnoreCase("quilt")) System.out.println(Ansi.ansi().a("https://quiltmc.org/en/install/").reset());
if (Utils.readYesNo()) {
versions = Arrays.stream(new File(Utils.getMinecraftPath() + File.separator + "versions").listFiles()).map(f -> f.getName().toLowerCase()).collect(Collectors.toList());
found = versions.stream().filter(name -> name.contains(loader) && name.contains(modVer) && name.contains(version)).findFirst();
if (found.isPresent()) return found.get();
if (versionsDir.exists()) {
String[] versionNames = versionsDir.list();
if (versionNames != null) {
Optional<String> found = Arrays.stream(versionNames).filter(name -> name.contains(loader) && name.contains(modVer) && name.contains(version)).findFirst();
if (found.isPresent()) return found.get();
}
}
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."));
}
if (loader.equalsIgnoreCase("forge")) id = version + "-forge-" + modVer;
Expand Down
5 changes: 4 additions & 1 deletion update.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"1.4.1": {
"title": "Prevent crashing when no versions directory is found"
},
"1.4.0": {
"title": "Quilt support"
},
Expand Down Expand Up @@ -83,5 +86,5 @@
"1.2.0": {
"title": "Update Checker & Profile Generator"
},
"latest": "1.4.0"
"latest": "1.4.1"
}

0 comments on commit ea3cb09

Please sign in to comment.