mirror of https://github.com/OpenTTD/OpenTTD
(svn r22465) -Fix [FS#4613]: When determining the executable path failed, the working directory was used instead, circumventing the not-home-directory check.
parent
003dee6e38
commit
b319fb31d5
|
@ -867,8 +867,9 @@ extern void DetermineBasePaths(const char *exe);
|
||||||
* in the same way we remove the name from the executable name.
|
* in the same way we remove the name from the executable name.
|
||||||
* @param exe the path to the executable
|
* @param exe the path to the executable
|
||||||
*/
|
*/
|
||||||
void ChangeWorkingDirectory(const char *exe)
|
static bool ChangeWorkingDirectoryToExecutable(const char *exe)
|
||||||
{
|
{
|
||||||
|
bool success = false;
|
||||||
#ifdef WITH_COCOA
|
#ifdef WITH_COCOA
|
||||||
char *app_bundle = strchr(exe, '.');
|
char *app_bundle = strchr(exe, '.');
|
||||||
while (app_bundle != NULL && strncasecmp(app_bundle, ".app", 4) != 0) app_bundle = strchr(&app_bundle[1], '.');
|
while (app_bundle != NULL && strncasecmp(app_bundle, ".app", 4) != 0) app_bundle = strchr(&app_bundle[1], '.');
|
||||||
|
@ -882,12 +883,17 @@ void ChangeWorkingDirectory(const char *exe)
|
||||||
/* If we want to go to the root, we can't use cd C:, but we must use '/' */
|
/* If we want to go to the root, we can't use cd C:, but we must use '/' */
|
||||||
if (s[-1] == ':') chdir("/");
|
if (s[-1] == ':') chdir("/");
|
||||||
#endif
|
#endif
|
||||||
if (chdir(exe) != 0) DEBUG(misc, 0, "Directory with the binary does not exist?");
|
if (chdir(exe) != 0) {
|
||||||
|
DEBUG(misc, 0, "Directory with the binary does not exist?");
|
||||||
|
} else {
|
||||||
|
success = true;
|
||||||
|
}
|
||||||
*s = PATHSEPCHAR;
|
*s = PATHSEPCHAR;
|
||||||
}
|
}
|
||||||
#ifdef WITH_COCOA
|
#ifdef WITH_COCOA
|
||||||
if (app_bundle != NULL) app_bundle[0] = '.';
|
if (app_bundle != NULL) app_bundle[0] = '.';
|
||||||
#endif /* WITH_COCOA */
|
#endif /* WITH_COCOA */
|
||||||
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -965,14 +971,19 @@ void DetermineBasePaths(const char *exe)
|
||||||
_do_scan_working_directory = DoScanWorkingDirectory();
|
_do_scan_working_directory = DoScanWorkingDirectory();
|
||||||
|
|
||||||
/* Change the working directory to that one of the executable */
|
/* Change the working directory to that one of the executable */
|
||||||
ChangeWorkingDirectory(exe);
|
if (ChangeWorkingDirectoryToExecutable(exe)) {
|
||||||
if (getcwd(tmp, MAX_PATH) == NULL) *tmp = '\0';
|
if (getcwd(tmp, MAX_PATH) == NULL) *tmp = '\0';
|
||||||
AppendPathSeparator(tmp, MAX_PATH);
|
AppendPathSeparator(tmp, MAX_PATH);
|
||||||
_searchpaths[SP_BINARY_DIR] = strdup(tmp);
|
_searchpaths[SP_BINARY_DIR] = strdup(tmp);
|
||||||
|
} else {
|
||||||
|
_searchpaths[SP_BINARY_DIR] = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (_searchpaths[SP_WORKING_DIR] != NULL) {
|
if (_searchpaths[SP_WORKING_DIR] != NULL) {
|
||||||
/* Go back to the current working directory. */
|
/* Go back to the current working directory. */
|
||||||
ChangeWorkingDirectory(_searchpaths[SP_WORKING_DIR]);
|
if (chdir(_searchpaths[SP_WORKING_DIR]) != 0) {
|
||||||
|
DEBUG(misc, 0, "Failed to return to working directory!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(__MORPHOS__) || defined(__AMIGA__) || defined(DOS) || defined(OS2)
|
#if defined(__MORPHOS__) || defined(__AMIGA__) || defined(DOS) || defined(OS2)
|
||||||
|
|
Loading…
Reference in New Issue