From ffa5c903a79992044fc9123d7242b7ed81d6b975 Mon Sep 17 00:00:00 2001 From: OpenSauce04 Date: Tue, 1 Oct 2024 19:15:28 +0100 Subject: [PATCH] lime_qt: Added `-i` option for installing CIAs --- src/lime_qt/main.cpp | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/src/lime_qt/main.cpp b/src/lime_qt/main.cpp index eb5fcd302..e9df13969 100644 --- a/src/lime_qt/main.cpp +++ b/src/lime_qt/main.cpp @@ -3610,9 +3610,10 @@ static Qt::HighDpiScaleFactorRoundingPolicy GetHighDpiRoundingPolicy() { static void PrintHelp(const char* argv0) { std::cout << "Usage: " << argv0 << " [options] \n" - "-g [path] Start game at path\n" "-f Start in fullscreen mode\n" + "-g [path] Start game at path\n" "-h Display this help and exit\n" + "-i [path] Installs the CIA file at the given path\n" "-v Output version information and exit\n"; } @@ -3622,12 +3623,40 @@ static void PrintVersion() { int main(int argc, char* argv[]) { while (optind < argc) { - int arg = getopt(argc, argv, "g:fhv"); + int arg = getopt(argc, argv, "fg:hi:v"); if (arg != -1) { switch (static_cast(arg)) { case 'h': PrintHelp(argv[0]); return 0; + case 'i': { + Service::AM::InstallStatus result = Service::AM::InstallCIA(std::string(optarg)); + if (result != Service::AM::InstallStatus::Success) { + std::string failure_reason; + + if (result == Service::AM::InstallStatus::ErrorFailedToOpenFile) + failure_reason = "Unable to open file."; + + if (result == Service::AM::InstallStatus::ErrorFileNotFound) + failure_reason = "File not found."; + + if (result == Service::AM::InstallStatus::ErrorAborted) + failure_reason = "Install was aborted."; + + if (result == Service::AM::InstallStatus::ErrorInvalid) + failure_reason = "CIA is invalid."; + + if (result == Service::AM::InstallStatus::ErrorEncrypted) + failure_reason = "CIA is encrypted."; + + std::cout << "Failed to install CIA: " << failure_reason << std::endl; + return (int)result + + 2; // 2 is added here to avoid stepping on the toes of + // exit codes 1 and 2 which have pre-established conventional meanings + } + std::cout << "Installed CIA successfully." << std::endl; + return 0; + } case 'v': PrintVersion(); return 0;