Last active
January 8, 2024 09:12
-
-
Save doccaico/d47e79b7886880679640c6a6755c7fc5 to your computer and use it in GitHub Desktop.
Odinlang Updater in Odinlang (Windows only)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "core:c/libc" | |
import "core:encoding/json" | |
import "core:fmt" | |
import "core:mem" | |
import "core:os" | |
import "core:path/filepath" | |
import "core:strings" | |
// Date: 2024/01/08 | |
// Odin version: odin version dev-2024-01-nightly:1e1228fb | |
// Debug Build: odin build odin_update -debug | |
// Release Build: odin build odin_update | |
// 必要なソフト | |
// Windows: curl, 7za | |
// Windows上でしかテストしていません | |
json_url :: "https://f001.backblazeb2.com/file/odin-binaries/nightly.json" | |
sep :: filepath.SEPARATOR_STRING | |
odin_path :: "c:\\odin" | |
main :: proc() { | |
when ODIN_DEBUG { | |
track: mem.Tracking_Allocator | |
mem.tracking_allocator_init(&track, context.allocator) | |
context.allocator = mem.tracking_allocator(&track) | |
defer { | |
if len(track.allocation_map) > 0 { | |
fmt.eprintf("=== %v allocations not freed: ===\n", len(track.allocation_map)) | |
for _, entry in track.allocation_map { | |
fmt.eprintf("- %v bytes @ %v\n", entry.size, entry.location) | |
} | |
} | |
if len(track.bad_free_array) > 0 { | |
fmt.eprintf("=== %v incorrect frees: ===\n", len(track.bad_free_array)) | |
for entry in track.bad_free_array { | |
fmt.eprintf("- %p @ %v\n", entry.memory, entry.location) | |
} | |
} | |
mem.tracking_allocator_destroy(&track) | |
} | |
} | |
home := os.get_env("USERPROFILE") | |
defer delete(home) | |
// ~/Downloadsへ移動 | |
dir_path := strings.join([]string{home, "Downloads"}, sep) | |
defer delete(dir_path) | |
os.change_directory(dir_path) | |
// 保存する (nightly.json) | |
libc.system("curl -OL " + json_url) | |
// ファイルを読み込む | |
f, success := os.read_entire_file_from_filename("nightly.json") | |
if !success { | |
fmt.eprintln("something wrong (os.read_entire_file_from_filename)") | |
} | |
defer delete(f) | |
// nightly.jsonをパースする | |
j, err := json.parse(f) | |
if err != json.Error.None { | |
fmt.eprintln("something wrong (json.parse)") | |
os.exit(-1) | |
} | |
json.destroy_value(j) | |
// "2014-01-01"を取得する | |
date := j.(json.Object)["last_updated"].(json.String)[:10] | |
// ファイル名を設定する | |
filename := strings.join([]string{"odin-windows-amd64-nightly%2B", date, ".zip"}, "") | |
defer delete(filename) | |
// ダウンロードするURLを設定する | |
dl_url := strings.join( | |
[]string{"https://f001.backblazeb2.com/file/odin-binaries/nightly/", filename}, | |
"", | |
) | |
defer delete(dl_url) | |
// ファイル(.zip)をダウンロードする | |
curl := strings.join([]string{"curl", "-OL", dl_url}, " ") | |
defer delete(curl) | |
curl_command := strings.clone_to_cstring(curl) | |
defer delete(curl_command) | |
libc.system(curl_command) | |
// ファイルを解凍する | |
extraction := strings.join([]string{"7za", "x", "-aoa", filename}, " ") | |
defer delete(extraction) | |
extraction_command := strings.clone_to_cstring(extraction) | |
defer delete(extraction_command) | |
libc.system(extraction_command) | |
// "c:\odin"を削除する | |
libc.system("cmd.exe /c rmdir /q /s " + odin_path) | |
// "windows_artifacts"を"c:\odin"にする | |
os.rename("windows_artifacts", odin_path) | |
// ファイルを削除する | |
// - nightly.json | |
// - odin-windows-amd64-nightly%2B2024-01-07.zip | |
os.remove("nightly.json") | |
os.remove(filename) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment