LibreOffice Module sfx2 (master) 1
safemode.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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 */
9
10#include <sfx2/safemode.hxx>
11
12#include <config_folders.h>
13
14#include <osl/file.hxx>
15#include <rtl/bootstrap.hxx>
16
17using namespace osl;
18
19namespace sfx2
20{
22{
23 File safeModeFile(getFilePath("safemode"));
24 if (safeModeFile.open(osl_File_OpenFlag_Create) == FileBase::E_None)
25 {
26 safeModeFile.close();
27 return true;
28 }
29 return false;
30}
32{
33 File safeModeFile(getFilePath("safemode"));
34 if (safeModeFile.open(osl_File_OpenFlag_Read) == FileBase::E_None)
35 {
36 safeModeFile.close();
37 return true;
38 }
39 return false;
40}
41bool SafeMode::removeFlag() { return File::remove(getFilePath("safemode")) == FileBase::E_None; }
42
44{
45 File restartFile(getFilePath("safemode_restart"));
46 if (restartFile.open(osl_File_OpenFlag_Create) == FileBase::E_None)
47 {
48 restartFile.close();
49 return true;
50 }
51 return false;
52}
54{
55 File restartFile(getFilePath("safemode_restart"));
56 if (restartFile.open(osl_File_OpenFlag_Read) == FileBase::E_None)
57 {
58 restartFile.close();
59 return true;
60 }
61 return false;
62}
64{
65 return File::remove(getFilePath("safemode_restart")) == FileBase::E_None;
66}
67
68OUString SafeMode::getFilePath(const OUString& sFilename)
69{
70 OUString url("${$BRAND_BASE_DIR/" LIBO_ETC_FOLDER
71 "/" SAL_CONFIGFILE("bootstrap") ":UserInstallation}/");
72 rtl::Bootstrap::expandMacros(url);
73
74 OUString aProfilePath;
75 FileBase::getSystemPathFromFileURL(url, aProfilePath);
76 (void)FileBase::getAbsoluteFileURL(url, sFilename, aProfilePath);
77 return aProfilePath;
78}
79}
80
81/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static bool putFlag()
Write a flag file to the user profile indicating that the next launch should be in safe mode.
Definition: safemode.cxx:21
static bool removeRestartFlag()
Remove the restart flag file.
Definition: safemode.cxx:63
static bool putRestartFlag()
Write a flag to the user profile indicating that we are currently restarting from safe mode - that me...
Definition: safemode.cxx:43
static bool hasFlag()
Check the existence of the safe mode flag file.
Definition: safemode.cxx:31
static bool hasRestartFlag()
Check the existence of the restart flag file.
Definition: safemode.cxx:53
static bool removeFlag()
Remove the flag file for the safe mode.
Definition: safemode.cxx:41
static OUString getFilePath(const OUString &sFilename)
Returns the path of the safe mode flag file.
Definition: safemode.cxx:68
#define SAL_CONFIGFILE(name)