nss: upgrade to release 3.73
[LibreOffice.git] / desktop / source / app / updater.cxx
blob2748373e5f623012b16ae3c25b43b0c9af09fcc0
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #include "updater.hxx"
12 #if UNX
13 #include <unistd.h>
14 #include <errno.h>
16 #endif
18 #ifdef _WIN32
19 #include <comphelper/windowsStart.hxx>
20 #endif
22 #include <fstream>
23 #include <config_folders.h>
24 #include <rtl/bootstrap.hxx>
26 #include <officecfg/Office/Update.hxx>
28 #include <rtl/ustring.hxx>
29 #include <unotools/tempfile.hxx>
30 #include <unotools/configmgr.hxx>
31 #include <osl/file.hxx>
32 #include <rtl/process.h>
33 #include <sal/log.hxx>
35 #include <curl/curl.h>
37 #include <orcus/json_document_tree.hpp>
38 #include <orcus/config.hpp>
39 #include <orcus/pstring.hpp>
40 #include <comphelper/hash.hxx>
42 #include <com/sun/star/container/XNameAccess.hpp>
44 #include <officecfg/Setup.hxx>
46 #include <functional>
47 #include <memory>
48 #include <set>
50 namespace {
52 class error_updater : public std::exception
54 OString maStr;
55 public:
57 error_updater(const OString& rStr):
58 maStr(rStr)
62 virtual const char* what() const throw() override
64 return maStr.getStr();
68 #ifdef UNX
69 static const char kUserAgent[] = "LibreOffice UpdateChecker/1.0 (Linux)";
70 #else
71 static const char kUserAgent[] = "LibreOffice UpdateChecker/1.0 (unknown platform)";
72 #endif
74 #ifdef UNX
75 const char* const pUpdaterName = "updater";
76 const char* const pSofficeExeName = "soffice";
77 #elif defined(_WIN32)
78 const char* pUpdaterName = "updater.exe";
79 const char* pSofficeExeName = "soffice.exe";
80 #else
81 #error "Need implementation"
82 #endif
84 OUString normalizePath(const OUString& rPath)
86 OUString aPath = rPath.replaceAll("//", "/");
88 // remove final /
89 if (aPath.endsWith("/"))
91 aPath = aPath.copy(0, aPath.getLength() - 1);
94 while (aPath.indexOf("/..") != -1)
96 sal_Int32 nIndex = aPath.indexOf("/..");
97 sal_Int32 i = nIndex - 1;
98 for (; i > 0; --i)
100 if (aPath[i] == '/')
101 break;
104 OUString aTempPath = aPath;
105 aPath = aTempPath.copy(0, i) + aPath.copy(nIndex + 3);
108 return aPath.replaceAll("\\", "/");
111 void CopyFileToDir(const OUString& rTempDirURL, const OUString & rFileName, const OUString& rOldDir)
113 OUString aSourceURL = rOldDir + "/" + rFileName;
114 OUString aDestURL = rTempDirURL + "/" + rFileName;
116 osl::File::RC eError = osl::File::copy(aSourceURL, aDestURL);
117 if (eError != osl::File::E_None)
119 SAL_WARN("desktop.updater", "could not copy the file to a temp directory: " << rFileName);
120 throw std::exception();
124 OUString getPathFromURL(const OUString& rURL)
126 OUString aPath;
127 osl::FileBase::getSystemPathFromFileURL(rURL, aPath);
129 return normalizePath(aPath);
132 void CopyUpdaterToTempDir(const OUString& rInstallDirURL, const OUString& rTempDirURL)
134 OUString aUpdaterName = OUString::fromUtf8(pUpdaterName);
135 CopyFileToDir(rTempDirURL, aUpdaterName, rInstallDirURL);
138 #ifdef UNX
139 typedef char CharT;
140 #define tstrncpy std::strncpy
141 #elif defined(_WIN32)
142 typedef wchar_t CharT;
143 #define tstrncpy std::wcsncpy
144 #else
145 #error "Need an implementation"
146 #endif
148 void createStr(const OUString& rStr, CharT** pArgs, size_t i)
150 #ifdef UNX
151 OString aStr = OUStringToOString(rStr, RTL_TEXTENCODING_UTF8);
152 #elif defined(_WIN32)
153 OUString aStr = rStr;
154 #else
155 #error "Need an implementation"
156 #endif
157 CharT* pStr = new CharT[aStr.getLength() + 1];
158 tstrncpy(pStr, (CharT*)aStr.getStr(), aStr.getLength());
159 pStr[aStr.getLength()] = '\0';
160 pArgs[i] = pStr;
163 CharT** createCommandLine()
165 OUString aInstallDir = Updater::getInstallationPath();
167 size_t nCommandLineArgs = rtl_getAppCommandArgCount();
168 size_t nArgs = 8 + nCommandLineArgs;
169 CharT** pArgs = new CharT*[nArgs];
171 OUString aUpdaterName = OUString::fromUtf8(pUpdaterName);
172 createStr(aUpdaterName, pArgs, 0);
175 // directory with the patch log
176 OUString aPatchDir = Updater::getPatchDirURL();
177 rtl::Bootstrap::expandMacros(aPatchDir);
178 OUString aTempDirPath = getPathFromURL(aPatchDir);
179 Updater::log("Patch Dir: " + aTempDirPath);
180 createStr(aTempDirPath, pArgs, 1);
183 // the actual update directory
184 Updater::log("Install Dir: " + aInstallDir);
185 createStr(aInstallDir, pArgs, 2);
188 // the temporary updated build
189 Updater::log("Working Dir: " + aInstallDir);
190 createStr(aInstallDir, pArgs, 3);
193 #ifdef UNX
194 OUString aPID("0");
195 #elif defined(_WIN32)
196 oslProcessInfo aInfo;
197 aInfo.Size = sizeof(oslProcessInfo);
198 osl_getProcessInfo(nullptr, osl_Process_IDENTIFIER, &aInfo);
199 OUString aPID = OUString::number(aInfo.Ident);
200 #else
201 #error "Need an implementation"
202 #endif
203 createStr(aPID, pArgs, 4);
206 OUString aExeDir = Updater::getExecutableDirURL();
207 OUString aSofficePath = getPathFromURL(aExeDir);
208 Updater::log("soffice Path: " + aSofficePath);
209 createStr(aSofficePath, pArgs, 5);
212 // the executable to start after the successful update
213 OUString aExeDir = Updater::getExecutableDirURL();
214 OUString aSofficePathURL = aExeDir + OUString::fromUtf8(pSofficeExeName);
215 OUString aSofficePath = getPathFromURL(aSofficePathURL);
216 createStr(aSofficePath, pArgs, 6);
219 // add the command line arguments from the soffice list
220 for (size_t i = 0; i < nCommandLineArgs; ++i)
222 OUString aCommandLineArg;
223 rtl_getAppCommandArg(i, &aCommandLineArg.pData);
224 createStr(aCommandLineArg, pArgs, 7 + i);
227 pArgs[nArgs - 1] = nullptr;
229 return pArgs;
232 struct update_file
234 OUString aURL;
235 OUString aHash;
236 size_t nSize;
239 struct language_file
241 update_file aUpdateFile;
242 OUString aLangCode;
245 struct update_info
247 OUString aFromBuildID;
248 OUString aSeeAlsoURL;
249 OUString aMessage;
251 update_file aUpdateFile;
252 std::vector<language_file> aLanguageFiles;
255 bool isUserWritable(const OUString& rFileURL)
257 osl::FileStatus aStatus(osl_FileStatus_Mask_Attributes);
258 osl::DirectoryItem aDirectoryItem;
260 osl::FileBase::RC eRes = osl::DirectoryItem::get(rFileURL, aDirectoryItem);
261 if (eRes != osl::FileBase::E_None)
263 Updater::log("Could not get the directory item for: " + rFileURL);
264 return false;
267 osl::FileBase::RC eResult = aDirectoryItem.getFileStatus(aStatus);
268 if (eResult != osl::FileBase::E_None)
270 Updater::log("Could not get the file status for: " + rFileURL);
271 return false;
274 bool bReadOnly = (aStatus.getAttributes() & static_cast<sal_uInt64>(osl_File_Attribute_ReadOnly)) != 0;
275 if (bReadOnly)
277 Updater::log("Update location as determined by: " + rFileURL + " is read-only.");
278 return false;
281 return true;
286 bool update()
288 utl::TempFile aTempDir(nullptr, true);
289 OUString aTempDirURL = aTempDir.GetURL();
290 CopyUpdaterToTempDir(Updater::getExecutableDirURL(), aTempDirURL);
292 OUString aUpdaterPath = getPathFromURL(aTempDirURL + "/" + OUString::fromUtf8(pUpdaterName));
294 Updater::log("Calling the updater with parameters: ");
295 CharT** pArgs = createCommandLine();
297 bool bSuccess = true;
298 const char* pUpdaterTestReplace = std::getenv("LIBO_UPDATER_TEST_REPLACE");
299 if (!pUpdaterTestReplace)
301 #if UNX
302 OString aPath = OUStringToOString(aUpdaterPath, RTL_TEXTENCODING_UTF8);
303 if (execv(aPath.getStr(), pArgs))
305 printf("execv failed with error %d %s\n",errno,strerror(errno));
306 bSuccess = false;
308 #elif defined(_WIN32)
309 bSuccess = WinLaunchChild((wchar_t*)aUpdaterPath.getStr(), 8, pArgs);
310 #endif
312 else
314 SAL_WARN("desktop.updater", "Updater executable path: " << aUpdaterPath);
315 for (size_t i = 0; i < 8 + rtl_getAppCommandArgCount(); ++i)
317 SAL_WARN("desktop.updater", pArgs[i]);
319 bSuccess = false;
322 for (size_t i = 0; i < 8 + rtl_getAppCommandArgCount(); ++i)
324 delete[] pArgs[i];
326 delete[] pArgs;
328 return bSuccess;
331 namespace {
333 // Callback to get the response data from server.
334 size_t WriteCallback(void *ptr, size_t size,
335 size_t nmemb, void *userp)
337 if (!userp)
338 return 0;
340 std::string* response = static_cast<std::string *>(userp);
341 size_t real_size = size * nmemb;
342 response->append(static_cast<char *>(ptr), real_size);
343 return real_size;
348 class invalid_update_info : public std::exception
352 class invalid_hash : public std::exception
354 OString maMessage;
355 public:
357 invalid_hash(const OUString& rExpectedHash, const OUString& rReceivedHash)
358 : maMessage(
359 OUStringToOString(
360 OUString("Invalid hash found.\nExpected: " + rExpectedHash + ";\nReceived: " + rReceivedHash),
361 RTL_TEXTENCODING_UTF8)
366 const char* what() const noexcept override
368 return maMessage.getStr();
372 class invalid_size : public std::exception
374 OString maMessage;
375 public:
377 invalid_size(const size_t nExpectedSize, const size_t nReceivedSize)
378 : maMessage(
379 OUStringToOString(
380 OUString("Invalid file size found.\nExpected: " + OUString::number(nExpectedSize) + ";\nReceived: " + OUString::number(nReceivedSize)),
381 RTL_TEXTENCODING_UTF8)
386 const char* what() const noexcept override
388 return maMessage.getStr();
392 OUString toOUString(const std::string& rStr)
394 return OUString::fromUtf8(rStr.c_str());
397 update_file parse_update_file(orcus::json::node& rNode)
399 if (rNode.type() != orcus::json::node_t::object)
401 SAL_WARN("desktop.updater", "invalid update or language file entry");
402 throw invalid_update_info();
405 if (rNode.child_count() < 4)
407 SAL_WARN("desktop.updater", "invalid update or language file entry");
408 throw invalid_update_info();
411 orcus::json::node aURLNode = rNode.child("url");
412 orcus::json::node aHashNode = rNode.child("hash");
413 orcus::json::node aHashTypeNode = rNode.child("hash_function");
414 orcus::json::node aSizeNode = rNode.child("size");
416 if (aHashTypeNode.string_value() != "sha512")
418 SAL_WARN("desktop.updater", "invalid hash type");
419 throw invalid_update_info();
422 update_file aUpdateFile;
423 aUpdateFile.aURL = toOUString(aURLNode.string_value().str());
425 if (aUpdateFile.aURL.isEmpty())
426 throw invalid_update_info();
428 aUpdateFile.aHash = toOUString(aHashNode.string_value().str());
429 aUpdateFile.nSize = static_cast<sal_uInt32>(aSizeNode.numeric_value());
430 return aUpdateFile;
433 update_info parse_response(const std::string& rResponse)
435 orcus::json::document_tree aJsonDoc;
436 orcus::json_config aConfig;
437 aJsonDoc.load(rResponse, aConfig);
439 auto aDocumentRoot = aJsonDoc.get_document_root();
440 if (aDocumentRoot.type() != orcus::json::node_t::object)
442 SAL_WARN("desktop.updater", "invalid root entries: " << rResponse);
443 throw invalid_update_info();
446 auto aRootKeys = aDocumentRoot.keys();
447 if (std::find(aRootKeys.begin(), aRootKeys.end(), "error") != aRootKeys.end())
449 throw invalid_update_info();
451 else if (std::find(aRootKeys.begin(), aRootKeys.end(), "response") != aRootKeys.end())
453 update_info aUpdateInfo;
454 auto aMsgNode = aDocumentRoot.child("response");
455 aUpdateInfo.aMessage = toOUString(aMsgNode.string_value().str());
456 return aUpdateInfo;
459 orcus::json::node aFromNode = aDocumentRoot.child("from");
460 if (aFromNode.type() != orcus::json::node_t::string)
462 throw invalid_update_info();
465 orcus::json::node aSeeAlsoNode = aDocumentRoot.child("see also");
466 if (aSeeAlsoNode.type() != orcus::json::node_t::string)
468 throw invalid_update_info();
471 orcus::json::node aUpdateNode = aDocumentRoot.child("update");
472 if (aUpdateNode.type() != orcus::json::node_t::object)
474 throw invalid_update_info();
477 orcus::json::node aLanguageNode = aDocumentRoot.child("languages");
478 if (aUpdateNode.type() != orcus::json::node_t::object)
480 throw invalid_update_info();
483 update_info aUpdateInfo;
484 aUpdateInfo.aFromBuildID = toOUString(aFromNode.string_value().str());
485 aUpdateInfo.aSeeAlsoURL = toOUString(aSeeAlsoNode.string_value().str());
487 aUpdateInfo.aUpdateFile = parse_update_file(aUpdateNode);
489 std::vector<orcus::pstring> aLanguages = aLanguageNode.keys();
490 for (auto const& language : aLanguages)
492 language_file aLanguageFile;
493 auto aLangEntry = aLanguageNode.child(language);
494 aLanguageFile.aLangCode = toOUString(language.str());
495 aLanguageFile.aUpdateFile = parse_update_file(aLangEntry);
496 aUpdateInfo.aLanguageFiles.push_back(aLanguageFile);
499 return aUpdateInfo;
502 struct WriteDataFile
504 comphelper::Hash maHash;
505 SvStream* mpStream;
507 WriteDataFile(SvStream* pStream):
508 maHash(comphelper::HashType::SHA512),
509 mpStream(pStream)
513 OUString getHash()
515 auto final_hash = maHash.finalize();
516 std::stringstream aStrm;
517 for (auto& i: final_hash)
519 aStrm << std::setw(2) << std::setfill('0') << std::hex << (int)i;
522 return toOUString(aStrm.str());
526 // Callback to get the response data from server to a file.
527 size_t WriteCallbackFile(void *ptr, size_t size,
528 size_t nmemb, void *userp)
530 if (!userp)
531 return 0;
533 WriteDataFile* response = static_cast<WriteDataFile *>(userp);
534 size_t real_size = size * nmemb;
535 response->mpStream->WriteBytes(ptr, real_size);
536 response->maHash.update(static_cast<const unsigned char*>(ptr), real_size);
537 return real_size;
540 std::string download_content(const OString& rURL, bool bFile, OUString& rHash)
542 Updater::log("Download: " + rURL);
543 std::unique_ptr<CURL, std::function<void(CURL *)>> curl(
544 curl_easy_init(), [](CURL * p) { curl_easy_cleanup(p); });
546 if (!curl)
547 return std::string();
549 curl_easy_setopt(curl.get(), CURLOPT_URL, rURL.getStr());
550 curl_easy_setopt(curl.get(), CURLOPT_USERAGENT, kUserAgent);
551 bool bUseProxy = false;
552 if (bUseProxy)
555 curl_easy_setopt(curl, CURLOPT_PROXY, proxy.c_str());
556 curl_easy_setopt(curl, CURLOPT_PROXYUSERPWD, proxy_user_pwd.c_str());
560 char buf[] = "Expect:";
561 curl_slist* headerlist = nullptr;
562 headerlist = curl_slist_append(headerlist, buf);
563 curl_easy_setopt(curl.get(), CURLOPT_HTTPHEADER, headerlist);
564 curl_easy_setopt(curl.get(), CURLOPT_FOLLOWLOCATION, 1); // follow redirects
565 // only allow redirect to http:// and https://
566 curl_easy_setopt(curl.get(), CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS);
568 std::string response_body;
569 utl::TempFile aTempFile;
570 WriteDataFile aFile(aTempFile.GetStream(StreamMode::WRITE));
571 if (!bFile)
573 curl_easy_setopt(curl.get(), CURLOPT_WRITEFUNCTION, WriteCallback);
574 curl_easy_setopt(curl.get(), CURLOPT_WRITEDATA,
575 static_cast<void *>(&response_body));
577 aTempFile.EnableKillingFile(true);
579 else
581 OUString aTempFileURL = aTempFile.GetURL();
582 OString aTempFileURLOString = OUStringToOString(aTempFileURL, RTL_TEXTENCODING_UTF8);
583 response_body.append(aTempFileURLOString.getStr(), aTempFileURLOString.getLength());
585 aTempFile.EnableKillingFile(false);
587 curl_easy_setopt(curl.get(), CURLOPT_WRITEFUNCTION, WriteCallbackFile);
588 curl_easy_setopt(curl.get(), CURLOPT_WRITEDATA,
589 static_cast<void *>(&aFile));
592 // Fail if 400+ is returned from the web server.
593 curl_easy_setopt(curl.get(), CURLOPT_FAILONERROR, 1);
595 CURLcode cc = curl_easy_perform(curl.get());
596 long http_code = 0;
597 curl_easy_getinfo(curl.get(), CURLINFO_RESPONSE_CODE, &http_code);
598 if (http_code != 200)
600 SAL_WARN("desktop.updater", "download did not succeed. Error code: " << http_code);
601 throw error_updater("download did not succeed");
604 if (cc != CURLE_OK)
606 SAL_WARN("desktop.updater", "curl error: " << cc);
607 throw error_updater("curl error");
610 if (bFile)
611 rHash = aFile.getHash();
613 return response_body;
616 void handle_file_error(osl::FileBase::RC eError, const OUString& rMsg)
618 switch (eError)
620 case osl::FileBase::E_None:
621 break;
622 default:
623 SAL_WARN("desktop.updater", "file error code: " << eError << ", " << rMsg);
624 throw error_updater(OUStringToOString(rMsg, RTL_TEXTENCODING_UTF8));
628 void download_file(const OUString& rURL, size_t nFileSize, const OUString& rHash, const OUString& aFileName)
630 Updater::log("Download File: " + rURL + "; FileName: " + aFileName);
631 OString aURL = OUStringToOString(rURL, RTL_TEXTENCODING_UTF8);
632 OUString aHash;
633 std::string temp_file = download_content(aURL, true, aHash);
634 if (temp_file.empty())
635 throw error_updater("empty temp file string");
637 OUString aTempFile = OUString::fromUtf8(temp_file.c_str());
638 Updater::log("TempFile: " + aTempFile);
639 osl::File aDownloadedFile(aTempFile);
640 osl::FileBase::RC eError = aDownloadedFile.open(1);
641 handle_file_error(eError, "Could not open the download file: " + aTempFile);
643 sal_uInt64 nSize = 0;
644 eError = aDownloadedFile.getSize(nSize);
645 handle_file_error(eError, "Could not get the file size of the downloaded file: " + aTempFile);
646 if (nSize != nFileSize)
648 SAL_WARN("desktop.updater", "File sizes don't match. File might be corrupted.");
649 throw invalid_size(nFileSize, nSize);
652 if (aHash != rHash)
654 SAL_WARN("desktop.updater", "File hash don't match. File might be corrupted.");
655 throw invalid_hash(rHash, aHash);
658 OUString aPatchDirURL("${$BRAND_BASE_DIR/" LIBO_ETC_FOLDER "/" SAL_CONFIGFILE("bootstrap") ":UserInstallation}/patch/");
659 rtl::Bootstrap::expandMacros(aPatchDirURL);
660 osl::Directory::create(aPatchDirURL);
662 OUString aDestFile = aPatchDirURL + aFileName;
663 Updater::log("Destination File: " + aDestFile);
664 aDownloadedFile.close();
665 eError = osl::File::move(aTempFile, aDestFile);
666 handle_file_error(eError, "Could not move the file from the Temp directory to the user config: TempFile: " + aTempFile + "; DestFile: " + aDestFile);
671 void update_checker()
673 OUString aBrandBaseDir("${BRAND_BASE_DIR}");
674 rtl::Bootstrap::expandMacros(aBrandBaseDir);
675 bool bUserWritable = isUserWritable(aBrandBaseDir);
676 if (!bUserWritable)
678 Updater::log("Can't update as the update location is not user writable");
679 return;
682 OUString aDownloadCheckBaseURL = officecfg::Office::Update::Update::URL::get();
683 static const char* pDownloadCheckBaseURLEnv = std::getenv("LIBO_UPDATER_URL");
684 if (pDownloadCheckBaseURLEnv)
686 aDownloadCheckBaseURL = OUString::createFromAscii(pDownloadCheckBaseURLEnv);
689 OUString aProductName = utl::ConfigManager::getProductName();
690 OUString aBuildID = Updater::getBuildID();
692 static const char* pBuildIdEnv = std::getenv("LIBO_UPDATER_BUILD");
693 if (pBuildIdEnv)
695 aBuildID = OUString::createFromAscii(pBuildIdEnv);
698 OUString aBuildTarget = "${_OS}_${_ARCH}";
699 rtl::Bootstrap::expandMacros(aBuildTarget);
700 OUString aChannel = Updater::getUpdateChannel();
701 static const char* pUpdateChannelEnv = std::getenv("LIBO_UPDATER_CHANNEL");
702 if (pUpdateChannelEnv)
704 aChannel = OUString::createFromAscii(pUpdateChannelEnv);
707 OUString aDownloadCheckURL = aDownloadCheckBaseURL + "update/check/1/" + aProductName +
708 "/" + aBuildID + "/" + aBuildTarget + "/" + aChannel;
709 OString aURL = OUStringToOString(aDownloadCheckURL, RTL_TEXTENCODING_UTF8);
710 Updater::log("Update check: " + aURL);
714 OUString aHash;
715 std::string response_body = download_content(aURL, false, aHash);
716 if (!response_body.empty())
719 update_info aUpdateInfo = parse_response(response_body);
720 if (aUpdateInfo.aUpdateFile.aURL.isEmpty())
722 // No update currently available
723 // add entry to updating.log with the message
724 SAL_WARN("desktop.updater", "Message received from the updater: " << aUpdateInfo.aMessage);
725 Updater::log("Server response: " + aUpdateInfo.aMessage);
727 else
729 css::uno::Sequence<OUString> aInstalledLanguages(officecfg::Setup::Office::InstalledLocales::get()->getElementNames());
730 std::set<OUString> aInstalledLanguageSet(std::begin(aInstalledLanguages), std::end(aInstalledLanguages));
731 download_file(aUpdateInfo.aUpdateFile.aURL, aUpdateInfo.aUpdateFile.nSize, aUpdateInfo.aUpdateFile.aHash, "update.mar");
732 for (auto& lang_update : aUpdateInfo.aLanguageFiles)
734 // only download the language packs for installed languages
735 if (aInstalledLanguageSet.find(lang_update.aLangCode) != aInstalledLanguageSet.end())
737 OUString aFileName = "update_" + lang_update.aLangCode + ".mar";
738 download_file(lang_update.aUpdateFile.aURL, lang_update.aUpdateFile.nSize, lang_update.aUpdateFile.aHash, aFileName);
741 OUString aSeeAlsoURL = aUpdateInfo.aSeeAlsoURL;
742 std::shared_ptr< comphelper::ConfigurationChanges > batch(
743 comphelper::ConfigurationChanges::create());
744 officecfg::Office::Update::Update::SeeAlso::set(aSeeAlsoURL, batch);
745 batch->commit();
749 catch (const invalid_update_info&)
751 SAL_WARN("desktop.updater", "invalid update information");
752 Updater::log(OString("warning: invalid update info"));
754 catch (const error_updater& e)
756 SAL_WARN("desktop.updater", "error during the update check: " << e.what());
757 Updater::log(OString("warning: error by the updater") + e.what());
759 catch (const invalid_size& e)
761 SAL_WARN("desktop.updater", e.what());
762 Updater::log(OString("warning: invalid size"));
764 catch (const invalid_hash& e)
766 SAL_WARN("desktop.updater", e.what());
767 Updater::log(OString("warning: invalid hash"));
769 catch (...)
771 SAL_WARN("desktop.updater", "unknown error during the update check");
772 Updater::log(OString("warning: unknown exception"));
776 OUString Updater::getUpdateInfoLog()
778 OUString aUpdateInfoURL("${$BRAND_BASE_DIR/" LIBO_ETC_FOLDER "/" SAL_CONFIGFILE("bootstrap") ":UserInstallation}/patch/updating.log");
779 rtl::Bootstrap::expandMacros(aUpdateInfoURL);
781 return aUpdateInfoURL;
784 OUString Updater::getPatchDirURL()
786 OUString aPatchDirURL("${$BRAND_BASE_DIR/" LIBO_ETC_FOLDER "/" SAL_CONFIGFILE("bootstrap") ":UserInstallation}/patch/");
787 rtl::Bootstrap::expandMacros(aPatchDirURL);
789 return aPatchDirURL;
792 OUString Updater::getUpdateFileURL()
794 return getPatchDirURL() + "update.mar";
797 OUString Updater::getInstallationPath()
799 OUString aInstallDir( "$BRAND_BASE_DIR/");
800 rtl::Bootstrap::expandMacros(aInstallDir);
802 return getPathFromURL(aInstallDir);
805 OUString Updater::getExecutableDirURL()
807 OUString aExeDir( "$BRAND_BASE_DIR/" LIBO_BIN_FOLDER "/" );
808 rtl::Bootstrap::expandMacros(aExeDir);
810 return aExeDir;
813 void Updater::log(const OUString& rMessage)
815 SAL_INFO("desktop.updater", rMessage);
816 OUString aUpdateLog = getUpdateInfoLog();
817 SvFileStream aLog(aUpdateLog, StreamMode::STD_READWRITE);
818 aLog.Seek(aLog.Tell() + aLog.remainingSize()); // make sure we are at the end
819 aLog.WriteLine(OUStringToOString(rMessage, RTL_TEXTENCODING_UTF8));
822 void Updater::log(const OString& rMessage)
824 SAL_INFO("desktop.updater", rMessage);
825 OUString aUpdateLog = getUpdateInfoLog();
826 SvFileStream aLog(aUpdateLog, StreamMode::STD_READWRITE);
827 aLog.Seek(aLog.Tell() + aLog.remainingSize()); // make sure we are at the end
828 aLog.WriteLine(rMessage);
831 void Updater::log(const char* pMessage)
833 SAL_INFO("desktop.updater", pMessage);
834 OUString aUpdateLog = getUpdateInfoLog();
835 SvFileStream aLog(aUpdateLog, StreamMode::STD_READWRITE);
836 aLog.Seek(aLog.Tell() + aLog.remainingSize()); // make sure we are at the end
837 aLog.WriteCharPtr(pMessage);
840 OUString Updater::getBuildID()
842 OUString aBuildID("${$BRAND_BASE_DIR/" LIBO_ETC_FOLDER "/" SAL_CONFIGFILE("version") ":buildid}");
843 rtl::Bootstrap::expandMacros(aBuildID);
845 return aBuildID;
848 OUString Updater::getUpdateChannel()
850 OUString aUpdateChannel("${$BRAND_BASE_DIR/" LIBO_ETC_FOLDER "/" SAL_CONFIGFILE("version") ":UpdateChannel}");
851 rtl::Bootstrap::expandMacros(aUpdateChannel);
853 return aUpdateChannel;
856 void Updater::removeUpdateFiles()
858 Updater::log("Removing: " + getUpdateFileURL());
859 osl::File::remove(getUpdateFileURL());
861 OUString aPatchDirURL = getPatchDirURL();
862 osl::Directory aDir(aPatchDirURL);
863 aDir.open();
865 osl::FileBase::RC eRC;
868 osl::DirectoryItem aItem;
869 eRC = aDir.getNextItem(aItem);
870 if (eRC == osl::FileBase::E_None)
872 osl::FileStatus aStatus(osl_FileStatus_Mask_All);
873 if (aItem.getFileStatus(aStatus) != osl::FileBase::E_None)
874 continue;
876 if (!aStatus.isRegular())
877 continue;
879 OUString aURL = aStatus.getFileURL();
880 if (!aURL.endsWith(".mar"))
881 continue;
883 Updater::log("Removing. " + aURL);
884 osl::File::remove(aURL);
887 while (eRC == osl::FileBase::E_None);
890 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */