LCOV - code coverage report
Current view: top level - desktop/source/migration - migration.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 112 711 15.8 %
Date: 2015-06-13 12:38:46 Functions: 12 38 31.6 %
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 <sal/config.h>
      21             : 
      22             : #include <algorithm>
      23             : #include <iterator>
      24             : #include <map>
      25             : #include <new>
      26             : #include <set>
      27             : 
      28             : #include "migration.hxx"
      29             : #include "migration_impl.hxx"
      30             : 
      31             : #include <sal/log.hxx>
      32             : #include <unotools/textsearch.hxx>
      33             : #include <comphelper/processfactory.hxx>
      34             : #include <comphelper/sequence.hxx>
      35             : #include <unotools/bootstrap.hxx>
      36             : #include <rtl/bootstrap.hxx>
      37             : #include <rtl/uri.hxx>
      38             : #include <i18nlangtag/lang.h>
      39             : #include <tools/urlobj.hxx>
      40             : #include <osl/file.hxx>
      41             : #include <osl/mutex.hxx>
      42             : #include <osl/security.hxx>
      43             : #include <unotools/configmgr.hxx>
      44             : 
      45             : #include <com/sun/star/configuration/Update.hpp>
      46             : #include <com/sun/star/configuration/theDefaultProvider.hpp>
      47             : #include <com/sun/star/lang/XInitialization.hpp>
      48             : #include <com/sun/star/task/XJob.hpp>
      49             : #include <com/sun/star/beans/NamedValue.hpp>
      50             : #include <com/sun/star/beans/XPropertySet.hpp>
      51             : #include <com/sun/star/util/XRefreshable.hpp>
      52             : #include <com/sun/star/util/XChangesBatch.hpp>
      53             : #include <com/sun/star/util/XStringSubstitution.hpp>
      54             : #include <com/sun/star/embed/ElementModes.hpp>
      55             : #include <com/sun/star/embed/FileSystemStorageFactory.hpp>
      56             : #include <com/sun/star/embed/XStorage.hpp>
      57             : #include <com/sun/star/ui/theModuleUIConfigurationManagerSupplier.hpp>
      58             : #include <com/sun/star/frame/theUICommandDescription.hpp>
      59             : #include <com/sun/star/ui/UIConfigurationManager.hpp>
      60             : #include <com/sun/star/ui/XUIConfiguration.hpp>
      61             : #include <com/sun/star/ui/XUIConfigurationStorage.hpp>
      62             : #include <com/sun/star/ui/XUIConfigurationPersistence.hpp>
      63             : 
      64             : using namespace osl;
      65             : using namespace std;
      66             : using namespace com::sun::star::task;
      67             : using namespace com::sun::star::lang;
      68             : using namespace com::sun::star::beans;
      69             : using namespace com::sun::star::util;
      70             : using namespace com::sun::star::container;
      71             : using com::sun::star::uno::Exception;
      72             : using namespace com::sun::star;
      73             : 
      74             : 
      75             : namespace desktop {
      76             : 
      77             : static const char ITEM_DESCRIPTOR_COMMANDURL[] = "CommandURL";
      78             : static const char ITEM_DESCRIPTOR_CONTAINER[] = "ItemDescriptorContainer";
      79             : static const char ITEM_DESCRIPTOR_LABEL[] = "Label";
      80             : 
      81           0 : OUString retrieveLabelFromCommand(const OUString& sCommand, const OUString& sModuleIdentifier)
      82             : {
      83           0 :     OUString sLabel;
      84             : 
      85           0 :     uno::Reference< container::XNameAccess > xUICommands;
      86             :     uno::Reference< container::XNameAccess > const xNameAccess(
      87             :             frame::theUICommandDescription::get(
      88           0 :                 ::comphelper::getProcessComponentContext()) );
      89           0 :     xNameAccess->getByName( sModuleIdentifier ) >>= xUICommands;
      90           0 :     if (xUICommands.is())
      91             :     {
      92           0 :         if ( !sCommand.isEmpty() )
      93             :         {
      94           0 :             OUString aStr;
      95           0 :             ::uno::Sequence< beans::PropertyValue > aPropSeq;
      96             :             try
      97             :             {
      98           0 :                 uno::Any a( xUICommands->getByName( sCommand ));
      99           0 :                 if ( a >>= aPropSeq )
     100             :                 {
     101           0 :                     for ( sal_Int32 i = 0; i < aPropSeq.getLength(); i++ )
     102             :                     {
     103           0 :                         if ( aPropSeq[i].Name == "Label" )
     104             :                         {
     105           0 :                             aPropSeq[i].Value >>= aStr;
     106           0 :                             break;
     107             :                         }
     108             :                     }
     109             :                 }
     110             : 
     111           0 :                 sLabel = aStr;
     112             :             }
     113           0 :             catch (const container::NoSuchElementException&)
     114             :             {
     115           0 :                 sLabel = sCommand;
     116           0 :                 sal_Int32 nIndex = sLabel.indexOf(':');
     117           0 :                 if (nIndex>=0 && nIndex <= sLabel.getLength()-1)
     118           0 :                     sLabel = sLabel.copy(nIndex+1);
     119           0 :             }
     120             : 
     121             :         }
     122             :     }
     123             : 
     124           0 :     return sLabel;
     125             : }
     126             : 
     127           0 : OUString mapModuleShortNameToIdentifier(const OUString& sShortName)
     128             : {
     129           0 :     OUString sIdentifier;
     130             : 
     131           0 :     if ( sShortName == "StartModule" )
     132           0 :         sIdentifier = "com.sun.star.frame.StartModule";
     133             : 
     134           0 :     else if ( sShortName == "swriter" )
     135           0 :         sIdentifier = "com.sun.star.text.TextDocument";
     136             : 
     137           0 :     else if ( sShortName == "scalc" )
     138           0 :         sIdentifier = "com.sun.star.sheet.SpreadsheetDocument";
     139             : 
     140           0 :     else if ( sShortName == "sdraw" )
     141           0 :         sIdentifier = "com.sun.star.drawing.DrawingDocument";
     142             : 
     143           0 :     else if ( sShortName == "simpress" )
     144           0 :         sIdentifier = "com.sun.star.presentation.PresentationDocument";
     145             : 
     146           0 :     else if ( sShortName == "smath" )
     147           0 :         sIdentifier = "com.sun.star.formula.FormulaProperties";
     148             : 
     149           0 :     else if ( sShortName == "schart" )
     150           0 :         sIdentifier = "com.sun.star.chart2.ChartDocument";
     151             : 
     152           0 :     else if ( sShortName == "BasicIDE" )
     153           0 :         sIdentifier = "com.sun.star.script.BasicIDE";
     154             : 
     155           0 :     else if ( sShortName == "dbapp" )
     156           0 :         sIdentifier = "com.sun.star.sdb.OfficeDatabaseDocument";
     157             : 
     158           0 :     else if ( sShortName == "sglobal" )
     159           0 :         sIdentifier = "com.sun.star.text.GlobalDocument";
     160             : 
     161           0 :     else if ( sShortName == "sweb" )
     162           0 :         sIdentifier = "com.sun.star.text.WebDocument";
     163             : 
     164           0 :     else if ( sShortName == "swxform" )
     165           0 :         sIdentifier = "com.sun.star.xforms.XMLFormDocument";
     166             : 
     167           0 :     else if ( sShortName == "sbibliography" )
     168           0 :         sIdentifier = "com.sun.star.frame.Bibliography";
     169             : 
     170           0 :     return sIdentifier;
     171             : }
     172             : 
     173           0 : bool MigrationImpl::alreadyMigrated()
     174             : {
     175           0 :     OUString MIGRATION_STAMP_NAME("/MIGRATED4");
     176           0 :     OUString aStr = m_aInfo.userdata + MIGRATION_STAMP_NAME;
     177           0 :     File aFile(aStr);
     178             :     // create migration stamp, and/or check its existence
     179           0 :     bool bRet = aFile.open (osl_File_OpenFlag_Write | osl_File_OpenFlag_Create | osl_File_OpenFlag_NoLock) == FileBase::E_EXIST;
     180             :     OSL_TRACE( "File '%s' exists? %d\n",
     181             :              OUStringToOString(aStr, RTL_TEXTENCODING_ASCII_US).getStr(),
     182             :              bRet );
     183           0 :     return bRet;
     184             : }
     185             : 
     186          53 : bool MigrationImpl::initializeMigration()
     187             : {
     188          53 :     bool bRet = false;
     189             : 
     190          53 :     if (!checkMigrationCompleted()) {
     191          53 :         readAvailableMigrations(m_vMigrationsAvailable);
     192          53 :         sal_Int32 nIndex = findPreferredMigrationProcess(m_vMigrationsAvailable);
     193             :         // m_aInfo is now set to the preferred migration source
     194          53 :         if ( nIndex >= 0 ) {
     195           0 :             if (alreadyMigrated())
     196           0 :                 return false;
     197           0 :             m_vrMigrations = readMigrationSteps(m_vMigrationsAvailable[nIndex].name);
     198             :         }
     199             : 
     200          53 :         bRet = !m_aInfo.userdata.isEmpty();
     201             :     }
     202             : 
     203             :     OSL_TRACE( "Migration %s", bRet ? "needed" : "not required" );
     204             : 
     205          53 :     return bRet;
     206             : }
     207             : 
     208          53 : void Migration::migrateSettingsIfNecessary()
     209             : {
     210          53 :     MigrationImpl aImpl;
     211             : 
     212          53 :     if (! aImpl.initializeMigration() )
     213         106 :         return;
     214             : 
     215           0 :     bool bResult = false;
     216             :     try
     217             :     {
     218           0 :         bResult = aImpl.doMigration();
     219             :     }
     220           0 :     catch (const Exception& e)
     221             :     {
     222           0 :         OString aMsg("doMigration() exception: ");
     223           0 :         aMsg += OUStringToOString(e.Message, RTL_TEXTENCODING_ASCII_US);
     224           0 :         OSL_FAIL(aMsg.getStr());
     225             :     }
     226             :     OSL_ENSURE(bResult, "Migration has not been successful");
     227           0 :     (void)bResult;
     228             : }
     229             : 
     230          53 : MigrationImpl::MigrationImpl()
     231          53 :     : m_vrVersions(new strings_v)
     232             : {
     233          53 : }
     234             : 
     235          53 : MigrationImpl::~MigrationImpl()
     236             : {
     237          53 : }
     238             : 
     239             : // The main entry point for migrating settings
     240           0 : bool MigrationImpl::doMigration()
     241             : {
     242             :     // compile file list for migration
     243           0 :     m_vrFileList = compileFileList();
     244             : 
     245           0 :     bool result = false;
     246             :     try
     247             :     {
     248           0 :         NewVersionUIInfo aNewVersionUIInfo;
     249           0 :         ::std::vector< MigrationModuleInfo > vModulesInfo = dectectUIChangesForAllModules();
     250           0 :         aNewVersionUIInfo.init(vModulesInfo);
     251             : 
     252           0 :         copyFiles();
     253             : 
     254           0 :         const OUString sMenubarResourceURL("private:resource/menubar/menubar");
     255           0 :         const OUString sToolbarResourcePre("private:resource/toolbar/");
     256           0 :         for (size_t i=0; i<vModulesInfo.size(); ++i)
     257             :         {
     258           0 :             OUString sModuleIdentifier = mapModuleShortNameToIdentifier(vModulesInfo[i].sModuleShortName);
     259           0 :             if (sModuleIdentifier.isEmpty())
     260           0 :                 continue;
     261             : 
     262           0 :             uno::Sequence< uno::Any > lArgs(2);
     263           0 :             OUString aOldCfgDataPath = m_aInfo.userdata + "/user/config/soffice.cfg/modules/";
     264           0 :             lArgs[0] <<= aOldCfgDataPath + vModulesInfo[i].sModuleShortName;
     265           0 :             lArgs[1] <<= embed::ElementModes::READ;
     266             : 
     267           0 :             uno::Reference< uno::XComponentContext > xContext(comphelper::getProcessComponentContext());
     268           0 :             uno::Reference< lang::XSingleServiceFactory > xStorageFactory(embed::FileSystemStorageFactory::create(xContext));
     269           0 :             uno::Reference< embed::XStorage >             xModules(xStorageFactory->createInstanceWithArguments(lArgs), uno::UNO_QUERY);
     270           0 :             uno::Reference< ui::XUIConfigurationManager2 > xOldCfgManager = ui::UIConfigurationManager::create(xContext);
     271             : 
     272           0 :             if ( xModules.is() )
     273             :             {
     274           0 :                     xOldCfgManager->setStorage( xModules );
     275           0 :                     xOldCfgManager->reload();
     276             :             }
     277             : 
     278           0 :             uno::Reference< ui::XUIConfigurationManager > xCfgManager = aNewVersionUIInfo.getConfigManager(vModulesInfo[i].sModuleShortName);
     279             : 
     280           0 :             if (vModulesInfo[i].bHasMenubar)
     281             :             {
     282           0 :                 uno::Reference< container::XIndexContainer > xOldVersionMenuSettings = uno::Reference< container::XIndexContainer >(xOldCfgManager->getSettings(sMenubarResourceURL, sal_True), uno::UNO_QUERY);
     283           0 :                 uno::Reference< container::XIndexContainer > xNewVersionMenuSettings = aNewVersionUIInfo.getNewMenubarSettings(vModulesInfo[i].sModuleShortName);
     284           0 :                 OUString sParent;
     285           0 :                 compareOldAndNewConfig(sParent, xOldVersionMenuSettings, xNewVersionMenuSettings, sMenubarResourceURL);
     286           0 :                 mergeOldToNewVersion(xCfgManager, xNewVersionMenuSettings, sModuleIdentifier, sMenubarResourceURL);
     287             :             }
     288             : 
     289           0 :             sal_Int32 nToolbars = vModulesInfo[i].m_vToolbars.size();
     290           0 :             if (nToolbars >0)
     291             :             {
     292           0 :                 for (sal_Int32 j=0; j<nToolbars; ++j)
     293             :                 {
     294           0 :                     OUString sToolbarName = vModulesInfo[i].m_vToolbars[j];
     295           0 :                     OUString sToolbarResourceURL = sToolbarResourcePre + sToolbarName;
     296             : 
     297           0 :                     uno::Reference< container::XIndexContainer > xOldVersionToolbarSettings = uno::Reference< container::XIndexContainer >(xOldCfgManager->getSettings(sToolbarResourceURL, sal_True), uno::UNO_QUERY);
     298           0 :                     uno::Reference< container::XIndexContainer > xNewVersionToolbarSettings = aNewVersionUIInfo.getNewToolbarSettings(vModulesInfo[i].sModuleShortName, sToolbarName);
     299           0 :                     OUString sParent;
     300           0 :                     compareOldAndNewConfig(sParent, xOldVersionToolbarSettings, xNewVersionToolbarSettings, sToolbarResourceURL);
     301           0 :                     mergeOldToNewVersion(xCfgManager, xNewVersionToolbarSettings, sModuleIdentifier, sToolbarResourceURL);
     302           0 :                 }
     303             :             }
     304             : 
     305           0 :             m_aOldVersionItemsHashMap.clear();
     306           0 :         }
     307             : 
     308             :         // execute the migration items from Setup.xcu
     309           0 :         copyConfig();
     310             : 
     311             :         // execute custom migration services from Setup.xcu
     312             :         // and refresh the cache
     313           0 :         runServices();
     314           0 :         refresh();
     315             : 
     316           0 :         result = true;
     317             :     }
     318           0 :     catch (css::uno::Exception & e)
     319             :     {
     320             :         SAL_WARN(
     321             :             "desktop.migration",
     322             :             "ignored Exception \"" << e.Message
     323             :                 << "\" while migrating from version \"" << m_aInfo.productname
     324             :                 << "\" data \"" << m_aInfo.userdata << "\"");
     325             :     }
     326             : 
     327             :     // prevent running the migration multiple times
     328           0 :     setMigrationCompleted();
     329           0 :     return result;
     330             : }
     331             : 
     332           0 : void MigrationImpl::refresh()
     333             : {
     334             :     uno::Reference< XRefreshable >(
     335             :         configuration::theDefaultProvider::get(comphelper::getProcessComponentContext()),
     336           0 :         uno::UNO_QUERY_THROW)->refresh();
     337           0 : }
     338             : 
     339           0 : void MigrationImpl::setMigrationCompleted()
     340             : {
     341             :     try
     342             :     {
     343           0 :         uno::Reference< XPropertySet > aPropertySet(getConfigAccess("org.openoffice.Setup/Office", true), uno::UNO_QUERY_THROW);
     344           0 :         aPropertySet->setPropertyValue("MigrationCompleted", uno::makeAny(sal_True));
     345           0 :         uno::Reference< XChangesBatch >(aPropertySet, uno::UNO_QUERY_THROW)->commitChanges();
     346             :     }
     347           0 :     catch (...)
     348             :     {
     349             :         // fail silently
     350             :     }
     351           0 : }
     352             : 
     353          53 : bool MigrationImpl::checkMigrationCompleted()
     354             : {
     355          53 :     bool bMigrationCompleted = false;
     356             :     try {
     357             :         uno::Reference< XPropertySet > aPropertySet(
     358          53 :             getConfigAccess("org.openoffice.Setup/Office"), uno::UNO_QUERY_THROW);
     359          53 :         aPropertySet->getPropertyValue("MigrationCompleted") >>= bMigrationCompleted;
     360             : 
     361          53 :         if( !bMigrationCompleted && getenv("SAL_DISABLE_USERMIGRATION" ) )
     362             :         {
     363             :             // migration prevented - fake it's success
     364           0 :             setMigrationCompleted();
     365           0 :             bMigrationCompleted = true;
     366          53 :         }
     367             :     }
     368           0 :     catch (const Exception&)
     369             :     {
     370             :         // just return false...
     371             :     }
     372             :     OSL_TRACE( "Migration %s", bMigrationCompleted ? "already completed" : "not done" );
     373             : 
     374          53 :     return bMigrationCompleted;
     375             : }
     376             : 
     377          53 : static void insertSorted(migrations_available& rAvailableMigrations, supported_migration& aSupportedMigration)
     378             : {
     379          53 :     bool                           bInserted( false );
     380          53 :     migrations_available::iterator pIter = rAvailableMigrations.begin();
     381         106 :     while ( !bInserted && pIter != rAvailableMigrations.end())
     382             :     {
     383           0 :         if ( pIter->nPriority < aSupportedMigration.nPriority )
     384             :         {
     385           0 :             rAvailableMigrations.insert(pIter, aSupportedMigration );
     386           0 :             bInserted = true;
     387           0 :             break; // i111193: insert invalidates iterator!
     388             :         }
     389           0 :         ++pIter;
     390             :     }
     391          53 :     if ( !bInserted )
     392          53 :         rAvailableMigrations.push_back( aSupportedMigration );
     393          53 : }
     394             : 
     395          53 : bool MigrationImpl::readAvailableMigrations(migrations_available& rAvailableMigrations)
     396             : {
     397             :     // get supported version names
     398          53 :     uno::Reference< XNameAccess > aMigrationAccess(getConfigAccess("org.openoffice.Setup/Migration/SupportedVersions"), uno::UNO_QUERY_THROW);
     399         106 :     uno::Sequence< OUString > seqSupportedVersions = aMigrationAccess->getElementNames();
     400             : 
     401         106 :     const OUString aVersionIdentifiers( "VersionIdentifiers" );
     402         106 :     const OUString aPriorityIdentifier( "Priority" );
     403             : 
     404         106 :     for (sal_Int32 i=0; i<seqSupportedVersions.getLength(); i++)
     405             :     {
     406          53 :         sal_Int32                 nPriority( 0 );
     407          53 :         uno::Sequence< OUString > seqVersions;
     408         106 :         uno::Reference< XNameAccess > xMigrationData( aMigrationAccess->getByName(seqSupportedVersions[i]), uno::UNO_QUERY_THROW );
     409          53 :         xMigrationData->getByName( aVersionIdentifiers ) >>= seqVersions;
     410          53 :         xMigrationData->getByName( aPriorityIdentifier ) >>= nPriority;
     411             : 
     412         106 :         supported_migration aSupportedMigration;
     413          53 :         aSupportedMigration.name      = seqSupportedVersions[i];
     414          53 :         aSupportedMigration.nPriority = nPriority;
     415         318 :         for (sal_Int32 j=0; j<seqVersions.getLength(); j++)
     416         265 :             aSupportedMigration.supported_versions.push_back(seqVersions[j].trim());
     417          53 :         insertSorted( rAvailableMigrations, aSupportedMigration );
     418             :         OSL_TRACE( " available migration '%s'\n",
     419             :                    OUStringToOString( aSupportedMigration.name, RTL_TEXTENCODING_ASCII_US ).getStr() );
     420          53 :     }
     421             : 
     422         106 :     return true;
     423             : }
     424             : 
     425           0 : migrations_vr MigrationImpl::readMigrationSteps(const OUString& rMigrationName)
     426             : {
     427             :     // get migration access
     428           0 :     uno::Reference< XNameAccess > aMigrationAccess(getConfigAccess("org.openoffice.Setup/Migration/SupportedVersions"), uno::UNO_QUERY_THROW);
     429           0 :     uno::Reference< XNameAccess > xMigrationData( aMigrationAccess->getByName(rMigrationName), uno::UNO_QUERY_THROW );
     430             : 
     431             :     // get migration description from org.openoffice.Setup/Migration
     432             :     // and build vector of migration steps
     433           0 :     OUString aMigrationSteps( "MigrationSteps" );
     434           0 :     uno::Reference< XNameAccess > theNameAccess(xMigrationData->getByName(aMigrationSteps), uno::UNO_QUERY_THROW);
     435           0 :     uno::Sequence< OUString > seqMigrations = theNameAccess->getElementNames();
     436           0 :     uno::Reference< XNameAccess > tmpAccess;
     437           0 :     uno::Reference< XNameAccess > tmpAccess2;
     438           0 :     uno::Sequence< OUString > tmpSeq;
     439           0 :     migrations_vr vrMigrations(new migrations_v);
     440           0 :     for (sal_Int32 i = 0; i < seqMigrations.getLength(); i++)
     441             :     {
     442             :         // get current migration step
     443           0 :         theNameAccess->getByName(seqMigrations[i]) >>= tmpAccess;
     444           0 :         migration_step tmpStep;
     445           0 :         tmpStep.name = seqMigrations[i];
     446             : 
     447             :         // read included files from current step description
     448           0 :         OUString aSeqEntry;
     449           0 :         if (tmpAccess->getByName("IncludedFiles") >>= tmpSeq)
     450             :         {
     451           0 :             for (sal_Int32 j=0; j<tmpSeq.getLength(); j++)
     452             :             {
     453           0 :                 aSeqEntry = tmpSeq[j];
     454           0 :                 tmpStep.includeFiles.push_back(aSeqEntry);
     455             :             }
     456             :         }
     457             : 
     458             :         // exluded files...
     459           0 :         if (tmpAccess->getByName("ExcludedFiles") >>= tmpSeq)
     460             :         {
     461           0 :             for (sal_Int32 j=0; j<tmpSeq.getLength(); j++)
     462           0 :                 tmpStep.excludeFiles.push_back(tmpSeq[j]);
     463             :         }
     464             : 
     465             :         // included nodes...
     466           0 :         if (tmpAccess->getByName("IncludedNodes") >>= tmpSeq)
     467             :         {
     468           0 :             for (sal_Int32 j=0; j<tmpSeq.getLength(); j++)
     469           0 :                 tmpStep.includeConfig.push_back(tmpSeq[j]);
     470             :         }
     471             : 
     472             :         // excluded nodes...
     473           0 :         if (tmpAccess->getByName("ExcludedNodes") >>= tmpSeq)
     474             :         {
     475           0 :             for (sal_Int32 j=0; j<tmpSeq.getLength(); j++)
     476           0 :                 tmpStep.excludeConfig.push_back(tmpSeq[j]);
     477             :         }
     478             : 
     479             :         // included extensions...
     480           0 :         if (tmpAccess->getByName("IncludedExtensions") >>= tmpSeq)
     481             :         {
     482           0 :             for (sal_Int32 j=0; j<tmpSeq.getLength(); j++)
     483           0 :                 tmpStep.includeExtensions.push_back(tmpSeq[j]);
     484             :         }
     485             : 
     486             :         // excluded extensions...
     487           0 :         if (tmpAccess->getByName("ExcludedExtensions") >>= tmpSeq)
     488             :         {
     489           0 :             for (sal_Int32 j=0; j<tmpSeq.getLength(); j++)
     490             :             {
     491           0 :                 aSeqEntry = tmpSeq[j];
     492           0 :                 tmpStep.excludeExtensions.push_back(aSeqEntry);
     493             :             }
     494             :         }
     495             : 
     496             :         // generic service
     497           0 :         tmpAccess->getByName("MigrationService") >>= tmpStep.service;
     498             : 
     499           0 :         vrMigrations->push_back(tmpStep);
     500           0 :     }
     501           0 :     return vrMigrations;
     502             : }
     503             : 
     504           0 : static FileBase::RC _checkAndCreateDirectory(INetURLObject& dirURL)
     505             : {
     506           0 :     FileBase::RC result = Directory::create(dirURL.GetMainURL(INetURLObject::DECODE_TO_IURI));
     507           0 :     if (result == FileBase::E_NOENT)
     508             :     {
     509           0 :         INetURLObject baseURL(dirURL);
     510           0 :         baseURL.removeSegment();
     511           0 :         _checkAndCreateDirectory(baseURL);
     512           0 :         return Directory::create(dirURL.GetMainURL(INetURLObject::DECODE_TO_IURI));
     513             :     } else
     514           0 :         return result;
     515             : }
     516             : 
     517             : #if defined UNX && ! defined MACOSX
     518             : 
     519             : static const char XDG_CONFIG_PART[] = "/.config/";
     520             : 
     521          53 : OUString MigrationImpl::preXDGConfigDir(const OUString& rConfigDir)
     522             : {
     523          53 :     OUString aPreXDGConfigPath;
     524          53 :     const char* pXDGCfgHome = getenv("XDG_CONFIG_HOME");
     525             : 
     526             :     // cater for XDG_CONFIG_HOME change
     527             :     // If XDG_CONFIG_HOME is set then we;
     528             :     // assume the user knows what they are doing ( room for improvement here, we could
     529             :     // of course search the default config dir etc. also  - but this is more complex,
     530             :     // we would need to weigh results from the current config dir against matches in
     531             :     // the 'old' config dir etc. ) - currently we just use the returned config dir.
     532             :     // If XDG_CONFIG_HOME is NOT set;
     533             :     // assume then we should now using the default $HOME/,config config location for
     534             :     // our user profiles, however *all* previous libreoffice and openoffice.org
     535             :     // configurations will be in the 'old' config directory and that's where we need
     536             :     // to search - we convert the returned config dir to the 'old' dir
     537          53 :     if ( !pXDGCfgHome && rConfigDir.endsWithAsciiL( XDG_CONFIG_PART, sizeof( XDG_CONFIG_PART ) - 1 )  )
     538             :         // remove trailing '.config/' but leave the terminating '/'
     539          53 :         aPreXDGConfigPath = rConfigDir.copy( 0, rConfigDir.getLength() - sizeof(  XDG_CONFIG_PART ) + 2 );
     540             :     else
     541           0 :         aPreXDGConfigPath = rConfigDir;
     542             : 
     543             :     // the application-specific config dir is not longer prefixed by '.' because it is hidden under ".config"
     544             :     // we have to add the '.' for the pre-XDG directory names
     545          53 :     aPreXDGConfigPath += ".";
     546             : 
     547          53 :    return aPreXDGConfigPath;
     548             : }
     549             : #endif
     550             : 
     551         530 : void MigrationImpl::setInstallInfoIfExist(
     552             :     install_info& aInfo,
     553             :     const OUString& rConfigDir,
     554             :     const OUString& rVersion)
     555             : {
     556         530 :     OUString url(INetURLObject(rConfigDir).GetMainURL(INetURLObject::NO_DECODE));
     557        1060 :     osl::DirectoryItem item;
     558        1060 :     osl::FileStatus stat(osl_FileStatus_Mask_Type);
     559             : 
     560        1060 :     if (osl::DirectoryItem::get(url, item) == osl::FileBase::E_None
     561           0 :             && item.getFileStatus(stat) == osl::FileBase::E_None
     562         530 :             && stat.getFileType() == osl::FileStatus::Directory)
     563             :     {
     564           0 :         aInfo.userdata = url;
     565           0 :         aInfo.productname = rVersion;
     566         530 :     }
     567         530 : }
     568             : 
     569          53 : install_info MigrationImpl::findInstallation(const strings_v& rVersions)
     570             : {
     571             : 
     572          53 :     OUString aTopConfigDir;
     573          53 :     osl::Security().getConfigDir( aTopConfigDir );
     574          53 :     if ( !aTopConfigDir.isEmpty() && aTopConfigDir[ aTopConfigDir.getLength()-1 ] != '/' )
     575          53 :         aTopConfigDir += "/";
     576             : 
     577             : #if defined UNX && ! defined MACOSX
     578         106 :     OUString aPreXDGTopConfigDir = preXDGConfigDir(aTopConfigDir);
     579             : #endif
     580             : 
     581          53 :     install_info aInfo;
     582          53 :     strings_v::const_iterator i_ver = rVersions.begin();
     583         371 :     while (i_ver != rVersions.end())
     584             :     {
     585         530 :         OUString aVersion, aProfileName;
     586         265 :         sal_Int32 nSeparatorIndex = (*i_ver).indexOf('=');
     587         265 :         if ( nSeparatorIndex != -1 )
     588             :         {
     589         265 :             aVersion = (*i_ver).copy( 0, nSeparatorIndex );
     590         265 :             aProfileName = (*i_ver).copy( nSeparatorIndex+1 );
     591             :         }
     592             : 
     593        1325 :         if ( !aVersion.isEmpty() && !aProfileName.isEmpty() &&
     594         265 :              ( aInfo.userdata.isEmpty() ||
     595             :                aProfileName.equalsIgnoreAsciiCase(
     596         265 :                    utl::ConfigManager::getProductName() ) ) )
     597             :         {
     598         265 :             setInstallInfoIfExist(aInfo, aTopConfigDir + aProfileName, aVersion);
     599             : #if defined UNX && ! defined MACOSX
     600             :             //try preXDG path if the new one does not exist
     601         265 :             if ( aInfo.userdata.isEmpty())
     602         265 :                 setInstallInfoIfExist(aInfo, aPreXDGTopConfigDir + aProfileName, aVersion);
     603             : #endif
     604             :         }
     605         265 :         ++i_ver;
     606         265 :     }
     607             : 
     608         106 :     return aInfo;
     609             : }
     610             : 
     611          53 : sal_Int32 MigrationImpl::findPreferredMigrationProcess(const migrations_available& rAvailableMigrations)
     612             : {
     613          53 :     sal_Int32    nIndex( -1 );
     614          53 :     sal_Int32    i( 0 );
     615             : 
     616          53 :     migrations_available::const_iterator rIter = rAvailableMigrations.begin();
     617          53 :     while ( rIter != rAvailableMigrations.end() )
     618             :     {
     619          53 :         install_info aInstallInfo = findInstallation(rIter->supported_versions);
     620          53 :         if (!aInstallInfo.productname.isEmpty() )
     621             :         {
     622           0 :             m_aInfo = aInstallInfo;
     623           0 :             nIndex  = i;
     624           0 :             break;
     625             :         }
     626          53 :         ++i;
     627          53 :         ++rIter;
     628          53 :     }
     629             : 
     630             :     OSL_TRACE( " preferred migration is from product '%s'\n",
     631             :                OUStringToOString( m_aInfo.productname, RTL_TEXTENCODING_ASCII_US ).getStr() );
     632             :     OSL_TRACE( " and settings directory '%s'\n",
     633             :                OUStringToOString( m_aInfo.userdata, RTL_TEXTENCODING_ASCII_US ).getStr() );
     634             : 
     635          53 :     return nIndex;
     636             : }
     637             : 
     638           0 : strings_vr MigrationImpl::applyPatterns(const strings_v& vSet, const strings_v& vPatterns)
     639             : {
     640             :     using namespace utl;
     641           0 :     strings_vr vrResult(new strings_v);
     642           0 :     strings_v::const_iterator i_set;
     643           0 :     strings_v::const_iterator i_pat = vPatterns.begin();
     644           0 :     while (i_pat != vPatterns.end())
     645             :     {
     646             :         // find matches for this pattern in input set
     647             :         // and copy them to the result
     648           0 :         SearchParam param(*i_pat, SearchParam::SRCH_REGEXP);
     649           0 :         TextSearch ts(param, LANGUAGE_DONTKNOW);
     650           0 :         i_set = vSet.begin();
     651           0 :         sal_Int32 start = 0;
     652           0 :         sal_Int32 end = 0;
     653           0 :         while (i_set != vSet.end())
     654             :         {
     655           0 :             end = i_set->getLength();
     656           0 :             if (ts.SearchForward(*i_set, &start, &end))
     657           0 :                 vrResult->push_back(*i_set);
     658           0 :             ++i_set;
     659             :         }
     660           0 :         ++i_pat;
     661           0 :     }
     662           0 :     return vrResult;
     663             : }
     664             : 
     665           0 : strings_vr MigrationImpl::getAllFiles(const OUString& baseURL) const
     666             : {
     667             :     using namespace osl;
     668           0 :     strings_vr vrResult(new strings_v);
     669             : 
     670             :     // get sub dirs
     671           0 :     Directory dir(baseURL);
     672           0 :     if (dir.open() == FileBase::E_None)
     673             :     {
     674           0 :         strings_v vSubDirs;
     675           0 :         strings_vr vrSubResult;
     676             : 
     677             :         // work through directory contents...
     678           0 :         DirectoryItem item;
     679           0 :         FileStatus fs(osl_FileStatus_Mask_Type | osl_FileStatus_Mask_FileURL);
     680           0 :         while (dir.getNextItem(item) == FileBase::E_None)
     681             :         {
     682           0 :             if (item.getFileStatus(fs) == FileBase::E_None)
     683             :             {
     684           0 :                 if (fs.getFileType() == FileStatus::Directory)
     685           0 :                     vSubDirs.push_back(fs.getFileURL());
     686             :                 else
     687           0 :                     vrResult->push_back(fs.getFileURL());
     688             :             }
     689             :         }
     690             : 
     691             :         // recurse subfolders
     692           0 :         strings_v::const_iterator i = vSubDirs.begin();
     693           0 :         while (i != vSubDirs.end())
     694             :         {
     695           0 :             vrSubResult = getAllFiles(*i);
     696           0 :             vrResult->insert(vrResult->end(), vrSubResult->begin(), vrSubResult->end());
     697           0 :             ++i;
     698           0 :         }
     699             :     }
     700           0 :     return vrResult;
     701             : }
     702             : 
     703             : namespace {
     704             : 
     705             : // removes elements of vector 2 in vector 1
     706           0 : strings_v subtract(strings_v const & va, strings_v const & vb) {
     707           0 :     strings_v a(va);
     708           0 :     std::sort(a.begin(), a.end());
     709           0 :     strings_v::iterator ae(std::unique(a.begin(), a.end()));
     710           0 :     strings_v b(vb);
     711           0 :     std::sort(b.begin(), b.end());
     712           0 :     strings_v::iterator be(std::unique(b.begin(), b.end()));
     713           0 :     strings_v c;
     714           0 :     std::set_difference(a.begin(), ae, b.begin(), be, std::back_inserter(c));
     715           0 :     return c;
     716             : }
     717             : 
     718             : }
     719             : 
     720           0 : strings_vr MigrationImpl::compileFileList()
     721             : {
     722             : 
     723           0 :     strings_vr vrResult(new strings_v);
     724           0 :     strings_vr vrInclude;
     725           0 :     strings_vr vrExclude;
     726             : 
     727             :     // get a list of all files:
     728           0 :     strings_vr vrFiles = getAllFiles(m_aInfo.userdata);
     729             : 
     730             :     // get a file list result for each migration step
     731           0 :     migrations_v::const_iterator i_migr = m_vrMigrations->begin();
     732           0 :     while (i_migr != m_vrMigrations->end())
     733             :     {
     734           0 :         vrInclude = applyPatterns(*vrFiles, i_migr->includeFiles);
     735           0 :         vrExclude = applyPatterns(*vrFiles, i_migr->excludeFiles);
     736           0 :         strings_v sub(subtract(*vrInclude, *vrExclude));
     737           0 :         vrResult->insert(vrResult->end(), sub.begin(), sub.end());
     738           0 :         ++i_migr;
     739           0 :     }
     740           0 :     return vrResult;
     741             : }
     742             : 
     743             : namespace {
     744             : 
     745           0 : struct componentParts {
     746             :     std::set< OUString > includedPaths;
     747             :     std::set< OUString > excludedPaths;
     748             : };
     749             : 
     750             : typedef std::map< OUString, componentParts > Components;
     751             : 
     752           0 : bool getComponent(OUString const & path, OUString * component) {
     753             :     OSL_ASSERT(component != 0);
     754           0 :     if (path.isEmpty() || path[0] != '/') {
     755             :         OSL_TRACE(
     756             :             ("configuration migration in/exclude path %s ignored (does not"
     757             :              " start with slash)"),
     758             :             OUStringToOString(path, RTL_TEXTENCODING_UTF8).getStr());
     759           0 :         return false;
     760             :     }
     761           0 :     sal_Int32 i = path.indexOf('/', 1);
     762           0 :     *component = i < 0 ? path.copy(1) : path.copy(1, i - 1);
     763           0 :     return true;
     764             : }
     765             : 
     766           0 : uno::Sequence< OUString > setToSeq(std::set< OUString > const & set) {
     767           0 :     std::set< OUString >::size_type n = set.size();
     768           0 :     if (n > SAL_MAX_INT32) {
     769           0 :         throw std::bad_alloc();
     770             :     }
     771           0 :     uno::Sequence< OUString > seq(static_cast< sal_Int32 >(n));
     772           0 :     sal_Int32 i = 0;
     773           0 :     for (std::set< OUString >::const_iterator j(set.begin());
     774           0 :          j != set.end(); ++j)
     775             :     {
     776           0 :         seq[i++] = *j;
     777             :     }
     778           0 :     return seq;
     779             : }
     780             : 
     781             : }
     782             : 
     783           0 : void MigrationImpl::copyConfig() {
     784           0 :     Components comps;
     785           0 :     for (migrations_v::const_iterator i(m_vrMigrations->begin());
     786           0 :          i != m_vrMigrations->end(); ++i)
     787             :     {
     788           0 :         for (strings_v::const_iterator j(i->includeConfig.begin());
     789           0 :              j != i->includeConfig.end(); ++j)
     790             :         {
     791           0 :             OUString comp;
     792           0 :             if (getComponent(*j, &comp)) {
     793           0 :                 comps[comp].includedPaths.insert(*j);
     794             :             }
     795           0 :         }
     796           0 :         for (strings_v::const_iterator j(i->excludeConfig.begin());
     797           0 :              j != i->excludeConfig.end(); ++j)
     798             :         {
     799           0 :             OUString comp;
     800           0 :             if (getComponent(*j, &comp)) {
     801           0 :                 comps[comp].excludedPaths.insert(*j);
     802             :             }
     803           0 :         }
     804             :     }
     805             : 
     806             :     // check if the shared registrymodifications.xcu file exists
     807           0 :     bool bRegistryModificationsXcuExists = false;
     808           0 :     OUString regFilePath(m_aInfo.userdata);
     809           0 :     regFilePath += "/user/registrymodifications.xcu";
     810           0 :     File regFile(regFilePath);
     811           0 :     ::osl::FileBase::RC nError = regFile.open(osl_File_OpenFlag_Read);
     812           0 :     if ( nError == ::osl::FileBase::E_None ) {
     813           0 :         bRegistryModificationsXcuExists = true;
     814           0 :         regFile.close();
     815             :     }
     816             : 
     817           0 :     for (Components::const_iterator i(comps.begin()); i != comps.end(); ++i) {
     818           0 :         if (!i->second.includedPaths.empty()) {
     819           0 :             if (!bRegistryModificationsXcuExists) {
     820             :                 // shared registrymodifications.xcu does not exists
     821             :                 // the configuration is split in many registry files
     822             :                 // determine the file names from the first element in included paths
     823           0 :                 OUStringBuffer buf(m_aInfo.userdata);
     824           0 :                 buf.appendAscii("/user/registry/data");
     825           0 :                 sal_Int32 n = 0;
     826           0 :                 do {
     827           0 :                     OUString seg(i->first.getToken(0, '.', n));
     828             :                     OUString enc(
     829             :                         rtl::Uri::encode(
     830             :                             seg, rtl_UriCharClassPchar, rtl_UriEncodeStrict,
     831           0 :                             RTL_TEXTENCODING_UTF8));
     832           0 :                     if (enc.isEmpty() && !seg.isEmpty()) {
     833             :                         OSL_TRACE(
     834             :                             ("configuration migration component %s ignored (cannot"
     835             :                             " be encoded as file path)"),
     836             :                             OUStringToOString(
     837             :                                 i->first, RTL_TEXTENCODING_UTF8).getStr());
     838           0 :                         goto next;
     839             :                     }
     840           0 :                     buf.append('/');
     841           0 :                     buf.append(enc);
     842           0 :                 } while (n >= 0);
     843           0 :                 buf.appendAscii(".xcu");
     844           0 :                 regFilePath = buf.toString();
     845             :             }
     846             :             configuration::Update::get(
     847           0 :                 comphelper::getProcessComponentContext())->
     848             :                 insertModificationXcuFile(
     849           0 :                     regFilePath, setToSeq(i->second.includedPaths),
     850           0 :                     setToSeq(i->second.excludedPaths));
     851             :         } else {
     852             :             OSL_TRACE(
     853             :                 ("configuration migration component %s ignored (only excludes,"
     854             :                  " no includes)"),
     855             :                 OUStringToOString(
     856             :                     i->first, RTL_TEXTENCODING_UTF8).getStr());
     857             :         }
     858             :     next:;
     859           0 :     }
     860           0 : }
     861             : 
     862         106 : uno::Reference< XNameAccess > MigrationImpl::getConfigAccess(const sal_Char* pPath, bool bUpdate)
     863             : {
     864         106 :     uno::Reference< XNameAccess > xNameAccess;
     865             :     try{
     866         106 :         OUString sAccessSrvc;
     867         106 :         if (bUpdate)
     868           0 :             sAccessSrvc = "com.sun.star.configuration.ConfigurationUpdateAccess";
     869             :         else
     870         106 :             sAccessSrvc = "com.sun.star.configuration.ConfigurationAccess";
     871             : 
     872         212 :         OUString sConfigURL = OUString::createFromAscii(pPath);
     873             : 
     874             :         uno::Reference< XMultiServiceFactory > theConfigProvider(
     875             :             configuration::theDefaultProvider::get(
     876         212 :                 comphelper::getProcessComponentContext()));
     877             : 
     878             :         // access the provider
     879         212 :         uno::Sequence< uno::Any > theArgs(1);
     880         106 :         theArgs[ 0 ] <<= sConfigURL;
     881         212 :         xNameAccess = uno::Reference< XNameAccess > (
     882         106 :                 theConfigProvider->createInstanceWithArguments(
     883         318 :                 sAccessSrvc, theArgs ), uno::UNO_QUERY_THROW );
     884             :     }
     885           0 :     catch (const com::sun::star::uno::Exception& e)
     886             :     {
     887             :         SAL_WARN(
     888             :             "desktop.migration", "ignoring Exception \"" << e.Message << "\"");
     889             :     }
     890         106 :     return xNameAccess;
     891             : }
     892             : 
     893           0 : void MigrationImpl::copyFiles()
     894             : {
     895           0 :     strings_v::const_iterator i_file = m_vrFileList->begin();
     896           0 :     OUString localName;
     897           0 :     OUString destName;
     898           0 :     OUString userInstall;
     899             :     utl::Bootstrap::PathStatus aStatus;
     900           0 :     aStatus = utl::Bootstrap::locateUserInstallation(userInstall);
     901           0 :     if (aStatus == utl::Bootstrap::PATH_EXISTS)
     902             :     {
     903           0 :         while (i_file != m_vrFileList->end())
     904             :         {
     905             :             // remove installation prefix from file
     906           0 :             localName = i_file->copy(m_aInfo.userdata.getLength());
     907           0 :             if (localName.endsWith( "/autocorr/acor_.dat"))
     908             :             {
     909             :                 // Previous versions used an empty language tag for
     910             :                 // LANGUAGE_DONTKNOW with the "[All]" autocorrection entry.
     911             :                 // As of LibreOffice 4.0 it is 'und' for LANGUAGE_UNDETERMINED
     912             :                 // so the file name is "acor_und.dat".
     913           0 :                 localName = localName.copy( 0, localName.getLength() - 4) + "und.dat";
     914             :             }
     915           0 :             destName = userInstall + localName;
     916           0 :             INetURLObject aURL(destName);
     917             :             // check whether destination directory exists
     918           0 :             aURL.removeSegment();
     919           0 :             _checkAndCreateDirectory(aURL);
     920           0 :             FileBase::RC copyResult = File::copy(*i_file, destName);
     921           0 :             if (copyResult != FileBase::E_None)
     922             :             {
     923           0 :                 OString msg("Cannot copy ");
     924           0 :                 msg += OUStringToOString(*i_file, RTL_TEXTENCODING_UTF8) + " to "
     925           0 :                     +  OUStringToOString(destName, RTL_TEXTENCODING_UTF8);
     926           0 :                 OSL_FAIL(msg.getStr());
     927             :             }
     928           0 :             ++i_file;
     929           0 :         }
     930             :     }
     931             :     else
     932             :     {
     933             :         OSL_FAIL("copyFiles: UserInstall does not exist");
     934           0 :     }
     935           0 : }
     936             : 
     937           0 : void MigrationImpl::runServices()
     938             : {
     939             :     // Build argument array
     940           0 :     uno::Sequence< uno::Any > seqArguments(3);
     941           0 :     seqArguments[0] = uno::makeAny(NamedValue("Productname",
     942           0 :         uno::makeAny(m_aInfo.productname)));
     943           0 :     seqArguments[1] = uno::makeAny(NamedValue("UserData",
     944           0 :         uno::makeAny(m_aInfo.userdata)));
     945             : 
     946             : 
     947             :     // create an instance of every migration service
     948             :     // and execute the migration job
     949           0 :     uno::Reference< XJob > xMigrationJob;
     950             : 
     951           0 :     uno::Reference< uno::XComponentContext > xContext(comphelper::getProcessComponentContext());
     952           0 :     migrations_v::const_iterator i_mig  = m_vrMigrations->begin();
     953           0 :     while (i_mig != m_vrMigrations->end())
     954             :     {
     955           0 :         if( !i_mig->service.isEmpty())
     956             :         {
     957             : 
     958             :             try
     959             :             {
     960             :                 // set black list for extension migration
     961           0 :                 uno::Sequence< OUString > seqExtBlackList;
     962           0 :                 sal_uInt32 nSize = i_mig->excludeExtensions.size();
     963           0 :                 if ( nSize > 0 )
     964           0 :                     seqExtBlackList = comphelper::arrayToSequence< OUString >(
     965           0 :                         &i_mig->excludeExtensions[0], nSize );
     966           0 :                 seqArguments[2] = uno::makeAny(NamedValue("ExtensionBlackList",
     967           0 :                     uno::makeAny( seqExtBlackList )));
     968             : 
     969           0 :                 xMigrationJob = uno::Reference< XJob >(
     970           0 :                     xContext->getServiceManager()->createInstanceWithArgumentsAndContext(i_mig->service, seqArguments, xContext),
     971           0 :                     uno::UNO_QUERY_THROW);
     972             : 
     973           0 :                 xMigrationJob->execute(uno::Sequence< NamedValue >());
     974             : 
     975             : 
     976             :             }
     977           0 :             catch (const Exception& e)
     978             :             {
     979           0 :                 OString aMsg("Execution of migration service failed (Exception caught).\nService: ");
     980           0 :                 aMsg += OUStringToOString(i_mig->service, RTL_TEXTENCODING_ASCII_US) + "\nMessage: ";
     981           0 :                 aMsg += OUStringToOString(e.Message, RTL_TEXTENCODING_ASCII_US);
     982           0 :                 OSL_FAIL(aMsg.getStr());
     983             :             }
     984           0 :             catch (...)
     985             :             {
     986           0 :                 OString aMsg("Execution of migration service failed (Exception caught).\nService: ");
     987           0 :                 aMsg += OUStringToOString(i_mig->service, RTL_TEXTENCODING_ASCII_US) +
     988           0 :                     "\nNo message available";
     989           0 :                 OSL_FAIL(aMsg.getStr());
     990             :             }
     991             : 
     992             :         }
     993           0 :         ++i_mig;
     994           0 :     }
     995           0 : }
     996             : 
     997           0 : ::std::vector< MigrationModuleInfo > MigrationImpl::dectectUIChangesForAllModules() const
     998             : {
     999           0 :     ::std::vector< MigrationModuleInfo > vModulesInfo;
    1000           0 :     const OUString MENUBAR("menubar");
    1001           0 :     const OUString TOOLBAR("toolbar");
    1002             : 
    1003           0 :     uno::Sequence< uno::Any > lArgs(2);
    1004           0 :     lArgs[0] <<= m_aInfo.userdata + "/user/config/soffice.cfg/modules";
    1005           0 :     lArgs[1] <<= embed::ElementModes::READ;
    1006             : 
    1007             :     uno::Reference< lang::XSingleServiceFactory > xStorageFactory(
    1008           0 :                      embed::FileSystemStorageFactory::create(comphelper::getProcessComponentContext()));
    1009           0 :     uno::Reference< embed::XStorage >             xModules;
    1010             : 
    1011           0 :     xModules = uno::Reference< embed::XStorage >(xStorageFactory->createInstanceWithArguments(lArgs), uno::UNO_QUERY);
    1012           0 :     if (!xModules.is())
    1013           0 :         return vModulesInfo;
    1014             : 
    1015           0 :     uno::Reference< container::XNameAccess > xAccess = uno::Reference< container::XNameAccess >(xModules, uno::UNO_QUERY);
    1016           0 :     uno::Sequence< OUString > lNames = xAccess->getElementNames();
    1017           0 :     sal_Int32 nLength = lNames.getLength();
    1018           0 :     for (sal_Int32 i=0; i<nLength; ++i)
    1019             :     {
    1020           0 :         OUString sModuleShortName = lNames[i];
    1021           0 :         uno::Reference< embed::XStorage > xModule = xModules->openStorageElement(sModuleShortName, embed::ElementModes::READ);
    1022           0 :         if (xModule.is())
    1023             :         {
    1024           0 :             MigrationModuleInfo aModuleInfo;
    1025             : 
    1026           0 :             uno::Reference< embed::XStorage > xMenubar = xModule->openStorageElement(MENUBAR, embed::ElementModes::READ);
    1027           0 :             if (xMenubar.is())
    1028             :             {
    1029           0 :                 uno::Reference< container::XNameAccess > xNameAccess = uno::Reference< container::XNameAccess >(xMenubar, uno::UNO_QUERY);
    1030           0 :                 if (xNameAccess->getElementNames().getLength() > 0)
    1031             :                 {
    1032           0 :                     aModuleInfo.sModuleShortName = sModuleShortName;
    1033           0 :                     aModuleInfo.bHasMenubar = true;
    1034           0 :                 }
    1035             :             }
    1036             : 
    1037           0 :             uno::Reference< embed::XStorage > xToolbar = xModule->openStorageElement(TOOLBAR, embed::ElementModes::READ);
    1038           0 :             if (xToolbar.is())
    1039             :             {
    1040           0 :                 const OUString RESOURCEURL_CUSTOM_ELEMENT("custom_");
    1041           0 :                 sal_Int32 nCustomLen = 7;
    1042             : 
    1043           0 :                 uno::Reference< container::XNameAccess > xNameAccess = uno::Reference< container::XNameAccess >(xToolbar, uno::UNO_QUERY);
    1044           0 :                 ::uno::Sequence< OUString > lToolbars = xNameAccess->getElementNames();
    1045           0 :                 for (sal_Int32 j=0; j<lToolbars.getLength(); ++j)
    1046             :                 {
    1047           0 :                     OUString sToolbarName = lToolbars[j];
    1048           0 :                     if (sToolbarName.getLength()>=nCustomLen &&
    1049           0 :                         sToolbarName.copy(0, nCustomLen).equals(RESOURCEURL_CUSTOM_ELEMENT))
    1050           0 :                         continue;
    1051             : 
    1052           0 :                     aModuleInfo.sModuleShortName = sModuleShortName;
    1053           0 :                     sal_Int32 nIndex = sToolbarName.lastIndexOf('.');
    1054           0 :                     if (nIndex > 0)
    1055             :                     {
    1056           0 :                         OUString sExtension(sToolbarName.copy(nIndex));
    1057           0 :                         OUString sToolbarResourceName(sToolbarName.copy(0, nIndex));
    1058           0 :                         if (!sToolbarResourceName.isEmpty() && sExtension == ".xml")
    1059           0 :                             aModuleInfo.m_vToolbars.push_back(sToolbarResourceName);
    1060             :                     }
    1061           0 :                 }
    1062             :             }
    1063             : 
    1064           0 :             if (!aModuleInfo.sModuleShortName.isEmpty())
    1065           0 :                 vModulesInfo.push_back(aModuleInfo);
    1066             :         }
    1067           0 :     }
    1068             : 
    1069           0 :     return vModulesInfo;
    1070             : }
    1071             : 
    1072           0 : void MigrationImpl::compareOldAndNewConfig(const OUString& sParent,
    1073             :                                            const uno::Reference< container::XIndexContainer >& xIndexOld,
    1074             :                                            const uno::Reference< container::XIndexContainer >& xIndexNew,
    1075             :                                            const OUString& sResourceURL)
    1076             : {
    1077           0 :     const OUString MENU_SEPARATOR(" | ");
    1078             : 
    1079           0 :     ::std::vector< MigrationItem > vOldItems;
    1080           0 :     ::std::vector< MigrationItem > vNewItems;
    1081           0 :     uno::Sequence< beans::PropertyValue > aProp;
    1082           0 :     sal_Int32 nOldCount = xIndexOld->getCount();
    1083           0 :     sal_Int32 nNewCount = xIndexNew->getCount();
    1084             : 
    1085           0 :     for (int n=0; n<nOldCount; ++n)
    1086             :     {
    1087           0 :         MigrationItem aMigrationItem;
    1088           0 :         if (xIndexOld->getByIndex(n) >>= aProp)
    1089             :         {
    1090           0 :             for(int i=0; i<aProp.getLength(); ++i)
    1091             :             {
    1092           0 :                 if ( aProp[i].Name == ITEM_DESCRIPTOR_COMMANDURL )
    1093           0 :                     aProp[i].Value >>= aMigrationItem.m_sCommandURL;
    1094           0 :                 else if ( aProp[i].Name == ITEM_DESCRIPTOR_CONTAINER )
    1095           0 :                     aProp[i].Value >>= aMigrationItem.m_xPopupMenu;
    1096             :             }
    1097             : 
    1098           0 :             if (!aMigrationItem.m_sCommandURL.isEmpty())
    1099           0 :                 vOldItems.push_back(aMigrationItem);
    1100             :         }
    1101           0 :     }
    1102             : 
    1103           0 :     for (int n=0; n<nNewCount; ++n)
    1104             :     {
    1105           0 :         MigrationItem aMigrationItem;
    1106           0 :         if (xIndexNew->getByIndex(n) >>= aProp)
    1107             :         {
    1108           0 :             for(int i=0; i<aProp.getLength(); ++i)
    1109             :             {
    1110           0 :                 if ( aProp[i].Name == ITEM_DESCRIPTOR_COMMANDURL )
    1111           0 :                     aProp[i].Value >>= aMigrationItem.m_sCommandURL;
    1112           0 :                 else if ( aProp[i].Name == ITEM_DESCRIPTOR_CONTAINER )
    1113           0 :                     aProp[i].Value >>= aMigrationItem.m_xPopupMenu;
    1114             :             }
    1115             : 
    1116           0 :             if (!aMigrationItem.m_sCommandURL.isEmpty())
    1117           0 :                 vNewItems.push_back(aMigrationItem);
    1118             :         }
    1119           0 :     }
    1120             : 
    1121           0 :     ::std::vector< MigrationItem >::iterator it;
    1122             : 
    1123           0 :     OUString sSibling;
    1124           0 :     for (it = vOldItems.begin(); it!=vOldItems.end(); ++it)
    1125             :     {
    1126           0 :         ::std::vector< MigrationItem >::iterator pFound = ::std::find(vNewItems.begin(), vNewItems.end(), *it);
    1127           0 :         if (pFound != vNewItems.end() && it->m_xPopupMenu.is())
    1128             :         {
    1129           0 :             OUString sName;
    1130           0 :             if (!sParent.isEmpty())
    1131           0 :                 sName = sParent + MENU_SEPARATOR + it->m_sCommandURL;
    1132             :             else
    1133           0 :                 sName = it->m_sCommandURL;
    1134           0 :             compareOldAndNewConfig(sName, it->m_xPopupMenu, pFound->m_xPopupMenu, sResourceURL);
    1135             :         }
    1136           0 :         else if (pFound == vNewItems.end())
    1137             :         {
    1138           0 :             MigrationItem aMigrationItem(sParent, sSibling, it->m_sCommandURL, it->m_xPopupMenu);
    1139           0 :             if (m_aOldVersionItemsHashMap.find(sResourceURL)==m_aOldVersionItemsHashMap.end())
    1140             :             {
    1141           0 :                 ::std::vector< MigrationItem > vMigrationItems;
    1142           0 :                 m_aOldVersionItemsHashMap.insert(MigrationHashMap::value_type(sResourceURL, vMigrationItems));
    1143           0 :                 m_aOldVersionItemsHashMap[sResourceURL].push_back(aMigrationItem);
    1144             :             }
    1145             :             else
    1146             :             {
    1147           0 :                 if (::std::find(m_aOldVersionItemsHashMap[sResourceURL].begin(), m_aOldVersionItemsHashMap[sResourceURL].end(), aMigrationItem)==m_aOldVersionItemsHashMap[sResourceURL].end())
    1148           0 :                     m_aOldVersionItemsHashMap[sResourceURL].push_back(aMigrationItem);
    1149           0 :             }
    1150             :         }
    1151             : 
    1152           0 :         sSibling = it->m_sCommandURL;
    1153           0 :     }
    1154           0 : }
    1155             : 
    1156           0 : void MigrationImpl::mergeOldToNewVersion(const uno::Reference< ui::XUIConfigurationManager >& xCfgManager,
    1157             :                                          const uno::Reference< container::XIndexContainer>& xIndexContainer,
    1158             :                                          const OUString& sModuleIdentifier,
    1159             :                                          const OUString& sResourceURL)
    1160             : {
    1161           0 :     MigrationHashMap::iterator pFound = m_aOldVersionItemsHashMap.find(sResourceURL);
    1162           0 :     if (pFound==m_aOldVersionItemsHashMap.end())
    1163           0 :         return;
    1164             : 
    1165           0 :     ::std::vector< MigrationItem >::iterator it;
    1166           0 :     for (it=pFound->second.begin(); it!=pFound->second.end(); ++it)
    1167             :     {
    1168           0 :         uno::Reference< container::XIndexContainer > xTemp = xIndexContainer;
    1169             : 
    1170           0 :         OUString sParentNodeName = it->m_sParentNodeName;
    1171           0 :         sal_Int32 nIndex = 0;
    1172           0 :         do
    1173             :         {
    1174           0 :             OUString sToken = sParentNodeName.getToken(0, '|', nIndex).trim();
    1175           0 :             if (sToken.isEmpty())
    1176           0 :                 break;
    1177             : 
    1178           0 :             sal_Int32 nCount = xTemp->getCount();
    1179           0 :             for (sal_Int32 i=0; i<nCount; ++i)
    1180             :             {
    1181           0 :                 OUString sCommandURL;
    1182           0 :                 OUString sLabel;
    1183           0 :                 uno::Reference< container::XIndexContainer > xChild;
    1184             : 
    1185           0 :                 uno::Sequence< beans::PropertyValue > aPropSeq;
    1186           0 :                 xTemp->getByIndex(i) >>= aPropSeq;
    1187           0 :                 for (sal_Int32 j=0; j<aPropSeq.getLength(); ++j)
    1188             :                 {
    1189           0 :                     OUString sPropName = aPropSeq[j].Name;
    1190           0 :                     if ( sPropName == ITEM_DESCRIPTOR_COMMANDURL )
    1191           0 :                         aPropSeq[j].Value >>= sCommandURL;
    1192           0 :                     else if ( sPropName == ITEM_DESCRIPTOR_LABEL )
    1193           0 :                         aPropSeq[j].Value >>= sLabel;
    1194           0 :                     else if ( sPropName == ITEM_DESCRIPTOR_CONTAINER )
    1195           0 :                         aPropSeq[j].Value >>= xChild;
    1196           0 :                 }
    1197             : 
    1198           0 :                 if (sCommandURL == sToken)
    1199             :                 {
    1200           0 :                     xTemp = xChild;
    1201           0 :                     break;
    1202             :                 }
    1203           0 :             }
    1204             : 
    1205           0 :         } while (nIndex>=0);
    1206             : 
    1207           0 :         if (nIndex == -1)
    1208             :         {
    1209           0 :             uno::Sequence< beans::PropertyValue > aPropSeq(3);
    1210             : 
    1211           0 :             aPropSeq[0].Name = ITEM_DESCRIPTOR_COMMANDURL;
    1212           0 :             aPropSeq[0].Value <<= it->m_sCommandURL;
    1213           0 :             aPropSeq[1].Name = ITEM_DESCRIPTOR_LABEL;
    1214           0 :             aPropSeq[1].Value <<= retrieveLabelFromCommand(it->m_sCommandURL, sModuleIdentifier);
    1215           0 :             aPropSeq[2].Name = ITEM_DESCRIPTOR_CONTAINER;
    1216           0 :             aPropSeq[2].Value <<= it->m_xPopupMenu;
    1217             : 
    1218           0 :             if (it->m_sPrevSibling.isEmpty())
    1219           0 :                 xTemp->insertByIndex(0, uno::makeAny(aPropSeq));
    1220             :             else
    1221             :             {
    1222           0 :                 sal_Int32 nCount = xTemp->getCount();
    1223           0 :                 sal_Int32 i = 0;
    1224           0 :                 for (; i<nCount; ++i)
    1225             :                 {
    1226           0 :                     OUString sCmd;
    1227           0 :                     uno::Sequence< beans::PropertyValue > aTempPropSeq;
    1228           0 :                     xTemp->getByIndex(i) >>= aTempPropSeq;
    1229           0 :                     for (sal_Int32 j=0; j<aTempPropSeq.getLength(); ++j)
    1230             :                     {
    1231           0 :                         if ( aTempPropSeq[j].Name == ITEM_DESCRIPTOR_COMMANDURL )
    1232             :                         {
    1233           0 :                             aTempPropSeq[j].Value >>= sCmd;
    1234           0 :                             break;
    1235             :                         }
    1236             :                     }
    1237             : 
    1238           0 :                     if (sCmd.equals(it->m_sPrevSibling))
    1239           0 :                         break;
    1240           0 :                 }
    1241             : 
    1242           0 :                 xTemp->insertByIndex(i+1, uno::makeAny(aPropSeq));
    1243           0 :             }
    1244             :         }
    1245           0 :     }
    1246             : 
    1247           0 :     uno::Reference< container::XIndexAccess > xIndexAccess(xIndexContainer, uno::UNO_QUERY);
    1248           0 :     if (xIndexAccess.is())
    1249           0 :         xCfgManager->replaceSettings(sResourceURL, xIndexAccess);
    1250             : 
    1251           0 :     uno::Reference< ui::XUIConfigurationPersistence > xUIConfigurationPersistence(xCfgManager, uno::UNO_QUERY);
    1252           0 :     if (xUIConfigurationPersistence.is())
    1253           0 :         xUIConfigurationPersistence->store();
    1254             : }
    1255             : 
    1256           0 : uno::Reference< ui::XUIConfigurationManager > NewVersionUIInfo::getConfigManager(const OUString& sModuleShortName) const
    1257             : {
    1258           0 :     uno::Reference< ui::XUIConfigurationManager > xCfgManager;
    1259             : 
    1260           0 :     for (sal_Int32 i=0; i<m_lCfgManagerSeq.getLength(); ++i)
    1261             :     {
    1262           0 :         if (m_lCfgManagerSeq[i].Name.equals(sModuleShortName))
    1263             :         {
    1264           0 :             m_lCfgManagerSeq[i].Value >>= xCfgManager;
    1265           0 :             break;
    1266             :         }
    1267             :     }
    1268             : 
    1269           0 :     return xCfgManager;
    1270             : }
    1271             : 
    1272           0 : uno::Reference< container::XIndexContainer > NewVersionUIInfo::getNewMenubarSettings(const OUString& sModuleShortName) const
    1273             : {
    1274           0 :     uno::Reference< container::XIndexContainer > xNewMenuSettings;
    1275             : 
    1276           0 :     for (sal_Int32 i=0; i<m_lNewVersionMenubarSettingsSeq.getLength(); ++i)
    1277             :     {
    1278           0 :         if (m_lNewVersionMenubarSettingsSeq[i].Name.equals(sModuleShortName))
    1279             :         {
    1280           0 :             m_lNewVersionMenubarSettingsSeq[i].Value >>= xNewMenuSettings;
    1281           0 :             break;
    1282             :         }
    1283             :     }
    1284             : 
    1285           0 :     return xNewMenuSettings;
    1286             : }
    1287             : 
    1288           0 : uno::Reference< container::XIndexContainer > NewVersionUIInfo::getNewToolbarSettings(const OUString& sModuleShortName, const OUString& sToolbarName) const
    1289             : {
    1290           0 :     uno::Reference< container::XIndexContainer > xNewToolbarSettings;
    1291             : 
    1292           0 :     for (sal_Int32 i=0; i<m_lNewVersionToolbarSettingsSeq.getLength(); ++i)
    1293             :     {
    1294           0 :         if (m_lNewVersionToolbarSettingsSeq[i].Name.equals(sModuleShortName))
    1295             :         {
    1296           0 :             uno::Sequence< beans::PropertyValue > lToolbarSettingsSeq;
    1297           0 :             m_lNewVersionToolbarSettingsSeq[i].Value >>= lToolbarSettingsSeq;
    1298           0 :             for (sal_Int32 j=0; j<lToolbarSettingsSeq.getLength(); ++j)
    1299             :             {
    1300           0 :                 if (lToolbarSettingsSeq[j].Name.equals(sToolbarName))
    1301             :                 {
    1302           0 :                     lToolbarSettingsSeq[j].Value >>= xNewToolbarSettings;
    1303           0 :                     break;
    1304             :                 }
    1305             :             }
    1306             : 
    1307           0 :             break;
    1308             :         }
    1309             :     }
    1310             : 
    1311           0 :     return xNewToolbarSettings;
    1312             : }
    1313             : 
    1314           0 : void NewVersionUIInfo::init(const ::std::vector< MigrationModuleInfo >& vModulesInfo)
    1315             : {
    1316           0 :     m_lCfgManagerSeq.realloc(vModulesInfo.size());
    1317           0 :     m_lNewVersionMenubarSettingsSeq.realloc(vModulesInfo.size());
    1318           0 :     m_lNewVersionToolbarSettingsSeq.realloc(vModulesInfo.size());
    1319             : 
    1320           0 :     const OUString sMenubarResourceURL("private:resource/menubar/menubar");
    1321           0 :     const OUString sToolbarResourcePre("private:resource/toolbar/");
    1322             : 
    1323           0 :     uno::Reference< ui::XModuleUIConfigurationManagerSupplier > xModuleCfgSupplier = ui::theModuleUIConfigurationManagerSupplier::get( ::comphelper::getProcessComponentContext() );
    1324             : 
    1325           0 :     for (size_t i=0; i<vModulesInfo.size(); ++i)
    1326             :     {
    1327           0 :         OUString sModuleIdentifier = mapModuleShortNameToIdentifier(vModulesInfo[i].sModuleShortName);
    1328           0 :         if (!sModuleIdentifier.isEmpty())
    1329             :         {
    1330           0 :             uno::Reference< ui::XUIConfigurationManager > xCfgManager = xModuleCfgSupplier->getUIConfigurationManager(sModuleIdentifier);
    1331           0 :             m_lCfgManagerSeq[i].Name = vModulesInfo[i].sModuleShortName;
    1332           0 :             m_lCfgManagerSeq[i].Value <<= xCfgManager;
    1333             : 
    1334           0 :             if (vModulesInfo[i].bHasMenubar)
    1335             :             {
    1336           0 :                 m_lNewVersionMenubarSettingsSeq[i].Name = vModulesInfo[i].sModuleShortName;
    1337           0 :                 m_lNewVersionMenubarSettingsSeq[i].Value <<= xCfgManager->getSettings(sMenubarResourceURL, sal_True);
    1338             :             }
    1339             : 
    1340           0 :             sal_Int32 nToolbars = vModulesInfo[i].m_vToolbars.size();
    1341           0 :             if (nToolbars > 0)
    1342             :             {
    1343           0 :                 uno::Sequence< beans::PropertyValue > lPropSeq(nToolbars);
    1344           0 :                 for (sal_Int32 j=0; j<nToolbars; ++j)
    1345             :                 {
    1346           0 :                     OUString sToolbarName = vModulesInfo[i].m_vToolbars[j];
    1347           0 :                     OUString sToolbarResourceURL = sToolbarResourcePre + sToolbarName;
    1348             : 
    1349           0 :                     lPropSeq[j].Name = sToolbarName;
    1350           0 :                     lPropSeq[j].Value <<= xCfgManager->getSettings(sToolbarResourceURL, sal_True);
    1351           0 :                 }
    1352             : 
    1353           0 :                 m_lNewVersionToolbarSettingsSeq[i].Name = vModulesInfo[i].sModuleShortName;
    1354           0 :                 m_lNewVersionToolbarSettingsSeq[i].Value <<= lPropSeq;
    1355           0 :             }
    1356             :         }
    1357           0 :     }
    1358           0 : }
    1359             : 
    1360             : } // namespace desktop
    1361             : 
    1362             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11