2016-05-04 19:24:41 +02:00
|
|
|
/*****************************************************************************
|
2018-06-15 14:07:34 +02:00
|
|
|
* Copyright (c) 2014-2018 OpenRCT2 developers
|
2016-05-04 19:24:41 +02:00
|
|
|
*
|
2018-06-15 14:07:34 +02:00
|
|
|
* For a complete list of all authors, please refer to contributors.md
|
|
|
|
|
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
|
2016-05-04 19:24:41 +02:00
|
|
|
*
|
2018-06-15 14:07:34 +02:00
|
|
|
* OpenRCT2 is licensed under the GNU General Public License version 3.
|
2016-05-04 19:24:41 +02:00
|
|
|
*****************************************************************************/
|
|
|
|
|
|
2018-06-22 22:57:42 +02:00
|
|
|
#include "../FileClassifier.h"
|
|
|
|
|
#include "../OpenRCT2.h"
|
|
|
|
|
#include "../ParkImporter.h"
|
2016-04-19 22:09:42 +01:00
|
|
|
#include "../common.h"
|
|
|
|
|
#include "../core/Console.hpp"
|
|
|
|
|
#include "../core/Path.hpp"
|
2018-06-22 22:57:42 +02:00
|
|
|
#include "../interface/Window.h"
|
2017-02-07 13:01:53 +00:00
|
|
|
#include "../rct2/S6Exporter.h"
|
2016-04-19 22:09:42 +01:00
|
|
|
#include "CommandLine.hpp"
|
|
|
|
|
|
2018-06-22 22:57:42 +02:00
|
|
|
#include <memory>
|
2016-04-19 22:09:42 +01:00
|
|
|
|
2018-06-20 17:28:51 +02:00
|
|
|
static void WriteConvertFromAndToMessage(uint32_t sourceFileType, uint32_t destinationFileType);
|
2018-06-22 22:57:42 +02:00
|
|
|
static const utf8* GetFileTypeFriendlyName(uint32_t fileType);
|
2016-04-19 22:09:42 +01:00
|
|
|
|
2018-06-22 22:57:42 +02:00
|
|
|
exitcode_t CommandLine::HandleCommandConvert(CommandLineArgEnumerator* enumerator)
|
2016-04-19 22:09:42 +01:00
|
|
|
{
|
|
|
|
|
exitcode_t result = CommandLine::HandleCommandDefault();
|
|
|
|
|
if (result != EXITCODE_CONTINUE)
|
|
|
|
|
{
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get the source path
|
2018-06-22 22:57:42 +02:00
|
|
|
const utf8* rawSourcePath;
|
2016-04-19 22:09:42 +01:00
|
|
|
if (!enumerator->TryPopString(&rawSourcePath))
|
|
|
|
|
{
|
|
|
|
|
Console::Error::WriteLine("Expected a source path.");
|
|
|
|
|
return EXITCODE_FAIL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
utf8 sourcePath[MAX_PATH];
|
|
|
|
|
Path::GetAbsolute(sourcePath, sizeof(sourcePath), rawSourcePath);
|
2018-06-20 17:28:51 +02:00
|
|
|
uint32_t sourceFileType = get_file_extension_type(sourcePath);
|
2016-04-19 22:09:42 +01:00
|
|
|
|
|
|
|
|
// Get the destination path
|
2018-06-22 22:57:42 +02:00
|
|
|
const utf8* rawDestinationPath;
|
2016-04-19 22:09:42 +01:00
|
|
|
if (!enumerator->TryPopString(&rawDestinationPath))
|
|
|
|
|
{
|
|
|
|
|
Console::Error::WriteLine("Expected a destination path.");
|
|
|
|
|
return EXITCODE_FAIL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
utf8 destinationPath[MAX_PATH];
|
|
|
|
|
Path::GetAbsolute(destinationPath, sizeof(sourcePath), rawDestinationPath);
|
2018-06-20 17:28:51 +02:00
|
|
|
uint32_t destinationFileType = get_file_extension_type(destinationPath);
|
2016-04-19 22:09:42 +01:00
|
|
|
|
|
|
|
|
// Validate target type
|
2018-06-22 22:57:42 +02:00
|
|
|
if (destinationFileType != FILE_EXTENSION_SC6 && destinationFileType != FILE_EXTENSION_SV6)
|
2016-04-19 22:09:42 +01:00
|
|
|
{
|
|
|
|
|
Console::Error::WriteLine("Only conversion to .SC6 or .SV4 is supported.");
|
|
|
|
|
return EXITCODE_FAIL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Validate the source type
|
2018-06-22 22:57:42 +02:00
|
|
|
switch (sourceFileType)
|
|
|
|
|
{
|
|
|
|
|
case FILE_EXTENSION_SC4:
|
|
|
|
|
case FILE_EXTENSION_SV4:
|
|
|
|
|
break;
|
|
|
|
|
case FILE_EXTENSION_SC6:
|
|
|
|
|
if (destinationFileType == FILE_EXTENSION_SC6)
|
|
|
|
|
{
|
|
|
|
|
Console::Error::WriteLine("File is already a RollerCoaster Tycoon 2 scenario.");
|
|
|
|
|
return EXITCODE_FAIL;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case FILE_EXTENSION_SV6:
|
|
|
|
|
if (destinationFileType == FILE_EXTENSION_SV6)
|
|
|
|
|
{
|
|
|
|
|
Console::Error::WriteLine("File is already a RollerCoaster Tycoon 2 saved game.");
|
|
|
|
|
return EXITCODE_FAIL;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
Console::Error::WriteLine("Only conversion from .SC4, .SV4, .SC6 or .SV6 is supported.");
|
2016-04-19 22:09:42 +01:00
|
|
|
return EXITCODE_FAIL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Perform conversion
|
|
|
|
|
WriteConvertFromAndToMessage(sourceFileType, destinationFileType);
|
|
|
|
|
|
|
|
|
|
gOpenRCT2Headless = true;
|
2017-03-26 21:04:14 +01:00
|
|
|
// if (!openrct2_initialise())
|
|
|
|
|
// {
|
|
|
|
|
// Console::Error::WriteLine("Error while initialising OpenRCT2.");
|
|
|
|
|
// return EXITCODE_FAIL;
|
|
|
|
|
// }
|
2016-04-19 22:09:42 +01:00
|
|
|
|
2017-02-07 13:01:53 +00:00
|
|
|
try
|
2016-04-19 22:09:42 +01:00
|
|
|
{
|
2018-04-20 22:16:37 +01:00
|
|
|
auto importer = ParkImporter::Create(sourcePath);
|
2017-02-07 13:01:53 +00:00
|
|
|
importer->Load(sourcePath);
|
|
|
|
|
importer->Import();
|
2016-04-19 22:09:42 +01:00
|
|
|
}
|
2018-06-22 22:57:42 +02:00
|
|
|
catch (const std::exception& ex)
|
2016-04-19 22:09:42 +01:00
|
|
|
{
|
2018-01-02 19:23:22 +00:00
|
|
|
Console::Error::WriteLine(ex.what());
|
2017-02-07 13:01:53 +00:00
|
|
|
return EXITCODE_FAIL;
|
2016-04-19 22:09:42 +01:00
|
|
|
}
|
|
|
|
|
|
2018-06-22 22:57:42 +02:00
|
|
|
if (sourceFileType == FILE_EXTENSION_SC4 || sourceFileType == FILE_EXTENSION_SC6)
|
2017-02-07 13:01:53 +00:00
|
|
|
{
|
|
|
|
|
// We are converting a scenario, so reset the park
|
|
|
|
|
scenario_begin();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
auto exporter = std::make_unique<S6Exporter>();
|
|
|
|
|
|
2016-04-19 22:09:42 +01:00
|
|
|
// HACK remove the main window so it saves the park with the
|
|
|
|
|
// correct initial view
|
|
|
|
|
window_close_by_class(WC_MAIN_WINDOW);
|
|
|
|
|
|
2017-02-07 20:13:50 +00:00
|
|
|
exporter->Export();
|
2016-04-19 22:09:42 +01:00
|
|
|
if (destinationFileType == FILE_EXTENSION_SC6)
|
|
|
|
|
{
|
2017-02-07 13:01:53 +00:00
|
|
|
exporter->SaveScenario(destinationPath);
|
2016-04-19 22:09:42 +01:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-02-07 13:01:53 +00:00
|
|
|
exporter->SaveGame(destinationPath);
|
2016-04-19 22:09:42 +01:00
|
|
|
}
|
|
|
|
|
}
|
2018-06-22 22:57:42 +02:00
|
|
|
catch (const std::exception& ex)
|
2016-04-19 22:09:42 +01:00
|
|
|
{
|
2018-01-02 19:23:22 +00:00
|
|
|
Console::Error::WriteLine(ex.what());
|
2016-04-19 22:09:42 +01:00
|
|
|
return EXITCODE_FAIL;
|
|
|
|
|
}
|
2017-02-07 13:01:53 +00:00
|
|
|
|
|
|
|
|
Console::WriteLine("Conversion successful!");
|
2016-04-19 22:09:42 +01:00
|
|
|
return EXITCODE_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-20 17:28:51 +02:00
|
|
|
static void WriteConvertFromAndToMessage(uint32_t sourceFileType, uint32_t destinationFileType)
|
2016-04-19 22:09:42 +01:00
|
|
|
{
|
2018-06-22 22:57:42 +02:00
|
|
|
const utf8* sourceFileTypeName = GetFileTypeFriendlyName(sourceFileType);
|
|
|
|
|
const utf8* destinationFileTypeName = GetFileTypeFriendlyName(destinationFileType);
|
2016-04-19 22:09:42 +01:00
|
|
|
Console::WriteFormat("Converting from a %s to a %s.", sourceFileTypeName, destinationFileTypeName);
|
|
|
|
|
Console::WriteLine();
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-22 22:57:42 +02:00
|
|
|
static const utf8* GetFileTypeFriendlyName(uint32_t fileType)
|
2016-04-19 22:09:42 +01:00
|
|
|
{
|
2018-06-22 22:57:42 +02:00
|
|
|
switch (fileType)
|
|
|
|
|
{
|
|
|
|
|
case FILE_EXTENSION_SC4:
|
|
|
|
|
return "RollerCoaster Tycoon 1 scenario";
|
|
|
|
|
case FILE_EXTENSION_SV4:
|
|
|
|
|
return "RollerCoaster Tycoon 1 saved game";
|
|
|
|
|
case FILE_EXTENSION_SC6:
|
|
|
|
|
return "RollerCoaster Tycoon 2 scenario";
|
|
|
|
|
case FILE_EXTENSION_SV6:
|
|
|
|
|
return "RollerCoaster Tycoon 2 saved game";
|
2016-04-19 22:09:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
assert(false);
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|