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

Move rct2_open_file to Context

This commit is contained in:
Ted John
2017-07-02 19:10:22 +01:00
parent f7dff37708
commit edcbfdf097
5 changed files with 41 additions and 112 deletions

View File

@@ -256,6 +256,12 @@ namespace OpenRCT2
return true;
}
void Open(const std::string &path) final override
{
auto fs = FileStream(path, FILE_MODE_OPEN);
OpenParkAutoDetectFormat(&fs, path);
}
private:
bool LoadBaseGraphics()
{
@@ -293,7 +299,6 @@ namespace OpenRCT2
break;
case STARTUP_ACTION_OPEN:
{
bool parkLoaded = false;
// A path that includes "://" is illegal with all common filesystems, so it is almost certainly a URL
// This way all cURL supported protocols, like http, ftp, scp and smb are automatically handled
if (strstr(gOpenRCT2StartupActionPath, "://") != nullptr)
@@ -309,18 +314,27 @@ namespace OpenRCT2
}
auto ms = MemoryStream(data, dataSize, MEMORY_ACCESS::OWNER);
parkLoaded = OpenParkAutoDetectFormat(&ms);
if (!OpenParkAutoDetectFormat(&ms, gOpenRCT2StartupActionPath))
{
Console::Error::WriteLine("Failed to load '%s'", gOpenRCT2StartupActionPath);
title_load();
break;
}
#endif
}
else
{
parkLoaded = rct2_open_file(gOpenRCT2StartupActionPath);
}
if (!parkLoaded)
{
Console::Error::WriteLine("Failed to load '%s'", gOpenRCT2StartupActionPath);
break;
try
{
Open(gOpenRCT2StartupActionPath);
}
catch (const std::exception &ex)
{
Console::Error::WriteLine("Failed to load '%s'", gOpenRCT2StartupActionPath);
Console::Error::WriteLine("%s", ex.what());
title_load();
break;
}
}
gScreenFlags = SCREEN_FLAGS_PLAYING;
@@ -534,7 +548,7 @@ namespace OpenRCT2
console_update();
}
bool OpenParkAutoDetectFormat(IStream * stream)
bool OpenParkAutoDetectFormat(IStream * stream, const std::string &path)
{
ClassifiedFile info;
if (TryClassifyFile(stream, &info))
@@ -552,41 +566,27 @@ namespace OpenRCT2
parkImporter.reset(ParkImporter::CreateS6(_objectRepository, _objectManager));
}
if (info.Type == FILE_TYPE::SAVED_GAME)
auto result = parkImporter->LoadFromStream(stream, false);
if (result.Error == PARK_LOAD_ERROR_OK)
{
try
parkImporter->Import();
game_fix_save_vars();
sprite_position_tween_reset();
gScreenAge = 0;
gLastAutoSaveUpdate = AUTOSAVE_PAUSE;
if (info.Type == FILE_TYPE::SAVED_GAME)
{
parkImporter->LoadFromStream(stream, false);
parkImporter->Import();
game_fix_save_vars();
sprite_position_tween_reset();
gScreenAge = 0;
gLastAutoSaveUpdate = AUTOSAVE_PAUSE;
game_load_init();
return true;
}
catch (const Exception &)
else
{
Console::Error::WriteLine("Error loading saved game.");
scenario_begin();
}
return true;
}
else
{
try
{
parkImporter->LoadFromStream(stream, true);
parkImporter->Import();
game_fix_save_vars();
sprite_position_tween_reset();
gScreenAge = 0;
gLastAutoSaveUpdate = AUTOSAVE_PAUSE;
scenario_begin();
return true;
}
catch (const Exception &)
{
Console::Error::WriteLine("Error loading scenario.");
}
handle_park_load_failure_with_title_opt(&result, path.c_str(), true);
}
}
else

View File

