mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2025-12-23 07:43:01 +01:00
This commit is contained in:
@@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <stdexcept>
|
||||||
#include <openrct2/common.h>
|
#include <openrct2/common.h>
|
||||||
#include <openrct2/core/String.hpp>
|
#include <openrct2/core/String.hpp>
|
||||||
#include <openrct2/ui/UiContext.h>
|
#include <openrct2/ui/UiContext.h>
|
||||||
@@ -160,7 +161,7 @@ namespace OpenRCT2 { namespace Ui
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
log_error("KDialog or Zenity not installed.");
|
ThrowMissingDialogApp();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -211,7 +212,7 @@ namespace OpenRCT2 { namespace Ui
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
log_error("KDialog or Zenity not installed.");
|
ThrowMissingDialogApp();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
@@ -337,6 +338,11 @@ namespace OpenRCT2 { namespace Ui
|
|||||||
}
|
}
|
||||||
return filtersb.str();
|
return filtersb.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void ThrowMissingDialogApp()
|
||||||
|
{
|
||||||
|
throw std::runtime_error("KDialog or Zenity not installed.");
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
IPlatformUiContext * CreatePlatformUiContext()
|
IPlatformUiContext * CreatePlatformUiContext()
|
||||||
|
|||||||
@@ -124,8 +124,10 @@ namespace OpenRCT2
|
|||||||
|
|
||||||
sint32 RunOpenRCT2(int argc, char * * argv) override
|
sint32 RunOpenRCT2(int argc, char * * argv) override
|
||||||
{
|
{
|
||||||
Initialise();
|
if (Initialise())
|
||||||
Launch();
|
{
|
||||||
|
Launch();
|
||||||
|
}
|
||||||
return gExitCode;
|
return gExitCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -677,26 +679,43 @@ extern "C"
|
|||||||
|
|
||||||
bool platform_open_common_file_dialog(utf8 * outFilename, file_dialog_desc * desc, size_t outSize)
|
bool platform_open_common_file_dialog(utf8 * outFilename, file_dialog_desc * desc, size_t outSize)
|
||||||
{
|
{
|
||||||
FileDialogDesc desc2;
|
try
|
||||||
desc2.Type = (FILE_DIALOG_TYPE)desc->type;
|
|
||||||
desc2.Title = String::ToStd(desc->title);
|
|
||||||
desc2.InitialDirectory = String::ToStd(desc->initial_directory);
|
|
||||||
desc2.DefaultFilename = String::ToStd(desc->default_filename);
|
|
||||||
for (const auto &filter : desc->filters)
|
|
||||||
{
|
{
|
||||||
if (filter.name != nullptr)
|
FileDialogDesc desc2;
|
||||||
|
desc2.Type = (FILE_DIALOG_TYPE)desc->type;
|
||||||
|
desc2.Title = String::ToStd(desc->title);
|
||||||
|
desc2.InitialDirectory = String::ToStd(desc->initial_directory);
|
||||||
|
desc2.DefaultFilename = String::ToStd(desc->default_filename);
|
||||||
|
for (const auto &filter : desc->filters)
|
||||||
{
|
{
|
||||||
desc2.Filters.push_back({ String::ToStd(filter.name), String::ToStd(filter.pattern) });
|
if (filter.name != nullptr)
|
||||||
|
{
|
||||||
|
desc2.Filters.push_back({ String::ToStd(filter.name), String::ToStd(filter.pattern) });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
std::string result = GetContext()->GetUiContext()->ShowFileDialog(desc2);
|
||||||
|
String::Set(outFilename, outSize, result.c_str());
|
||||||
|
return !result.empty();
|
||||||
|
}
|
||||||
|
catch (const std::exception &ex)
|
||||||
|
{
|
||||||
|
log_error(ex.what());
|
||||||
|
outFilename[0] = '\0';
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
std::string result = GetContext()->GetUiContext()->ShowFileDialog(desc2);
|
|
||||||
String::Set(outFilename, outSize, result.c_str());
|
|
||||||
return !result.empty();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
utf8 * platform_open_directory_browser(const utf8 * title)
|
utf8 * platform_open_directory_browser(const utf8 * title)
|
||||||
{
|
{
|
||||||
std::string result = GetContext()->GetUiContext()->ShowDirectoryDialog(title);
|
try
|
||||||
return String::Duplicate(result.c_str());
|
{
|
||||||
|
std::string result = GetContext()->GetUiContext()->ShowDirectoryDialog(title);
|
||||||
|
return String::Duplicate(result.c_str());
|
||||||
|
}
|
||||||
|
catch (const std::exception &ex)
|
||||||
|
{
|
||||||
|
log_error(ex.what());
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -693,26 +693,36 @@ extern "C"
|
|||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
while (1)
|
|
||||||
|
try
|
||||||
{
|
{
|
||||||
IUiContext * uiContext = GetContext()->GetUiContext();
|
while (true)
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
return false;
|
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.");
|
||||||
|
|
||||||
|
std::string installPath = uiContext->ShowDirectoryDialog("Please select your RCT2 directory");
|
||||||
|
if (installPath.empty())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Memory::Free(gConfigGeneral.rct2_path);
|
||||||
|
gConfigGeneral.rct2_path = String::Duplicate(installPath.c_str());
|
||||||
|
|
||||||
|
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.c_str());
|
||||||
|
uiContext->ShowMessageBox(message);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
Memory::Free(gConfigGeneral.rct2_path);
|
catch (const std::exception &ex)
|
||||||
gConfigGeneral.rct2_path = installPath;
|
{
|
||||||
|
Console::Error::WriteLine(ex.what());
|
||||||
if (platform_original_game_data_exists(installPath))
|
return false;
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string message = String::StdFormat("Could not find %s" PATH_SEPARATOR "Data" PATH_SEPARATOR "g1.dat at this path", installPath);
|
|
||||||
uiContext->ShowMessageBox(message);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user