mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-08-04 08:22:32 +00:00
Rewriting code to use program_options library (pending ext-boost PR)
This commit is contained in:
parent
df2f721449
commit
99defa7f08
@ -99,7 +99,7 @@ string(TIMESTAMP BUILD_DATE "%Y-%m-%d %H:%M:%S")
|
||||
|
||||
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/src/common/scm_rev.cpp.in" "${CMAKE_CURRENT_SOURCE_DIR}/src/common/scm_rev.cpp" @ONLY)
|
||||
|
||||
find_package(Boost 1.84.0 CONFIG)
|
||||
find_package(Boost 1.84.0 CONFIG COMPONENTS program_options)
|
||||
find_package(FFmpeg 5.1.2 MODULE)
|
||||
find_package(fmt 10.2.0 CONFIG)
|
||||
find_package(glslang 14.2.0 CONFIG)
|
||||
@ -762,7 +762,7 @@ endif()
|
||||
create_target_directory_groups(shadps4)
|
||||
|
||||
target_link_libraries(shadps4 PRIVATE magic_enum::magic_enum fmt::fmt toml11::toml11 tsl::robin_map xbyak::xbyak Tracy::TracyClient RenderDoc::API FFmpeg::ffmpeg Dear_ImGui gcn)
|
||||
target_link_libraries(shadps4 PRIVATE Boost::headers GPUOpen::VulkanMemoryAllocator sirit Vulkan::Headers xxHash::xxhash Zydis::Zydis glslang::SPIRV glslang::glslang SDL3::SDL3 pugixml::pugixml)
|
||||
target_link_libraries(shadps4 PRIVATE Boost::headers Boost::program_options GPUOpen::VulkanMemoryAllocator sirit Vulkan::Headers xxHash::xxhash Zydis::Zydis glslang::SPIRV glslang::glslang SDL3::SDL3 pugixml::pugixml)
|
||||
|
||||
target_compile_definitions(shadps4 PRIVATE IMGUI_USER_CONFIG="imgui/imgui_config.h")
|
||||
target_compile_definitions(Dear_ImGui PRIVATE IMGUI_USER_CONFIG="${PROJECT_SOURCE_DIR}/src/imgui/imgui_config.h")
|
||||
|
@ -2,7 +2,9 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <boost/program_options.hpp>
|
||||
#include <common/version.h>
|
||||
#include <fmt/core.h>
|
||||
#include <fmt/xchar.h> // for wstring support
|
||||
@ -28,8 +30,13 @@ std::filesystem::path find_fs_path_or(const basic_value<TC>& v, const K& ky,
|
||||
}
|
||||
} // namespace toml
|
||||
|
||||
namespace po = boost::program_options;
|
||||
|
||||
namespace Config {
|
||||
|
||||
// Program options map
|
||||
static po::variables_map optionMap;
|
||||
|
||||
static bool isNeo = false;
|
||||
static bool isFullscreen = false;
|
||||
static bool playBGM = false;
|
||||
@ -42,7 +49,6 @@ static std::string logFilter;
|
||||
static std::string logType = "async";
|
||||
static std::string userName = "shadPS4";
|
||||
static std::string updateChannel;
|
||||
static std::string patchFile = "";
|
||||
static std::string backButtonBehavior = "left";
|
||||
static bool useSpecialPad = false;
|
||||
static int specialPadClass = 1;
|
||||
@ -89,6 +95,10 @@ bool isNeoMode() {
|
||||
}
|
||||
|
||||
bool isFullscreenMode() {
|
||||
if (optionMap.count("fullscreen")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return isFullscreen;
|
||||
}
|
||||
|
||||
@ -141,7 +151,11 @@ std::string getUpdateChannel() {
|
||||
}
|
||||
|
||||
std::string getPatchFile() {
|
||||
return patchFile;
|
||||
if (optionMap.contains("patch-file")) {
|
||||
return optionMap["patch-file"].as<std::string>();
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string getBackButtonBehavior() {
|
||||
@ -312,10 +326,6 @@ void setUpdateChannel(const std::string& type) {
|
||||
updateChannel = type;
|
||||
}
|
||||
|
||||
void setPatchFile(const std::string& fileName) {
|
||||
patchFile = fileName;
|
||||
}
|
||||
|
||||
void setBackButtonBehavior(const std::string& type) {
|
||||
backButtonBehavior = type;
|
||||
}
|
||||
@ -576,15 +586,24 @@ void load(const std::filesystem::path& path) {
|
||||
}
|
||||
}
|
||||
|
||||
void loadArgs(int& argc, char* argv[]) {
|
||||
for (int i = 0; i < argc; i++) {
|
||||
const std::string arg = argv[i];
|
||||
if (arg == "-p") {
|
||||
patchFile = argv[i + 1];
|
||||
} else if (arg == "-f" || arg == "--fullscreen") {
|
||||
isFullscreen = true;
|
||||
}
|
||||
bool loadArgs(int argc, char* argv[]) {
|
||||
// Declare the supported options.
|
||||
std::string description = fmt::format("Usage: {} [options] <elf or eboot.bin path>", argv[0]);
|
||||
po::options_description desc(description);
|
||||
auto options = desc.add_options();
|
||||
options("help", "Shows this help message");
|
||||
options("patch-file,p", po::value<std::string>(), "Specifies the patch file");
|
||||
options("fullscreen,f", "Switches the emulator to fullscreen mode");
|
||||
|
||||
po::store(po::parse_command_line(argc, argv, desc), optionMap);
|
||||
po::notify(optionMap);
|
||||
|
||||
if (argc == 1 || optionMap.count("help")) {
|
||||
std::cout << desc << "\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void save(const std::filesystem::path& path) {
|
||||
@ -690,7 +709,6 @@ void setDefaultValues() {
|
||||
} else {
|
||||
updateChannel = "Nightly";
|
||||
}
|
||||
patchFile = "";
|
||||
cursorState = HideCursorState::Idle;
|
||||
cursorHideTimeout = 5;
|
||||
backButtonBehavior = "left";
|
||||
|
@ -13,7 +13,7 @@ enum HideCursorState : s16 { Never, Idle, Always };
|
||||
|
||||
void load(const std::filesystem::path& path);
|
||||
void save(const std::filesystem::path& path);
|
||||
void loadArgs(int& argc, char* argv[]);
|
||||
bool loadArgs(int argc, char* argv[]);
|
||||
|
||||
bool isNeoMode();
|
||||
bool isFullscreenMode();
|
||||
|
@ -256,14 +256,6 @@ void Emulator::Run(const std::filesystem::path& file) {
|
||||
std::exit(0);
|
||||
}
|
||||
|
||||
void Emulator::Run(int& argc, char* argv[]) {
|
||||
// Load config options from arguments
|
||||
Config::loadArgs(argc, argv);
|
||||
MemoryPatcher::patchFile = Config::getPatchFile();
|
||||
|
||||
this->Run(argv[1]);
|
||||
}
|
||||
|
||||
void Emulator::LoadSystemModules(const std::filesystem::path& file) {
|
||||
constexpr std::array<SysModules, 13> ModulesToLoad{
|
||||
{{"libSceNgs2.sprx", &Libraries::Ngs2::RegisterlibSceNgs2},
|
||||
|
@ -26,7 +26,6 @@ public:
|
||||
~Emulator();
|
||||
|
||||
void Run(const std::filesystem::path& file);
|
||||
void Run(int& argc, char* argv[]);
|
||||
void UpdatePlayTime(const std::string& serial);
|
||||
|
||||
private:
|
||||
|
11
src/main.cpp
11
src/main.cpp
@ -2,6 +2,8 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <fmt/core.h>
|
||||
#include "common/config.h"
|
||||
#include "common/memory_patcher.h"
|
||||
#include "emulator.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
@ -13,6 +15,13 @@ int main(int argc, char* argv[]) {
|
||||
SetConsoleOutputCP(CP_UTF8);
|
||||
#endif
|
||||
|
||||
// Parse command line arguments
|
||||
if (!Config::loadArgs(argc, argv)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
MemoryPatcher::patchFile = Config::getPatchFile();
|
||||
|
||||
if (argc == 1) {
|
||||
fmt::print("Usage: {} <elf or eboot.bin path>\n", argv[0]);
|
||||
return -1;
|
||||
@ -24,7 +33,7 @@ int main(int argc, char* argv[]) {
|
||||
}
|
||||
|
||||
Core::Emulator emulator;
|
||||
emulator.Run(argc, argv);
|
||||
emulator.Run(argv[argc - 1]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "common/config.h"
|
||||
#include "common/memory_patcher.h"
|
||||
#include "core/file_sys/fs.h"
|
||||
#include "emulator.h"
|
||||
#include "game_install_dialog.h"
|
||||
@ -18,13 +19,19 @@ int main(int argc, char* argv[]) {
|
||||
#ifdef _WIN32
|
||||
SetConsoleOutputCP(CP_UTF8);
|
||||
#endif
|
||||
// Parse command line arguments
|
||||
if (!Config::loadArgs(argc, argv)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
QApplication a(argc, argv);
|
||||
MemoryPatcher::patchFile = Config::getPatchFile();
|
||||
|
||||
// Load configurations and initialize Qt application
|
||||
const auto user_dir = Common::FS::GetUserPath(Common::FS::PathType::UserDir);
|
||||
Config::load(user_dir / "config.toml");
|
||||
|
||||
QApplication a(argc, argv);
|
||||
|
||||
// Check if elf or eboot.bin path was passed as a command line argument
|
||||
bool has_command_line_argument = argc > 1;
|
||||
|
||||
@ -44,7 +51,7 @@ int main(int argc, char* argv[]) {
|
||||
// Check for command line arguments
|
||||
if (has_command_line_argument) {
|
||||
Core::Emulator emulator;
|
||||
emulator.Run(argc, argv);
|
||||
emulator.Run(argv[argc - 1]);
|
||||
}
|
||||
|
||||
// Run the Qt application
|
||||
|
Loading…
Reference in New Issue
Block a user