Do not crash when downloadBytes fails
This commit is contained in:
@@ -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
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user