LCOV - code coverage report
Current view: top level - desktop/source/migration/services - basicmigration.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 89 0.0 %
Date: 2012-08-25 Functions: 0 14 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include "basicmigration.hxx"
      30                 :            : #include <tools/urlobj.hxx>
      31                 :            : #include <unotools/bootstrap.hxx>
      32                 :            : 
      33                 :            : 
      34                 :            : using namespace ::com::sun::star;
      35                 :            : using namespace ::com::sun::star::uno;
      36                 :            : 
      37                 :            : 
      38                 :            : //.........................................................................
      39                 :            : namespace migration
      40                 :            : {
      41                 :            : //.........................................................................
      42                 :            : 
      43                 :            : 
      44                 :            :     #define sSourceUserBasic ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("/user/basic"))
      45                 :            :     #define sTargetUserBasic ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("/user/__basic_80"))
      46                 :            : 
      47                 :            :     // =============================================================================
      48                 :            :     // component operations
      49                 :            :     // =============================================================================
      50                 :            : 
      51                 :          0 :     ::rtl::OUString BasicMigration_getImplementationName()
      52                 :            :     {
      53                 :          0 :         return ::rtl::OUString (RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.desktop.migration.Basic"));
      54                 :            :     }
      55                 :            : 
      56                 :            :     // -----------------------------------------------------------------------------
      57                 :            : 
      58                 :          0 :     Sequence< ::rtl::OUString > BasicMigration_getSupportedServiceNames()
      59                 :            :     {
      60                 :          0 :         Sequence< ::rtl::OUString > aNames(1);
      61                 :          0 :         aNames.getArray()[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.migration.Basic" ) );
      62                 :          0 :         return aNames;
      63                 :            :     }
      64                 :            : 
      65                 :            :     // =============================================================================
      66                 :            :     // BasicMigration
      67                 :            :     // =============================================================================
      68                 :            : 
      69                 :          0 :     BasicMigration::BasicMigration()
      70                 :            :     {
      71                 :          0 :     }
      72                 :            : 
      73                 :            :     // -----------------------------------------------------------------------------
      74                 :            : 
      75                 :          0 :     BasicMigration::~BasicMigration()
      76                 :            :     {
      77                 :          0 :     }
      78                 :            : 
      79                 :            :     // -----------------------------------------------------------------------------
      80                 :            : 
      81                 :          0 :     TStringVectorPtr BasicMigration::getFiles( const ::rtl::OUString& rBaseURL ) const
      82                 :            :     {
      83                 :          0 :         TStringVectorPtr aResult( new TStringVector );
      84                 :          0 :         ::osl::Directory aDir( rBaseURL);
      85                 :            : 
      86                 :          0 :         if ( aDir.open() == ::osl::FileBase::E_None )
      87                 :            :         {
      88                 :            :             // iterate over directory content
      89                 :          0 :             TStringVector aSubDirs;
      90                 :          0 :             ::osl::DirectoryItem aItem;
      91                 :          0 :             while ( aDir.getNextItem( aItem ) == ::osl::FileBase::E_None )
      92                 :            :             {
      93                 :          0 :                 ::osl::FileStatus aFileStatus( osl_FileStatus_Mask_Type | osl_FileStatus_Mask_FileURL );
      94                 :          0 :                 if ( aItem.getFileStatus( aFileStatus ) == ::osl::FileBase::E_None )
      95                 :            :                 {
      96                 :          0 :                     if ( aFileStatus.getFileType() == ::osl::FileStatus::Directory )
      97                 :          0 :                         aSubDirs.push_back( aFileStatus.getFileURL() );
      98                 :            :                     else
      99                 :          0 :                         aResult->push_back( aFileStatus.getFileURL() );
     100                 :            :                 }
     101                 :          0 :             }
     102                 :            : 
     103                 :            :             // iterate recursive over subfolders
     104                 :          0 :             TStringVector::const_iterator aI = aSubDirs.begin();
     105                 :          0 :             while ( aI != aSubDirs.end() )
     106                 :            :             {
     107                 :          0 :                 TStringVectorPtr aSubResult = getFiles( *aI );
     108                 :          0 :                 aResult->insert( aResult->end(), aSubResult->begin(), aSubResult->end() );
     109                 :          0 :                 ++aI;
     110                 :          0 :             }
     111                 :            :         }
     112                 :            : 
     113                 :          0 :         return aResult;
     114                 :            :     }
     115                 :            : 
     116                 :            :     // -----------------------------------------------------------------------------
     117                 :            : 
     118                 :          0 :     ::osl::FileBase::RC BasicMigration::checkAndCreateDirectory( INetURLObject& rDirURL )
     119                 :            :     {
     120                 :          0 :         ::osl::FileBase::RC aResult = ::osl::Directory::create( rDirURL.GetMainURL( INetURLObject::DECODE_TO_IURI ) );
     121                 :          0 :         if ( aResult == ::osl::FileBase::E_NOENT )
     122                 :            :         {
     123                 :          0 :             INetURLObject aBaseURL( rDirURL );
     124                 :          0 :             aBaseURL.removeSegment();
     125                 :          0 :             checkAndCreateDirectory( aBaseURL );
     126                 :          0 :             return ::osl::Directory::create( rDirURL.GetMainURL( INetURLObject::DECODE_TO_IURI ) );
     127                 :            :         }
     128                 :            :         else
     129                 :            :         {
     130                 :          0 :             return aResult;
     131                 :            :         }
     132                 :            :     }
     133                 :            : 
     134                 :            :     // -----------------------------------------------------------------------------
     135                 :            : 
     136                 :          0 :     void BasicMigration::copyFiles()
     137                 :            :     {
     138                 :          0 :         ::rtl::OUString sTargetDir;
     139                 :          0 :         ::utl::Bootstrap::PathStatus aStatus = ::utl::Bootstrap::locateUserInstallation( sTargetDir );
     140                 :          0 :         if ( aStatus == ::utl::Bootstrap::PATH_EXISTS )
     141                 :            :         {
     142                 :          0 :             sTargetDir += sTargetUserBasic;
     143                 :          0 :             TStringVectorPtr aFileList = getFiles( m_sSourceDir );
     144                 :          0 :             TStringVector::const_iterator aI = aFileList->begin();
     145                 :          0 :             while ( aI != aFileList->end() )
     146                 :            :             {
     147                 :          0 :                 ::rtl::OUString sLocalName = aI->copy( m_sSourceDir.getLength() );
     148                 :          0 :                 ::rtl::OUString sTargetName = sTargetDir + sLocalName;
     149                 :          0 :                 INetURLObject aURL( sTargetName );
     150                 :          0 :                 aURL.removeSegment();
     151                 :          0 :                 checkAndCreateDirectory( aURL );
     152                 :          0 :                 ::osl::FileBase::RC aResult = ::osl::File::copy( *aI, sTargetName );
     153                 :          0 :                 if ( aResult != ::osl::FileBase::E_None )
     154                 :            :                 {
     155                 :          0 :                     ::rtl::OString aMsg( "BasicMigration::copyFiles: cannot copy " );
     156                 :          0 :                     aMsg += ::rtl::OUStringToOString( *aI, RTL_TEXTENCODING_UTF8 ) + " to "
     157                 :          0 :                          +  ::rtl::OUStringToOString( sTargetName, RTL_TEXTENCODING_UTF8 );
     158                 :          0 :                     OSL_FAIL( aMsg.getStr() );
     159                 :            :                 }
     160                 :          0 :                 ++aI;
     161                 :          0 :             }
     162                 :            :         }
     163                 :            :         else
     164                 :            :         {
     165                 :            :             OSL_FAIL( "BasicMigration::copyFiles: no user installation!" );
     166                 :          0 :         }
     167                 :          0 :     }
     168                 :            : 
     169                 :            :     // -----------------------------------------------------------------------------
     170                 :            :     // XServiceInfo
     171                 :            :     // -----------------------------------------------------------------------------
     172                 :            : 
     173                 :          0 :     ::rtl::OUString BasicMigration::getImplementationName() throw (RuntimeException)
     174                 :            :     {
     175                 :          0 :         return BasicMigration_getImplementationName();
     176                 :            :     }
     177                 :            : 
     178                 :            :     // -----------------------------------------------------------------------------
     179                 :            : 
     180                 :          0 :     sal_Bool BasicMigration::supportsService( const ::rtl::OUString& rServiceName ) throw (RuntimeException)
     181                 :            :     {
     182                 :          0 :         Sequence< ::rtl::OUString > aNames( getSupportedServiceNames() );
     183                 :          0 :         const ::rtl::OUString* pNames = aNames.getConstArray();
     184                 :          0 :         const ::rtl::OUString* pEnd = pNames + aNames.getLength();
     185                 :          0 :         for ( ; pNames != pEnd && !pNames->equals( rServiceName ); ++pNames )
     186                 :            :             ;
     187                 :            : 
     188                 :          0 :         return pNames != pEnd;
     189                 :            :     }
     190                 :            : 
     191                 :            :     // -----------------------------------------------------------------------------
     192                 :            : 
     193                 :          0 :     Sequence< ::rtl::OUString > BasicMigration::getSupportedServiceNames() throw (RuntimeException)
     194                 :            :     {
     195                 :          0 :         return BasicMigration_getSupportedServiceNames();
     196                 :            :     }
     197                 :            : 
     198                 :            :     // -----------------------------------------------------------------------------
     199                 :            :     // XInitialization
     200                 :            :     // -----------------------------------------------------------------------------
     201                 :            : 
     202                 :          0 :     void BasicMigration::initialize( const Sequence< Any >& aArguments ) throw (Exception, RuntimeException)
     203                 :            :     {
     204                 :          0 :         ::osl::MutexGuard aGuard( m_aMutex );
     205                 :            : 
     206                 :          0 :         const Any* pIter = aArguments.getConstArray();
     207                 :          0 :         const Any* pEnd = pIter + aArguments.getLength();
     208                 :          0 :         for ( ; pIter != pEnd ; ++pIter )
     209                 :            :         {
     210                 :          0 :             beans::NamedValue aValue;
     211                 :          0 :             *pIter >>= aValue;
     212                 :          0 :             if ( aValue.Name == "UserData" )
     213                 :            :             {
     214                 :          0 :                 if ( !(aValue.Value >>= m_sSourceDir) )
     215                 :            :                 {
     216                 :            :                     OSL_FAIL( "BasicMigration::initialize: argument UserData has wrong type!" );
     217                 :            :                 }
     218                 :          0 :                 m_sSourceDir += sSourceUserBasic;
     219                 :            :                 break;
     220                 :            :             }
     221                 :          0 :         }
     222                 :          0 :     }
     223                 :            : 
     224                 :            :     // -----------------------------------------------------------------------------
     225                 :            :     // XJob
     226                 :            :     // -----------------------------------------------------------------------------
     227                 :            : 
     228                 :          0 :     Any BasicMigration::execute( const Sequence< beans::NamedValue >& )
     229                 :            :         throw (lang::IllegalArgumentException, Exception, RuntimeException)
     230                 :            :     {
     231                 :          0 :         ::osl::MutexGuard aGuard( m_aMutex );
     232                 :            : 
     233                 :          0 :         copyFiles();
     234                 :            : 
     235                 :          0 :         return Any();
     236                 :            :     }
     237                 :            : 
     238                 :            :     // =============================================================================
     239                 :            :     // component operations
     240                 :            :     // =============================================================================
     241                 :            : 
     242                 :          0 :     Reference< XInterface > SAL_CALL BasicMigration_create(
     243                 :            :         Reference< XComponentContext > const & )
     244                 :            :         SAL_THROW(())
     245                 :            :     {
     246                 :          0 :         return static_cast< lang::XTypeProvider * >( new BasicMigration() );
     247                 :            :     }
     248                 :            : 
     249                 :            :     // -----------------------------------------------------------------------------
     250                 :            : 
     251                 :            : //.........................................................................
     252                 :            : }   // namespace migration
     253                 :            : //.........................................................................
     254                 :            : 
     255                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10