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

Commit 4c24f5b

Browse files
Fixed profile update delete mod when no download
1 parent d282475 commit 4c24f5b

4 files changed

Lines changed: 15 additions & 8 deletions

File tree

src/ml/northwestwind/Constants.java

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

33
public class Constants {
44
public static final String CURSEFORGE_API = "https://addons-ecs.forgesvc.net/api/v2/addon/";
5-
public static final String VERSION = "1.2.8";
5+
public static final String VERSION = "1.2.9";
66
private static final String OS = System.getProperty("os.name").toLowerCase();
77
public static final boolean IS_WINDOWS = (OS.contains("win"));
88
public static final boolean IS_MAC = (OS.contains("mac"));

src/ml/northwestwind/Profile.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,10 @@ private static void update(String[] args) {
479479
for (String id : Arrays.stream(args).skip(1).toArray(String[]::new)) {
480480
try {
481481
if (!Utils.isInteger(id)) throw new NoSuchObjectException("Mod ID is invalid: " + id);
482+
if (!mods.containsKey(Integer.parseInt(id))) {
483+
System.out.println(Ansi.ansi().fg(Ansi.Color.YELLOW).a("Cannot find mod with ID " + id + " installed. Skipping updating this mod..."));
484+
continue;
485+
}
482486
JSONObject json = Utils.runRetry(() -> (JSONObject) Utils.readJsonFromUrl(Constants.CURSEFORGE_API + id));
483487
if (((long) ((JSONObject) json.get("categorySection")).get("gameCategoryId")) != 6)
484488
throw new NoSuchObjectException("The ID " + id + " does not represent a mod.");
@@ -490,11 +494,11 @@ private static void update(String[] args) {
490494
JSONObject bestFile = (JSONObject) f.get(0);
491495
Map.Entry<Integer, String> entry = mods.get(Integer.parseInt(id));
492496
if (((long) bestFile.get("id")) > entry.getKey()) {
493-
System.out.println(Ansi.ansi().fg(Ansi.Color.YELLOW).a(entry.getValue()).reset().a(" | ").fg(Ansi.Color.MAGENTA).a(entry.getKey()));
497+
System.out.println(Ansi.ansi().fg(Ansi.Color.YELLOW).a(entry.getValue()).reset().a(" | ").fg(Ansi.Color.MAGENTA).a(id));
494498
String downloadUrl = ((String) bestFile.get("downloadUrl")).replaceFirst("edge", "media");
495-
if (mods.containsKey(Integer.parseInt(id)))
496-
new File(profileConfig.getParent() + File.separator + "mods" + File.separator + entry.getValue() + "_" + id + "_" + entry.getKey() + ".jar").delete();
497499
String loc = Utils.downloadFile(downloadUrl, profileConfig.getParent() + File.separator + "mods", ((String) bestFile.get("fileName")).replace(".jar", "_" + id + "_" + bestFile.get("id") + ".jar"));
500+
if (loc == null) continue;
501+
new File(profileConfig.getParent() + File.separator + "mods" + File.separator + entry.getValue() + "_" + id + "_" + entry.getKey() + ".jar").delete();
498502
System.out.println(Ansi.ansi().fg(Ansi.Color.GREEN).a("Downloaded " + loc));
499503
}
500504
} catch (Exception e) {

src/ml/northwestwind/Utils.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,8 @@ public static boolean checkVersion(JSONArray versions, JSONObject config) {
223223
if (oppoLauncher == null || !versions.contains(oppoLauncher) || (versions.contains(oppoLauncher) && versions.contains(launcher)))
224224
launcherMatch = true;
225225
if (!versions.contains(requiredVer)) {
226-
if (Config.acceptParentVersionMod && !versions.contains(parentVersion(requiredVer))) {
227-
if (versions.stream().noneMatch(ver -> isMCVersionValid((String) ver))) versionMatch = true;
228-
} else versionMatch = true;
226+
if (Config.acceptParentVersionMod && versions.contains(parentVersion(requiredVer))) versionMatch = true;
227+
else if (!versions.contains(parentVersion(requiredVer)) && versions.stream().noneMatch(ver -> isMCVersionValid((String) ver))) versionMatch = true;
229228
} else versionMatch = true;
230229
return versionMatch && launcherMatch;
231230
}

update.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
{
2+
"1.2.9": {
3+
"title": "Profile \"update\" retains old mods",
4+
"description": "Fixed the profile \"update\" command removing old mod even when the new mod download fails."
5+
},
26
"1.2.8": {
37
"title": "Fixed \"update\" still deleting mods"
48
},
@@ -31,5 +35,5 @@
3135
"1.2.0": {
3236
"title": "Update Checker & Profile Generator"
3337
},
34-
"latest": "1.2.8"
38+
"latest": "1.2.9"
3539
}

0 commit comments

Comments
 (0)