user.odin 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package os2
  2. import "core:strings"
  3. user_cache_dir :: proc(allocator := context.allocator) -> (dir: string, is_defined: bool) {
  4. switch ODIN_OS {
  5. case "windows":
  6. dir = get_env("LocalAppData")
  7. if dir != "" {
  8. dir = strings.clone(dir, allocator)
  9. }
  10. case "darwin":
  11. dir = get_env("HOME")
  12. if dir != "" {
  13. dir = strings.concatenate({dir, "/Library/Caches"}, allocator)
  14. }
  15. case: // All other UNIX systems
  16. dir = get_env("XDG_CACHE_HOME")
  17. if dir == "" {
  18. dir = get_env("HOME")
  19. if dir == "" {
  20. return
  21. }
  22. dir = strings.concatenate({dir, "/.cache"}, allocator)
  23. }
  24. }
  25. is_defined = dir != ""
  26. return
  27. }
  28. user_config_dir :: proc(allocator := context.allocator) -> (dir: string, is_defined: bool) {
  29. switch ODIN_OS {
  30. case "windows":
  31. dir = get_env("AppData")
  32. if dir != "" {
  33. dir = strings.clone(dir, allocator)
  34. }
  35. case "darwin":
  36. dir = get_env("HOME")
  37. if dir != "" {
  38. dir = strings.concatenate({dir, "/Library/Application Support"}, allocator)
  39. }
  40. case: // All other UNIX systems
  41. dir = get_env("XDG_CACHE_HOME")
  42. if dir == "" {
  43. dir = get_env("HOME")
  44. if dir == "" {
  45. return
  46. }
  47. dir = strings.concatenate({dir, "/.config"}, allocator)
  48. }
  49. }
  50. is_defined = dir != ""
  51. return
  52. }
  53. user_home_dir :: proc() -> (dir: string, is_defined: bool) {
  54. env := "HOME"
  55. switch ODIN_OS {
  56. case "windows":
  57. env = "USERPROFILE"
  58. }
  59. if v := get_env(env); v != "" {
  60. return v, true
  61. }
  62. return "", false
  63. }