59
59
// given the #ifdef/#else above, the following is not required.
60
60
// Nor it is the #if FreeBSD below.
61
61
#ifdef __OpenBSD__
62
- #include < sys/types.h>
63
- #include < sys/sysctl.h>
64
- #include < unistd.h>
65
- #include < limits.h>
62
+ #include < sys/types.h>
63
+ #include < sys/sysctl.h>
64
+ #include < unistd.h>
65
+ #include < limits.h>
66
66
#endif
67
67
68
68
#ifdef __FreeBSD__
69
69
#include < sys/types.h>
70
70
#include < sys/sysctl.h>
71
71
#endif
72
72
73
- static std::string GetHomeDirectory () {
74
- std::string directory;
75
-
76
- #ifdef WIN32
77
- DWORD bufferSize = GetEnvironmentVariable (L" APPDATA" , 0 , 0 );
78
- wchar_t *buffer = new wchar_t [bufferSize + 2 ];
79
- GetEnvironmentVariable (L" APPDATA" , buffer, bufferSize);
80
- directory.assign (u16to8 (buffer));
81
- delete[] buffer;
82
- #else
83
- directory = std::string (std::getenv (" HOME" ));
84
- #endif
85
-
86
- return directory;
87
- }
88
-
89
- static std::string getDataDirectoryRoot () {
90
- #ifdef WIN32
91
- return GetHomeDirectory ();
92
- #else
93
- return GetHomeDirectory () + " /.config" ;
94
- #endif
95
- }
96
-
97
73
static inline void silentDelete (const std::string fn) {
98
74
boost::system::error_code ec;
99
75
boost::filesystem::remove (boost::filesystem::path (fn), ec);
100
76
}
101
77
102
78
namespace musik { namespace core {
103
79
80
+ static std::string getDataDirectoryRoot () {
81
+ #ifdef WIN32
82
+ return GetHomeDirectory ();
83
+ #else
84
+ return GetHomeDirectory () + " /.config" ;
85
+ #endif
86
+ }
87
+
104
88
std::string GetPluginDirectory () {
105
89
std::string path (GetApplicationDirectory ());
106
90
path.append (" /plugins/" );
@@ -135,26 +119,25 @@ namespace musik { namespace core {
135
119
size_t bufsize = sizeof (pathbuf);
136
120
sysctl (mib, 4 , pathbuf, &bufsize, nullptr , 0 );
137
121
#elif defined __OpenBSD__
138
- int mib[4 ];
139
- char **argv;
140
- size_t len = ARG_MAX;
122
+ int mib[4 ];
123
+ char **argv;
124
+ size_t len = ARG_MAX;
141
125
142
- mib[0 ] = CTL_KERN;
143
- mib[1 ] = KERN_PROC_ARGS;
144
- mib[2 ] = getpid ();
145
- mib[3 ] = KERN_PROC_ARGV;
126
+ mib[0 ] = CTL_KERN;
127
+ mib[1 ] = KERN_PROC_ARGS;
128
+ mib[2 ] = getpid ();
129
+ mib[3 ] = KERN_PROC_ARGV;
146
130
147
- argv = new char *[len];
148
- if (sysctl (mib, 4 , argv, &len, nullptr , 0 ) < 0 ) abort ();
131
+ argv = new char *[len];
132
+ if (sysctl (mib, 4 , argv, &len, nullptr , 0 ) < 0 ) abort ();
149
133
150
- boost::filesystem::path command = boost::filesystem::system_complete (argv[0 ]);
151
- realpath (command.c_str (), pathbuf);
152
- delete[] argv;
134
+ boost::filesystem::path command = boost::filesystem::system_complete (argv[0 ]);
135
+ realpath (command.c_str (), pathbuf);
136
+ delete[] argv;
153
137
#else
154
138
std::string pathToProc = u8fmt (" /proc/%d/exe" , (int ) getpid ());
155
139
readlink (pathToProc.c_str (), pathbuf, PATH_MAX);
156
- #endif
157
-
140
+ #endif
158
141
result.assign (pathbuf);
159
142
size_t last = result.find_last_of (" /" );
160
143
result = result.substr (0 , last); /* remove filename component */
@@ -167,13 +150,19 @@ namespace musik { namespace core {
167
150
std::string directory;
168
151
169
152
#ifdef WIN32
170
- DWORD bufferSize = GetEnvironmentVariable (L" USERPROFILE " , 0 , 0 );
171
- wchar_t * buffer = new wchar_t [bufferSize + 2 ];
172
- GetEnvironmentVariable (L" USERPROFILE " , buffer, bufferSize);
153
+ DWORD bufferSize = GetEnvironmentVariable (L" APPDATA " , 0 , 0 );
154
+ wchar_t * buffer = new wchar_t [bufferSize + 2 ];
155
+ GetEnvironmentVariable (L" APPDATA " , buffer, bufferSize);
173
156
directory.assign (u16to8 (buffer));
174
157
delete[] buffer;
175
158
#else
176
- directory = std::string (std::getenv (" HOME" ));
159
+ const char * result = std::getenv (" XDG_CONFIG_HOME" );
160
+ if (result && strlen (result)) {
161
+ directory = std::string (result);
162
+ }
163
+ else {
164
+ directory = std::string (std::getenv (" HOME" ));
165
+ }
177
166
#endif
178
167
179
168
return directory;
0 commit comments