diff options
-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 | 35 | ||||
-rw-r--r-- | svx/source/dialog/SafeModeDialog.cxx | 1 |
4 files changed, 58 insertions, 7 deletions
diff --git a/desktop/source/app/app.cxx b/desktop/source/app/app.cxx index eba8bf6e1488..437ff5114485 100644 --- a/desktop/source/app/app.cxx +++ b/desktop/source/app/app.cxx @@ -560,7 +560,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 3e84f7ed02e6..6d8dcf981a4d 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,17 +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}/"); rtl::Bootstrap::expandMacros(url); OUString aProfilePath; FileBase::getSystemPathFromFileURL(url, aProfilePath); - FileBase::getAbsoluteFileURL(url, "safemode", aProfilePath); + FileBase::getAbsoluteFileURL(url, sFilename, aProfilePath); return aProfilePath; } diff --git a/svx/source/dialog/SafeModeDialog.cxx b/svx/source/dialog/SafeModeDialog.cxx index ac9c494d9f8e..b77b83fe680a 100644 --- a/svx/source/dialog/SafeModeDialog.cxx +++ b/svx/source/dialog/SafeModeDialog.cxx @@ -326,6 +326,7 @@ IMPL_LINK(SafeModeDialog, DialogBtnHdl, Button*, pBtn, void) } else if (pBtn == mpBtnRestart.get()) { + sfx2::SafeMode::putRestartFlag(); Close(); applyChanges(); } |