From a766ed930ce72059c8d3c8adf069fa6cd73c0927 Mon Sep 17 00:00:00 2001 From: lifegpc Date: Tue, 25 Mar 2025 14:38:06 +0800 Subject: [PATCH] Add more config settings --- CMakeLists.txt | 5 +++++ config.cpp | 14 ++++++++++++++ config.hpp | 10 ++++++++++ dllmain.cpp | 10 +++------- 4 files changed, 32 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1b7ed0b..63d06d5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,6 +10,11 @@ include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include") option(USE_LIBMPV "Use libmpv." ON) option(USE_PLAYER "Use player." OFF) +option(STATIC_CRT "Use static CRT" ON) + +if (STATIC_CRT) + set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") +endif() if (USE_LIBMPV AND USE_PLAYER) message(FATAL_ERROR "USE_LIBMPV and USE_PLAYER cannot be both enabled.") diff --git a/config.cpp b/config.cpp index b862413..8f22d9c 100644 --- a/config.cpp +++ b/config.cpp @@ -42,6 +42,16 @@ bool Config::Load(std::string path) { } std::string key = l.substr(0, eq_pos); std::string value = l.substr(eq_pos + 1); +#if HAVE_MPV + if (key.find("mpv-") == 0) { + key = key.substr(4); + if (str_util::tolower(key) == "wid") { + continue; + } + mpv.push_back(std::make_pair(key, value)); + continue; + } +#endif configs[key] = value; } free_file_reader(reader); @@ -49,6 +59,8 @@ bool Config::Load(std::string path) { return true; } +#if HAVE_PLAYER + bool Config::IsAppendLogging() { auto re = configs.find("appendLogging"); if (re == configs.end()) { @@ -99,3 +111,5 @@ uint32_t Config::VideoBuffer() { } return std::stoul((*re).second); } + +#endif diff --git a/config.hpp b/config.hpp index de63e26..5c993e5 100644 --- a/config.hpp +++ b/config.hpp @@ -1,21 +1,31 @@ #include #include +#include +#include +#include "patch_config.h" class Config { public: std::unordered_map configs; +#if HAVE_MPV + std::list> mpv; +#endif Config() { configs["defaultFont"] = "微软雅黑"; configs["stringReplaceFile"] = ""; + #if HAVE_PLAYER configs["appendLogging"] = "false"; configs["loggingFile"] = ""; configs["loggingLevel"] = "info"; configs["audioBuffer"] = "0"; configs["videoBuffer"] = "0"; + #endif } bool Load(std::string path); +#if HAVE_PLAYER bool IsAppendLogging(); int LoggingLevel(); uint32_t AudioBuffer(); uint32_t VideoBuffer(); +#endif }; diff --git a/dllmain.cpp b/dllmain.cpp index bbebf0a..6e9094e 100644 --- a/dllmain.cpp +++ b/dllmain.cpp @@ -196,18 +196,14 @@ int64_t HookedOpenMediaFileAndGetDuration(DWORD* duration, const char* arcName, goto end; } HWND hwnd = *GetHwndPointer(); - int64_t wid = (int64_t)(intptr_t)hwnd; + int64_t wid = (int64_t)(uint32_t)hwnd; mpv_set_option(player, "wid", MPV_FORMAT_INT64, &wid); mpv_set_option_string(player, "config", "no"); mpv_set_option_string(player, "input-default-bindings", "no"); mpv_set_option_string(player, "hwdec", "auto"); mpv_set_option_string(player, "auto-window-resize", "no"); - // mpv_set_option_string(player, "fullscreen", "no"); - // mpv_set_option_string(player, "ontop", "no"); - // mpv_set_option_string(player, "d3d11-exclusive-fs", "no"); - auto loggingFile = config.configs["loggingFile"]; - if (!loggingFile.empty()) { - mpv_set_option_string(player, "log-file", loggingFile.c_str()); + for (auto& i : config.mpv) { + mpv_set_option_string(player, i.first.c_str(), i.second.c_str()); } const char* cmd[] = { "loadfile", videoName, nullptr }; err = mpv_command(player, cmd);