mirror of https://github.com/OpenRCT2/OpenRCT2.git
Remove use of RWops from ConvertCommand
This commit is contained in:
parent
4a6905d1eb
commit
c80021d9da
|
@ -21,6 +21,7 @@
|
|||
#include "../core/Guard.hpp"
|
||||
#include "../core/Path.hpp"
|
||||
#include "../ParkImporter.h"
|
||||
#include "../rct2/S6Exporter.h"
|
||||
#include "CommandLine.hpp"
|
||||
|
||||
extern "C"
|
||||
|
@ -102,74 +103,55 @@ exitcode_t CommandLine::HandleCommandConvert(CommandLineArgEnumerator * enumerat
|
|||
WriteConvertFromAndToMessage(sourceFileType, destinationFileType);
|
||||
|
||||
gOpenRCT2Headless = true;
|
||||
if (!openrct2_initialise()) {
|
||||
if (!openrct2_initialise())
|
||||
{
|
||||
Console::Error::WriteLine("Error while initialising OpenRCT2.");
|
||||
return EXITCODE_FAIL;
|
||||
}
|
||||
|
||||
if (sourceFileType == FILE_EXTENSION_SV4 ||
|
||||
sourceFileType == FILE_EXTENSION_SC4)
|
||||
{
|
||||
try
|
||||
{
|
||||
auto s4Importer = std::unique_ptr<IParkImporter>(ParkImporter::CreateS4());
|
||||
if (sourceFileType == FILE_EXTENSION_SC4)
|
||||
{
|
||||
s4Importer->LoadScenario(sourcePath);
|
||||
auto importer = std::unique_ptr<IParkImporter>(ParkImporter::Create(destinationPath));
|
||||
importer->Load(sourcePath);
|
||||
importer->Import();
|
||||
}
|
||||
if (sourceFileType == FILE_EXTENSION_SV4)
|
||||
catch (const Exception &ex)
|
||||
{
|
||||
s4Importer->LoadSavedGame(sourcePath);
|
||||
Console::Error::WriteLine(ex.GetMessage());
|
||||
return EXITCODE_FAIL;
|
||||
}
|
||||
|
||||
s4Importer->Import();
|
||||
|
||||
if (sourceFileType == FILE_EXTENSION_SC4)
|
||||
if (sourceFileType == FILE_EXTENSION_SC4 ||
|
||||
sourceFileType == FILE_EXTENSION_SC6)
|
||||
{
|
||||
// We are converting a scenario, so reset the park
|
||||
scenario_begin();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
auto exporter = std::make_unique<S6Exporter>();
|
||||
|
||||
// HACK remove the main window so it saves the park with the
|
||||
// correct initial view
|
||||
window_close_by_class(WC_MAIN_WINDOW);
|
||||
|
||||
if (destinationFileType == FILE_EXTENSION_SC6)
|
||||
{
|
||||
exporter->SaveScenario(destinationPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
exporter->SaveGame(destinationPath);
|
||||
}
|
||||
}
|
||||
catch (const Exception &ex)
|
||||
{
|
||||
Console::Error::WriteLine(ex.GetMessage());
|
||||
return EXITCODE_FAIL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (sourceFileType == FILE_EXTENSION_SC6)
|
||||
{
|
||||
scenario_load_and_play_from_path(sourcePath);
|
||||
}
|
||||
if (sourceFileType == FILE_EXTENSION_SV6)
|
||||
{
|
||||
game_load_save(sourcePath);
|
||||
}
|
||||
}
|
||||
|
||||
SDL_RWops* rw = SDL_RWFromFile(destinationPath, "wb+");
|
||||
if (rw != NULL) {
|
||||
// HACK remove the main window so it saves the park with the
|
||||
// correct initial view
|
||||
window_close_by_class(WC_MAIN_WINDOW);
|
||||
|
||||
if (destinationFileType == FILE_EXTENSION_SC6)
|
||||
{
|
||||
scenario_save(rw, 0x80000002);
|
||||
}
|
||||
else
|
||||
{
|
||||
scenario_save(rw, 0x80000001);
|
||||
}
|
||||
SDL_RWclose(rw);
|
||||
Console::WriteLine("Conversion successful!");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console::Error::WriteLine("Unable to write destination file.");
|
||||
return EXITCODE_FAIL;
|
||||
}
|
||||
return EXITCODE_OK;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue