Do not crash when downloadBytes fails

This commit is contained in:
luboslenco
2020-01-22 13:06:40 +01:00
parent 510a502b69
commit f66fa79a82
2 changed files with 22 additions and 12 deletions
+6 -1
View File
@@ -84,6 +84,11 @@ class File {
public static function downloadBytes(url: String): Bytes {
var save = Path.data() + Path.sep + "download.bin";
download(url, save);
return Bytes.ofData(Krom.loadBlob(save));
try {
return Bytes.ofData(Krom.loadBlob(save));
}
catch (e: Dynamic) {
return null;
}
}
}
+16 -11
View File
@@ -347,19 +347,24 @@ class UIMenu {
// Retrieve latest version number
var url = "'https://luboslenco.gitlab.io/armorpaint/index.html'";
var blob = File.downloadBytes(url);
// Compare versions
var update = Json.parse(blob.toString());
var updateVersion = Std.int(update.version);
if (updateVersion > 0) {
var date = BuildMacros.date().split(" ")[0].substr(2); // 2019 -> 19
var dateInt = Std.parseInt(date.replace("-", ""));
if (updateVersion > dateInt) {
UIBox.showMessage("Update", "Update is available!\nPlease visit armorpaint.org to download.");
}
else {
UIBox.showMessage("Update", "You are up to date!");
if (blob != null) {
// Compare versions
var update = Json.parse(blob.toString());
var updateVersion = Std.int(update.version);
if (updateVersion > 0) {
var date = BuildMacros.date().split(" ")[0].substr(2); // 2019 -> 19
var dateInt = Std.parseInt(date.replace("-", ""));
if (updateVersion > dateInt) {
UIBox.showMessage("Update", "Update is available!\nPlease visit armorpaint.org to download.");
}
else {
UIBox.showMessage("Update", "You are up to date!");
}
}
}
else {
UIBox.showMessage("Update", "Unable to check for updates.\nPlease visit armorpaint.org.");
}
}
if (ui.button(" About...", Left)) {
var sha = BuildMacros.sha();