CMake: uninstall service during NSIS installation
Description
Add additional step to beginning of installation to execute uninstall-service.bat in target folder (if it exists). This allows users to upgrade to newer versions without having to manually stop an existing Sunshine service before installation.
N.B. CMake's default NSIS.template.in executes CPACK_NSIS_EXTRA_PREINSTALL_COMMANDS after components are installed. Resolve by including an updated template that reorders the preinstall step to run earlier.
Type of Change
- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] Dependency update (updates to dependencies)
- [ ] Documentation update (changes to documentation)
- [ ] Repository update (changes to repository files, e.g.
.github/...)
Checklist
- [x] My code follows the style guidelines of this project
- [x] I have performed a self-review of my own code
- [x] I have commented my code, particularly in hard-to-understand areas
- [ ] I have added or updated the in code docstring/documentation-blocks for new or existing methods/components
Branch Updates
LizardByte requires that branches be up-to-date before merging. This means that after any PR is merged, this branch must be updated before it can be merged. You must also Allow edits from maintainers.
- [x] I want maintainers to keep my branch updated
In case you want to see the template customization:
# git diff /mingw64/share/cmake/Modules/Internal/CPack/NSIS.template.in ../cmake/NSIS.template.in
diff --git a/mingw64/share/cmake/Modules/Internal/CPack/NSIS.template.in b/../cmake/NSIS.template.in
index 21753af..920f11d 100644
--- a/mingw64/share/cmake/Modules/Internal/CPack/NSIS.template.in
+++ b/../cmake/NSIS.template.in
@@ -644,6 +644,12 @@ FunctionEnd
; Installation types
@CPACK_NSIS_INSTALLATION_TYPES@
+Section "-Core preinstallation"
+ ;Run preinstall commands before installing component sections
+ SetOutPath "$INSTDIR"
+ @CPACK_NSIS_EXTRA_PREINSTALL_COMMANDS@
+SectionEnd
+
;--------------------------------
; Component sections
@CPACK_NSIS_COMPONENT_SECTIONS@
@@ -655,7 +661,7 @@ Section "-Core installation"
;Use the entire tree produced by the INSTALL target. Keep the
;list of directories here in sync with the RMDir commands below.
SetOutPath "$INSTDIR"
- @CPACK_NSIS_EXTRA_PREINSTALL_COMMANDS@
+ ;@CPACK_NSIS_EXTRA_PREINSTALL_COMMANDS@
@CPACK_NSIS_FULL_INSTALL@
;Store installation folder
Is it possible to only patch the default template at build time instead of including the entire template?
Or perhaps force an uninstall before a new install?
Is it possible to only patch the default template at build time instead of including the entire template?
CMake's FindTemplate function searches in CMAKE_ROOT_PATH, CMAKE_MODULE_PATH and then finally the default CMake installation path + /Modules/Internal/CPack/. I don't think we have a reliable way to locate and copy the original template ourselves without relying on hardcoded paths? Also, copying the patched file into CMAKE_MODULE_PATH is going to dirty the working tree.
Or perhaps force an uninstall before a new install?
Yes, by uncommenting: https://github.com/LizardByte/Sunshine/blob/08d623ce44f77061a26de9dc50a2aef60f1b6158/CMakeLists.txt#L565
But the user experience is suboptimal when done this way. Each time the user upgrades, the uninstall step will ask if they want to remove all files from the target. The wrong choice here may delete the user's configuration and pairing.