LibreOffice Module desktop (master)  1
basicmigration.cxx
Go to the documentation of this file.
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"
22 #include <tools/urlobj.hxx>
23 #include <unotools/bootstrap.hxx>
24 #include <sal/log.hxx>
25 
26 
27 using namespace ::com::sun::star;
28 using namespace ::com::sun::star::uno;
29 
30 
31 namespace migration
32 {
33 
34 
35  #define sSourceUserBasic "/user/basic"
36  #define sTargetUserBasic "/user/__basic_80"
37 
38 
39  // component operations
40 
41 
43  {
44  return OUString("com.sun.star.comp.desktop.migration.Basic");
45  }
46 
47 
49  {
50  Sequence< OUString > aNames { "com.sun.star.migration.Basic" };
51  return aNames;
52  }
53 
54 
55  // BasicMigration
56 
57 
59  {
60  }
61 
62 
64  {
65  }
66 
67 
68  TStringVectorPtr BasicMigration::getFiles( const OUString& rBaseURL ) const
69  {
70  TStringVectorPtr aResult( new TStringVector );
71  ::osl::Directory aDir( rBaseURL);
72 
73  if ( aDir.open() == ::osl::FileBase::E_None )
74  {
75  // iterate over directory content
76  TStringVector aSubDirs;
77  ::osl::DirectoryItem aItem;
78  while ( aDir.getNextItem( aItem ) == ::osl::FileBase::E_None )
79  {
80  ::osl::FileStatus aFileStatus( osl_FileStatus_Mask_Type | osl_FileStatus_Mask_FileURL );
81  if ( aItem.getFileStatus( aFileStatus ) == ::osl::FileBase::E_None )
82  {
83  if ( aFileStatus.getFileType() == ::osl::FileStatus::Directory )
84  aSubDirs.push_back( aFileStatus.getFileURL() );
85  else
86  aResult->push_back( aFileStatus.getFileURL() );
87  }
88  }
89 
90  // iterate recursive over subfolders
91  for (auto const& subDir : aSubDirs)
92  {
93  TStringVectorPtr aSubResult = getFiles(subDir);
94  aResult->insert( aResult->end(), aSubResult->begin(), aSubResult->end() );
95  }
96  }
97 
98  return aResult;
99  }
100 
101 
103  {
104  ::osl::FileBase::RC aResult = ::osl::Directory::create( rDirURL.GetMainURL( INetURLObject::DecodeMechanism::ToIUri ) );
105  if ( aResult == ::osl::FileBase::E_NOENT )
106  {
107  INetURLObject aBaseURL( rDirURL );
108  aBaseURL.removeSegment();
109  checkAndCreateDirectory( aBaseURL );
111  }
112  }
113 
114 
116  {
117  OUString sTargetDir;
119  if ( aStatus == ::utl::Bootstrap::PATH_EXISTS )
120  {
121  sTargetDir += sTargetUserBasic;
122  TStringVectorPtr aFileList = getFiles( m_sSourceDir );
123  for (auto const& elem : *aFileList)
124  {
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 )
132  {
133  SAL_WARN( "desktop", "BasicMigration::copyFiles: cannot copy "
134  << elem << " to " << sTargetName );
135  }
136  }
137  }
138  else
139  {
140  OSL_FAIL( "BasicMigration::copyFiles: no user installation!" );
141  }
142  }
143 
144 
145  // XServiceInfo
146 
147 
149  {
151  }
152 
153 
154  sal_Bool BasicMigration::supportsService(OUString const & ServiceName)
155  {
156  return cppu::supportsService(this, ServiceName);
157  }
158 
159 
161  {
163  }
164 
165 
166  // XInitialization
167 
168 
169  void BasicMigration::initialize( const Sequence< Any >& aArguments )
170  {
171  ::osl::MutexGuard aGuard( m_aMutex );
172 
173  const Any* pIter = aArguments.getConstArray();
174  const Any* pEnd = pIter + aArguments.getLength();
175  for ( ; pIter != pEnd ; ++pIter )
176  {
177  beans::NamedValue aValue;
178  *pIter >>= aValue;
179  if ( aValue.Name == "UserData" )
180  {
181  if ( !(aValue.Value >>= m_sSourceDir) )
182  {
183  OSL_FAIL( "BasicMigration::initialize: argument UserData has wrong type!" );
184  }
186  break;
187  }
188  }
189  }
190 
191 
192  // XJob
193 
194 
195  Any BasicMigration::execute( const Sequence< beans::NamedValue >& )
196  {
197  ::osl::MutexGuard aGuard( m_aMutex );
198 
199  copyFiles();
200 
201  return Any();
202  }
203 
204 
205  // component operations
206 
207 
210  {
211  return static_cast< lang::XTypeProvider * >( new BasicMigration() );
212  }
213 
214 
215 } // namespace migration
216 
217 
218 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual css::uno::Any SAL_CALL execute(const css::uno::Sequence< css::beans::NamedValue > &Arguments) override
static PathStatus locateUserInstallation(OUString &_rURL)
OUString BasicMigration_getImplementationName()
Reference< XInterface > BasicMigration_create(Reference< XComponentContext > const &)
virtual ~BasicMigration() override
css::uno::Reference< css::deployment::XPackageRegistry > create(css::uno::Reference< css::deployment::XPackageRegistry > const &xRootRegistry, OUString const &context, OUString const &cachePath, css::uno::Reference< css::uno::XComponentContext > const &xComponentContext)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
void checkAndCreateDirectory(INetURLObject const &rDirURL)
Sequence< OUString > BasicMigration_getSupportedServiceNames()
std::unique_ptr< TStringVector > TStringVectorPtr
Definition: misc.hxx:34
unsigned char sal_Bool
std::vector< OUString > TStringVector
Definition: misc.hxx:33
OUString GetMainURL(DecodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
#define sSourceUserBasic
#define SAL_WARN(area, stream)
TStringVectorPtr getFiles(const OUString &rBaseURL) const
#define sTargetUserBasic
virtual OUString SAL_CALL getImplementationName() override
bool removeSegment(sal_Int32 nIndex=LAST_SEGMENT, bool bIgnoreFinalSlash=true)
virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any > &aArguments) override
virtual sal_Bool SAL_CALL supportsService(const OUString &rServiceName) override