From 16ca7851c5cded923d53047486c621b10ddeadfc Mon Sep 17 00:00:00 2001 From: lizzie Date: Thu, 4 Dec 2025 07:26:56 +0100 Subject: [PATCH] [qt, cmd] Document & fix some inconsistencies with command line arguments (#3104) - documents command line arguments - allows you to specify files starting with `-` Signed-off-by: lizzie lizzie@eden-emu.dev Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/3104 Reviewed-by: Caio Oliveira Reviewed-by: crueter Co-authored-by: lizzie Co-committed-by: lizzie --- docs/user/CommandLine.md | 22 ++++++++++++ docs/user/README.md | 1 + src/yuzu/main_window.cpp | 78 ++++++++++++---------------------------- 3 files changed, 46 insertions(+), 55 deletions(-) create mode 100644 docs/user/CommandLine.md diff --git a/docs/user/CommandLine.md b/docs/user/CommandLine.md new file mode 100644 index 0000000000..4b3a5bdf58 --- /dev/null +++ b/docs/user/CommandLine.md @@ -0,0 +1,22 @@ +# User Handbook - Command Line + +There are two main applications, an SDL2 based app (`eden-cli`) and a Qt based app (`eden`); both accept command line arguments. + +## eden +- `./eden `: Running with a single argument and nothing else, will make the emulator look for the given file and load it, this behaviour is similar to `eden-cli`; allows dragging and dropping games into the application. +- `-g `: Alternate way to specify what to load, overrides. However let it be noted that arguments that use `-` will be treated as options/ignored, if your game, for some reason, starts with `-`, in order to safely handle it you may need to specify it as an argument. +- `-f`: Use fullscreen. +- `-u `: Select the index of the user to load as. +- `-qlaunch`: Launch QLaunch. +- `-setup`: Launch setup applet. + +## eden-cli +- `--debug/-d`: Enter debug mode, allow gdb stub at port `1234` +- `--config/-c`: Specify alternate configuration file. +- `--fullscreen/-f`: Set fullscreen. +- `--help/-h`: Display help. +- `--game/-g`: Specify the game to run. +- `--multiplayer/-m`: Specify multiplayer options. +- `--program/-p`: Specify the program arguments to pass (optional). +- `--user/-u`: Specify the user index. +- `--version/-v`: Display version and quit. diff --git a/docs/user/README.md b/docs/user/README.md index 822da97830..8badbabe9b 100644 --- a/docs/user/README.md +++ b/docs/user/README.md @@ -12,4 +12,5 @@ This handbook is primarily aimed at the end-user - baking useful knowledge for e - **[Testing](Testing.md)** - **[Data, savefiles and storage](Storage.md)** - **[Orphaned Profiles](Orphaned.md)** +- **[Command Line](CommandLine.md)** - **[Native Application Development](Native.md)** diff --git a/src/yuzu/main_window.cpp b/src/yuzu/main_window.cpp index 62b2f0561f..a301ae077e 100644 --- a/src/yuzu/main_window.cpp +++ b/src/yuzu/main_window.cpp @@ -627,75 +627,43 @@ MainWindow::MainWindow(bool has_broken_vulkan) bool has_gamepath = false; bool is_fullscreen = false; - for (int i = 1; i < args.size(); ++i) { - // Preserves drag/drop functionality - if (args.size() == 2 && !args[1].startsWith(QChar::fromLatin1('-'))) { - game_path = args[1]; - has_gamepath = true; - break; - } - - // Launch game in fullscreen mode + // Preserves drag/drop functionality + if (args.size() == 2 && !args[1].startsWith(QChar::fromLatin1('-'))) { + game_path = args[1]; + has_gamepath = true; + } else for (int i = 1; i < args.size(); ++i) { if (args[i] == QStringLiteral("-f")) { + // Launch game in fullscreen mode is_fullscreen = true; - continue; - } - - // Launch game with a specific user - if (args[i] == QStringLiteral("-u")) { - if (i >= args.size() - 1) { - continue; - } - - if (args[i + 1].startsWith(QChar::fromLatin1('-'))) { - continue; - } - + } else if (args[i] == QStringLiteral("-u") && i < args.size() - 1) { + // Launch game with a specific user int user_arg_idx = ++i; bool argument_ok; std::size_t selected_user = args[user_arg_idx].toUInt(&argument_ok); - if (!argument_ok) { // try to look it up by username, only finds the first username that matches. - const std::string user_arg_str = args[user_arg_idx].toStdString(); - const auto user_idx = QtCommon::system->GetProfileManager().GetUserIndex(user_arg_str); - - if (user_idx == std::nullopt) { - LOG_ERROR(Frontend, "Invalid user argument"); + std::string const user_arg_str = args[user_arg_idx].toStdString(); + auto const user_idx = QtCommon::system->GetProfileManager().GetUserIndex(user_arg_str); + if (user_idx != std::nullopt) { + selected_user = user_idx.value(); + } else { + LOG_ERROR(Frontend, "Invalid user argument '{}'", user_arg_str); continue; } - - selected_user = user_idx.value(); } - - if (!QtCommon::system->GetProfileManager().UserExistsIndex(selected_user)) { - LOG_ERROR(Frontend, "Selected user doesn't exist"); - continue; - } - - Settings::values.current_user = static_cast(selected_user); - - user_flag_cmd_line = true; - continue; - } - - // Launch game at path - if (args[i] == QStringLiteral("-g")) { - if (i >= args.size() - 1) { - continue; - } - - if (args[i + 1].startsWith(QChar::fromLatin1('-'))) { - continue; + if (QtCommon::system->GetProfileManager().UserExistsIndex(selected_user)) { + Settings::values.current_user = s32(selected_user); + user_flag_cmd_line = true; + } else { + LOG_ERROR(Frontend, "Selected user {} doesn't exist", selected_user); } - + } else if (args[i] == QStringLiteral("-g") && i < args.size() - 1) { + // Launch game at path game_path = args[++i]; has_gamepath = true; - } - - if (args[i] == QStringLiteral("-qlaunch")) + } else if (args[i] == QStringLiteral("-qlaunch")) should_launch_qlaunch = true; - if (args[i] == QStringLiteral("-setup")) + else if (args[i] == QStringLiteral("-setup")) should_launch_setup = true; }