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