| 53 | static u8string GetFileTypeFriendlyName(FileExtension fileType); |
| 54 | |
| 55 | static ExitCode HandleCommandConvert(CommandLineArgEnumerator* enumerator) |
| 56 | { |
| 57 | ExitCode result = CommandLine::HandleCommandDefault(); |
| 58 | if (result != ExitCode::launch) |
| 59 | { |
| 60 | return result; |
| 61 | } |
| 62 | |
| 63 | // Get the source path |
| 64 | const utf8* rawSourcePath; |
| 65 | if (!enumerator->TryPopString(&rawSourcePath)) |
| 66 | { |
| 67 | Console::Error::WriteLine("Expected a source path."); |
| 68 | return ExitCode::fail; |
| 69 | } |
| 70 | |
| 71 | const auto sourcePath = Path::GetAbsolute(rawSourcePath); |
| 72 | auto sourceFileType = GetFileExtensionType(sourcePath.c_str()); |
| 73 | |
| 74 | // Get the destination path |
| 75 | const utf8* rawDestinationPath; |
| 76 | if (!enumerator->TryPopString(&rawDestinationPath) || String::startsWith(rawDestinationPath, "-")) |
| 77 | { |
| 78 | // if no destination path is provided, convert the park file in-place |
| 79 | rawDestinationPath = rawSourcePath; |
| 80 | } |
| 81 | |
| 82 | const auto destinationPath = Path::GetAbsolute(rawDestinationPath); |
| 83 | auto destinationFileType = GetFileExtensionType(destinationPath.c_str()); |
| 84 | |
| 85 | // Validate target type |
| 86 | if (destinationFileType != FileExtension::PARK) |
| 87 | { |
| 88 | Console::Error::WriteLine("Only conversion to .PARK is supported."); |
| 89 | return ExitCode::fail; |
| 90 | } |
| 91 | |
| 92 | // Validate the source type |
| 93 | switch (sourceFileType) |
| 94 | { |
| 95 | case FileExtension::SC4: |
| 96 | case FileExtension::SV4: |
| 97 | case FileExtension::SC6: |
| 98 | case FileExtension::SV6: |
| 99 | break; |
| 100 | case FileExtension::PARK: |
| 101 | if (destinationFileType == FileExtension::PARK) |
| 102 | { |
| 103 | Console::Error::WriteLine( |
| 104 | "File is already an OpenRCT2 saved game or scenario. Updating file version and recompressing."); |
| 105 | } |
| 106 | break; |
| 107 | default: |
| 108 | Console::Error::WriteLine("Only conversion from .SC4, .SV4, .SC6, .SV6, or .PARK is supported."); |
| 109 | return ExitCode::fail; |
| 110 | } |
| 111 | |
| 112 | // Perform conversion |
nothing calls this directly
no test coverage detected