diff options
Diffstat (limited to 'desktop/source/deployment/misc/dp_misc.cxx')
-rw-r--r-- | desktop/source/deployment/misc/dp_misc.cxx | 72 |
1 files changed, 40 insertions, 32 deletions
diff --git a/desktop/source/deployment/misc/dp_misc.cxx b/desktop/source/deployment/misc/dp_misc.cxx index d24811621d72..6011d15cb11d 100644 --- a/desktop/source/deployment/misc/dp_misc.cxx +++ b/desktop/source/deployment/misc/dp_misc.cxx @@ -19,10 +19,11 @@ #include <config_folders.h> #include <config_features.h> -#include <chrono> #include <dp_misc.h> #include <dp_interact.h> +#include <dp_shared.hxx> +#include <o3tl/string_view.hxx> #include <rtl/uri.hxx> #include <rtl/digest.h> #include <rtl/random.h> @@ -44,6 +45,7 @@ #include <com/sun/star/task/OfficeRestartManager.hpp> #include <memory> #include <string_view> +#include <thread> #include <comphelper/lok.hxx> #include <comphelper/processfactory.hxx> #include <salhelper/linkhelper.hxx> @@ -59,15 +61,17 @@ using namespace ::com::sun::star::uno; namespace dp_misc { namespace { -struct UnoRc : public rtl::StaticWithInit< - std::shared_ptr<rtl::Bootstrap>, UnoRc> { - std::shared_ptr<rtl::Bootstrap> operator () () { - OUString unorc( "$BRAND_BASE_DIR/" LIBO_ETC_FOLDER "/" SAL_CONFIGFILE("louno") ); - ::rtl::Bootstrap::expandMacros( unorc ); - auto ret = std::make_shared<::rtl::Bootstrap>( unorc ); - OSL_ASSERT( ret->getHandle() != nullptr ); - return ret; - } +std::shared_ptr<rtl::Bootstrap> & UnoRc() +{ + static std::shared_ptr<rtl::Bootstrap> theRc = []() + { + OUString unorc( "$BRAND_BASE_DIR/" LIBO_ETC_FOLDER "/" SAL_CONFIGFILE("louno") ); + ::rtl::Bootstrap::expandMacros( unorc ); + auto ret = std::make_shared<::rtl::Bootstrap>( unorc ); + OSL_ASSERT( ret->getHandle() != nullptr ); + return ret; + }(); + return theRc; }; OUString generateOfficePipeId() @@ -99,8 +103,7 @@ OUString generateOfficePipeId() // create hex-value string from the MD5 value to keep // the string size minimal - OUStringBuffer buf; - buf.append( "SingleOfficeIPC_" ); + OUStringBuffer buf( "SingleOfficeIPC_" ); for ( sal_uInt32 i = 0; i < md5_key_len; ++i ) { buf.append( static_cast<sal_Int32>(md5_buf[ i ]), 0x10 ); } @@ -223,12 +226,12 @@ bool needToSyncRepository(std::u16string_view name) namespace { -OUString encodeForRcFile( OUString const & str ) +OUString encodeForRcFile( std::u16string_view str ) { // escape $\{} (=> rtl bootstrap files) OUStringBuffer buf(64); - sal_Int32 pos = 0; - const sal_Int32 len = str.getLength(); + size_t pos = 0; + const size_t len = str.size(); for ( ; pos < len; ++pos ) { sal_Unicode c = str[ pos ]; switch (c) { @@ -246,11 +249,11 @@ OUString encodeForRcFile( OUString const & str ) } -OUString makeURL( OUString const & baseURL, OUString const & relPath_ ) +OUString makeURL( std::u16string_view baseURL, OUString const & relPath_ ) { OUStringBuffer buf(128); - if (baseURL.getLength() > 1 && baseURL[ baseURL.getLength() - 1 ] == '/') - buf.append( baseURL.subView(0, baseURL.getLength() - 1) ); + if (baseURL.size() > 1 && baseURL[ baseURL.size() - 1 ] == '/') + buf.append( baseURL.substr(0, baseURL.size() - 1) ); else buf.append( baseURL ); OUString relPath(relPath_); @@ -259,7 +262,7 @@ OUString makeURL( OUString const & baseURL, OUString const & relPath_ ) if (!relPath.isEmpty()) { buf.append( '/' ); - if (baseURL.match( "vnd.sun.star.expand:" )) { + if (o3tl::starts_with(baseURL, u"vnd.sun.star.expand:" )) { // encode for macro expansion: relPath is supposed to have no // macros, so encode $, {} \ (bootstrap mimic) relPath = encodeForRcFile(relPath); @@ -276,7 +279,7 @@ OUString makeURL( OUString const & baseURL, OUString const & relPath_ ) return buf.makeStringAndClear(); } -OUString makeURLAppendSysPathSegment( OUString const & baseURL, OUString const & segment ) +OUString makeURLAppendSysPathSegment( std::u16string_view baseURL, OUString const & segment ) { OSL_ASSERT(segment.indexOf(u'/') == -1); @@ -290,16 +293,14 @@ OUString makeURLAppendSysPathSegment( OUString const & baseURL, OUString const & OUString expandUnoRcTerm( OUString const & term_ ) { OUString term(term_); - UnoRc::get()->expandMacrosFrom( term ); + UnoRc()->expandMacrosFrom( term ); return term; } OUString makeRcTerm( OUString const & url ) { OSL_ASSERT( url.match( "vnd.sun.star.expand:" )); - if (url.match( "vnd.sun.star.expand:" )) { - // cut protocol: - OUString rcterm( url.copy( sizeof ("vnd.sun.star.expand:") - 1 ) ); + if (OUString rcterm; url.startsWithIgnoreAsciiCase("vnd.sun.star.expand:", &rcterm)) { // decode uric class chars: rcterm = ::rtl::Uri::decode( rcterm, rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8 ); @@ -312,14 +313,12 @@ OUString makeRcTerm( OUString const & url ) OUString expandUnoRcUrl( OUString const & url ) { - if (url.match( "vnd.sun.star.expand:" )) { - // cut protocol: - OUString rcurl( url.copy( sizeof ("vnd.sun.star.expand:") - 1 ) ); + if (OUString rcurl; url.startsWithIgnoreAsciiCase("vnd.sun.star.expand:", &rcurl)) { // decode uric class chars: rcurl = ::rtl::Uri::decode( rcurl, rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8 ); // expand macro string: - UnoRc::get()->expandMacrosFrom( rcurl ); + UnoRc()->expandMacrosFrom( rcurl ); return rcurl; } else { @@ -415,7 +414,7 @@ OUString generateRandomPipeId() throw RuntimeException( "cannot create random pool!?", nullptr ); sal_uInt8 bytes[ 32 ]; if (rtl_random_getBytes( - s_hPool, bytes, SAL_N_ELEMENTS(bytes) ) != rtl_Random_E_None) { + s_hPool, bytes, std::size(bytes) ) != rtl_Random_E_None) { throw RuntimeException( "random pool error!?", nullptr ); } OUStringBuffer buf; @@ -445,7 +444,7 @@ Reference<XInterface> resolveUnoURL( catch (const connection::NoConnectException &) { if (i < 40) { - ::osl::Thread::wait( std::chrono::milliseconds(500) ); + std::this_thread::sleep_for( std::chrono::milliseconds(500) ); } else throw; } @@ -512,7 +511,9 @@ void syncRepositories( Reference<task::XAbortChannel>(), xCmdEnv); } } -#if !HAVE_FEATURE_MACOSX_SANDBOX +#if HAVE_FEATURE_MACOSX_SANDBOX + (void) bModified; +#else if (bModified && !comphelper::LibreOfficeKit::isActive()) { Reference<task::XRestartManager> restarter(task::OfficeRestartManager::get(comphelper::getProcessComponentContext())); @@ -521,7 +522,7 @@ void syncRepositories( restarter->requestRestart(xCmdEnv.is() ? xCmdEnv->getInteractionHandler() : Reference<task::XInteractionHandler>()); } - } + } #endif } @@ -550,4 +551,11 @@ void disposeBridges(Reference<css::uno::XComponentContext> const & ctx) } +OUString DpResId(TranslateId aId) +{ + static std::locale SINGLETON = Translate::Create("dkt"); + return Translate::get(aId, SINGLETON); +} + + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |