24#include <config_folders.h>
28#include <rtl/bootstrap.hxx>
29#include <rtl/ustrbuf.hxx>
31#include <osl/process.h>
32#include <osl/file.hxx>
39#include <com/sun/star/lang/XMultiServiceFactory.hpp>
40#include <com/sun/star/ucb/UniversalContentBroker.hpp>
57 assert(info !=
nullptr);
58 OUStringBuffer buf(
"--");
59 buf.appendAscii(info->
m_name);
62 buf.append(
" (short -" + OUStringChar(info->
m_short_option) +
")");
65 buf.append(
" <argument>" );
66 return buf.makeStringAndClear();
72 OUString
const & opt )
74 for ( ; list->
m_name !=
nullptr; ++list )
93 assert(option_info !=
nullptr);
94 if (osl_getCommandArgCount() <= *pIndex)
98 osl_getCommandArg( *pIndex, &arg.pData );
99 sal_Int32 len = arg.getLength();
101 if (len < 2 || arg[ 0 ] !=
'-')
111 if (arg[ 1 ] ==
'-' && rtl_ustr_ascii_compare(
112 arg.pData->buffer + 2, option_info->
m_name ) == 0)
116 + OUString::createFromAscii(option_info->
m_name) +
"\'\n");
125 OSL_ASSERT(osl_getCommandArgCount() >= *pIndex);
128 osl_getCommandArg(*pIndex, &arg.pData);
129 if (arg.match(
"-env:"))
139 OUString * pValue,
OptionInfo const * option_info, sal_uInt32 * pIndex )
141 if (
isOption( option_info, pIndex ))
143 if (*pIndex < osl_getCommandArgCount())
145 OSL_ASSERT( pValue !=
nullptr );
146 osl_getCommandArg( *pIndex, &pValue->pData );
160 static const OUString EXEC =
164 if (osl_getExecutableFile( &path.pData ) != osl_Process_E_None) {
167 return path.copy( 0, path.lastIndexOf(
'/' ) );
175 static const OUString WORKING =
187 OUString
const & sys_path, OUString
const & base_url )
191 oslFileError rc = osl_getFileURLFromSystemPath( sys_path.pData, &file_url.pData );
192 if ( rc != osl_File_E_None) {
194 if ( osl_getSystemPathFromFileURL( sys_path.pData, &tempPath.pData) != osl_File_E_None )
203 if (osl_getAbsoluteFileURL(
204 base_url.pData, file_url.pData, &
abs.pData ) != osl_File_E_None)
207 "making absolute file url failed: \"" + base_url
208 +
"\" (base-url) and \"" + file_url +
"\" (file-url)!" );
210 return abs[
abs.getLength() -1 ] ==
'/'
211 ?
abs.copy( 0,
abs.getLength() -1 ) :
abs;
218void printf_space( sal_Int32 space )
226 std::u16string_view name, std::u16string_view value, sal_Int32 level )
228 printf_space( level );
234 Reference<deployment::XPackage>
const & xPackage,
235 Reference<XCommandEnvironment>
const & xCmdEnv, sal_Int32 level )
237 beans::Optional< OUString > id(
239 ? beans::Optional< OUString >(
241 : xPackage->getIdentifier() );
243 printf_line( u
"Identifier",
id.Value, level );
244 OUString version(xPackage->getVersion());
245 if (!version.isEmpty())
246 printf_line( u
"Version", version, level + 1 );
247 printf_line( u
"URL", xPackage->getURL(), level + 1 );
249 beans::Optional< beans::Ambiguous<sal_Bool> >
option(
250 xPackage->isRegistered( Reference<task::XAbortChannel>(), xCmdEnv ) );
253 beans::Ambiguous<sal_Bool>
const & reg =
option.Value;
257 value = reg.Value ? std::u16string_view(u
"yes") :
std::u16string_view(
u"no");
261 printf_line( u
"is registered", value, level + 1 );
263 const Reference<deployment::XPackageTypeInfo> xPackageType(
264 xPackage->getPackageType() );
265 OSL_ASSERT( xPackageType.is() );
266 if (xPackageType.is()) {
267 printf_line( u
"Media-Type", xPackageType->getMediaType(), level + 1 );
269 printf_line( u
"Description", xPackage->getDescription(), level + 1 );
270 if (!xPackage->isBundle())
273 Sequence< Reference<deployment::XPackage> > seq(
274 xPackage->getBundle( Reference<task::XAbortChannel>(), xCmdEnv ) );
275 printf_space( level + 1 );
277 std::vector<Reference<deployment::XPackage> >vec_bundle;
278 ::comphelper::sequenceToContainer(vec_bundle, seq);
280 xCmdEnv, level + 2 );
281 printf_space( level + 1 );
288 Reference<deployment::XPackage>
const & ext)
292 printf_line(
u"Identifier",
id, 0 );
299 std::vector< Reference<deployment::XPackage> >
const & allExtensions,
300 std::vector<bool>
const & vecUnaccepted,
301 Reference<XCommandEnvironment>
const & xCmdEnv, sal_Int32 level )
303 OSL_ASSERT(allExtensions.size() == vecUnaccepted.size());
305 if (allExtensions.empty())
307 printf_space( level );
313 for (
auto const& extension : allExtensions)
315 if (vecUnaccepted[
index])
318 printf_package( extension, xCmdEnv, level );
329Reference<XComponentContext> bootstrapStandAlone()
331 Reference<XComponentContext>
xContext =
332 ::cppu::defaultBootstrap_InitialComponentContext();
334 Reference<lang::XMultiServiceFactory> xServiceManager(
335 xContext->getServiceManager(), UNO_QUERY_THROW );
337 ::comphelper::setProcessServiceFactory( xServiceManager );
347Reference<XComponentContext> connectToOffice(
348 Reference<XComponentContext>
const & xLocalComponentContext,
352 OUString acceptArg =
"--accept=pipe,name=" + pipeId +
";urp;";
354 Sequence<OUString>
args {
"--nologo",
"--nodefault", acceptArg };
360 "Raising process: " + appURL +
361 "\nArguments: --nologo --nodefault " + args[2] +
370 OUString sUnoUrl =
"uno:pipe,name=" + pipeId +
";urp;StarOffice.ComponentContext";
371 Reference<XComponentContext> xRet(
373 sUnoUrl, xLocalComponentContext ),
389 OUString sBootstrap(
"${$BRAND_BASE_DIR/" LIBO_ETC_FOLDER
"/" SAL_CONFIGFILE(
"bootstrap")
":UserInstallation}");
390 rtl::Bootstrap::expandMacros(sBootstrap);
392 if (::osl::File::E_None == ::osl::File::getAbsoluteFileURL(
393 sBootstrap,
".lock", sAbs))
395 if (::osl::File::E_None ==
396 ::osl::File::getSystemPathFromFileURL(sAbs, sBootstrap))
406 bool verbose,
bool bGui,
const OUString& sTempDir,
407 Reference<XComponentContext> & out_localContext)
410 if (!sTempDir.isEmpty())
411 rtl::Bootstrap::set(
"UserInstallation", sTempDir);
414 static ::desktop::Lockfile s_lockfile(
false );
415 Reference<XComponentContext> xComponentContext( bootstrapStandAlone() );
416 out_localContext = xComponentContext;
418 xComponentContext.set(
419 connectToOffice( xComponentContext,
verbose ) );
423 if (! s_lockfile.check(
nullptr ))
425 OUString sMsg(
DpResId(RID_STR_CONCURRENTINSTANCE));
426 OUString sError(
DpResId(RID_STR_UNOPKG_ERROR));
438 VclMessageType::Warning, VclButtonsType::Ok,
450 return xComponentContext;
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, const ILibreOfficeKitNotifier *pNotifier=nullptr)
static bool getProcessWorkingDir(OUString &rUrl)
static OUString getProductName()
#define SAL_CONFIGFILE(name)
OUString DpResId(TranslateId aId)
static uno::Reference< css::uno::XComponentContext > xContext
#define SAL_WARN(area, stream)
void TRACE(OUString const &sText)
print the text to the console in a debug build.
Reference< XInterface > resolveUnoURL(OUString const &connectString, Reference< XComponentContext > const &xLocalContext, AbortChannel const *abortChannel)
OUString generateRandomPipeId()
void writeConsole(std::u16string_view sText)
writes the argument string to the console.
oslProcess raiseProcess(OUString const &appURL, Sequence< OUString > const &args)
DESKTOP_DEPLOYMENTMISC_DLLPUBLIC OUString getIdentifier(css::uno::Reference< css::deployment::XPackage > const &package)
Gets the identifier of a package.
css::uno::Reference< css::deployment::XPackageRegistry > create(css::uno::Reference< css::deployment::XPackageRegistry > const &xRootRegistry, OUString const &context, OUString const &cachePath, css::uno::Reference< css::uno::XComponentContext > const &xComponentContext)
Reference< XComponentContext > getUNO(bool verbose, bool bGui, const OUString &sTempDir, Reference< XComponentContext > &out_localContext)
OUString toString(OptionInfo const *info)
bool isOption(OptionInfo const *option_info, sal_uInt32 *pIndex)
OUString const & getProcessWorkingDir()
static OUString getLockFilePath()
returns the path to the lock file used by unopkg.
bool readArgument(OUString *pValue, OptionInfo const *option_info, sal_uInt32 *pIndex)
OUString const & getExecutableDir()
void printf_packages(std::vector< Reference< deployment::XPackage > > const &allExtensions, std::vector< bool > const &vecUnaccepted, Reference< XCommandEnvironment > const &xCmdEnv, sal_Int32 level)
static void printf_unaccepted_licenses(Reference< deployment::XPackage > const &ext)
bool isBootstrapVariable(sal_uInt32 *pIndex)
checks if an argument is a bootstrap variable.
OptionInfo const * getOptionInfo(OptionInfo const *list, OUString const &opt)
OUString makeAbsoluteFileUrl(OUString const &sys_path, OUString const &base_url)
SwNodeOffset abs(const SwNodeOffset &a)
sal_Unicode m_short_option
VCL_DLLPUBLIC bool InitVCL()
VCL_DLLPUBLIC void DeInitVCL()