From a7487b5ede858fef58a7caf9ca0db955c57d8cd8 Mon Sep 17 00:00:00 2001 From: rubidium Date: Sun, 15 May 2011 18:06:13 +0000 Subject: [PATCH] (svn r22467) [1.1] -Backport from trunk: - Fix: When determining the executable path failed, the working directory was used instead, circumventing the not-home-directory check [FS#4613] (r22465) - Fix: [Windows] Prevent a crash when launching OpenTTD with -d from a MSYS console [FS#4587] (r22464) - Fix: Update the saveload window immediatelly after scanning a new directory, so queued events reach the window when already updated [FS#4615] (r22463) --- known-bugs.txt | 6 ++++++ src/fileio.cpp | 25 ++++++++++++++++++------- src/fios_gui.cpp | 9 +++++++++ src/lang/catalan.txt | 2 ++ src/lang/dutch.txt | 2 ++ src/os/windows/win32.cpp | 16 +++++++++++++++- 6 files changed, 52 insertions(+), 8 deletions(-) diff --git a/known-bugs.txt b/known-bugs.txt index 499801c256..4fd48c77a4 100644 --- a/known-bugs.txt +++ b/known-bugs.txt @@ -293,3 +293,9 @@ Can't change volume inside OpenTTD [FS#4416] in OpenTTD. As a result you can't change the volume inside OpenTTD for backends such as SDL; just use the volume control provided by your operating system. + +Can't run OpenTTD with the -d option from a MSYS console [FS#4587] + The MSYS console does not allow OpenTTD to open an extra console for + debugging output. Compiling OpenTTD with the --enable-console + configure option prevents this issue and allows the -d option to use + the MSYS console for its output. diff --git a/src/fileio.cpp b/src/fileio.cpp index c56640579a..3b8d2aaaa3 100644 --- a/src/fileio.cpp +++ b/src/fileio.cpp @@ -860,8 +860,9 @@ extern void DetermineBasePaths(const char *exe); * in the same way we remove the name from the executable name. * @param exe the path to the executable */ -void ChangeWorkingDirectory(const char *exe) +static bool ChangeWorkingDirectoryToExecutable(const char *exe) { + bool success = false; #ifdef WITH_COCOA char *app_bundle = strchr(exe, '.'); while (app_bundle != NULL && strncasecmp(app_bundle, ".app", 4) != 0) app_bundle = strchr(&app_bundle[1], '.'); @@ -875,12 +876,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 (s[-1] == ':') chdir("/"); #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; } #ifdef WITH_COCOA if (app_bundle != NULL) app_bundle[0] = '.'; #endif /* WITH_COCOA */ + return success; } /** @@ -958,14 +964,19 @@ void DetermineBasePaths(const char *exe) _do_scan_working_directory = DoScanWorkingDirectory(); /* Change the working directory to that one of the executable */ - ChangeWorkingDirectory(exe); - if (getcwd(tmp, MAX_PATH) == NULL) *tmp = '\0'; - AppendPathSeparator(tmp, MAX_PATH); - _searchpaths[SP_BINARY_DIR] = strdup(tmp); + if (ChangeWorkingDirectoryToExecutable(exe)) { + if (getcwd(tmp, MAX_PATH) == NULL) *tmp = '\0'; + AppendPathSeparator(tmp, MAX_PATH); + _searchpaths[SP_BINARY_DIR] = strdup(tmp); + } else { + _searchpaths[SP_BINARY_DIR] = NULL; + } if (_searchpaths[SP_WORKING_DIR] != NULL) { /* 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) diff --git a/src/fios_gui.cpp b/src/fios_gui.cpp index 3b97b420b2..efca60fce9 100644 --- a/src/fios_gui.cpp +++ b/src/fios_gui.cpp @@ -211,6 +211,9 @@ void BuildFileList() default: FiosGetSavegameList(_saveload_mode); break; } + + /* Invalidate saveload window */ + InvalidateWindowData(WC_SAVELOAD, 0, 2, true); } static void MakeSortedSaveGameList() @@ -684,6 +687,12 @@ public: !_load_check_data.HasNewGrfs()); } break; + case 2: + /* _fios_items changed */ + this->vscroll->SetCount(_fios_items.Length()); + this->selected = NULL; + _load_check_data.Clear(); + break; } } }; diff --git a/src/lang/catalan.txt b/src/lang/catalan.txt index 132288c910..4416b971d2 100644 --- a/src/lang/catalan.txt +++ b/src/lang/catalan.txt @@ -2485,6 +2485,8 @@ STR_NEWGRF_ERROR_CORRUPT_SPRITE :{YELLOW}{STRING STR_NEWGRF_ERROR_MULTIPLE_ACTION_8 :Conté múltiples Accions 8 entrades STR_NEWGRF_ERROR_READ_BOUNDS :Lectura després de la fi d'un pseudo-sprite STR_NEWGRF_ERROR_MISSING_SPRITES :{WHITE}Al joc de gràfics base establert actualment li falten un nombre d'sprites.{}Si us plau actualitza el joc de gràfics base +STR_NEWGRF_ERROR_GRM_FAILED :Els recursos GRF demanats no estan disponibles +STR_NEWGRF_ERROR_FORCEFULLY_DISABLED :{2:STRING} ha estat desactivat per {4:STRING} # NewGRF related 'general' warnings STR_NEWGRF_POPUP_CAUTION_CAPTION :{WHITE}Alerta! diff --git a/src/lang/dutch.txt b/src/lang/dutch.txt index fa2056f4b5..1ccc9c58a8 100644 --- a/src/lang/dutch.txt +++ b/src/lang/dutch.txt @@ -2484,6 +2484,8 @@ STR_NEWGRF_ERROR_CORRUPT_SPRITE :{YELLOW}{STRING STR_NEWGRF_ERROR_MULTIPLE_ACTION_8 :Bevat meerdere 'Action 8'-elementen STR_NEWGRF_ERROR_READ_BOUNDS :Lees voorbij einde van pseudo-sprite STR_NEWGRF_ERROR_MISSING_SPRITES :{WHITE}De huidige basis graphics-set mist een aantal sprites..{}Werk de graphics-set bij aub +STR_NEWGRF_ERROR_GRM_FAILED :Gevraagde GRF middelen niet beschikbaar +STR_NEWGRF_ERROR_FORCEFULLY_DISABLED :{2:STRING} is uitgeschakeld door {4:STRING} # NewGRF related 'general' warnings STR_NEWGRF_POPUP_CAUTION_CAPTION :{WHITE}Waarschuwing! diff --git a/src/os/windows/win32.cpp b/src/os/windows/win32.cpp index 14f010a760..85368bf69a 100644 --- a/src/os/windows/win32.cpp +++ b/src/os/windows/win32.cpp @@ -297,7 +297,21 @@ void CreateConsole() /* redirect unbuffered STDIN, STDOUT, STDERR to the console */ #if !defined(__CYGWIN__) - *stdout = *_fdopen( _open_osfhandle((intptr_t)hand, _O_TEXT), "w" ); + + /* Check if we can open a handle to STDOUT. */ + int fd = _open_osfhandle((intptr_t)hand, _O_TEXT); + if (fd == -1) { + /* Free everything related to the console. */ + FreeConsole(); + _has_console = false; + _close(fd); + CloseHandle(hand); + + ShowInfo("Unable to open an output handle to the console. Check known-bugs.txt for details."); + return; + } + + *stdout = *_fdopen(fd, "w"); *stdin = *_fdopen(_open_osfhandle((intptr_t)GetStdHandle(STD_INPUT_HANDLE), _O_TEXT), "r" ); *stderr = *_fdopen(_open_osfhandle((intptr_t)GetStdHandle(STD_ERROR_HANDLE), _O_TEXT), "w" ); #else