Update error handling for os2 on windows

This commit is contained in:
gingerBill
2022-05-12 12:54:27 +01:00
parent ccb38c3dc6
commit bb4f108487
15 changed files with 310 additions and 191 deletions
+18 -13
View File
@@ -1,18 +1,19 @@
package os2
import "core:strings"
import "core:runtime"
user_cache_dir :: proc(allocator := context.allocator) -> (dir: string, is_defined: bool) {
user_cache_dir :: proc(allocator: runtime.Allocator) -> (dir: string, err: Error) {
#partial switch ODIN_OS {
case .Windows:
dir = get_env("LocalAppData")
if dir != "" {
dir = strings.clone(dir, allocator)
dir = strings.clone_safe(dir, allocator) or_return
}
case .Darwin:
dir = get_env("HOME")
if dir != "" {
dir = strings.concatenate({dir, "/Library/Caches"}, allocator)
dir = strings.concatenate_safe({dir, "/Library/Caches"}, allocator) or_return
}
case: // All other UNIX systems
dir = get_env("XDG_CACHE_HOME")
@@ -21,24 +22,26 @@ user_cache_dir :: proc(allocator := context.allocator) -> (dir: string, is_defin
if dir == "" {
return
}
dir = strings.concatenate({dir, "/.cache"}, allocator)
dir = strings.concatenate_safe({dir, "/.cache"}, allocator) or_return
}
}
is_defined = dir != ""
if dir == "" {
err = .Invalid_Path
}
return
}
user_config_dir :: proc(allocator := context.allocator) -> (dir: string, is_defined: bool) {
user_config_dir :: proc(allocator: runtime.Allocator) -> (dir: string, err: Error) {
#partial switch ODIN_OS {
case .Windows:
dir = get_env("AppData")
if dir != "" {
dir = strings.clone(dir, allocator)
dir = strings.clone_safe(dir, allocator) or_return
}
case .Darwin:
dir = get_env("HOME")
if dir != "" {
dir = strings.concatenate({dir, "/Library/Application Support"}, allocator)
dir = strings.concatenate_safe({dir, "/Library/Application Support"}, allocator) or_return
}
case: // All other UNIX systems
dir = get_env("XDG_CACHE_HOME")
@@ -47,22 +50,24 @@ user_config_dir :: proc(allocator := context.allocator) -> (dir: string, is_defi
if dir == "" {
return
}
dir = strings.concatenate({dir, "/.config"}, allocator)
dir = strings.concatenate_safe({dir, "/.config"}, allocator) or_return
}
}
is_defined = dir != ""
if dir == "" {
err = .Invalid_Path
}
return
}
user_home_dir :: proc() -> (dir: string, is_defined: bool) {
user_home_dir :: proc() -> (dir: string, err: Error) {
env := "HOME"
#partial switch ODIN_OS {
case .Windows:
env = "USERPROFILE"
}
if v := get_env(env); v != "" {
return v, true
return v, nil
}
return "", false
return "", .Invalid_Path
}