diff options
Diffstat (limited to 'main.odin')
| -rw-r--r-- | main.odin | 73 |
1 files changed, 38 insertions, 35 deletions
@@ -2,7 +2,6 @@ package main import "core:fmt" import "core:os" -import "core:os/os2" import "core:strings" import "core:strconv" import "core:sys/windows" @@ -49,7 +48,7 @@ main :: proc() { when ODIN_OS == .Windows { windows.SetConsoleOutputCP(windows.CODEPAGE.UTF8) } - exe_dir, _ = os2.get_executable_directory(context.allocator) + exe_dir, _ = os.get_executable_directory(context.allocator) data_dir = fmt.tprint(exe_dir, "statics_data", sep = SEPARATOR) alias_dir = fmt.tprint(data_dir, "aliases", sep = SEPARATOR) ics_cache_dir = fmt.tprint(data_dir, "ics_cache", sep = SEPARATOR) @@ -312,7 +311,11 @@ save_alias :: proc(name, url : string) -> bool { output_file_path := fmt.tprint(alias_dir, name, sep=SEPARATOR) just_fucking_make_the_directory(alias_dir) - os.write_entire_file(output_file_path, data) + err := os.write_entire_file(output_file_path, data) + + if err != .NONE { + fmt.eprintln(err) + } fmt.printfln("Saved alias [%s -> %s] to: %s", name, url, output_file_path) return true @@ -320,18 +323,18 @@ save_alias :: proc(name, url : string) -> bool { // Returns false if no aliases exist load_aliases :: proc() -> bool { - w := os2.walker_create(alias_dir) - defer os2.walker_destroy(&w) + w := os.walker_create(alias_dir) + defer os.walker_destroy(&w) found_alias := false - for info in os2.walker_walk(&w) { - if path, err := os2.walker_error(&w); err != nil { + for info in os.walker_walk(&w) { + if path, err := os.walker_error(&w); err != nil { fmt.eprintfln("ERROR: Failed to walk %s: %s", path, err) continue } - file_data, err := os2.read_entire_file_from_path(info.fullpath, allocator=context.allocator) + file_data, err := os.read_entire_file_from_path(info.fullpath, allocator=context.allocator) if err != nil { fmt.eprintln("ERROR: Failed to load data from %s: %s", info.fullpath, err) } else { @@ -385,51 +388,51 @@ import "core:path/filepath" // RECURSIVELY CREATES ANY DIRECTORY LIKE GOD INTENDED just_fucking_make_the_directory :: proc(path : string) -> (directory_now_exists : bool) { - path_clean := filepath.clean(path) - - if os.is_dir(path_clean) { - return true - } - - // Get parent directory - parent := filepath.dir(path_clean) - - // If parent doesn't exist, create it recursively - if parent != path_clean && !os.is_dir(parent) { - ok := just_fucking_make_the_directory(parent) - if !ok { - return false - } - } - - err := os.make_directory(path_clean, 0o755) - return err == os.ERROR_NONE + path_clean, _ := filepath.clean(path) + + if os.is_dir(path_clean) { + return true + } + + // Get parent directory + parent := filepath.dir(path_clean) + + // If parent doesn't exist, create it recursively + if parent != path_clean && !os.is_dir(parent) { + ok := just_fucking_make_the_directory(parent) + if !ok { + return false + } + } + + err := os.make_directory(path_clean) + return err == os.ERROR_NONE } exec :: proc(command: ^[]string) -> bool { - desc := os2.Process_Desc{ + desc := os.Process_Desc{ command = command^, // Inherit parent's print pipes - stdout = os2.stdout, - stderr = os2.stderr, - stdin = os2.stdin, + stdout = os.stdout, + stderr = os.stderr, + stdin = os.stdin, } - process, err := os2.process_start(desc) + process, err := os.process_start(desc) if err != nil { fmt.printf("Failed to start process: %v\n", err) return false } defer { - if close_err := os2.process_close(process); close_err != nil { + if close_err := os.process_terminate(process); close_err != nil { fmt.printf("Failed to close process: %v\n", close_err) } } - state, wait_err := os2.process_wait(process) + state, wait_err := os.process_wait(process) if wait_err != nil { fmt.printf("Error waiting for process: %v\n", wait_err) return false @@ -440,7 +443,7 @@ exec :: proc(command: ^[]string) -> bool { // TODO: Don't call out to the system's curl, ship my own download_file :: proc(url: string, output_path: string) -> (ok: bool) { - command : []string = {"curl", "-L", "-s", "-o", output_path, url} + command : []string = {"curl", "-L", "-s", "-o", output_path, url} exec(&command) return os.exists(output_path) }
\ No newline at end of file |