1*2722ceddSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*2722ceddSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*2722ceddSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*2722ceddSAndrew Rist * distributed with this work for additional information 6*2722ceddSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*2722ceddSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*2722ceddSAndrew Rist * "License"); you may not use this file except in compliance 9*2722ceddSAndrew Rist * with the License. You may obtain a copy of the License at 10*2722ceddSAndrew Rist * 11*2722ceddSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*2722ceddSAndrew Rist * 13*2722ceddSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*2722ceddSAndrew Rist * software distributed under the License is distributed on an 15*2722ceddSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*2722ceddSAndrew Rist * KIND, either express or implied. See the License for the 17*2722ceddSAndrew Rist * specific language governing permissions and limitations 18*2722ceddSAndrew Rist * under the License. 19*2722ceddSAndrew Rist * 20*2722ceddSAndrew Rist *************************************************************/ 21*2722ceddSAndrew Rist 22*2722ceddSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_desktop.hxx" 26cdf0e10cSrcweir #include "basicmigration.hxx" 27cdf0e10cSrcweir #include <tools/urlobj.hxx> 28cdf0e10cSrcweir #include <unotools/bootstrap.hxx> 29cdf0e10cSrcweir 30cdf0e10cSrcweir 31cdf0e10cSrcweir using namespace ::com::sun::star; 32cdf0e10cSrcweir using namespace ::com::sun::star::uno; 33cdf0e10cSrcweir 34cdf0e10cSrcweir 35cdf0e10cSrcweir //......................................................................... 36cdf0e10cSrcweir namespace migration 37cdf0e10cSrcweir { 38cdf0e10cSrcweir //......................................................................... 39cdf0e10cSrcweir 40cdf0e10cSrcweir 41cdf0e10cSrcweir static ::rtl::OUString sSourceUserBasic = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/user/basic" ) ); 42cdf0e10cSrcweir static ::rtl::OUString sTargetUserBasic = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/user/__basic_80" ) ); 43cdf0e10cSrcweir 44cdf0e10cSrcweir 45cdf0e10cSrcweir // ============================================================================= 46cdf0e10cSrcweir // component operations 47cdf0e10cSrcweir // ============================================================================= 48cdf0e10cSrcweir BasicMigration_getImplementationName()49cdf0e10cSrcweir ::rtl::OUString BasicMigration_getImplementationName() 50cdf0e10cSrcweir { 51cdf0e10cSrcweir static ::rtl::OUString* pImplName = 0; 52cdf0e10cSrcweir if ( !pImplName ) 53cdf0e10cSrcweir { 54cdf0e10cSrcweir ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); 55cdf0e10cSrcweir if ( !pImplName ) 56cdf0e10cSrcweir { 57cdf0e10cSrcweir static ::rtl::OUString aImplName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.desktop.migration.Basic" ) ); 58cdf0e10cSrcweir pImplName = &aImplName; 59cdf0e10cSrcweir } 60cdf0e10cSrcweir } 61cdf0e10cSrcweir return *pImplName; 62cdf0e10cSrcweir } 63cdf0e10cSrcweir 64cdf0e10cSrcweir // ----------------------------------------------------------------------------- 65cdf0e10cSrcweir BasicMigration_getSupportedServiceNames()66cdf0e10cSrcweir Sequence< ::rtl::OUString > BasicMigration_getSupportedServiceNames() 67cdf0e10cSrcweir { 68cdf0e10cSrcweir static Sequence< ::rtl::OUString >* pNames = 0; 69cdf0e10cSrcweir if ( !pNames ) 70cdf0e10cSrcweir { 71cdf0e10cSrcweir ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); 72cdf0e10cSrcweir if ( !pNames ) 73cdf0e10cSrcweir { 74cdf0e10cSrcweir static Sequence< ::rtl::OUString > aNames(1); 75cdf0e10cSrcweir aNames.getArray()[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.migration.Basic" ) ); 76cdf0e10cSrcweir pNames = &aNames; 77cdf0e10cSrcweir } 78cdf0e10cSrcweir } 79cdf0e10cSrcweir return *pNames; 80cdf0e10cSrcweir } 81cdf0e10cSrcweir 82cdf0e10cSrcweir // ============================================================================= 83cdf0e10cSrcweir // BasicMigration 84cdf0e10cSrcweir // ============================================================================= 85cdf0e10cSrcweir BasicMigration()86cdf0e10cSrcweir BasicMigration::BasicMigration() 87cdf0e10cSrcweir { 88cdf0e10cSrcweir } 89cdf0e10cSrcweir 90cdf0e10cSrcweir // ----------------------------------------------------------------------------- 91cdf0e10cSrcweir ~BasicMigration()92cdf0e10cSrcweir BasicMigration::~BasicMigration() 93cdf0e10cSrcweir { 94cdf0e10cSrcweir } 95cdf0e10cSrcweir 96cdf0e10cSrcweir // ----------------------------------------------------------------------------- 97cdf0e10cSrcweir getFiles(const::rtl::OUString & rBaseURL) const98cdf0e10cSrcweir TStringVectorPtr BasicMigration::getFiles( const ::rtl::OUString& rBaseURL ) const 99cdf0e10cSrcweir { 100cdf0e10cSrcweir TStringVectorPtr aResult( new TStringVector ); 101cdf0e10cSrcweir ::osl::Directory aDir( rBaseURL); 102cdf0e10cSrcweir 103cdf0e10cSrcweir if ( aDir.open() == ::osl::FileBase::E_None ) 104cdf0e10cSrcweir { 105cdf0e10cSrcweir // iterate over directory content 106cdf0e10cSrcweir TStringVector aSubDirs; 107cdf0e10cSrcweir ::osl::DirectoryItem aItem; 108cdf0e10cSrcweir while ( aDir.getNextItem( aItem ) == ::osl::FileBase::E_None ) 109cdf0e10cSrcweir { 110cdf0e10cSrcweir ::osl::FileStatus aFileStatus( FileStatusMask_Type | FileStatusMask_FileURL ); 111cdf0e10cSrcweir if ( aItem.getFileStatus( aFileStatus ) == ::osl::FileBase::E_None ) 112cdf0e10cSrcweir { 113cdf0e10cSrcweir if ( aFileStatus.getFileType() == ::osl::FileStatus::Directory ) 114cdf0e10cSrcweir aSubDirs.push_back( aFileStatus.getFileURL() ); 115cdf0e10cSrcweir else 116cdf0e10cSrcweir aResult->push_back( aFileStatus.getFileURL() ); 117cdf0e10cSrcweir } 118cdf0e10cSrcweir } 119cdf0e10cSrcweir 120cdf0e10cSrcweir // iterate recursive over subfolders 121cdf0e10cSrcweir TStringVector::const_iterator aI = aSubDirs.begin(); 122cdf0e10cSrcweir while ( aI != aSubDirs.end() ) 123cdf0e10cSrcweir { 124cdf0e10cSrcweir TStringVectorPtr aSubResult = getFiles( *aI ); 125cdf0e10cSrcweir aResult->insert( aResult->end(), aSubResult->begin(), aSubResult->end() ); 126cdf0e10cSrcweir ++aI; 127cdf0e10cSrcweir } 128cdf0e10cSrcweir } 129cdf0e10cSrcweir 130cdf0e10cSrcweir return aResult; 131cdf0e10cSrcweir } 132cdf0e10cSrcweir 133cdf0e10cSrcweir // ----------------------------------------------------------------------------- 134cdf0e10cSrcweir checkAndCreateDirectory(INetURLObject & rDirURL)135cdf0e10cSrcweir ::osl::FileBase::RC BasicMigration::checkAndCreateDirectory( INetURLObject& rDirURL ) 136cdf0e10cSrcweir { 137cdf0e10cSrcweir ::osl::FileBase::RC aResult = ::osl::Directory::create( rDirURL.GetMainURL( INetURLObject::DECODE_TO_IURI ) ); 138cdf0e10cSrcweir if ( aResult == ::osl::FileBase::E_NOENT ) 139cdf0e10cSrcweir { 140cdf0e10cSrcweir INetURLObject aBaseURL( rDirURL ); 141cdf0e10cSrcweir aBaseURL.removeSegment(); 142cdf0e10cSrcweir checkAndCreateDirectory( aBaseURL ); 143cdf0e10cSrcweir return ::osl::Directory::create( rDirURL.GetMainURL( INetURLObject::DECODE_TO_IURI ) ); 144cdf0e10cSrcweir } 145cdf0e10cSrcweir else 146cdf0e10cSrcweir { 147cdf0e10cSrcweir return aResult; 148cdf0e10cSrcweir } 149cdf0e10cSrcweir } 150cdf0e10cSrcweir 151cdf0e10cSrcweir // ----------------------------------------------------------------------------- 152cdf0e10cSrcweir copyFiles()153cdf0e10cSrcweir void BasicMigration::copyFiles() 154cdf0e10cSrcweir { 155cdf0e10cSrcweir ::rtl::OUString sTargetDir; 156cdf0e10cSrcweir ::utl::Bootstrap::PathStatus aStatus = ::utl::Bootstrap::locateUserInstallation( sTargetDir ); 157cdf0e10cSrcweir if ( aStatus == ::utl::Bootstrap::PATH_EXISTS ) 158cdf0e10cSrcweir { 159cdf0e10cSrcweir sTargetDir += sTargetUserBasic; 160cdf0e10cSrcweir TStringVectorPtr aFileList = getFiles( m_sSourceDir ); 161cdf0e10cSrcweir TStringVector::const_iterator aI = aFileList->begin(); 162cdf0e10cSrcweir while ( aI != aFileList->end() ) 163cdf0e10cSrcweir { 164cdf0e10cSrcweir ::rtl::OUString sLocalName = aI->copy( m_sSourceDir.getLength() ); 165cdf0e10cSrcweir ::rtl::OUString sTargetName = sTargetDir + sLocalName; 166cdf0e10cSrcweir INetURLObject aURL( sTargetName ); 167cdf0e10cSrcweir aURL.removeSegment(); 168cdf0e10cSrcweir checkAndCreateDirectory( aURL ); 169cdf0e10cSrcweir ::osl::FileBase::RC aResult = ::osl::File::copy( *aI, sTargetName ); 170cdf0e10cSrcweir if ( aResult != ::osl::FileBase::E_None ) 171cdf0e10cSrcweir { 172cdf0e10cSrcweir ::rtl::OString aMsg( "BasicMigration::copyFiles: cannot copy " ); 173cdf0e10cSrcweir aMsg += ::rtl::OUStringToOString( *aI, RTL_TEXTENCODING_UTF8 ) + " to " 174cdf0e10cSrcweir + ::rtl::OUStringToOString( sTargetName, RTL_TEXTENCODING_UTF8 ); 175cdf0e10cSrcweir OSL_ENSURE( sal_False, aMsg.getStr() ); 176cdf0e10cSrcweir } 177cdf0e10cSrcweir ++aI; 178cdf0e10cSrcweir } 179cdf0e10cSrcweir } 180cdf0e10cSrcweir else 181cdf0e10cSrcweir { 182cdf0e10cSrcweir OSL_ENSURE( sal_False, "BasicMigration::copyFiles: no user installation!" ); 183cdf0e10cSrcweir } 184cdf0e10cSrcweir } 185cdf0e10cSrcweir 186cdf0e10cSrcweir // ----------------------------------------------------------------------------- 187cdf0e10cSrcweir // XServiceInfo 188cdf0e10cSrcweir // ----------------------------------------------------------------------------- 189cdf0e10cSrcweir getImplementationName()190cdf0e10cSrcweir ::rtl::OUString BasicMigration::getImplementationName() throw (RuntimeException) 191cdf0e10cSrcweir { 192cdf0e10cSrcweir return BasicMigration_getImplementationName(); 193cdf0e10cSrcweir } 194cdf0e10cSrcweir 195cdf0e10cSrcweir // ----------------------------------------------------------------------------- 196cdf0e10cSrcweir supportsService(const::rtl::OUString & rServiceName)197cdf0e10cSrcweir sal_Bool BasicMigration::supportsService( const ::rtl::OUString& rServiceName ) throw (RuntimeException) 198cdf0e10cSrcweir { 199cdf0e10cSrcweir Sequence< ::rtl::OUString > aNames( getSupportedServiceNames() ); 200cdf0e10cSrcweir const ::rtl::OUString* pNames = aNames.getConstArray(); 201cdf0e10cSrcweir const ::rtl::OUString* pEnd = pNames + aNames.getLength(); 202cdf0e10cSrcweir for ( ; pNames != pEnd && !pNames->equals( rServiceName ); ++pNames ) 203cdf0e10cSrcweir ; 204cdf0e10cSrcweir 205cdf0e10cSrcweir return pNames != pEnd; 206cdf0e10cSrcweir } 207cdf0e10cSrcweir 208cdf0e10cSrcweir // ----------------------------------------------------------------------------- 209cdf0e10cSrcweir getSupportedServiceNames()210cdf0e10cSrcweir Sequence< ::rtl::OUString > BasicMigration::getSupportedServiceNames() throw (RuntimeException) 211cdf0e10cSrcweir { 212cdf0e10cSrcweir return BasicMigration_getSupportedServiceNames(); 213cdf0e10cSrcweir } 214cdf0e10cSrcweir 215cdf0e10cSrcweir // ----------------------------------------------------------------------------- 216cdf0e10cSrcweir // XInitialization 217cdf0e10cSrcweir // ----------------------------------------------------------------------------- 218cdf0e10cSrcweir initialize(const Sequence<Any> & aArguments)219cdf0e10cSrcweir void BasicMigration::initialize( const Sequence< Any >& aArguments ) throw (Exception, RuntimeException) 220cdf0e10cSrcweir { 221cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 222cdf0e10cSrcweir 223cdf0e10cSrcweir const Any* pIter = aArguments.getConstArray(); 224cdf0e10cSrcweir const Any* pEnd = pIter + aArguments.getLength(); 225cdf0e10cSrcweir for ( ; pIter != pEnd ; ++pIter ) 226cdf0e10cSrcweir { 227cdf0e10cSrcweir beans::NamedValue aValue; 228cdf0e10cSrcweir *pIter >>= aValue; 229cdf0e10cSrcweir if ( aValue.Name.equalsAscii( "UserData" ) ) 230cdf0e10cSrcweir { 231cdf0e10cSrcweir if ( !(aValue.Value >>= m_sSourceDir) ) 232cdf0e10cSrcweir { 233cdf0e10cSrcweir OSL_ENSURE( false, "BasicMigration::initialize: argument UserData has wrong type!" ); 234cdf0e10cSrcweir } 235cdf0e10cSrcweir m_sSourceDir += sSourceUserBasic; 236cdf0e10cSrcweir break; 237cdf0e10cSrcweir } 238cdf0e10cSrcweir } 239cdf0e10cSrcweir } 240cdf0e10cSrcweir 241cdf0e10cSrcweir // ----------------------------------------------------------------------------- 242cdf0e10cSrcweir // XJob 243cdf0e10cSrcweir // ----------------------------------------------------------------------------- 244cdf0e10cSrcweir execute(const Sequence<beans::NamedValue> &)245cdf0e10cSrcweir Any BasicMigration::execute( const Sequence< beans::NamedValue >& ) 246cdf0e10cSrcweir throw (lang::IllegalArgumentException, Exception, RuntimeException) 247cdf0e10cSrcweir { 248cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 249cdf0e10cSrcweir 250cdf0e10cSrcweir copyFiles(); 251cdf0e10cSrcweir 252cdf0e10cSrcweir return Any(); 253cdf0e10cSrcweir } 254cdf0e10cSrcweir 255cdf0e10cSrcweir // ============================================================================= 256cdf0e10cSrcweir // component operations 257cdf0e10cSrcweir // ============================================================================= 258cdf0e10cSrcweir BasicMigration_create(Reference<XComponentContext> const &)259cdf0e10cSrcweir Reference< XInterface > SAL_CALL BasicMigration_create( 260cdf0e10cSrcweir Reference< XComponentContext > const & ) 261cdf0e10cSrcweir SAL_THROW( () ) 262cdf0e10cSrcweir { 263cdf0e10cSrcweir return static_cast< lang::XTypeProvider * >( new BasicMigration() ); 264cdf0e10cSrcweir } 265cdf0e10cSrcweir 266cdf0e10cSrcweir // ----------------------------------------------------------------------------- 267cdf0e10cSrcweir 268cdf0e10cSrcweir //......................................................................... 269cdf0e10cSrcweir } // namespace migration 270cdf0e10cSrcweir //......................................................................... 271