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