Update git submodules
[LibreOffice.git] / sfx2 / source / safemode / safemode.cxx
blob048e8d7356a73c3daca794efd8de8a10d89f3572
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 <sfx2/safemode.hxx>
12 #include <config_folders.h>
14 #include <osl/file.hxx>
15 #include <rtl/bootstrap.hxx>
17 using namespace osl;
19 namespace sfx2
21 bool SafeMode::putFlag()
23 File safeModeFile(getFilePath(u"safemode"_ustr));
24 if (safeModeFile.open(osl_File_OpenFlag_Create) == FileBase::E_None)
26 safeModeFile.close();
27 return true;
29 return false;
31 bool SafeMode::hasFlag()
33 File safeModeFile(getFilePath(u"safemode"_ustr));
34 if (safeModeFile.open(osl_File_OpenFlag_Read) == FileBase::E_None)
36 safeModeFile.close();
37 return true;
39 return false;
41 bool SafeMode::removeFlag()
43 return File::remove(getFilePath(u"safemode"_ustr)) == FileBase::E_None;
46 bool SafeMode::putRestartFlag()
48 File restartFile(getFilePath(u"safemode_restart"_ustr));
49 if (restartFile.open(osl_File_OpenFlag_Create) == FileBase::E_None)
51 restartFile.close();
52 return true;
54 return false;
56 bool SafeMode::hasRestartFlag()
58 File restartFile(getFilePath(u"safemode_restart"_ustr));
59 if (restartFile.open(osl_File_OpenFlag_Read) == FileBase::E_None)
61 restartFile.close();
62 return true;
64 return false;
66 bool SafeMode::removeRestartFlag()
68 return File::remove(getFilePath(u"safemode_restart"_ustr)) == FileBase::E_None;
71 OUString SafeMode::getFilePath(const OUString& sFilename)
73 OUString url(u"${$BRAND_BASE_DIR/" LIBO_ETC_FOLDER
74 "/" SAL_CONFIGFILE("bootstrap") ":UserInstallation}/"_ustr);
75 rtl::Bootstrap::expandMacros(url);
77 OUString aProfilePath;
78 FileBase::getSystemPathFromFileURL(url, aProfilePath);
79 (void)FileBase::getAbsoluteFileURL(url, sFilename, aProfilePath);
80 return aProfilePath;
84 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */