Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions Minecraft Note Block Studio.yyp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions scripts/check_updates/check_updates.gml
Original file line number Diff line number Diff line change
@@ -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
}
8 changes: 8 additions & 0 deletions scripts/check_updates/check_updates.yy

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 13 additions & 2 deletions scripts/control_create/control_create.gml
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -354,4 +363,6 @@ if (file_exists_lib(backup_file)) {
if (parameter_count() > 0) {
filename = parameter_string(1)
if (filename != "") load_song(filename)
}
}

log("Startup OK")
7 changes: 7 additions & 0 deletions scripts/control_draw/control_draw.gml
Original file line number Diff line number Diff line change
Expand Up @@ -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
31 changes: 3 additions & 28 deletions scripts/control_http/control_http.gml
Original file line number Diff line number Diff line change
@@ -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()
33 changes: 33 additions & 0 deletions scripts/draw_downloadprogress/draw_downloadprogress.gml
Original file line number Diff line number Diff line change
@@ -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)
8 changes: 8 additions & 0 deletions scripts/draw_downloadprogress/draw_downloadprogress.yy

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions scripts/file_get_size/file_get_size.gml
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions scripts/file_get_size/file_get_size.yy

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions scripts/get_update/get_update.gml
Original file line number Diff line number Diff line change
@@ -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
}
}
}
8 changes: 8 additions & 0 deletions scripts/get_update/get_update.yy

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion scripts/macros/macros.gml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"

Expand Down
4 changes: 3 additions & 1 deletion views/56f20c67-9fcc-4085-9cad-4785628f8831.yy

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions views/851a6098-0a35-48ef-8f86-8d6cd677f3fd.yy

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion views/a89d59b8-0ac7-4c34-a3aa-a1c4e95fa1e3.yy

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.