GPU-Calc: remove Alloc_Host_Ptr for clmem of NAN vector
[LibreOffice.git] / desktop / source / migration / services / basicmigration.cxx
blobc35a167e8a9498b9fc1a616e74b56e39dee2ac39
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "basicmigration.hxx"
21 #include <cppuhelper/supportsservice.hxx>
22 #include <tools/urlobj.hxx>
23 #include <unotools/bootstrap.hxx>
26 using namespace ::com::sun::star;
27 using namespace ::com::sun::star::uno;
30 //.........................................................................
31 namespace migration
33 //.........................................................................
36 #define sSourceUserBasic OUString( "/user/basic" )
37 #define sTargetUserBasic OUString( "/user/__basic_80" )
39 // =============================================================================
40 // component operations
41 // =============================================================================
43 OUString BasicMigration_getImplementationName()
45 return OUString("com.sun.star.comp.desktop.migration.Basic");
48 // -----------------------------------------------------------------------------
50 Sequence< OUString > BasicMigration_getSupportedServiceNames()
52 Sequence< OUString > aNames(1);
53 aNames.getArray()[0] = "com.sun.star.migration.Basic";
54 return aNames;
57 // =============================================================================
58 // BasicMigration
59 // =============================================================================
61 BasicMigration::BasicMigration()
65 // -----------------------------------------------------------------------------
67 BasicMigration::~BasicMigration()
71 // -----------------------------------------------------------------------------
73 TStringVectorPtr BasicMigration::getFiles( const OUString& rBaseURL ) const
75 TStringVectorPtr aResult( new TStringVector );
76 ::osl::Directory aDir( rBaseURL);
78 if ( aDir.open() == ::osl::FileBase::E_None )
80 // iterate over directory content
81 TStringVector aSubDirs;
82 ::osl::DirectoryItem aItem;
83 while ( aDir.getNextItem( aItem ) == ::osl::FileBase::E_None )
85 ::osl::FileStatus aFileStatus( osl_FileStatus_Mask_Type | osl_FileStatus_Mask_FileURL );
86 if ( aItem.getFileStatus( aFileStatus ) == ::osl::FileBase::E_None )
88 if ( aFileStatus.getFileType() == ::osl::FileStatus::Directory )
89 aSubDirs.push_back( aFileStatus.getFileURL() );
90 else
91 aResult->push_back( aFileStatus.getFileURL() );
95 // iterate recursive over subfolders
96 TStringVector::const_iterator aI = aSubDirs.begin();
97 while ( aI != aSubDirs.end() )
99 TStringVectorPtr aSubResult = getFiles( *aI );
100 aResult->insert( aResult->end(), aSubResult->begin(), aSubResult->end() );
101 ++aI;
105 return aResult;
108 // -----------------------------------------------------------------------------
110 ::osl::FileBase::RC BasicMigration::checkAndCreateDirectory( INetURLObject& rDirURL )
112 ::osl::FileBase::RC aResult = ::osl::Directory::create( rDirURL.GetMainURL( INetURLObject::DECODE_TO_IURI ) );
113 if ( aResult == ::osl::FileBase::E_NOENT )
115 INetURLObject aBaseURL( rDirURL );
116 aBaseURL.removeSegment();
117 checkAndCreateDirectory( aBaseURL );
118 return ::osl::Directory::create( rDirURL.GetMainURL( INetURLObject::DECODE_TO_IURI ) );
120 else
122 return aResult;
126 // -----------------------------------------------------------------------------
128 void BasicMigration::copyFiles()
130 OUString sTargetDir;
131 ::utl::Bootstrap::PathStatus aStatus = ::utl::Bootstrap::locateUserInstallation( sTargetDir );
132 if ( aStatus == ::utl::Bootstrap::PATH_EXISTS )
134 sTargetDir += sTargetUserBasic;
135 TStringVectorPtr aFileList = getFiles( m_sSourceDir );
136 TStringVector::const_iterator aI = aFileList->begin();
137 while ( aI != aFileList->end() )
139 OUString sLocalName = aI->copy( m_sSourceDir.getLength() );
140 OUString sTargetName = sTargetDir + sLocalName;
141 INetURLObject aURL( sTargetName );
142 aURL.removeSegment();
143 checkAndCreateDirectory( aURL );
144 ::osl::FileBase::RC aResult = ::osl::File::copy( *aI, sTargetName );
145 if ( aResult != ::osl::FileBase::E_None )
147 OString aMsg( "BasicMigration::copyFiles: cannot copy " );
148 aMsg += OUStringToOString( *aI, RTL_TEXTENCODING_UTF8 ) + " to "
149 + OUStringToOString( sTargetName, RTL_TEXTENCODING_UTF8 );
150 OSL_FAIL( aMsg.getStr() );
152 ++aI;
155 else
157 OSL_FAIL( "BasicMigration::copyFiles: no user installation!" );
161 // -----------------------------------------------------------------------------
162 // XServiceInfo
163 // -----------------------------------------------------------------------------
165 OUString BasicMigration::getImplementationName() throw (RuntimeException)
167 return BasicMigration_getImplementationName();
170 // -----------------------------------------------------------------------------
172 sal_Bool BasicMigration::supportsService(OUString const & ServiceName)
173 throw (css::uno::RuntimeException)
175 return cppu::supportsService(this, ServiceName);
178 // -----------------------------------------------------------------------------
180 Sequence< OUString > BasicMigration::getSupportedServiceNames() throw (RuntimeException)
182 return BasicMigration_getSupportedServiceNames();
185 // -----------------------------------------------------------------------------
186 // XInitialization
187 // -----------------------------------------------------------------------------
189 void BasicMigration::initialize( const Sequence< Any >& aArguments ) throw (Exception, RuntimeException)
191 ::osl::MutexGuard aGuard( m_aMutex );
193 const Any* pIter = aArguments.getConstArray();
194 const Any* pEnd = pIter + aArguments.getLength();
195 for ( ; pIter != pEnd ; ++pIter )
197 beans::NamedValue aValue;
198 *pIter >>= aValue;
199 if ( aValue.Name == "UserData" )
201 if ( !(aValue.Value >>= m_sSourceDir) )
203 OSL_FAIL( "BasicMigration::initialize: argument UserData has wrong type!" );
205 m_sSourceDir += sSourceUserBasic;
206 break;
211 // -----------------------------------------------------------------------------
212 // XJob
213 // -----------------------------------------------------------------------------
215 Any BasicMigration::execute( const Sequence< beans::NamedValue >& )
216 throw (lang::IllegalArgumentException, Exception, RuntimeException)
218 ::osl::MutexGuard aGuard( m_aMutex );
220 copyFiles();
222 return Any();
225 // =============================================================================
226 // component operations
227 // =============================================================================
229 Reference< XInterface > SAL_CALL BasicMigration_create(
230 Reference< XComponentContext > const & )
231 SAL_THROW(())
233 return static_cast< lang::XTypeProvider * >( new BasicMigration() );
236 // -----------------------------------------------------------------------------
238 //.........................................................................
239 } // namespace migration
240 //.........................................................................
242 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */