Coverage Report

Created: 2025-07-07 10:01

/src/libreoffice/sfx2/source/safemode/safemode.cxx
Line
Count
Source (jump to first uncovered line)
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
17
using namespace osl;
18
19
namespace sfx2
20
{
21
bool SafeMode::putFlag()
22
0
{
23
0
    File safeModeFile(getFilePath(u"safemode"_ustr));
24
0
    if (safeModeFile.open(osl_File_OpenFlag_Create) == FileBase::E_None)
25
0
    {
26
0
        safeModeFile.close();
27
0
        return true;
28
0
    }
29
0
    return false;
30
0
}
31
bool SafeMode::hasFlag()
32
0
{
33
0
    File safeModeFile(getFilePath(u"safemode"_ustr));
34
0
    if (safeModeFile.open(osl_File_OpenFlag_Read) == FileBase::E_None)
35
0
    {
36
0
        safeModeFile.close();
37
0
        return true;
38
0
    }
39
0
    return false;
40
0
}
41
bool SafeMode::removeFlag()
42
0
{
43
0
    return File::remove(getFilePath(u"safemode"_ustr)) == FileBase::E_None;
44
0
}
45
46
bool SafeMode::putRestartFlag()
47
0
{
48
0
    File restartFile(getFilePath(u"safemode_restart"_ustr));
49
0
    if (restartFile.open(osl_File_OpenFlag_Create) == FileBase::E_None)
50
0
    {
51
0
        restartFile.close();
52
0
        return true;
53
0
    }
54
0
    return false;
55
0
}
56
bool SafeMode::hasRestartFlag()
57
0
{
58
0
    File restartFile(getFilePath(u"safemode_restart"_ustr));
59
0
    if (restartFile.open(osl_File_OpenFlag_Read) == FileBase::E_None)
60
0
    {
61
0
        restartFile.close();
62
0
        return true;
63
0
    }
64
0
    return false;
65
0
}
66
bool SafeMode::removeRestartFlag()
67
0
{
68
0
    return File::remove(getFilePath(u"safemode_restart"_ustr)) == FileBase::E_None;
69
0
}
70
71
OUString SafeMode::getFilePath(const OUString& sFilename)
72
0
{
73
0
    OUString url(u"${$BRAND_BASE_DIR/" LIBO_ETC_FOLDER
74
0
                 "/" SAL_CONFIGFILE("bootstrap") ":UserInstallation}/"_ustr);
75
0
    rtl::Bootstrap::expandMacros(url);
76
77
0
    OUString aProfilePath;
78
0
    FileBase::getSystemPathFromFileURL(url, aProfilePath);
79
0
    (void)FileBase::getAbsoluteFileURL(url, sFilename, aProfilePath);
80
0
    return aProfilePath;
81
0
}
82
}
83
84
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */