pairinteraction
A Rydberg Interaction Calculator
paths.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2024 Pairinteraction Developers
2// SPDX-License-Identifier: LGPL-3.0-or-later
3
4#pragma once
5
6#include <cstdlib>
7#include <filesystem>
8
10
12#ifdef _WIN32
13 char const *hdrive = getenv("HOMEDRIVE");
14 char const *hpath = getenv("HOMEPATH");
15 if (hdrive != nullptr && hpath != nullptr) {
16 std::filesystem::path path = std::string(hdrive) + hpath;
17 return path;
18 }
19#else
20 const char *home = std::getenv("HOME");
21 if (home != nullptr) {
22 std::filesystem::path path = home;
23 return path;
24 }
25#endif
26 return {"~"};
27}
28
31
32 char const *pairinteraction_cache_dir = getenv("PAIRINTERACTION_CACHE_DIR");
33 if (pairinteraction_cache_dir != nullptr) {
34 path = pairinteraction_cache_dir;
35 return path;
36 }
37
38#ifdef _WIN32
39 char const *localappdata = std::getenv("LOCALAPPDATA");
40 if (localappdata != nullptr) {
41 path = localappdata;
42 } else {
43 path = get_home_directory() / "AppData" / "Local";
44 }
45 path /= "pairinteraction";
46#elif __APPLE__
47 path = get_home_directory() / "Library" / "Caches" / "pairinteraction";
48#else
49 char const *xdg_cache_home = std::getenv("XDG_CACHE_HOME");
50 if (xdg_cache_home != nullptr) {
51 path = xdg_cache_home;
52 } else {
53 path = get_home_directory() / ".cache";
54 }
55 path /= "pairinteraction";
56#endif
57
58 return path;
59}
60
63
64 char const *pairinteraction_config_dir = getenv("PAIRINTERACTION_CONFIG_DIR");
65 if (pairinteraction_config_dir != nullptr) {
66 path = pairinteraction_config_dir;
67 return path;
68 }
69
70#ifdef _WIN32
71 char const *appdata = std::getenv("APPDATA");
72 if (appdata != nullptr) {
73 path = appdata;
74 } else {
75 path = get_home_directory() / "AppData" / "Roaming";
76 }
77 path /= "pairinteraction";
78#elif __APPLE__
79 path = get_home_directory() / "Library" / "Preferences" / "pairinteraction";
80#else
81 char const *xdg_config_home = std::getenv("XDG_CONFIG_HOME");
82 if (xdg_config_home != nullptr) {
83 path = xdg_config_home;
84 } else {
85 path = get_home_directory() / ".config";
86 }
87 path /= "pairinteraction";
88#endif
89
90 return path;
91}
92
93} // namespace pairinteraction::paths
std::filesystem::path get_home_directory()
Definition: paths.hpp:11
std::filesystem::path get_config_directory()
Definition: paths.hpp:61
std::filesystem::path get_cache_directory()
Definition: paths.hpp:29