diff --git a/src/gfx.cpp b/src/gfx.cpp index 88943534cf..c5fbcac2ff 100644 --- a/src/gfx.cpp +++ b/src/gfx.cpp @@ -1561,7 +1561,7 @@ void DrawDirtyBlocks() _modal_progress_work_mutex->EndCritical(); /* Wait a while and update _realtime_tick so we are given the rights */ - CSleep(MODAL_PROGRESS_REDRAW_TIMEOUT); + if (!IsFirstModalProgressLoop()) CSleep(MODAL_PROGRESS_REDRAW_TIMEOUT); _realtime_tick += MODAL_PROGRESS_REDRAW_TIMEOUT; _modal_progress_paint_mutex->BeginCritical(); _modal_progress_work_mutex->BeginCritical(); diff --git a/src/lang/english.txt b/src/lang/english.txt index fdf5a5b84f..80601c1aaa 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -2527,6 +2527,7 @@ STR_NEWGRF_INVALID_INDUSTRYTYPE :BeginCritical(); - - /* Only then can we really start, especially by marking the whole screen dirty. Get those other windows hidden!. */ - MarkWholeScreenDirty(); _modal_progress_work_mutex->BeginCritical(); - _modal_progress_paint_mutex->EndCritical(); ClearGRFConfigList(&_all_grfs); @@ -694,12 +687,19 @@ void DoScanNewGRFFiles(void *callback) */ void ScanNewGRFFiles(NewGRFScanCallback *callback) { + /* First set the modal progress. This ensures that it will eventually let go of the paint mutex. */ + SetModalProgress(true); + /* Only then can we really start, especially by marking the whole screen dirty. Get those other windows hidden!. */ + MarkWholeScreenDirty(); + if (!_video_driver->HasGUI() || !ThreadObject::New(&DoScanNewGRFFiles, callback, NULL)) { _modal_progress_work_mutex->EndCritical(); _modal_progress_paint_mutex->EndCritical(); DoScanNewGRFFiles(callback); _modal_progress_paint_mutex->BeginCritical(); _modal_progress_work_mutex->BeginCritical(); + } else { + UpdateNewGRFScanStatus(0, NULL); } } diff --git a/src/newgrf_gui.cpp b/src/newgrf_gui.cpp index 8fcc38c7c3..ca1d13f335 100644 --- a/src/newgrf_gui.cpp +++ b/src/newgrf_gui.cpp @@ -1787,7 +1787,13 @@ struct ScanProgressWindow : public Window { void UpdateNewGRFScanStatus(uint num, const char *name) { free(this->last_name); - this->last_name = strdup(name); + if (name == NULL) { + char buf[256]; + GetString(buf, STR_NEWGRF_SCAN_ARCHIVES, lastof(buf)); + this->last_name = strdup(buf); + } else { + this->last_name = strdup(name); + } this->scanned = num; if (num > _settings_client.gui.last_newgrf_count) _settings_client.gui.last_newgrf_count = num; diff --git a/src/progress.cpp b/src/progress.cpp index ac34afd07f..208f681a63 100644 --- a/src/progress.cpp +++ b/src/progress.cpp @@ -15,6 +15,7 @@ /** Are we in a modal progress or not? */ bool _in_modal_progress = false; +bool _first_in_modal_loop = false; /** Rights for the performing work. */ ThreadMutex *_modal_progress_work_mutex = ThreadMutex::New(); /** Rights for the painting. */ @@ -22,9 +23,23 @@ ThreadMutex *_modal_progress_paint_mutex = ThreadMutex::New(); /** * Set the modal progress state. + * @note Makes IsFirstModalProgressLoop return true for the next call. * @param state The new state; are we modal or not? */ void SetModalProgress(bool state) { _in_modal_progress = state; + _first_in_modal_loop = true; +} + +/** + * Check whether this is the first modal progress loop. + * @note Set by SetModalProgress, unset by calling this method. + * @return True if this is the first loop. + */ +bool IsFirstModalProgressLoop() +{ + bool ret = _first_in_modal_loop; + _first_in_modal_loop = false; + return ret; } diff --git a/src/progress.h b/src/progress.h index 85a27de726..eec369b23c 100644 --- a/src/progress.h +++ b/src/progress.h @@ -26,10 +26,7 @@ static inline bool HasModalProgress() return _in_modal_progress; } -/** - * Set the modal progress state. - * @param state The new state; are we modal or not? - */ +bool IsFirstModalProgressLoop(); void SetModalProgress(bool state); extern class ThreadMutex *_modal_progress_work_mutex;