From b3b9ae6c6fd19b437a5414489a9f38fb310a2843 Mon Sep 17 00:00:00 2001 From: Samuel Mehrbrodt Date: Tue, 11 Oct 2016 16:07:37 +0200 Subject: [PATCH] safemode: Add flag to indicate safemode Change-Id: Ifdbb291715b033eaace159297eac5348530e9f36 --- desktop/source/app/app.cxx | 3 +- include/sfx2/safemode.hxx | 32 +++++++++++++++ sfx2/Library_sfx.mk | 1 + sfx2/source/appl/appserv.cxx | 2 + sfx2/source/safemode/safemode.cxx | 58 ++++++++++++++++++++++++++++ svx/source/dialog/SafeModeDialog.cxx | 3 +- svx/source/dialog/crashreportdlg.cxx | 3 +- 7 files changed, 99 insertions(+), 3 deletions(-) create mode 100644 include/sfx2/safemode.hxx create mode 100644 sfx2/source/safemode/safemode.cxx diff --git a/desktop/source/app/app.cxx b/desktop/source/app/app.cxx index a9d10c3a99ba..69da758aac42 100644 --- a/desktop/source/app/app.cxx +++ b/desktop/source/app/app.cxx @@ -101,6 +101,7 @@ #include #include #include +#include #include #include #include @@ -2138,7 +2139,7 @@ void Desktop::OpenClients() bool bAllowRecoveryAndSessionManagement = ( !rArgs.IsNoRestore() ) && ( !rArgs.IsHeadless() ); // Enter safe mode if requested - if (rArgs.IsSafeMode()) + if (rArgs.IsSafeMode() || sfx2::SafeMode::hasFlag()) handleSafeMode(); diff --git a/include/sfx2/safemode.hxx b/include/sfx2/safemode.hxx new file mode 100644 index 000000000000..666d2d4215ef --- /dev/null +++ b/include/sfx2/safemode.hxx @@ -0,0 +1,32 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef INCLUDED_SFX2_SAFEMODE_HXX +#define INCLUDED_SFX2_SAFEMODE_HXX + +#include + +#include + +namespace sfx2 { + +class SFX2_DLLPUBLIC SafeMode +{ +public: + static bool putFlag(); + static bool hasFlag(); + static bool removeFlag(); + static OUString getFileName(); +}; + +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sfx2/Library_sfx.mk b/sfx2/Library_sfx.mk index 9ec5f0ee3af8..e3daa773a50d 100644 --- a/sfx2/Library_sfx.mk +++ b/sfx2/Library_sfx.mk @@ -251,6 +251,7 @@ $(eval $(call gb_Library_add_exception_objects,sfx,\ sfx2/source/notify/globalevents \ sfx2/source/notify/hintpost \ sfx2/source/notify/openurlhint \ + sfx2/source/safemode/safemode \ sfx2/source/sidebar/Sidebar \ sfx2/source/sidebar/SidebarChildWindow \ sfx2/source/sidebar/SidebarDockingWindow \ diff --git a/sfx2/source/appl/appserv.cxx b/sfx2/source/appl/appserv.cxx index b09613e081e6..defd3b601d8b 100644 --- a/sfx2/source/appl/appserv.cxx +++ b/sfx2/source/appl/appserv.cxx @@ -127,6 +127,7 @@ #include #include #include +#include #include #include @@ -311,6 +312,7 @@ namespace IMPL_LINK_NOARG(SafeModeQueryDialog, RestartHdl, Button*, void) { EndDialog(RET_OK); + sfx2::SafeMode::putFlag(); uno::Reference< uno::XComponentContext > xContext = comphelper::getProcessComponentContext(); css::task::OfficeRestartManager::get(xContext)->requestRestart( css::uno::Reference< css::task::XInteractionHandler >()); diff --git a/sfx2/source/safemode/safemode.cxx b/sfx2/source/safemode/safemode.cxx new file mode 100644 index 000000000000..a5669d19587f --- /dev/null +++ b/sfx2/source/safemode/safemode.cxx @@ -0,0 +1,58 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include + +#include + +#include +#include + +using namespace osl; + +namespace sfx2 { + +bool SafeMode::putFlag() +{ + File safeModeFile(getFileName()); + if (safeModeFile.open(osl_File_OpenFlag_Create) == FileBase::E_None) + { + safeModeFile.close(); + return true; + } + return false; +} +bool SafeMode::hasFlag() +{ + File safeModeFile(getFileName()); + if (safeModeFile.open(osl_File_OpenFlag_Read) == FileBase::E_None) + { + safeModeFile.close(); + return true; + } + return false; +} +bool SafeMode::removeFlag() +{ + return File::remove(getFileName()) == FileBase::E_None; +} + +OUString SafeMode::getFileName() +{ + OUString url("${$BRAND_BASE_DIR/" LIBO_ETC_FOLDER "/" SAL_CONFIGFILE("bootstrap") ":UserInstallation}/safemode"); + rtl::Bootstrap::expandMacros(url); + + OUString aProfilePath; + FileBase::getSystemPathFromFileURL(url, aProfilePath); + return aProfilePath; +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svx/source/dialog/SafeModeDialog.cxx b/svx/source/dialog/SafeModeDialog.cxx index c9f6e4c7fb99..0553436bd673 100644 --- a/svx/source/dialog/SafeModeDialog.cxx +++ b/svx/source/dialog/SafeModeDialog.cxx @@ -10,9 +10,9 @@ #include "SafeModeDialog.hxx" #include - #include #include +#include SafeModeDialog::SafeModeDialog(vcl::Window* pParent): Dialog(pParent, "SafeModeDialog", "svx/ui/safemodedialog.ui") @@ -60,6 +60,7 @@ IMPL_LINK(SafeModeDialog, BtnHdl, Button*, pBtn, void) { Close(); } + sfx2::SafeMode::removeFlag(); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svx/source/dialog/crashreportdlg.cxx b/svx/source/dialog/crashreportdlg.cxx index bbac21157dfb..1692a444fa53 100644 --- a/svx/source/dialog/crashreportdlg.cxx +++ b/svx/source/dialog/crashreportdlg.cxx @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -104,7 +105,7 @@ IMPL_LINK(CrashReportDialog, BtnHdl, Button*, pBtn, void) // Check whether to go to safe mode if (mpCBSafeMode->IsChecked()) { - //TODO: Actually set the safe mode, currently it's only restarting + sfx2::SafeMode::putFlag(); css::uno::Reference< css::uno::XComponentContext > xContext = comphelper::getProcessComponentContext(); css::task::OfficeRestartManager::get(xContext)->requestRestart( css::uno::Reference< css::task::XInteractionHandler >());