From c95f54f874841d9f772780856c4c64150ef015bc Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Sat, 7 Jan 2023 12:34:06 -0600 Subject: [PATCH] Migrate Windows config files into specific config directory (#716) --- CMakeLists.txt | 11 ++++- docs/source/about/advanced_usage.rst | 2 +- src/platform/windows/misc.cpp | 4 +- src_assets/linux/assets/apps.json | 1 - src_assets/macos/assets/apps.json | 1 - src_assets/windows/assets/apps.json | 1 - .../windows/misc/migration/migrate-config.bat | 46 +++++++++++++++++++ 7 files changed, 59 insertions(+), 7 deletions(-) create mode 100644 src_assets/windows/misc/migration/migrate-config.bat diff --git a/CMakeLists.txt b/CMakeLists.txt index ef731b51..54303f01 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -532,6 +532,9 @@ if(WIN32) # see options at: https://cmake.org/cmake/help/latest/cpack_gen/nsis.h install(DIRECTORY "${SUNSHINE_SOURCE_ASSETS_DIR}/windows/misc/service/" DESTINATION "scripts" COMPONENT service) + install(DIRECTORY "${SUNSHINE_SOURCE_ASSETS_DIR}/windows/misc/migration/" + DESTINATION "scripts" + COMPONENT assets) # Sunshine assets install(DIRECTORY "${SUNSHINE_SOURCE_ASSETS_DIR}/common/assets/" @@ -548,12 +551,16 @@ if(WIN32) # see options at: https://cmake.org/cmake/help/latest/cpack_gen/nsis.h set(CPACK_PACKAGE_INSTALL_DIRECTORY "${CPACK_PACKAGE_NAME}") # Extra install commands - # Sets permissions on the installed folder so that we can write in it + # Restores permissions on the install directory + # Migrates config files from the root into the new config folder + # Sets permissions on the config folder so that we can write in it # Install service SET(CPACK_NSIS_EXTRA_INSTALL_COMMANDS "${CPACK_NSIS_EXTRA_INSTALL_COMMANDS} ExecWait '\\\"$SYSDIR\\\\cmd.exe\\\" /c \\\"start https://sunshinestream.readthedocs.io/\\\"' - ExecWait 'icacls \\\"$INSTDIR\\\" /grant:r Users:\\\(OI\\\)\\\(CI\\\)\\\(F\\\)' + ExecWait 'icacls \\\"$INSTDIR\\\" /reset' + ExecWait '\\\"$INSTDIR\\\\scripts\\\\migrate-config.bat\\\"' + ExecWait 'icacls \\\"$INSTDIR\\\\config\\\" /grant:r Users:\\\(OI\\\)\\\(CI\\\)\\\(F\\\)' ExecWait '\\\"$INSTDIR\\\\scripts\\\\add-firewall-rule.bat\\\"' ExecWait '\\\"$INSTDIR\\\\scripts\\\\install-service.bat\\\"' MessageBox MB_YESNO|MB_ICONQUESTION 'Do you want to add/update ViGEmBus (virtual controller support)?' \ diff --git a/docs/source/about/advanced_usage.rst b/docs/source/about/advanced_usage.rst index f2087728..03e46983 100644 --- a/docs/source/about/advanced_usage.rst +++ b/docs/source/about/advanced_usage.rst @@ -33,7 +33,7 @@ location by modifying the configuration file. Docker /config/ Linux ~/.config/sunshine/ macOS ~/.config/sunshine/ - Windows ./config/ + Windows %ProgramFiles%\\Sunshine\\config ========= =========== **Example** diff --git a/src/platform/windows/misc.cpp b/src/platform/windows/misc.cpp index 88e714d3..a9d31b8f 100644 --- a/src/platform/windows/misc.cpp +++ b/src/platform/windows/misc.cpp @@ -29,7 +29,9 @@ namespace platf { using adapteraddrs_t = util::c_ptr; std::filesystem::path appdata() { - return L"."sv; + WCHAR sunshine_path[MAX_PATH]; + GetModuleFileNameW(NULL, sunshine_path, _countof(sunshine_path)); + return std::filesystem::path { sunshine_path }.remove_filename() / L"config"sv; } std::string from_sockaddr(const sockaddr *const socket_address) { diff --git a/src_assets/linux/assets/apps.json b/src_assets/linux/assets/apps.json index a5211fa5..5331dcf8 100644 --- a/src_assets/linux/assets/apps.json +++ b/src_assets/linux/assets/apps.json @@ -19,7 +19,6 @@ }, { "name": "Steam BigPicture", - "output": "steam.txt", "detached": [ "setsid steam steam://open/bigpicture" ], diff --git a/src_assets/macos/assets/apps.json b/src_assets/macos/assets/apps.json index 94b2cde1..88559542 100644 --- a/src_assets/macos/assets/apps.json +++ b/src_assets/macos/assets/apps.json @@ -9,7 +9,6 @@ }, { "name": "Steam BigPicture", - "output": "steam.txt", "detached": [ "open steam://open/bigpicture" ], diff --git a/src_assets/windows/assets/apps.json b/src_assets/windows/assets/apps.json index 1f27805a..08d2386d 100644 --- a/src_assets/windows/assets/apps.json +++ b/src_assets/windows/assets/apps.json @@ -9,7 +9,6 @@ }, { "name": "Steam BigPicture", - "output": "steam.txt", "detached": [ "steam steam://open/bigpicture" ], diff --git a/src_assets/windows/misc/migration/migrate-config.bat b/src_assets/windows/misc/migration/migrate-config.bat new file mode 100644 index 00000000..313b472e --- /dev/null +++ b/src_assets/windows/misc/migration/migrate-config.bat @@ -0,0 +1,46 @@ +@echo off + +rem Get sunshine root directory +for %%I in ("%~dp0\..") do set "OLD_DIR=%%~fI" + +rem Create the config directory if it didn't already exist +set "NEW_DIR=%OLD_DIR%\config" +if not exist "%NEW_DIR%\" mkdir "%NEW_DIR%" + +rem Migrate all files that aren't already present in the config dir +if exist "%OLD_DIR%\apps.json" ( + if not exist "%NEW_DIR%\apps.json" ( + move "%OLD_DIR%\apps.json" "%NEW_DIR%\apps.json" + ) +) +if exist "%OLD_DIR%\sunshine.conf" ( + if not exist "%NEW_DIR%\sunshine.conf" ( + move "%OLD_DIR%\sunshine.conf" "%NEW_DIR%\sunshine.conf" + ) +) +if exist "%OLD_DIR%\sunshine_state.json" ( + if not exist "%NEW_DIR%\sunshine_state.json" ( + move "%OLD_DIR%\sunshine_state.json" "%NEW_DIR%\sunshine_state.json" + ) +) + +rem Migrate the credentials directory +if exist "%OLD_DIR%\credentials\" ( + if not exist "%NEW_DIR%\credentials\" ( + move "%OLD_DIR%\credentials" "%NEW_DIR%\" + ) +) + +rem Migrate the covers directory +if exist "%OLD_DIR%\covers\" ( + if not exist "%NEW_DIR%\covers\" ( + move "%OLD_DIR%\covers" "%NEW_DIR%\" + + rem Fix apps.json image path values that point at the old covers directory + powershell -c "(Get-Content '%NEW_DIR%\apps.json').replace('.\/covers\/', '.\/config\/covers\/') | Set-Content '%NEW_DIR%\apps.json'" + ) +) + +rem Remove log files +del "%OLD_DIR%\*.txt" +del "%OLD_DIR%\*.log"