Skip to content

Check for MSVC redist before starting service on Windows - #8327

Merged
nbolton merged 2 commits into
masterfrom
fix8326
Mar 7, 2025
Merged

Check for MSVC redist before starting service on Windows#8327
nbolton merged 2 commits into
masterfrom
fix8326

Conversation

@nbolton

@nbolton nbolton commented Mar 7, 2025

Copy link
Copy Markdown
Member

Fixes: #8326

image

nbolton added 2 commits March 7, 2025 14:35
Indefinitely restarting the daemon is annoying as it makes problems harder to diagnose.
@nbolton

nbolton commented Mar 7, 2025

Copy link
Copy Markdown
Member Author

Saving this for later... I tried to get a bit fancy and run the MSVC installer if the MSVC runtime is missing or it's minor version is too low, but got stuck and ran out of time.

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7337b096..7f93a6f8 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -94,6 +94,8 @@ set(REQUIRED_OPENSSL_VERSION 3.0)
 set(REQUIRED_LIBEI_VERSION 1.3)
 set(REQUIRED_LIBPORTAL_VERSION 0.8)
 set(REQUIRED_QT_VERSION 6.7.0)
+set(REQUIRED_MSVC_RUNTIME_MAJOR 14)
+set(REQUIRED_MSVC_RUNTIME_MINOR 42)
 
 # Control debug item visibility
 # When not set logging is forced to DEBUG and show code locations
diff --git a/deploy/windows/deploy.cmake b/deploy/windows/deploy.cmake
index fe71d90c..1d50a6ea 100644
--- a/deploy/windows/deploy.cmake
+++ b/deploy/windows/deploy.cmake
@@ -6,7 +6,7 @@
 set(MY_DIR ${CMAKE_CURRENT_LIST_DIR})
 
 install(CODE "execute_process(
-  COMMAND ${DEPLOYQT} --no-compiler-runtime --no-system-d3d-compiler --no-quick-import -network \"\${CMAKE_INSTALL_PREFIX}/deskflow.exe\"
+  COMMAND ${DEPLOYQT} --no-system-d3d-compiler --no-quick-import -network \"\${CMAKE_INSTALL_PREFIX}/deskflow.exe\"
 )")
 
 # Setup OS_STRING
diff --git a/deploy/windows/wix-patch.xml.in b/deploy/windows/wix-patch.xml.in
index 55fd1e9b..6bc94f79 100644
--- a/deploy/windows/wix-patch.xml.in
+++ b/deploy/windows/wix-patch.xml.in
@@ -30,22 +30,50 @@
   <CPackWiXFragment Id="#PRODUCT">
     <Property Id="VC_REDIST_INSTALLED">
       <RegistrySearch
-        Id="FindVCRedist"
+        Id="Find_VCRedist_Installed"
         Root="HKLM"
         Key="SOFTWARE\Microsoft\VisualStudio\14.0\VC\Runtimes\x64"
         Name="Installed"
         Type="raw" />
     </Property>
 
+    <Property Id="VC_REDIST_VERSION_MINOR">
+      <RegistrySearch
+        Id="Find_VCRedist_Version_Minor"
+        Root="HKLM"
+        Key="SOFTWARE\Microsoft\VisualStudio\@[email protected]\VC\Runtimes\x64"
+        Name="Minor"
+        Type="raw" />
+    </Property>
+
     <CustomAction Id="Run_Deskflow" ExeCommand="Deskflow" FileRef="CM_FP_deskflow.exe" Return="asyncNoWait"/>
-    
+
     <CustomAction
-      Id="ShowVCRedistError"
-      Error="Latest Microsoft Visual C++ Redistributable is required. Please install it before proceeding."/>
+      Id="Show_VCRedist_Error"
+      Error="Microsoft Visual C++ Redistributable v@REQUIRED_MSVC_RUNTIME_MAJOR@.@REQUIRED_MSVC_RUNTIME_MINOR@ is required. The installer will now exit and install the Redistributable. Please restart the installation afterwards."/>
+
+    <CustomAction 
+      Id="Run_VCRedist"
+      ExeCommand=""
+      FileRef="CM_FP_vc_redist.x64.exe"
+      Execute="deferred"
+      Impersonate="no"
+      Return="check"
+    />
 
     <InstallExecuteSequence>
-      <Custom Action="ShowVCRedistError" Before="InstallServices" Condition="NOT Installed AND NOT VC_REDIST_INSTALLED"/>
-      <Custom Action="Run_Deskflow" OnExit="success" Condition="NOT Installed"/>
+      <Custom
+        Action="Show_VCRedist_Error"
+        Before="InstallServices"
+        Condition="NOT Installed AND (NOT VC_REDIST_INSTALLED OR VC_REDIST_VERSION_MINOR &lt; @REQUIRED_MSVC_RUNTIME_MINOR@)"/>
+      <Custom
+        Action="Run_VCRedist"
+        OnExit="error"
+        Condition="NOT Installed AND (NOT VC_REDIST_INSTALLED OR VC_REDIST_VERSION_MINOR &lt; @REQUIRED_MSVC_RUNTIME_MINOR@)"/>
+      <Custom
+        Action="Run_Deskflow"
+        OnExit="success"
+        Condition="NOT Installed"/>
     </InstallExecuteSequence>
   </CPackWiXFragment>
 </CPackWiXPatch>
diff --git a/src/lib/arch/win32/ArchMiscWindows.cpp b/src/lib/arch/win32/ArchMiscWindows.cpp
index 7f149496..15524304 100644
--- a/src/lib/arch/win32/ArchMiscWindows.cpp
+++ b/src/lib/arch/win32/ArchMiscWindows.cpp
@@ -38,8 +38,8 @@
 // See table of the compiler versions and the matching runtime DLL versions:
 // https://dev.to/yumetodo/list-of-mscver-and-mscfullver-8nd
 #if _MSC_VER >= 1942 // Visual Studio 2022 Update 12 (v17.12.4)
-const auto kRequiredMajor = 14;
-const auto kRequiredMinor = 42;
+const auto kRequiredMajor = kWindowsRuntimeMajor;
+const auto kRequiredMinor = kWindowsRuntimeMinor;
 #elif _MSC_VER >= 1920 // Visual Studio 2019 Update 7 (v16.7)
 const auto kRequiredMajor = 14;
 const auto kRequiredMinor = 27;
diff --git a/src/lib/common/constants.h.in b/src/lib/common/constants.h.in
index ba762c44..5d6b2430 100644
--- a/src/lib/common/constants.h.in
+++ b/src/lib/common/constants.h.in
@@ -7,6 +7,8 @@
 
 #pragma once
 
+// clang-format off
+
 const auto kAppName = "@CMAKE_PROJECT_PROPER_NAME@";
 const auto kAppId = "@CMAKE_PROJECT_NAME@";
 const auto kAppDescription = "@CMAKE_PROJECT_DESCRIPTION@";
@@ -17,6 +19,8 @@ const auto kDaemonBinName = "@CMAKE_PROJECT_NAME@-daemon";
 const auto kDaemonIpcName = "@CMAKE_PROJECT_NAME@-daemon";
 const auto kDaemonLogFilename = "@[email protected]";
 const auto kWindowsRegistryKey = "SOFTWARE\\@CMAKE_PROJECT_PROPER_NAME@";
+const auto kWindowsRuntimeMajor = @REQUIRED_MSVC_RUNTIME_MAJOR@;
+const auto kWindowsRuntimeMinor = @REQUIRED_MSVC_RUNTIME_MINOR@;
 
 const auto kCopyright = //
     "Copyright @CMAKE_PROJECT_COPYRIGHT@\n"
@@ -36,3 +40,5 @@ const auto kCertificateFilename = "@[email protected]";
 const auto kFingerprintLocalFilename = "local-fingerprint";
 const auto kFingerprintTrustedServersFilename = "trusted-servers";
 const auto kFingerprintTrustedClientsFilename = "trusted-clients";
+
+// clang-format on

@nbolton
nbolton requested a review from sithlord48 March 7, 2025 16:12
@nbolton
nbolton merged commit 80606ef into master Mar 7, 2025
@nbolton
nbolton deleted the fix8326 branch March 7, 2025 16:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Show friendly message during install when MSVC redist not installed

2 participants