From abb529ca273142c4c2d5dd061e516e72213cd4c6 Mon Sep 17 00:00:00 2001 From: pigeatgarlic <64737125+pigeatgarlic@users.noreply.github.com> Date: Mon, 10 Feb 2025 15:10:10 +0000 Subject: [PATCH] only run nvprefs on video --- src/main.cpp | 63 +++++++++---------- .../windows/nvprefs/nvprefs_interface.cpp | 18 +----- 2 files changed, 30 insertions(+), 51 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 80cec8d9..8110ed18 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -158,28 +158,6 @@ main(int argc, char *argv[]) { } -#ifdef _WIN32 - // Modify relevant NVIDIA control panel settings if the system has corresponding gpu - if (nvprefs_instance.load()) { - // Restore global settings to the undo file left by improper termination of sunshine.exe - nvprefs_instance.restore_from_and_delete_undo_file_if_exists(); - // Modify application settings for sunshine.exe - nvprefs_instance.modify_application_profile(); - // Modify global settings, undo file is produced in the process to restore after improper termination - nvprefs_instance.modify_global_profile(); - // Unload dynamic library to survive driver re-installation - nvprefs_instance.unload(); - } - - // Wait as long as possible to terminate Sunshine.exe during logoff/shutdown - SetProcessShutdownParameters(0x100, SHUTDOWN_NORETRY); - - // We must create a hidden window to receive shutdown notifications since we load gdi32.dll - std::promise session_monitor_hwnd_promise; - auto session_monitor_hwnd_future = session_monitor_hwnd_promise.get_future(); - std::promise session_monitor_join_thread_promise; - auto session_monitor_join_thread_future = session_monitor_join_thread_promise.get_future(); -#endif task_pool.start(1); @@ -209,15 +187,6 @@ main(int argc, char *argv[]) { process_shutdown_event->raise(true); }); - // If any of the following fail, we log an error and continue event though sunshine will not function correctly. - // This allows access to the UI to fix configuration problems or view the logs. - - auto platf_deinit_guard = platf::init(); - if (!platf_deinit_guard) { - BOOST_LOG(error) << "Platform failed to initialize"sv; - } - - int queuetype = QueueType::Video; std::stringstream ss0; ss0 << argv[1]; std::string target; ss0 >> target; @@ -227,10 +196,36 @@ main(int argc, char *argv[]) { if(queuetype == QueueType::Video) { - if (video::probe_encoders()) { - BOOST_LOG(error) << "Video failed to find working encoder"sv; - return StatusCode::NO_ENCODER_AVAILABLE; +#ifdef _WIN32 + // Modify relevant NVIDIA control panel settings if the system has corresponding gpu + if (nvprefs_instance.load()) { + // Restore global settings to the undo file left by improper termination of sunshine.exe + nvprefs_instance.restore_from_and_delete_undo_file_if_exists(); + // Modify application settings for sunshine.exe + nvprefs_instance.modify_application_profile(); + // Modify global settings, undo file is produced in the process to restore after improper termination + nvprefs_instance.modify_global_profile(); + // Unload dynamic library to survive driver re-installation + nvprefs_instance.unload(); } + + // Wait as long as possible to terminate Sunshine.exe during logoff/shutdown + SetProcessShutdownParameters(0x100, SHUTDOWN_NORETRY); + + // We must create a hidden window to receive shutdown notifications since we load gdi32.dll + std::promise session_monitor_hwnd_promise; + auto session_monitor_hwnd_future = session_monitor_hwnd_promise.get_future(); + std::promise session_monitor_join_thread_promise; + auto session_monitor_join_thread_future = session_monitor_join_thread_promise.get_future(); +#endif + } + + auto platf_deinit_guard = platf::init(); + if (!platf_deinit_guard) + BOOST_LOG(error) << "Platform failed to initialize"sv; + if(queuetype == QueueType::Video && video::probe_encoders()) { + BOOST_LOG(error) << "Video failed to find working encoder"sv; + return StatusCode::NO_ENCODER_AVAILABLE; } //Get buffer local address from handle diff --git a/src/platform/windows/nvprefs/nvprefs_interface.cpp b/src/platform/windows/nvprefs/nvprefs_interface.cpp index 628248ad..d89e870c 100644 --- a/src/platform/windows/nvprefs/nvprefs_interface.cpp +++ b/src/platform/windows/nvprefs/nvprefs_interface.cpp @@ -18,7 +18,6 @@ namespace nvprefs { struct nvprefs_interface::impl { bool loaded = false; driver_settings_t driver_settings; - std::filesystem::path undo_folder_path; std::filesystem::path undo_file_path; std::optional undo_data; std::optional undo_file; @@ -38,17 +37,8 @@ namespace nvprefs { bool nvprefs_interface::load() { if (!pimpl->loaded) { - // Check %ProgramData% variable, need it for storing undo file - wchar_t program_data_env[MAX_PATH]; - auto get_env_result = GetEnvironmentVariableW(L"ProgramData", program_data_env, MAX_PATH); - if (get_env_result == 0 || get_env_result >= MAX_PATH || !std::filesystem::is_directory(program_data_env)) { - error_message("Missing or malformed %ProgramData% environment variable"); - return false; - } - // Prepare undo file path variables - pimpl->undo_folder_path = std::filesystem::path(program_data_env) / sunshine_program_data_folder; - pimpl->undo_file_path = pimpl->undo_folder_path / nvprefs_undo_file_name; + pimpl->undo_file_path = std::filesystem::current_path() / nvprefs_undo_file_name; // Dynamically load nvapi library and load driver settings pimpl->loaded = pimpl->driver_settings.init(); @@ -144,12 +134,6 @@ namespace nvprefs { auto make_undo_and_commit = [&]() -> bool { // Create and lock undo file if it hasn't been done yet if (!pimpl->undo_file) { - // Prepare Sunshine folder in ProgramData if it doesn't exist - if (!CreateDirectoryW(pimpl->undo_folder_path.c_str(), nullptr) && GetLastError() != ERROR_ALREADY_EXISTS) { - error_message("Couldn't create undo folder"); - return false; - } - // Create undo file to handle improper termination of nvprefs.exe pimpl->undo_file = undo_file_t::create_new_file(pimpl->undo_file_path); if (!pimpl->undo_file) {