20#include <config_folders.h>
27#include <com/sun/star/ucb/CommandAbortedException.hpp>
28#include <com/sun/star/ucb/CommandFailedException.hpp>
29#include <osl/diagnose.h>
30#include <rtl/bootstrap.hxx>
40int determineHighestVersion(
41 OUString
const & userVersion,
42 OUString
const & sharedVersion,
43 OUString
const & bundledVersion,
44 std::u16string_view onlineVersion)
47 OUString greatest = userVersion;
51 greatest = sharedVersion;
56 greatest = bundledVersion;
65Sequence< Reference< xml::dom::XElement > >
66getUpdateInformation( Reference<deployment::XUpdateInformationProvider >
const & updateInformation,
68 OUString
const & identifier,
72 return updateInformation->getUpdateInformation(urls, identifier);
73 }
catch (
const uno::RuntimeException &) {
75 }
catch (
const ucb::CommandFailedException & e) {
77 }
catch (
const ucb::CommandAbortedException &) {
78 }
catch (
const uno::Exception & e) {
82 Sequence<Reference< xml::dom::XElement > >();
85void getOwnUpdateInfos(
86 Reference<uno::XComponentContext>
const &
xContext,
87 Reference<deployment::XUpdateInformationProvider >
const & updateInformation,
88 UpdateInfoMap& inout_map, std::vector<std::pair<Reference<deployment::XPackage>,
uno::Any> > & out_errors,
91 bool bAllHaveOwnUpdateInformation =
true;
92 for (
auto & inout : inout_map)
94 OSL_ASSERT(inout.second.extension.is());
95 Sequence<OUString> urls(inout.second.extension->getUpdateInformationURLs());
96 if (urls.hasElements())
99 SAL_INFO(
"extensions.update",
"Searching update for " << search_id );
103 const Sequence<Reference< xml::dom::XElement > >
104 infos(getUpdateInformation(updateInformation, urls, search_id, anyError));
106 out_errors.emplace_back(inout.second.extension, anyError);
108 for (
const Reference< xml::dom::XElement >& element : infos)
112 Reference< xml::dom::XNode >(element, UNO_QUERY_THROW));
113 if (!infoset.hasDescription())
115 std::optional< OUString > result_id(infoset.getIdentifier());
118 SAL_INFO(
"extensions.update",
" found version "
119 << infoset.getVersion() <<
" for " << *result_id );
120 if (*result_id != search_id)
122 inout.second.version = infoset.getVersion();
123 inout.second.info.set(element, UNO_QUERY_THROW);
129 bAllHaveOwnUpdateInformation =
false;
132 out_allFound = bAllHaveOwnUpdateInformation;
135void getDefaultUpdateInfos(
136 Reference<uno::XComponentContext>
const &
xContext,
137 Reference<deployment::XUpdateInformationProvider >
const & updateInformation,
139 std::vector<std::pair<Reference<deployment::XPackage>,
uno::Any> > & out_errors)
142 OSL_ASSERT(!sDefaultURL.isEmpty());
145 const Sequence< Reference< xml::dom::XElement > >
147 getUpdateInformation(
150 if (anyError.hasValue())
151 out_errors.emplace_back(Reference<deployment::XPackage>(), anyError);
152 for (
const Reference< xml::dom::XElement >& element : infos)
154 Reference< xml::dom::XNode > node(element, UNO_QUERY_THROW);
156 std::optional< OUString > id(infoset.getIdentifier());
160 UpdateInfoMap::iterator j = inout_map.find(*
id);
161 if (j != inout_map.end())
164 if (j->second.extension->getUpdateInformationURLs().getLength())
166 OUString
v(infoset.getVersion());
171 j->second.version =
v;
172 j->second.info = node;
178bool containsBundledOnly(Sequence<Reference<deployment::XPackage> >
const & sameIdExtensions)
180 OSL_ASSERT(sameIdExtensions.getLength() == 3);
181 return !sameIdExtensions[0].is() && !sameIdExtensions[1].is() && sameIdExtensions[2].is();
188bool onlyBundledExtensions(
189 Reference<deployment::XExtensionManager>
const & xExtMgr,
190 std::vector< Reference<deployment::XPackage > >
const * extensionList)
192 OSL_ASSERT(xExtMgr.is());
193 bool bOnlyBundled =
true;
196 for (
auto const& elem : *extensionList)
198 Sequence<Reference<deployment::XPackage> > seqExt = xExtMgr->getExtensionsWithSameIdentifier(
201 bOnlyBundled = containsBundledOnly(seqExt);
209 xExtMgr->getAllExtensions(Reference<task::XAbortChannel>(), Reference<ucb::XCommandEnvironment>());
211 for (
int pos(0), nLen(seqAllExt.getLength()); bOnlyBundled && pos != nLen; ++pos)
213 bOnlyBundled = containsBundledOnly(seqAllExt[pos]);
225 "${$BRAND_BASE_DIR/" LIBO_ETC_FOLDER
"/" SAL_CONFIGFILE(
"version")
226 ":Version:ExtensionUpdateURL}");
227 ::rtl::Bootstrap::expandMacros(sUrl);
235 bool bReadOnlyShared,
236 OUString
const & userVersion,
237 OUString
const & sharedVersion,
238 OUString
const & bundledVersion,
239 std::u16string_view onlineVersion)
244 if (!userVersion.isEmpty())
246 int index = determineHighestVersion(
247 userVersion, sharedVersion, bundledVersion, onlineVersion);
255 else if (!sharedVersion.isEmpty())
257 int index = determineHighestVersion(
258 OUString(), sharedVersion, bundledVersion, onlineVersion);
268 if (!userVersion.isEmpty())
270 int index = determineHighestVersion(
271 userVersion, sharedVersion, bundledVersion, onlineVersion);
285 bool bReadOnlyShared,
286 OUString
const & sharedVersion,
287 OUString
const & bundledVersion,
288 std::u16string_view onlineVersion)
294 if (!sharedVersion.isEmpty())
296 int index = determineHighestVersion(
297 OUString(), sharedVersion, bundledVersion, onlineVersion);
306Reference<deployment::XPackage>
308 Sequence<Reference<deployment::XPackage> >
const & seqExt)
310 if (!seqExt.hasElements())
311 return Reference<deployment::XPackage>();
313 Reference<deployment::XPackage> greatest;
314 sal_Int32 len = seqExt.getLength();
316 for (sal_Int32
i = 0;
i < len;
i++)
320 greatest = seqExt[
i];
323 Reference<deployment::XPackage>
const & current = seqExt[
i];
341 Reference<uno::XComponentContext>
const &
xContext,
342 Reference<deployment::XExtensionManager>
const & xExtMgr,
343 Reference<deployment::XUpdateInformationProvider >
const & updateInformation,
344 std::vector<Reference<deployment::XPackage > >
const * extensionList,
345 std::vector<std::pair< Reference<deployment::XPackage>,
uno::Any> > & out_errors)
347 OSL_ASSERT(xExtMgr.is());
349 if (!xExtMgr.is() || onlyBundledExtensions(xExtMgr, extensionList))
355 Reference<task::XAbortChannel>(), Reference<ucb::XCommandEnvironment>());
358 for (
int pos = seqAllExt.getLength();
pos --; )
363 OSL_ASSERT(extension.is());
365 std::pair<UpdateInfoMap::iterator, bool> insertRet = infoMap.emplace(
367 OSL_ASSERT(insertRet.second);
372 for (
auto const& elem : *extensionList)
374 OSL_ASSERT(elem.is());
375 std::pair<UpdateInfoMap::iterator, bool> insertRet = infoMap.emplace(
377 OSL_ASSERT(insertRet.second);
383 bool bAllInfosObtained =
false;
384 getOwnUpdateInfos(
xContext, updateInformation, infoMap, out_errors, bAllInfosObtained);
386 if (!bAllInfosObtained)
387 getDefaultUpdateInfos(
xContext, updateInformation, infoMap, out_errors);
391 OUString
const & sharedVersion,
392 OUString
const & bundledVersion,
393 OUString
const & onlineVersion)
395 int index = determineHighestVersion(OUString(), sharedVersion, bundledVersion, onlineVersion);
398 case 1:
return sharedVersion;
399 case 2:
return bundledVersion;
400 case 3:
return onlineVersion;
401 default: OSL_ASSERT(
false);
Access to the content of an XML description element.
#define SAL_CONFIGFILE(name)
static uno::Reference< css::uno::XComponentContext > xContext
#define SAL_INFO(area, stream)
std::map< OUString, UpdateInfo > UpdateInfoMap
DESKTOP_DEPLOYMENTMISC_DLLPUBLIC OUString getExtensionDefaultUpdateURL()
returns the default update URL (for the update information) which is used when an extension does not ...
DESKTOP_DEPLOYMENTMISC_DLLPUBLIC OUString getHighestVersion(OUString const &sharedVersion, OUString const &bundledVersion, OUString const &onlineVersion)
DESKTOP_DEPLOYMENTMISC_DLLPUBLIC UPDATE_SOURCE isUpdateUserExtension(bool bReadOnlyShared, OUString const &userVersion, OUString const &sharedVersion, OUString const &bundledVersion, std::u16string_view onlineVersion)
DESKTOP_DEPLOYMENTMISC_DLLPUBLIC UPDATE_SOURCE isUpdateSharedExtension(bool bReadOnlyShared, OUString const &sharedVersion, OUString const &bundledVersion, std::u16string_view onlineVersion)
DESKTOP_DEPLOYMENTMISC_DLLPUBLIC Order compareVersions(std::u16string_view version1, std::u16string_view version2)
DESKTOP_DEPLOYMENTMISC_DLLPUBLIC css::uno::Reference< css::deployment::XPackage > getExtensionWithHighestVersion(css::uno::Sequence< css::uno::Reference< css::deployment::XPackage > > const &seqExtensionsWithSameId)
DESKTOP_DEPLOYMENTMISC_DLLPUBLIC OUString getIdentifier(css::uno::Reference< css::deployment::XPackage > const &package)
Gets the identifier of a package.
DESKTOP_DEPLOYMENTMISC_DLLPUBLIC UpdateInfoMap getOnlineUpdateInfos(css::uno::Reference< css::uno::XComponentContext > const &xContext, css::uno::Reference< css::deployment::XExtensionManager > const &xExtMgr, css::uno::Reference< css::deployment::XUpdateInformationProvider > const &updateInformation, std::vector< css::uno::Reference< css::deployment::XPackage > > const *extensionList, std::vector< std::pair< css::uno::Reference< css::deployment::XPackage >, css::uno::Any > > &out_errors)
UpdateInfo(css::uno::Reference< css::deployment::XPackage > const &ext)