external/onlineupdate/Library_install_updateservice.mk |    1 
 external/onlineupdate/install_updateservice.cxx        |   18 +++++++++++++++++
 2 files changed, 19 insertions(+)

New commits:
commit 5b2674b278fd48700409079803fbaf7ea177be61
Author:     Stephan Bergmann <[email protected]>
AuthorDate: Tue Dec 17 16:56:15 2024 +0100
Commit:     Stephan Bergmann <[email protected]>
CommitDate: Wed Dec 18 09:46:07 2024 +0100

    tdf#164225: Only install MAR update_service when it will be needed
    
    ...where "will be needed" is approximated by "install location is under
    C:\Program Files" (i.e., where admin privileges will be necessary to do an
    update)
    
    Change-Id: I00c93df8c0c2c5132fffa4056b88af098cb4a644
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/178679
    Reviewed-by: Stephan Bergmann <[email protected]>
    Tested-by: Jenkins

diff --git a/external/onlineupdate/Library_install_updateservice.mk 
b/external/onlineupdate/Library_install_updateservice.mk
index 86d6101abe44..c284f322d7ea 100644
--- a/external/onlineupdate/Library_install_updateservice.mk
+++ b/external/onlineupdate/Library_install_updateservice.mk
@@ -47,6 +47,7 @@ $(eval $(call 
gb_Library_use_system_win32_libs,install_updateservice, \
     kernel32 \
     user32 \
     advapi32 \
+    ole32 \
     shell32 \
     shlwapi \
 ))
diff --git a/external/onlineupdate/install_updateservice.cxx 
b/external/onlineupdate/install_updateservice.cxx
index c1d547156098..47c90bc148d6 100644
--- a/external/onlineupdate/install_updateservice.cxx
+++ b/external/onlineupdate/install_updateservice.cxx
@@ -18,6 +18,7 @@
 #define WIN32_LEAN_AND_MEAN
 #include <windows.h>
 #include <msiquery.h>
+#include <shlobj.h>
 
 #include <pathhash.h>
 
@@ -80,6 +81,23 @@ CloseHandleGuard guard(HANDLE handle) { return 
CloseHandleGuard(handle, CloseHan
 
 bool runExecutable(std::wstring const& installLocation, wchar_t const* 
argument)
 {
+    bool use = false;
+    PWSTR progPath;
+    if (SHGetKnownFolderPath(FOLDERID_ProgramFiles, 0, nullptr, &progPath) == 
S_OK)
+    {
+        auto const n = wcslen(progPath);
+        // For SHGetKnownFolderPath it is guaranteed that "The returned path 
does not include a
+        // trailing backslash":
+        use = (installLocation.size() == n
+               || (installLocation.size() > n && installLocation[n] == L'\'))
+              && _wcsnicmp(progPath, installLocation.data(), n) == 0;
+    }
+    CoTaskMemFree(progPath);
+    if (!use)
+    {
+        return true;
+    }
+
     std::wstring cmdline(L"\"");
     cmdline += installLocation;
     cmdline += L"\program\update_service.exe\" ";

Reply via email to