[Libreoffice-commits] core.git: Branch 'libreoffice-5-3' - desktop/source include/sfx2 sfx2/source svx/source

Samuel Mehrbrodt Samuel.Mehrbrodt at cib.de
Tue Dec 13 09:56:12 UTC 2016


 desktop/source/app/app.cxx           |    5 ++++-
 include/sfx2/safemode.hxx            |   24 +++++++++++++++++++++++-
 sfx2/source/safemode/safemode.cxx    |   35 ++++++++++++++++++++++++++++++-----
 svx/source/dialog/SafeModeDialog.cxx |    1 +
 4 files changed, 58 insertions(+), 7 deletions(-)

New commits:
commit 159ec429d136adc208922f27ba6044b529022dde
Author: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
Date:   Mon Dec 12 17:29:28 2016 +0100

    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 at cib.de>
    Tested-by: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
    (cherry picked from commit 0fda52cc4a5c78c55f96850faa734ea66891808c)
    Reviewed-on: https://gerrit.libreoffice.org/31937
    Tested-by: Jenkins <ci at libreoffice.org>

diff --git a/desktop/source/app/app.cxx b/desktop/source/app/app.cxx
index 7abfdda..ea49fd2 100644
--- a/desktop/source/app/app.cxx
+++ b/desktop/source/app/app.cxx
@@ -558,7 +558,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 03f8590..47034f6 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 3e84f7e..6d8dcf9 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 ac9c494..b77b83f 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();
     }


More information about the Libreoffice-commits mailing list