mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-22 22:34:33 +01:00
Refactor get_file_extension_type()
This commit is contained in:
committed by
GitHub
parent
3359dc4509
commit
2c8c940caa
@@ -22,8 +22,8 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
static void WriteConvertFromAndToMessage(uint32_t sourceFileType, uint32_t destinationFileType);
|
||||
static const utf8* GetFileTypeFriendlyName(uint32_t fileType);
|
||||
static void WriteConvertFromAndToMessage(FileExtension sourceFileType, FileExtension destinationFileType);
|
||||
static u8string GetFileTypeFriendlyName(FileExtension fileType);
|
||||
|
||||
exitcode_t CommandLine::HandleCommandConvert(CommandLineArgEnumerator* enumerator)
|
||||
{
|
||||
@@ -42,7 +42,7 @@ exitcode_t CommandLine::HandleCommandConvert(CommandLineArgEnumerator* enumerato
|
||||
}
|
||||
|
||||
const auto sourcePath = Path::GetAbsolute(rawSourcePath);
|
||||
uint32_t sourceFileType = get_file_extension_type(sourcePath.c_str());
|
||||
auto sourceFileType = get_file_extension_type(sourcePath.c_str());
|
||||
|
||||
// Get the destination path
|
||||
const utf8* rawDestinationPath;
|
||||
@@ -53,10 +53,10 @@ exitcode_t CommandLine::HandleCommandConvert(CommandLineArgEnumerator* enumerato
|
||||
}
|
||||
|
||||
const auto destinationPath = Path::GetAbsolute(rawDestinationPath);
|
||||
uint32_t destinationFileType = get_file_extension_type(destinationPath.c_str());
|
||||
auto destinationFileType = get_file_extension_type(destinationPath.c_str());
|
||||
|
||||
// Validate target type
|
||||
if (destinationFileType != FILE_EXTENSION_PARK)
|
||||
if (destinationFileType != FileExtension::PARK)
|
||||
{
|
||||
Console::Error::WriteLine("Only conversion to .PARK is supported.");
|
||||
return EXITCODE_FAIL;
|
||||
@@ -65,20 +65,15 @@ exitcode_t CommandLine::HandleCommandConvert(CommandLineArgEnumerator* enumerato
|
||||
// Validate the source type
|
||||
switch (sourceFileType)
|
||||
{
|
||||
case FILE_EXTENSION_SC4:
|
||||
case FILE_EXTENSION_SV4:
|
||||
case FileExtension::SC4:
|
||||
case FileExtension::SV4:
|
||||
case FileExtension::SC6:
|
||||
case FileExtension::SV6:
|
||||
break;
|
||||
case FILE_EXTENSION_SC6:
|
||||
if (destinationFileType == FILE_EXTENSION_SC6)
|
||||
case FileExtension::PARK:
|
||||
if (destinationFileType == FileExtension::PARK)
|
||||
{
|
||||
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.");
|
||||
Console::Error::WriteLine("File is already an OpenRCT2 saved game or scenario.");
|
||||
return EXITCODE_FAIL;
|
||||
}
|
||||
break;
|
||||
@@ -111,7 +106,7 @@ exitcode_t CommandLine::HandleCommandConvert(CommandLineArgEnumerator* enumerato
|
||||
return EXITCODE_FAIL;
|
||||
}
|
||||
|
||||
if (sourceFileType == FILE_EXTENSION_SC4 || sourceFileType == FILE_EXTENSION_SC6)
|
||||
if (sourceFileType == FileExtension::SC4 || sourceFileType == FileExtension::SC6)
|
||||
{
|
||||
// We are converting a scenario, so reset the park
|
||||
scenario_begin();
|
||||
@@ -137,28 +132,30 @@ exitcode_t CommandLine::HandleCommandConvert(CommandLineArgEnumerator* enumerato
|
||||
return EXITCODE_OK;
|
||||
}
|
||||
|
||||
static void WriteConvertFromAndToMessage(uint32_t sourceFileType, uint32_t destinationFileType)
|
||||
static void WriteConvertFromAndToMessage(FileExtension sourceFileType, FileExtension destinationFileType)
|
||||
{
|
||||
const utf8* sourceFileTypeName = GetFileTypeFriendlyName(sourceFileType);
|
||||
const utf8* destinationFileTypeName = GetFileTypeFriendlyName(destinationFileType);
|
||||
Console::WriteFormat("Converting from a %s to a %s.", sourceFileTypeName, destinationFileTypeName);
|
||||
const auto sourceFileTypeName = GetFileTypeFriendlyName(sourceFileType);
|
||||
const auto destinationFileTypeName = GetFileTypeFriendlyName(destinationFileType);
|
||||
Console::WriteFormat("Converting from a %s to a %s.", sourceFileTypeName.c_str(), destinationFileTypeName.c_str());
|
||||
Console::WriteLine();
|
||||
}
|
||||
|
||||
static const utf8* GetFileTypeFriendlyName(uint32_t fileType)
|
||||
static u8string GetFileTypeFriendlyName(FileExtension fileType)
|
||||
{
|
||||
switch (fileType)
|
||||
{
|
||||
case FILE_EXTENSION_SC4:
|
||||
case FileExtension::SC4:
|
||||
return "RollerCoaster Tycoon 1 scenario";
|
||||
case FILE_EXTENSION_SV4:
|
||||
case FileExtension::SV4:
|
||||
return "RollerCoaster Tycoon 1 saved game";
|
||||
case FILE_EXTENSION_SC6:
|
||||
case FileExtension::SC6:
|
||||
return "RollerCoaster Tycoon 2 scenario";
|
||||
case FILE_EXTENSION_SV6:
|
||||
case FileExtension::SV6:
|
||||
return "RollerCoaster Tycoon 2 saved game";
|
||||
case FILE_EXTENSION_PARK:
|
||||
case FileExtension::PARK:
|
||||
return "OpenRCT2 park";
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
assert(false);
|
||||
|
||||
Reference in New Issue
Block a user