1
0
Fork 0

(svn r10194) -Codechange: prefer the current working directory above the user's home directory when openttd.cfg exists in the current working directory, otherwise prefer the home directory.

release/0.6
rubidium 2007-06-17 21:26:57 +00:00
parent f5776a8c6b
commit 5938dea88d
2 changed files with 33 additions and 11 deletions

View File

@ -224,7 +224,7 @@ char *FioGetFullPath(char *buf, size_t buflen, Searchpath sp, Subdirectory subdi
assert(subdir < NUM_SUBDIRS); assert(subdir < NUM_SUBDIRS);
assert(sp < NUM_SEARCHPATHS); assert(sp < NUM_SEARCHPATHS);
snprintf(buf, buflen, "%s%s" PATHSEP "%s", _searchpaths[sp], _subdirs[subdir], filename); snprintf(buf, buflen, "%s%s%s", _searchpaths[sp], _subdirs[subdir], filename);
return buf; return buf;
} }
@ -464,17 +464,39 @@ void DeterminePaths(const char *exe)
Searchpath sp; Searchpath sp;
FOR_ALL_SEARCHPATHS(sp) DEBUG(misc, 4, "%s added as search path", _searchpaths[sp]); FOR_ALL_SEARCHPATHS(sp) DEBUG(misc, 4, "%s added as search path", _searchpaths[sp]);
/* Search for the first search path, as that will be the closest to if (_config_file != NULL) {
* the personal directory. */ _personal_dir = strdup(_config_file);
FOR_ALL_SEARCHPATHS(sp) { char *end = strrchr(_personal_dir , PATHSEPCHAR);
_personal_dir = strdup(_searchpaths[sp]); if (end == NULL) {
DEBUG(misc, 3, "%s found as personal directory", _searchpaths[sp]); _personal_dir[0] = '\0';
break; } else {
end[1] = '\0';
}
} else {
char personal_dir[MAX_PATH];
FioFindFullPath(personal_dir, lengthof(personal_dir), BASE_DIR, "openttd.cfg");
if (FileExists(personal_dir)) {
char *end = strrchr(personal_dir, PATHSEPCHAR);
if (end != NULL) end[1] = '\0';
_personal_dir = strdup(personal_dir);
_config_file = str_fmt("%sopenttd.cfg", _personal_dir);
} else {
static const Searchpath new_openttd_cfg_order[] = {
SP_PERSONAL_DIR, SP_BINARY_DIR, SP_WORKING_DIR, SP_SHARED_DIR, SP_INSTALLATION_DIR
};
for (uint i = 0; i < lengthof(new_openttd_cfg_order); i++) {
if (IsValidSearchPath(new_openttd_cfg_order[i])) {
_personal_dir = strdup(_searchpaths[new_openttd_cfg_order[i]]);
_config_file = str_fmt("%sopenttd.cfg", _personal_dir);
break;
}
}
}
} }
if (_config_file == NULL) { DEBUG(misc, 3, "%s found as personal directory", _personal_dir);
_config_file = str_fmt("%sopenttd.cfg", _personal_dir);
}
_highscore_file = str_fmt("%shs.dat", _personal_dir); _highscore_file = str_fmt("%shs.dat", _personal_dir);
_log_file = str_fmt("%sopenttd.log", _personal_dir); _log_file = str_fmt("%sopenttd.log", _personal_dir);

View File

@ -40,9 +40,9 @@ enum Subdirectory {
* Types of searchpaths OpenTTD might use * Types of searchpaths OpenTTD might use
*/ */
enum Searchpath { enum Searchpath {
SP_WORKING_DIR, ///< Search in the working directory
SP_PERSONAL_DIR, ///< Search in the personal directory SP_PERSONAL_DIR, ///< Search in the personal directory
SP_SHARED_DIR, ///< Search in the shared directory, like 'Shared Files' under Windows SP_SHARED_DIR, ///< Search in the shared directory, like 'Shared Files' under Windows
SP_WORKING_DIR, ///< Search in the working directory
SP_BINARY_DIR, ///< Search in the directory where the binary resides SP_BINARY_DIR, ///< Search in the directory where the binary resides
SP_INSTALLATION_DIR, ///< Search in the installation directory SP_INSTALLATION_DIR, ///< Search in the installation directory
SP_APPLICATION_BUNDLE_DIR, ///< Search within the application bundle SP_APPLICATION_BUNDLE_DIR, ///< Search within the application bundle