@@ -67,6 +67,8 @@ enum
#ifdef __cplusplus
#include <string>
namespace OpenRCT2
{
interface IPlatformEnvironment;
@@ -94,6 +96,7 @@ namespace OpenRCT2
virtual sint32 RunOpenRCT2(int argc, char * * argv) abstract;
virtual bool Initialise() abstract;
virtual void Open(const std::string &path) abstract;
virtual void Finish() abstract;
};

View File

@@ -269,7 +269,7 @@ sint32 cmdline_for_gfxbench(const char **argv, sint32 argc)
if (context->Initialise())
{
drawing_engine_init();
rct2_open_file(inputPath);
context->Open(inputPath);
gIntroState = INTRO_STATE_NONE;
gScreenFlags = SCREEN_FLAGS_PLAYING;
@@ -388,7 +388,7 @@ sint32 cmdline_for_screenshot(const char **argv, sint32 argc)
if (context->Initialise())
{
drawing_engine_init();
rct2_open_file(inputPath);
context->Open(inputPath);
gIntroState = INTRO_STATE_NONE;
gScreenFlags = SCREEN_FLAGS_PLAYING;

View File

@@ -275,78 +275,6 @@ static void rct2_draw_fps(rct_drawpixelinfo *dpi)
gfx_set_dirty_blocks(x - 16, y - 4, gLastDrawStringX + 16, 16);
}
bool rct2_open_file(const char *path)
{
char *extension = strrchr(path, '.');
if (extension == NULL) {
title_load();
return false;
}
extension++;
if (_stricmp(extension, "sv6") == 0) {
ParkLoadResult * result = game_load_sv6_path(path);
if (ParkLoadResult_GetError(result) == PARK_LOAD_ERROR_OK) {
ParkLoadResult_Delete(result);
gFirstTimeSaving = false;
if (network_get_mode() == NETWORK_MODE_CLIENT) {
network_close();
}
game_load_init();
if (network_get_mode() == NETWORK_MODE_SERVER) {
network_send_map();
}
peep_update_names(gConfigGeneral.show_real_names_of_guests);
return true;
}
else {
handle_park_load_failure_with_title_opt(result, path, true);
ParkLoadResult_Delete(result);
return false;
}
} else if (_stricmp(extension, "sc6") == 0) {
// TODO scenario install
ParkLoadResult * result = scenario_load_and_play_from_path(path);
if (ParkLoadResult_GetError(result) == PARK_LOAD_ERROR_OK) {
ParkLoadResult_Delete(result);
return true;
} else {
handle_park_load_failure_with_title_opt(result, path, true);
ParkLoadResult_Delete(result);
return false;
}
} else if (_stricmp(extension, "td6") == 0 || _stricmp(extension, "td4") == 0) {
// TODO track design install
return true;
} else if (_stricmp(extension, "sv4") == 0) {
ParkLoadResult * result = rct1_load_saved_game(path);
if (ParkLoadResult_GetError(result) == PARK_LOAD_ERROR_OK) {
ParkLoadResult_Delete(result);
game_load_init();
return true;
}
else {
handle_park_load_failure_with_title_opt(result, path, true);
ParkLoadResult_Delete(result);
return false;
}
} else if (_stricmp(extension, "sc4") == 0) {
ParkLoadResult * result = rct1_load_scenario(path);
if (ParkLoadResult_GetError(result) == PARK_LOAD_ERROR_OK) {
ParkLoadResult_Delete(result);
scenario_begin();
return true;
}
else {
handle_park_load_failure_with_title_opt(result, path, true);
ParkLoadResult_Delete(result);
return false;
}
}
title_load();
return false;
}
/**
*
* rct2: 0x00674C95

View File

@@ -177,8 +177,6 @@ sint32 check_files_integrity();
const char *get_file_path(sint32 pathId);
void rct2_quit();
bool rct2_open_file(const char *path);
uint32 get_file_extension_type(const utf8 *path);
#ifdef __cplusplus