1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
10 #include "updater.hxx"
19 #include <comphelper/windowsStart.hxx>
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>
52 class error_updater
: public std::exception
57 error_updater(const OString
& rStr
):
62 virtual const char* what() const throw() override
64 return maStr
.getStr();
69 static const char kUserAgent
[] = "LibreOffice UpdateChecker/1.0 (Linux)";
71 static const char kUserAgent
[] = "LibreOffice UpdateChecker/1.0 (unknown platform)";
75 const char* const pUpdaterName
= "updater";
76 const char* const pSofficeExeName
= "soffice";
78 const char* pUpdaterName
= "updater.exe";
79 const char* pSofficeExeName
= "soffice.exe";
81 #error "Need implementation"
84 OUString
normalizePath(const OUString
& rPath
)
86 OUString aPath
= rPath
.replaceAll("//", "/");
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;
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
)
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
);
140 #define tstrncpy std::strncpy
141 #elif defined(_WIN32)
142 typedef wchar_t CharT
;
143 #define tstrncpy std::wcsncpy
145 #error "Need an implementation"
148 void createStr(const OUString
& rStr
, CharT
** pArgs
, size_t i
)
151 OString aStr
= OUStringToOString(rStr
, RTL_TEXTENCODING_UTF8
);
152 #elif defined(_WIN32)
153 OUString aStr
= rStr
;
155 #error "Need an implementation"
157 CharT
* pStr
= new CharT
[aStr
.getLength() + 1];
158 tstrncpy(pStr
, (CharT
*)aStr
.getStr(), aStr
.getLength());
159 pStr
[aStr
.getLength()] = '\0';
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);
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
);
201 #error "Need an implementation"
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;
241 update_file aUpdateFile
;
247 OUString aFromBuildID
;
248 OUString aSeeAlsoURL
;
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
);
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
);
274 bool bReadOnly
= (aStatus
.getAttributes() & static_cast<sal_uInt64
>(osl_File_Attribute_ReadOnly
)) != 0;
277 Updater::log("Update location as determined by: " + rFileURL
+ " is read-only.");
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
)
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
));
308 #elif defined(_WIN32)
309 bSuccess
= WinLaunchChild((wchar_t*)aUpdaterPath
.getStr(), 8, pArgs
);
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
]);
322 for (size_t i
= 0; i
< 8 + rtl_getAppCommandArgCount(); ++i
)
333 // Callback to get the response data from server.
334 size_t WriteCallback(void *ptr
, size_t size
,
335 size_t nmemb
, void *userp
)
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
);
348 class invalid_update_info
: public std::exception
352 class invalid_hash
: public std::exception
357 invalid_hash(const OUString
& rExpectedHash
, const OUString
& rReceivedHash
)
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
377 invalid_size(const size_t nExpectedSize
, const size_t nReceivedSize
)
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());
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());
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
);
504 comphelper::Hash maHash
;
507 WriteDataFile(SvStream
* pStream
):
508 maHash(comphelper::HashType::SHA512
),
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
)
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
);
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
); });
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;
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
));
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);
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());
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");
606 SAL_WARN("desktop.updater", "curl error: " << cc
);
607 throw error_updater("curl error");
611 rHash
= aFile
.getHash();
613 return response_body
;
616 void handle_file_error(osl::FileBase::RC eError
, const OUString
& rMsg
)
620 case osl::FileBase::E_None
:
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
);
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
);
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
);
678 Updater::log("Can't update as the update location is not user writable");
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");
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
);
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
);
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
);
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"));
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
);
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
);
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
);
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
);
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
)
876 if (!aStatus
.isRegular())
879 OUString aURL
= aStatus
.getFileURL();
880 if (!aURL
.endsWith(".mar"))
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: */