23#include <osl/file.hxx>
31#include <com/sun/star/task/XInteractionApprove.hpp>
32#include <com/sun/star/ucb/CommandAbortedException.hpp>
33#include <com/sun/star/ucb/XCommandEnvironment.hpp>
34#include <com/sun/star/ucb/SimpleFileAccess.hpp>
35#include <com/sun/star/xml/xpath/XPathAPI.hpp>
36#include <com/sun/star/xml/xpath/XPathException.hpp>
37#include <com/sun/star/xml/dom/DOMException.hpp>
38#include <com/sun/star/xml/dom/DocumentBuilder.hpp>
39#include <com/sun/star/beans/NamedValue.hpp>
40#include <com/sun/star/deployment/ExtensionManager.hpp>
41#include <com/sun/star/deployment/XExtensionManager.hpp>
64 osl::Directory aScanRootDir( sSourceDir );
65 osl::FileStatus
fs(osl_FileStatus_Mask_Type | osl_FileStatus_Mask_FileURL);
66 osl::FileBase::RC nRetCode = aScanRootDir.open();
67 if ( nRetCode != osl::Directory::E_None )
70 sal_uInt32 nHint( 0 );
71 osl::DirectoryItem aItem;
72 while ( aScanRootDir.getNextItem( aItem, nHint ) == osl::Directory::E_None )
74 if (( aItem.getFileStatus(
fs) == osl::FileBase::E_None ) &&
75 (
fs.getFileType() == osl::FileStatus::Directory ))
78 OUString sExtensionFolderURL =
fs.getFileURL();
80 osl::Directory aExtensionRootDir( sExtensionFolderURL );
82 nRetCode = aExtensionRootDir.open();
83 if ( nRetCode == osl::Directory::E_None )
85 osl::DirectoryItem aExtDirItem;
86 while ( aExtensionRootDir.getNextItem( aExtDirItem, nHint ) == osl::Directory::E_None )
88 bool bFileStatus = aExtDirItem.getFileStatus(
fs) == osl::FileBase::E_None;
89 bool bIsDir =
fs.getFileType() == osl::FileStatus::Directory;
91 if ( bFileStatus && bIsDir )
93 sExtensionFolderURL =
fs.getFileURL();
96 aMigrateExtensions.push_back( sExtensionFolderURL );
108 osl::Directory aDir(sExtFolder);
111 if (aDir.open() == osl::FileBase::E_None)
114 osl::DirectoryItem item;
115 osl::FileStatus
fs(osl_FileStatus_Mask_Type | osl_FileStatus_Mask_FileURL);
117 while ((aDir.getNextItem(item) == osl::FileBase::E_None ) &&
120 if (item.getFileStatus(
fs) == osl::FileBase::E_None)
122 if (
fs.getFileType() == osl::FileStatus::Directory)
123 aDirectories.push_back(
fs.getFileURL() );
126 OUString aDirEntryURL =
fs.getFileURL();
127 if ( aDirEntryURL.indexOf(
"/description.xml" ) > 0 )
133 for (
auto const& directory : aDirectories)
155 OUString aExtIdentifier;
167 if ( xRoot.is() && xRoot->getTagName() ==
"description" )
171 xPath->registerNS(
"desc", xRoot->getNamespaceURI());
172 xPath->registerNS(
"xlink",
"http://www.w3.org/1999/xlink");
177 xPath->selectSingleNode(
178 xRoot,
"desc:identifier/@value" ));
180 aExtIdentifier = xNode->getNodeValue();
182 catch (
const xml::xpath::XPathException& )
185 catch (
const xml::dom::DOMException& )
192 if ( !aExtIdentifier.isEmpty() )
201 sal_Int32
end = aExtIdentifier.getLength();
207 catch (
const ucb::CommandAbortedException& )
210 catch (
const uno::RuntimeException& )
214 if ( aExtIdentifier.isEmpty() )
226 sal_Int32
end = sDescriptionXmlURL.getLength();
237 css::uno::Reference< css::deployment::XExtensionManager > extMgr(
238 deployment::ExtensionManager::get(
m_ctx ) );
244 extMgr->addExtension(
246 xAbortChannel, pCmdEnv );
248 catch ( css::uno::Exception & )
252 "Ignoring UNO Exception while migrating extension from <" << sSourceDir <<
">");
262 return "com.sun.star.comp.desktop.migration.OOo3Extensions";
274 return {
"com.sun.star.migration.Extensions" };
283 ::osl::MutexGuard aGuard(
m_aMutex );
287 for ( ; pIter != pEnd ; ++pIter )
289 beans::NamedValue aValue;
291 if ( aValue.Name ==
"UserData" )
295 OSL_FAIL(
"ExtensionMigration::initialize: argument UserData has wrong type!" );
298 else if ( aValue.Name ==
"ExtensionDenyList" )
301 if ( (aValue.Value >>= aDenyList ) && aDenyList.hasElements())
304 ::comphelper::sequenceToArray< OUString >(
m_aDenyList.data(), aDenyList );
312 ::osl::MutexGuard aGuard(
m_aMutex );
319 "/user/uno_packages/cache/uno_packages";
322 for (
auto const& extensionToMigrate : aExtensionToMigrate)
359 OSL_ASSERT( xRequest->getRequest().getValueTypeClass() == uno::TypeClass_EXCEPTION );
365 xRequest->getContinuations() );
366 Reference< task::XInteractionContinuation >
const * pConts =
367 conts.getConstArray();
368 sal_Int32 len = conts.getLength();
369 for ( sal_Int32 pos = 0;
pos < len; ++
pos )
373 pConts[ pos ], uno::UNO_QUERY );
374 if (xInteractionApprove.is()) {
375 xInteractionApprove->select();
401extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
403 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any>
const&)
css::uno::Reference< css::uno::XComponentContext > m_ctx
virtual sal_Bool SAL_CALL supportsService(const OUString &rServiceName) override
css::uno::Reference< css::ucb::XSimpleFileAccess3 > m_xSimpleFileAccess
virtual ~OO3ExtensionMigration() override
void migrateExtension(const OUString &sSourceDir)
ScanResult scanExtensionFolder(const OUString &sExtFolder)
css::uno::Reference< css::xml::dom::XDocumentBuilder > m_xDocBuilder
virtual OUString SAL_CALL getImplementationName() override
void scanUserExtensions(const OUString &sSourceDir, TStringVector &aMigrateExtensions)
TStringVector m_aDenyList
OO3ExtensionMigration(css::uno::Reference< css::uno::XComponentContext > const &ctx)
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
bool scanDescriptionXml(const OUString &sDescriptionXmlFilePath)
@ SCANRESULT_DONTMIGRATE_EXTENSION
@ SCANRESULT_MIGRATE_EXTENSION
virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any > &aArguments) override
virtual css::uno::Any SAL_CALL execute(const css::uno::Sequence< css::beans::NamedValue > &Arguments) override
virtual css::uno::Reference< css::task::XInteractionHandler > SAL_CALL getInteractionHandler() override
TmpRepositoryCommandEnv()
virtual void SAL_CALL push(css::uno::Any const &Status) override
virtual void SAL_CALL pop() override
virtual void SAL_CALL handle(css::uno::Reference< css::task::XInteractionRequest > const &xRequest) override
virtual ~TmpRepositoryCommandEnv() override
virtual void SAL_CALL update(css::uno::Any const &Status) override
virtual css::uno::Reference< css::ucb::XProgressHandler > SAL_CALL getProgressHandler() override
static PathStatus locateUserInstallation(OUString &_rURL)
bool SearchForward(const OUString &rStr, sal_Int32 *pStart, sal_Int32 *pEnd, css::util::SearchResult *pRes=nullptr)
#define TOOLS_WARN_EXCEPTION(area, stream)
Sequence< PropertyValue > aArguments
#define LANGUAGE_DONTKNOW
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
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)
std::vector< OUString > TStringVector
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * desktop_OO3ExtensionMigration_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)