summaryrefslogtreecommitdiff
path: root/desktop/source/app/updater.cxx
diff options
context:
space:
mode:
authorMarkus Mohrhard <markus.mohrhard@googlemail.com>2017-08-09 15:36:03 +0200
committerMarkus Mohrhard <markus.mohrhard@googlemail.com>2017-08-13 17:55:25 +0200
commit25ac5330e84b5e8c55cd81c7fd0c84c8aa889d47 (patch)
tree7898f8d38db899542a4cf18c3dc5d042c479aa47 /desktop/source/app/updater.cxx
parent596f866ee9e3acee114d3b4638df3f9000d93cc7 (diff)
updater: call the updater executable on windows
Change-Id: Ibbcfea2e42bc55cf5c018bfb1856be7f1981f57d Reviewed-on: https://gerrit.libreoffice.org/40922 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Markus Mohrhard <markus.mohrhard@googlemail.com>
Diffstat (limited to 'desktop/source/app/updater.cxx')
-rw-r--r--desktop/source/app/updater.cxx65
1 files changed, 46 insertions, 19 deletions
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 {