2 * Copyright (C) 2003 Robert Kooima
4 * NEVERBALL is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published
6 * by the Free Software Foundation; either version 2 of the License,
7 * or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
20 #include "base_config.h"
24 /*---------------------------------------------------------------------------*/
26 static const char *pick_data_path(const char *arg_data_path)
28 static char dir[MAXSTR];
34 if ((env = getenv("NEVERBALL_DATA")))
37 if (path_is_abs(CONFIG_DATA))
40 SAFECPY(dir, fs_base_dir());
42 SAFECAT(dir, CONFIG_DATA);
47 static const char *pick_home_path(void)
52 return (path = getenv("APPDATA")) ? path : fs_base_dir();
54 return (path = getenv("HOME")) ? path : fs_base_dir();
58 void config_paths(const char *arg_data_path)
60 const char *data, *home, *user;
63 * Scan in turn the game data and user directories for archives,
64 * adding each archive to the search path. Archives with names
65 * further down the alphabet take precedence. After each scan,
66 * add the directory itself, taking precedence over archives added
72 data = pick_data_path(arg_data_path);
74 fs_add_path_with_archives(data);
78 home = pick_home_path();
79 user = concat_string(home, "/", CONFIG_USER, NULL);
81 /* Set up directory for writing, create if needed. */
83 if (!fs_set_write_dir(user))
85 if (fs_set_write_dir(home) && fs_mkdir(CONFIG_USER))
86 fs_set_write_dir(user);
89 fs_add_path_with_archives(user);
94 /*---------------------------------------------------------------------------*/