include/sfx2/docfile.hxx         |    2 ++
 sfx2/source/doc/docfile.cxx      |   19 ++++++++++---------
 sfx2/source/doc/objmisc.cxx      |    4 +---
 sfx2/source/doc/objstor.cxx      |    3 +--
 sfx2/source/doc/sfxbasemodel.cxx |    6 ++----
 5 files changed, 16 insertions(+), 18 deletions(-)

New commits:
commit 4981c0e7d5bbe8e1fadc1b5cc7923e32f160d635
Author:     Mike Kaganski <[email protected]>
AuthorDate: Fri Feb 2 11:28:27 2024 +0600
Commit:     Mike Kaganski <[email protected]>
CommitDate: Fri Feb 2 08:49:14 2024 +0100

    Add SfxMedium::IsRepairPackage
    
    Change-Id: Id100e5a85a0504ab4fb80f75a168a4fd31a54119
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162924
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <[email protected]>

diff --git a/include/sfx2/docfile.hxx b/include/sfx2/docfile.hxx
index fb8039f6b8f1..f4a29a9414d9 100644
--- a/include/sfx2/docfile.hxx
+++ b/include/sfx2/docfile.hxx
@@ -200,6 +200,8 @@ public:
     // independent of later changes via SetOpenMode; used for SID_RELOAD:
     [[nodiscard]] bool IsOriginallyLoadedReadOnly() const;
 
+    [[nodiscard]] bool IsRepairPackage() const;
+
     css::uno::Reference< css::io::XInputStream > const &  GetInputStream();
 
     void                CreateTempFile( bool bReplace = true );
diff --git a/sfx2/source/doc/docfile.cxx b/sfx2/source/doc/docfile.cxx
index 670a27841414..fe1f5d0b773c 100644
--- a/sfx2/source/doc/docfile.cxx
+++ b/sfx2/source/doc/docfile.cxx
@@ -1764,6 +1764,12 @@ 
SfxMedium::TryEncryptedInnerPackage(uno::Reference<embed::XStorage> const xStora
     return xRet;
 }
 
+bool SfxMedium::IsRepairPackage() const
+{
+    const SfxBoolItem* pRepairItem = GetItemSet().GetItem(SID_REPAIRPACKAGE, 
false);
+    return pRepairItem && pRepairItem->GetValue();
+}
+
 uno::Reference < embed::XStorage > SfxMedium::GetStorage( bool bCreateTempFile 
)
 {
     if ( pImpl->xStorage.is() || pImpl->m_bTriedStorage )
@@ -1784,8 +1790,7 @@ uno::Reference < embed::XStorage > SfxMedium::GetStorage( 
bool bCreateTempFile )
     if ( GetErrorIgnoreWarning() )
         return pImpl->xStorage;
 
-    const SfxBoolItem* pRepairItem = GetItemSet().GetItem(SID_REPAIRPACKAGE, 
false);
-    if ( pRepairItem && pRepairItem->GetValue() )
+    if (IsRepairPackage())
     {
         // the storage should be created for repairing mode
         CreateTempFile( false );
@@ -1979,13 +1984,11 @@ uno::Reference<embed::XStorage> 
SfxMedium::GetScriptingStorageToSign_Impl()
             SAL_WARN_IF(!pImpl->m_xODFDecryptedInnerPackageStream.is(), 
"sfx.doc", "no inner package stream?");
             if (pImpl->m_xODFDecryptedInnerPackageStream.is())
             {
-                const SfxBoolItem* pRepairItem = 
GetItemSet().GetItem(SID_REPAIRPACKAGE, false);
-                const bool bRepairPackage = pRepairItem && 
pRepairItem->GetValue();
                 pImpl->m_xODFDecryptedInnerZipStorage =
                     
::comphelper::OStorageHelper::GetStorageOfFormatFromInputStream(
                         ZIP_STORAGE_FORMAT_STRING,
                         
pImpl->m_xODFDecryptedInnerPackageStream->getInputStream(), {},
-                        bRepairPackage);
+                        IsRepairPackage());
             }
         }
         return pImpl->m_xODFDecryptedInnerZipStorage;
