| ... | ... | @@ -15,27 +15,12 @@ pub const GetAppDataDirError = error{ |
| 15 | 15 | pub fn getAppDataDir(allocator: mem.Allocator, appname: []const u8) GetAppDataDirError![]u8 { |
| 16 | 16 | switch (builtin.os.tag) { |
| 17 | 17 | .windows => { |
| 18 | | var dir_path_ptr: [*:0]u16 = undefined; |
| 19 | | switch (os.windows.shell32.SHGetKnownFolderPath( |
| 20 | | &os.windows.FOLDERID_LocalAppData, |
| 21 | | os.windows.KF_FLAG_CREATE, |
| 22 | | null, |
| 23 | | &dir_path_ptr, |
| 24 | | )) { |
| 25 | | os.windows.S_OK => { |
| 26 | | defer os.windows.ole32.CoTaskMemFree(dir_path_ptr); |
| 27 | | const global_dir = unicode.utf16leToUtf8Alloc(allocator, mem.sliceTo(dir_path_ptr, 0)) catch |err| switch (err) { |
| 28 | | error.UnexpectedSecondSurrogateHalf => return error.AppDataDirUnavailable, |
| 29 | | error.ExpectedSecondSurrogateHalf => return error.AppDataDirUnavailable, |
| 30 | | error.DanglingSurrogateHalf => return error.AppDataDirUnavailable, |
| 31 | | error.OutOfMemory => return error.OutOfMemory, |
| 32 | | }; |
| 33 | | defer allocator.free(global_dir); |
| 34 | | return fs.path.join(allocator, &[_][]const u8{ global_dir, appname }); |
| 35 | | }, |
| 36 | | os.windows.E_OUTOFMEMORY => return error.OutOfMemory, |
| 18 | const local_app_data_dir = std.process.getEnvVarOwned(allocator, "LOCALAPPDATA") catch |err| switch (err) { |
| 19 | error.OutOfMemory => |e| return e, |
| 37 | 20 | else => return error.AppDataDirUnavailable, |
| 38 | | } |
| 21 | }; |
| 22 | defer allocator.free(local_app_data_dir); |
| 23 | return fs.path.join(allocator, &[_][]const u8{ local_app_data_dir, appname }); |
| 39 | 24 | }, |
| 40 | 25 | .macos => { |
| 41 | 26 | const home_dir = os.getenv("HOME") orelse { |