25#include <rtl/bootstrap.hxx>
26#include <rtl/random.h>
27#include <rtl/ustrbuf.hxx>
29#include <osl/file.hxx>
30#include <osl/security.hxx>
31#include <osl/thread.hxx>
33#include <osl/process.h>
38#include <com/sun/star/bridge/UnoUrlResolver.hpp>
39#include <com/sun/star/bridge/XUnoUrlResolver.hpp>
43namespace com :: sun :: star ::
uno {
class XComponentContext; }
59 :m_aMessage( rMessage )
85 Reference< XComponentContext > xRemoteContext;
92 "no soffice installation found!");
99 bool bOk = rtl_convertStringToUString(
100 &p2.pData, p1, std::strlen(p1), osl_getThreadTextEncoding(),
101 (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR |
102 RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR |
103 RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR));
108 "bad characters in soffice installation path!");
112 if (osl::FileBase::getFileURLFromSystemPath(p2, path) !=
113 osl::FileBase::E_None)
116 "cannot convert soffice installation path to URL!");
118 if (!path.isEmpty() && !path.endsWith(
"/")) {
123 if (!Bootstrap::get(
"URE_BOOTSTRAP", uri)) {
135 Reference< XComponentContext > xLocalContext(
137 if ( !xLocalContext.is() )
142 if ( hPool ==
nullptr )
145 if ( rtl_random_getBytes( hPool,
bytes, std::size(
bytes ) )
146 != rtl_Random_E_None )
148 rtl_random_destroyPool( hPool );
149 OUStringBuffer buf(
"uno");
150 for (
unsigned char byte :
bytes)
151 buf.append(
static_cast< sal_Int32
>(
byte ) );
152 OUString sPipeName( buf.makeStringAndClear() );
156 OUString(
"--nologo"),
157 OUString(
"--nodefault"),
158 OUString(
"--norestore"),
159 OUString(
"--nolockcheck"),
160 OUString(
"--accept=pipe,name=" + sPipeName +
";urp;")
162 rtl_uString * ar_args [] = {
172 oslProcess hProcess =
nullptr;
173 oslProcessError rc = osl_executeProcess(
174 OUString(path +
"soffice").
pData, ar_args, std::size( ar_args ),
175 osl_Process_DETACHED,
182 case osl_Process_E_None:
183 osl_freeProcessHandle( hProcess );
185 case osl_Process_E_NotFound:
187 case osl_Process_E_TimedOut:
189 case osl_Process_E_NoPermission:
191 case osl_Process_E_Unknown:
193 case osl_Process_E_InvalidError:
199 Reference< bridge::XUnoUrlResolver > xUrlResolver(
200 bridge::UnoUrlResolver::create( xLocalContext ) );
203 OUString sConnectString(
"uno:pipe,name=" + sPipeName +
";urp;StarOffice.ComponentContext" );
212 xUrlResolver->resolve( sConnectString ), UNO_QUERY_THROW );
215 catch ( connection::NoConnectException & )
218 ::osl::Thread::wait( std::chrono::milliseconds(500) );
225 "unexpected UNO exception caught: " + e.Message );
228 return xRemoteContext;
233 return uri.startsWith(
"vnd.sun.star.expand:", &rest)
236 rest, rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8))
An exception indicating a bootstrap error.
BootstrapException & operator=(const BootstrapException &e)
Assigns a BootstrapException.
BootstrapException()
Constructs a BootstrapException.
::rtl::OUString m_aMessage
virtual ~BootstrapException()
Destructs a BootstrapException.
const ::rtl::OUString & getMessage() const
Gets the message.
#define SAL_CONFIGFILE(name)
char * cppuhelper_detail_findSofficePath(void)
std::unique_ptr< sal_Int32[]> pData
OUString bootstrap_expandUri(OUString const &uri)
Reference< XComponentContext > SAL_CALL bootstrap()
Bootstraps the component context from a UNO installation.
CPPUHELPER_DLLPUBLIC css::uno::Reference< css::uno::XComponentContext > SAL_CALL defaultBootstrap_InitialComponentContext()
Bootstraps an initial component context with service manager upon information from bootstrap variable...
OUString expandMacros(OUString const &text)
Helper function to expand macros based on the unorc/uno.ini.
std::vector< sal_uInt8 > bytes