2016-01-17 04:11:43 -07:00
|
|
|
// Copyright 2017 Dolphin Emulator Project
|
2021-07-04 19:22:19 -06:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2016-01-17 04:11:43 -07:00
|
|
|
|
2016-01-19 07:15:48 -07:00
|
|
|
#include <list>
|
2017-11-26 10:24:01 -07:00
|
|
|
#include <optional>
|
2016-01-19 07:15:48 -07:00
|
|
|
#include <sstream>
|
|
|
|
#include <string>
|
|
|
|
#include <tuple>
|
|
|
|
|
2016-01-17 04:11:43 -07:00
|
|
|
#include <OptionParser.h>
|
|
|
|
|
2016-01-19 07:15:48 -07:00
|
|
|
#include "Common/Config/Config.h"
|
2017-10-30 11:15:21 -06:00
|
|
|
#include "Common/StringUtil.h"
|
2017-09-09 13:52:35 -06:00
|
|
|
#include "Common/Version.h"
|
2017-10-30 11:15:21 -06:00
|
|
|
#include "Core/Config/MainSettings.h"
|
2016-01-17 04:11:43 -07:00
|
|
|
#include "UICommon/CommandLineParse.h"
|
|
|
|
|
|
|
|
namespace CommandLineParse
|
|
|
|
{
|
2016-01-19 07:15:48 -07:00
|
|
|
class CommandLineConfigLayerLoader final : public Config::ConfigLayerLoader
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CommandLineConfigLayerLoader(const std::list<std::string>& args, const std::string& video_backend,
|
2019-10-27 12:03:10 -06:00
|
|
|
const std::string& audio_backend, bool batch)
|
2016-01-19 07:15:48 -07:00
|
|
|
: ConfigLayerLoader(Config::LayerType::CommandLine)
|
|
|
|
{
|
2019-02-12 15:47:17 -07:00
|
|
|
if (!video_backend.empty())
|
2020-09-20 05:58:17 -06:00
|
|
|
m_values.emplace_back(Config::MAIN_GFX_BACKEND.GetLocation(), video_backend);
|
2016-01-19 07:15:48 -07:00
|
|
|
|
2019-02-12 15:47:17 -07:00
|
|
|
if (!audio_backend.empty())
|
2020-09-20 05:58:17 -06:00
|
|
|
{
|
|
|
|
m_values.emplace_back(Config::MAIN_DSP_HLE.GetLocation(),
|
|
|
|
ValueToString(audio_backend == "HLE"));
|
|
|
|
}
|
2016-01-19 07:15:48 -07:00
|
|
|
|
2019-10-27 12:03:10 -06:00
|
|
|
// Batch mode hides the main window, and render to main hides the render window. To avoid a
|
|
|
|
// situation where we would have no window at all, disable render to main when using batch mode.
|
|
|
|
if (batch)
|
2020-09-20 05:58:17 -06:00
|
|
|
m_values.emplace_back(Config::MAIN_RENDER_TO_MAIN.GetLocation(), ValueToString(false));
|
2019-10-27 12:03:10 -06:00
|
|
|
|
2016-01-19 07:15:48 -07:00
|
|
|
// Arguments are in the format of <System>.<Section>.<Key>=Value
|
|
|
|
for (const auto& arg : args)
|
|
|
|
{
|
|
|
|
std::istringstream buffer(arg);
|
2017-10-30 11:15:21 -06:00
|
|
|
std::string system_str, section, key, value;
|
|
|
|
std::getline(buffer, system_str, '.');
|
2016-01-19 07:15:48 -07:00
|
|
|
std::getline(buffer, section, '.');
|
|
|
|
std::getline(buffer, key, '=');
|
|
|
|
std::getline(buffer, value, '=');
|
2020-08-17 18:23:28 -06:00
|
|
|
std::optional<Config::System> system = Config::GetSystemFromName(system_str);
|
2017-11-26 10:24:01 -07:00
|
|
|
if (system)
|
|
|
|
{
|
|
|
|
m_values.emplace_back(
|
2020-05-02 06:39:40 -06:00
|
|
|
Config::Location{std::move(*system), std::move(section), std::move(key)},
|
2019-08-11 12:43:18 -06:00
|
|
|
std::move(value));
|
2017-11-26 10:24:01 -07:00
|
|
|
}
|
2016-01-19 07:15:48 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-29 13:11:15 -06:00
|
|
|
void Load(Config::Layer* layer) override
|
2016-01-19 07:15:48 -07:00
|
|
|
{
|
|
|
|
for (auto& value : m_values)
|
|
|
|
{
|
2017-10-29 13:11:15 -06:00
|
|
|
layer->Set(std::get<0>(value), std::get<1>(value));
|
2016-01-19 07:15:48 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-29 13:11:15 -06:00
|
|
|
void Save(Config::Layer* layer) override
|
2016-01-19 07:15:48 -07:00
|
|
|
{
|
|
|
|
// Save Nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2020-05-02 06:39:40 -06:00
|
|
|
std::list<std::tuple<Config::Location, std::string>> m_values;
|
2016-01-19 07:15:48 -07:00
|
|
|
};
|
|
|
|
|
2016-01-17 04:11:43 -07:00
|
|
|
std::unique_ptr<optparse::OptionParser> CreateParser(ParserOptions options)
|
|
|
|
{
|
|
|
|
auto parser = std::make_unique<optparse::OptionParser>();
|
2017-09-09 13:52:35 -06:00
|
|
|
parser->usage("usage: %prog [options]... [FILE]...").version(Common::scm_rev_str);
|
2016-01-17 04:11:43 -07:00
|
|
|
|
|
|
|
parser->add_option("-u", "--user").action("store").help("User folder path");
|
|
|
|
parser->add_option("-m", "--movie").action("store").help("Play a movie file");
|
|
|
|
parser->add_option("-e", "--exec")
|
2018-11-05 11:20:45 -07:00
|
|
|
.action("append")
|
2016-01-17 04:11:43 -07:00
|
|
|
.metavar("<file>")
|
|
|
|
.type("string")
|
|
|
|
.help("Load the specified file");
|
2017-10-01 16:09:07 -06:00
|
|
|
parser->add_option("-n", "--nand_title")
|
|
|
|
.action("store")
|
|
|
|
.metavar("<16-character ASCII title ID>")
|
|
|
|
.type("string")
|
|
|
|
.help("Launch a NAND title");
|
2016-01-19 07:15:48 -07:00
|
|
|
parser->add_option("-C", "--config")
|
|
|
|
.action("append")
|
|
|
|
.metavar("<System>.<Section>.<Key>=<Value>")
|
|
|
|
.type("string")
|
|
|
|
.help("Set a configuration option");
|
2020-05-06 21:10:30 -06:00
|
|
|
parser->add_option("-s", "--save_state")
|
|
|
|
.action("store")
|
|
|
|
.metavar("<file>")
|
|
|
|
.type("string")
|
|
|
|
.help("Load the initial save state");
|
2016-01-17 04:11:43 -07:00
|
|
|
|
|
|
|
if (options == ParserOptions::IncludeGUIOptions)
|
|
|
|
{
|
2017-09-09 23:49:35 -06:00
|
|
|
parser->add_option("-d", "--debugger")
|
|
|
|
.action("store_true")
|
|
|
|
.help("Show the debugger pane and additional View menu options");
|
2017-11-19 14:11:33 -07:00
|
|
|
parser->add_option("-l", "--logger").action("store_true").help("Open the logger");
|
2019-08-11 12:58:04 -06:00
|
|
|
parser->add_option("-b", "--batch")
|
|
|
|
.action("store_true")
|
2019-10-27 12:03:10 -06:00
|
|
|
.help("Run Dolphin without the user interface (Requires --exec or --nand-title)");
|
2016-01-17 04:11:43 -07:00
|
|
|
parser->add_option("-c", "--confirm").action("store_true").help("Set Confirm on Stop");
|
|
|
|
}
|
|
|
|
|
2016-01-19 07:15:48 -07:00
|
|
|
parser->set_defaults("video_backend", "");
|
|
|
|
parser->set_defaults("audio_emulation", "");
|
2016-01-17 04:11:43 -07:00
|
|
|
parser->add_option("-v", "--video_backend").action("store").help("Specify a video backend");
|
|
|
|
parser->add_option("-a", "--audio_emulation")
|
|
|
|
.choices({"HLE", "LLE"})
|
|
|
|
.help("Choose audio emulation from [%choices]");
|
|
|
|
|
|
|
|
return parser;
|
|
|
|
}
|
|
|
|
|
2017-11-26 09:22:37 -07:00
|
|
|
static void AddConfigLayer(const optparse::Values& options)
|
2016-01-17 04:11:43 -07:00
|
|
|
{
|
2019-10-28 03:30:34 -06:00
|
|
|
std::list<std::string> config_args;
|
2017-11-26 10:14:43 -07:00
|
|
|
if (options.is_set_by_user("config"))
|
2019-10-28 03:30:34 -06:00
|
|
|
config_args = options.all("config");
|
|
|
|
|
|
|
|
Config::AddLayer(std::make_unique<CommandLineConfigLayerLoader>(
|
|
|
|
std::move(config_args), static_cast<const char*>(options.get("video_backend")),
|
2019-10-27 12:03:10 -06:00
|
|
|
static_cast<const char*>(options.get("audio_emulation")),
|
|
|
|
static_cast<bool>(options.get("batch"))));
|
2017-11-26 09:22:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
optparse::Values& ParseArguments(optparse::OptionParser* parser, int argc, char** argv)
|
|
|
|
{
|
|
|
|
optparse::Values& options = parser->parse_args(argc, argv);
|
|
|
|
AddConfigLayer(options);
|
|
|
|
return options;
|
|
|
|
}
|
|
|
|
|
|
|
|
optparse::Values& ParseArguments(optparse::OptionParser* parser,
|
|
|
|
const std::vector<std::string>& arguments)
|
|
|
|
{
|
|
|
|
optparse::Values& options = parser->parse_args(arguments);
|
|
|
|
AddConfigLayer(options);
|
2016-01-19 07:15:48 -07:00
|
|
|
return options;
|
2016-01-17 04:11:43 -07:00
|
|
|
}
|
2019-05-05 17:48:12 -06:00
|
|
|
} // namespace CommandLineParse
|