mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-16 11:33:03 +01:00
Refactor get_file_extension_type()
This commit is contained in:
committed by
GitHub
parent
3359dc4509
commit
2c8c940caa
@@ -345,13 +345,13 @@ static bool Browse(bool isSave, char* path, size_t pathSize)
|
||||
{
|
||||
file_dialog_desc desc = {};
|
||||
const utf8* extension = "";
|
||||
uint32_t fileType = FILE_EXTENSION_UNKNOWN;
|
||||
auto fileType = FileExtension::Unknown;
|
||||
rct_string_id title = STR_NONE;
|
||||
switch (_type & 0x0E)
|
||||
{
|
||||
case LOADSAVETYPE_GAME:
|
||||
extension = ".park";
|
||||
fileType = FILE_EXTENSION_PARK;
|
||||
fileType = FileExtension::PARK;
|
||||
title = isSave ? STR_FILE_DIALOG_TITLE_SAVE_GAME : STR_FILE_DIALOG_TITLE_LOAD_GAME;
|
||||
desc.filters[0].name = language_get_string(STR_OPENRCT2_SAVED_GAME);
|
||||
desc.filters[0].pattern = GetFilterPatternByType(_type, isSave);
|
||||
@@ -359,7 +359,7 @@ static bool Browse(bool isSave, char* path, size_t pathSize)
|
||||
|
||||
case LOADSAVETYPE_LANDSCAPE:
|
||||
extension = ".park";
|
||||
fileType = FILE_EXTENSION_PARK;
|
||||
fileType = FileExtension::PARK;
|
||||
title = isSave ? STR_FILE_DIALOG_TITLE_SAVE_LANDSCAPE : STR_FILE_DIALOG_TITLE_LOAD_LANDSCAPE;
|
||||
desc.filters[0].name = language_get_string(STR_OPENRCT2_LANDSCAPE_FILE);
|
||||
desc.filters[0].pattern = GetFilterPatternByType(_type, isSave);
|
||||
@@ -367,7 +367,7 @@ static bool Browse(bool isSave, char* path, size_t pathSize)
|
||||
|
||||
case LOADSAVETYPE_SCENARIO:
|
||||
extension = ".park";
|
||||
fileType = FILE_EXTENSION_PARK;
|
||||
fileType = FileExtension::PARK;
|
||||
title = STR_FILE_DIALOG_TITLE_SAVE_SCENARIO;
|
||||
desc.filters[0].name = language_get_string(STR_OPENRCT2_SCENARIO_FILE);
|
||||
desc.filters[0].pattern = GetFilterPatternByType(_type, isSave);
|
||||
@@ -375,7 +375,7 @@ static bool Browse(bool isSave, char* path, size_t pathSize)
|
||||
|
||||
case LOADSAVETYPE_TRACK:
|
||||
extension = ".td6";
|
||||
fileType = FILE_EXTENSION_TD6;
|
||||
fileType = FileExtension::TD6;
|
||||
title = isSave ? STR_FILE_DIALOG_TITLE_SAVE_TRACK : STR_FILE_DIALOG_TITLE_INSTALL_NEW_TRACK_DESIGN;
|
||||
desc.filters[0].name = language_get_string(STR_OPENRCT2_TRACK_DESIGN_FILE);
|
||||
desc.filters[0].pattern = GetFilterPatternByType(_type, isSave);
|
||||
|
||||
@@ -1132,8 +1132,8 @@ static bool SaveFilenameExists(const utf8* filename)
|
||||
|
||||
static void WindowTitleEditorAddParkCallback(int32_t result, const utf8* path)
|
||||
{
|
||||
uint32_t extension = get_file_extension_type(path);
|
||||
if (extension != FILE_EXTENSION_SV4 && extension != FILE_EXTENSION_SV6 && extension != FILE_EXTENSION_PARK)
|
||||
auto extension = get_file_extension_type(path);
|
||||
if (extension != FileExtension::SV4 && extension != FileExtension::SV6 && extension != FileExtension::PARK)
|
||||
return;
|
||||
|
||||
const utf8* filename = path_get_filename(path);
|
||||
|
||||
@@ -228,17 +228,17 @@ namespace Editor
|
||||
// after we have loaded a new park.
|
||||
window_close_all();
|
||||
|
||||
uint32_t extension = get_file_extension_type(path);
|
||||
auto extension = get_file_extension_type(path);
|
||||
switch (extension)
|
||||
{
|
||||
case FILE_EXTENSION_SC6:
|
||||
case FILE_EXTENSION_SV6:
|
||||
case FileExtension::SC6:
|
||||
case FileExtension::SV6:
|
||||
return ReadS6(path);
|
||||
case FILE_EXTENSION_SC4:
|
||||
case FileExtension::SC4:
|
||||
return LoadLandscapeFromSC4(path);
|
||||
case FILE_EXTENSION_SV4:
|
||||
case FileExtension::SV4:
|
||||
return LoadLandscapeFromSV4(path);
|
||||
case FILE_EXTENSION_PARK:
|
||||
case FileExtension::PARK:
|
||||
return ReadPark(path);
|
||||
default:
|
||||
return false;
|
||||
|
||||
@@ -194,28 +194,28 @@ static bool TryClassifyAsTD4_TD6(OpenRCT2::IStream* stream, ClassifiedFileInfo*
|
||||
return success;
|
||||
}
|
||||
|
||||
uint32_t get_file_extension_type(const utf8* path)
|
||||
FileExtension get_file_extension_type(u8string_view path)
|
||||
{
|
||||
auto extension = Path::GetExtension(path);
|
||||
if (String::Equals(extension, ".dat", true) || String::Equals(extension, ".pob", true))
|
||||
return FILE_EXTENSION_DAT;
|
||||
return FileExtension::DAT;
|
||||
if (String::Equals(extension, ".sc4", true))
|
||||
return FILE_EXTENSION_SC4;
|
||||
return FileExtension::SC4;
|
||||
if (String::Equals(extension, ".sv4", true))
|
||||
return FILE_EXTENSION_SV4;
|
||||
return FileExtension::SV4;
|
||||
if (String::Equals(extension, ".td4", true))
|
||||
return FILE_EXTENSION_TD4;
|
||||
return FileExtension::TD4;
|
||||
if (String::Equals(extension, ".sc6", true))
|
||||
return FILE_EXTENSION_SC6;
|
||||
return FileExtension::SC6;
|
||||
if (String::Equals(extension, ".sea", true))
|
||||
return FILE_EXTENSION_SC6;
|
||||
return FileExtension::SC6;
|
||||
if (String::Equals(extension, ".sv6", true))
|
||||
return FILE_EXTENSION_SV6;
|
||||
return FileExtension::SV6;
|
||||
if (String::Equals(extension, ".sv7", true))
|
||||
return FILE_EXTENSION_SV6;
|
||||
return FileExtension::SV6;
|
||||
if (String::Equals(extension, ".td6", true))
|
||||
return FILE_EXTENSION_TD6;
|
||||
return FileExtension::TD6;
|
||||
if (String::Equals(extension, ".park", true))
|
||||
return FILE_EXTENSION_PARK;
|
||||
return FILE_EXTENSION_UNKNOWN;
|
||||
return FileExtension::PARK;
|
||||
return FileExtension::Unknown;
|
||||
}
|
||||
|
||||
@@ -12,17 +12,17 @@
|
||||
#include "common.h"
|
||||
#include "core/String.hpp"
|
||||
|
||||
enum
|
||||
enum class FileExtension
|
||||
{
|
||||
FILE_EXTENSION_UNKNOWN,
|
||||
FILE_EXTENSION_DAT,
|
||||
FILE_EXTENSION_SC4,
|
||||
FILE_EXTENSION_SV4,
|
||||
FILE_EXTENSION_TD4,
|
||||
FILE_EXTENSION_SC6,
|
||||
FILE_EXTENSION_SV6,
|
||||
FILE_EXTENSION_TD6,
|
||||
FILE_EXTENSION_PARK,
|
||||
Unknown,
|
||||
DAT,
|
||||
SC4,
|
||||
SV4,
|
||||
TD4,
|
||||
SC6,
|
||||
SV6,
|
||||
TD6,
|
||||
PARK,
|
||||
};
|
||||
|
||||
#include <string>
|
||||
@@ -52,4 +52,4 @@ struct ClassifiedFileInfo
|
||||
bool TryClassifyFile(const std::string& path, ClassifiedFileInfo* result);
|
||||
bool TryClassifyFile(OpenRCT2::IStream* stream, ClassifiedFileInfo* result);
|
||||
|
||||
uint32_t get_file_extension_type(const utf8* path);
|
||||
FileExtension get_file_extension_type(u8string_view path);
|
||||
|
||||
@@ -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