(svn r9129) -Codechange: unify parts of DeterminePaths.
This commit is contained in:
69
src/unix.cpp
69
src/unix.cpp
@@ -7,6 +7,7 @@
|
||||
#include "string.h"
|
||||
#include "table/strings.h"
|
||||
#include "variables.h"
|
||||
#include "fileio.h"
|
||||
|
||||
#include <dirent.h>
|
||||
#include <unistd.h>
|
||||
@@ -168,79 +169,41 @@ int CDECL main(int argc, char* argv[])
|
||||
return ret;
|
||||
}
|
||||
|
||||
void DeterminePaths()
|
||||
void DetermineBasePaths()
|
||||
{
|
||||
char *s;
|
||||
|
||||
_paths.game_data_dir = MallocT<char>(MAX_PATH);
|
||||
ttd_strlcpy(_paths.game_data_dir, GAME_DATA_DIR, MAX_PATH);
|
||||
#if defined SECOND_DATA_DIR
|
||||
#if defined(SECOND_DATA_DIR)
|
||||
_paths.second_data_dir = MallocT<char>(MAX_PATH);
|
||||
ttd_strlcpy(_paths.second_data_dir, SECOND_DATA_DIR, MAX_PATH);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(USE_HOMEDIR)
|
||||
{
|
||||
const char *homedir = getenv("HOME");
|
||||
const char *homedir = getenv("HOME");
|
||||
|
||||
if (homedir == NULL) {
|
||||
const struct passwd *pw = getpwuid(getuid());
|
||||
if (pw != NULL) homedir = pw->pw_dir;
|
||||
}
|
||||
|
||||
_paths.personal_dir = str_fmt("%s" PATHSEP "%s", homedir, PERSONAL_DIR);
|
||||
if (homedir == NULL) {
|
||||
const struct passwd *pw = getpwuid(getuid());
|
||||
if (pw != NULL) homedir = pw->pw_dir;
|
||||
}
|
||||
|
||||
_paths.personal_dir = str_fmt("%s" PATHSEP "%s", homedir, PERSONAL_DIR);
|
||||
#else /* not defined(USE_HOMEDIR) */
|
||||
|
||||
_paths.personal_dir = MallocT<char>(MAX_PATH);
|
||||
ttd_strlcpy(_paths.personal_dir, PERSONAL_DIR, MAX_PATH);
|
||||
|
||||
// check if absolute or relative path
|
||||
s = strchr(_paths.personal_dir, '/');
|
||||
/* check if absolute or relative path */
|
||||
const char *s = strchr(_paths.personal_dir, PATHSEPCHAR);
|
||||
|
||||
// add absolute path
|
||||
/* add absolute path */
|
||||
if (s == NULL || _paths.personal_dir != s) {
|
||||
getcwd(_paths.personal_dir, MAX_PATH);
|
||||
s = strchr(_paths.personal_dir, 0);
|
||||
*s++ = '/';
|
||||
ttd_strlcpy(s, PERSONAL_DIR, MAX_PATH);
|
||||
AppendPathSeparator(_paths.personal_dir, MAX_PATH);
|
||||
ttd_strlcat(_paths.personal_dir, PERSONAL_DIR, MAX_PATH);
|
||||
}
|
||||
|
||||
#endif /* defined(USE_HOMEDIR) */
|
||||
|
||||
s = strchr(_paths.personal_dir, 0);
|
||||
|
||||
// append a / ?
|
||||
if (s[-1] != '/') strcpy(s, "/");
|
||||
|
||||
_paths.save_dir = str_fmt("%ssave", _paths.personal_dir);
|
||||
_paths.autosave_dir = str_fmt("%s/autosave", _paths.save_dir);
|
||||
_paths.scenario_dir = str_fmt("%sscenario", _paths.personal_dir);
|
||||
_paths.heightmap_dir = str_fmt("%sscenario/heightmap", _paths.personal_dir);
|
||||
_paths.gm_dir = str_fmt("%sgm/", _paths.game_data_dir);
|
||||
_paths.data_dir = str_fmt("%sdata/", _paths.game_data_dir);
|
||||
|
||||
if (_config_file == NULL)
|
||||
_config_file = str_fmt("%sopenttd.cfg", _paths.personal_dir);
|
||||
|
||||
_highscore_file = str_fmt("%shs.dat", _paths.personal_dir);
|
||||
_log_file = str_fmt("%sopenttd.log", _paths.personal_dir);
|
||||
|
||||
#if defined CUSTOM_LANG_DIR
|
||||
// sets the search path for lng files to the custom one
|
||||
_paths.lang_dir = MallocT<char>(MAX_PATH);
|
||||
ttd_strlcpy( _paths.lang_dir, CUSTOM_LANG_DIR, MAX_PATH);
|
||||
#else
|
||||
_paths.lang_dir = str_fmt("%slang/", _paths.game_data_dir);
|
||||
#endif
|
||||
|
||||
// create necessary folders
|
||||
mkdir(_paths.personal_dir, 0755);
|
||||
mkdir(_paths.save_dir, 0755);
|
||||
mkdir(_paths.autosave_dir, 0755);
|
||||
mkdir(_paths.scenario_dir, 0755);
|
||||
mkdir(_paths.heightmap_dir, 0755);
|
||||
AppendPathSeparator(_paths.personal_dir, MAX_PATH);
|
||||
AppendPathSeparator(_paths.game_data_dir, MAX_PATH);
|
||||
}
|
||||
|
||||
bool InsertTextBufferClipboard(Textbuf *tb)
|
||||
|
Reference in New Issue
Block a user