sfx2/source/appl/shutdowniconw32.cxx |   45 ++++++++++++-----------------------
 1 file changed, 16 insertions(+), 29 deletions(-)

New commits:
commit 4213b4cb860900f7a6247f582aeb6e84c5772e2d
Author:     Mike Kaganski <[email protected]>
AuthorDate: Sat Jan 18 18:59:01 2025 +0500
Commit:     Mike Kaganski <[email protected]>
CommitDate: Sun Jan 19 06:21:00 2025 +0100

    Use COMReference to handle COM pointers in CreateShortcut
    
    Simplifies the code.
    
    Change-Id: I25ab66380e982aaa111242507997f3bc0fda4bd0
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/180446
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <[email protected]>

diff --git a/sfx2/source/appl/shutdowniconw32.cxx 
b/sfx2/source/appl/shutdowniconw32.cxx
index 332a183b27b1..9bbbac69c094 100644
--- a/sfx2/source/appl/shutdowniconw32.cxx
+++ b/sfx2/source/appl/shutdowniconw32.cxx
@@ -32,6 +32,7 @@
 #include <objidl.h>
 #include <osl/diagnose.h>
 #include <osl/thread.h>
+#include <systools/win32/comtools.hxx>
 #include <systools/win32/extended_max_path.hxx>
 #include <systools/win32/qswin32.h>
 #include <comphelper/sequenceashashmap.hxx>
@@ -701,36 +702,22 @@ static HRESULT WINAPI SHCoCreateInstance( LPVOID 
lpszReserved, REFCLSID clsid, L
 static bool CreateShortcut( const OUString& rAbsObject, const OUString& 
rAbsObjectPath,
     const OUString& rAbsShortcut, const OUString& rDescription, const 
OUString& rParameter )
 {
-    HRESULT hres;
-    IShellLinkW* psl;
-    CLSID clsid_ShellLink = CLSID_ShellLink;
-    CLSID clsid_IShellLink = IID_IShellLinkW;
-
-    hres = CoCreateInstance( clsid_ShellLink, nullptr, CLSCTX_INPROC_SERVER,
-                             clsid_IShellLink, reinterpret_cast<void**>(&psl) 
);
-    if( FAILED(hres) )
-        hres = SHCoCreateInstance( nullptr, clsid_ShellLink, nullptr, 
clsid_IShellLink, reinterpret_cast<void**>(&psl) );
-
-    if( SUCCEEDED(hres) )
+    try
     {
-        IPersistFile* ppf;
+        sal::systools::COMReference<IShellLinkW> psl(CLSID_ShellLink, nullptr, 
CLSCTX_INPROC_SERVER);
         psl->SetPath( o3tl::toW(rAbsObject.getStr()) );
         psl->SetWorkingDirectory( o3tl::toW(rAbsObjectPath.getStr()) );
         psl->SetDescription( o3tl::toW(rDescription.getStr()) );
-        if( rParameter.getLength() )
+        if (!rParameter.isEmpty())
             psl->SetArguments( o3tl::toW(rParameter.getStr()) );
 
-        CLSID clsid_IPersistFile = IID_IPersistFile;
-        hres = psl->QueryInterface( clsid_IPersistFile, 
reinterpret_cast<void**>(&ppf) );
-
-        if( SUCCEEDED(hres) )
-        {
-            hres = ppf->Save( o3tl::toW(rAbsShortcut.getStr()), TRUE );
-            ppf->Release();
-        } else return false;
-        psl->Release();
-    } else return false;
-    return true;
+        sal::systools::COMReference<IPersistFile> ppf(psl, 
sal::systools::COM_QUERY_THROW);
+        return SUCCEEDED(ppf->Save(o3tl::toW(rAbsShortcut.getStr()), TRUE));
+    }
+    catch (const sal::systools::ComError&)
+    {
+        return false;
+    }
 }
 
 
commit 582517d60032acfbed2622a2ee905d2c9d3860ce
Author:     Mike Kaganski <[email protected]>
AuthorDate: Sat Jan 18 18:55:45 2025 +0500
Commit:     Mike Kaganski <[email protected]>
CommitDate: Sun Jan 19 06:20:46 2025 +0100

    Use std::u16string_view to avoid needless allocation
    
    Change-Id: I0b7c64ea29f65a381a5d02e8818a848e8cc46258
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/180445
    Reviewed-by: Mike Kaganski <[email protected]>
    Tested-by: Jenkins

diff --git a/sfx2/source/appl/shutdowniconw32.cxx 
b/sfx2/source/appl/shutdowniconw32.cxx
index 03c8bbf997a8..332a183b27b1 100644
--- a/sfx2/source/appl/shutdowniconw32.cxx
+++ b/sfx2/source/appl/shutdowniconw32.cxx
@@ -757,12 +757,12 @@ bool ShutdownIcon::IsQuickstarterInstalled()
     wchar_t aPath[EXTENDED_MAX_PATH];
     GetModuleFileNameW(nullptr, aPath, std::size(aPath));
 
-    OUString aOfficepath( o3tl::toU(aPath) );
-    int i = aOfficepath.lastIndexOf('\');
-    if( i != -1 )
-        aOfficepath = aOfficepath.copy(0, i);
+    std::u16string_view aOfficepath(o3tl::toU(aPath));
+    auto i = aOfficepath.find_last_of('\');
+    if (i != std::u16string_view::npos)
+        aOfficepath = aOfficepath.substr(0, i);
 
-    OUString quickstartExe(aOfficepath + "\quickstart.exe");
+    OUString quickstartExe(OUString::Concat(aOfficepath) + "\quickstart.exe");
 
     return FileExistsW( o3tl::toW(quickstartExe.getStr()) );
 }

Reply via email to