Skip to content

Commit

Permalink
Fix silent crash in auto-updater if a mod's release has a bad version…
Browse files Browse the repository at this point in the history
… number
  • Loading branch information
kiooeht committed Nov 27, 2018
1 parent 0a55af7 commit 8f8ee46
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## Changelog ##
#### dev ####
* Fix silent crash in auto-updater if a mod's release has a bad version number

#### v3.6.1 ####
* Fix silent crash if a mod has a bad version number
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import com.google.gson.*;
import com.vdurmont.semver4j.Semver;
import com.vdurmont.semver4j.SemverException;

import javax.swing.*;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -57,7 +59,17 @@ protected void obtainLatestRelease() throws IOException
@Override
public Semver getLatestReleaseVersion() throws IOException
{
return ModInfo.safeVersion(getElementAsString("tag_name"));
try {
return ModInfo.safeVersion(getElementAsString("tag_name"));
} catch (SemverException e) {
JOptionPane.showMessageDialog(null,
getElementAsString("html_url")
+ "\nrelease has a missing or bad version number: \""
+ getElementAsString("tag_name")
+ "\".\nGo yell at the author to fix it.",
"Warning", JOptionPane.WARNING_MESSAGE);
return null;
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,12 @@ public boolean isNewerVersionAvailable(Semver current) throws IOException
if (latest == null) {
return false;
}
return getLatestReleaseVersion().compareTo(current) > 0;
Semver latestVersion = getLatestReleaseVersion();
if (latestVersion != null) {
return latestVersion.compareTo(current) > 0;
} else {
return false;
}
}

public JsonElement getElement(String key) throws IOException
Expand Down

0 comments on commit 8f8ee46

Please sign in to comment.