@@ -2006,21 +2009,19 @@ uno::Reference< embed::XStorage > const & 
SfxMedium::GetZipStorageToSign_Impl( b
 
         try
         {
-            const SfxBoolItem* pRepairItem = 
GetItemSet().GetItem(SID_REPAIRPACKAGE, false);
-            const bool bRepairPackage = pRepairItem && pRepairItem->GetValue();
             // we can not sign document if there is no stream
             // should it be possible at all?
             if ( !bReadOnly && pImpl->xStream.is() )
             {
                 pImpl->m_xZipStorage = 
::comphelper::OStorageHelper::GetStorageOfFormatFromStream(
                     ZIP_STORAGE_FORMAT_STRING, pImpl->xStream, 
css::embed::ElementModes::READWRITE,
-                    {}, bRepairPackage);
+                    {}, IsRepairPackage());
             }
             else if ( pImpl->xInputStream.is() )
             {
                 pImpl->m_xZipStorage
                     = 
::comphelper::OStorageHelper::GetStorageOfFormatFromInputStream(
-                        ZIP_STORAGE_FORMAT_STRING, pImpl->xInputStream, {}, 
bRepairPackage);
+                        ZIP_STORAGE_FORMAT_STRING, pImpl->xInputStream, {}, 
IsRepairPackage());
             }
         }
         catch( const uno::Exception& )
diff --git a/sfx2/source/doc/objmisc.cxx b/sfx2/source/doc/objmisc.cxx
index 72e7f01e3d54..d7f417a9bcad 100644
--- a/sfx2/source/doc/objmisc.cxx
+++ b/sfx2/source/doc/objmisc.cxx
@@ -1957,9 +1957,7 @@ bool SfxObjectShell::IsContinueImportOnFilterExceptions()
             return false;
         }
 
-        if (const SfxBoolItem* pRepairItem
-            = pMedium->GetItemSet().GetItem(SID_REPAIRPACKAGE, false);
-            pRepairItem && pRepairItem->GetValue())
+        if (pMedium->IsRepairPackage())
         {
             mbContinueImportOnFilterExceptions = yes;
             return true;
diff --git a/sfx2/source/doc/objstor.cxx b/sfx2/source/doc/objstor.cxx
index 5a300dd164ad..b73b76282e00 100644
--- a/sfx2/source/doc/objstor.cxx
+++ b/sfx2/source/doc/objstor.cxx
@@ -670,14 +670,13 @@ bool SfxObjectShell::DoLoad( SfxMedium *pMed )
             try
             {
                 bool bWarnMediaTypeFallback = false;
-                const SfxBoolItem* pRepairPackageItem = 
rSet.GetItem(SID_REPAIRPACKAGE, false);
 
                 // treat the package as broken if the mediatype was retrieved 
as a fallback
                 uno::Reference< beans::XPropertySet > xStorProps( xStorage, 
uno::UNO_QUERY_THROW );
                 xStorProps->getPropertyValue("MediaTypeFallbackUsed")
                                                                     >>= 
bWarnMediaTypeFallback;
 
-                if ( pRepairPackageItem && pRepairPackageItem->GetValue() )
+                if (pMedium->IsRepairPackage())
                 {
                     // the macros in repaired documents should be disabled
                     pMedium->GetItemSet().Put( SfxUInt16Item( 
SID_MACROEXECMODE, document::MacroExecMode::NEVER_EXECUTE ) );
diff --git a/sfx2/source/doc/sfxbasemodel.cxx b/sfx2/source/doc/sfxbasemodel.cxx
index c25d31deb110..b1862799b6b7 100644
--- a/sfx2/source/doc/sfxbasemodel.cxx
+++ b/sfx2/source/doc/sfxbasemodel.cxx
@@ -1988,8 +1988,7 @@ void SAL_CALL SfxBaseModel::load(   const Sequence< 
beans::PropertyValue >& seqA
         if ( nError == ERRCODE_IO_BROKENPACKAGE && xHandler.is() )
         {
             const OUString aDocName( pMedium->GetURLObject().getName( 
INetURLObject::LAST_SEGMENT, true, INetURLObject::DecodeMechanism::WithCharset 
) );
-            const SfxBoolItem* pRepairItem = 
pMedium->GetItemSet().GetItem(SID_REPAIRPACKAGE, false);
-            if ( !pRepairItem || !pRepairItem->GetValue() )
+            if (!pMedium->IsRepairPackage())
             {
                 RequestPackageReparation aRequest( aDocName );
                 xHandler->handle( aRequest.GetRequest() );
@@ -4052,8 +4051,7 @@ OUString SAL_CALL SfxBaseModel::getTitle()
             catch (const ucb::CommandAbortedException &)
             {
             }
-            const SfxBoolItem* pRepairedDocItem = 
pMedium->GetItemSet().GetItem(SID_REPAIRPACKAGE, false);
-            if ( pRepairedDocItem && pRepairedDocItem->GetValue() )
+            if (pMedium->IsRepairPackage())
                 aResult += SfxResId(STR_REPAIREDDOCUMENT);
         }
 

Reply via email to