1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2025-12-23 15:52:55 +01:00

Fix #5521: Infinite loop on first run if neither Zenity nor kdialog are installed (#5526)

This commit is contained in:
Ted John
2017-06-03 22:13:20 +01:00
committed by GitHub
parent 810d46055a
commit af91b9f4b4
3 changed files with 69 additions and 34 deletions

View File

@@ -18,6 +18,7 @@
#include <dlfcn.h>
#include <sstream>
#include <stdexcept>
#include <openrct2/common.h>
#include <openrct2/core/String.hpp>
#include <openrct2/ui/UiContext.h>
@@ -160,7 +161,7 @@ namespace OpenRCT2 { namespace Ui
break;
}
default:
log_error("KDialog or Zenity not installed.");
ThrowMissingDialogApp();
break;
}
@@ -211,7 +212,7 @@ namespace OpenRCT2 { namespace Ui
break;
}
default:
log_error("KDialog or Zenity not installed.");
ThrowMissingDialogApp();
break;
}
return result;
@@ -337,6 +338,11 @@ namespace OpenRCT2 { namespace Ui
}
return filtersb.str();
}
static void ThrowMissingDialogApp()
{
throw std::runtime_error("KDialog or Zenity not installed.");
}
};
IPlatformUiContext * CreatePlatformUiContext()

View File

@@ -124,8 +124,10 @@ namespace OpenRCT2
sint32 RunOpenRCT2(int argc, char * * argv) override
{
Initialise();
if (Initialise())
{
Launch();
}
return gExitCode;
}
@@ -676,6 +678,8 @@ extern "C"
}
bool platform_open_common_file_dialog(utf8 * outFilename, file_dialog_desc * desc, size_t outSize)
{
try
{
FileDialogDesc desc2;
desc2.Type = (FILE_DIALOG_TYPE)desc->type;
@@ -693,10 +697,25 @@ extern "C"
String::Set(outFilename, outSize, result.c_str());
return !result.empty();
}
catch (const std::exception &ex)
{
log_error(ex.what());
outFilename[0] = '\0';
return false;
}
}
utf8 * platform_open_directory_browser(const utf8 * title)
{
try
{
std::string result = GetContext()->GetUiContext()->ShowDirectoryDialog(title);
return String::Duplicate(result.c_str());
}
catch (const std::exception &ex)
{
log_error(ex.what());
return nullptr;
}
}
}

View File

@@ -693,28 +693,38 @@ extern "C"
{
return false;
}
while (1)
try
{
while (true)
{
IUiContext * uiContext = GetContext()->GetUiContext();
uiContext->ShowMessageBox("OpenRCT2 needs files from the original RollerCoaster Tycoon 2 in order to work. Please select the directory where you installed RollerCoaster Tycoon 2.");
utf8 * installPath = platform_open_directory_browser("Please select your RCT2 directory");
if (installPath == nullptr)
std::string installPath = uiContext->ShowDirectoryDialog("Please select your RCT2 directory");
if (installPath.empty())
{
return false;
}
Memory::Free(gConfigGeneral.rct2_path);
gConfigGeneral.rct2_path = installPath;
gConfigGeneral.rct2_path = String::Duplicate(installPath.c_str());
if (platform_original_game_data_exists(installPath))
if (platform_original_game_data_exists(installPath.c_str()))
{
return true;
}
std::string message = String::StdFormat("Could not find %s" PATH_SEPARATOR "Data" PATH_SEPARATOR "g1.dat at this path", installPath);
std::string message = String::StdFormat("Could not find %s" PATH_SEPARATOR "Data" PATH_SEPARATOR "g1.dat at this path", installPath.c_str());
uiContext->ShowMessageBox(message);
}
}
catch (const std::exception &ex)
{
Console::Error::WriteLine(ex.what());
return false;
}
}
return true;
}
}