-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpath.hpp
67 lines (52 loc) · 1.43 KB
/
path.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#pragma once
#include <nall/string.hpp>
namespace nall::Path {
inline auto active() -> string {
char path[PATH_MAX] = "";
(void)getcwd(path, PATH_MAX);
string result = path;
if(!result) result = ".";
result.transform("\\", "/");
if(!result.endsWith("/")) result.append("/");
return result;
}
inline auto real(string_view name) -> string {
string result;
char path[PATH_MAX] = "";
if(::realpath(name, path)) result = Location::path(string{path}.transform("\\", "/"));
if(!result) return active();
result.transform("\\", "/");
if(!result.endsWith("/")) result.append("/");
return result;
}
auto program() -> string;
// /
// c:/
auto root() -> string;
// /home/username/
// c:/users/username/
auto user() -> string;
// /home/username/Desktop/
// c:/users/username/Desktop/
auto desktop(string_view name = {}) -> string;
//todo: MacOS uses the same location for userData() and userSettings()
//... is there a better option here?
// /home/username/.config/
// ~/Library/Application Support/
// c:/users/username/appdata/roaming/
auto userSettings() -> string;
// /home/username/.local/share/
// ~/Library/Application Support/
// c:/users/username/appdata/local/
auto userData() -> string;
// /usr/share
// /Library/Application Support/
// c:/ProgramData/
auto sharedData() -> string;
// /tmp
// c:/users/username/AppData/Local/Temp/
auto temporary() -> string;
}
#if defined(NALL_HEADER_ONLY)
#include <nall/path.cpp>
#endif