1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <strings.hrc>
22 #include <dp_package.hxx>
23 #include <dp_backend.h>
26 #include <dp_interact.h>
27 #include <dp_dependencies.hxx>
28 #include <dp_platform.hxx>
29 #include <dp_descriptioninfoset.hxx>
30 #include <dp_identifier.hxx>
31 #include <dp_resource.h>
32 #include <rtl/uri.hxx>
33 #include <rtl/ustrbuf.hxx>
34 #include <sal/log.hxx>
35 #include <o3tl/string_view.hxx>
36 #include <cppuhelper/exc_hlp.hxx>
37 #include <cppuhelper/implbase.hxx>
38 #include <cppuhelper/supportsservice.hxx>
39 #include <ucbhelper/content.hxx>
40 #include <svl/inettype.hxx>
41 #include <comphelper/propertyvalue.hxx>
42 #include <comphelper/sequence.hxx>
43 #include <com/sun/star/lang/WrappedTargetException.hpp>
44 #include <com/sun/star/graphic/XGraphic.hpp>
45 #include <com/sun/star/graphic/GraphicProvider.hpp>
46 #include <com/sun/star/graphic/XGraphicProvider.hpp>
47 #include <com/sun/star/io/Pipe.hpp>
48 #include <com/sun/star/io/XOutputStream.hpp>
49 #include <com/sun/star/io/XInputStream.hpp>
50 #include <com/sun/star/task/InteractionClassification.hpp>
51 #include <com/sun/star/task/XInteractionApprove.hpp>
52 #include <com/sun/star/ucb/CommandAbortedException.hpp>
53 #include <com/sun/star/ucb/CommandFailedException.hpp>
54 #include <com/sun/star/ucb/ContentCreationException.hpp>
55 #include <com/sun/star/ucb/XInteractionReplaceExistingData.hpp>
56 #include <com/sun/star/ucb/NameClashResolveRequest.hpp>
57 #include <com/sun/star/ucb/XContentAccess.hpp>
58 #include <com/sun/star/ucb/NameClash.hpp>
59 #include <com/sun/star/ucb/UnsupportedCommandException.hpp>
60 #include <com/sun/star/sdbc/XResultSet.hpp>
61 #include <com/sun/star/sdbc/XRow.hpp>
62 #include <com/sun/star/packages/manifest/ManifestReader.hpp>
63 #include <com/sun/star/packages/manifest/ManifestWriter.hpp>
64 #include <com/sun/star/deployment/DependencyException.hpp>
65 #include <com/sun/star/deployment/DeploymentException.hpp>
66 #include <com/sun/star/deployment/ExtensionRemovedException.hpp>
67 #include <com/sun/star/deployment/LicenseException.hpp>
68 #include <com/sun/star/deployment/PlatformException.hpp>
69 #include <com/sun/star/deployment/Prerequisites.hpp>
71 #include <comphelper/diagnose_ex.hxx>
75 #include <string_view>
79 #include "dp_extbackenddb.hxx"
80 using namespace ::dp_misc
;
81 using namespace ::com::sun::star
;
82 using namespace ::com::sun::star::uno
;
85 namespace dp_registry::backend::bundle
{
88 typedef cppu::ImplInheritanceHelper
<PackageRegistryBackend
> ImplBaseT
;
91 class BackendImpl
: public ImplBaseT
93 class PackageImpl
: public ::dp_registry::backend::Package
95 BackendImpl
* getMyBackend() const;
96 /** contains the old tooltip description for the Extension Manager GUI in OOo v.2.x
97 We keep it for backward compatibility.
99 OUString m_oldDescription
;
100 OUString m_url_expanded
;
101 const bool m_legacyBundle
;
102 Sequence
< Reference
<deployment::XPackage
> > m_bundle
;
103 Sequence
< Reference
<deployment::XPackage
> > * m_pBundle
;
105 ExtensionBackendDb::Data m_dbData
;
107 Reference
<deployment::XPackage
> bindBundleItem(
108 OUString
const & url
, OUString
const & mediaType
,
109 bool bRemoved
, //that is, using data base information
110 OUString
const & identifier
,
111 Reference
<ucb::XCommandEnvironment
> const & xCmdEnv
,
112 bool notifyDetectionError
= true );
114 typedef std::vector
< Reference
<deployment::XPackage
> > t_packagevec
;
116 t_packagevec
& bundle
,
117 ::rtl::Reference
<AbortChannel
> const & abortChannel
,
118 Reference
<ucb::XCommandEnvironment
> const & xCmdEnv
);
119 void scanLegacyBundle(
120 t_packagevec
& bundle
,
121 OUString
const & url
,
122 ::rtl::Reference
<AbortChannel
> const & abortChannel
,
123 Reference
<ucb::XCommandEnvironment
> const & xCmdEnv
,
124 bool skip_registration
= false );
125 std::vector
<Reference
<deployment::XPackage
> > getPackagesFromDb(
126 Reference
<ucb::XCommandEnvironment
> const & xCmdEnv
);
128 Reference
<ucb::XCommandEnvironment
> const & environment
);
130 bool checkDependencies(
131 Reference
<ucb::XCommandEnvironment
> const &
133 DescriptionInfoset
const & description
);
134 // throws css::uno::RuntimeException,
135 // css::deployment::DeploymentException
137 /// @throws deployment::DeploymentException
138 /// @throws ucb::CommandFailedException
139 /// @throws ucb::CommandAbortedException
140 /// @throws RuntimeException
142 Reference
< ucb::XCommandEnvironment
> const & xCmdEnv
,
143 DescriptionInfoset
const & description
, bool bNoLicenseChecking
);
144 // @throws DeploymentException
145 OUString
getTextFromURL(
146 const Reference
< ucb::XCommandEnvironment
>& xCmdEnv
,
147 const OUString
& licenseUrl
);
149 DescriptionInfoset
getDescriptionInfoset() const;
152 virtual beans::Optional
< beans::Ambiguous
<sal_Bool
> > isRegistered_(
153 ::osl::ResettableMutexGuard
& guard
,
154 ::rtl::Reference
<AbortChannel
> const & abortChannel
,
155 Reference
<ucb::XCommandEnvironment
> const & xCmdEnv
) override
;
156 virtual void processPackage_(
157 ::osl::ResettableMutexGuard
& guard
,
158 bool registerPackage
,
160 ::rtl::Reference
<AbortChannel
> const & abortChannel
,
161 Reference
<ucb::XCommandEnvironment
> const & xCmdEnv
) override
;
163 virtual void SAL_CALL
disposing() override
;
168 ::rtl::Reference
<PackageRegistryBackend
> const & myBackend
,
169 OUString
const & url
,
170 OUString
const & name
,
171 Reference
<deployment::XPackageTypeInfo
> const & xPackageType
,
174 OUString
const & identifier
);
177 virtual sal_Bool SAL_CALL
isBundle() override
;
179 virtual Sequence
< Reference
<deployment::XPackage
> > SAL_CALL
getBundle(
180 Reference
<task::XAbortChannel
> const & xAbortChannel
,
181 Reference
<ucb::XCommandEnvironment
> const & xCmdEnv
) override
;
182 virtual OUString SAL_CALL
getDescription() override
;
184 virtual OUString SAL_CALL
getLicenseText() override
;
186 virtual void SAL_CALL
exportTo(
187 OUString
const & destFolderURL
, OUString
const & newTitle
,
188 sal_Int32 nameClashAction
,
189 Reference
<ucb::XCommandEnvironment
> const & xCmdEnv
) override
;
191 virtual ::sal_Int32 SAL_CALL
checkPrerequisites(
192 const Reference
< task::XAbortChannel
>& xAbortChannel
,
193 const Reference
< ucb::XCommandEnvironment
>& xCmdEnv
,
194 sal_Bool noLicenseChecking
) override
;
196 virtual sal_Bool SAL_CALL
checkDependencies(
197 const Reference
< ucb::XCommandEnvironment
>& xCmdEnv
) override
;
199 virtual beans::Optional
<OUString
> SAL_CALL
getIdentifier() override
;
201 virtual OUString SAL_CALL
getVersion() override
;
203 virtual Sequence
<OUString
> SAL_CALL
getUpdateInformationURLs() override
;
205 virtual beans::StringPair SAL_CALL
getPublisherInfo() override
;
207 virtual OUString SAL_CALL
getDisplayName() override
;
209 virtual Reference
< graphic::XGraphic
> SAL_CALL
210 getIcon( sal_Bool bHighContrast
) override
;
212 friend class PackageImpl
;
214 Reference
<deployment::XPackageRegistry
> m_xRootRegistry
;
215 const Reference
<deployment::XPackageTypeInfo
> m_xBundleTypeInfo
;
216 const Reference
<deployment::XPackageTypeInfo
> m_xLegacyBundleTypeInfo
;
217 Sequence
< Reference
<deployment::XPackageTypeInfo
> > m_typeInfos
;
219 std::unique_ptr
<ExtensionBackendDb
> m_backendDb
;
221 void addDataToDb(OUString
const & url
, ExtensionBackendDb::Data
const & data
);
222 ExtensionBackendDb::Data
readDataFromDb(std::u16string_view url
);
223 void revokeEntryFromDb(std::u16string_view url
);
225 // PackageRegistryBackend
226 virtual Reference
<deployment::XPackage
> bindPackage_(
227 OUString
const & url
, OUString
const & mediaType
,
228 bool bRemoved
, OUString
const & identifier
,
229 Reference
<ucb::XCommandEnvironment
> const & xCmdEnv
) override
;
231 virtual void SAL_CALL
disposing() override
;
235 Sequence
<Any
> const & args
,
236 Reference
<XComponentContext
> const & xComponentContext
,
237 Reference
<deployment::XPackageRegistry
> const & xRootRegistry
);
240 virtual OUString SAL_CALL
getImplementationName() override
;
241 virtual sal_Bool SAL_CALL
supportsService( OUString
const& name
) override
;
242 virtual Sequence
<OUString
> SAL_CALL
getSupportedServiceNames() override
;
245 virtual Sequence
< Reference
<deployment::XPackageTypeInfo
> > SAL_CALL
246 getSupportedPackageTypes() override
;
247 virtual void SAL_CALL
packageRemoved(OUString
const & url
, OUString
const & mediaType
) override
;
249 using ImplBaseT::disposing
;
252 //Used to find a XPackage with a particular URL
257 explicit XPackage_eq(OUString s
) : m_URL(std::move(s
)) {}
258 bool operator() (const Reference
<deployment::XPackage
> & p
) const
260 return m_URL
== p
->getURL();
265 BackendImpl::BackendImpl(
266 Sequence
<Any
> const & args
,
267 Reference
<XComponentContext
> const & xComponentContext
,
268 Reference
<deployment::XPackageRegistry
> const & xRootRegistry
)
269 : ImplBaseT( args
, xComponentContext
),
270 m_xRootRegistry( xRootRegistry
),
271 m_xBundleTypeInfo( new Package::TypeInfo(
272 "application/vnd.sun.star.package-bundle",
274 DpResId(RID_STR_PACKAGE_BUNDLE
)
276 m_xLegacyBundleTypeInfo( new Package::TypeInfo(
277 "application/vnd.sun.star.legacy-package-bundle",
279 m_xBundleTypeInfo
->getShortDescription()
281 m_typeInfos
{ m_xBundleTypeInfo
, m_xLegacyBundleTypeInfo
}
283 if (!transientMode())
285 OUString dbFile
= makeURL(getCachePath(), getImplementationName());
286 dbFile
= makeURL(dbFile
, "backenddb.xml");
288 new ExtensionBackendDb(getComponentContext(), dbFile
));
293 void BackendImpl::disposing()
295 m_xRootRegistry
.clear();
296 PackageRegistryBackend::disposing();
300 OUString
BackendImpl::getImplementationName()
302 return "com.sun.star.comp.deployment.bundle.PackageRegistryBackend";
305 sal_Bool
BackendImpl::supportsService(OUString
const & ServiceName
)
307 return cppu::supportsService(this, ServiceName
);
310 Sequence
<OUString
> BackendImpl::getSupportedServiceNames()
312 return { OUString(BACKEND_SERVICE_NAME
) };
317 Sequence
< Reference
<deployment::XPackageTypeInfo
> >
318 BackendImpl::getSupportedPackageTypes()
323 void BackendImpl::packageRemoved(OUString
const & url
, OUString
const & /*mediaType*/)
325 //Notify the backend responsible for processing the different media
326 //types that this extension was removed.
327 ExtensionBackendDb::Data data
= readDataFromDb(url
);
328 for (auto const& item
: data
.items
)
330 m_xRootRegistry
->packageRemoved(item
.first
, item
.second
);
334 m_backendDb
->removeEntry(url
);
338 // PackageRegistryBackend
340 Reference
<deployment::XPackage
> BackendImpl::bindPackage_(
341 OUString
const & url
, OUString
const & mediaType_
,
342 bool bRemoved
, OUString
const & identifier
,
343 Reference
<ucb::XCommandEnvironment
> const & xCmdEnv
)
345 OUString
mediaType( mediaType_
);
346 if (mediaType
.isEmpty())
348 // detect media-type:
349 ::ucbhelper::Content ucbContent
;
350 if (create_ucb_content( &ucbContent
, url
, xCmdEnv
))
352 if (ucbContent
.isFolder())
354 //Every .oxt, uno.pkg file must contain a META-INF folder
355 ::ucbhelper::Content metaInfContent
;
356 if (create_ucb_content(
357 &metaInfContent
, makeURL( url
, "META-INF" ),
358 xCmdEnv
, false /* no throw */ ))
360 mediaType
= "application/vnd.sun.star.package-bundle";
362 //No support of legacy bundles, because every folder could be one.
366 const OUString
title( StrTitle::getTitle( ucbContent
) );
367 if (title
.endsWithIgnoreAsciiCase(".oxt") ||
368 title
.endsWithIgnoreAsciiCase(".uno.pkg"))
369 mediaType
= "application/vnd.sun.star.package-bundle";
370 else if (title
.endsWithIgnoreAsciiCase(".zip"))
371 mediaType
= "application/vnd.sun.star.legacy-package-bundle";
374 if (mediaType
.isEmpty())
375 throw lang::IllegalArgumentException(
376 StrCannotDetectMediaType() + url
,
377 static_cast<OWeakObject
*>(this), static_cast<sal_Int16
>(-1) );
380 OUString type
, subType
;
381 INetContentTypeParameterList params
;
382 if (INetContentTypes::parse( mediaType
, type
, subType
, ¶ms
))
384 if (type
.equalsIgnoreAsciiCase("application"))
387 //In case a XPackage is created for a removed extension, we cannot
392 ::ucbhelper::Content
ucbContent(
393 url
, xCmdEnv
, getComponentContext() );
394 name
= StrTitle::getTitle( ucbContent
);
396 if (subType
.equalsIgnoreAsciiCase("vnd.sun.star.package-bundle"))
398 return new PackageImpl(
399 this, url
, name
, m_xBundleTypeInfo
, false, bRemoved
,
402 else if (subType
.equalsIgnoreAsciiCase( "vnd.sun.star.legacy-package-bundle"))
404 return new PackageImpl(
405 this, url
, name
, m_xLegacyBundleTypeInfo
, true, bRemoved
,
410 throw lang::IllegalArgumentException(
411 StrUnsupportedMediaType() + mediaType
,
412 static_cast<OWeakObject
*>(this),
413 static_cast<sal_Int16
>(-1) );
416 void BackendImpl::addDataToDb(
417 OUString
const & url
, ExtensionBackendDb::Data
const & data
)
420 m_backendDb
->addEntry(url
, data
);
423 ExtensionBackendDb::Data
BackendImpl::readDataFromDb(
424 std::u16string_view url
)
426 ExtensionBackendDb::Data data
;
428 data
= m_backendDb
->getEntry(url
);
432 void BackendImpl::revokeEntryFromDb(std::u16string_view url
)
435 m_backendDb
->revokeEntry(url
);
439 BackendImpl::PackageImpl::PackageImpl(
440 ::rtl::Reference
<PackageRegistryBackend
> const & myBackend
,
441 OUString
const & url
,
442 OUString
const & name
,
443 Reference
<deployment::XPackageTypeInfo
> const & xPackageType
,
444 bool legacyBundle
, bool bRemoved
, OUString
const & identifier
)
445 : Package( myBackend
, url
, name
, name
/* display-name */,
446 xPackageType
, bRemoved
, identifier
),
447 m_url_expanded( expandUnoRcUrl( url
) ),
448 m_legacyBundle( legacyBundle
),
452 m_dbData
= getMyBackend()->readDataFromDb(url
);
455 BackendImpl
* BackendImpl::PackageImpl::getMyBackend() const
457 BackendImpl
* pBackend
= static_cast<BackendImpl
*>(m_myBackend
.get());
458 if (nullptr == pBackend
)
460 //May throw a DisposedException
462 //We should never get here...
463 throw RuntimeException("Failed to get the BackendImpl",
464 static_cast<OWeakObject
*>(const_cast<PackageImpl
*>(this)));
469 void BackendImpl::PackageImpl::disposing()
471 sal_Int32 len
= m_bundle
.getLength();
472 Reference
<deployment::XPackage
> const * p
= m_bundle
.getConstArray();
473 for ( sal_Int32 pos
= 0; pos
< len
; ++pos
)
474 try_dispose( p
[ pos
] );
475 m_bundle
.realloc( 0 );
477 Package::disposing();
482 beans::Optional
< beans::Ambiguous
<sal_Bool
> >
483 BackendImpl::PackageImpl::isRegistered_(
484 ::osl::ResettableMutexGuard
&,
485 ::rtl::Reference
<AbortChannel
> const & abortChannel
,
486 Reference
<ucb::XCommandEnvironment
> const & xCmdEnv
)
488 //In case the object was created for a removed extension (m_bRemoved = true)
489 //but the extension is not registered, then bundle will be empty. Then
490 //the return value will be Optional<...>.IsPresent= false. Although this is
491 //not true, this does not matter. Then registerPackage or revokePackage
492 //would never be called for the items. But since the extension is removed
493 //and not registered anyway, this does not matter.
494 const Sequence
< Reference
<deployment::XPackage
> > bundle(
495 getBundle( abortChannel
, xCmdEnv
) );
498 bool present
= false;
500 for ( sal_Int32 pos
= bundle
.getLength(); pos
--; )
502 Reference
<deployment::XPackage
> const & xPackage
= bundle
[ pos
];
503 Reference
<task::XAbortChannel
> xSubAbortChannel(
504 xPackage
->createAbortChannel() );
505 AbortChannel::Chain
chain( abortChannel
, xSubAbortChannel
);
506 beans::Optional
< beans::Ambiguous
<sal_Bool
> > option(
507 xPackage
->isRegistered( xSubAbortChannel
, xCmdEnv
) );
509 //present = true if at least one bundle item has this value.
510 //reg = true if all bundle items have an option value (option.IsPresent == 1)
511 //and all have value of true (option.Value.Value == true)
512 //If not, then the bundle has the status of not registered and ambiguous.
513 if (option
.IsPresent
)
515 beans::Ambiguous
<sal_Bool
> const & status
= option
.Value
;
518 //we never come here in the first iteration
519 if (reg
!= bool(status
.Value
)) {
528 //we always come here in the first iteration
534 return beans::Optional
< beans::Ambiguous
<sal_Bool
> >(
535 present
, beans::Ambiguous
<sal_Bool
>(reg
, ambig
) );
538 OUString
BackendImpl::PackageImpl::getTextFromURL(
539 const css::uno::Reference
< css::ucb::XCommandEnvironment
>& xCmdEnv
,
540 const OUString
& licenseUrl
)
544 ::ucbhelper::Content
descContent(
545 licenseUrl
, xCmdEnv
, getMyBackend()->getComponentContext());
546 std::vector
<sal_Int8
> seq
= dp_misc::readFile(descContent
);
547 return OUString( reinterpret_cast<char const *>(
548 seq
.data()), seq
.size(), RTL_TEXTENCODING_UTF8
);
550 catch (const css::uno::Exception
&)
552 Any
exc( ::cppu::getCaughtException() );
553 throw css::deployment::DeploymentException(
554 "Could not read file " + licenseUrl
, nullptr, exc
);
559 DescriptionInfoset
BackendImpl::PackageImpl::getDescriptionInfoset() const
561 return dp_misc::getDescriptionInfoset(m_url_expanded
);
564 bool BackendImpl::PackageImpl::checkPlatform(
565 css::uno::Reference
< css::ucb::XCommandEnvironment
> const & environment
)
568 DescriptionInfoset
info(getDescriptionInfoset());
569 Sequence
<OUString
> platforms(info
.getSupportedPlatforms());
570 if (hasValidPlatform(platforms
))
578 "unsupported platform");
580 css::deployment::PlatformException(
581 msg
, static_cast<OWeakObject
*>(this), this));
582 if (!interactContinuation(
583 e
, cppu::UnoType
< css::task::XInteractionApprove
>::get(),
584 environment
, nullptr, nullptr))
586 throw css::deployment::DeploymentException(
587 msg
, static_cast<OWeakObject
*>(this), e
);
594 bool BackendImpl::PackageImpl::checkDependencies(
595 css::uno::Reference
< css::ucb::XCommandEnvironment
> const & environment
,
596 DescriptionInfoset
const & description
)
598 css::uno::Sequence
< css::uno::Reference
< css::xml::dom::XElement
> >
599 unsatisfied(dp_misc::Dependencies::check(description
));
601 if (!unsatisfied
.hasElements()) {
605 "unsatisfied dependencies");
607 css::deployment::DependencyException(
608 msg
, static_cast<OWeakObject
*>(this), unsatisfied
));
609 if (!interactContinuation(
610 e
, cppu::UnoType
< css::task::XInteractionApprove
>::get(),
611 environment
, nullptr, nullptr))
613 throw css::deployment::DeploymentException(
614 msg
, static_cast<OWeakObject
*>(this), e
);
620 bool BackendImpl::PackageImpl::checkLicense(
621 css::uno::Reference
< css::ucb::XCommandEnvironment
> const & xCmdEnv
,
622 DescriptionInfoset
const & info
, bool alreadyInstalled
)
626 ::std::optional
<SimpleLicenseAttributes
> simplLicAttr
627 = info
.getSimpleLicenseAttributes();
630 OUString sLic
= info
.getLocalizedLicenseURL();
631 //If we do not get a localized licence then there is an error in the description.xml
632 //This should be handled by using a validating parser. Therefore we assume that no
633 //license is available.
635 throw css::deployment::DeploymentException(
636 "Could not obtain path to license. Possible error in description.xml", nullptr, Any());
637 OUString sHref
= m_url_expanded
+ "/" + sLic
;
638 OUString sLicense
= getTextFromURL(xCmdEnv
, sHref
);
639 ////determine who has to agree to the license
640 //check correct value for attribute
641 if ( simplLicAttr
->acceptBy
!= "user" && simplLicAttr
->acceptBy
!= "admin")
642 throw css::deployment::DeploymentException(
643 "Could not obtain attribute simple-license@accept-by or it has no valid value", nullptr, Any());
646 //Only use interaction if there is no version of this extension already installed
647 //and the suppress-on-update flag is not set for the new extension
648 // alreadyInstalled | bSuppressOnUpdate | show license
655 if ( !(alreadyInstalled
&& simplLicAttr
->suppressOnUpdate
))
657 css::deployment::LicenseException
licExc(
658 OUString(), nullptr, getDisplayName(), sLicense
,
659 simplLicAttr
->acceptBy
);
660 bool approve
= false;
662 if (! interactContinuation(
663 Any(licExc
), cppu::UnoType
<task::XInteractionApprove
>::get(), xCmdEnv
, &approve
, &abort
))
664 throw css::deployment::DeploymentException(
665 "Could not interact with user.", nullptr, Any());
670 } catch (const css::ucb::CommandFailedException
&) {
672 } catch (const css::ucb::CommandAbortedException
&) {
674 } catch (const css::deployment::DeploymentException
&) {
676 } catch (const css::uno::RuntimeException
&) {
678 } catch (const css::uno::Exception
&) {
679 Any anyExc
= cppu::getCaughtException();
680 throw css::deployment::DeploymentException("Unexpected exception", nullptr, anyExc
);
684 ::sal_Int32
BackendImpl::PackageImpl::checkPrerequisites(
685 const css::uno::Reference
< css::task::XAbortChannel
>&,
686 const css::uno::Reference
< css::ucb::XCommandEnvironment
>& xCmdEnv
,
687 sal_Bool alreadyInstalled
)
690 throw deployment::ExtensionRemovedException();
691 DescriptionInfoset info
= getDescriptionInfoset();
692 if (!info
.hasDescription())
695 //always return LICENSE as long as the user did not accept the license
696 //so that XExtensionManager::checkPrerequisitesAndEnable will again
698 if (!checkPlatform(xCmdEnv
))
699 return deployment::Prerequisites::PLATFORM
|
700 deployment::Prerequisites::LICENSE
;
701 else if(!checkDependencies(xCmdEnv
, info
))
702 return deployment::Prerequisites::DEPENDENCIES
|
703 deployment::Prerequisites::LICENSE
;
704 else if(!checkLicense(xCmdEnv
, info
, alreadyInstalled
))
705 return deployment::Prerequisites::LICENSE
;
710 sal_Bool
BackendImpl::PackageImpl::checkDependencies(
711 const css::uno::Reference
< css::ucb::XCommandEnvironment
>& xCmdEnv
)
714 throw deployment::ExtensionRemovedException();
715 DescriptionInfoset info
= getDescriptionInfoset();
716 if (!info
.hasDescription())
719 return checkDependencies(xCmdEnv
, info
);
722 beans::Optional
<OUString
> BackendImpl::PackageImpl::getIdentifier()
726 identifier
= m_identifier
;
728 identifier
= dp_misc::generateIdentifier(
729 getDescriptionInfoset().getIdentifier(), m_name
);
731 return beans::Optional
<OUString
>(
735 OUString
BackendImpl::PackageImpl::getVersion()
738 throw deployment::ExtensionRemovedException();
739 return getDescriptionInfoset().getVersion();
742 Sequence
<OUString
> BackendImpl::PackageImpl::getUpdateInformationURLs()
745 throw deployment::ExtensionRemovedException();
746 return getDescriptionInfoset().getUpdateInformationUrls();
749 beans::StringPair
BackendImpl::PackageImpl::getPublisherInfo()
752 throw deployment::ExtensionRemovedException();
753 std::pair
< OUString
, OUString
> aInfo
= getDescriptionInfoset().getLocalizedPublisherNameAndURL();
754 beans::StringPair
aStrPair( aInfo
.first
, aInfo
.second
);
759 uno::Reference
< graphic::XGraphic
> BackendImpl::PackageImpl::getIcon( sal_Bool bHighContrast
)
762 throw deployment::ExtensionRemovedException();
764 uno::Reference
< graphic::XGraphic
> xGraphic
;
766 OUString aIconURL
= getDescriptionInfoset().getIconURL( bHighContrast
);
767 if ( !aIconURL
.isEmpty() )
769 OUString aFullIconURL
= m_url_expanded
+ "/" + aIconURL
;
771 uno::Reference
< XComponentContext
> xContext( getMyBackend()->getComponentContext() );
772 uno::Reference
< graphic::XGraphicProvider
> xGraphProvider( graphic::GraphicProvider::create(xContext
) );
774 uno::Sequence
< beans::PropertyValue
> aMediaProps
{ comphelper::makePropertyValue(
775 "URL", aFullIconURL
) };
776 xGraphic
= xGraphProvider
->queryGraphic( aMediaProps
);
783 void BackendImpl::PackageImpl::processPackage_(
784 ::osl::ResettableMutexGuard
&,
785 bool doRegisterPackage
,
787 ::rtl::Reference
<AbortChannel
> const & abortChannel
,
788 Reference
<ucb::XCommandEnvironment
> const & xCmdEnv
)
790 const Sequence
< Reference
<deployment::XPackage
> > bundle(
791 getBundle( abortChannel
, xCmdEnv
) );
793 if (doRegisterPackage
)
795 ExtensionBackendDb::Data data
;
796 const sal_Int32 len
= bundle
.getLength();
797 for ( sal_Int32 pos
= 0; pos
< len
; ++pos
)
799 checkAborted(abortChannel
);
800 Reference
<deployment::XPackage
> const & xPackage
= bundle
[ pos
];
801 Reference
<task::XAbortChannel
> xSubAbortChannel(
802 xPackage
->createAbortChannel() );
803 AbortChannel::Chain
chain( abortChannel
, xSubAbortChannel
);
805 xPackage
->registerPackage( startup
, xSubAbortChannel
, xCmdEnv
);
807 catch (const Exception
&)
809 //We even try a rollback if the user cancelled the action (CommandAbortedException)
810 //in order to prevent invalid database entries.
811 Any
exc( ::cppu::getCaughtException() );
812 // try to handle exception, notify:
813 bool approve
= false, abort
= false;
814 if (! interactContinuation(
815 Any( lang::WrappedTargetException(
816 "bundle item registration error!",
817 static_cast<OWeakObject
*>(this), exc
) ),
818 cppu::UnoType
<task::XInteractionApprove
>::get(), xCmdEnv
,
819 &approve
, &abort
)) {
820 OSL_ASSERT( !approve
&& !abort
);
821 if (m_legacyBundle
) // default for legacy packages: ignore
823 // no selection at all, so rethrow;
824 // no C++ rethrow after getCaughtException(),
825 // see cppuhelper/exc_hlp.hxx:
826 ::cppu::throwException(exc
);
828 if (approve
&& !abort
) // ignore error, just continue
832 ProgressLevel
progress( xCmdEnv
, "rollback..." );
837 bundle
[ pos
]->revokePackage(
838 startup
, xSubAbortChannel
, xCmdEnv
);
840 catch (const Exception
&)
842 TOOLS_WARN_EXCEPTION( "desktop", "" );
843 // ignore any errors of rollback
846 progress
.update( "rollback finished." );
849 deployment::DeploymentException dpExc
;
851 throw ucb::CommandFailedException(
852 dpExc
.Message
, dpExc
.Context
, dpExc
.Cause
);
855 // rethrow CommandFailedException
856 ::cppu::throwException(exc
);
859 data
.items
.emplace_back(xPackage
->getURL(),
860 xPackage
->getPackageType()->getMediaType());
862 getMyBackend()->addDataToDb(getURL(), data
);
866 // revoke in reverse order:
867 for ( sal_Int32 pos
= bundle
.getLength(); pos
--; )
869 checkAborted(abortChannel
);
870 Reference
<deployment::XPackage
> const & xPackage
= bundle
[ pos
];
871 Reference
<task::XAbortChannel
> xSubAbortChannel(
872 xPackage
->createAbortChannel() );
873 AbortChannel::Chain
chain( abortChannel
, xSubAbortChannel
);
875 bundle
[ pos
]->revokePackage(
876 startup
, xSubAbortChannel
, xCmdEnv
);
878 catch (const RuntimeException
&) {
881 catch (const ucb::CommandAbortedException
&) {
884 catch (const Exception
&) {
885 // CommandFailedException, DeploymentException:
886 Any
exc( ::cppu::getCaughtException() );
887 // try to handle exception, notify:
888 bool approve
= false, abort
= false;
889 if (! interactContinuation(
890 Any( lang::WrappedTargetException(
891 "bundle item revocation error!",
892 static_cast<OWeakObject
*>(this), exc
) ),
893 cppu::UnoType
<task::XInteractionApprove
>::get(), xCmdEnv
,
894 &approve
, &abort
)) {
895 OSL_ASSERT( !approve
&& !abort
);
896 if (m_legacyBundle
) // default for legacy packages: ignore
898 // no selection at all, so rethrow
899 // no C++ rethrow after getCaughtException(),
900 // see cppuhelper/exc_hlp.hxx:
901 ::cppu::throwException(exc
);
903 // ignore errors when revoking, although abort may have been
907 getMyBackend()->revokeEntryFromDb(getURL());
912 OUString
BackendImpl::PackageImpl::getDescription()
915 throw deployment::ExtensionRemovedException();
917 const OUString
sRelativeURL(getDescriptionInfoset().getLocalizedDescriptionURL());
918 OUString sDescription
;
919 if (!sRelativeURL
.isEmpty())
921 OUString sURL
= m_url_expanded
+ "/" + sRelativeURL
;
925 sDescription
= getTextFromURL( css::uno::Reference
< css::ucb::XCommandEnvironment
>(), sURL
);
927 catch ( const css::deployment::DeploymentException
& )
929 TOOLS_WARN_EXCEPTION( "desktop", "" );
933 if (!sDescription
.isEmpty())
935 return m_oldDescription
;
939 OUString
BackendImpl::PackageImpl::getLicenseText()
942 throw deployment::ExtensionRemovedException();
945 DescriptionInfoset aInfo
= getDescriptionInfoset();
947 ::std::optional
< SimpleLicenseAttributes
> aSimplLicAttr
= aInfo
.getSimpleLicenseAttributes();
950 OUString aLicenseURL
= aInfo
.getLocalizedLicenseURL();
952 if ( !aLicenseURL
.isEmpty() )
954 OUString aFullURL
= m_url_expanded
+ "/" + aLicenseURL
;
955 sLicense
= getTextFromURL( Reference
< ucb::XCommandEnvironment
>(), aFullURL
);
963 void BackendImpl::PackageImpl::exportTo(
964 OUString
const & destFolderURL
, OUString
const & newTitle
,
965 sal_Int32 nameClashAction
, Reference
<ucb::XCommandEnvironment
> const & xCmdEnv
)
968 throw deployment::ExtensionRemovedException();
970 ::ucbhelper::Content
sourceContent(
971 m_url_expanded
, xCmdEnv
, getMyBackend()->getComponentContext() );
972 OUString
title(newTitle
);
974 sourceContent
.getPropertyValue( "Title" ) >>= title
;
975 OUString
destURL( makeURL( destFolderURL
, ::rtl::Uri::encode(
976 title
, rtl_UriCharClassPchar
,
977 rtl_UriEncodeIgnoreEscapes
,
978 RTL_TEXTENCODING_UTF8
) ) );
980 if (nameClashAction
== ucb::NameClash::ASK
)
982 if (create_ucb_content(
983 nullptr, destURL
, xCmdEnv
, false /* no throw */ )) {
984 bool replace
= false, abort
= false;
985 if (! interactContinuation(
986 Any( ucb::NameClashResolveRequest(
987 "file already exists: " + title
,
988 static_cast<OWeakObject
*>(this),
989 task::InteractionClassification_QUERY
,
990 destFolderURL
, title
, OUString() ) ),
991 cppu::UnoType
<ucb::XInteractionReplaceExistingData
>::get(), xCmdEnv
,
992 &replace
, &abort
) || !replace
) {
997 else if (nameClashAction
!= ucb::NameClash::OVERWRITE
) {
998 throw ucb::CommandFailedException("unsupported nameClashAction!",
999 static_cast<OWeakObject
*>(this), Any() );
1001 erase_path( destURL
, xCmdEnv
);
1003 OUString destFolder
=
1004 "vnd.sun.star.zip://" +
1005 ::rtl::Uri::encode( destURL
,
1006 rtl_UriCharClassRegName
,
1007 rtl_UriEncodeIgnoreEscapes
,
1008 RTL_TEXTENCODING_UTF8
) +
1011 ::ucbhelper::Content
destFolderContent(
1012 destFolder
, xCmdEnv
, getMyBackend()->getComponentContext() );
1014 // transfer every item of folder into zip:
1015 Reference
<sdbc::XResultSet
> xResultSet(
1016 sourceContent
.createCursor( Sequence
<OUString
>() ) );
1017 ProgressLevel
progress( xCmdEnv
, OUString() );
1018 while (xResultSet
->next())
1020 ::ucbhelper::Content
subContent(
1021 Reference
<ucb::XContentAccess
>(
1022 xResultSet
, UNO_QUERY_THROW
)->queryContent(),
1023 xCmdEnv
, getMyBackend()->getComponentContext() );
1024 destFolderContent
.transferContent(
1025 subContent
, ::ucbhelper::InsertOperation::Copy
,
1026 OUString(), ucb::NameClash::OVERWRITE
);
1027 progress
.update( Any() ); // animating progress bar
1031 // assure META-INF folder:
1032 ::ucbhelper::Content metainfFolderContent
;
1033 create_folder( &metainfFolderContent
,
1034 makeURL( destFolderContent
.getURL(), "META-INF" ),
1039 // easy to migrate legacy bundles to new format:
1040 // just export them once using a .oxt name!
1041 // set detected media-types of any bundle item:
1043 // collect all manifest entries:
1044 Sequence
< Reference
<deployment::XPackage
> > bundle
;
1046 bundle
= getBundle( Reference
<task::XAbortChannel
>(), xCmdEnv
);
1048 // xxx todo: think about exception specs:
1049 catch (const deployment::DeploymentException
&) {
1050 TOOLS_WARN_EXCEPTION( "desktop", "" );
1052 catch (const lang::IllegalArgumentException
&) {
1053 TOOLS_WARN_EXCEPTION( "desktop", "" );
1056 std::vector
< Sequence
<beans::PropertyValue
> > manifest
;
1057 manifest
.reserve( bundle
.getLength() );
1058 sal_Int32 baseURLlen
= m_url_expanded
.getLength();
1059 Reference
<deployment::XPackage
> const *pbundle
= bundle
.getConstArray();
1060 static const OUStringLiteral
strMediaType( u
"MediaType" );
1061 static const OUStringLiteral
strFullPath( u
"FullPath" );
1062 static const OUStringLiteral
strIsFolder( u
"IsFolder" );
1063 for ( sal_Int32 pos
= bundle
.getLength(); pos
--; )
1065 Reference
<deployment::XPackage
> const & xPackage
= pbundle
[ pos
];
1066 OUString
url_( expandUnoRcUrl( xPackage
->getURL() ) );
1067 OSL_ASSERT( url_
.getLength() >= baseURLlen
);
1069 if (url_
.getLength() > baseURLlen
)
1070 fullPath
= url_
.copy( baseURLlen
+ 1 );
1071 ::ucbhelper::Content
ucbContent(
1072 url_
, xCmdEnv
, getMyBackend()->getComponentContext() );
1073 if (ucbContent
.getPropertyValue(strIsFolder
).get
<bool>())
1075 Sequence
<beans::PropertyValue
> attribs( 2 );
1076 beans::PropertyValue
* pattribs
= attribs
.getArray();
1077 pattribs
[ 0 ].Name
= strFullPath
;
1078 pattribs
[ 0 ].Value
<<= fullPath
;
1079 pattribs
[ 1 ].Name
= strMediaType
;
1080 const Reference
<deployment::XPackageTypeInfo
> xPackageType(
1081 xPackage
->getPackageType() );
1083 OSL_ASSERT( xPackageType
.is() );
1084 if (xPackageType
.is())
1085 mediaType
= xPackageType
->getMediaType();
1087 mediaType
= "unknown";
1088 pattribs
[ 1 ].Value
<<= mediaType
;
1089 manifest
.push_back( attribs
);
1093 Reference
<XComponentContext
> xContext(
1094 getMyBackend()->getComponentContext() );
1095 Reference
<packages::manifest::XManifestWriter
> xManifestWriter
=
1096 packages::manifest::ManifestWriter::create( xContext
);
1097 Reference
<io::XOutputStream
> xPipe( io::Pipe::create(xContext
), UNO_QUERY_THROW
);
1098 xManifestWriter
->writeManifestSequence(
1099 xPipe
, comphelper::containerToSequence(manifest
) );
1101 // write buffered pipe data to content:
1102 ::ucbhelper::Content
manifestContent(
1103 makeURL( metainfFolderContent
.getURL(), "manifest.xml" ),
1104 xCmdEnv
, getMyBackend()->getComponentContext() );
1105 manifestContent
.writeStream(
1106 Reference
<io::XInputStream
>( xPipe
, UNO_QUERY_THROW
),
1107 true /* replace existing */ );
1111 bool bSuccess
= false;
1114 // overwrite manifest.xml:
1115 ::ucbhelper::Content manifestContent
;
1116 if ( ! create_ucb_content(
1118 makeURL( m_url_expanded
, "META-INF/manifest.xml" ),
1121 OSL_FAIL( "### missing META-INF/manifest.xml file!" );
1125 metainfFolderContent
.transferContent(
1126 manifestContent
, ::ucbhelper::InsertOperation::Copy
,
1127 OUString(), ucb::NameClash::OVERWRITE
);
1130 catch (const css::ucb::ContentCreationException
&)
1132 TOOLS_WARN_EXCEPTION("desktop.deployment", "exception on overwriting manifest");
1136 throw RuntimeException( "UCB transferContent() failed!",
1137 static_cast<OWeakObject
*>(this) );
1140 // xxx todo: maybe obsolete in the future
1142 destFolderContent
.executeCommand( "flush", Any() );
1144 catch (const ucb::UnsupportedCommandException
&) {
1149 sal_Bool
BackendImpl::PackageImpl::isBundle()
1155 Sequence
< Reference
<deployment::XPackage
> > BackendImpl::PackageImpl::getBundle(
1156 Reference
<task::XAbortChannel
> const & xAbortChannel
,
1157 Reference
<ucb::XCommandEnvironment
> const & xCmdEnv
)
1159 Sequence
< Reference
<deployment::XPackage
> > * pBundle
= m_pBundle
;
1160 if (pBundle
== nullptr)
1162 t_packagevec bundle
;
1165 bundle
= getPackagesFromDb(xCmdEnv
);
1172 // .zip legacy packages allow script.xlb, dialog.xlb in bundle
1175 // probe for script.xlb:
1176 if (create_ucb_content(
1177 nullptr, makeURL( m_url_expanded
, "script.xlb" ),
1178 xCmdEnv
, false /* no throw */ )) {
1179 mediaType
= "application/vnd.sun.star.basic-library";
1181 // probe for dialog.xlb:
1182 else if (create_ucb_content(
1183 nullptr, makeURL( m_url_expanded
, "dialog.xlb" ),
1184 xCmdEnv
, false /* no throw */ ))
1185 mediaType
= "application/vnd.sun.star.dialog-library";
1187 if (!mediaType
.isEmpty()) {
1188 const Reference
<deployment::XPackage
> xPackage(
1189 bindBundleItem( getURL(), mediaType
, false, OUString(),
1192 bundle
.push_back( xPackage
);
1193 // continue scanning:
1195 scanLegacyBundle( bundle
, getURL(),
1196 AbortChannel::get(xAbortChannel
), xCmdEnv
);
1201 scanBundle( bundle
, AbortChannel::get(xAbortChannel
), xCmdEnv
);
1205 catch (const RuntimeException
&) {
1208 catch (const ucb::CommandFailedException
&) {
1211 catch (const ucb::CommandAbortedException
&) {
1214 catch (const deployment::DeploymentException
&) {
1217 catch (const Exception
&) {
1218 Any
exc( ::cppu::getCaughtException() );
1219 throw deployment::DeploymentException(
1220 "error scanning bundle: " + getURL(),
1221 static_cast<OWeakObject
*>(this), exc
);
1225 // sort: schema before config data, typelibs before components:
1226 Sequence
< Reference
<deployment::XPackage
> > ret( bundle
.size() );
1227 Reference
<deployment::XPackage
> * pret
= ret
.getArray();
1228 sal_Int32 lower_end
= 0;
1229 sal_Int32 upper_end
= ret
.getLength();
1230 for (auto const& elem
: bundle
)
1232 const Reference
<deployment::XPackageTypeInfo
> xPackageType(
1233 elem
->getPackageType() );
1234 OSL_ASSERT( xPackageType
.is() );
1235 if (xPackageType
.is())
1237 const OUString
mediaType( xPackageType
->getMediaType() );
1238 OUString type
, subType
;
1239 INetContentTypeParameterList params
;
1240 if (INetContentTypes::parse( mediaType
, type
, subType
, ¶ms
) &&
1241 type
.equalsIgnoreAsciiCase("application") &&
1242 (subType
.equalsIgnoreAsciiCase( "vnd.sun.star.uno-component") ||
1243 subType
.equalsIgnoreAsciiCase( "vnd.sun.star.configuration-data")))
1246 pret
[ upper_end
] = elem
;
1250 pret
[ lower_end
] = elem
;
1253 OSL_ASSERT( lower_end
== upper_end
);
1255 const ::osl::MutexGuard
guard( m_aMutex
);
1256 pBundle
= m_pBundle
;
1257 if (pBundle
== nullptr) {
1259 pBundle
= &m_bundle
;
1260 OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
1261 m_pBundle
= pBundle
;
1265 OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
1270 bool isBundle_( std::u16string_view mediaType
)
1272 // xxx todo: additional parsing?
1273 return !mediaType
.empty() &&
1274 (o3tl::matchIgnoreAsciiCase( mediaType
, u
"application/vnd.sun.star.package-bundle") ||
1275 o3tl::matchIgnoreAsciiCase( mediaType
, u
"application/vnd.sun.star.legacy-package-bundle"));
1279 Reference
<deployment::XPackage
> BackendImpl::PackageImpl::bindBundleItem(
1280 OUString
const & url
, OUString
const & mediaType
,
1281 bool bRemoved
, OUString
const & identifier
,
1282 Reference
<ucb::XCommandEnvironment
> const & xCmdEnv
,
1283 bool notifyDetectionError
)
1285 // ignore any nested bundles:
1286 if (isBundle_(mediaType
))
1287 return Reference
<deployment::XPackage
>();
1289 Reference
<deployment::XPackage
>xPackage
;
1292 xPackage
.set( getMyBackend()->m_xRootRegistry
->bindPackage(
1293 url
, mediaType
, bRemoved
, identifier
, xCmdEnv
) );
1294 OSL_ASSERT( xPackage
.is() );
1295 } catch (css::lang::IllegalArgumentException
& e
) {
1296 css::uno::Any
exc(cppu::getCaughtException());
1297 throw css::lang::WrappedTargetException(
1298 "wrapped: " + e
.Message
, e
.Context
, exc
);
1301 catch (const RuntimeException
&) {
1304 catch (const ucb::CommandFailedException
&) {
1305 // ignore already handled error
1307 catch (const Exception
&) {
1308 const Any
exc( ::cppu::getCaughtException() );
1309 if (notifyDetectionError
||
1310 !exc
.isExtractableTo( cppu::UnoType
<lang::IllegalArgumentException
>::get()) )
1312 (void)interactContinuation(
1313 Any( lang::WrappedTargetException("bundle item error!",
1314 static_cast<OWeakObject
*>(this), exc
) ),
1315 cppu::UnoType
<task::XInteractionApprove
>::get(), xCmdEnv
, nullptr, nullptr );
1319 if (xPackage
.is()) {
1320 const Reference
<deployment::XPackageTypeInfo
> xPackageType(
1321 xPackage
->getPackageType() );
1322 OSL_ASSERT( xPackageType
.is() );
1323 // ignore any nested bundles:
1324 if (xPackageType
.is() && isBundle_( xPackageType
->getMediaType() ))
1331 void BackendImpl::PackageImpl::scanBundle(
1332 t_packagevec
& bundle
,
1333 ::rtl::Reference
<AbortChannel
> const & abortChannel
,
1334 Reference
<ucb::XCommandEnvironment
> const & xCmdEnv
)
1336 OSL_ASSERT( !m_legacyBundle
);
1338 OUString
mfUrl( makeURL( m_url_expanded
, "META-INF/manifest.xml" ) );
1339 ::ucbhelper::Content manifestContent
;
1340 if (! create_ucb_content(
1341 &manifestContent
, mfUrl
, xCmdEnv
, false /* no throw */ ))
1344 "desktop.deployment",
1345 "cannot create UCB Content for <" << mfUrl
<< ">" );
1350 const LanguageTag
& officeLocale
= getOfficeLanguageTag();
1351 const std::vector
< OUString
> officeFallbacks( officeLocale
.getFallbackStrings( true));
1352 const size_t nPenaltyMax
= std::numeric_limits
<size_t>::max();
1353 size_t descrPenalty
= nPenaltyMax
;
1356 const Reference
<XComponentContext
> xContext(
1357 getMyBackend()->getComponentContext() );
1358 Reference
<packages::manifest::XManifestReader
> xManifestReader
=
1359 packages::manifest::ManifestReader::create( xContext
);
1360 const Sequence
< Sequence
<beans::PropertyValue
> > manifestSeq(
1361 xManifestReader
->readManifestSequence( manifestContent
.openStream() ) );
1362 const OUString
packageRootURL( getURL() );
1363 for ( sal_Int32 pos
= manifestSeq
.getLength(); pos
--; )
1365 OUString fullPath
, mediaType
;
1366 Sequence
<beans::PropertyValue
> const & attribs
= manifestSeq
[ pos
];
1367 for ( sal_Int32 i
= attribs
.getLength(); i
--; )
1369 if (!(fullPath
.isEmpty() || mediaType
.isEmpty()))
1371 if ( attribs
[i
].Name
== "FullPath" )
1372 attribs
[i
].Value
>>= fullPath
;
1373 else if ( attribs
[i
].Name
== "MediaType" )
1374 attribs
[i
].Value
>>= mediaType
;
1377 if ( fullPath
.isEmpty() || mediaType
.isEmpty() || mediaType
== "text/xml" )// opt: exclude common text/xml
1380 OUString type
, subType
;
1381 INetContentTypeParameterList params
;
1382 if (! INetContentTypes::parse( mediaType
, type
, subType
, ¶ms
))
1386 auto const iter
= params
.find("platform");
1387 if (iter
!= params
.end() && !platform_fits(iter
->second
.m_sValue
))
1390 const OUString
url( makeURL( packageRootURL
, fullPath
) );
1392 // check for bundle description:
1393 if (type
.equalsIgnoreAsciiCase("application") &&
1394 subType
.equalsIgnoreAsciiCase( "vnd.sun.star.package-bundle-description"))
1397 auto const iter
= params
.find("locale");
1398 if (iter
== params
.end())
1400 if (descrFile
.isEmpty())
1404 // match best locale:
1405 LanguageTag
descrTag(iter
->second
.m_sValue
);
1406 if (officeLocale
.getLanguage() == descrTag
.getLanguage())
1408 size_t nPenalty
= nPenaltyMax
;
1409 const std::vector
< OUString
> descrFallbacks( descrTag
.getFallbackStrings( true));
1410 for (size_t o
=0; o
< officeFallbacks
.size() && nPenalty
== nPenaltyMax
; ++o
)
1412 for (size_t d
=0; d
< descrFallbacks
.size() && nPenalty
== nPenaltyMax
; ++d
)
1414 if (officeFallbacks
[o
] == descrFallbacks
[d
])
1416 // The last fallbacks are always language-only
1417 // fallbacks, so we _will_ have _some_ match if
1418 // we ever entered the overall if() condition.
1419 nPenalty
= o
* 1000 + d
;
1420 if (descrPenalty
> nPenalty
)
1422 descrPenalty
= nPenalty
;
1429 // TODO: we could break here if descrPenalty==0 for an exact
1430 // match of officeLocale, but the previous code didn't; are
1431 // there side effects?
1436 checkAborted( abortChannel
);
1438 //We make sure that we only create one XPackage for a particular URL.
1439 //Sometime programmers insert the same URL several times in the manifest
1440 //which may lead to DisposedExceptions.
1441 if (std::none_of(bundle
.begin(), bundle
.end(), XPackage_eq(url
)))
1443 const Reference
<deployment::XPackage
> xPackage(
1444 bindBundleItem( url
, mediaType
, false, OUString(), xCmdEnv
) );
1446 bundle
.push_back( xPackage
);
1450 SAL_WARN("desktop.deployment", "manifest.xml contains a duplicate entry (from " << url
<< ")");
1454 if (descrFile
.isEmpty())
1457 ::ucbhelper::Content descrFileContent
;
1458 if (!create_ucb_content( &descrFileContent
, descrFile
,
1459 xCmdEnv
, false /* no throw */ ))
1462 // patch description:
1463 std::vector
<sal_Int8
> bytes( readFile( descrFileContent
) );
1465 if ( !bytes
.empty() )
1467 buf
.append( OUString( reinterpret_cast<char const *>(
1469 bytes
.size(), RTL_TEXTENCODING_UTF8
) );
1473 buf
.append( Package::getDescription() );
1475 m_oldDescription
= buf
.makeStringAndClear();
1479 void BackendImpl::PackageImpl::scanLegacyBundle(
1480 t_packagevec
& bundle
,
1481 OUString
const & url
,
1482 ::rtl::Reference
<AbortChannel
> const & abortChannel
,
1483 Reference
<ucb::XCommandEnvironment
> const & xCmdEnv
,
1484 bool skip_registration
)
1486 ::ucbhelper::Content
ucbContent(
1487 url
, xCmdEnv
, getMyBackend()->getComponentContext() );
1489 // check for platform paths:
1490 const OUString
title( StrTitle::getTitle( ucbContent
) );
1491 if (title
.endsWithIgnoreAsciiCase( ".plt" ) &&
1492 !platform_fits( title
.subView( 0, title
.getLength() - 4 ) )) {
1495 if (title
.endsWithIgnoreAsciiCase("skip_registration") )
1496 skip_registration
= true;
1498 Sequence
<OUString
> ar
{ OUString("Title"), OUString("IsFolder") };
1499 Reference
<sdbc::XResultSet
> xResultSet( ucbContent
.createCursor( ar
) );
1500 while (xResultSet
->next())
1502 checkAborted( abortChannel
);
1504 const Reference
<sdbc::XRow
> xRow( xResultSet
, UNO_QUERY_THROW
);
1505 const OUString
title_enc( ::rtl::Uri::encode(
1506 xRow
->getString( 1 /* Title */ ),
1507 rtl_UriCharClassPchar
,
1508 rtl_UriEncodeIgnoreEscapes
,
1509 RTL_TEXTENCODING_UTF8
) );
1510 const OUString
path( makeURL( url
, title_enc
) );
1513 const Reference
<deployment::XPackage
> xPackage(
1514 bindBundleItem( path
, OUString() /* detect */, false, OUString(),
1515 xCmdEnv
, false /* ignore detection errors */ ) );
1516 if (xPackage
.is()) {
1517 const Reference
<deployment::XPackageTypeInfo
> xPackageType(
1518 xPackage
->getPackageType() );
1519 OSL_ASSERT( xPackageType
.is() );
1520 if (xPackageType
.is())
1521 mediaType
= xPackageType
->getMediaType();
1523 if (skip_registration
&&
1524 // xxx todo: additional parsing?
1525 mediaType
.matchIgnoreAsciiCase("application/vnd.sun.star.uno-component"))
1528 bundle
.push_back( xPackage
);
1531 if (mediaType
.isEmpty() ||
1532 // script.xlb, dialog.xlb can be met everywhere:
1533 mediaType
.matchIgnoreAsciiCase("application/vnd.sun.star.basic-library") ||
1534 mediaType
.matchIgnoreAsciiCase("application/vnd.sun.star.dialog-library"))
1536 if (xRow
->getBoolean( 2 /* IsFolder */ )) { // recurse into folder:
1538 bundle
, path
, abortChannel
, xCmdEnv
, skip_registration
);
1544 OUString
BackendImpl::PackageImpl::getDisplayName()
1547 throw deployment::ExtensionRemovedException();
1549 OUString sName
= getDescriptionInfoset().getLocalizedDisplayName();
1550 if (sName
.isEmpty())
1551 return m_displayName
;
1556 std::vector
<Reference
<deployment::XPackage
> >
1557 BackendImpl::PackageImpl::getPackagesFromDb(
1558 Reference
<ucb::XCommandEnvironment
> const & xCmdEnv
)
1560 std::vector
<Reference
<deployment::XPackage
> > retVector
;
1562 for (auto const& item
: m_dbData
.items
)
1564 Reference
<deployment::XPackage
> xExtension
=
1565 bindBundleItem(item
.first
, item
.second
, true, m_identifier
, xCmdEnv
);
1566 OSL_ASSERT(xExtension
.is());
1567 if (xExtension
.is())
1568 retVector
.push_back(xExtension
);
1577 Reference
<deployment::XPackageRegistry
> create(
1578 Reference
<deployment::XPackageRegistry
> const & xRootRegistry
,
1579 OUString
const & context
, OUString
const & cachePath
,
1580 Reference
<XComponentContext
> const & xComponentContext
)
1582 Sequence
<Any
> args(cachePath
.isEmpty() ? 1 : 3 );
1583 auto pArgs
= args
.getArray();
1584 pArgs
[ 0 ] <<= context
;
1585 if (!cachePath
.isEmpty()) {
1586 pArgs
[ 1 ] <<= cachePath
;
1587 pArgs
[ 2 ] <<= false; // readOnly
1589 return new BackendImpl( args
, xComponentContext
, xRootRegistry
);
1592 } // namespace dp_registry
1594 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */