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"
28 /*---------------------------------------------------------------------------*/
30 static const char *pick_data_path(const char *arg_data_path)
32 static char dir[MAXSTR];
38 if ((env = getenv("NEVERBALL_DATA")))
41 if (path_is_abs(CONFIG_DATA))
44 SAFECPY(dir, fs_base_dir());
46 SAFECAT(dir, CONFIG_DATA);
51 static const char *pick_home_path(void)
56 return (path = getenv("APPDATA")) ? path : fs_base_dir();
58 return (path = getenv("HOME")) ? path : fs_base_dir();
62 void config_paths(const char *arg_data_path)
64 const char *data, *home, *user;
67 * Scan in turn the game data and user directories for archives,
68 * adding each archive to the search path. Archives with names
69 * further down the alphabet take precedence. After each scan,
70 * add the directory itself, taking precedence over archives added
76 data = pick_data_path(arg_data_path);
78 fs_add_path_with_archives(data);
82 home = pick_home_path();
83 user = concat_string(home, "/", CONFIG_USER, NULL);
85 /* Set up directory for writing, create if needed. */
87 if (!fs_set_write_dir(user))
89 if (fs_set_write_dir(home) && fs_mkdir(CONFIG_USER))
90 fs_set_write_dir(user);
93 fs_add_path_with_archives(user);
98 /*---------------------------------------------------------------------------*/