1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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 <sal/config.h>
16 #include <osl/file.hxx>
17 #include <osl/thread.h>
18 #include <rtl/textcvt.h>
19 #include <rtl/ustring.h>
20 #include <rtl/ustring.hxx>
21 #include <sal/log.hxx>
22 #include <sfx2/flatpak.hxx>
23 #include <tools/debug.hxx>
24 #include <unotools/tempfile.hxx>
25 #include <unotools/ucbhelper.hxx>
27 bool flatpak::isFlatpak() {
28 static auto const flatpak
= [] { return std::getenv("LIBO_FLATPAK") != nullptr; }();
34 // Must only be accessed with SolarMutex locked:
38 } temporaryHtmlDirectoryStatus
;
42 bool flatpak::createTemporaryHtmlDirectory(OUString
** url
) {
43 assert(url
!= nullptr);
45 if (!temporaryHtmlDirectoryStatus
.created
) {
46 auto const env
= std::getenv("XDG_CACHE_HOME");
48 SAL_WARN("sfx.appl", "LIBO_FLATPAK mode but unset XDG_CACHE_HOME");
52 if (!rtl_convertStringToUString(
53 &path
.pData
, env
, std::strlen(env
), osl_getThreadTextEncoding(),
54 (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR
| RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR
55 | RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR
)))
59 "LIBO_FLATPAK mode failure converting XDG_CACHE_HOME \"" << env
<< "\" encoding");
63 auto const err
= osl::FileBase::getFileURLFromSystemPath(path
, parent
);
64 if (err
!= osl::FileBase::E_None
) {
67 "LIBO_FLATPAK mode failure converting XDG_CACHE_HOME \"" << path
<< "\" to URL: "
71 if (!parent
.endsWith("/")) {
74 auto const tmp
= utl::TempFile(&parent
, true);
77 "sfx.appl", "LIBO_FLATPAK mode failure creating temp dir at <" << parent
<< ">");
80 temporaryHtmlDirectoryStatus
.url
= tmp
.GetURL();
81 temporaryHtmlDirectoryStatus
.created
= true;
83 *url
= &temporaryHtmlDirectoryStatus
.url
;
87 void flatpak::removeTemporaryHtmlDirectory() {
89 if (temporaryHtmlDirectoryStatus
.created
) {
90 if (!utl::UCBContentHelper::Kill(temporaryHtmlDirectoryStatus
.url
)) {
93 "LIBO_FLATPAK mode failure removing directory <"
94 << temporaryHtmlDirectoryStatus
.url
<< ">");
99 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */