LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/desktop/source/migration/services - basicmigration.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 86 0.0 %
Date: 2013-07-09 Functions: 0 14 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include "basicmigration.hxx"
      21             : #include <cppuhelper/supportsservice.hxx>
      22             : #include <tools/urlobj.hxx>
      23             : #include <unotools/bootstrap.hxx>
      24             : 
      25             : 
      26             : using namespace ::com::sun::star;
      27             : using namespace ::com::sun::star::uno;
      28             : 
      29             : 
      30             : //.........................................................................
      31             : namespace migration
      32             : {
      33             : //.........................................................................
      34             : 
      35             : 
      36             :     #define sSourceUserBasic OUString( "/user/basic" )
      37             :     #define sTargetUserBasic OUString( "/user/__basic_80" )
      38             : 
      39             :     // =============================================================================
      40             :     // component operations
      41             :     // =============================================================================
      42             : 
      43           0 :     OUString BasicMigration_getImplementationName()
      44             :     {
      45           0 :         return OUString("com.sun.star.comp.desktop.migration.Basic");
      46             :     }
      47             : 
      48             :     // -----------------------------------------------------------------------------
      49             : 
      50           0 :     Sequence< OUString > BasicMigration_getSupportedServiceNames()
      51             :     {
      52           0 :         Sequence< OUString > aNames(1);
      53           0 :         aNames.getArray()[0] = "com.sun.star.migration.Basic";
      54           0 :         return aNames;
      55             :     }
      56             : 
      57             :     // =============================================================================
      58             :     // BasicMigration
      59             :     // =============================================================================
      60             : 
      61           0 :     BasicMigration::BasicMigration()
      62             :     {
      63           0 :     }
      64             : 
      65             :     // -----------------------------------------------------------------------------
      66             : 
      67           0 :     BasicMigration::~BasicMigration()
      68             :     {
      69           0 :     }
      70             : 
      71             :     // -----------------------------------------------------------------------------
      72             : 
      73           0 :     TStringVectorPtr BasicMigration::getFiles( const OUString& rBaseURL ) const
      74             :     {
      75           0 :         TStringVectorPtr aResult( new TStringVector );
      76           0 :         ::osl::Directory aDir( rBaseURL);
      77             : 
      78           0 :         if ( aDir.open() == ::osl::FileBase::E_None )
      79             :         {
      80             :             // iterate over directory content
      81           0 :             TStringVector aSubDirs;
      82           0 :             ::osl::DirectoryItem aItem;
      83           0 :             while ( aDir.getNextItem( aItem ) == ::osl::FileBase::E_None )
      84             :             {
      85           0 :                 ::osl::FileStatus aFileStatus( osl_FileStatus_Mask_Type | osl_FileStatus_Mask_FileURL );
      86           0 :                 if ( aItem.getFileStatus( aFileStatus ) == ::osl::FileBase::E_None )
      87             :                 {
      88           0 :                     if ( aFileStatus.getFileType() == ::osl::FileStatus::Directory )
      89           0 :                         aSubDirs.push_back( aFileStatus.getFileURL() );
      90             :                     else
      91           0 :                         aResult->push_back( aFileStatus.getFileURL() );
      92             :                 }
      93           0 :             }
      94             : 
      95             :             // iterate recursive over subfolders
      96           0 :             TStringVector::const_iterator aI = aSubDirs.begin();
      97           0 :             while ( aI != aSubDirs.end() )
      98             :             {
      99           0 :                 TStringVectorPtr aSubResult = getFiles( *aI );
     100           0 :                 aResult->insert( aResult->end(), aSubResult->begin(), aSubResult->end() );
     101           0 :                 ++aI;
     102           0 :             }
     103             :         }
     104             : 
     105           0 :         return aResult;
     106             :     }
     107             : 
     108             :     // -----------------------------------------------------------------------------
     109             : 
     110           0 :     ::osl::FileBase::RC BasicMigration::checkAndCreateDirectory( INetURLObject& rDirURL )
     111             :     {
     112           0 :         ::osl::FileBase::RC aResult = ::osl::Directory::create( rDirURL.GetMainURL( INetURLObject::DECODE_TO_IURI ) );
     113           0 :         if ( aResult == ::osl::FileBase::E_NOENT )
     114             :         {
     115           0 :             INetURLObject aBaseURL( rDirURL );
     116           0 :             aBaseURL.removeSegment();
     117           0 :             checkAndCreateDirectory( aBaseURL );
     118           0 :             return ::osl::Directory::create( rDirURL.GetMainURL( INetURLObject::DECODE_TO_IURI ) );
     119             :         }
     120             :         else
     121             :         {
     122           0 :             return aResult;
     123             :         }
     124             :     }
     125             : 
     126             :     // -----------------------------------------------------------------------------
     127             : 
     128           0 :     void BasicMigration::copyFiles()
     129             :     {
     130           0 :         OUString sTargetDir;
     131           0 :         ::utl::Bootstrap::PathStatus aStatus = ::utl::Bootstrap::locateUserInstallation( sTargetDir );
     132           0 :         if ( aStatus == ::utl::Bootstrap::PATH_EXISTS )
     133             :         {
     134           0 :             sTargetDir += sTargetUserBasic;
     135           0 :             TStringVectorPtr aFileList = getFiles( m_sSourceDir );
     136           0 :             TStringVector::const_iterator aI = aFileList->begin();
     137           0 :             while ( aI != aFileList->end() )
     138             :             {
     139           0 :                 OUString sLocalName = aI->copy( m_sSourceDir.getLength() );
     140           0 :                 OUString sTargetName = sTargetDir + sLocalName;
     141           0 :                 INetURLObject aURL( sTargetName );
     142           0 :                 aURL.removeSegment();
     143           0 :                 checkAndCreateDirectory( aURL );
     144           0 :                 ::osl::FileBase::RC aResult = ::osl::File::copy( *aI, sTargetName );
     145           0 :                 if ( aResult != ::osl::FileBase::E_None )
     146             :                 {
     147           0 :                     OString aMsg( "BasicMigration::copyFiles: cannot copy " );
     148           0 :                     aMsg += OUStringToOString( *aI, RTL_TEXTENCODING_UTF8 ) + " to "
     149           0 :                          +  OUStringToOString( sTargetName, RTL_TEXTENCODING_UTF8 );
     150           0 :                     OSL_FAIL( aMsg.getStr() );
     151             :                 }
     152           0 :                 ++aI;
     153           0 :             }
     154             :         }
     155             :         else
     156             :         {
     157             :             OSL_FAIL( "BasicMigration::copyFiles: no user installation!" );
     158           0 :         }
     159           0 :     }
     160             : 
     161             :     // -----------------------------------------------------------------------------
     162             :     // XServiceInfo
     163             :     // -----------------------------------------------------------------------------
     164             : 
     165           0 :     OUString BasicMigration::getImplementationName() throw (RuntimeException)
     166             :     {
     167           0 :         return BasicMigration_getImplementationName();
     168             :     }
     169             : 
     170             :     // -----------------------------------------------------------------------------
     171             : 
     172           0 :     sal_Bool BasicMigration::supportsService(OUString const & ServiceName)
     173             :         throw (css::uno::RuntimeException)
     174             :     {
     175           0 :         return cppu::supportsService(this, ServiceName);
     176             :     }
     177             : 
     178             :     // -----------------------------------------------------------------------------
     179             : 
     180           0 :     Sequence< OUString > BasicMigration::getSupportedServiceNames() throw (RuntimeException)
     181             :     {
     182           0 :         return BasicMigration_getSupportedServiceNames();
     183             :     }
     184             : 
     185             :     // -----------------------------------------------------------------------------
     186             :     // XInitialization
     187             :     // -----------------------------------------------------------------------------
     188             : 
     189           0 :     void BasicMigration::initialize( const Sequence< Any >& aArguments ) throw (Exception, RuntimeException)
     190             :     {
     191           0 :         ::osl::MutexGuard aGuard( m_aMutex );
     192             : 
     193           0 :         const Any* pIter = aArguments.getConstArray();
     194           0 :         const Any* pEnd = pIter + aArguments.getLength();
     195           0 :         for ( ; pIter != pEnd ; ++pIter )
     196             :         {
     197           0 :             beans::NamedValue aValue;
     198           0 :             *pIter >>= aValue;
     199           0 :             if ( aValue.Name == "UserData" )
     200             :             {
     201           0 :                 if ( !(aValue.Value >>= m_sSourceDir) )
     202             :                 {
     203             :                     OSL_FAIL( "BasicMigration::initialize: argument UserData has wrong type!" );
     204             :                 }
     205           0 :                 m_sSourceDir += sSourceUserBasic;
     206           0 :                 break;
     207             :             }
     208           0 :         }
     209           0 :     }
     210             : 
     211             :     // -----------------------------------------------------------------------------
     212             :     // XJob
     213             :     // -----------------------------------------------------------------------------
     214             : 
     215           0 :     Any BasicMigration::execute( const Sequence< beans::NamedValue >& )
     216             :         throw (lang::IllegalArgumentException, Exception, RuntimeException)
     217             :     {
     218           0 :         ::osl::MutexGuard aGuard( m_aMutex );
     219             : 
     220           0 :         copyFiles();
     221             : 
     222           0 :         return Any();
     223             :     }
     224             : 
     225             :     // =============================================================================
     226             :     // component operations
     227             :     // =============================================================================
     228             : 
     229           0 :     Reference< XInterface > SAL_CALL BasicMigration_create(
     230             :         Reference< XComponentContext > const & )
     231             :         SAL_THROW(())
     232             :     {
     233           0 :         return static_cast< lang::XTypeProvider * >( new BasicMigration() );
     234             :     }
     235             : 
     236             :     // -----------------------------------------------------------------------------
     237             : 
     238             : //.........................................................................
     239             : }   // namespace migration
     240             : //.........................................................................
     241             : 
     242             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10