|
18 | 18 | #include <sys/param.h> |
19 | 19 | #include <sys/mman.h> |
20 | 20 | #include <sys/time.h> |
| 21 | +#include <sys/stat.h> |
21 | 22 | #include "hw/sh4/dyna/blockmanager.h" |
22 | 23 | #include "hw/maple/maple_cfg.h" |
23 | 24 | #include <unistd.h> |
|
42 | 43 | #include "sdl/sdl.h" |
43 | 44 | #endif |
44 | 45 |
|
45 | | -#if defined(USES_HOMEDIR) |
46 | | - #include <sys/stat.h> |
47 | | -#endif |
48 | | - |
49 | 46 | #if defined(USE_EVDEV) |
50 | 47 | #include "linux-dist/evdev.h" |
51 | 48 | #endif |
@@ -237,83 +234,79 @@ void common_linux_setup(); |
237 | 234 |
|
238 | 235 | string find_user_config_dir() |
239 | 236 | { |
240 | | - #ifdef USES_HOMEDIR |
241 | | - struct stat info; |
242 | | - string home = ""; |
243 | | - if(getenv("HOME") != NULL) |
244 | | - { |
245 | | - // Support for the legacy config dir at "$HOME/.reicast" |
246 | | - string legacy_home = (string)getenv("HOME") + "/.reicast"; |
247 | | - if((stat(legacy_home.c_str(), &info) == 0) && (info.st_mode & S_IFDIR)) |
248 | | - { |
249 | | - // "$HOME/.reicast" already exists, let's use it! |
250 | | - return legacy_home; |
251 | | - } |
252 | | - |
253 | | - /* If $XDG_CONFIG_HOME is not set, we're supposed to use "$HOME/.config" instead. |
254 | | - * Consult the XDG Base Directory Specification for details: |
255 | | - * http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html#variables |
256 | | - */ |
257 | | - home = (string)getenv("HOME") + "/.config/reicast"; |
258 | | - } |
259 | | - if(getenv("XDG_CONFIG_HOME") != NULL) |
| 237 | + struct stat info; |
| 238 | + string home = ""; |
| 239 | + if(getenv("HOME") != NULL) |
| 240 | + { |
| 241 | + // Support for the legacy config dir at "$HOME/.reicast" |
| 242 | + string legacy_home = (string)getenv("HOME") + "/.reicast"; |
| 243 | + if((stat(legacy_home.c_str(), &info) == 0) && (info.st_mode & S_IFDIR)) |
260 | 244 | { |
261 | | - // If XDG_CONFIG_HOME is set explicitly, we'll use that instead of $HOME/.config |
262 | | - home = (string)getenv("XDG_CONFIG_HOME") + "/reicast"; |
| 245 | + // "$HOME/.reicast" already exists, let's use it! |
| 246 | + return legacy_home; |
263 | 247 | } |
264 | 248 |
|
265 | | - if(!home.empty()) |
| 249 | + /* If $XDG_CONFIG_HOME is not set, we're supposed to use "$HOME/.config" instead. |
| 250 | + * Consult the XDG Base Directory Specification for details: |
| 251 | + * http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html#variables |
| 252 | + */ |
| 253 | + home = (string)getenv("HOME") + "/.config/reicast"; |
| 254 | + } |
| 255 | + if(getenv("XDG_CONFIG_HOME") != NULL) |
| 256 | + { |
| 257 | + // If XDG_CONFIG_HOME is set explicitly, we'll use that instead of $HOME/.config |
| 258 | + home = (string)getenv("XDG_CONFIG_HOME") + "/reicast"; |
| 259 | + } |
| 260 | + |
| 261 | + if(!home.empty()) |
| 262 | + { |
| 263 | + if((stat(home.c_str(), &info) != 0) || !(info.st_mode & S_IFDIR)) |
266 | 264 | { |
267 | | - if((stat(home.c_str(), &info) != 0) || !(info.st_mode & S_IFDIR)) |
268 | | - { |
269 | | - // If the directory doesn't exist yet, create it! |
270 | | - mkdir(home.c_str(), 0755); |
271 | | - } |
272 | | - return home; |
| 265 | + // If the directory doesn't exist yet, create it! |
| 266 | + mkdir(home.c_str(), 0755); |
273 | 267 | } |
274 | | - #endif |
| 268 | + return home; |
| 269 | + } |
275 | 270 |
|
276 | 271 | // Unable to detect config dir, use the current folder |
277 | 272 | return "."; |
278 | 273 | } |
279 | 274 |
|
280 | 275 | string find_user_data_dir() |
281 | 276 | { |
282 | | - #ifdef USES_HOMEDIR |
283 | | - struct stat info; |
284 | | - string data = ""; |
285 | | - if(getenv("HOME") != NULL) |
286 | | - { |
287 | | - // Support for the legacy config dir at "$HOME/.reicast" |
288 | | - string legacy_data = (string)getenv("HOME") + "/.reicast"; |
289 | | - if((stat(legacy_data.c_str(), &info) == 0) && (info.st_mode & S_IFDIR)) |
290 | | - { |
291 | | - // "$HOME/.reicast" already exists, let's use it! |
292 | | - return legacy_data; |
293 | | - } |
294 | | - |
295 | | - /* If $XDG_DATA_HOME is not set, we're supposed to use "$HOME/.local/share" instead. |
296 | | - * Consult the XDG Base Directory Specification for details: |
297 | | - * http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html#variables |
298 | | - */ |
299 | | - data = (string)getenv("HOME") + "/.local/share/reicast"; |
300 | | - } |
301 | | - if(getenv("XDG_DATA_HOME") != NULL) |
| 277 | + struct stat info; |
| 278 | + string data = ""; |
| 279 | + if(getenv("HOME") != NULL) |
| 280 | + { |
| 281 | + // Support for the legacy config dir at "$HOME/.reicast" |
| 282 | + string legacy_data = (string)getenv("HOME") + "/.reicast"; |
| 283 | + if((stat(legacy_data.c_str(), &info) == 0) && (info.st_mode & S_IFDIR)) |
302 | 284 | { |
303 | | - // If XDG_DATA_HOME is set explicitly, we'll use that instead of $HOME/.config |
304 | | - data = (string)getenv("XDG_DATA_HOME") + "/reicast"; |
| 285 | + // "$HOME/.reicast" already exists, let's use it! |
| 286 | + return legacy_data; |
305 | 287 | } |
306 | 288 |
|
307 | | - if(!data.empty()) |
| 289 | + /* If $XDG_DATA_HOME is not set, we're supposed to use "$HOME/.local/share" instead. |
| 290 | + * Consult the XDG Base Directory Specification for details: |
| 291 | + * http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html#variables |
| 292 | + */ |
| 293 | + data = (string)getenv("HOME") + "/.local/share/reicast"; |
| 294 | + } |
| 295 | + if(getenv("XDG_DATA_HOME") != NULL) |
| 296 | + { |
| 297 | + // If XDG_DATA_HOME is set explicitly, we'll use that instead of $HOME/.config |
| 298 | + data = (string)getenv("XDG_DATA_HOME") + "/reicast"; |
| 299 | + } |
| 300 | + |
| 301 | + if(!data.empty()) |
| 302 | + { |
| 303 | + if((stat(data.c_str(), &info) != 0) || !(info.st_mode & S_IFDIR)) |
308 | 304 | { |
309 | | - if((stat(data.c_str(), &info) != 0) || !(info.st_mode & S_IFDIR)) |
310 | | - { |
311 | | - // If the directory doesn't exist yet, create it! |
312 | | - mkdir(data.c_str(), 0755); |
313 | | - } |
314 | | - return data; |
| 305 | + // If the directory doesn't exist yet, create it! |
| 306 | + mkdir(data.c_str(), 0755); |
315 | 307 | } |
316 | | - #endif |
| 308 | + return data; |
| 309 | + } |
317 | 310 |
|
318 | 311 | // Unable to detect config dir, use the current folder |
319 | 312 | return "."; |
@@ -439,8 +432,6 @@ int main(int argc, wchar* argv[]) |
439 | 432 | add_system_data_dir(dirs[i]); |
440 | 433 | } |
441 | 434 | add_system_data_dir(find_user_data_dir()); |
442 | | - printf("Config dir is: %s\n", get_writable_config_path("/").c_str()); |
443 | | - printf("Data dir is: %s\n", get_writable_data_path("/").c_str()); |
444 | 435 |
|
445 | 436 | #if defined(USE_SDL) |
446 | 437 | if (SDL_Init(0) != 0) |
|
0 commit comments