Kaydet (Commit) 0fda52cc authored tarafından Samuel Mehrbrodt's avatar Samuel Mehrbrodt

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/31913Reviewed-by: 's avatarSamuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>
Tested-by: 's avatarSamuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>
üst 19650d0e
......@@ -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
......
......@@ -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);
};
}
......
......@@ -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;
}
......
......@@ -326,6 +326,7 @@ IMPL_LINK(SafeModeDialog, DialogBtnHdl, Button*, pBtn, void)
}
else if (pBtn == mpBtnRestart.get())
{
sfx2::SafeMode::putRestartFlag();
Close();
applyChanges();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment