mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-10-04 07:09:14 +00:00
# Conflicts: # CMakeLists.txt # CMakeSettings.json # Data/Sys/GameSettings/GLR.ini # Data/Sys/GameSettings/HA9.ini # Data/Sys/GameSettings/MB3.ini # Data/Sys/GameSettings/MBA.ini # Data/Sys/GameSettings/MCV.ini # Data/Sys/GameSettings/MCY.ini # Data/Sys/GameSettings/NAK.ini # Data/Sys/GameSettings/NAL.ini # Data/Sys/GameSettings/NAT.ini # Data/Sys/GameSettings/R8P.ini # Data/Sys/GameSettings/R9I.ini # Data/Sys/GameSettings/REF.ini # Data/Sys/GameSettings/RES.ini # Data/Sys/GameSettings/RMHE08.ini # Data/Sys/GameSettings/RMHP08.ini # Data/Sys/GameSettings/SE2.ini # Data/Sys/GameSettings/WW2.ini # Data/Sys/GameSettings/WW3.ini # Data/Sys/GameSettings/WWI.ini # Externals/Bochs_disasm/Bochs_disasm.vcxproj # Externals/FreeSurround/FreeSurround.vcxproj # Externals/LZO/LZO.vcxproj # Externals/SFML/build/vc2010/SFML_Network.vcxproj # Externals/bzip2/bzip2.vcxproj # Externals/cpp-optparse/cpp-optparse.vcxproj # Externals/cubeb/msvc/cubeb.vcxproj # Externals/curl/curl.vcxproj # Externals/curl/lib/CMakeLists.txt # Externals/discord-rpc/src/discord-rpc.vcxproj # Externals/ed25519/ed25519.vcxproj # Externals/enet/enet.vcxproj # Externals/glslang/glslang.vcxproj # Externals/imgui/imgui.vcxproj # Externals/liblzma/liblzma.vcxproj # Externals/libpng/png/png.vcxproj # Externals/libusb/libusb_static_2013.vcxproj # Externals/mbedtls/mbedTLS.vcxproj # Externals/miniupnpc/miniupnpc.vcxproj # Externals/minizip/minizip.vcxproj # Externals/picojson/picojson.vcxproj # Externals/pugixml/pugixml.vcxproj # Externals/soundtouch/SoundTouch.vcxproj # Externals/xxhash/xxhash.vcxproj # Externals/zlib/zlib.vcxproj # Externals/zstd/zstd.vcxproj # Languages/Languages.vcxproj # Source/Android/jni/MainAndroid.cpp # Source/Core/AudioCommon/AudioCommon.vcxproj # Source/Core/Common/Common.vcxproj # Source/Core/Common/Common.vcxproj.filters # Source/Core/Common/Logging/Log.h # Source/Core/Common/StringUtil.cpp # Source/Core/Core/CMakeLists.txt # Source/Core/Core/ConfigManager.cpp # Source/Core/Core/ConfigManager.h # Source/Core/Core/Core.vcxproj # Source/Core/Core/Core.vcxproj.filters # Source/Core/Core/HotkeyManager.cpp # Source/Core/Core/State.cpp # Source/Core/DiscIO/DiscIO.vcxproj # Source/Core/DolphinNoGUI/DolphinNoGUI.vcxproj # Source/Core/DolphinQt/Config/Graphics/GeneralWidget.cpp # Source/Core/DolphinQt/DolphinQt.vcxproj # Source/Core/InputCommon/InputCommon.vcxproj # Source/Core/InputCommon/InputCommon.vcxproj.filters # Source/Core/UICommon/UICommon.vcxproj # Source/Core/UpdaterCommon/UpdaterCommon.vcxproj # Source/Core/VideoBackends/D3D/D3D.vcxproj # Source/Core/VideoBackends/D3D12/D3D12.vcxproj # Source/Core/VideoBackends/D3DCommon/D3DCommon.vcxproj # Source/Core/VideoBackends/Null/Null.vcxproj # Source/Core/VideoBackends/OGL/OGL.vcxproj # Source/Core/VideoBackends/Software/Software.vcxproj # Source/Core/VideoBackends/Vulkan/Vulkan.vcxproj # Source/Core/VideoCommon/OnScreenDisplay.cpp # Source/Core/VideoCommon/OnScreenDisplay.h # Source/Core/VideoCommon/VideoCommon.vcxproj # Source/Core/WinUpdater/WinUpdater.vcxproj # Source/DSPTool/DSPTool.vcxproj # Source/PCH/pch.vcxproj # Source/UnitTests/UnitTests.vcxproj
156 lines
5.2 KiB
C++
156 lines
5.2 KiB
C++
// Copyright 2017 Dolphin Emulator Project
|
|
// Licensed under GPLv2+
|
|
// Refer to the license.txt file included.
|
|
|
|
#include <list>
|
|
#include <optional>
|
|
#include <sstream>
|
|
#include <string>
|
|
#include <tuple>
|
|
|
|
#include <OptionParser.h>
|
|
|
|
#include "Common/Config/Config.h"
|
|
#include "Common/StringUtil.h"
|
|
#include "Common/Version.h"
|
|
#include "Core/Config/MainSettings.h"
|
|
#include "UICommon/CommandLineParse.h"
|
|
|
|
namespace CommandLineParse
|
|
{
|
|
class CommandLineConfigLayerLoader final : public Config::ConfigLayerLoader
|
|
{
|
|
public:
|
|
CommandLineConfigLayerLoader(const std::list<std::string>& args, const std::string& video_backend,
|
|
const std::string& audio_backend, bool batch)
|
|
: ConfigLayerLoader(Config::LayerType::CommandLine)
|
|
{
|
|
if (!video_backend.empty())
|
|
m_values.emplace_back(Config::MAIN_GFX_BACKEND.location, video_backend);
|
|
|
|
if (!audio_backend.empty())
|
|
m_values.emplace_back(Config::MAIN_DSP_HLE.location, ValueToString(audio_backend == "HLE"));
|
|
|
|
// 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)
|
|
m_values.emplace_back(Config::MAIN_RENDER_TO_MAIN.location, ValueToString(false));
|
|
|
|
// Arguments are in the format of <System>.<Section>.<Key>=Value
|
|
for (const auto& arg : args)
|
|
{
|
|
std::istringstream buffer(arg);
|
|
std::string system_str, section, key, value;
|
|
std::getline(buffer, system_str, '.');
|
|
std::getline(buffer, section, '.');
|
|
std::getline(buffer, key, '=');
|
|
std::getline(buffer, value, '=');
|
|
std::optional<Config::System> system = Config::GetSystemFromName(system_str);
|
|
if (system)
|
|
{
|
|
m_values.emplace_back(
|
|
Config::Location{std::move(*system), std::move(section), std::move(key)},
|
|
std::move(value));
|
|
}
|
|
}
|
|
}
|
|
|
|
void Load(Config::Layer* layer) override
|
|
{
|
|
for (auto& value : m_values)
|
|
{
|
|
layer->Set(std::get<0>(value), std::get<1>(value));
|
|
}
|
|
}
|
|
|
|
void Save(Config::Layer* layer) override
|
|
{
|
|
// Save Nothing
|
|
}
|
|
|
|
private:
|
|
std::list<std::tuple<Config::Location, std::string>> m_values;
|
|
};
|
|
|
|
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);
|
|
|
|
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("append")
|
|
.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");
|
|
parser->add_option("-C", "--config")
|
|
.action("append")
|
|
.metavar("<System>.<Section>.<Key>=<Value>")
|
|
.type("string")
|
|
.help("Set a configuration option");
|
|
parser->add_option("-s", "--save_state")
|
|
.action("store")
|
|
.metavar("<file>")
|
|
.type("string")
|
|
.help("Load the initial save state");
|
|
|
|
if (options == ParserOptions::IncludeGUIOptions)
|
|
{
|
|
parser->add_option("-d", "--debugger")
|
|
.action("store_true")
|
|
.help("Show the debugger pane and additional View menu options");
|
|
parser->add_option("-l", "--logger").action("store_true").help("Open the logger");
|
|
parser->add_option("-b", "--batch")
|
|
.action("store_true")
|
|
.help("Run Dolphin without the user interface (Requires --exec or --nand-title)");
|
|
parser->add_option("-c", "--confirm").action("store_true").help("Set Confirm on Stop");
|
|
}
|
|
|
|
parser->set_defaults("video_backend", "");
|
|
parser->set_defaults("audio_emulation", "");
|
|
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]");
|
|
parser->add_option("-i", "--slippi_input")
|
|
.action("store")
|
|
.metavar("<file>")
|
|
.type("string")
|
|
.help("Path to Slippi replay config file (default: Slippi/playback.txt)");
|
|
|
|
return parser;
|
|
}
|
|
|
|
static void AddConfigLayer(const optparse::Values& options)
|
|
{
|
|
std::list<std::string> config_args;
|
|
if (options.is_set_by_user("config"))
|
|
config_args = options.all("config");
|
|
|
|
Config::AddLayer(std::make_unique<CommandLineConfigLayerLoader>(
|
|
std::move(config_args), static_cast<const char*>(options.get("video_backend")),
|
|
static_cast<const char*>(options.get("audio_emulation")),
|
|
static_cast<bool>(options.get("batch"))));
|
|
}
|
|
|
|
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);
|
|
return options;
|
|
}
|
|
} // namespace CommandLineParse
|