29 #include <sys/types.h> 33 string game::User_data_dir;
34 string game::Global_data_dir;
35 string game::Game_data_dir;
40 Global_data_dir = game_dir;
41 #ifndef SINGLE_DIR_INST 42 User_data_dir = getenv (
"HOME");
43 User_data_dir +=
"/.adonthell";
45 User_data_dir = Global_data_dir;
51 Game_data_dir = game_dir;
54 bool game::directory_exist (
const string & dirname)
56 DIR * dir = opendir (dirname.c_str ());
67 bool game::file_exist (
const string & fname)
69 FILE * file = fopen (fname.c_str (),
"r");
85 if (fname[0] ==
'/')
return fname;
88 if ((ret =
game_data_dir () +
"/") !=
"/" && file_exist (ret + fname))
107 if (dirname[0] ==
'/')
return dirname;
110 if ((ret =
game_data_dir () +
"/") !=
"/" && directory_exist (ret + dirname))
116 else if (directory_exist ((ret =
user_data_dir () +
"/") + dirname))
static string find_directory(const string &dirname)
Finds a directory in the directories hierarchy, starting searching from game_data_dir(), then global_data_dir() and finally user_data_dir().
static void init(string game_dir)
Initialise the game framework.
static string global_data_dir()
Returns the absolute path to the global data directory.
static string find_file(const string &fname)
Finds a file in the directories hierarchy, starting searching from game_data_dir(), then global_data_dir() and finally user_data_dir().
static string game_data_dir()
Returns the absolute path to the current game's directory (if any).
static void set_game_data_dir(string game_dir)
Specify an additional data directory containing game data.
static string user_data_dir()
Returns the absolute path to the user data directory (usually ~/.adonthell).