diff --git a/Minecraft Note Block Studio.yyp b/Minecraft Note Block Studio.yyp index 4d5147f1f..a560fb1d4 100644 --- a/Minecraft Note Block Studio.yyp +++ b/Minecraft Note Block Studio.yyp @@ -646,6 +646,14 @@ "resourceType": "GMScript" } }, + { + "Key": "252af0d3-fda0-4686-99ee-e50c77599791", + "Value": { + "id": "6b3ab05d-6386-40a1-9e9d-e82a79991252", + "resourcePath": "scripts\\draw_downloadprogress\\draw_downloadprogress.yy", + "resourceType": "GMScript" + } + }, { "Key": "262425f5-3f8a-4051-87ac-9e5516650c6f", "Value": { @@ -1030,6 +1038,14 @@ "resourceType": "GMFolder" } }, + { + "Key": "3c1514e1-5885-49b4-86ef-115f1fdec3ea", + "Value": { + "id": "a12fd799-06e2-4b03-94e2-28c9e406f39e", + "resourcePath": "scripts\\check_updates\\check_updates.yy", + "resourceType": "GMScript" + } + }, { "Key": "3c3845a5-e4dd-4c4f-85c2-1ec8e589979c", "Value": { @@ -3814,6 +3830,14 @@ "resourceType": "GMSprite" } }, + { + "Key": "e74f03fa-1407-4d25-93ab-0dccb3eb91ca", + "Value": { + "id": "922ab784-ea4b-4bb9-83da-0ddc43463332", + "resourcePath": "scripts\\get_update\\get_update.yy", + "resourceType": "GMScript" + } + }, { "Key": "e7ef2956-a38a-44fc-858f-fcc654140bb3", "Value": { @@ -3918,6 +3942,14 @@ "resourceType": "GMScript" } }, + { + "Key": "f136e3ca-963a-4648-ae87-60c3ee8476a9", + "Value": { + "id": "af2a944a-2b4a-4349-adf6-66e1b3b3936e", + "resourcePath": "scripts\\file_get_size\\file_get_size.yy", + "resourceType": "GMScript" + } + }, { "Key": "f156b801-b9bb-4929-af5c-2b9df4acc238", "Value": { @@ -4163,6 +4195,8 @@ "0ce5a906-0342-42fb-89f3-04f3609f5689", "3ef34f15-11b7-471c-aa91-4f191100f959", "0097ab11-b126-461a-8194-e3aaf09a6ddd", + "3c1514e1-5885-49b4-86ef-115f1fdec3ea", + "e74f03fa-1407-4d25-93ab-0dccb3eb91ca", "f51781f2-7a5a-49bf-895e-4338650ab87c", "5a190bcc-d435-4a9c-ab94-dc50a0f3107d", "5dcc6852-84c3-404a-9c42-174e7315465a", @@ -4202,6 +4236,7 @@ "af9a3525-3682-420e-b2a0-d952cc347296", "a0fe9bd7-a654-4de6-abd8-41b5be7e41a8", "7dfa1c5c-2dd7-4604-a776-ff2a1c2d26b0", + "f136e3ca-963a-4648-ae87-60c3ee8476a9", "1501c0c9-c863-4723-9ccc-f004078dc78d", "c032c6f1-0ef4-493c-82d0-cbc09ed91a90", "c54d19c6-44b4-403d-83b5-46645ef6d7d0", @@ -4276,6 +4311,7 @@ "28131748-b621-459e-952c-fcd16de0bd8b", "36bf530d-9afd-4915-8e0f-6d9162ea03b2", "f6cfba59-defd-47c1-b2fa-8fa627a1c1a4", + "252af0d3-fda0-4686-99ee-e50c77599791", "ffdb58ba-3567-4019-acf7-c6e674131bbb", "bb77e968-5a4f-4c9d-954b-7ddca77d2c0a", "a38ae6de-e436-4b50-af0b-964bf5f26cd9", diff --git a/scripts/check_updates/check_updates.gml b/scripts/check_updates/check_updates.gml new file mode 100644 index 000000000..649d5e0da --- /dev/null +++ b/scripts/check_updates/check_updates.gml @@ -0,0 +1,34 @@ +// check_updates() +// Handles the update checking +// update values: +// -1: unable to check for update +// 1: update found +// 2: up to date + +if (async_load[? "id"] = update_http) { + update_http = -1 + if (async_load[? "http_status"] = 200) { + var res = async_load[? "result"]; + if (is_string(res)) { + res = json_decode(res) + if(res[?"tag_name"] != undefined){ + var newVersion = string_replace(res[?"tag_name"],"v","") + if (string_count(".", newVersion) = 2) { + if (newVersion = version) { + update = 2 + } else { + if (question("Version " + newVersion + " is available! Do you want to download it?", "Update available!")) { + update_download = http_get_file("https://github.com/HielkeMinecraft/OpenNoteBlockStudio/releases/latest/download/Minecraft.Note.Block.Studio.exe", update_file) + update = 4 + } else { + update = 1 + } + } + } + }else + update = -1 + }else + update = -1 + } else + update = -1 +} diff --git a/scripts/check_updates/check_updates.yy b/scripts/check_updates/check_updates.yy new file mode 100644 index 000000000..6f8dc9cb8 --- /dev/null +++ b/scripts/check_updates/check_updates.yy @@ -0,0 +1,8 @@ +{ + "id": "3c1514e1-5885-49b4-86ef-115f1fdec3ea", + "modelName": "GMScript", + "mvc": "1.0", + "name": "check_updates", + "IsCompatibility": false, + "IsDnD": false +} \ No newline at end of file diff --git a/scripts/control_create/control_create.gml b/scripts/control_create/control_create.gml index 2995c7ec5..b656f17dd 100644 --- a/scripts/control_create/control_create.gml +++ b/scripts/control_create/control_create.gml @@ -333,15 +333,24 @@ save_version = nbs_version load_settings() change_theme() if (show_welcome) window = w_greeting + +// Updates if (check_update) update_http = http_get("https://api.github.com/repos/HielkeMinecraft/OpenNoteBlockStudio/releases/latest") else update_http = -1 +update_download = -1 +downloaded_size = 0 +total_size = -1 if (file_exists_lib(settings_file) && vers != version) { window = w_update update = 3 } -log("Startup OK") + +// Delete old installer +if (file_exists_lib(update_file)) { + files_delete_lib(update_file) +} // Auto-recovery if (file_exists_lib(backup_file)) { @@ -354,4 +363,6 @@ if (file_exists_lib(backup_file)) { if (parameter_count() > 0) { filename = parameter_string(1) if (filename != "") load_song(filename) -} \ No newline at end of file +} + +log("Startup OK") \ No newline at end of file diff --git a/scripts/control_draw/control_draw.gml b/scripts/control_draw/control_draw.gml index 2169cdb72..aab49422d 100644 --- a/scripts/control_draw/control_draw.gml +++ b/scripts/control_draw/control_draw.gml @@ -1323,6 +1323,13 @@ if (mouse_check_button_released(mb_left)) { } if (window = w_releasemouse && !mouse_check_button(mb_left)) window = 0 draw_windows() + +// Draw update progress bar +if (update == 4) { + window = -1 + draw_downloadprogress("Update", "Downloading update...", downloaded_size, total_size) +} + window_set_cursor(curs) mouse_xprev = mouse_x mouse_yprev = mouse_y diff --git a/scripts/control_http/control_http.gml b/scripts/control_http/control_http.gml index 999056c11..3985d4e71 100644 --- a/scripts/control_http/control_http.gml +++ b/scripts/control_http/control_http.gml @@ -1,30 +1,5 @@ // control_http() -// Handles the update checking -// update values: -// -1: unable to check for update -// 1: update found -// 2: up to date +// Handles the check for updates, then attempts to download it if one is available -if (async_load[? "id"] = update_http) { - update_http = -1 - if (async_load[? "http_status"] = 200) { - var res = async_load[? "result"]; - if (is_string(res)) { - res = json_decode(res) - if(res[?"tag_name"] != undefined){ - var newVersion = string_replace(res[?"tag_name"],"v","") - if (string_count(".", newVersion) = 2) { - if (newVersion = version) { - update = 2 - } else { - if (question("Version " + newVersion + " is available! Do you want to download it?", "Update available!")) open_url(link_download) - update = 1 - } - } - }else - update = -1 - }else - update = -1 - } else - update = -1 -} +check_updates() +get_update() \ No newline at end of file diff --git a/scripts/draw_downloadprogress/draw_downloadprogress.gml b/scripts/draw_downloadprogress/draw_downloadprogress.gml new file mode 100644 index 000000000..9055e380d --- /dev/null +++ b/scripts/draw_downloadprogress/draw_downloadprogress.gml @@ -0,0 +1,33 @@ +// draw_downloadprogress(caption, desc, downloaded_size, total_size) +var caption, desc, done, total, done_mb, total_mb, done_text, total_text, text, percent, x1, y1; +caption = argument0 +desc = argument1 +done = argument2 +total = argument3 +percent = done/total +done_mb = done/power(1024, 2) +total_mb = total/power(1024, 2) +x1 = floor(window_width / 2 - 150) +y1 = floor(window_height / 2 - 50) +draw_theme_color() +draw_window(x1, y1, x1 + 300, y1 + 100) +draw_set_font(fnt_mainbold) +draw_text(x1 + 16, y1 + 16, caption) +draw_set_font(fnt_main) +draw_set_halign(fa_center) +draw_text(floor(window_width / 2), y1 + 40, desc) +draw_set_color(10512464) +draw_rectangle(x1 + 30, y1 + 60, x1 + 30 + percent * 240, y1 + 80, 0) +draw_theme_color() +draw_rectangle(x1 + 30, y1 + 60, x1 + 270, y1 + 80, 1) +if (percent > 0.5) draw_set_color(c_white) +if (total <= 0) { + done_text = "-.--" + total_text = "-.--" +} else { + done_text = string_format(done_mb, 0, 2) + total_text = string_format(total_mb, 0, 2) +} +text = done_text + "/" + total_text + " MB (" + string(round(percent * 100)) + "%)" +draw_text(floor(window_width / 2), y1 + 65, text) +draw_set_halign(fa_left) diff --git a/scripts/draw_downloadprogress/draw_downloadprogress.yy b/scripts/draw_downloadprogress/draw_downloadprogress.yy new file mode 100644 index 000000000..6ff61dd8a --- /dev/null +++ b/scripts/draw_downloadprogress/draw_downloadprogress.yy @@ -0,0 +1,8 @@ +{ + "id": "252af0d3-fda0-4686-99ee-e50c77599791", + "modelName": "GMScript", + "mvc": "1.0", + "name": "draw_downloadprogress", + "IsCompatibility": false, + "IsDnD": false +} \ No newline at end of file diff --git a/scripts/file_get_size/file_get_size.gml b/scripts/file_get_size/file_get_size.gml new file mode 100644 index 000000000..f421b4cc9 --- /dev/null +++ b/scripts/file_get_size/file_get_size.gml @@ -0,0 +1,12 @@ +// file_get_size(path) +// Returns the size of a file, in bytes. + +var path, file, size +path = argument0 +if (file_exists(path)) { + file = file_bin_open(path, 0) + size = file_bin_size(file) + file_bin_close(file) + return size +} +return 0 diff --git a/scripts/file_get_size/file_get_size.yy b/scripts/file_get_size/file_get_size.yy new file mode 100644 index 000000000..e3111ed65 --- /dev/null +++ b/scripts/file_get_size/file_get_size.yy @@ -0,0 +1,8 @@ +{ + "id": "f136e3ca-963a-4648-ae87-60c3ee8476a9", + "modelName": "GMScript", + "mvc": "1.0", + "name": "file_get_size", + "IsCompatibility": false, + "IsDnD": false +} \ No newline at end of file diff --git a/scripts/get_update/get_update.gml b/scripts/get_update/get_update.gml new file mode 100644 index 000000000..a553622bc --- /dev/null +++ b/scripts/get_update/get_update.gml @@ -0,0 +1,29 @@ +// get_update() +// Attempts to download a newer version if one is available +// status: +// 1 - receiving packets (download in progress) +// 0 - success (download complete) + +if (async_load[? "id"] == update_download) { + var status = async_load[? "status"] + if (status == 1) { + downloaded_size = async_load[? "sizeDownloaded"] + total_size = async_load[? "contentLength"] + } else if (status == 0) { + // Download was interrupted, may have been successful or not (if connection was interrupted) + update = 5 + if (file_get_size(update_file) == total_size) { + show_message("Download complete! Click OK to begin installing the update.") + // At this point, the game is paused until the user dismisses the message + ExecuteShell("\"" + update_file + "\"", false, true) + game_end() + } else { + if (question("Failed to download update. Do you want to open the Note Block Studio website and update manually?", "Failed")) { + open_url(link_download) + } + window = w_greeting + update_download = -1 + update = 1 + } + } +} \ No newline at end of file diff --git a/scripts/get_update/get_update.yy b/scripts/get_update/get_update.yy new file mode 100644 index 000000000..48397d03e --- /dev/null +++ b/scripts/get_update/get_update.yy @@ -0,0 +1,8 @@ +{ + "id": "e74f03fa-1407-4d25-93ab-0dccb3eb91ca", + "modelName": "GMScript", + "mvc": "1.0", + "name": "get_update", + "IsCompatibility": false, + "IsDnD": false +} \ No newline at end of file diff --git a/scripts/macros/macros.gml b/scripts/macros/macros.gml index aa1975f6e..83f1508c5 100644 --- a/scripts/macros/macros.gml +++ b/scripts/macros/macros.gml @@ -4,7 +4,7 @@ #macro nbs_version 4 #macro pat_version 1 -#macro link_download "https://github.com/HielkeMinecraft/OpenNoteBlockStudio/releases/latest" +#macro link_download "https://hielkeminecraft.github.io/OpenNoteBlockStudio/" #macro link_topic "https://www.minecraftforum.net/forums/mapping-and-modding-java-edition/minecraft-tools/2945101-open-minecraft-note-block-studio" #macro file_directory game_save_id @@ -14,6 +14,7 @@ #macro pattern_directory data_directory + "Patterns\\" #macro log_file file_directory + "log.txt" #macro temp_file file_directory + "tmp.file" +#macro update_file file_directory + "Minecraft Note Block Studio Installer.exe" #macro settings_file file_directory + "settings.ini" #macro backup_file file_directory + "backup.nbs" diff --git a/views/56f20c67-9fcc-4085-9cad-4785628f8831.yy b/views/56f20c67-9fcc-4085-9cad-4785628f8831.yy index 4ac67695c..393d5fa7b 100644 --- a/views/56f20c67-9fcc-4085-9cad-4785628f8831.yy +++ b/views/56f20c67-9fcc-4085-9cad-4785628f8831.yy @@ -15,7 +15,9 @@ "caf03170-c1fc-42ce-abd4-cc04c23cc07e", "0ce5a906-0342-42fb-89f3-04f3609f5689", "3ef34f15-11b7-471c-aa91-4f191100f959", - "0097ab11-b126-461a-8194-e3aaf09a6ddd" + "0097ab11-b126-461a-8194-e3aaf09a6ddd", + "3c1514e1-5885-49b4-86ef-115f1fdec3ea", + "e74f03fa-1407-4d25-93ab-0dccb3eb91ca" ], "filterType": "GMScript", "folderName": "Controller", diff --git a/views/851a6098-0a35-48ef-8f86-8d6cd677f3fd.yy b/views/851a6098-0a35-48ef-8f86-8d6cd677f3fd.yy index 102e78982..eef07bed5 100644 --- a/views/851a6098-0a35-48ef-8f86-8d6cd677f3fd.yy +++ b/views/851a6098-0a35-48ef-8f86-8d6cd677f3fd.yy @@ -21,6 +21,7 @@ "28131748-b621-459e-952c-fcd16de0bd8b", "36bf530d-9afd-4915-8e0f-6d9162ea03b2", "f6cfba59-defd-47c1-b2fa-8fa627a1c1a4", + "252af0d3-fda0-4686-99ee-e50c77599791", "ffdb58ba-3567-4019-acf7-c6e674131bbb", "bb77e968-5a4f-4c9d-954b-7ddca77d2c0a", "a38ae6de-e436-4b50-af0b-964bf5f26cd9", diff --git a/views/a89d59b8-0ac7-4c34-a3aa-a1c4e95fa1e3.yy b/views/a89d59b8-0ac7-4c34-a3aa-a1c4e95fa1e3.yy index 71b17a16a..8bfea894a 100644 --- a/views/a89d59b8-0ac7-4c34-a3aa-a1c4e95fa1e3.yy +++ b/views/a89d59b8-0ac7-4c34-a3aa-a1c4e95fa1e3.yy @@ -16,7 +16,8 @@ "395e2149-7095-4b85-9a90-9b808723ddb7", "af9a3525-3682-420e-b2a0-d952cc347296", "a0fe9bd7-a654-4de6-abd8-41b5be7e41a8", - "7dfa1c5c-2dd7-4604-a776-ff2a1c2d26b0" + "7dfa1c5c-2dd7-4604-a776-ff2a1c2d26b0", + "f136e3ca-963a-4648-ae87-60c3ee8476a9" ], "filterType": "GMScript", "folderName": "File",