Skip to content

Commit 8f8ee46

Browse files
committed
Fix silent crash in auto-updater if a mod's release has a bad version number
1 parent 0a55af7 commit 8f8ee46

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## Changelog ##
22
#### dev ####
3+
* Fix silent crash in auto-updater if a mod's release has a bad version number
34

45
#### v3.6.1 ####
56
* Fix silent crash if a mod has a bad version number

src/main/java/com/evacipated/cardcrawl/modthespire/GithubUpdateChecker.java

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

33
import com.google.gson.*;
44
import com.vdurmont.semver4j.Semver;
5+
import com.vdurmont.semver4j.SemverException;
56

7+
import javax.swing.*;
68
import java.io.FileNotFoundException;
79
import java.io.IOException;
810
import java.io.InputStream;
@@ -57,7 +59,17 @@ protected void obtainLatestRelease() throws IOException
5759
@Override
5860
public Semver getLatestReleaseVersion() throws IOException
5961
{
60-
return ModInfo.safeVersion(getElementAsString("tag_name"));
62+
try {
63+
return ModInfo.safeVersion(getElementAsString("tag_name"));
64+
} catch (SemverException e) {
65+
JOptionPane.showMessageDialog(null,
66+
getElementAsString("html_url")
67+
+ "\nrelease has a missing or bad version number: \""
68+
+ getElementAsString("tag_name")
69+
+ "\".\nGo yell at the author to fix it.",
70+
"Warning", JOptionPane.WARNING_MESSAGE);
71+
return null;
72+
}
6173
}
6274

6375
@Override

src/main/java/com/evacipated/cardcrawl/modthespire/UpdateChecker.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,12 @@ public boolean isNewerVersionAvailable(Semver current) throws IOException
9898
if (latest == null) {
9999
return false;
100100
}
101-
return getLatestReleaseVersion().compareTo(current) > 0;
101+
Semver latestVersion = getLatestReleaseVersion();
102+
if (latestVersion != null) {
103+
return latestVersion.compareTo(current) > 0;
104+
} else {
105+
return false;
106+
}
102107
}
103108

104109
public JsonElement getElement(String key) throws IOException

0 commit comments

Comments
 (0)