diff options
author | Michael Meeks <michael.meeks@novell.com> | 2010-10-29 16:41:56 +0100 |
---|---|---|
committer | Michael Meeks <michael.meeks@novell.com> | 2010-11-01 10:57:43 +0000 |
commit | 5e5d42e84fb0c1f3f06fecc91acba8209d7794d1 (patch) | |
tree | e458b1730d87ad695a2bb83ea6697312207ff091 | |
parent | 38d1ca3c32432137e159af1f290cd71ea616ab04 (diff) |
Further simplify and trace migration code
-rw-r--r-- | desktop/source/migration/migration.cxx | 63 | ||||
-rw-r--r-- | desktop/source/migration/migration_impl.hxx | 8 | ||||
-rw-r--r-- | desktop/source/migration/services/autocorrmigration.cxx | 8 | ||||
-rw-r--r-- | desktop/source/migration/services/basicmigration.cxx | 8 |
4 files changed, 38 insertions, 49 deletions
diff --git a/desktop/source/migration/migration.cxx b/desktop/source/migration/migration.cxx index be9d0147a2..d24a1747a5 100644 --- a/desktop/source/migration/migration.cxx +++ b/desktop/source/migration/migration.cxx @@ -194,32 +194,18 @@ static const ::rtl::OUString MENU_SUBMENU(RTL_CONSTASCII_USTRINGPARAM("...")); return sIdentifier; } -static MigrationImpl *pImpl = 0; -static Mutex aMutex; -static MigrationImpl *getImpl() -{ - MutexGuard aGuard(aMutex); - if (pImpl == 0) - pImpl = new MigrationImpl(comphelper::getProcessServiceFactory()); - return pImpl; -} - -static void releaseImpl() -{ - MutexGuard aGuard(aMutex); - if (pImpl != 0) - { - delete pImpl; - pImpl = 0; - } -} - -sal_Bool MigrationImpl::needsMigration() +sal_Bool MigrationImpl::initializeMigration() { sal_Bool bRet = sal_False; - if (m_aInfo.userdata.getLength() > 0 && ! checkMigrationCompleted()) - return sal_True; + if (!checkMigrationCompleted()) { + readAvailableMigrations(m_vMigrationsAvailable); + sal_Int32 nIndex = findPreferedMigrationProcess(m_vMigrationsAvailable); + if ( nIndex >= 0 ) + m_vrMigrations = readMigrationSteps(m_vMigrationsAvailable[nIndex].name); + + bRet = m_aInfo.userdata.getLength() > 0; + } OSL_TRACE( "Migration %s\n", bRet ? "needed" : "not required" ); @@ -228,12 +214,14 @@ sal_Bool MigrationImpl::needsMigration() void Migration::migrateSettingsIfNecessary() { - if ( !getImpl()->needsMigration() ) + MigrationImpl aImpl( comphelper::getProcessServiceFactory() ); + + if (! aImpl.initializeMigration() ) return; sal_Bool bResult = sal_False; try { - bResult = getImpl()->doMigration(); + bResult = aImpl.doMigration(); } catch (Exception& e) { OString aMsg("doMigration() exception: "); @@ -241,25 +229,19 @@ void Migration::migrateSettingsIfNecessary() OSL_ENSURE(sal_False, aMsg.getStr()); } OSL_ENSURE(bResult, "Migration has not been successfull"); - // shut down migration framework - releaseImpl(); } MigrationImpl::MigrationImpl(const uno::Reference< XMultiServiceFactory >& xFactory) : m_vrVersions(new strings_v) , m_xFactory(xFactory) { - readAvailableMigrations(m_vMigrationsAvailable); - sal_Int32 nIndex = findPreferedMigrationProcess(m_vMigrationsAvailable); - if ( nIndex >= 0 ) - m_vrMigrations = readMigrationSteps(m_vMigrationsAvailable[nIndex].name); } MigrationImpl::~MigrationImpl() { - } +// The main entry point for migrating settings sal_Bool MigrationImpl::doMigration() { // compile file list for migration @@ -325,7 +307,7 @@ sal_Bool MigrationImpl::doMigration() ::rtl::OUString sParent; compareOldAndNewConfig(sParent, xOldVersionToolbarSettings, xNewVersionToolbarSettings, sToolbarResourceURL); mergeOldToNewVersion(xCfgManager, xNewVersionToolbarSettings, sModuleIdentifier, sToolbarResourceURL); - } + } } m_aOldVersionItemsHashMap.clear(); @@ -420,7 +402,7 @@ bool MigrationImpl::readAvailableMigrations(migrations_available& rAvailableMigr // get supported version names uno::Reference< XNameAccess > aMigrationAccess(getConfigAccess("org.openoffice.Setup/Migration/SupportedVersions"), uno::UNO_QUERY_THROW); uno::Sequence< OUString > seqSupportedVersions = aMigrationAccess->getElementNames(); - + const OUString aVersionIdentifiers( RTL_CONSTASCII_USTRINGPARAM( "VersionIdentifiers" )); const OUString aPriorityIdentifier( RTL_CONSTASCII_USTRINGPARAM( "Priority" )); @@ -438,6 +420,8 @@ bool MigrationImpl::readAvailableMigrations(migrations_available& rAvailableMigr for (sal_Int32 j=0; j<seqVersions.getLength(); j++) aSupportedMigration.supported_versions.push_back(seqVersions[j].trim()); insertSorted( rAvailableMigrations, aSupportedMigration ); + OSL_TRACE( " available migration '%s'\n", + rtl::OUStringToOString( aSupportedMigration.name, RTL_TEXTENCODING_ASCII_US ).getStr() ); } return true; @@ -589,7 +573,7 @@ sal_Int32 MigrationImpl::findPreferedMigrationProcess(const migrations_available { sal_Int32 nIndex( -1 ); sal_Int32 i( 0 ); - + migrations_available::const_iterator rIter = rAvailableMigrations.begin(); while ( rIter != rAvailableMigrations.end() ) { @@ -604,6 +588,11 @@ sal_Int32 MigrationImpl::findPreferedMigrationProcess(const migrations_available ++rIter; } + OSL_TRACE( " preferred migration is from product '%s'\n", + rtl::OUStringToOString( m_aInfo.productname, RTL_TEXTENCODING_ASCII_US ).getStr() ); + OSL_TRACE( " and settings directory '%s'\n", + rtl::OUStringToOString( m_aInfo.userdata, RTL_TEXTENCODING_ASCII_US ).getStr() ); + return nIndex; } @@ -933,8 +922,8 @@ void MigrationImpl::runServices() uno::Sequence< rtl::OUString > seqExtBlackList; sal_uInt32 nSize = i_mig->excludeExtensions.size(); if ( nSize > 0 ) - seqExtBlackList = comphelper::arrayToSequence< ::rtl::OUString >( - &i_mig->excludeExtensions[0], nSize ); + seqExtBlackList = comphelper::arrayToSequence< ::rtl::OUString >( + &i_mig->excludeExtensions[0], nSize ); seqArguments[2] = uno::makeAny(NamedValue( OUString(RTL_CONSTASCII_USTRINGPARAM("ExtensionBlackList")), uno::makeAny( seqExtBlackList ))); diff --git a/desktop/source/migration/migration_impl.hxx b/desktop/source/migration/migration_impl.hxx index e0a6e5a606..835194f32e 100644 --- a/desktop/source/migration/migration_impl.hxx +++ b/desktop/source/migration/migration_impl.hxx @@ -90,8 +90,8 @@ typedef std::auto_ptr< migrations_v > migrations_vr; typedef std::vector< supported_migration > migrations_available; //__________________________________________ -/** - define the item, e.g.:menuitem, toolbaritem, to be migrated. we keep the information +/** + define the item, e.g.:menuitem, toolbaritem, to be migrated. we keep the information of the command URL, the previous sibling node and the parent node of a item */ struct MigrationItem @@ -196,7 +196,7 @@ class MigrationImpl private: strings_vr m_vrVersions; NS_UNO::Reference< NS_CSS::lang::XMultiServiceFactory > m_xFactory; - + migrations_available m_vMigrationsAvailable; // list of all available migrations migrations_vr m_vrMigrations; // list of all migration specs from config install_info m_aInfo; // info about the version being migrated @@ -240,8 +240,8 @@ private: public: MigrationImpl(const NS_UNO::Reference< NS_CSS::lang::XMultiServiceFactory >&); ~MigrationImpl(); + sal_Bool initializeMigration(); sal_Bool doMigration(); - sal_Bool needsMigration(); rtl::OUString getOldVersionName(); }; } diff --git a/desktop/source/migration/services/autocorrmigration.cxx b/desktop/source/migration/services/autocorrmigration.cxx index 7fc9cf74c2..1f5290f383 100644 --- a/desktop/source/migration/services/autocorrmigration.cxx +++ b/desktop/source/migration/services/autocorrmigration.cxx @@ -154,7 +154,7 @@ namespace migration { return aResult; } - } + } // ----------------------------------------------------------------------------- @@ -168,7 +168,7 @@ namespace migration TStringVectorPtr aFileList = getFiles( m_sSourceDir ); TStringVector::const_iterator aI = aFileList->begin(); while ( aI != aFileList->end() ) - { + { ::rtl::OUString sSourceLocalName = aI->copy( m_sSourceDir.getLength() ); sal_Int32 nStart = sBaseName.getLength(); sal_Int32 nEnd = sSourceLocalName.lastIndexOf ( sSuffix ); @@ -181,7 +181,7 @@ namespace migration ::rtl::OUString sTargetName = sTargetDir + sTargetLocalName; INetURLObject aURL( sTargetName ); aURL.removeSegment(); - checkAndCreateDirectory( aURL ); + checkAndCreateDirectory( aURL ); ::osl::FileBase::RC aResult = ::osl::File::copy( *aI, sTargetName ); if ( aResult != ::osl::FileBase::E_None ) { @@ -192,7 +192,7 @@ namespace migration } ++aI; } - } + } else { OSL_ENSURE( sal_False, "AutocorrectionMigration::copyFiles: no user installation!" ); diff --git a/desktop/source/migration/services/basicmigration.cxx b/desktop/source/migration/services/basicmigration.cxx index afe8d4f2e1..4ed093cfe4 100644 --- a/desktop/source/migration/services/basicmigration.cxx +++ b/desktop/source/migration/services/basicmigration.cxx @@ -151,7 +151,7 @@ namespace migration { return aResult; } - } + } // ----------------------------------------------------------------------------- @@ -165,12 +165,12 @@ namespace migration TStringVectorPtr aFileList = getFiles( m_sSourceDir ); TStringVector::const_iterator aI = aFileList->begin(); while ( aI != aFileList->end() ) - { + { ::rtl::OUString sLocalName = aI->copy( m_sSourceDir.getLength() ); ::rtl::OUString sTargetName = sTargetDir + sLocalName; INetURLObject aURL( sTargetName ); aURL.removeSegment(); - checkAndCreateDirectory( aURL ); + checkAndCreateDirectory( aURL ); ::osl::FileBase::RC aResult = ::osl::File::copy( *aI, sTargetName ); if ( aResult != ::osl::FileBase::E_None ) { @@ -181,7 +181,7 @@ namespace migration } ++aI; } - } + } else { OSL_ENSURE( sal_False, "BasicMigration::copyFiles: no user installation!" ); |