diff options
Diffstat (limited to 'desktop/source/deployment/misc/dp_misc.cxx')
-rw-r--r-- | desktop/source/deployment/misc/dp_misc.cxx | 87 |
1 files changed, 42 insertions, 45 deletions
diff --git a/desktop/source/deployment/misc/dp_misc.cxx b/desktop/source/deployment/misc/dp_misc.cxx index f4437711dab5..fc85925ca0b9 100644 --- a/desktop/source/deployment/misc/dp_misc.cxx +++ b/desktop/source/deployment/misc/dp_misc.cxx @@ -19,11 +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> @@ -45,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> @@ -60,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( u"$BRAND_BASE_DIR/" LIBO_ETC_FOLDER "/" SAL_CONFIGFILE("louno") ""_ustr ); + ::rtl::Bootstrap::expandMacros( unorc ); + auto ret = std::make_shared<::rtl::Bootstrap>( unorc ); + OSL_ASSERT( ret->getHandle() != nullptr ); + return ret; + }(); + return theRc; }; OUString generateOfficePipeId() @@ -79,12 +82,12 @@ OUString generateOfficePipeId() if (aLocateResult != ::utl::Bootstrap::PATH_EXISTS && aLocateResult != ::utl::Bootstrap::PATH_VALID) { - throw Exception("Extension Manager: Could not obtain path for UserInstallation.", nullptr); + throw Exception(u"Extension Manager: Could not obtain path for UserInstallation."_ustr, nullptr); } rtlDigest digest = rtl_digest_create( rtl_Digest_AlgorithmMD5 ); if (!digest) { - throw RuntimeException("cannot get digest rtl_Digest_AlgorithmMD5!", nullptr ); + throw RuntimeException(u"cannot get digest rtl_Digest_AlgorithmMD5!"_ustr, nullptr ); } sal_uInt8 const * data = @@ -100,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 ); } @@ -224,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) { @@ -247,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_); @@ -260,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); @@ -277,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); @@ -291,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 ); @@ -313,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 { @@ -392,16 +390,16 @@ oslProcess raiseProcess( case osl_Process_E_None: break; case osl_Process_E_NotFound: - throw RuntimeException( "image not found!", nullptr ); + throw RuntimeException( u"image not found!"_ustr, nullptr ); case osl_Process_E_TimedOut: - throw RuntimeException( "timeout occurred!", nullptr ); + throw RuntimeException( u"timeout occurred!"_ustr, nullptr ); case osl_Process_E_NoPermission: - throw RuntimeException( "permission denied!", nullptr ); + throw RuntimeException( u"permission denied!"_ustr, nullptr ); case osl_Process_E_Unknown: - throw RuntimeException( "unknown error!", nullptr ); + throw RuntimeException( u"unknown error!"_ustr, nullptr ); case osl_Process_E_InvalidError: default: - throw RuntimeException( "unmapped error!", nullptr ); + throw RuntimeException( u"unmapped error!"_ustr, nullptr ); } return hProcess; @@ -411,13 +409,10 @@ oslProcess raiseProcess( OUString generateRandomPipeId() { // compute some good pipe id: - static rtlRandomPool s_hPool = rtl_random_createPool(); - if (s_hPool == nullptr) - 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) { - throw RuntimeException( "random pool error!?", nullptr ); + nullptr, bytes, std::size(bytes) ) != rtl_Random_E_None) { + throw RuntimeException( u"random pool error!?"_ustr, nullptr ); } OUStringBuffer buf; for (unsigned char byte : bytes) { @@ -438,7 +433,7 @@ Reference<XInterface> resolveUnoURL( for (int i = 0; i <= 40; ++i) // 20 seconds { if (abortChannel != nullptr && abortChannel->isAborted()) { - throw ucb::CommandAbortedException( "abort!" ); + throw ucb::CommandAbortedException( u"abort!"_ustr ); } try { return xUnoUrlResolver->resolve( connectString ); @@ -446,7 +441,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; } @@ -481,7 +476,7 @@ OUString readConsole() OUString value = OStringToOUString(std::string_view(buf), osl_getThreadTextEncoding()); return value.trim(); } - throw css::uno::RuntimeException("reading from stdin failed"); + throw css::uno::RuntimeException(u"reading from stdin failed"_ustr); } void TRACE(OUString const & sText) @@ -493,7 +488,7 @@ void syncRepositories( bool force, Reference<ucb::XCommandEnvironment> const & xCmdEnv) { OUString sDisable; - ::rtl::Bootstrap::get( "DISABLE_EXTENSION_SYNCHRONIZATION", sDisable, OUString() ); + ::rtl::Bootstrap::get( u"DISABLE_EXTENSION_SYNCHRONIZATION"_ustr, sDisable, OUString() ); if (!sDisable.isEmpty()) return; @@ -513,7 +508,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())); |