12722ceddSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 32722ceddSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 42722ceddSAndrew Rist * or more contributor license agreements. See the NOTICE file 52722ceddSAndrew Rist * distributed with this work for additional information 62722ceddSAndrew Rist * regarding copyright ownership. The ASF licenses this file 72722ceddSAndrew Rist * to you under the Apache License, Version 2.0 (the 82722ceddSAndrew Rist * "License"); you may not use this file except in compliance 92722ceddSAndrew Rist * with the License. You may obtain a copy of the License at 102722ceddSAndrew Rist * 112722ceddSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 122722ceddSAndrew Rist * 132722ceddSAndrew Rist * Unless required by applicable law or agreed to in writing, 142722ceddSAndrew Rist * software distributed under the License is distributed on an 152722ceddSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 162722ceddSAndrew Rist * KIND, either express or implied. See the License for the 172722ceddSAndrew Rist * specific language governing permissions and limitations 182722ceddSAndrew Rist * under the License. 192722ceddSAndrew Rist * 202722ceddSAndrew Rist *************************************************************/ 212722ceddSAndrew Rist 222722ceddSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_desktop.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include "oo3extensionmigration.hxx" 28cdf0e10cSrcweir #include <rtl/instance.hxx> 29cdf0e10cSrcweir #include <osl/file.hxx> 30cdf0e10cSrcweir #include <osl/thread.h> 31cdf0e10cSrcweir #include <tools/urlobj.hxx> 32cdf0e10cSrcweir #include <unotools/bootstrap.hxx> 33cdf0e10cSrcweir #include <unotools/ucbstreamhelper.hxx> 34cdf0e10cSrcweir #include <unotools/textsearch.hxx> 35cdf0e10cSrcweir #include <comphelper/sequence.hxx> 36cdf0e10cSrcweir #include <comphelper/processfactory.hxx> 37cdf0e10cSrcweir #include <ucbhelper/content.hxx> 38cdf0e10cSrcweir 39cdf0e10cSrcweir #include <com/sun/star/task/XInteractionApprove.hpp> 40cdf0e10cSrcweir #include <com/sun/star/task/XInteractionAbort.hpp> 41cdf0e10cSrcweir #include <com/sun/star/ucb/XCommandInfo.hpp> 42cdf0e10cSrcweir #include <com/sun/star/ucb/TransferInfo.hpp> 43cdf0e10cSrcweir #include <com/sun/star/ucb/NameClash.hpp> 44cdf0e10cSrcweir #include <com/sun/star/ucb/XCommandEnvironment.hpp> 45cdf0e10cSrcweir #include <com/sun/star/xml/xpath/XXPathAPI.hpp> 46cdf0e10cSrcweir #include <com/sun/star/beans/NamedValue.hpp> 47cdf0e10cSrcweir #include <com/sun/star/deployment/ExtensionManager.hpp> 48cdf0e10cSrcweir 49*5e679a6cSOliver-Rainer Wittmann #include <com/sun/star/deployment/VersionException.hpp> 50*5e679a6cSOliver-Rainer Wittmann #include <dp_gui_handleversionexception.hxx> 51*5e679a6cSOliver-Rainer Wittmann 52cdf0e10cSrcweir using namespace ::com::sun::star; 53cdf0e10cSrcweir using namespace ::com::sun::star::uno; 54cdf0e10cSrcweir 55cdf0e10cSrcweir namespace migration 56cdf0e10cSrcweir { 57cdf0e10cSrcweir 58cdf0e10cSrcweir static ::rtl::OUString sExtensionSubDir = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/user/uno_packages/" ) ); 59cdf0e10cSrcweir static ::rtl::OUString sSubDirName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "cache" ) ); 60cdf0e10cSrcweir static ::rtl::OUString sConfigDir = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/user/registry/data" ) ); 61cdf0e10cSrcweir static ::rtl::OUString sOrgDir = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/user/registry/data/org" ) ); 62cdf0e10cSrcweir static ::rtl::OUString sExcludeDir1 = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/user/registry/data/org" ) ); 63cdf0e10cSrcweir static ::rtl::OUString sExcludeDir2 = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/user/registry/data/org/openoffice" ) ); 64cdf0e10cSrcweir static ::rtl::OUString sDescriptionXmlFile = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/description.xml" ) ); 65cdf0e10cSrcweir static ::rtl::OUString sExtensionRootSubDirName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/uno_packages" ) ); 66cdf0e10cSrcweir 67cdf0e10cSrcweir static ::rtl::OUString sConfigurationDataType = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("application/vnd.sun.star.configuration-data")); 68cdf0e10cSrcweir static ::rtl::OUString sConfigurationSchemaType = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("application/vnd.sun.star.configuration-schema")); 69cdf0e10cSrcweir 70cdf0e10cSrcweir // ============================================================================= 71cdf0e10cSrcweir // component operations 72cdf0e10cSrcweir // ============================================================================= 73cdf0e10cSrcweir 74cdf0e10cSrcweir ::rtl::OUString OO3ExtensionMigration_getImplementationName() 75cdf0e10cSrcweir { 76cdf0e10cSrcweir static ::rtl::OUString* pImplName = 0; 77cdf0e10cSrcweir if ( !pImplName ) 78cdf0e10cSrcweir { 79cdf0e10cSrcweir ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); 80cdf0e10cSrcweir if ( !pImplName ) 81cdf0e10cSrcweir { 82cdf0e10cSrcweir static ::rtl::OUString aImplName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.desktop.migration.OOo3Extensions" ) ); 83cdf0e10cSrcweir pImplName = &aImplName; 84cdf0e10cSrcweir } 85cdf0e10cSrcweir } 86cdf0e10cSrcweir return *pImplName; 87cdf0e10cSrcweir } 88cdf0e10cSrcweir 89cdf0e10cSrcweir // ----------------------------------------------------------------------------- 90cdf0e10cSrcweir 91cdf0e10cSrcweir Sequence< ::rtl::OUString > OO3ExtensionMigration_getSupportedServiceNames() 92cdf0e10cSrcweir { 93cdf0e10cSrcweir static Sequence< ::rtl::OUString >* pNames = 0; 94cdf0e10cSrcweir if ( !pNames ) 95cdf0e10cSrcweir { 96cdf0e10cSrcweir ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); 97cdf0e10cSrcweir if ( !pNames ) 98cdf0e10cSrcweir { 99cdf0e10cSrcweir static Sequence< ::rtl::OUString > aNames(1); 100cdf0e10cSrcweir aNames.getArray()[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.migration.Extensions" ) ); 101cdf0e10cSrcweir pNames = &aNames; 102cdf0e10cSrcweir } 103cdf0e10cSrcweir } 104cdf0e10cSrcweir return *pNames; 105cdf0e10cSrcweir } 106cdf0e10cSrcweir 107cdf0e10cSrcweir // ============================================================================= 108cdf0e10cSrcweir // ExtensionMigration 109cdf0e10cSrcweir // ============================================================================= 110cdf0e10cSrcweir 111cdf0e10cSrcweir OO3ExtensionMigration::OO3ExtensionMigration(Reference< XComponentContext > const & ctx) : 112cdf0e10cSrcweir m_ctx(ctx) 113cdf0e10cSrcweir { 114cdf0e10cSrcweir } 115cdf0e10cSrcweir 116cdf0e10cSrcweir // ----------------------------------------------------------------------------- 117cdf0e10cSrcweir 118cdf0e10cSrcweir OO3ExtensionMigration::~OO3ExtensionMigration() 119cdf0e10cSrcweir { 120cdf0e10cSrcweir } 121cdf0e10cSrcweir 122cdf0e10cSrcweir ::osl::FileBase::RC OO3ExtensionMigration::checkAndCreateDirectory( INetURLObject& rDirURL ) 123cdf0e10cSrcweir { 124cdf0e10cSrcweir ::osl::FileBase::RC aResult = ::osl::Directory::create( rDirURL.GetMainURL( INetURLObject::DECODE_TO_IURI ) ); 125cdf0e10cSrcweir if ( aResult == ::osl::FileBase::E_NOENT ) 126cdf0e10cSrcweir { 127cdf0e10cSrcweir INetURLObject aBaseURL( rDirURL ); 128cdf0e10cSrcweir aBaseURL.removeSegment(); 129cdf0e10cSrcweir checkAndCreateDirectory( aBaseURL ); 130cdf0e10cSrcweir return ::osl::Directory::create( rDirURL.GetMainURL( INetURLObject::DECODE_TO_IURI ) ); 131cdf0e10cSrcweir } 132cdf0e10cSrcweir else 133cdf0e10cSrcweir { 134cdf0e10cSrcweir return aResult; 135cdf0e10cSrcweir } 136cdf0e10cSrcweir } 137cdf0e10cSrcweir 138cdf0e10cSrcweir void OO3ExtensionMigration::scanUserExtensions( const ::rtl::OUString& sSourceDir, TStringVector& aMigrateExtensions ) 139cdf0e10cSrcweir { 140cdf0e10cSrcweir osl::Directory aScanRootDir( sSourceDir ); 141cdf0e10cSrcweir osl::FileStatus fs(FileStatusMask_Type | FileStatusMask_FileURL); 142cdf0e10cSrcweir osl::FileBase::RC nRetCode = aScanRootDir.open(); 143cdf0e10cSrcweir if ( nRetCode == osl::Directory::E_None ) 144cdf0e10cSrcweir { 145cdf0e10cSrcweir sal_uInt32 nHint( 0 ); 146cdf0e10cSrcweir osl::DirectoryItem aItem; 147cdf0e10cSrcweir while ( aScanRootDir.getNextItem( aItem, nHint ) == osl::Directory::E_None ) 148cdf0e10cSrcweir { 149cdf0e10cSrcweir if (( aItem.getFileStatus(fs) == osl::FileBase::E_None ) && 150cdf0e10cSrcweir ( fs.getFileType() == osl::FileStatus::Directory )) 151cdf0e10cSrcweir { 152cdf0e10cSrcweir //Check next folder as the "real" extension folder is below a temp folder! 153cdf0e10cSrcweir ::rtl::OUString sExtensionFolderURL = fs.getFileURL(); 154cdf0e10cSrcweir 155cdf0e10cSrcweir osl::DirectoryItem aExtDirItem; 156cdf0e10cSrcweir osl::Directory aExtensionRootDir( sExtensionFolderURL ); 157cdf0e10cSrcweir 158cdf0e10cSrcweir nRetCode = aExtensionRootDir.open(); 159cdf0e10cSrcweir if (( nRetCode == osl::Directory::E_None ) && 160cdf0e10cSrcweir ( aExtensionRootDir.getNextItem( aExtDirItem, nHint ) == osl::Directory::E_None )) 161cdf0e10cSrcweir { 162cdf0e10cSrcweir bool bFileStatus = aExtDirItem.getFileStatus(fs) == osl::FileBase::E_None; 163cdf0e10cSrcweir bool bIsDir = fs.getFileType() == osl::FileStatus::Directory; 164cdf0e10cSrcweir 165cdf0e10cSrcweir if ( bFileStatus && bIsDir ) 166cdf0e10cSrcweir { 167cdf0e10cSrcweir sExtensionFolderURL = fs.getFileURL(); 168cdf0e10cSrcweir ScanResult eResult = scanExtensionFolder( sExtensionFolderURL ); 169cdf0e10cSrcweir if ( eResult == SCANRESULT_MIGRATE_EXTENSION ) 170cdf0e10cSrcweir aMigrateExtensions.push_back( sExtensionFolderURL ); 171cdf0e10cSrcweir } 172cdf0e10cSrcweir } 173cdf0e10cSrcweir } 174cdf0e10cSrcweir } 175cdf0e10cSrcweir } 176cdf0e10cSrcweir } 177cdf0e10cSrcweir 178cdf0e10cSrcweir OO3ExtensionMigration::ScanResult OO3ExtensionMigration::scanExtensionFolder( const ::rtl::OUString& sExtFolder ) 179cdf0e10cSrcweir { 180cdf0e10cSrcweir ScanResult aResult = SCANRESULT_NOTFOUND; 181cdf0e10cSrcweir osl::Directory aDir(sExtFolder); 182cdf0e10cSrcweir 183cdf0e10cSrcweir // get sub dirs 184cdf0e10cSrcweir if (aDir.open() == osl::FileBase::E_None) 185cdf0e10cSrcweir { 186cdf0e10cSrcweir // work through directory contents... 187cdf0e10cSrcweir osl::DirectoryItem item; 188cdf0e10cSrcweir osl::FileStatus fs(FileStatusMask_Type | FileStatusMask_FileURL); 189cdf0e10cSrcweir TStringVector aDirectories; 190cdf0e10cSrcweir while ((aDir.getNextItem(item) == osl::FileBase::E_None ) && 191cdf0e10cSrcweir ( aResult == SCANRESULT_NOTFOUND )) 192cdf0e10cSrcweir { 193cdf0e10cSrcweir if (item.getFileStatus(fs) == osl::FileBase::E_None) 194cdf0e10cSrcweir { 195cdf0e10cSrcweir ::rtl::OUString aDirEntryURL; 196cdf0e10cSrcweir if (fs.getFileType() == osl::FileStatus::Directory) 197cdf0e10cSrcweir aDirectories.push_back( fs.getFileURL() ); 198cdf0e10cSrcweir else 199cdf0e10cSrcweir { 200cdf0e10cSrcweir aDirEntryURL = fs.getFileURL(); 201cdf0e10cSrcweir if ( aDirEntryURL.indexOf( sDescriptionXmlFile ) > 0 ) 202cdf0e10cSrcweir aResult = scanDescriptionXml( aDirEntryURL ) ? SCANRESULT_MIGRATE_EXTENSION : SCANRESULT_DONTMIGRATE_EXTENSION; 203cdf0e10cSrcweir } 204cdf0e10cSrcweir } 205cdf0e10cSrcweir } 206cdf0e10cSrcweir 207cdf0e10cSrcweir TStringVector::const_iterator pIter = aDirectories.begin(); 208cdf0e10cSrcweir while ( pIter != aDirectories.end() && aResult == SCANRESULT_NOTFOUND ) 209cdf0e10cSrcweir { 210cdf0e10cSrcweir aResult = scanExtensionFolder( *pIter ); 211cdf0e10cSrcweir ++pIter; 212cdf0e10cSrcweir } 213cdf0e10cSrcweir } 214cdf0e10cSrcweir return aResult; 215cdf0e10cSrcweir } 216cdf0e10cSrcweir 217cdf0e10cSrcweir bool OO3ExtensionMigration::scanDescriptionXml( const ::rtl::OUString& sDescriptionXmlURL ) 218cdf0e10cSrcweir { 219cdf0e10cSrcweir if ( !m_xDocBuilder.is() ) 220cdf0e10cSrcweir { 221cdf0e10cSrcweir m_xDocBuilder = uno::Reference< xml::dom::XDocumentBuilder >( 222cdf0e10cSrcweir m_ctx->getServiceManager()->createInstanceWithContext( 223cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.xml.dom.DocumentBuilder")), 224cdf0e10cSrcweir m_ctx ), uno::UNO_QUERY ); 225cdf0e10cSrcweir } 226cdf0e10cSrcweir 227cdf0e10cSrcweir if ( !m_xSimpleFileAccess.is() ) 228cdf0e10cSrcweir { 229cdf0e10cSrcweir m_xSimpleFileAccess = uno::Reference< ucb::XSimpleFileAccess >( 230cdf0e10cSrcweir m_ctx->getServiceManager()->createInstanceWithContext( 231cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.ucb.SimpleFileAccess")), 232cdf0e10cSrcweir m_ctx ), uno::UNO_QUERY ); 233cdf0e10cSrcweir } 234cdf0e10cSrcweir 235cdf0e10cSrcweir ::rtl::OUString aExtIdentifier; 236cdf0e10cSrcweir if ( m_xDocBuilder.is() && m_xSimpleFileAccess.is() ) 237cdf0e10cSrcweir { 238cdf0e10cSrcweir try 239cdf0e10cSrcweir { 240cdf0e10cSrcweir uno::Reference< io::XInputStream > xIn = 241cdf0e10cSrcweir m_xSimpleFileAccess->openFileRead( sDescriptionXmlURL ); 242cdf0e10cSrcweir 243cdf0e10cSrcweir if ( xIn.is() ) 244cdf0e10cSrcweir { 245cdf0e10cSrcweir uno::Reference< xml::dom::XDocument > xDoc = m_xDocBuilder->parse( xIn ); 246cdf0e10cSrcweir if ( xDoc.is() ) 247cdf0e10cSrcweir { 248cdf0e10cSrcweir uno::Reference< xml::dom::XElement > xRoot = xDoc->getDocumentElement(); 249cdf0e10cSrcweir if ( xRoot.is() && 250cdf0e10cSrcweir xRoot->getTagName().equals(::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("description"))) ) 251cdf0e10cSrcweir { 252cdf0e10cSrcweir uno::Reference< xml::xpath::XXPathAPI > xPath( 253cdf0e10cSrcweir m_ctx->getServiceManager()->createInstanceWithContext( 254cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.xml.xpath.XPathAPI")), 255cdf0e10cSrcweir m_ctx), 256cdf0e10cSrcweir uno::UNO_QUERY); 257cdf0e10cSrcweir 258cdf0e10cSrcweir xPath->registerNS( 259cdf0e10cSrcweir ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("desc")), 260cdf0e10cSrcweir xRoot->getNamespaceURI()); 261cdf0e10cSrcweir xPath->registerNS( 262cdf0e10cSrcweir ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("xlink")), 263cdf0e10cSrcweir ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("http://www.w3.org/1999/xlink"))); 264cdf0e10cSrcweir 265cdf0e10cSrcweir try 266cdf0e10cSrcweir { 267cdf0e10cSrcweir uno::Reference< xml::dom::XNode > xRootNode( xRoot, uno::UNO_QUERY ); 268cdf0e10cSrcweir uno::Reference< xml::dom::XNode > xNode( 269cdf0e10cSrcweir xPath->selectSingleNode( 270cdf0e10cSrcweir xRootNode, 271cdf0e10cSrcweir ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("desc:identifier/@value")) )); 272cdf0e10cSrcweir if ( xNode.is() ) 273cdf0e10cSrcweir aExtIdentifier = xNode->getNodeValue(); 274cdf0e10cSrcweir } 275cdf0e10cSrcweir catch ( xml::xpath::XPathException& ) 276cdf0e10cSrcweir { 277cdf0e10cSrcweir } 278cdf0e10cSrcweir catch ( xml::dom::DOMException& ) 279cdf0e10cSrcweir { 280cdf0e10cSrcweir } 281cdf0e10cSrcweir } 282cdf0e10cSrcweir } 283cdf0e10cSrcweir } 284cdf0e10cSrcweir 285cdf0e10cSrcweir if ( aExtIdentifier.getLength() > 0 ) 286cdf0e10cSrcweir { 287cdf0e10cSrcweir // scan extension identifier and try to match with our black list entries 288cdf0e10cSrcweir for ( sal_uInt32 i = 0; i < m_aBlackList.size(); i++ ) 289cdf0e10cSrcweir { 290cdf0e10cSrcweir utl::SearchParam param(m_aBlackList[i], utl::SearchParam::SRCH_REGEXP); 291cdf0e10cSrcweir utl::TextSearch ts(param, LANGUAGE_DONTKNOW); 292cdf0e10cSrcweir 293cdf0e10cSrcweir xub_StrLen start = 0; 294cdf0e10cSrcweir xub_StrLen end = static_cast<sal_uInt16>(aExtIdentifier.getLength()); 295cdf0e10cSrcweir if (ts.SearchFrwrd(aExtIdentifier, &start, &end)) 296cdf0e10cSrcweir return false; 297cdf0e10cSrcweir } 298cdf0e10cSrcweir } 299cdf0e10cSrcweir } 300cdf0e10cSrcweir catch ( ucb::CommandAbortedException& ) 301cdf0e10cSrcweir { 302cdf0e10cSrcweir } 303cdf0e10cSrcweir catch ( uno::RuntimeException& ) 304cdf0e10cSrcweir { 305cdf0e10cSrcweir } 306cdf0e10cSrcweir 307cdf0e10cSrcweir if ( aExtIdentifier.getLength() == 0 ) 308cdf0e10cSrcweir { 309cdf0e10cSrcweir // Fallback: 310cdf0e10cSrcweir // Try to use the folder name to match our black list 311cdf0e10cSrcweir // as some extensions don't provide an identifier in the 312cdf0e10cSrcweir // description.xml! 313cdf0e10cSrcweir for ( sal_uInt32 i = 0; i < m_aBlackList.size(); i++ ) 314cdf0e10cSrcweir { 315cdf0e10cSrcweir utl::SearchParam param(m_aBlackList[i], utl::SearchParam::SRCH_REGEXP); 316cdf0e10cSrcweir utl::TextSearch ts(param, LANGUAGE_DONTKNOW); 317cdf0e10cSrcweir 318cdf0e10cSrcweir xub_StrLen start = 0; 319cdf0e10cSrcweir xub_StrLen end = static_cast<sal_uInt16>(sDescriptionXmlURL.getLength()); 320cdf0e10cSrcweir if (ts.SearchFrwrd(sDescriptionXmlURL, &start, &end)) 321cdf0e10cSrcweir return false; 322cdf0e10cSrcweir } 323cdf0e10cSrcweir } 324cdf0e10cSrcweir } 325cdf0e10cSrcweir 326cdf0e10cSrcweir return true; 327cdf0e10cSrcweir } 328cdf0e10cSrcweir 329cdf0e10cSrcweir bool OO3ExtensionMigration::migrateExtension( const ::rtl::OUString& sSourceDir ) 330cdf0e10cSrcweir { 331cdf0e10cSrcweir if ( !m_xExtensionManager.is() ) 332cdf0e10cSrcweir { 333cdf0e10cSrcweir try 334cdf0e10cSrcweir { 335cdf0e10cSrcweir m_xExtensionManager = deployment::ExtensionManager::get( m_ctx ); 336cdf0e10cSrcweir } 337cdf0e10cSrcweir catch ( ucb::CommandFailedException & ){} 338cdf0e10cSrcweir catch ( uno::RuntimeException & ) {} 339cdf0e10cSrcweir } 340cdf0e10cSrcweir 341cdf0e10cSrcweir if ( m_xExtensionManager.is() ) 342cdf0e10cSrcweir { 343cdf0e10cSrcweir try 344cdf0e10cSrcweir { 345cdf0e10cSrcweir TmpRepositoryCommandEnv* pCmdEnv = new TmpRepositoryCommandEnv(); 346cdf0e10cSrcweir 347cdf0e10cSrcweir uno::Reference< ucb::XCommandEnvironment > xCmdEnv( 348cdf0e10cSrcweir static_cast< cppu::OWeakObject* >( pCmdEnv ), uno::UNO_QUERY ); 349cdf0e10cSrcweir uno::Reference< task::XAbortChannel > xAbortChannel; 350cdf0e10cSrcweir uno::Reference< deployment::XPackage > xPackage = 351cdf0e10cSrcweir m_xExtensionManager->addExtension( 352cdf0e10cSrcweir sSourceDir, uno::Sequence<beans::NamedValue>(), 353cdf0e10cSrcweir ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("user")), xAbortChannel, xCmdEnv ); 354cdf0e10cSrcweir 355cdf0e10cSrcweir if ( xPackage.is() ) 356cdf0e10cSrcweir return true; 357cdf0e10cSrcweir } 358cdf0e10cSrcweir catch ( ucb::CommandFailedException& ) 359cdf0e10cSrcweir { 360cdf0e10cSrcweir } 361cdf0e10cSrcweir catch ( ucb::CommandAbortedException& ) 362cdf0e10cSrcweir { 363cdf0e10cSrcweir } 364cdf0e10cSrcweir catch ( lang::IllegalArgumentException& ) 365cdf0e10cSrcweir { 366cdf0e10cSrcweir } 367cdf0e10cSrcweir } 368cdf0e10cSrcweir 369cdf0e10cSrcweir return false; 370cdf0e10cSrcweir } 371cdf0e10cSrcweir 372cdf0e10cSrcweir 373cdf0e10cSrcweir // ----------------------------------------------------------------------------- 374cdf0e10cSrcweir // XServiceInfo 375cdf0e10cSrcweir // ----------------------------------------------------------------------------- 376cdf0e10cSrcweir 377cdf0e10cSrcweir ::rtl::OUString OO3ExtensionMigration::getImplementationName() throw (RuntimeException) 378cdf0e10cSrcweir { 379cdf0e10cSrcweir return OO3ExtensionMigration_getImplementationName(); 380cdf0e10cSrcweir } 381cdf0e10cSrcweir 382cdf0e10cSrcweir // ----------------------------------------------------------------------------- 383cdf0e10cSrcweir 384cdf0e10cSrcweir sal_Bool OO3ExtensionMigration::supportsService( const ::rtl::OUString& rServiceName ) throw (RuntimeException) 385cdf0e10cSrcweir { 386cdf0e10cSrcweir Sequence< ::rtl::OUString > aNames( getSupportedServiceNames() ); 387cdf0e10cSrcweir const ::rtl::OUString* pNames = aNames.getConstArray(); 388cdf0e10cSrcweir const ::rtl::OUString* pEnd = pNames + aNames.getLength(); 389cdf0e10cSrcweir for ( ; pNames != pEnd && !pNames->equals( rServiceName ); ++pNames ) 390cdf0e10cSrcweir ; 391cdf0e10cSrcweir 392cdf0e10cSrcweir return pNames != pEnd; 393cdf0e10cSrcweir } 394cdf0e10cSrcweir 395cdf0e10cSrcweir // ----------------------------------------------------------------------------- 396cdf0e10cSrcweir 397cdf0e10cSrcweir Sequence< ::rtl::OUString > OO3ExtensionMigration::getSupportedServiceNames() throw (RuntimeException) 398cdf0e10cSrcweir { 399cdf0e10cSrcweir return OO3ExtensionMigration_getSupportedServiceNames(); 400cdf0e10cSrcweir } 401cdf0e10cSrcweir 402cdf0e10cSrcweir // ----------------------------------------------------------------------------- 403cdf0e10cSrcweir // XInitialization 404cdf0e10cSrcweir // ----------------------------------------------------------------------------- 405cdf0e10cSrcweir 406cdf0e10cSrcweir void OO3ExtensionMigration::initialize( const Sequence< Any >& aArguments ) throw (Exception, RuntimeException) 407cdf0e10cSrcweir { 408cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 409cdf0e10cSrcweir 410cdf0e10cSrcweir const Any* pIter = aArguments.getConstArray(); 411cdf0e10cSrcweir const Any* pEnd = pIter + aArguments.getLength(); 412cdf0e10cSrcweir for ( ; pIter != pEnd ; ++pIter ) 413cdf0e10cSrcweir { 414cdf0e10cSrcweir beans::NamedValue aValue; 415cdf0e10cSrcweir *pIter >>= aValue; 416cdf0e10cSrcweir if ( aValue.Name.equalsAscii( "UserData" ) ) 417cdf0e10cSrcweir { 418cdf0e10cSrcweir if ( !(aValue.Value >>= m_sSourceDir) ) 419cdf0e10cSrcweir { 420cdf0e10cSrcweir OSL_ENSURE( false, "ExtensionMigration::initialize: argument UserData has wrong type!" ); 421cdf0e10cSrcweir } 422cdf0e10cSrcweir } 423cdf0e10cSrcweir else if ( aValue.Name.equalsAscii( "ExtensionBlackList" ) ) 424cdf0e10cSrcweir { 425cdf0e10cSrcweir Sequence< ::rtl::OUString > aBlackList; 426cdf0e10cSrcweir if ( (aValue.Value >>= aBlackList ) && ( aBlackList.getLength() > 0 )) 427cdf0e10cSrcweir { 428cdf0e10cSrcweir m_aBlackList.resize( aBlackList.getLength() ); 429cdf0e10cSrcweir ::comphelper::sequenceToArray< ::rtl::OUString >( &m_aBlackList[0], aBlackList ); 430cdf0e10cSrcweir } 431cdf0e10cSrcweir } 432cdf0e10cSrcweir } 433cdf0e10cSrcweir } 434cdf0e10cSrcweir 435cdf0e10cSrcweir // ----------------------------------------------------------------------------- 436cdf0e10cSrcweir 437cdf0e10cSrcweir TStringVectorPtr getContent( const ::rtl::OUString& rBaseURL ) 438cdf0e10cSrcweir { 439cdf0e10cSrcweir TStringVectorPtr aResult( new TStringVector ); 440cdf0e10cSrcweir ::osl::Directory aDir( rBaseURL); 441cdf0e10cSrcweir if ( aDir.open() == ::osl::FileBase::E_None ) 442cdf0e10cSrcweir { 443cdf0e10cSrcweir // iterate over directory content 444cdf0e10cSrcweir TStringVector aSubDirs; 445cdf0e10cSrcweir ::osl::DirectoryItem aItem; 446cdf0e10cSrcweir while ( aDir.getNextItem( aItem ) == ::osl::FileBase::E_None ) 447cdf0e10cSrcweir { 448cdf0e10cSrcweir ::osl::FileStatus aFileStatus( FileStatusMask_Type | FileStatusMask_FileURL ); 449cdf0e10cSrcweir if ( aItem.getFileStatus( aFileStatus ) == ::osl::FileBase::E_None ) 450cdf0e10cSrcweir aResult->push_back( aFileStatus.getFileURL() ); 451cdf0e10cSrcweir } 452cdf0e10cSrcweir } 453cdf0e10cSrcweir 454cdf0e10cSrcweir return aResult; 455cdf0e10cSrcweir } 456cdf0e10cSrcweir 457cdf0e10cSrcweir Any OO3ExtensionMigration::execute( const Sequence< beans::NamedValue >& ) 458cdf0e10cSrcweir throw (lang::IllegalArgumentException, Exception, RuntimeException) 459cdf0e10cSrcweir { 460cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 461cdf0e10cSrcweir 462cdf0e10cSrcweir ::utl::Bootstrap::PathStatus aStatus = ::utl::Bootstrap::locateUserInstallation( m_sTargetDir ); 463cdf0e10cSrcweir if ( aStatus == ::utl::Bootstrap::PATH_EXISTS ) 464cdf0e10cSrcweir { 465cdf0e10cSrcweir // copy all extensions 466cdf0e10cSrcweir ::rtl::OUString sSourceDir( m_sSourceDir ); 467cdf0e10cSrcweir sSourceDir += sExtensionSubDir; 468cdf0e10cSrcweir sSourceDir += sSubDirName; 469cdf0e10cSrcweir sSourceDir += sExtensionRootSubDirName; 470cdf0e10cSrcweir TStringVector aExtensionToMigrate; 471cdf0e10cSrcweir scanUserExtensions( sSourceDir, aExtensionToMigrate ); 472cdf0e10cSrcweir if ( aExtensionToMigrate.size() > 0 ) 473cdf0e10cSrcweir { 474cdf0e10cSrcweir TStringVector::iterator pIter = aExtensionToMigrate.begin(); 475cdf0e10cSrcweir while ( pIter != aExtensionToMigrate.end() ) 476cdf0e10cSrcweir { 477cdf0e10cSrcweir migrateExtension( *pIter ); 478cdf0e10cSrcweir ++pIter; 479cdf0e10cSrcweir } 480cdf0e10cSrcweir } 481cdf0e10cSrcweir } 482cdf0e10cSrcweir 483cdf0e10cSrcweir return Any(); 484cdf0e10cSrcweir } 485cdf0e10cSrcweir 486cdf0e10cSrcweir // ----------------------------------------------------------------------------- 487cdf0e10cSrcweir // TmpRepositoryCommandEnv 488cdf0e10cSrcweir // ----------------------------------------------------------------------------- 489cdf0e10cSrcweir 490cdf0e10cSrcweir TmpRepositoryCommandEnv::TmpRepositoryCommandEnv() 491cdf0e10cSrcweir { 492cdf0e10cSrcweir } 493cdf0e10cSrcweir 494cdf0e10cSrcweir TmpRepositoryCommandEnv::~TmpRepositoryCommandEnv() 495cdf0e10cSrcweir { 496cdf0e10cSrcweir } 497cdf0e10cSrcweir // XCommandEnvironment 498cdf0e10cSrcweir //______________________________________________________________________________ 499cdf0e10cSrcweir uno::Reference< task::XInteractionHandler > TmpRepositoryCommandEnv::getInteractionHandler() 500cdf0e10cSrcweir throw ( uno::RuntimeException ) 501cdf0e10cSrcweir { 502cdf0e10cSrcweir return this; 503cdf0e10cSrcweir } 504cdf0e10cSrcweir 505cdf0e10cSrcweir //______________________________________________________________________________ 506cdf0e10cSrcweir uno::Reference< ucb::XProgressHandler > TmpRepositoryCommandEnv::getProgressHandler() 507cdf0e10cSrcweir throw ( uno::RuntimeException ) 508cdf0e10cSrcweir { 509cdf0e10cSrcweir return this; 510cdf0e10cSrcweir } 511cdf0e10cSrcweir 512cdf0e10cSrcweir // XInteractionHandler 513cdf0e10cSrcweir void TmpRepositoryCommandEnv::handle( 514cdf0e10cSrcweir uno::Reference< task::XInteractionRequest> const & xRequest ) 515cdf0e10cSrcweir throw ( uno::RuntimeException ) 516cdf0e10cSrcweir { 517cdf0e10cSrcweir uno::Any request( xRequest->getRequest() ); 518cdf0e10cSrcweir OSL_ASSERT( request.getValueTypeClass() == uno::TypeClass_EXCEPTION ); 519cdf0e10cSrcweir 520cdf0e10cSrcweir bool approve = true; 521cdf0e10cSrcweir bool abort = false; 522cdf0e10cSrcweir 523*5e679a6cSOliver-Rainer Wittmann deployment::VersionException verExc; 524*5e679a6cSOliver-Rainer Wittmann if ( xRequest->getRequest() >>= verExc ) 525*5e679a6cSOliver-Rainer Wittmann { 526*5e679a6cSOliver-Rainer Wittmann // user interaction, if an extension is already been installed. 527*5e679a6cSOliver-Rainer Wittmann approve = dp_gui::handleVersionException( verExc ); 528*5e679a6cSOliver-Rainer Wittmann abort = !approve; 529*5e679a6cSOliver-Rainer Wittmann } 530*5e679a6cSOliver-Rainer Wittmann 531cdf0e10cSrcweir // select: 532cdf0e10cSrcweir uno::Sequence< Reference< task::XInteractionContinuation > > conts( 533cdf0e10cSrcweir xRequest->getContinuations() ); 534cdf0e10cSrcweir Reference< task::XInteractionContinuation > const * pConts = 535cdf0e10cSrcweir conts.getConstArray(); 536cdf0e10cSrcweir sal_Int32 len = conts.getLength(); 537cdf0e10cSrcweir for ( sal_Int32 pos = 0; pos < len; ++pos ) 538cdf0e10cSrcweir { 539cdf0e10cSrcweir if (approve) { 540cdf0e10cSrcweir uno::Reference< task::XInteractionApprove > xInteractionApprove( 541cdf0e10cSrcweir pConts[ pos ], uno::UNO_QUERY ); 542cdf0e10cSrcweir if (xInteractionApprove.is()) { 543cdf0e10cSrcweir xInteractionApprove->select(); 544cdf0e10cSrcweir // don't query again for ongoing continuations: 545cdf0e10cSrcweir approve = false; 546cdf0e10cSrcweir } 547cdf0e10cSrcweir } 548cdf0e10cSrcweir else if (abort) { 549cdf0e10cSrcweir uno::Reference< task::XInteractionAbort > xInteractionAbort( 550cdf0e10cSrcweir pConts[ pos ], uno::UNO_QUERY ); 551cdf0e10cSrcweir if (xInteractionAbort.is()) { 552cdf0e10cSrcweir xInteractionAbort->select(); 553cdf0e10cSrcweir // don't query again for ongoing continuations: 554cdf0e10cSrcweir abort = false; 555cdf0e10cSrcweir } 556cdf0e10cSrcweir } 557cdf0e10cSrcweir } 558cdf0e10cSrcweir } 559cdf0e10cSrcweir 560cdf0e10cSrcweir // XProgressHandler 561cdf0e10cSrcweir void TmpRepositoryCommandEnv::push( uno::Any const & /*Status*/ ) 562cdf0e10cSrcweir throw (uno::RuntimeException) 563cdf0e10cSrcweir { 564cdf0e10cSrcweir } 565cdf0e10cSrcweir 566cdf0e10cSrcweir 567cdf0e10cSrcweir void TmpRepositoryCommandEnv::update( uno::Any const & /*Status */) 568cdf0e10cSrcweir throw (uno::RuntimeException) 569cdf0e10cSrcweir { 570cdf0e10cSrcweir } 571cdf0e10cSrcweir 572cdf0e10cSrcweir void TmpRepositoryCommandEnv::pop() throw (uno::RuntimeException) 573cdf0e10cSrcweir { 574cdf0e10cSrcweir } 575cdf0e10cSrcweir 576cdf0e10cSrcweir // ============================================================================= 577cdf0e10cSrcweir // component operations 578cdf0e10cSrcweir // ============================================================================= 579cdf0e10cSrcweir 580cdf0e10cSrcweir Reference< XInterface > SAL_CALL OO3ExtensionMigration_create( 581cdf0e10cSrcweir Reference< XComponentContext > const & ctx ) 582cdf0e10cSrcweir SAL_THROW( () ) 583cdf0e10cSrcweir { 584cdf0e10cSrcweir return static_cast< lang::XTypeProvider * >( new OO3ExtensionMigration( 585cdf0e10cSrcweir ctx) ); 586cdf0e10cSrcweir } 587cdf0e10cSrcweir 588cdf0e10cSrcweir // ----------------------------------------------------------------------------- 589cdf0e10cSrcweir 590cdf0e10cSrcweir } // namespace migration 591