26#include <rtl/bootstrap.hxx>
27#include <rtl/random.h>
28#include <rtl/ustrbuf.hxx>
30#include <osl/file.hxx>
31#include <osl/security.hxx>
32#include <osl/thread.hxx>
34#include <osl/process.h>
39#include <com/sun/star/bridge/UnoUrlResolver.hpp>
40#include <com/sun/star/bridge/XUnoUrlResolver.hpp>
44namespace com :: sun :: star ::
uno {
class XComponentContext; }
60 :m_aMessage( rMessage )
86 Reference< XComponentContext > xRemoteContext;
93 "no soffice installation found!");
100 bool bOk = rtl_convertStringToUString(
101 &p2.pData, p1, std::strlen(p1), osl_getThreadTextEncoding(),
102 (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR |
103 RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR |
104 RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR));
109 "bad characters in soffice installation path!");
113 if (osl::FileBase::getFileURLFromSystemPath(p2, path) !=
114 osl::FileBase::E_None)
117 "cannot convert soffice installation path to URL!");
119 if (!path.isEmpty() && !path.endsWith(
"/")) {
124 if (!Bootstrap::get(
"URE_BOOTSTRAP", uri)) {
136 Reference< XComponentContext > xLocalContext(
138 if ( !xLocalContext.is() )
143 if ( hPool ==
nullptr )
146 if ( rtl_random_getBytes( hPool,
bytes, std::size(
bytes ) )
147 != rtl_Random_E_None )
149 rtl_random_destroyPool( hPool );
150 OUStringBuffer buf(
"uno");
151 for (
unsigned char byte :
bytes)
152 buf.append(
static_cast< sal_Int32
>(
byte ) );
153 OUString sPipeName( buf.makeStringAndClear() );
157 OUString(
"--nologo"),
158 OUString(
"--nodefault"),
159 OUString(
"--norestore"),
160 OUString(
"--nolockcheck"),
161 OUString(
"--accept=pipe,name=" + sPipeName +
";urp;")
163 rtl_uString * ar_args [] = {
173 oslProcess hProcess =
nullptr;
174 oslProcessError rc = osl_executeProcess(
175 OUString(path +
"soffice").
pData, ar_args, std::size( ar_args ),
176 osl_Process_DETACHED,
183 case osl_Process_E_None:
184 osl_freeProcessHandle( hProcess );
186 case osl_Process_E_NotFound:
188 case osl_Process_E_TimedOut:
190 case osl_Process_E_NoPermission:
192 case osl_Process_E_Unknown:
194 case osl_Process_E_InvalidError:
200 Reference< bridge::XUnoUrlResolver > xUrlResolver(
201 bridge::UnoUrlResolver::create( xLocalContext ) );
204 OUString sConnectString(
"uno:pipe,name=" + sPipeName +
";urp;StarOffice.ComponentContext" );
213 xUrlResolver->resolve( sConnectString ), UNO_QUERY_THROW );
216 catch ( connection::NoConnectException & )
219 std::this_thread::sleep_for(std::chrono::milliseconds(500));
226 "unexpected UNO exception caught: " + e.Message );
229 return xRemoteContext;
234 return uri.startsWith(
"vnd.sun.star.expand:", &rest)
237 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