dolphin/Source/Core/UICommon/CommandLineParse.cpp

122 lines
4.0 KiB
C++
Raw Normal View History

2016-01-17 11:11:43 +00:00
// Copyright 2017 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
2016-01-19 14:15:48 +00:00
#include <list>
#include <sstream>
#include <string>
#include <tuple>
2016-01-17 11:11:43 +00:00
#include <OptionParser.h>
2016-01-19 14:15:48 +00:00
#include "Common/Config/Config.h"
2017-10-30 17:15:21 +00:00
#include "Common/StringUtil.h"
#include "Common/Version.h"
2017-10-30 17:15:21 +00:00
#include "Core/Config/MainSettings.h"
2016-01-17 11:11:43 +00:00
#include "UICommon/CommandLineParse.h"
namespace CommandLineParse
{
2016-01-19 14:15:48 +00:00
class CommandLineConfigLayerLoader final : public Config::ConfigLayerLoader
{
public:
CommandLineConfigLayerLoader(const std::list<std::string>& args, const std::string& video_backend,
const std::string& audio_backend)
: ConfigLayerLoader(Config::LayerType::CommandLine)
{
if (video_backend.size())
2017-10-30 17:15:21 +00:00
m_values.emplace_back(std::make_tuple(Config::MAIN_GFX_BACKEND.location, video_backend));
2016-01-19 14:15:48 +00:00
if (audio_backend.size())
m_values.emplace_back(
2017-10-30 17:15:21 +00:00
std::make_tuple(Config::MAIN_DSP_HLE.location, StringFromBool(audio_backend == "HLE")));
2016-01-19 14:15:48 +00:00
// Arguments are in the format of <System>.<Section>.<Key>=Value
for (const auto& arg : args)
{
std::istringstream buffer(arg);
2017-10-30 17:15:21 +00:00
std::string system_str, section, key, value;
std::getline(buffer, system_str, '.');
2016-01-19 14:15:48 +00:00
std::getline(buffer, section, '.');
std::getline(buffer, key, '=');
std::getline(buffer, value, '=');
2017-10-30 17:15:21 +00:00
Config::System system = Config::GetSystemFromName(system_str);
m_values.emplace_back(std::make_tuple(Config::ConfigLocation{system, section, key}, value));
2016-01-19 14:15:48 +00:00
}
}
void Load(Config::Layer* layer) override
2016-01-19 14:15:48 +00:00
{
for (auto& value : m_values)
{
layer->Set(std::get<0>(value), std::get<1>(value));
2016-01-19 14:15:48 +00:00
}
}
void Save(Config::Layer* layer) override
2016-01-19 14:15:48 +00:00
{
// Save Nothing
}
private:
2017-10-30 17:15:21 +00:00
std::list<std::tuple<Config::ConfigLocation, std::string>> m_values;
2016-01-19 14:15:48 +00:00
};
2016-01-17 11:11:43 +00:00
std::unique_ptr<optparse::OptionParser> CreateParser(ParserOptions options)
{
auto parser = std::make_unique<optparse::OptionParser>();
parser->usage("usage: %prog [options]... [FILE]...").version(Common::scm_rev_str);
2016-01-17 11:11:43 +00: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")
.action("store")
.metavar("<file>")
.type("string")
.help("Load the specified file");
parser->add_option("-n", "--nand_title")
.action("store")
.metavar("<16-character ASCII title ID>")
.type("string")
.help("Launch a NAND title");
2016-01-19 14:15:48 +00:00
parser->add_option("-C", "--config")
.action("append")
.metavar("<System>.<Section>.<Key>=<Value>")
.type("string")
.help("Set a configuration option");
2016-01-17 11:11:43 +00:00
if (options == ParserOptions::IncludeGUIOptions)
{
2017-09-10 05:49:35 +00:00
parser->add_option("-d", "--debugger")
.action("store_true")
.help("Show the debugger pane and additional View menu options");
2016-01-17 11:11:43 +00:00
parser->add_option("-l", "--logger").action("store_true").help("Opens the logger");
parser->add_option("-b", "--batch").action("store_true").help("Exit Dolphin with emulation");
parser->add_option("-c", "--confirm").action("store_true").help("Set Confirm on Stop");
}
2016-01-19 14:15:48 +00:00
parser->set_defaults("video_backend", "");
parser->set_defaults("audio_emulation", "");
2016-01-17 11:11:43 +00: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;
}
optparse::Values& ParseArguments(optparse::OptionParser* parser, int argc, char** argv)
{
2016-01-19 14:15:48 +00:00
optparse::Values& options = parser->parse_args(argc, argv);
const std::list<std::string>& config_args = options.all("config");
if (config_args.size())
{
Config::AddLayer(std::make_unique<CommandLineConfigLayerLoader>(
config_args, static_cast<const char*>(options.get("video_backend")),
static_cast<const char*>(options.get("audio_emulation"))));
}
return options;
2016-01-17 11:11:43 +00:00
}
}