diff options
author | Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de> | 2016-12-12 17:29:28 +0100 |
---|---|---|
committer | Katarina Behrens <Katarina.Behrens@cib.de> | 2017-01-19 18:12:58 +0100 |
commit | ee28048245699d87cdd58c84d2bb1a6bd4cda093 (patch) | |
tree | f4c2ec7ee7ba8e02c78c0a693920bb039ef2d00c | |
parent | SafeModeDialog: Rename widget to match label (diff) | |
download | core-ee28048245699d87cdd58c84d2bb1a6bd4cda093.tar.gz core-ee28048245699d87cdd58c84d2bb1a6bd4cda093.zip |
SafeMode: Restart goes into safe mode again
Looks like the XRestartManager keeps all command line arguments when
restarting, so it also keeps --safe-mode.
Solution is to add a flag file when restarting from safe mode,
to prevent going into safe mode again.
Change-Id: I9820d3ccbddf98b0bf6132f254c989f52ea5e808
Reviewed-on: https://gerrit.libreoffice.org/31913
Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>
Tested-by: Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>
-rw-r--r-- | desktop/source/app/app.cxx | 5 | ||||
-rw-r--r-- | include/sfx2/safemode.hxx | 24 | ||||
-rw-r--r-- | sfx2/source/safemode/safemode.cxx | 34 | ||||
-rw-r--r-- | svx/source/dialog/SafeModeDialog.cxx | 1 |
4 files changed, 58 insertions, 6 deletions
diff --git a/desktop/source/app/app.cxx b/desktop/source/app/app.cxx index c72b4853dc0a..1ae2a8a55ada 100644 --- a/desktop/source/app/app.cxx +++ b/desktop/source/app/app.cxx @@ -564,7 +564,10 @@ void Desktop::Init() // Check whether safe mode is enabled CommandLineArgs& rCmdLine = GetCommandLineArgs(); - if (rCmdLine.IsSafeMode() || sfx2::SafeMode::hasFlag()) + // Check if we are restarting from safe mode - in that case we don't want to enter it again + if (sfx2::SafeMode::hasRestartFlag()) + sfx2::SafeMode::removeRestartFlag(); + else if (rCmdLine.IsSafeMode() || sfx2::SafeMode::hasFlag()) Application::EnableSafeMode(); // When we are in SafeMode we need to do changes before the configuration diff --git a/include/sfx2/safemode.hxx b/include/sfx2/safemode.hxx index 03f85904271c..47034f62130a 100644 --- a/include/sfx2/safemode.hxx +++ b/include/sfx2/safemode.hxx @@ -40,9 +40,31 @@ public: */ static bool removeFlag(); + /** + * Write a flag to the user profile indicating that we are currently restarting from safe mode - + * that means we don't want to enter safe mode again. + * + * @return Whether the file could be written successfully + */ + static bool putRestartFlag(); + + /** + * Check the existence of the restart flag file. + * + * @return Whether the restart flag file exists + */ + static bool hasRestartFlag(); + + /** + * Remove the restart flag file. + * + * @return Whether the flag file could be removed successfully + */ + static bool removeRestartFlag(); + private: /** Returns the path of the safe mode flag file.*/ - static OUString getFileName(); + static OUString getFilePath(const OUString& sFilename); }; } diff --git a/sfx2/source/safemode/safemode.cxx b/sfx2/source/safemode/safemode.cxx index a5669d19587f..609ebbd6876e 100644 --- a/sfx2/source/safemode/safemode.cxx +++ b/sfx2/source/safemode/safemode.cxx @@ -20,7 +20,7 @@ namespace sfx2 { bool SafeMode::putFlag() { - File safeModeFile(getFileName()); + File safeModeFile(getFilePath("safemode")); if (safeModeFile.open(osl_File_OpenFlag_Create) == FileBase::E_None) { safeModeFile.close(); @@ -30,7 +30,7 @@ bool SafeMode::putFlag() } bool SafeMode::hasFlag() { - File safeModeFile(getFileName()); + File safeModeFile(getFilePath("safemode")); if (safeModeFile.open(osl_File_OpenFlag_Read) == FileBase::E_None) { safeModeFile.close(); @@ -40,16 +40,42 @@ bool SafeMode::hasFlag() } bool SafeMode::removeFlag() { - return File::remove(getFileName()) == FileBase::E_None; + return File::remove(getFilePath("safemode")) == FileBase::E_None; } -OUString SafeMode::getFileName() +bool SafeMode::putRestartFlag() +{ + File restartFile(getFilePath("safemode_restart")); + if (restartFile.open(osl_File_OpenFlag_Create) == FileBase::E_None) + { + restartFile.close(); + return true; + } + return false; +} +bool SafeMode::hasRestartFlag() +{ + File restartFile(getFilePath("safemode_restart")); + if (restartFile.open(osl_File_OpenFlag_Read) == FileBase::E_None) + { + restartFile.close(); + return true; + } + return false; +} +bool SafeMode::removeRestartFlag() +{ + return File::remove(getFilePath("safemode_restart")) == FileBase::E_None; +} + +OUString SafeMode::getFilePath(const OUString& sFilename) { OUString url("${$BRAND_BASE_DIR/" LIBO_ETC_FOLDER "/" SAL_CONFIGFILE("bootstrap") ":UserInstallation}/safemode"); rtl::Bootstrap::expandMacros(url); OUString aProfilePath; FileBase::getSystemPathFromFileURL(url, aProfilePath); + FileBase::getAbsoluteFileURL(url, sFilename, aProfilePath); return aProfilePath; } diff --git a/svx/source/dialog/SafeModeDialog.cxx b/svx/source/dialog/SafeModeDialog.cxx index 59db86c13964..e9ff29cbbe08 100644 --- a/svx/source/dialog/SafeModeDialog.cxx +++ b/svx/source/dialog/SafeModeDialog.cxx @@ -353,6 +353,7 @@ IMPL_LINK(SafeModeDialog, DialogBtnHdl, Button*, pBtn) } else if (pBtn == mpBtnRestart.get()) { + sfx2::SafeMode::putRestartFlag(); Close(); applyChanges(); } |