[Libreoffice-commits] core.git: 2 commits - desktop/Library_sofficeapp.mk desktop/source

Markus Mohrhard markus.mohrhard at googlemail.com
Sun Aug 13 15:56:42 UTC 2017


 desktop/Library_sofficeapp.mk  |    7 +++
 desktop/source/app/app.cxx     |    4 +-
 desktop/source/app/updater.cxx |   73 ++++++++++++++++++++++++++++-------------
 desktop/source/app/updater.hxx |    2 -
 4 files changed, 62 insertions(+), 24 deletions(-)

New commits:
commit 1e7b9c6826f07b724b433e978b0f580460168752
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Wed Aug 9 15:41:03 2017 +0200

    updater: make sure we pass the correct path for the updater executable on win
    
    Change-Id: Ia7655317582b891e109f3b310498264cc59a3924
    Reviewed-on: https://gerrit.libreoffice.org/40923
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Markus Mohrhard <markus.mohrhard at googlemail.com>

diff --git a/desktop/source/app/updater.cxx b/desktop/source/app/updater.cxx
index 1ee55fcf3944..6c0206059a6a 100644
--- a/desktop/source/app/updater.cxx
+++ b/desktop/source/app/updater.cxx
@@ -275,33 +275,35 @@ bool update()
     CopyUpdaterToTempDir(Updater::getExecutableDirURL(), aTempDirURL);
 
     OUString aTempDirPath = getPathFromURL(aTempDirURL);
-    OString aPath = OUStringToOString(aTempDirPath + "/" + OUString::fromUtf8(pUpdaterName), RTL_TEXTENCODING_UTF8);
+    OUString aUpdaterPath = aTempDirPath + "/" + OUString::fromUtf8(pUpdaterName);
 
     Updater::log("Calling the updater with parameters: ");
     CharT** pArgs = createCommandLine();
 
     bool bSuccess = true;
-#if UNX
     const char* pUpdaterTestReplace = std::getenv("LIBO_UPDATER_TEST_REPLACE");
     if (!pUpdaterTestReplace)
     {
+#if UNX
+        OString aPath = OUStringToOString(aUpdaterPath, RTL_TEXTENCODING_UTF8);
         if (execv(aPath.getStr(), pArgs))
         {
             printf("execv failed with error %d %s\n",errno,strerror(errno));
             bSuccess = false;
         }
+#elif _WIN32
+        bSuccess = WinLaunchChild((wchar_t*)aUpdaterPath.getStr(), 8, pArgs);
+#endif
     }
     else
     {
+        SAL_WARN("updater", "Executable Path:" << aUpdaterPath);
         for (size_t i = 0; i < 8 + rtl_getAppCommandArgCount(); ++i)
         {
             SAL_WARN("desktop.updater", pArgs[i]);
         }
         bSuccess = false;
     }
-#elif _WIN32
-    bSuccess = WinLaunchChild(nullptr, 8, pArgs);
-#endif
 
     for (size_t i = 0; i < 8 + rtl_getAppCommandArgCount(); ++i)
     {
commit 25ac5330e84b5e8c55cd81c7fd0c84c8aa889d47
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Wed Aug 9 15:36:03 2017 +0200

    updater: call the updater executable on windows
    
    Change-Id: Ibbcfea2e42bc55cf5c018bfb1856be7f1981f57d
    Reviewed-on: https://gerrit.libreoffice.org/40922
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Markus Mohrhard <markus.mohrhard at googlemail.com>

diff --git a/desktop/Library_sofficeapp.mk b/desktop/Library_sofficeapp.mk
index 1c88d4e1a421..53496f2c1544 100644
--- a/desktop/Library_sofficeapp.mk
+++ b/desktop/Library_sofficeapp.mk
@@ -80,6 +80,13 @@ $(eval $(call gb_Library_use_libraries,sofficeapp,\
     vcl \
 ))
 
+ifeq ($(OS),WNT)
+$(eval $(call gb_Library_use_static_libraries,sofficeapp,\
+    $(if $(ENABLE_ONLINE_UPDATE_MAR),\
+        windows_process )\
+))
+endif
+
 ifeq ($(OS),MACOSX)
 
 $(eval $(call gb_Library_add_cxxflags,sofficeapp,\
diff --git a/desktop/source/app/app.cxx b/desktop/source/app/app.cxx
index fe89eeb3b628..cc5e59dcda9b 100644
--- a/desktop/source/app/app.cxx
+++ b/desktop/source/app/app.cxx
@@ -1442,7 +1442,9 @@ int Desktop::Main()
                 xFlushable->flush();
                 // avoid the old oosplash staying around
                 CloseSplashScreen();
-                update();
+                bool bSuccess = update();
+                if (bSuccess)
+                    return EXIT_SUCCESS;
             }
             else if (isTimeForUpdateCheck())
             {
diff --git a/desktop/source/app/updater.cxx b/desktop/source/app/updater.cxx
index f855a15672a0..1ee55fcf3944 100644
--- a/desktop/source/app/updater.cxx
+++ b/desktop/source/app/updater.cxx
@@ -15,6 +15,10 @@
 
 #endif
 
+#ifdef _WIN32
+#include <comphelper/windowsStart.hxx>
+#endif
+
 #include <fstream>
 #include <config_folders.h>
 #include <rtl/bootstrap.hxx>
@@ -116,33 +120,41 @@ void CopyUpdaterToTempDir(const OUString& rInstallDirURL, const OUString& rTempD
     CopyFileToDir(rTempDirURL, aUpdaterName, rInstallDirURL);
 }
 
-void createStr(const char* pSrc, char** pArgs, size_t i)
-{
-    size_t nLength = std::strlen(pSrc);
-    char* pFinalStr = new char[nLength + 1];
-    std::strncpy(pFinalStr, pSrc, nLength);
-    pFinalStr[nLength] = '\0';
-    pArgs[i] = pFinalStr;
-}
+#ifdef UNX
+typedef char CharT;
+#define tstrncpy std::strncpy
+#elif _WIN32
+typedef wchar_t CharT;
+#define tstrncpy std::wcsncpy
+#else
+#error "Need an implementation"
+#endif
 
-void createStr(const OUString& rStr, char** pArgs, size_t i)
+void createStr(const OUString& rStr, CharT** pArgs, size_t i)
 {
+#ifdef UNX
     OString aStr = OUStringToOString(rStr, RTL_TEXTENCODING_UTF8);
-    char* pStr = new char[aStr.getLength() + 1];
-    std::strncpy(pStr, aStr.getStr(), aStr.getLength());
+#elif _WIN32
+    OUString aStr = rStr;
+#else
+#error "Need an implementation"
+#endif
+    CharT* pStr = new CharT[aStr.getLength() + 1];
+    tstrncpy(pStr, (CharT*)aStr.getStr(), aStr.getLength());
     pStr[aStr.getLength()] = '\0';
     pArgs[i] = pStr;
 }
 
-char** createCommandLine()
+CharT** createCommandLine()
 {
     OUString aInstallDir = Updater::getInstallationPath();
 
     size_t nCommandLineArgs = rtl_getAppCommandArgCount();
     size_t nArgs = 8 + nCommandLineArgs;
-    char** pArgs = new char*[nArgs];
+    CharT** pArgs = new CharT*[nArgs];
     {
-        createStr(pUpdaterName, pArgs, 0);
+        OUString aUpdaterName = OUString::fromUtf8(pUpdaterName);
+        createStr(aUpdaterName, pArgs, 0);
     }
     {
         // directory with the patch log
@@ -163,8 +175,17 @@ char** createCommandLine()
         createStr(aInstallDir, pArgs, 3);
     }
     {
-        const char* pPID = "0";
-        createStr(pPID, pArgs, 4);
+#ifdef UNX
+        OUString aPID("0");
+#elif _WIN32
+        oslProcessInfo aInfo;
+        aInfo.Size = sizeof(oslProcessInfo);
+        osl_getProcessInfo(nullptr, osl_Process_IDENTIFIER, &aInfo);
+        OUString aPID = OUString::number(aInfo.Ident);
+#else
+#error "Need an implementation"
+#endif
+        createStr(aPID, pArgs, 4);
     }
     {
         OUString aExeDir = Updater::getExecutableDirURL();
@@ -247,7 +268,7 @@ bool isUserWritable(const OUString& rFileURL)
 
 }
 
-void update()
+bool update()
 {
     utl::TempFile aTempDir(nullptr, true);
     OUString aTempDirURL = aTempDir.GetURL();
@@ -257,9 +278,9 @@ void update()
     OString aPath = OUStringToOString(aTempDirPath + "/" + OUString::fromUtf8(pUpdaterName), RTL_TEXTENCODING_UTF8);
 
     Updater::log("Calling the updater with parameters: ");
-    char** pArgs = createCommandLine();
-
+    CharT** pArgs = createCommandLine();
 
+    bool bSuccess = true;
 #if UNX
     const char* pUpdaterTestReplace = std::getenv("LIBO_UPDATER_TEST_REPLACE");
     if (!pUpdaterTestReplace)
@@ -267,6 +288,7 @@ void update()
         if (execv(aPath.getStr(), pArgs))
         {
             printf("execv failed with error %d %s\n",errno,strerror(errno));
+            bSuccess = false;
         }
     }
     else
@@ -275,7 +297,10 @@ void update()
         {
             SAL_WARN("desktop.updater", pArgs[i]);
         }
+        bSuccess = false;
     }
+#elif _WIN32
+    bSuccess = WinLaunchChild(nullptr, 8, pArgs);
 #endif
 
     for (size_t i = 0; i < 8 + rtl_getAppCommandArgCount(); ++i)
@@ -283,6 +308,8 @@ void update()
         delete[] pArgs[i];
     }
     delete[] pArgs;
+
+    return bSuccess;
 }
 
 namespace {
diff --git a/desktop/source/app/updater.hxx b/desktop/source/app/updater.hxx
index 4c01129f9697..937728dd70bc 100644
--- a/desktop/source/app/updater.hxx
+++ b/desktop/source/app/updater.hxx
@@ -12,7 +12,7 @@
 
 #include <rtl/ustring.hxx>
 
-void update();
+bool update();
 
 void update_checker();
 


More information about the Libreoffice-commits mailing list