lok: vcl: fix multiple floatwin removal case more robustly.
[LibreOffice.git] / desktop / source / migration / services / basicmigration.cxx
blob52388235f607c6f90bf27c47510a0e0e7145de89
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>
24 #include <sal/log.hxx>
27 using namespace ::com::sun::star;
28 using namespace ::com::sun::star::uno;
31 namespace migration
35 #define sSourceUserBasic "/user/basic"
36 #define sTargetUserBasic "/user/__basic_80"
39 // component operations
42 OUString BasicMigration_getImplementationName()
44 return "com.sun.star.comp.desktop.migration.Basic";
48 Sequence< OUString > BasicMigration_getSupportedServiceNames()
50 Sequence< OUString > aNames { "com.sun.star.migration.Basic" };
51 return aNames;
55 // BasicMigration
58 BasicMigration::BasicMigration()
63 BasicMigration::~BasicMigration()
68 TStringVectorPtr BasicMigration::getFiles( const OUString& rBaseURL ) const
70 TStringVectorPtr aResult( new TStringVector );
71 ::osl::Directory aDir( rBaseURL);
73 if ( aDir.open() == ::osl::FileBase::E_None )
75 // iterate over directory content
76 TStringVector aSubDirs;
77 ::osl::DirectoryItem aItem;
78 while ( aDir.getNextItem( aItem ) == ::osl::FileBase::E_None )
80 ::osl::FileStatus aFileStatus( osl_FileStatus_Mask_Type | osl_FileStatus_Mask_FileURL );
81 if ( aItem.getFileStatus( aFileStatus ) == ::osl::FileBase::E_None )
83 if ( aFileStatus.getFileType() == ::osl::FileStatus::Directory )
84 aSubDirs.push_back( aFileStatus.getFileURL() );
85 else
86 aResult->push_back( aFileStatus.getFileURL() );
90 // iterate recursive over subfolders
91 for (auto const& subDir : aSubDirs)
93 TStringVectorPtr aSubResult = getFiles(subDir);
94 aResult->insert( aResult->end(), aSubResult->begin(), aSubResult->end() );
98 return aResult;
102 void BasicMigration::checkAndCreateDirectory( INetURLObject const & rDirURL )
104 ::osl::FileBase::RC aResult = ::osl::Directory::create( rDirURL.GetMainURL( INetURLObject::DecodeMechanism::ToIUri ) );
105 if ( aResult == ::osl::FileBase::E_NOENT )
107 INetURLObject aBaseURL( rDirURL );
108 aBaseURL.removeSegment();
109 checkAndCreateDirectory( aBaseURL );
110 ::osl::Directory::create( rDirURL.GetMainURL( INetURLObject::DecodeMechanism::ToIUri ) );
115 void BasicMigration::copyFiles()
117 OUString sTargetDir;
118 ::utl::Bootstrap::PathStatus aStatus = ::utl::Bootstrap::locateUserInstallation( sTargetDir );
119 if ( aStatus == ::utl::Bootstrap::PATH_EXISTS )
121 sTargetDir += sTargetUserBasic;
122 TStringVectorPtr aFileList = getFiles( m_sSourceDir );
123 for (auto const& elem : *aFileList)
125 OUString sLocalName = elem.copy( m_sSourceDir.getLength() );
126 OUString sTargetName = sTargetDir + sLocalName;
127 INetURLObject aURL( sTargetName );
128 aURL.removeSegment();
129 checkAndCreateDirectory( aURL );
130 ::osl::FileBase::RC aResult = ::osl::File::copy( elem, sTargetName );
131 if ( aResult != ::osl::FileBase::E_None )
133 SAL_WARN( "desktop", "BasicMigration::copyFiles: cannot copy "
134 << elem << " to " << sTargetName );
138 else
140 OSL_FAIL( "BasicMigration::copyFiles: no user installation!" );
145 // XServiceInfo
148 OUString BasicMigration::getImplementationName()
150 return BasicMigration_getImplementationName();
154 sal_Bool BasicMigration::supportsService(OUString const & ServiceName)
156 return cppu::supportsService(this, ServiceName);
160 Sequence< OUString > BasicMigration::getSupportedServiceNames()
162 return BasicMigration_getSupportedServiceNames();
166 // XInitialization
169 void BasicMigration::initialize( const Sequence< Any >& aArguments )
171 ::osl::MutexGuard aGuard( m_aMutex );
173 const Any* pIter = aArguments.getConstArray();
174 const Any* pEnd = pIter + aArguments.getLength();
175 for ( ; pIter != pEnd ; ++pIter )
177 beans::NamedValue aValue;
178 *pIter >>= aValue;
179 if ( aValue.Name == "UserData" )
181 if ( !(aValue.Value >>= m_sSourceDir) )
183 OSL_FAIL( "BasicMigration::initialize: argument UserData has wrong type!" );
185 m_sSourceDir += sSourceUserBasic;
186 break;
192 // XJob
195 Any BasicMigration::execute( const Sequence< beans::NamedValue >& )
197 ::osl::MutexGuard aGuard( m_aMutex );
199 copyFiles();
201 return Any();
205 // component operations
208 Reference< XInterface > BasicMigration_create(
209 Reference< XComponentContext > const & )
211 return static_cast< lang::XTypeProvider * >( new BasicMigration() );
215 } // namespace migration
218 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */