diff options
Diffstat (limited to 'desktop/source/migration')
32 files changed, 7442 insertions, 0 deletions
diff --git a/desktop/source/migration/cfgfilter.cxx b/desktop/source/migration/cfgfilter.cxx new file mode 100644 index 000000000000..e4589e1a10e1 --- /dev/null +++ b/desktop/source/migration/cfgfilter.cxx @@ -0,0 +1,333 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_desktop.hxx" +#include "cfgfilter.hxx" + +#include <com/sun/star/beans/NamedValue.hpp> +#include <unotools/textsearch.hxx> + +using namespace rtl; +using namespace com::sun::star; +using namespace com::sun::star::uno; +using namespace com::sun::star::lang; +using namespace com::sun::star::beans; +using namespace com::sun::star::configuration::backend; + +namespace desktop { + +CConfigFilter::CConfigFilter(const strings_v* include, const strings_v* exclude) + : m_pvInclude(include) + , m_pvExclude(exclude) +{ +} + +void SAL_CALL CConfigFilter::initialize(const Sequence< Any >& seqArgs) + throw (Exception) +{ + NamedValue nv; + for (sal_Int32 i=0; i < seqArgs.getLength(); i++) + { + if (seqArgs[i] >>= nv) + { + if (nv.Name.equalsAscii("Source")) + nv.Value >>= m_xSourceLayer; + if (nv.Name.equalsAscii("ComponentName")) + nv.Value >>= m_aCurrentComponent; + } + } + if (m_aCurrentComponent.getLength() == 0) + m_aCurrentComponent = OUString::createFromAscii("unknown.component"); + + if (!m_xSourceLayer.is()) { + throw Exception(); + } + +} + + +void CConfigFilter::pushElement(rtl::OUString aName, sal_Bool bUse) +{ + OUString aPath; + if (!m_elementStack.empty()) { + aPath = m_elementStack.top().path; // or use base path + aPath += OUString::createFromAscii("/"); + } + aPath += aName; + + // create element + element elem; + elem.name = aName; + elem.path = aPath; + elem.use = bUse; + m_elementStack.push(elem); +} + +sal_Bool CConfigFilter::checkCurrentElement() +{ + return m_elementStack.top().use; +} + +sal_Bool CConfigFilter::checkElement(rtl::OUString aName) +{ + + sal_Bool bResult = sal_False; + + // get full pathname for element + OUString aFullPath; + if (!m_elementStack.empty()) + aFullPath = m_elementStack.top().path + OUString::createFromAscii("/"); + + aFullPath += aName; + + // check whether any include patterns patch this path + for (strings_v::const_iterator i_in = m_pvInclude->begin(); + i_in != m_pvInclude->end(); i_in++) + { + // pattern is beginning of path + // or path is a begiing for pattern + if (i_in->match(aFullPath.copy(0, i_in->getLength()>aFullPath.getLength() + ? aFullPath.getLength() : i_in->getLength()), 0)) + { + bResult = sal_True; + break; // one match is enough + } + } + // if match is found, check for exclusion + if (bResult) + { + for (strings_v::const_iterator i_ex = m_pvExclude->begin(); + i_ex != m_pvExclude->end(); i_ex++) + { + if (aFullPath.match(*i_ex, 0)) // pattern is beginning of path + { + bResult = sal_False; + break; // one is enough... + } + } + } + return bResult; +} + +void CConfigFilter::popElement() +{ + m_elementStack.pop(); +} + + +void SAL_CALL CConfigFilter::readData( + const Reference< configuration::backend::XLayerHandler >& layerHandler) + throw ( + com::sun::star::lang::NullPointerException, lang::WrappedTargetException, + com::sun::star::configuration::backend::MalformedDataException) +{ + // when readData is called, the submitted handler will be stored + // in m_xLayerHandler. we will then submit ourself as a handler to + // the SourceLayer in m_xSourceLayer. + // when the source calls our handler functions we will use the patterns that + // where given in the ctor to decide whther they should be relaied to the caller + + if (m_xSourceLayer.is() && layerHandler.is()) + { + m_xLayerHandler = layerHandler; + m_xSourceLayer->readData(Reference<XLayerHandler>(static_cast< XLayerHandler* >(this))); + } else + { + throw NullPointerException(); + } +} + +// XLayerHandler +void SAL_CALL CConfigFilter::startLayer() + throw(::com::sun::star::lang::WrappedTargetException) +{ + m_xLayerHandler->startLayer(); +} + +void SAL_CALL CConfigFilter::endLayer() + throw( + ::com::sun::star::configuration::backend::MalformedDataException, + ::com::sun::star::lang::WrappedTargetException ) +{ + m_xLayerHandler->endLayer(); +} + +void SAL_CALL CConfigFilter::overrideNode( + const OUString& aName, + sal_Int16 aAttributes, + sal_Bool bClear) + throw( + ::com::sun::star::configuration::backend::MalformedDataException, + ::com::sun::star::lang::WrappedTargetException ) +{ + if (checkElement(aName)) + { + m_xLayerHandler->overrideNode(aName, aAttributes, bClear); + pushElement(aName); + } + else + pushElement(aName, sal_False); +} + +void SAL_CALL CConfigFilter::addOrReplaceNode( + const OUString& aName, + sal_Int16 aAttributes) + throw( + ::com::sun::star::configuration::backend::MalformedDataException, + ::com::sun::star::lang::WrappedTargetException ) +{ + if (checkElement(aName)) + { + m_xLayerHandler->addOrReplaceNode(aName, aAttributes); + pushElement(aName); + } + else + pushElement(aName, sal_False); +} + +void SAL_CALL CConfigFilter::addOrReplaceNodeFromTemplate( + const OUString& aName, + const com::sun::star::configuration::backend::TemplateIdentifier& aTemplate, + sal_Int16 aAttributes ) + throw( + ::com::sun::star::configuration::backend::MalformedDataException, + ::com::sun::star::lang::WrappedTargetException ) +{ + if (checkElement(aName)) + { + m_xLayerHandler->addOrReplaceNodeFromTemplate(aName, aTemplate, aAttributes); + pushElement(aName); + } + else + pushElement(aName, sal_False); +} + +void SAL_CALL CConfigFilter::endNode() + throw( + ::com::sun::star::configuration::backend::MalformedDataException, + ::com::sun::star::lang::WrappedTargetException ) +{ + if (checkCurrentElement()) + { + m_xLayerHandler->endNode(); + } + popElement(); +} + +void SAL_CALL CConfigFilter::dropNode( + const OUString& aName ) + throw( + ::com::sun::star::configuration::backend::MalformedDataException, + ::com::sun::star::lang::WrappedTargetException ) +{ + // does not get pushed + if (checkElement(aName)) + { + m_xLayerHandler->dropNode(aName); + } +} + +void SAL_CALL CConfigFilter::overrideProperty( + const OUString& aName, + sal_Int16 aAttributes, + const Type& aType, + sal_Bool bClear ) + throw( + ::com::sun::star::configuration::backend::MalformedDataException, + ::com::sun::star::lang::WrappedTargetException ) +{ + if (checkElement(aName)){ + m_xLayerHandler->overrideProperty(aName, aAttributes, aType, bClear); + pushElement(aName); + } + else + pushElement(aName, sal_False); +} + +void SAL_CALL CConfigFilter::setPropertyValue( + const Any& aValue ) + throw( + ::com::sun::star::configuration::backend::MalformedDataException, + ::com::sun::star::lang::WrappedTargetException ) +{ + if (checkCurrentElement()) + m_xLayerHandler->setPropertyValue(aValue); +} + +void SAL_CALL CConfigFilter::setPropertyValueForLocale( + const Any& aValue, + const OUString& aLocale ) + throw( + ::com::sun::star::configuration::backend::MalformedDataException, + ::com::sun::star::lang::WrappedTargetException ) +{ + if (checkCurrentElement()) + m_xLayerHandler->setPropertyValueForLocale(aValue, aLocale); +} + +void SAL_CALL CConfigFilter::endProperty() + throw( + ::com::sun::star::configuration::backend::MalformedDataException, + ::com::sun::star::lang::WrappedTargetException ) +{ + if (checkCurrentElement()) + { + m_xLayerHandler->endProperty(); + } + popElement(); + +} + +void SAL_CALL CConfigFilter::addProperty( + const rtl::OUString& aName, + sal_Int16 aAttributes, + const Type& aType ) + throw( + ::com::sun::star::configuration::backend::MalformedDataException, + ::com::sun::star::lang::WrappedTargetException ) +{ + if (checkElement(aName)) + m_xLayerHandler->addProperty(aName, aAttributes, aType); +} + +void SAL_CALL CConfigFilter::addPropertyWithValue( + const rtl::OUString& aName, + sal_Int16 aAttributes, + const Any& aValue ) + throw( + ::com::sun::star::configuration::backend::MalformedDataException, + ::com::sun::star::lang::WrappedTargetException ) +{ + // add property with value doesn't push the property + if (checkElement(aName)) + m_xLayerHandler->addPropertyWithValue(aName, aAttributes, aValue); + +} + +} // namespace desktop diff --git a/desktop/source/migration/cfgfilter.hxx b/desktop/source/migration/cfgfilter.hxx new file mode 100644 index 000000000000..605788a12e1b --- /dev/null +++ b/desktop/source/migration/cfgfilter.hxx @@ -0,0 +1,173 @@ +#ifndef _DESKTOP_CFGFILTER_HXX_ +#define _DESKTOP_CFGFILTER_HXX_ + +#include <stack> + +#include <sal/types.h> +#include <rtl/ustring.hxx> + +#include <cppuhelper/implbase2.hxx> +#include <cppuhelper/implbase3.hxx> + +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Type.hxx> + +#include <com/sun/star/lang/XInitialization.hpp> +#include <com/sun/star/configuration/backend/XLayer.hpp> +#include <com/sun/star/configuration/backend/XLayerHandler.hpp> +#include <com/sun/star/configuration/backend/TemplateIdentifier.hpp> + + +#include "migration_impl.hxx" + +#define NS_CSS com::sun::star +#define NS_UNO com::sun::star::uno + + +namespace desktop { + +struct element +{ + rtl::OUString name; + rtl::OUString path; + sal_Bool use; + +}; + +typedef std::stack< element > element_stack; + +// XInitialization: +// -> Source : XLayer +// XLayer +// XLayerHandler +class CConfigFilter : public cppu::WeakImplHelper3< + NS_CSS::configuration::backend::XLayer, + NS_CSS::configuration::backend::XLayerHandler, + NS_CSS::lang::XInitialization> +{ + +private: + NS_UNO::Reference< NS_CSS::configuration::backend::XLayerHandler > m_xLayerHandler; + NS_UNO::Reference< NS_CSS::configuration::backend::XLayer > m_xSourceLayer; + + rtl::OUString m_aCurrentComponent; + + const strings_v *m_pvInclude; + const strings_v *m_pvExclude; + + element_stack m_elementStack; + + void pushElement(rtl::OUString aName, sal_Bool bUse = sal_True); + void popElement(); + sal_Bool checkElement(rtl::OUString aName); + sal_Bool checkCurrentElement(); + +public: + CConfigFilter(const strings_v* include, const strings_v* exclude); + + // XInitialization + virtual void SAL_CALL initialize(const NS_UNO::Sequence< NS_UNO::Any >& seqArgs) + throw (NS_UNO::Exception); + + // XLayer + virtual void SAL_CALL readData( + const NS_UNO::Reference< NS_CSS::configuration::backend::XLayerHandler >& layerHandler) + throw (NS_CSS::lang::NullPointerException, NS_CSS::lang::WrappedTargetException, + NS_CSS::configuration::backend::MalformedDataException); + + // XLayerHandler + virtual void SAL_CALL startLayer() + throw(::com::sun::star::lang::WrappedTargetException); + + virtual void SAL_CALL endLayer() + throw( + ::com::sun::star::configuration::backend::MalformedDataException, + ::com::sun::star::lang::WrappedTargetException ); + + virtual void SAL_CALL overrideNode( + const rtl::OUString& aName, + sal_Int16 aAttributes, + sal_Bool bClear) + throw( + ::com::sun::star::configuration::backend::MalformedDataException, + ::com::sun::star::lang::WrappedTargetException ); + + virtual void SAL_CALL addOrReplaceNode( + const rtl::OUString& aName, + sal_Int16 aAttributes) + throw( + ::com::sun::star::configuration::backend::MalformedDataException, + ::com::sun::star::lang::WrappedTargetException ); + + virtual void SAL_CALL addOrReplaceNodeFromTemplate( + const rtl::OUString& aName, + const NS_CSS::configuration::backend::TemplateIdentifier& aTemplate, + sal_Int16 aAttributes ) + throw( + ::com::sun::star::configuration::backend::MalformedDataException, + ::com::sun::star::lang::WrappedTargetException ); + + virtual void SAL_CALL endNode() + throw( + ::com::sun::star::configuration::backend::MalformedDataException, + ::com::sun::star::lang::WrappedTargetException ); + + virtual void SAL_CALL dropNode( + const rtl::OUString& aName ) + throw( + ::com::sun::star::configuration::backend::MalformedDataException, + ::com::sun::star::lang::WrappedTargetException ); + + virtual void SAL_CALL overrideProperty( + const rtl::OUString& aName, + sal_Int16 aAttributes, + const NS_UNO::Type& aType, + sal_Bool bClear ) + throw( + ::com::sun::star::configuration::backend::MalformedDataException, + ::com::sun::star::lang::WrappedTargetException ); + + virtual void SAL_CALL setPropertyValue( + const NS_UNO::Any& aValue ) + throw( + ::com::sun::star::configuration::backend::MalformedDataException, + ::com::sun::star::lang::WrappedTargetException ); + + virtual void SAL_CALL setPropertyValueForLocale( + const NS_UNO::Any& aValue, + const rtl::OUString& aLocale ) + throw( + ::com::sun::star::configuration::backend::MalformedDataException, + ::com::sun::star::lang::WrappedTargetException ); + + virtual void SAL_CALL endProperty() + throw( + ::com::sun::star::configuration::backend::MalformedDataException, + ::com::sun::star::lang::WrappedTargetException ); + + virtual void SAL_CALL addProperty( + const rtl::OUString& aName, + sal_Int16 aAttributes, + const NS_UNO::Type& aType ) + throw( + ::com::sun::star::configuration::backend::MalformedDataException, + ::com::sun::star::lang::WrappedTargetException ); + + virtual void SAL_CALL addPropertyWithValue( + const rtl::OUString& aName, + sal_Int16 aAttributes, + const NS_UNO::Any& aValue ) + throw( + ::com::sun::star::configuration::backend::MalformedDataException, + ::com::sun::star::lang::WrappedTargetException ); + +}; + +} // namespace desktop +#undef NS_CSS +#undef NS_UNO + +#endif + + diff --git a/desktop/source/migration/makefile.mk b/desktop/source/migration/makefile.mk new file mode 100644 index 000000000000..bc0cd9a62b10 --- /dev/null +++ b/desktop/source/migration/makefile.mk @@ -0,0 +1,59 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=..$/.. + +PRJNAME=desktop +TARGET=mig +AUTOSEG=true +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +# --- Files -------------------------------------------------------- + +RSCEXTINC=..$/app + +# hacky - is no define +CDEFS+=-I..$/app + +SLOFILES = \ + $(SLO)$/migration.obj \ + $(SLO)$/wizard.obj \ + $(SLO)$/pages.obj \ + $(SLO)$/cfgfilter.obj + +SRS1NAME= wizard +SRC1FILES= wizard.src + + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk + diff --git a/desktop/source/migration/migration.cxx b/desktop/source/migration/migration.cxx new file mode 100644 index 000000000000..2181daab7454 --- /dev/null +++ b/desktop/source/migration/migration.cxx @@ -0,0 +1,807 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_desktop.hxx" + +#include "migration.hxx" +#include "migration_impl.hxx" +#include "cfgfilter.hxx" + +#include <unotools/textsearch.hxx> +#include <comphelper/processfactory.hxx> +#include <comphelper/sequence.hxx> +#include <unotools/bootstrap.hxx> +#include <rtl/bootstrap.hxx> +#include <tools/config.hxx> +#include <i18npool/lang.h> +#include <tools/urlobj.hxx> +#include <osl/file.hxx> +#include <osl/mutex.hxx> +#include <ucbhelper/content.hxx> +#include <osl/security.hxx> +#include <unotools/configmgr.hxx> + +#include <com/sun/star/lang/XInitialization.hpp> +#include <com/sun/star/task/XJob.hpp> +#include <com/sun/star/beans/NamedValue.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/configuration/backend/XLayer.hpp> +#include <com/sun/star/configuration/backend/XSingleLayerStratum.hpp> +#include <com/sun/star/util/XRefreshable.hpp> +#include <com/sun/star/util/XChangesBatch.hpp> +#include <com/sun/star/util/XStringSubstitution.hpp> + +using namespace rtl; +using namespace osl; +using namespace std; +using namespace com::sun::star::task; +using namespace com::sun::star::lang; +using namespace com::sun::star::beans; +using namespace com::sun::star::util; +using namespace com::sun::star::container; +using namespace com::sun::star::configuration; +using namespace com::sun::star::configuration::backend; +using com::sun::star::uno::Exception; +using namespace com::sun::star; + +namespace desktop { + + +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; + } +} + +// static main entry point for the migration process +void Migration::doMigration() +{ + sal_Bool bResult = sal_False; + try { + bResult = getImpl()->doMigration(); + } catch (Exception& e) + { + OString aMsg("doMigration() exception: "); + aMsg += OUStringToOString(e.Message, RTL_TEXTENCODING_ASCII_US); + OSL_ENSURE(sal_False, aMsg.getStr()); + } + OSL_ENSURE(bResult, "Migration has not been successfull"); + // shut down migration framework + releaseImpl(); +} + +void Migration::cancelMigration() +{ + releaseImpl(); +} + +sal_Bool Migration::checkMigration() +{ + return getImpl()->checkMigration(); +} + +OUString Migration::getOldVersionName() +{ + return getImpl()->getOldVersionName(); +} + +OUString MigrationImpl::getOldVersionName() +{ + return m_aInfo.productname; +} + +sal_Bool MigrationImpl::checkMigration() +{ + if (m_aInfo.userdata.getLength() > 0 && ! checkMigrationCompleted()) + return sal_True; + else + return sal_False; +} + +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() +{ + +} + +sal_Bool MigrationImpl::doMigration() +{ + // compile file and service list for migration + m_vrFileList = compileFileList(); + m_vrServiceList = compileServiceList(); + + sal_Bool result = sal_False; + try{ + copyFiles(); + + // execute the migration items from Setup.xcu + // and refresh the cache + copyConfig(); + refresh(); + + // execute custom migration services from Setup.xcu + // and refresh the cache + runServices(); + refresh(); + + result = sal_True; + } catch (...) + { + OString aMsg("An unexpected exception was thrown during migration"); + aMsg += "\nOldVersion: " + OUStringToOString(m_aInfo.productname, RTL_TEXTENCODING_ASCII_US); + aMsg += "\nDataPath : " + OUStringToOString(m_aInfo.userdata, RTL_TEXTENCODING_ASCII_US); + OSL_ENSURE(sal_False, aMsg.getStr()); + } + + // prevent running the migration multiple times + setMigrationCompleted(); + return result; +} + +void MigrationImpl::refresh() +{ + uno::Reference< XRefreshable > xRefresh(m_xFactory->createInstance( + OUString::createFromAscii("com.sun.star.configuration.ConfigurationProvider")), uno::UNO_QUERY); + if (xRefresh.is()) + xRefresh->refresh(); + else + OSL_ENSURE(sal_False, "could not get XRefresh interface from default config provider. No refresh done."); + +} + +void MigrationImpl::setMigrationCompleted() +{ + try { + uno::Reference< XPropertySet > aPropertySet(getConfigAccess("org.openoffice.Setup/Office", true), uno::UNO_QUERY_THROW); + aPropertySet->setPropertyValue(OUString::createFromAscii("MigrationCompleted"), uno::makeAny(sal_True)); + uno::Reference< XChangesBatch >(aPropertySet, uno::UNO_QUERY_THROW)->commitChanges(); + } catch (...) { + // fail silently + } +} + +sal_Bool MigrationImpl::checkMigrationCompleted() +{ + sal_Bool bMigrationCompleted = sal_False; + try { + uno::Reference< XPropertySet > aPropertySet( + getConfigAccess("org.openoffice.Setup/Office"), uno::UNO_QUERY_THROW); + aPropertySet->getPropertyValue( + OUString::createFromAscii("MigrationCompleted")) >>= bMigrationCompleted; + } catch (Exception&) { + // just return false... + } + return bMigrationCompleted; +} + +static void insertSorted(migrations_available& rAvailableMigrations, supported_migration& aSupportedMigration) +{ + bool bInserted( false ); + migrations_available::iterator pIter = rAvailableMigrations.begin(); + while ( !bInserted && pIter != rAvailableMigrations.end()) + { + if ( pIter->nPriority < aSupportedMigration.nPriority ) + { + rAvailableMigrations.insert(pIter, aSupportedMigration ); + bInserted = true; + } + ++pIter; + } + if ( !bInserted ) + rAvailableMigrations.push_back( aSupportedMigration ); +} + +bool MigrationImpl::readAvailableMigrations(migrations_available& rAvailableMigrations) +{ + // 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" )); + + for (sal_Int32 i=0; i<seqSupportedVersions.getLength(); i++) + { + sal_Int32 nPriority( 0 ); + uno::Sequence< OUString > seqVersions; + uno::Reference< XNameAccess > xMigrationData( aMigrationAccess->getByName(seqSupportedVersions[i]), uno::UNO_QUERY_THROW ); + xMigrationData->getByName( aVersionIdentifiers ) >>= seqVersions; + xMigrationData->getByName( aPriorityIdentifier ) >>= nPriority; + + supported_migration aSupportedMigration; + aSupportedMigration.name = seqSupportedVersions[i]; + aSupportedMigration.nPriority = nPriority; + for (sal_Int32 j=0; j<seqVersions.getLength(); j++) + aSupportedMigration.supported_versions.push_back(seqVersions[j].trim()); + insertSorted( rAvailableMigrations, aSupportedMigration ); + } + + return true; +} + +migrations_vr MigrationImpl::readMigrationSteps(const ::rtl::OUString& rMigrationName) +{ + // get migration access + uno::Reference< XNameAccess > aMigrationAccess(getConfigAccess("org.openoffice.Setup/Migration/SupportedVersions"), uno::UNO_QUERY_THROW); + uno::Reference< XNameAccess > xMigrationData( aMigrationAccess->getByName(rMigrationName), uno::UNO_QUERY_THROW ); + + // get migration description from from org.openoffice.Setup/Migration + // and build vector of migration steps + OUString aMigrationSteps( RTL_CONSTASCII_USTRINGPARAM( "MigrationSteps" )); + uno::Reference< XNameAccess > theNameAccess(xMigrationData->getByName(aMigrationSteps), uno::UNO_QUERY_THROW); + uno::Sequence< OUString > seqMigrations = theNameAccess->getElementNames(); + uno::Reference< XNameAccess > tmpAccess; + uno::Reference< XNameAccess > tmpAccess2; + uno::Sequence< OUString > tmpSeq; + migrations_vr vrMigrations(new migrations_v); + for (sal_Int32 i = 0; i < seqMigrations.getLength(); i++) + { + // get current migration step + theNameAccess->getByName(seqMigrations[i]) >>= tmpAccess; + // tmpStepPtr = new migration_step(); + migration_step tmpStep; + tmpStep.name = seqMigrations[i]; + + // read included files from current step description + if (tmpAccess->getByName(OUString::createFromAscii("IncludedFiles")) >>= tmpSeq) + { + for (sal_Int32 j=0; j<tmpSeq.getLength(); j++) + tmpStep.includeFiles.push_back(tmpSeq[j]); + } + + // exluded files... + if (tmpAccess->getByName(OUString::createFromAscii("ExcludedFiles")) >>= tmpSeq) + { + for (sal_Int32 j=0; j<tmpSeq.getLength(); j++) + tmpStep.excludeFiles.push_back(tmpSeq[j]); + } + + // included nodes... + if (tmpAccess->getByName(OUString::createFromAscii("IncludedNodes")) >>= tmpSeq) + { + for (sal_Int32 j=0; j<tmpSeq.getLength(); j++) + tmpStep.includeConfig.push_back(tmpSeq[j]); + } + + // excluded nodes... + if (tmpAccess->getByName(OUString::createFromAscii("ExcludedNodes")) >>= tmpSeq) + { + for (sal_Int32 j=0; j<tmpSeq.getLength(); j++) + tmpStep.excludeConfig.push_back(tmpSeq[j]); + } + + // included extensions... + if (tmpAccess->getByName(OUString::createFromAscii("IncludedExtensions")) >>= tmpSeq) + { + for (sal_Int32 j=0; j<tmpSeq.getLength(); j++) + tmpStep.includeExtensions.push_back(tmpSeq[j]); + } + + // excluded extensions... + if (tmpAccess->getByName(OUString::createFromAscii("ExcludedExtensions")) >>= tmpSeq) + { + for (sal_Int32 j=0; j<tmpSeq.getLength(); j++) + tmpStep.excludeExtensions.push_back(tmpSeq[j]); + } + + // config components + if (tmpAccess->getByName(OUString::createFromAscii("ServiceConfigComponents")) >>= tmpSeq) + { + for (sal_Int32 j=0; j<tmpSeq.getLength(); j++) + tmpStep.configComponents.push_back(tmpSeq[j]); + } + + // generic service + tmpAccess->getByName(OUString::createFromAscii("MigrationService")) >>= tmpStep.service; + + vrMigrations->push_back(tmpStep); + } + return vrMigrations; +} + +static FileBase::RC _checkAndCreateDirectory(INetURLObject& dirURL) +{ + FileBase::RC result = Directory::create(dirURL.GetMainURL(INetURLObject::DECODE_TO_IURI)); + if (result == FileBase::E_NOENT) + { + INetURLObject baseURL(dirURL); + baseURL.removeSegment(); + _checkAndCreateDirectory(baseURL); + return Directory::create(dirURL.GetMainURL(INetURLObject::DECODE_TO_IURI)); + } else + return result; +} + +install_info MigrationImpl::findInstallation(const strings_v& rVersions) +{ + rtl::OUString aProductName; + uno::Any aRet = ::utl::ConfigManager::GetDirectConfigProperty( ::utl::ConfigManager::PRODUCTNAME ); + aRet >>= aProductName; + aProductName = aProductName.toAsciiLowerCase(); + + install_info aInfo; + strings_v::const_iterator i_ver = rVersions.begin(); + uno::Reference < util::XStringSubstitution > xSubst( ::comphelper::getProcessServiceFactory()->createInstance(::rtl::OUString::createFromAscii("com.sun.star.util.PathSubstitution")), uno::UNO_QUERY ); + while (i_ver != rVersions.end()) + { + ::rtl::OUString aVersion, aProfileName; + sal_Int32 nSeparatorIndex = (*i_ver).indexOf('='); + if ( nSeparatorIndex != -1 ) + { + aVersion = (*i_ver).copy( 0, nSeparatorIndex ); + aProfileName = (*i_ver).copy( nSeparatorIndex+1 ); + } + + if ( aVersion.getLength() && aProfileName.getLength() && + ( !aInfo.userdata.getLength() || !aProfileName.toAsciiLowerCase().compareTo( aProductName, aProductName.getLength() ) ) + ) + { + ::rtl::OUString aUserInst; + osl::Security().getConfigDir( aUserInst ); + if ( aUserInst.getLength() && aUserInst[ aUserInst.getLength()-1 ] != '/' ) + aUserInst += ::rtl::OUString::createFromAscii("/"); +#if defined UNX && ! defined MACOSX + // tribute to whoever had the "great" idea to use different names on Windows and Unix + aUserInst += ::rtl::OUString::createFromAscii("."); +#endif + aUserInst += aProfileName; + try + { + INetURLObject aObj(aUserInst); + ::ucbhelper::Content aCnt( aObj.GetMainURL( INetURLObject::NO_DECODE ), uno::Reference< ucb::XCommandEnvironment > () ); + aCnt.isDocument(); + aInfo.userdata = aObj.GetMainURL( INetURLObject::NO_DECODE ); + aInfo.productname = aVersion; + } + catch( uno::Exception& ){} + } + ++i_ver; + } + + return aInfo; +} + +sal_Int32 MigrationImpl::findPreferedMigrationProcess(const migrations_available& rAvailableMigrations) +{ + sal_Int32 nIndex( -1 ); + sal_Int32 i( 0 ); + + migrations_available::const_iterator rIter = rAvailableMigrations.begin(); + while ( rIter != rAvailableMigrations.end() ) + { + install_info aInstallInfo = findInstallation(rIter->supported_versions); + if (aInstallInfo.productname.getLength() > 0 ) + { + m_aInfo = aInstallInfo; + nIndex = i; + break; + } + ++i; + ++rIter; + } + + return nIndex; +} + +strings_vr MigrationImpl::applyPatterns(const strings_v& vSet, const strings_v& vPatterns) const +{ + using namespace utl; + strings_vr vrResult(new strings_v); + strings_v::const_iterator i_set; + strings_v::const_iterator i_pat = vPatterns.begin(); + while (i_pat != vPatterns.end()) + { + // find matches for this pattern in input set + // and copy them to the result + SearchParam param(*i_pat, SearchParam::SRCH_REGEXP); + TextSearch ts(param, LANGUAGE_DONTKNOW); + i_set = vSet.begin(); + xub_StrLen start = 0; + xub_StrLen end = 0; + while (i_set != vSet.end()) + { + end = (xub_StrLen)(i_set->getLength()); + if (ts.SearchFrwrd(*i_set, &start, &end)) + vrResult->push_back(*i_set); + i_set++; + } + i_pat++; + } + return vrResult; +} + +strings_vr MigrationImpl::getAllFiles(const OUString& baseURL) const +{ + using namespace osl; + strings_vr vrResult(new strings_v); + + // get sub dirs + Directory dir(baseURL); + if (dir.open() == FileBase::E_None) + { + strings_v vSubDirs; + strings_vr vrSubResult; + + // work through directory contents... + DirectoryItem item; + FileStatus fs(FileStatusMask_Type | FileStatusMask_FileURL); + while (dir.getNextItem(item) == FileBase::E_None) + { + if (item.getFileStatus(fs) == FileBase::E_None) + { + if (fs.getFileType() == FileStatus::Directory) + vSubDirs.push_back(fs.getFileURL()); + else + vrResult->push_back(fs.getFileURL()); + } + } + + // recurse subfolders + strings_v::const_iterator i = vSubDirs.begin(); + while (i != vSubDirs.end()) + { + vrSubResult = getAllFiles(*i); + vrResult->insert(vrResult->end(), vrSubResult->begin(), vrSubResult->end()); + i++; + } + } + return vrResult; +} + +strings_vr MigrationImpl::compileFileList() +{ + + strings_vr vrResult(new strings_v); + strings_vr vrInclude; + strings_vr vrExclude; + strings_vr vrTemp; + +#ifdef SAL_OS2 + if (m_aInfo.userdata.getLength() == 0) + return vrResult; +#endif + + // get a list of all files: + strings_vr vrFiles = getAllFiles(m_aInfo.userdata); + + // get a file list result for each migration step + migrations_v::const_iterator i_migr = m_vrMigrations->begin(); + while (i_migr != m_vrMigrations->end()) + { + vrInclude = applyPatterns(*vrFiles, i_migr->includeFiles); + vrExclude = applyPatterns(*vrFiles, i_migr->excludeFiles); + substract(*vrInclude, *vrExclude); + vrResult->insert(vrResult->end(), vrInclude->begin(), vrInclude->end()); + i_migr++; + } + return vrResult; +} + + +void MigrationImpl::copyConfig() +{ + try { + // 1. get a list of all components from hierachy browser + uno::Reference< XJob > xBrowser(m_xFactory->createInstance( + OUString::createFromAscii("com.sun.star.configuration.backend.LocalHierarchyBrowser")), uno::UNO_QUERY_THROW); + + uno::Sequence< NamedValue > seqArgs(2); + seqArgs[0] = NamedValue( + OUString::createFromAscii("LayerDataUrl"), + uno::makeAny(m_aInfo.userdata + OUString::createFromAscii("/user/registry"))); + seqArgs[1] = NamedValue( + OUString::createFromAscii("FetchComponentNames"), + uno::makeAny(sal_True)); + + // execute the search + uno::Any aResult = xBrowser->execute(seqArgs); + uno::Sequence< OUString > seqComponents; + aResult >>= seqComponents; + OSL_ENSURE(seqComponents.getLength()>0, "MigrationImpl::copyConfig(): no config components available"); + + // 2. create an importer + uno::Reference< XJob > xImporter(m_xFactory->createInstance( + OUString::createFromAscii("com.sun.star.configuration.backend.LocalDataImporter")), uno::UNO_QUERY_THROW); + + // 3. for each migration step... + uno::Sequence< NamedValue > importerArgs(3); + importerArgs[0] = NamedValue( + OUString::createFromAscii("LayerDataUrl"), + uno::makeAny(m_aInfo.userdata + OUString::createFromAscii("/user/registry"))); + importerArgs[1] = NamedValue( + OUString::createFromAscii("LayerFilter"), + uno::Any()); + importerArgs[2] = NamedValue( + OUString::createFromAscii("Component"), + uno::Any()); + + migrations_v::const_iterator i_mig = m_vrMigrations->begin(); + while (i_mig != m_vrMigrations->end()) + { + // a. create config filter for step + uno::Reference< XInitialization > xFilter( + new CConfigFilter(&(i_mig->includeConfig), &(i_mig->excludeConfig))); + importerArgs[1].Value = uno::makeAny(xFilter); + + // b. run each importer with config filter + for (sal_Int32 i=0; i<seqComponents.getLength(); i++) + { + OUString component = seqComponents[i]; + importerArgs[2].Value = uno::makeAny(seqComponents[i]); + try { + aResult = xImporter->execute(importerArgs); + Exception myException; + if (aResult >>= myException) throw myException; + } catch(Exception& aException) { + OString aMsg("Exception in config layer import.\ncomponent: "); + aMsg += OUStringToOString(seqComponents[i], RTL_TEXTENCODING_ASCII_US); + aMsg += "\nmessage: "; + aMsg += OUStringToOString(aException.Message, RTL_TEXTENCODING_ASCII_US); + OSL_ENSURE(sal_False, aMsg.getStr()); + } + } + i_mig++; + } + } + catch (Exception& e) + { + OString aMsg("Exception in config layer import.\nmessage: "); + aMsg += OUStringToOString(e.Message, RTL_TEXTENCODING_ASCII_US); + OSL_ENSURE(sal_False, aMsg.getStr()); + } +} + +// removes elements of vector 2 in vector 1 +void MigrationImpl::substract(strings_v& va, const strings_v& vb_c) const +{ + strings_v vb(vb_c); + // ensure uniqueness of entries + sort(va.begin(), va.end()); + sort(vb.begin(), vb.end()); + unique(va.begin(), va.end()); + unique(vb.begin(), vb.end()); + + strings_v::const_iterator i_ex = vb.begin(); + strings_v::iterator i_in; + strings_v::iterator i_next; + while (i_ex != vb.end()) + { + i_in = va.begin(); + while (i_in != va.end()) + { + if ( *i_in == *i_ex) + { + i_next = i_in+1; + va.erase(i_in); + i_in = i_next; + // we can only find one match since we + // ensured uniquness of the entries. ergo: + break; + } + else + i_in++; + } + i_ex++; + } +} + +uno::Reference< XNameAccess > MigrationImpl::getConfigAccess(const sal_Char* pPath, sal_Bool bUpdate) +{ + uno::Reference< XNameAccess > xNameAccess; + try{ + OUString sConfigSrvc = OUString::createFromAscii("com.sun.star.configuration.ConfigurationProvider"); + OUString sAccessSrvc; + if (bUpdate) + sAccessSrvc = OUString::createFromAscii("com.sun.star.configuration.ConfigurationUpdateAccess"); + else + sAccessSrvc = OUString::createFromAscii("com.sun.star.configuration.ConfigurationAccess"); + + OUString sConfigURL = OUString::createFromAscii(pPath); + + // get configuration provider + uno::Reference< XMultiServiceFactory > theMSF = comphelper::getProcessServiceFactory(); + uno::Reference< XMultiServiceFactory > theConfigProvider = uno::Reference< XMultiServiceFactory > ( + theMSF->createInstance( sConfigSrvc ),uno::UNO_QUERY_THROW ); + + // access the provider + uno::Sequence< uno::Any > theArgs(1); + theArgs[ 0 ] <<= sConfigURL; + xNameAccess = uno::Reference< XNameAccess > ( + theConfigProvider->createInstanceWithArguments( + sAccessSrvc, theArgs ), uno::UNO_QUERY_THROW ); + } catch (com::sun::star::uno::Exception& e) + { + OString aMsg = OUStringToOString(e.Message, RTL_TEXTENCODING_ASCII_US); + OSL_ENSURE(sal_False, aMsg.getStr()); + } + return xNameAccess; +} + +void MigrationImpl::copyFiles() +{ + strings_v::const_iterator i_file = m_vrFileList->begin(); + OUString localName; + OUString destName; + OUString userInstall; + utl::Bootstrap::PathStatus aStatus; + aStatus = utl::Bootstrap::locateUserInstallation(userInstall); + if (aStatus == utl::Bootstrap::PATH_EXISTS) + { + while (i_file != m_vrFileList->end()) + { + + // remove installation prefix from file + localName = i_file->copy(m_aInfo.userdata.getLength()); + destName = userInstall + localName; + INetURLObject aURL(destName); + // check whether destination directory exists + aURL.removeSegment(); + _checkAndCreateDirectory(aURL); + FileBase::RC copyResult = File::copy(*i_file, destName); + if (copyResult != FileBase::E_None) + { + OString msg("Cannot copy "); + msg += OUStringToOString(*i_file, RTL_TEXTENCODING_UTF8) + " to " + + OUStringToOString(destName, RTL_TEXTENCODING_UTF8); + OSL_ENSURE(sal_False, msg.getStr()); + } + i_file++; + } + } + else + { + OSL_ENSURE(sal_False, "copyFiles: UserInstall does not exist"); + } +} + +void MigrationImpl::runServices() +{ + //create stratum for old user layer + OUString aOldLayerURL = m_aInfo.userdata; + aOldLayerURL += OUString::createFromAscii("/user/registry"); + OUString aStratumSvc = OUString::createFromAscii("com.sun.star.configuration.backend.LocalSingleStratum"); + uno::Sequence< uno::Any > stratumArgs(1); + stratumArgs[0] = uno::makeAny(aOldLayerURL); + uno::Reference< XSingleLayerStratum> xStartum( m_xFactory->createInstanceWithArguments( + aStratumSvc, stratumArgs), uno::UNO_QUERY); + + // Build argument array + uno::Sequence< uno::Any > seqArguments(4); + seqArguments[0] = uno::makeAny(NamedValue( + OUString::createFromAscii("Productname"), + uno::makeAny(m_aInfo.productname))); + seqArguments[1] = uno::makeAny(NamedValue( + OUString::createFromAscii("UserData"), + uno::makeAny(m_aInfo.userdata))); + + + // create an instance of every migration service + // and execute the migration job + uno::Reference< XJob > xMigrationJob; + + migrations_v::const_iterator i_mig = m_vrMigrations->begin(); + while (i_mig != m_vrMigrations->end()) + { + if( i_mig->service.getLength() > 0) + { + + try + { + // create access to old configuration components in the user layer + // that were requested by the migration service + uno::Sequence< NamedValue > seqComponents(i_mig->configComponents.size()); + strings_v::const_iterator i_comp = i_mig->configComponents.begin(); + sal_Int32 i = 0; + while (i_comp != i_mig->configComponents.end() && xStartum.is()) + { + // create Layer for i_comp + seqComponents[i] = NamedValue( + *i_comp, uno::makeAny(xStartum->getLayer(*i_comp, OUString()))); + + // next component + i_comp++; + i++; + } + + // set old config argument + seqArguments[2] = uno::makeAny(NamedValue( + OUString::createFromAscii("OldConfiguration"), + uno::makeAny(seqComponents))); + + // set black list for extension migration + 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 ); + seqArguments[3] = uno::makeAny(NamedValue( + OUString::createFromAscii("ExtensionBlackList"), + uno::makeAny( seqExtBlackList ))); + + xMigrationJob = uno::Reference< XJob >(m_xFactory->createInstanceWithArguments( + i_mig->service, seqArguments), uno::UNO_QUERY_THROW); + + xMigrationJob->execute(uno::Sequence< NamedValue >()); + + + } catch (Exception& e) + { + OString aMsg("Execution of migration service failed (Exception caught).\nService: "); + aMsg += OUStringToOString(i_mig->service, RTL_TEXTENCODING_ASCII_US) + "\nMessage: "; + aMsg += OUStringToOString(e.Message, RTL_TEXTENCODING_ASCII_US); + OSL_ENSURE(sal_False, aMsg.getStr()); + } catch (...) + { + OString aMsg("Execution of migration service failed (Exception caught).\nService: "); + aMsg += OUStringToOString(i_mig->service, RTL_TEXTENCODING_ASCII_US) + + "\nNo message available"; + OSL_ENSURE(sal_False, aMsg.getStr()); + } + + } + i_mig++; + } +} + + +strings_vr MigrationImpl::compileServiceList() +{ + strings_vr vrResult(new strings_v); + migrations_v::const_iterator i_migr = m_vrMigrations->begin(); + while (i_migr != m_vrMigrations->end()) + { + vrResult->push_back(i_migr->service); + i_migr++; + } + return vrResult; +} + +} // namespace desktop diff --git a/desktop/source/migration/migration.hxx b/desktop/source/migration/migration.hxx new file mode 100644 index 000000000000..5ac8c5f5702c --- /dev/null +++ b/desktop/source/migration/migration.hxx @@ -0,0 +1,46 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _DESKTOP_MIGRATION_HXX_ +#define _DESKTOP_MIGRATION_HXX_ + +#include <sal/types.h> +#include <rtl/ustring.hxx> + +namespace desktop { + +class Migration +{ +public: + // starts the migration process + static void doMigration(); + static void cancelMigration(); + static sal_Bool checkMigration(); + static rtl::OUString getOldVersionName(); +}; +} +#endif diff --git a/desktop/source/migration/migration_impl.hxx b/desktop/source/migration/migration_impl.hxx new file mode 100644 index 000000000000..b40de510261d --- /dev/null +++ b/desktop/source/migration/migration_impl.hxx @@ -0,0 +1,135 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef _DESKTOP_MIGRATION_IMPL_HXX_ +#define _DESKTOP_MIGRATION_IMPL_HXX_ + +#include <vector> +#include <algorithm> +#include <memory> + +#include "migration.hxx" + +#include <sal/types.h> +#include <rtl/string.hxx> +#include <rtl/ustring.hxx> + +#include <com/sun/star/uno/Reference.hxx> + +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/container/XNameAccess.hpp> + +#define NS_CSS com::sun::star +#define NS_UNO com::sun::star::uno + +namespace desktop +{ + +struct install_info +{ + rtl::OUString productname; // human readeable product name + rtl::OUString userdata; // file: url for user installation +}; + +typedef std::vector< rtl::OUString > strings_v; +typedef std::auto_ptr< strings_v > strings_vr; + +struct migration_step +{ + rtl::OUString name; + strings_v includeFiles; + strings_v excludeFiles; + strings_v includeConfig; + strings_v excludeConfig; + strings_v configComponents; + strings_v includeExtensions; + strings_v excludeExtensions; + rtl::OUString service; +}; + +struct supported_migration +{ + rtl::OUString name; + sal_Int32 nPriority; + strings_v supported_versions; +}; + +typedef std::vector< migration_step > migrations_v; +typedef std::auto_ptr< migrations_v > migrations_vr; +typedef std::vector< supported_migration > migrations_available; + +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 + strings_vr m_vrFileList; // final list of files to be copied + strings_vr m_vrConfigList; // final list of nodes to be copied + strings_vr m_vrServiceList; // final list of services to be called + + // functions to control the migration process + bool readAvailableMigrations(migrations_available&); + migrations_vr readMigrationSteps(const ::rtl::OUString& rMigrationName); + sal_Int32 findPreferedMigrationProcess(const migrations_available&); + install_info findInstallation(const strings_v& rVersions); + strings_vr compileFileList(); + strings_vr compileConfigList(); + strings_vr compileServiceList(); + + // helpers + void substract(strings_v& va, const strings_v& vb_c) const; + strings_vr getAllFiles(const rtl::OUString& baseURL) const; + strings_vr applyPatterns(const strings_v& vSet, const strings_v& vPatterns) const; + NS_UNO::Reference< NS_CSS::container::XNameAccess > getConfigAccess(const sal_Char* path, sal_Bool rw=sal_False); + + // actual processing function that perform the migration steps + void copyFiles(); + void copyConfig(); + void runServices(); + void refresh(); + + void setMigrationCompleted(); + sal_Bool checkMigrationCompleted(); + +public: + MigrationImpl(const NS_UNO::Reference< NS_CSS::lang::XMultiServiceFactory >&); + ~MigrationImpl(); + sal_Bool doMigration(); + sal_Bool checkMigration(); + rtl::OUString getOldVersionName(); + + +}; +} +#undef NS_CSS +#undef NS_UNO + +#endif diff --git a/desktop/source/migration/pages.cxx b/desktop/source/migration/pages.cxx new file mode 100644 index 000000000000..11cc61ed84ff --- /dev/null +++ b/desktop/source/migration/pages.cxx @@ -0,0 +1,673 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_desktop.hxx" + +#include "pages.hxx" +#include "wizard.hrc" +#include "wizard.hxx" +#include "migration.hxx" +#include <vcl/msgbox.hxx> +#include <vcl/mnemonic.hxx> +#include <vos/security.hxx> +#include <app.hxx> +#include <rtl/ustring.hxx> +#include <osl/file.hxx> +#include <unotools/bootstrap.hxx> +#include <unotools/configmgr.hxx> +#include <unotools/regoptions.hxx> +#include <unotools/useroptions.hxx> +#include <sfx2/basedlgs.hxx> +#include <comphelper/processfactory.hxx> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/lang/XInitialization.hpp> +#include <com/sun/star/frame/XDesktop.hpp> +#include <com/sun/star/beans/XMaterialHolder.hpp> +#include <com/sun/star/beans/NamedValue.hpp> +#include <com/sun/star/container/XNameReplace.hpp> +#include <com/sun/star/task/XJobExecutor.hpp> +#include <comphelper/configurationhelper.hxx> +#include <rtl/bootstrap.hxx> +#include <rtl/ustrbuf.hxx> +#include <osl/file.hxx> +#include <osl/thread.hxx> +#include <unotools/bootstrap.hxx> +#include <tools/config.hxx> + +using namespace rtl; +using namespace osl; +using namespace utl; +using namespace svt; +using namespace com::sun::star; +using namespace com::sun::star::frame; +using namespace com::sun::star::lang; +using namespace com::sun::star::util; +using namespace com::sun::star::beans; +using namespace com::sun::star::uno; +using namespace com::sun::star::container; + +#define UNISTRING(s) rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(s)) + +namespace desktop { + +static void _setBold(FixedText& ft) +{ + Font f = ft.GetControlFont(); + f.SetWeight(WEIGHT_BOLD); + ft.SetControlFont(f); +} + +WelcomePage::WelcomePage( svt::OWizardMachine* parent, const ResId& resid, sal_Bool bLicenseNeedsAcceptance ) + : OWizardPage(parent, resid) + , m_ftHead(this, WizardResId(FT_WELCOME_HEADER)) + , m_ftBody(this, WizardResId(FT_WELCOME_BODY)) + , m_pParent(parent) + , m_bLicenseNeedsAcceptance( bLicenseNeedsAcceptance ) + , bIsEvalVersion(false) + , bNoEvalText(false) +{ + FreeResource(); + + _setBold(m_ftHead); + + checkEval(); + + // check for migration + if (Migration::checkMigration()) + { + String aText(WizardResId(STR_WELCOME_MIGRATION)); + // replace %OLDPRODUCT with found version name + aText.SearchAndReplaceAll( UniString::CreateFromAscii("%OLD_VERSION"), Migration::getOldVersionName()); + m_ftBody.SetText( aText ); + } + else if ( ! m_bLicenseNeedsAcceptance ) + { + String aText(WizardResId(STR_WELCOME_WITHOUT_LICENSE)); + m_ftBody.SetText( aText ); + } +} + + +void WelcomePage::checkEval() +{ + Reference< XMultiServiceFactory > xFactory = ::comphelper::getProcessServiceFactory(); + Reference< XMaterialHolder > xHolder(xFactory->createInstance( + OUString::createFromAscii("com.sun.star.tab.tabreg")), UNO_QUERY); + if (xHolder.is()) { + Any aData = xHolder->getMaterial(); + Sequence < NamedValue > aSeq; + if (aData >>= aSeq) { + bIsEvalVersion = true; + for (int i=0; i< aSeq.getLength(); i++) { + if (aSeq[i].Name.equalsAscii("NoEvalText")) { + aSeq[i].Value >>= bNoEvalText; + } + } + } + } +} + + +void WelcomePage::ActivatePage() +{ + OWizardPage::ActivatePage(); + // this page has no controls, so forwarding to default + // button (next) won't work if we grap focus + // GrabFocus(); +} + +LicensePage::LicensePage( svt::OWizardMachine* parent, const ResId& resid, const rtl::OUString &rLicensePath ) + : OWizardPage(parent, resid) + , m_pParent(parent) + , m_ftHead(this, WizardResId(FT_LICENSE_HEADER)) + , m_ftBody1(this, WizardResId(FT_LICENSE_BODY_1)) + , m_ftBody1Txt(this, WizardResId(FT_LICENSE_BODY_1_TXT)) + , m_ftBody2(this, WizardResId(FT_LICENSE_BODY_2)) + , m_ftBody2Txt(this, WizardResId(FT_LICENSE_BODY_2_TXT)) + , m_mlLicense(this, WizardResId(ML_LICENSE)) + , m_pbDown(this, WizardResId(PB_LICENSE_DOWN)) + , m_bLicenseRead(sal_False) +{ + FreeResource(); + + _setBold(m_ftHead); + + m_mlLicense.SetEndReachedHdl( LINK(this, LicensePage, EndReachedHdl) ); + m_mlLicense.SetScrolledHdl( LINK(this, LicensePage, ScrolledHdl) ); + m_pbDown.SetClickHdl( LINK(this, LicensePage, PageDownHdl) ); + + // We want a automatic repeating page down button + WinBits aStyle = m_pbDown.GetStyle(); + aStyle |= WB_REPEAT; + m_pbDown.SetStyle( aStyle ); + + // replace %PAGEDOWN in text2 with button text + String aText = m_ftBody1Txt.GetText(); + aText.SearchAndReplaceAll( UniString::CreateFromAscii("%PAGEDOWN"), + MnemonicGenerator::EraseAllMnemonicChars(m_pbDown.GetText())); + + m_ftBody1Txt.SetText( aText ); + + // load license text + File aLicenseFile(rLicensePath); + if ( aLicenseFile.open(OpenFlag_Read) == FileBase::E_None) + { + DirectoryItem d; + DirectoryItem::get(rLicensePath, d); + FileStatus fs(FileStatusMask_FileSize); + d.getFileStatus(fs); + sal_uInt64 nBytesRead = 0; + sal_uInt64 nPosition = 0; + sal_uInt32 nBytes = (sal_uInt32)fs.getFileSize(); + sal_Char *pBuffer = new sal_Char[nBytes]; + // FileBase RC r = FileBase::E_None; + while (aLicenseFile.read(pBuffer+nPosition, nBytes-nPosition, nBytesRead) == FileBase::E_None + && nPosition + nBytesRead < nBytes) + { + nPosition += nBytesRead; + } + OUString aLicenseString(pBuffer, nBytes, RTL_TEXTENCODING_UTF8, + OSTRING_TO_OUSTRING_CVTFLAGS | RTL_TEXTTOUNICODE_FLAGS_GLOBAL_SIGNATURE); + delete[] pBuffer; + m_mlLicense.SetText(aLicenseString); + + } +} + +void LicensePage::ActivatePage() +{ + OWizardPage::ActivatePage(); + m_bLicenseRead = m_mlLicense.IsEndReached(); + m_pbDown.GrabFocus(); + updateDialogTravelUI(); +} + +bool LicensePage::canAdvance() const +{ + if (m_mlLicense.IsEndReached()) + const_cast< LicensePage* >( this )->m_pbDown.Disable(); + else + const_cast< LicensePage* >( this )->m_pbDown.Enable(); + + return m_bLicenseRead; +} + +IMPL_LINK( LicensePage, PageDownHdl, PushButton *, EMPTYARG ) +{ + m_mlLicense.ScrollDown( SCROLL_PAGEDOWN ); + return 0; +} + +IMPL_LINK( LicensePage, EndReachedHdl, LicenseView *, EMPTYARG ) +{ + m_bLicenseRead = TRUE; + updateDialogTravelUI(); + return 0; +} + +IMPL_LINK( LicensePage, ScrolledHdl, LicenseView *, EMPTYARG ) +{ + updateDialogTravelUI(); + return 0; +} + + +LicenseView::LicenseView( Window* pParent, const ResId& rResId ) + : MultiLineEdit( pParent, rResId ) +{ + SetLeftMargin( 5 ); + mbEndReached = IsEndReached(); + StartListening( *GetTextEngine() ); +} + +LicenseView::~LicenseView() +{ + maEndReachedHdl = Link(); + maScrolledHdl = Link(); + EndListeningAll(); +} + +void LicenseView::ScrollDown( ScrollType eScroll ) +{ + ScrollBar* pScroll = GetVScrollBar(); + if ( pScroll ) + pScroll->DoScrollAction( eScroll ); +} + +BOOL LicenseView::IsEndReached() const +{ + BOOL bEndReached; + + ExtTextView* pView = GetTextView(); + ExtTextEngine* pEdit = GetTextEngine(); + ULONG nHeight = pEdit->GetTextHeight(); + Size aOutSize = pView->GetWindow()->GetOutputSizePixel(); + Point aBottom( 0, aOutSize.Height() ); + + if ( (ULONG) pView->GetDocPos( aBottom ).Y() >= nHeight - 1 ) + bEndReached = TRUE; + else + bEndReached = FALSE; + + return bEndReached; +} + +void LicenseView::Notify( SfxBroadcaster&, const SfxHint& rHint ) +{ + if ( rHint.IsA( TYPE(TextHint) ) ) + { + BOOL bLastVal = EndReached(); + ULONG nId = ((const TextHint&)rHint).GetId(); + + if ( nId == TEXT_HINT_PARAINSERTED ) + { + if ( bLastVal ) + mbEndReached = IsEndReached(); + } + else if ( nId == TEXT_HINT_VIEWSCROLLED ) + { + if ( ! mbEndReached ) + mbEndReached = IsEndReached(); + maScrolledHdl.Call( this ); + } + + if ( EndReached() && !bLastVal ) + { + maEndReachedHdl.Call( this ); + } + } +} + + + +// ------------------------------------------------------------------- + +class MigrationThread : public ::osl::Thread +{ + public: + MigrationThread(); + + virtual void SAL_CALL run(); + virtual void SAL_CALL onTerminated(); +}; + +MigrationThread::MigrationThread() +{ +} + +void MigrationThread::run() +{ + try + { + Migration::doMigration(); + } + catch ( uno::Exception& ) + { + } +} + +void MigrationThread::onTerminated() +{ +} + +// ------------------------------------------------------------------- + +MigrationPage::MigrationPage( + svt::OWizardMachine* parent, + const ResId& resid, + ::com::sun::star::uno::Reference< ::com::sun::star::awt::XThrobber > xThrobber) + : OWizardPage(parent, resid) + , m_ftHead(this, WizardResId(FT_MIGRATION_HEADER)) + , m_ftBody(this, WizardResId(FT_MIGRATION_BODY)) + , m_cbMigration(this, WizardResId(CB_MIGRATION)) + , m_bMigrationDone(sal_False) + , m_xThrobber(xThrobber) +{ + FreeResource(); + _setBold(m_ftHead); + + // replace %OLDPRODUCT with found version name + String aText = m_ftBody.GetText(); + aText.SearchAndReplaceAll( UniString::CreateFromAscii("%OLDPRODUCT"), Migration::getOldVersionName()); + m_ftBody.SetText( aText ); +} + +sal_Bool MigrationPage::commitPage( CommitPageReason _eReason ) +{ + if (_eReason == eTravelForward && m_cbMigration.IsChecked() && !m_bMigrationDone) + { + GetParent()->EnterWait(); + FirstStartWizard* pWizard = dynamic_cast< FirstStartWizard* >( GetParent() ); + if ( pWizard ) + pWizard->DisableButtonsWhileMigration(); + + uno::Reference< awt::XWindow > xWin( m_xThrobber, uno::UNO_QUERY ); + xWin->setVisible( true ); + m_xThrobber->start(); + MigrationThread* pMigThread = new MigrationThread(); + pMigThread->create(); + + while ( pMigThread->isRunning() ) + { + Application::Reschedule(); + } + + m_xThrobber->stop(); + GetParent()->LeaveWait(); + // Next state will enable buttons - so no EnableButtons necessary! + xWin->setVisible( false ); + pMigThread->join(); + delete pMigThread; + m_bMigrationDone = sal_True; + } + else + Migration::cancelMigration(); + return sal_True; +} + +void MigrationPage::ActivatePage() +{ + OWizardPage::ActivatePage(); + GrabFocus(); +} + +UserPage::UserPage( svt::OWizardMachine* parent, const ResId& resid) + : OWizardPage(parent, resid) + , m_ftHead(this, WizardResId(FT_USER_HEADER)) + , m_ftBody(this, WizardResId(FT_USER_BODY)) + , m_ftFirst(this, WizardResId(FT_USER_FIRST)) + , m_edFirst(this, WizardResId(ED_USER_FIRST)) + , m_ftLast(this, WizardResId(FT_USER_LAST)) + , m_edLast(this, WizardResId(ED_USER_LAST)) + , m_ftInitials(this, WizardResId(FT_USER_INITIALS)) + , m_edInitials(this, WizardResId(ED_USER_INITIALS)) + , m_ftFather(this, WizardResId(FT_USER_FATHER)) + , m_edFather(this, WizardResId(ED_USER_FATHER)) + , m_lang(Application::GetSettings().GetUILanguage()) +{ + FreeResource(); + _setBold(m_ftHead); + + // check whether this is a russian version. otherwise + // we'll hide the 'Fathers name' field + SvtUserOptions aUserOpt; + m_edFirst.SetText(aUserOpt.GetFirstName()); + m_edLast.SetText(aUserOpt.GetLastName()); +#if 0 + rtl::OUString aUserName; + vos::OSecurity().getUserName( aUserName ); + aUserOpt.SetID( aUserName ); +#endif + + m_edInitials.SetText(aUserOpt.GetID()); + if (m_lang == LANGUAGE_RUSSIAN) + { + m_ftFather.Show(); + m_edFather.Show(); + m_edFather.SetText(aUserOpt.GetFathersName()); + } +} + +sal_Bool UserPage::commitPage( CommitPageReason ) +{ + SvtUserOptions aUserOpt; + aUserOpt.SetFirstName(m_edFirst.GetText()); + aUserOpt.SetLastName(m_edLast.GetText()); + aUserOpt.SetID( m_edInitials.GetText()); + + if (m_lang == LANGUAGE_RUSSIAN) + aUserOpt.SetFathersName(m_edFather.GetText()); + + return sal_True; +} + +void UserPage::ActivatePage() +{ + OWizardPage::ActivatePage(); + GrabFocus(); +} + +// ------------------------------------------------------------------- +UpdateCheckPage::UpdateCheckPage( svt::OWizardMachine* parent, const ResId& resid) + : OWizardPage(parent, resid) + , m_ftHead(this, WizardResId(FT_UPDATE_CHECK_HEADER)) + , m_ftBody(this, WizardResId(FT_UPDATE_CHECK_BODY)) + , m_cbUpdateCheck(this, WizardResId(CB_UPDATE_CHECK)) +{ + FreeResource(); + _setBold(m_ftHead); +} + +sal_Bool UpdateCheckPage::commitPage( CommitPageReason _eReason ) +{ + if ( _eReason == eTravelForward ) + { + try { + Reference < XNameReplace > xUpdateAccess; + Reference < XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory() ); + + xUpdateAccess = Reference < XNameReplace >( + xFactory->createInstance( UNISTRING( "com.sun.star.setup.UpdateCheckConfig" ) ), UNO_QUERY_THROW ); + + if ( !xUpdateAccess.is() ) + return sal_False; + + sal_Bool bAutoUpdChk = m_cbUpdateCheck.IsChecked(); + xUpdateAccess->replaceByName( UNISTRING("AutoCheckEnabled"), makeAny( bAutoUpdChk ) ); + + Reference< XChangesBatch > xChangesBatch( xUpdateAccess, UNO_QUERY); + if( xChangesBatch.is() && xChangesBatch->hasPendingChanges() ) + xChangesBatch->commitChanges(); + } catch (RuntimeException) + { + } + } + + return sal_True; +} + +void UpdateCheckPage::ActivatePage() +{ + OWizardPage::ActivatePage(); + GrabFocus(); +} + +// ------------------------------------------------------------------- +RegistrationPage::RegistrationPage( Window* pParent, const ResId& rResid ) + : OWizardPage( pParent, rResid ) + , m_ftHeader(this, WizardResId(FT_REGISTRATION_HEADER)) + , m_ftBody(this, WizardResId(FT_REGISTRATION_BODY)) + , m_rbNow(this, WizardResId(RB_REGISTRATION_NOW)) + , m_rbLater(this, WizardResId(RB_REGISTRATION_LATER)) + , m_rbNever(this, WizardResId(RB_REGISTRATION_NEVER)) + , m_flSeparator(this, WizardResId(FL_REGISTRATION)) + , m_ftEnd(this, WizardResId(FT_REGISTRATION_END)) + , m_bNeverVisible( sal_True ) +{ + FreeResource(); + + // another text for OOo + sal_Int32 nOpenSourceContext = 0; + try + { + ::utl::ConfigManager::GetDirectConfigProperty( + ::utl::ConfigManager::OPENSOURCECONTEXT ) >>= nOpenSourceContext; + } + catch( Exception& ) + { + DBG_ERRORFILE( "RegistrationPage::RegistrationPage(): error while getting open source context" ); + } + + if ( nOpenSourceContext > 0 ) + { + String sBodyText( WizardResId( STR_REGISTRATION_OOO ) ); + m_ftBody.SetText( sBodyText ); + } + + // calculate height of body text and rearrange the buttons + Size aSize = m_ftBody.GetSizePixel(); + Size aMinSize = m_ftBody.CalcMinimumSize( aSize.Width() ); + long nTxtH = aMinSize.Height(); + long nCtrlH = aSize.Height(); + long nDelta = ( nCtrlH - nTxtH ); + aSize.Height() -= nDelta; + m_ftBody.SetSizePixel( aSize ); + Window* pWins[] = { &m_rbNow, &m_rbLater, &m_rbNever }; + Window** pCurrent = pWins; + for ( sal_uInt32 i = 0; i < sizeof( pWins ) / sizeof( pWins[ 0 ] ); ++i, ++pCurrent ) + { + Point aNewPos = (*pCurrent)->GetPosPixel(); + aNewPos.Y() -= nDelta; + (*pCurrent)->SetPosPixel( aNewPos ); + } + + _setBold(m_ftHeader); + impl_retrieveConfigurationData(); + updateButtonStates(); +} + +bool RegistrationPage::canAdvance() const +{ + return false; +} + +void RegistrationPage::ActivatePage() +{ + OWizardPage::ActivatePage(); + GrabFocus(); +} + +void RegistrationPage::impl_retrieveConfigurationData() +{ + static ::rtl::OUString PACKAGE = ::rtl::OUString::createFromAscii("org.openoffice.FirstStartWizard"); + static ::rtl::OUString PATH = ::rtl::OUString::createFromAscii("TabPages/Registration/RegistrationOptions/NeverButton"); + static ::rtl::OUString KEY = ::rtl::OUString::createFromAscii("Visible"); + + ::com::sun::star::uno::Any aValue; + try + { + aValue = ::comphelper::ConfigurationHelper::readDirectKey( + ::comphelper::getProcessServiceFactory(), + PACKAGE, + PATH, + KEY, + ::comphelper::ConfigurationHelper::E_READONLY); + } + catch(const ::com::sun::star::uno::Exception&) + { aValue.clear(); } + + aValue >>= m_bNeverVisible; +} + +void RegistrationPage::updateButtonStates() +{ + m_rbNever.Show( m_bNeverVisible ); +} + +sal_Bool RegistrationPage::commitPage( CommitPageReason _eReason ) +{ + if ( _eReason == eFinish ) + { + ::utl::RegOptions aOptions; + rtl::OUString aEvent; + + if ( m_rbNow.IsChecked()) + { + aEvent = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "RegistrationRequired" ) ); + } + else if (m_rbLater.IsChecked()) + { + aOptions.activateReminder(7); + // avtivate a reminder job... + } + // aOptions.markSessionDone(); + + try + { + // create the Desktop component which can load components + Reference < XMultiServiceFactory > xFactory = ::comphelper::getProcessServiceFactory(); + if( xFactory.is() ) + { + Reference< com::sun::star::task::XJobExecutor > xProductRegistration( + xFactory->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.setup.ProductRegistration" ) ) ), + UNO_QUERY_THROW ); + + // tell it that the user wants to register + xProductRegistration->trigger( aEvent ); + } + } + catch( const Exception& ) + { + } + } + return sal_True; +} + +RegistrationPage::RegistrationMode RegistrationPage::getRegistrationMode() const +{ + RegistrationPage::RegistrationMode eMode = rmNow; + if ( m_rbLater.IsChecked() ) + eMode = rmLater; + else if ( m_rbNever.IsChecked() ) + eMode = rmNever; + return eMode; +} + +void RegistrationPage::prepareSingleMode() +{ + // remove wizard text (hide and cut) + m_flSeparator.Hide(); + m_ftEnd.Hide(); + Size aNewSize = GetSizePixel(); + aNewSize.Height() -= ( aNewSize.Height() - m_flSeparator.GetPosPixel().Y() ); + SetSizePixel( aNewSize ); +} + +bool RegistrationPage::hasReminderDateCome() +{ + return ::utl::RegOptions().hasReminderDateCome(); +} + +void RegistrationPage::executeSingleMode() +{ + // opens the page in a single tabdialog + SfxSingleTabDialog aSingleDlg( NULL, TP_REGISTRATION ); + RegistrationPage* pPage = new RegistrationPage( &aSingleDlg, WizardResId( TP_REGISTRATION ) ); + pPage->prepareSingleMode(); + aSingleDlg.SetPage( pPage ); + aSingleDlg.SetText( pPage->getSingleModeTitle() ); + aSingleDlg.Execute(); + // the registration modes "Now" and "Later" are handled by the page + RegistrationPage::RegistrationMode eMode = pPage->getRegistrationMode(); + if ( eMode == RegistrationPage::rmNow || eMode == RegistrationPage::rmLater ) + pPage->commitPage( IWizardPage::eFinish ); + if ( eMode != RegistrationPage::rmLater ) + ::utl::RegOptions().removeReminder(); +} + +} // namespace desktop diff --git a/desktop/source/migration/pages.hxx b/desktop/source/migration/pages.hxx new file mode 100644 index 000000000000..9740773fe602 --- /dev/null +++ b/desktop/source/migration/pages.hxx @@ -0,0 +1,214 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _PAGES_HXX_ +#define _PAGES_HXX_ + +#include <vcl/tabpage.hxx> +#include <vcl/fixed.hxx> +#include <vcl/button.hxx> +#include <vcl/dialog.hxx> +#include <vcl/scrbar.hxx> +#include <svtools/wizardmachine.hxx> +#include <svtools/svmedit.hxx> +#include <svl/lstner.hxx> +#include <svtools/xtextedt.hxx> + +#include <com/sun/star/awt/XThrobber.hpp> + +namespace desktop +{ +class WelcomePage : public svt::OWizardPage +{ +private: + FixedText m_ftHead; + FixedText m_ftBody; + svt::OWizardMachine *m_pParent; + sal_Bool m_bLicenseNeedsAcceptance; + enum OEMType + { + OEM_NONE, OEM_NORMAL, OEM_EXTENDED + }; + bool bIsEvalVersion; + bool bNoEvalText; + void checkEval(); + + +public: + WelcomePage( svt::OWizardMachine* parent, const ResId& resid, sal_Bool bLicenseNeedsAcceptance ); +protected: + virtual void ActivatePage(); +}; + +class LicenseView : public MultiLineEdit, public SfxListener +{ + BOOL mbEndReached; + Link maEndReachedHdl; + Link maScrolledHdl; + +public: + LicenseView( Window* pParent, const ResId& rResId ); + ~LicenseView(); + + void ScrollDown( ScrollType eScroll ); + + BOOL IsEndReached() const; + BOOL EndReached() const { return mbEndReached; } + void SetEndReached( BOOL bEnd ) { mbEndReached = bEnd; } + + void SetEndReachedHdl( const Link& rHdl ) { maEndReachedHdl = rHdl; } + const Link& GetAutocompleteHdl() const { return maEndReachedHdl; } + + void SetScrolledHdl( const Link& rHdl ) { maScrolledHdl = rHdl; } + const Link& GetScrolledHdl() const { return maScrolledHdl; } + + virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ); + +protected: + using MultiLineEdit::Notify; +}; + +class LicensePage : public svt::OWizardPage +{ +private: + svt::OWizardMachine *m_pParent; + FixedText m_ftHead; + FixedText m_ftBody1; + FixedText m_ftBody1Txt; + FixedText m_ftBody2; + FixedText m_ftBody2Txt; + LicenseView m_mlLicense; + PushButton m_pbDown; + sal_Bool m_bLicenseRead; +public: + LicensePage( svt::OWizardMachine* parent, const ResId& resid, const rtl::OUString &rLicensePath ); +private: + DECL_LINK(PageDownHdl, PushButton*); + DECL_LINK(EndReachedHdl, LicenseView*); + DECL_LINK(ScrolledHdl, LicenseView*); +protected: + virtual bool canAdvance() const; + virtual void ActivatePage(); +}; + +class MigrationPage : public svt::OWizardPage +{ +private: + FixedText m_ftHead; + FixedText m_ftBody; + CheckBox m_cbMigration; + sal_Bool m_bMigrationDone; + ::com::sun::star::uno::Reference< ::com::sun::star::awt::XThrobber > m_xThrobber; +public: + MigrationPage( svt::OWizardMachine* parent, const ResId& resid, ::com::sun::star::uno::Reference< ::com::sun::star::awt::XThrobber > xThrobber ); + virtual sal_Bool commitPage( CommitPageReason _eReason ); + +protected: + virtual void ActivatePage(); +}; + +class UserPage : public svt::OWizardPage +{ +private: + FixedText m_ftHead; + FixedText m_ftBody; + FixedText m_ftFirst; + Edit m_edFirst; + FixedText m_ftLast; + Edit m_edLast; + FixedText m_ftInitials; + Edit m_edInitials; + FixedText m_ftFather; + Edit m_edFather; + LanguageType m_lang; + +public: + UserPage( svt::OWizardMachine* parent, const ResId& resid); + virtual sal_Bool commitPage( CommitPageReason _eReason ); +protected: + virtual void ActivatePage(); +}; + +class UpdateCheckPage : public svt::OWizardPage +{ +private: + FixedText m_ftHead; + FixedText m_ftBody; + CheckBox m_cbUpdateCheck; +public: + UpdateCheckPage( svt::OWizardMachine* parent, const ResId& resid); + virtual sal_Bool commitPage( CommitPageReason _eReason ); + +protected: + virtual void ActivatePage(); +}; + + +class RegistrationPage : public svt::OWizardPage +{ +private: + FixedText m_ftHeader; + FixedText m_ftBody; + RadioButton m_rbNow; + RadioButton m_rbLater; + RadioButton m_rbNever; + FixedLine m_flSeparator; + FixedText m_ftEnd; + + sal_Bool m_bNeverVisible; + + void updateButtonStates(); + void impl_retrieveConfigurationData(); + +protected: + virtual bool canAdvance() const; + virtual void ActivatePage(); + + virtual sal_Bool commitPage( CommitPageReason _eReason ); + +public: + RegistrationPage( Window* parent, const ResId& resid); + + enum RegistrationMode + { + rmNow, // register now + rmLater, // register later + rmNever // register never + }; + + RegistrationMode getRegistrationMode() const; + void prepareSingleMode(); + inline String getSingleModeTitle() const { return m_ftHeader.GetText(); } + + static bool hasReminderDateCome(); + static void executeSingleMode(); +}; + +} // namespace desktop + +#endif // #ifndef _PAGES_HXX_ + diff --git a/desktop/source/migration/services/autocorrmigration.cxx b/desktop/source/migration/services/autocorrmigration.cxx new file mode 100644 index 000000000000..c416992da13c --- /dev/null +++ b/desktop/source/migration/services/autocorrmigration.cxx @@ -0,0 +1,285 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_desktop.hxx" +#include "autocorrmigration.hxx" +#include <i18npool/mslangid.hxx> +#include <tools/urlobj.hxx> +#include <unotools/bootstrap.hxx> + + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; + + +//......................................................................... +namespace migration +{ +//......................................................................... + + + static ::rtl::OUString sSourceSubDir = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/user/autocorr" ) ); + static ::rtl::OUString sTargetSubDir = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/user/autocorr" ) ); + static ::rtl::OUString sBaseName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/acor" ) ); + static ::rtl::OUString sSuffix = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".dat" ) ); + + + // ============================================================================= + // component operations + // ============================================================================= + + ::rtl::OUString AutocorrectionMigration_getImplementationName() + { + static ::rtl::OUString* pImplName = 0; + if ( !pImplName ) + { + ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); + if ( !pImplName ) + { + static ::rtl::OUString aImplName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.desktop.migration.Autocorrection" ) ); + pImplName = &aImplName; + } + } + return *pImplName; + } + + // ----------------------------------------------------------------------------- + + Sequence< ::rtl::OUString > AutocorrectionMigration_getSupportedServiceNames() + { + static Sequence< ::rtl::OUString >* pNames = 0; + if ( !pNames ) + { + ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); + if ( !pNames ) + { + static Sequence< ::rtl::OUString > aNames(1); + aNames.getArray()[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.migration.Autocorrection" ) ); + pNames = &aNames; + } + } + return *pNames; + } + + // ============================================================================= + // AutocorrectionMigration + // ============================================================================= + + AutocorrectionMigration::AutocorrectionMigration() + { + } + + // ----------------------------------------------------------------------------- + + AutocorrectionMigration::~AutocorrectionMigration() + { + } + + // ----------------------------------------------------------------------------- + + TStringVectorPtr AutocorrectionMigration::getFiles( const ::rtl::OUString& rBaseURL ) const + { + TStringVectorPtr aResult( new TStringVector ); + ::osl::Directory aDir( rBaseURL); + + if ( aDir.open() == ::osl::FileBase::E_None ) + { + // iterate over directory content + TStringVector aSubDirs; + ::osl::DirectoryItem aItem; + while ( aDir.getNextItem( aItem ) == ::osl::FileBase::E_None ) + { + ::osl::FileStatus aFileStatus( FileStatusMask_Type | FileStatusMask_FileURL ); + if ( aItem.getFileStatus( aFileStatus ) == ::osl::FileBase::E_None ) + { + if ( aFileStatus.getFileType() == ::osl::FileStatus::Directory ) + aSubDirs.push_back( aFileStatus.getFileURL() ); + else + aResult->push_back( aFileStatus.getFileURL() ); + } + } + + // iterate recursive over subfolders + TStringVector::const_iterator aI = aSubDirs.begin(); + while ( aI != aSubDirs.end() ) + { + TStringVectorPtr aSubResult = getFiles( *aI ); + aResult->insert( aResult->end(), aSubResult->begin(), aSubResult->end() ); + ++aI; + } + } + + return aResult; + } + + // ----------------------------------------------------------------------------- + + ::osl::FileBase::RC AutocorrectionMigration::checkAndCreateDirectory( INetURLObject& rDirURL ) + { + ::osl::FileBase::RC aResult = ::osl::Directory::create( rDirURL.GetMainURL( INetURLObject::DECODE_TO_IURI ) ); + if ( aResult == ::osl::FileBase::E_NOENT ) + { + INetURLObject aBaseURL( rDirURL ); + aBaseURL.removeSegment(); + checkAndCreateDirectory( aBaseURL ); + return ::osl::Directory::create( rDirURL.GetMainURL( INetURLObject::DECODE_TO_IURI ) ); + } + else + { + return aResult; + } + } + + // ----------------------------------------------------------------------------- + + void AutocorrectionMigration::copyFiles() + { + ::rtl::OUString sTargetDir; + ::utl::Bootstrap::PathStatus aStatus = ::utl::Bootstrap::locateUserInstallation( sTargetDir ); + if ( aStatus == ::utl::Bootstrap::PATH_EXISTS ) + { + sTargetDir += sTargetSubDir; + 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 ); + ::rtl::OUString sLanguageType = sSourceLocalName.copy( nStart, nEnd - nStart ); + ::rtl::OUString sIsoName = MsLangId::convertLanguageToIsoString( (LanguageType) sLanguageType.toInt32() ); + ::rtl::OUString sTargetLocalName = sBaseName; + sTargetLocalName += ::rtl::OUString::createFromAscii( "_" ); + sTargetLocalName += sIsoName; + sTargetLocalName += sSuffix; + ::rtl::OUString sTargetName = sTargetDir + sTargetLocalName; + INetURLObject aURL( sTargetName ); + aURL.removeSegment(); + checkAndCreateDirectory( aURL ); + ::osl::FileBase::RC aResult = ::osl::File::copy( *aI, sTargetName ); + if ( aResult != ::osl::FileBase::E_None ) + { + ::rtl::OString aMsg( "AutocorrectionMigration::copyFiles: cannot copy " ); + aMsg += ::rtl::OUStringToOString( *aI, RTL_TEXTENCODING_UTF8 ) + " to " + + ::rtl::OUStringToOString( sTargetName, RTL_TEXTENCODING_UTF8 ); + OSL_ENSURE( sal_False, aMsg.getStr() ); + } + ++aI; + } + } + else + { + OSL_ENSURE( sal_False, "AutocorrectionMigration::copyFiles: no user installation!" ); + } + } + + // ----------------------------------------------------------------------------- + // XServiceInfo + // ----------------------------------------------------------------------------- + + ::rtl::OUString AutocorrectionMigration::getImplementationName() throw (RuntimeException) + { + return AutocorrectionMigration_getImplementationName(); + } + + // ----------------------------------------------------------------------------- + + sal_Bool AutocorrectionMigration::supportsService( const ::rtl::OUString& rServiceName ) throw (RuntimeException) + { + Sequence< ::rtl::OUString > aNames( getSupportedServiceNames() ); + const ::rtl::OUString* pNames = aNames.getConstArray(); + const ::rtl::OUString* pEnd = pNames + aNames.getLength(); + for ( ; pNames != pEnd && !pNames->equals( rServiceName ); ++pNames ) + ; + + return pNames != pEnd; + } + + // ----------------------------------------------------------------------------- + + Sequence< ::rtl::OUString > AutocorrectionMigration::getSupportedServiceNames() throw (RuntimeException) + { + return AutocorrectionMigration_getSupportedServiceNames(); + } + + // ----------------------------------------------------------------------------- + // XInitialization + // ----------------------------------------------------------------------------- + + void AutocorrectionMigration::initialize( const Sequence< Any >& aArguments ) throw (Exception, RuntimeException) + { + ::osl::MutexGuard aGuard( m_aMutex ); + + const Any* pIter = aArguments.getConstArray(); + const Any* pEnd = pIter + aArguments.getLength(); + for ( ; pIter != pEnd ; ++pIter ) + { + beans::NamedValue aValue; + *pIter >>= aValue; + if ( aValue.Name.equalsAscii( "UserData" ) ) + { + if ( !(aValue.Value >>= m_sSourceDir) ) + { + OSL_ENSURE( false, "AutocorrectionMigration::initialize: argument UserData has wrong type!" ); + } + m_sSourceDir += sSourceSubDir; + break; + } + } + } + + // ----------------------------------------------------------------------------- + // XJob + // ----------------------------------------------------------------------------- + + Any AutocorrectionMigration::execute( const Sequence< beans::NamedValue >& ) + throw (lang::IllegalArgumentException, Exception, RuntimeException) + { + ::osl::MutexGuard aGuard( m_aMutex ); + + copyFiles(); + + return Any(); + } + + // ============================================================================= + // component operations + // ============================================================================= + + Reference< XInterface > SAL_CALL AutocorrectionMigration_create( + Reference< XComponentContext > const & ) + SAL_THROW( () ) + { + return static_cast< lang::XTypeProvider * >( new AutocorrectionMigration() ); + } + + // ----------------------------------------------------------------------------- + +//......................................................................... +} // namespace migration +//......................................................................... diff --git a/desktop/source/migration/services/autocorrmigration.hxx b/desktop/source/migration/services/autocorrmigration.hxx new file mode 100644 index 000000000000..715baa6bca12 --- /dev/null +++ b/desktop/source/migration/services/autocorrmigration.hxx @@ -0,0 +1,102 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _DESKTOP_AUTOCORRMIGRATION_HXX_ +#define _DESKTOP_AUTOCORRMIGRATION_HXX_ + +#include "misc.hxx" +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/lang/XInitialization.hpp> +#include <com/sun/star/task/XJob.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <cppuhelper/implbase3.hxx> +#include <osl/mutex.hxx> +#include <osl/file.hxx> + + +class INetURLObject; + + +//......................................................................... +namespace migration +{ +//......................................................................... + + ::rtl::OUString SAL_CALL AutocorrectionMigration_getImplementationName(); + ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL AutocorrectionMigration_getSupportedServiceNames(); + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL AutocorrectionMigration_create( + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > const & xContext ) + SAL_THROW( (::com::sun::star::uno::Exception) ); + + + // ============================================================================= + // class AutocorrectionMigration + // ============================================================================= + + typedef ::cppu::WeakImplHelper3< + ::com::sun::star::lang::XServiceInfo, + ::com::sun::star::lang::XInitialization, + ::com::sun::star::task::XJob > AutocorrectionMigration_BASE; + + class AutocorrectionMigration : public AutocorrectionMigration_BASE + { + private: + ::osl::Mutex m_aMutex; + ::rtl::OUString m_sSourceDir; + + TStringVectorPtr getFiles( const ::rtl::OUString& rBaseURL ) const; + ::osl::FileBase::RC checkAndCreateDirectory( INetURLObject& rDirURL ); + void copyFiles(); + + public: + AutocorrectionMigration(); + virtual ~AutocorrectionMigration(); + + // XServiceInfo + virtual ::rtl::OUString SAL_CALL getImplementationName() + throw (::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& rServiceName ) + throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() + throw (::com::sun::star::uno::RuntimeException); + + // XInitialization + virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) + throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); + + // XJob + virtual ::com::sun::star::uno::Any SAL_CALL execute( + const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& Arguments ) + throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::Exception, + ::com::sun::star::uno::RuntimeException); + }; + +//......................................................................... +} // namespace migration +//......................................................................... + +#endif // _DESKTOP_AUTOCORRMIGRATION_HXX_ diff --git a/desktop/source/migration/services/basicmigration.cxx b/desktop/source/migration/services/basicmigration.cxx new file mode 100644 index 000000000000..3e7384f2262f --- /dev/null +++ b/desktop/source/migration/services/basicmigration.cxx @@ -0,0 +1,274 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_desktop.hxx" +#include "basicmigration.hxx" +#include <tools/urlobj.hxx> +#include <unotools/bootstrap.hxx> + + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; + + +//......................................................................... +namespace migration +{ +//......................................................................... + + + static ::rtl::OUString sSourceUserBasic = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/user/basic" ) ); + static ::rtl::OUString sTargetUserBasic = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/user/__basic_80" ) ); + + + // ============================================================================= + // component operations + // ============================================================================= + + ::rtl::OUString BasicMigration_getImplementationName() + { + static ::rtl::OUString* pImplName = 0; + if ( !pImplName ) + { + ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); + if ( !pImplName ) + { + static ::rtl::OUString aImplName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.desktop.migration.Basic" ) ); + pImplName = &aImplName; + } + } + return *pImplName; + } + + // ----------------------------------------------------------------------------- + + Sequence< ::rtl::OUString > BasicMigration_getSupportedServiceNames() + { + static Sequence< ::rtl::OUString >* pNames = 0; + if ( !pNames ) + { + ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); + if ( !pNames ) + { + static Sequence< ::rtl::OUString > aNames(1); + aNames.getArray()[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.migration.Basic" ) ); + pNames = &aNames; + } + } + return *pNames; + } + + // ============================================================================= + // BasicMigration + // ============================================================================= + + BasicMigration::BasicMigration() + { + } + + // ----------------------------------------------------------------------------- + + BasicMigration::~BasicMigration() + { + } + + // ----------------------------------------------------------------------------- + + TStringVectorPtr BasicMigration::getFiles( const ::rtl::OUString& rBaseURL ) const + { + TStringVectorPtr aResult( new TStringVector ); + ::osl::Directory aDir( rBaseURL); + + if ( aDir.open() == ::osl::FileBase::E_None ) + { + // iterate over directory content + TStringVector aSubDirs; + ::osl::DirectoryItem aItem; + while ( aDir.getNextItem( aItem ) == ::osl::FileBase::E_None ) + { + ::osl::FileStatus aFileStatus( FileStatusMask_Type | FileStatusMask_FileURL ); + if ( aItem.getFileStatus( aFileStatus ) == ::osl::FileBase::E_None ) + { + if ( aFileStatus.getFileType() == ::osl::FileStatus::Directory ) + aSubDirs.push_back( aFileStatus.getFileURL() ); + else + aResult->push_back( aFileStatus.getFileURL() ); + } + } + + // iterate recursive over subfolders + TStringVector::const_iterator aI = aSubDirs.begin(); + while ( aI != aSubDirs.end() ) + { + TStringVectorPtr aSubResult = getFiles( *aI ); + aResult->insert( aResult->end(), aSubResult->begin(), aSubResult->end() ); + ++aI; + } + } + + return aResult; + } + + // ----------------------------------------------------------------------------- + + ::osl::FileBase::RC BasicMigration::checkAndCreateDirectory( INetURLObject& rDirURL ) + { + ::osl::FileBase::RC aResult = ::osl::Directory::create( rDirURL.GetMainURL( INetURLObject::DECODE_TO_IURI ) ); + if ( aResult == ::osl::FileBase::E_NOENT ) + { + INetURLObject aBaseURL( rDirURL ); + aBaseURL.removeSegment(); + checkAndCreateDirectory( aBaseURL ); + return ::osl::Directory::create( rDirURL.GetMainURL( INetURLObject::DECODE_TO_IURI ) ); + } + else + { + return aResult; + } + } + + // ----------------------------------------------------------------------------- + + void BasicMigration::copyFiles() + { + ::rtl::OUString sTargetDir; + ::utl::Bootstrap::PathStatus aStatus = ::utl::Bootstrap::locateUserInstallation( sTargetDir ); + if ( aStatus == ::utl::Bootstrap::PATH_EXISTS ) + { + sTargetDir += sTargetUserBasic; + 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 ); + ::osl::FileBase::RC aResult = ::osl::File::copy( *aI, sTargetName ); + if ( aResult != ::osl::FileBase::E_None ) + { + ::rtl::OString aMsg( "BasicMigration::copyFiles: cannot copy " ); + aMsg += ::rtl::OUStringToOString( *aI, RTL_TEXTENCODING_UTF8 ) + " to " + + ::rtl::OUStringToOString( sTargetName, RTL_TEXTENCODING_UTF8 ); + OSL_ENSURE( sal_False, aMsg.getStr() ); + } + ++aI; + } + } + else + { + OSL_ENSURE( sal_False, "BasicMigration::copyFiles: no user installation!" ); + } + } + + // ----------------------------------------------------------------------------- + // XServiceInfo + // ----------------------------------------------------------------------------- + + ::rtl::OUString BasicMigration::getImplementationName() throw (RuntimeException) + { + return BasicMigration_getImplementationName(); + } + + // ----------------------------------------------------------------------------- + + sal_Bool BasicMigration::supportsService( const ::rtl::OUString& rServiceName ) throw (RuntimeException) + { + Sequence< ::rtl::OUString > aNames( getSupportedServiceNames() ); + const ::rtl::OUString* pNames = aNames.getConstArray(); + const ::rtl::OUString* pEnd = pNames + aNames.getLength(); + for ( ; pNames != pEnd && !pNames->equals( rServiceName ); ++pNames ) + ; + + return pNames != pEnd; + } + + // ----------------------------------------------------------------------------- + + Sequence< ::rtl::OUString > BasicMigration::getSupportedServiceNames() throw (RuntimeException) + { + return BasicMigration_getSupportedServiceNames(); + } + + // ----------------------------------------------------------------------------- + // XInitialization + // ----------------------------------------------------------------------------- + + void BasicMigration::initialize( const Sequence< Any >& aArguments ) throw (Exception, RuntimeException) + { + ::osl::MutexGuard aGuard( m_aMutex ); + + const Any* pIter = aArguments.getConstArray(); + const Any* pEnd = pIter + aArguments.getLength(); + for ( ; pIter != pEnd ; ++pIter ) + { + beans::NamedValue aValue; + *pIter >>= aValue; + if ( aValue.Name.equalsAscii( "UserData" ) ) + { + if ( !(aValue.Value >>= m_sSourceDir) ) + { + OSL_ENSURE( false, "BasicMigration::initialize: argument UserData has wrong type!" ); + } + m_sSourceDir += sSourceUserBasic; + break; + } + } + } + + // ----------------------------------------------------------------------------- + // XJob + // ----------------------------------------------------------------------------- + + Any BasicMigration::execute( const Sequence< beans::NamedValue >& ) + throw (lang::IllegalArgumentException, Exception, RuntimeException) + { + ::osl::MutexGuard aGuard( m_aMutex ); + + copyFiles(); + + return Any(); + } + + // ============================================================================= + // component operations + // ============================================================================= + + Reference< XInterface > SAL_CALL BasicMigration_create( + Reference< XComponentContext > const & ) + SAL_THROW( () ) + { + return static_cast< lang::XTypeProvider * >( new BasicMigration() ); + } + + // ----------------------------------------------------------------------------- + +//......................................................................... +} // namespace migration +//......................................................................... diff --git a/desktop/source/migration/services/basicmigration.hxx b/desktop/source/migration/services/basicmigration.hxx new file mode 100644 index 000000000000..9b6433ba88e8 --- /dev/null +++ b/desktop/source/migration/services/basicmigration.hxx @@ -0,0 +1,102 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _DESKTOP_BASICMIGRATION_HXX_ +#define _DESKTOP_BASICMIGRATION_HXX_ + +#include "misc.hxx" +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/lang/XInitialization.hpp> +#include <com/sun/star/task/XJob.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <cppuhelper/implbase3.hxx> +#include <osl/mutex.hxx> +#include <osl/file.hxx> + + +class INetURLObject; + + +//......................................................................... +namespace migration +{ +//......................................................................... + + ::rtl::OUString SAL_CALL BasicMigration_getImplementationName(); + ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL BasicMigration_getSupportedServiceNames(); + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL BasicMigration_create( + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > const & xContext ) + SAL_THROW( (::com::sun::star::uno::Exception) ); + + + // ============================================================================= + // class BasicMigration + // ============================================================================= + + typedef ::cppu::WeakImplHelper3< + ::com::sun::star::lang::XServiceInfo, + ::com::sun::star::lang::XInitialization, + ::com::sun::star::task::XJob > BasicMigration_BASE; + + class BasicMigration : public BasicMigration_BASE + { + private: + ::osl::Mutex m_aMutex; + ::rtl::OUString m_sSourceDir; + + TStringVectorPtr getFiles( const ::rtl::OUString& rBaseURL ) const; + ::osl::FileBase::RC checkAndCreateDirectory( INetURLObject& rDirURL ); + void copyFiles(); + + public: + BasicMigration(); + virtual ~BasicMigration(); + + // XServiceInfo + virtual ::rtl::OUString SAL_CALL getImplementationName() + throw (::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& rServiceName ) + throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() + throw (::com::sun::star::uno::RuntimeException); + + // XInitialization + virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) + throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); + + // XJob + virtual ::com::sun::star::uno::Any SAL_CALL execute( + const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& Arguments ) + throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::Exception, + ::com::sun::star::uno::RuntimeException); + }; + +//......................................................................... +} // namespace migration +//......................................................................... + +#endif // _DESKTOP_BASICMIGRATION_HXX_ diff --git a/desktop/source/migration/services/cexports.cxx b/desktop/source/migration/services/cexports.cxx new file mode 100644 index 000000000000..c1971e9d4d00 --- /dev/null +++ b/desktop/source/migration/services/cexports.cxx @@ -0,0 +1,80 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_desktop.hxx" + +#include "cppuhelper/implementationentry.hxx" +#include "basicmigration.hxx" +#include "wordbookmigration.hxx" +#include "extensionmigration.hxx" + +extern "C" +{ + +::cppu::ImplementationEntry entries [] = +{ + { + migration::BasicMigration_create, migration::BasicMigration_getImplementationName, + migration::BasicMigration_getSupportedServiceNames, ::cppu::createSingleComponentFactory, + 0, 0 + }, + { + migration::WordbookMigration_create, migration::WordbookMigration_getImplementationName, + migration::WordbookMigration_getSupportedServiceNames, ::cppu::createSingleComponentFactory, + 0, 0 + }, + { + migration::ExtensionMigration_create, migration::ExtensionMigration_getImplementationName, + migration::ExtensionMigration_getSupportedServiceNames, ::cppu::createSingleComponentFactory, + 0, 0 + }, + { 0, 0, 0, 0, 0, 0 } +}; + + +void SAL_CALL component_getImplementationEnvironment( + const sal_Char ** ppEnvTypeName, uno_Environment ** ) +{ + *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; +} + +sal_Bool SAL_CALL component_writeInfo( + void * pServiceManager, void * pRegistryKey ) +{ + return ::cppu::component_writeInfoHelper( + pServiceManager, pRegistryKey, entries ); +} + +void * SAL_CALL component_getFactory( + const sal_Char * pImplName, void * pServiceManager, void * pRegistryKey ) +{ + return ::cppu::component_getFactoryHelper( + pImplName, pServiceManager, pRegistryKey, entries ); +} + +} diff --git a/desktop/source/migration/services/cexportsoo3.cxx b/desktop/source/migration/services/cexportsoo3.cxx new file mode 100755 index 000000000000..20b8232044e9 --- /dev/null +++ b/desktop/source/migration/services/cexportsoo3.cxx @@ -0,0 +1,71 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: cexports.cxx,v $ + * $Revision: 1.9 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_desktop.hxx" + +#include "cppuhelper/implementationentry.hxx" +#include "oo3extensionmigration.hxx" + +extern "C" +{ + +::cppu::ImplementationEntry entries [] = +{ + { + migration::OO3ExtensionMigration_create, migration::OO3ExtensionMigration_getImplementationName, + migration::OO3ExtensionMigration_getSupportedServiceNames, ::cppu::createSingleComponentFactory, + 0, 0 + }, + { 0, 0, 0, 0, 0, 0 } +}; + + +void SAL_CALL component_getImplementationEnvironment( + const sal_Char ** ppEnvTypeName, uno_Environment ** ) +{ + *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; +} + +sal_Bool SAL_CALL component_writeInfo( + void * pServiceManager, void * pRegistryKey ) +{ + return ::cppu::component_writeInfoHelper( + pServiceManager, pRegistryKey, entries ); +} + +void * SAL_CALL component_getFactory( + const sal_Char * pImplName, void * pServiceManager, void * pRegistryKey ) +{ + return ::cppu::component_getFactoryHelper( + pImplName, pServiceManager, pRegistryKey, entries ); +} + +} diff --git a/desktop/source/migration/services/cppumaker.mk b/desktop/source/migration/services/cppumaker.mk new file mode 100644 index 000000000000..5ab16ed1e3fe --- /dev/null +++ b/desktop/source/migration/services/cppumaker.mk @@ -0,0 +1,36 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +.IF "$(debug)" != "" + +# MSVC++: no inlining +.IF "$(COM)" == "MSC" +CFLAGS += -Ob0 +.ENDIF + +.ENDIF + diff --git a/desktop/source/migration/services/extensionmigration.cxx b/desktop/source/migration/services/extensionmigration.cxx new file mode 100755 index 000000000000..a926f17c0c19 --- /dev/null +++ b/desktop/source/migration/services/extensionmigration.cxx @@ -0,0 +1,540 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_desktop.hxx" +#include "extensionmigration.hxx" +#include <tools/urlobj.hxx> +#include <unotools/bootstrap.hxx> +#include <unotools/ucbstreamhelper.hxx> +#include <ucbhelper/content.hxx> +#include <com/sun/star/ucb/XCommandInfo.hpp> +#include <com/sun/star/ucb/TransferInfo.hpp> +#include <com/sun/star/ucb/NameClash.hpp> +#include "comphelper/processfactory.hxx" +#include "com/sun/star/deployment/XPackageManagerFactory.hpp" +#include "com/sun/star/ucb/XCommandEnvironment.hpp" +#include "com/sun/star/xml/sax/XParser.hpp" +#include "rtl/instance.hxx" +#include "osl/file.hxx" +#include "osl/thread.h" + +#include "xmlscript/xmllib_imexp.hxx" +#include "../../deployment/inc/dp_ucb.h" + +#ifdef SYSTEM_DB +#include <db.h> +#else +#include <berkeleydb/db.h> +#endif + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; + +namespace { + + struct LibDescriptor : + public rtl::StaticWithInit<const ::xmlscript::LibDescriptorArray, LibDescriptor> { + const ::xmlscript::LibDescriptorArray operator () () { + + + return ::xmlscript::LibDescriptorArray(); + } +}; +} +//......................................................................... +namespace migration +{ +//......................................................................... + + + static ::rtl::OUString sExtensionSubDir = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/user/uno_packages/" ) ); + static ::rtl::OUString sSubDirName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "cache" ) ); + static ::rtl::OUString sConfigDir = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/user/registry/data" ) ); + static ::rtl::OUString sOrgDir = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/user/registry/data/org" ) ); + static ::rtl::OUString sExcludeDir1 = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/user/registry/data/org" ) ); + static ::rtl::OUString sExcludeDir2 = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/user/registry/data/org/openoffice" ) ); + + static ::rtl::OUString sBasicType = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("application/vnd.sun.star.basic-library")); + static ::rtl::OUString sDialogType = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("application/vnd.sun.star.dialog-library")); + + static ::rtl::OUString sConfigurationDataType = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("application/vnd.sun.star.configuration-data")); + static ::rtl::OUString sConfigurationSchemaType = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("application/vnd.sun.star.configuration-schema")); + + // ============================================================================= + // component operations + // ============================================================================= + + ::rtl::OUString ExtensionMigration_getImplementationName() + { + static ::rtl::OUString* pImplName = 0; + if ( !pImplName ) + { + ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); + if ( !pImplName ) + { + static ::rtl::OUString aImplName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.desktop.migration.Extensions" ) ); + pImplName = &aImplName; + } + } + return *pImplName; + } + + // ----------------------------------------------------------------------------- + + Sequence< ::rtl::OUString > ExtensionMigration_getSupportedServiceNames() + { + static Sequence< ::rtl::OUString >* pNames = 0; + if ( !pNames ) + { + ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); + if ( !pNames ) + { + static Sequence< ::rtl::OUString > aNames(1); + aNames.getArray()[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.migration.Extensions" ) ); + pNames = &aNames; + } + } + return *pNames; + } + + // ============================================================================= + // ExtensionMigration + // ============================================================================= + + ExtensionMigration::ExtensionMigration(Reference< XComponentContext > const & ctx) : + m_ctx(ctx) + { + } + + // ----------------------------------------------------------------------------- + + ExtensionMigration::~ExtensionMigration() + { + } + + ::osl::FileBase::RC ExtensionMigration::checkAndCreateDirectory( INetURLObject& rDirURL ) + { + ::osl::FileBase::RC aResult = ::osl::Directory::create( rDirURL.GetMainURL( INetURLObject::DECODE_TO_IURI ) ); + if ( aResult == ::osl::FileBase::E_NOENT ) + { + INetURLObject aBaseURL( rDirURL ); + aBaseURL.removeSegment(); + checkAndCreateDirectory( aBaseURL ); + return ::osl::Directory::create( rDirURL.GetMainURL( INetURLObject::DECODE_TO_IURI ) ); + } + else + { + return aResult; + } + } + + void ExtensionMigration::prepareBasicLibs() + { + prepareBasicLibs(m_sSourceDir + ::rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM("/user/basic/script.xlc")), m_scriptElements); + prepareBasicLibs(m_sSourceDir + ::rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM("/user/basic/dialog.xlc")), m_dialogElements); + } + + void ExtensionMigration::prepareBasicLibs(const ::rtl::OUString & sURL, + ::xmlscript::LibDescriptorArray & out_elements) + { + + ::ucbhelper::Content ucb_content; + if (dp_misc::create_ucb_content( &ucb_content, sURL, + uno::Reference< ucb::XCommandEnvironment>(), false /* no throw */ )) + { + uno::Reference<xml::sax::XParser> xParser( + m_ctx->getServiceManager()->createInstanceWithContext( + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.xml.sax.Parser")), + m_ctx ), UNO_QUERY_THROW ); + + xParser->setDocumentHandler( ::xmlscript::importLibraryContainer( &out_elements ) ); + xml::sax::InputSource source; + source.aInputStream = ucb_content.openStream(); + source.sSystemId = ucb_content.getURL(); + xParser->parseStream( source ); + } + //else + //The file need not exists + } + /* Checks if basic package is enabled in StarOffice 8. This is the case when the dialog.xlc or + the script.xlc in the user installation contains an entry for this package. + The passed package MUST be a basic package. + */ + bool ExtensionMigration::isBasicPackageEnabled( const uno::Reference< deployment::XPackage > & xPkg) + { + ::rtl::OUString sScriptURL = xPkg->getURL(); + if ( sScriptURL[ sScriptURL.getLength()-1 ] != '/' ) + sScriptURL += ::rtl::OUString::createFromAscii("/"); + sScriptURL += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("script.xlb") ); + + bool bEntryFound = false; + for ( sal_Int32 nPos = m_scriptElements.mnLibCount; nPos--; ) + { + ::xmlscript::LibDescriptor const & descr = + m_scriptElements.mpLibs[ nPos ]; + + if (descr.aStorageURL.equals(sScriptURL)) + { + bEntryFound = true; + break; + } + } + + ::rtl::OUString sDialogURL = xPkg->getURL(); + if ( sDialogURL[ sDialogURL.getLength()-1 ] != '/' ) + sDialogURL += ::rtl::OUString::createFromAscii("/"); + sScriptURL += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("dialog.xlb") ); + + if (!bEntryFound) + { + for ( sal_Int32 nPos = m_dialogElements.mnLibCount; nPos--; ) + { + ::xmlscript::LibDescriptor const & descr = + m_dialogElements.mpLibs[ nPos ]; + + if (descr.aStorageURL.equals(sDialogURL)) + { + bEntryFound = true; + break; + } + } + } + return bEntryFound; + } + /* This function only registers basic and dialog packages. + */ + void ExtensionMigration::registerBasicPackage( const uno::Reference< deployment::XPackage > & xPkg) + { + const ::rtl::OUString sMediaType = xPkg->getPackageType()->getMediaType(); + if ( (sMediaType.equals(sBasicType) || sMediaType.equals(sDialogType)) + && isBasicPackageEnabled(xPkg)) + { + xPkg->registerPackage(uno::Reference< task::XAbortChannel >(), + uno::Reference< ucb::XCommandEnvironment> ()); + } + } + + bool ExtensionMigration::processExtensions( const ::rtl::OUString& sSourceDir, const ::rtl::OUString& sTargetDir ) + { + if (!copy(sSourceDir, sTargetDir)) + return false; + + // Find all basic and script packages and reregister them + uno::Reference< deployment::XPackageManagerFactory > xPMF; + if (! ( m_ctx->getValueByName( ::rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM("/singletons/com.sun.star.deployment.thePackageManagerFactory"))) + >>= xPMF)) + throw uno::RuntimeException(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( + "ExtensionsMigration: could not get thePackageManagerFactory")), 0); + + const uno::Reference< deployment::XPackageManager > xPackageMgr = + xPMF->getPackageManager(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("user"))); + + if (!xPackageMgr.is()) + throw uno::RuntimeException(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( + "ExtensionsMigration: could not get XPackageManager")), 0); + + const uno::Sequence< uno::Reference< deployment::XPackage > > allPackages = + xPackageMgr->getDeployedPackages( + uno::Reference< task::XAbortChannel >(), uno::Reference< ucb::XCommandEnvironment> ()); + + for (int i = 0; i < allPackages.getLength(); i ++) + { + const uno::Reference< deployment::XPackage > aPackage = allPackages[i]; + if ( aPackage->isBundle() ) + { + const uno::Sequence< uno::Reference < deployment::XPackage > > seqPkg = + aPackage->getBundle( + uno::Reference< task::XAbortChannel >(), + uno::Reference< ucb::XCommandEnvironment> ()); + + for ( int k = 0; k < seqPkg.getLength(); k++ ) + registerBasicPackage(seqPkg[k]); + + for (int l = 0; l < seqPkg.getLength(); l++) + { + const ::rtl::OUString sMediaType = seqPkg[l]->getPackageType()->getMediaType(); + beans::Optional<beans::Ambiguous<sal_Bool> > opt = + seqPkg[l]->isRegistered(uno::Reference< task::XAbortChannel >(), uno::Reference< ucb::XCommandEnvironment> ()); + bool bRegistered = opt.IsPresent && opt.Value.IsAmbiguous == sal_False && opt.Value.Value == sal_True ? true : false; + + if ( bRegistered && !sMediaType.equals(sBasicType) && !sMediaType.equals(sDialogType) ) + { + seqPkg[l]->revokePackage(uno::Reference< task::XAbortChannel >(), uno::Reference< ucb::XCommandEnvironment> ()); + seqPkg[l]->registerPackage(uno::Reference< task::XAbortChannel >(), uno::Reference< ucb::XCommandEnvironment> ()); + } + } + } + else + { + registerBasicPackage(aPackage); + { + aPackage->revokePackage(uno::Reference< task::XAbortChannel >(), uno::Reference< ucb::XCommandEnvironment> ()); + aPackage->registerPackage(uno::Reference< task::XAbortChannel >(), uno::Reference< ucb::XCommandEnvironment> ()); + } + } + } + + + return true; + + } + +bool ExtensionMigration::isCompatibleBerkleyDb(const ::rtl::OUString& sSourceDir) +{ + try + { + ::rtl::OUString sDb(sSourceDir + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( + "/uno_packages.db"))); + //check if the db exist at all. If not then the call to db_create would create + //the file. + ::osl::File f(sDb); + if (::osl::File::E_None != f.open(OpenFlag_Read)) + { + f.close(); + return false; + } + f.close(); + + //create a system path + ::rtl::OUString sSysPath; + if (::osl::File::getSystemPathFromFileURL(sDb, sSysPath ) != ::osl::File::E_None) + return false; + + ::rtl::OString cstr_sysPath( + ::rtl::OUStringToOString( sSysPath, osl_getThreadTextEncoding() ) ); + char const * pcstr_sysPath = cstr_sysPath.getStr(); + + //Open the db. If it works then we assume that the file was written with a + //compatible version of Berkeley Db + DB* pDB = NULL; + //using DB_RDONLY will return an "Invalid argument" error. + //DB_CREATE: only creates the file if it does not exist. + //An existing db is not modified. + if (0 != db_create(& pDB, 0, DB_CREATE)) + return false; + + if (0 != pDB->open(pDB, 0, pcstr_sysPath , 0, DB_HASH, DB_RDONLY, 0664 /* fs mode */)) + return false; + + pDB->close(pDB, 0); + } + catch (uno::Exception& ) + { + return false; + } + + return true; +} + +bool ExtensionMigration::copy( const ::rtl::OUString& sSourceDir, const ::rtl::OUString& sTargetDir ) +{ + bool bRet = false; + if (! isCompatibleBerkleyDb(sSourceDir)) + return false; + + INetURLObject aSourceObj( sSourceDir ); + INetURLObject aDestObj( sTargetDir ); + String aName = aDestObj.getName(); + aDestObj.removeSegment(); + aDestObj.setFinalSlash(); + + try + { + ::ucbhelper::Content aDestPath( aDestObj.GetMainURL( INetURLObject::NO_DECODE ), uno::Reference< ucb::XCommandEnvironment > () ); + uno::Reference< ucb::XCommandInfo > xInfo = aDestPath.getCommands(); + ::rtl::OUString aTransferName = ::rtl::OUString::createFromAscii( "transfer" ); + if ( xInfo->hasCommandByName( aTransferName ) ) + { + aDestPath.executeCommand( aTransferName, uno::makeAny( + ucb::TransferInfo( sal_False, aSourceObj.GetMainURL( INetURLObject::NO_DECODE ), aName, ucb::NameClash::OVERWRITE ) ) ); + bRet = true; + } + } + catch( uno::Exception& ) + { + } + + return bRet; +} + + + // ----------------------------------------------------------------------------- + // XServiceInfo + // ----------------------------------------------------------------------------- + + ::rtl::OUString ExtensionMigration::getImplementationName() throw (RuntimeException) + { + return ExtensionMigration_getImplementationName(); + } + + // ----------------------------------------------------------------------------- + + sal_Bool ExtensionMigration::supportsService( const ::rtl::OUString& rServiceName ) throw (RuntimeException) + { + Sequence< ::rtl::OUString > aNames( getSupportedServiceNames() ); + const ::rtl::OUString* pNames = aNames.getConstArray(); + const ::rtl::OUString* pEnd = pNames + aNames.getLength(); + for ( ; pNames != pEnd && !pNames->equals( rServiceName ); ++pNames ) + ; + + return pNames != pEnd; + } + + // ----------------------------------------------------------------------------- + + Sequence< ::rtl::OUString > ExtensionMigration::getSupportedServiceNames() throw (RuntimeException) + { + return ExtensionMigration_getSupportedServiceNames(); + } + + // ----------------------------------------------------------------------------- + // XInitialization + // ----------------------------------------------------------------------------- + + void ExtensionMigration::initialize( const Sequence< Any >& aArguments ) throw (Exception, RuntimeException) + { + ::osl::MutexGuard aGuard( m_aMutex ); + + const Any* pIter = aArguments.getConstArray(); + const Any* pEnd = pIter + aArguments.getLength(); + for ( ; pIter != pEnd ; ++pIter ) + { + beans::NamedValue aValue; + *pIter >>= aValue; + if ( aValue.Name.equalsAscii( "UserData" ) ) + { + if ( !(aValue.Value >>= m_sSourceDir) ) + { + OSL_ENSURE( false, "ExtensionMigration::initialize: argument UserData has wrong type!" ); + } + break; + } + } + prepareBasicLibs(); + } + + TStringVectorPtr getContent( const ::rtl::OUString& rBaseURL ) + { + TStringVectorPtr aResult( new TStringVector ); + ::osl::Directory aDir( rBaseURL); + if ( aDir.open() == ::osl::FileBase::E_None ) + { + // iterate over directory content + TStringVector aSubDirs; + ::osl::DirectoryItem aItem; + while ( aDir.getNextItem( aItem ) == ::osl::FileBase::E_None ) + { + ::osl::FileStatus aFileStatus( FileStatusMask_Type | FileStatusMask_FileURL ); + if ( aItem.getFileStatus( aFileStatus ) == ::osl::FileBase::E_None ) + aResult->push_back( aFileStatus.getFileURL() ); + } + } + + return aResult; + } + + // ----------------------------------------------------------------------------- + // XJob + // ----------------------------------------------------------------------------- + +void ExtensionMigration::copyConfig( const ::rtl::OUString& sSourceDir, const ::rtl::OUString& sTargetDir ) +{ + ::rtl::OUString sEx1( m_sSourceDir ); + sEx1 += sExcludeDir1; + ::rtl::OUString sEx2( m_sSourceDir ); + sEx2 += sExcludeDir2; + + TStringVectorPtr aList = getContent( sSourceDir ); + TStringVector::const_iterator aI = aList->begin(); + while ( aI != aList->end() ) + { + ::rtl::OUString sSourceLocalName = aI->copy( sSourceDir.getLength() ); + ::rtl::OUString aTemp = aI->copy( m_sSourceDir.getLength() ); + if ( aTemp != sExcludeDir1 && aTemp != sExcludeDir2 ) + { + ::rtl::OUString sTargetName = sTargetDir + sSourceLocalName; + copy( (*aI), sTargetName ); + } + ++aI; + } +} + + Any ExtensionMigration::execute( const Sequence< beans::NamedValue >& ) + throw (lang::IllegalArgumentException, Exception, RuntimeException) + { + ::osl::MutexGuard aGuard( m_aMutex ); + + ::utl::Bootstrap::PathStatus aStatus = ::utl::Bootstrap::locateUserInstallation( m_sTargetDir ); + if ( aStatus == ::utl::Bootstrap::PATH_EXISTS ) + { + // copy all extensions + ::rtl::OUString sTargetDir(m_sTargetDir), sSourceDir( m_sSourceDir ); + sTargetDir += sExtensionSubDir; + sSourceDir += sExtensionSubDir; + sSourceDir += sSubDirName; + sTargetDir += sSubDirName; + processExtensions( sSourceDir, sTargetDir ); + + // copy all user config settings in user/registry/data (except user/registry/data/org) + sSourceDir = m_sSourceDir; + sSourceDir += sConfigDir; + sTargetDir = m_sTargetDir; + sTargetDir += sConfigDir; + copyConfig( sSourceDir, sTargetDir ); + + // copy all user config settings in user/registry/data/org (except user/registry/data/org/openoffice) + sSourceDir = m_sSourceDir; + sSourceDir += sOrgDir; + sTargetDir = m_sTargetDir; + sTargetDir += sOrgDir; + copyConfig( sSourceDir, sTargetDir ); + } + + return Any(); + } + + // ============================================================================= + // component operations + // ============================================================================= + + Reference< XInterface > SAL_CALL ExtensionMigration_create( + Reference< XComponentContext > const & ctx ) + SAL_THROW( () ) + { + return static_cast< lang::XTypeProvider * >( new ExtensionMigration( + ctx) ); + } + + // ----------------------------------------------------------------------------- + +//......................................................................... +} // namespace migration +//......................................................................... diff --git a/desktop/source/migration/services/extensionmigration.hxx b/desktop/source/migration/services/extensionmigration.hxx new file mode 100755 index 000000000000..70f6a4c44c9b --- /dev/null +++ b/desktop/source/migration/services/extensionmigration.hxx @@ -0,0 +1,130 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _DESKTOP_EXTENSIONMIGRATION_HXX_ +#define _DESKTOP_EXTENSIONMIGRATION_HXX_ + +#include "misc.hxx" +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/task/XJob.hpp> +#include <com/sun/star/lang/XInitialization.hpp> +#include <cppuhelper/implbase3.hxx> +#include <osl/mutex.hxx> +#include <osl/file.hxx> +#include "xmlscript/xmllib_imexp.hxx" + +namespace com { namespace sun { namespace star { + namespace uno { + class XComponentContext; + } + namespace deployment { + class XPackage; + } +}}} + + + +class INetURLObject; + + +//......................................................................... +namespace migration +{ +//......................................................................... + + ::rtl::OUString SAL_CALL ExtensionMigration_getImplementationName(); + ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL ExtensionMigration_getSupportedServiceNames(); + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL ExtensionMigration_create( + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > const & xContext ) + SAL_THROW( (::com::sun::star::uno::Exception) ); + + + // ============================================================================= + // class ExtensionMigration + // ============================================================================= + + typedef ::cppu::WeakImplHelper3< + ::com::sun::star::lang::XServiceInfo, + ::com::sun::star::lang::XInitialization, + ::com::sun::star::task::XJob > ExtensionMigration_BASE; + + class ExtensionMigration : public ExtensionMigration_BASE + { + private: + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > m_ctx; + ::osl::Mutex m_aMutex; + ::rtl::OUString m_sSourceDir; + ::rtl::OUString m_sTargetDir; + + ::xmlscript::LibDescriptorArray m_scriptElements; + ::xmlscript::LibDescriptorArray m_dialogElements; + + ::osl::FileBase::RC checkAndCreateDirectory( INetURLObject& rDirURL ); + void copyConfig( const ::rtl::OUString& sSourceDir, const ::rtl::OUString& sTargetDir ); + bool isCompatibleBerkleyDb(const ::rtl::OUString& sSourceDir); + bool copy( const ::rtl::OUString& sSourceDir, const ::rtl::OUString& sTargetDir ); + bool processExtensions( const ::rtl::OUString& sSourceDir, + const ::rtl::OUString& sTargetDir ); + /* fills m_scriptElements and m_dialogElements + */ + void prepareBasicLibs(); + void prepareBasicLibs(const ::rtl::OUString & sURL, + ::xmlscript::LibDescriptorArray & out_elements); + bool isBasicPackageEnabled( const ::com::sun::star::uno::Reference< + ::com::sun::star::deployment::XPackage > & xPkg); + void registerBasicPackage( + const ::com::sun::star::uno::Reference< ::com::sun::star::deployment::XPackage > & xPkg); + + public: + ExtensionMigration(::com::sun::star::uno::Reference< + ::com::sun::star::uno::XComponentContext > const & ctx); + virtual ~ExtensionMigration(); + + // XServiceInfo + virtual ::rtl::OUString SAL_CALL getImplementationName() + throw (::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& rServiceName ) + throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() + throw (::com::sun::star::uno::RuntimeException); + + // XInitialization + virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) + throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); + + // XJob + virtual ::com::sun::star::uno::Any SAL_CALL execute( + const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& Arguments ) + throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::Exception, + ::com::sun::star::uno::RuntimeException); + }; + +//......................................................................... +} // namespace migration +//......................................................................... + +#endif // _DESKTOP_AUTOCORRMIGRATION_HXX_ diff --git a/desktop/source/migration/services/jvmfwk.cxx b/desktop/source/migration/services/jvmfwk.cxx new file mode 100644 index 000000000000..381b6cb378c1 --- /dev/null +++ b/desktop/source/migration/services/jvmfwk.cxx @@ -0,0 +1,529 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_desktop.hxx" + +#include "cppuhelper/implbase4.hxx" +#include "cppuhelper/implementationentry.hxx" +#include "rtl/ustrbuf.hxx" +#include "rtl/ustring.h" +#include "rtl/ustring.hxx" +#include "rtl/bootstrap.hxx" +#include "sal/types.h" +#include "sal/config.h" +#include "boost/scoped_array.hpp" +#include "com/sun/star/lang/XServiceInfo.hpp" +#include "com/sun/star/lang/XInitialization.hpp" +#include "com/sun/star/lang/WrappedTargetException.hpp" +#include "com/sun/star/task/XJob.hpp" +#include "com/sun/star/configuration/backend/XLayer.hpp" +#include "com/sun/star/configuration/backend/XLayerHandler.hpp" +#include "com/sun/star/configuration/backend/MalformedDataException.hpp" +#include "com/sun/star/configuration/backend/TemplateIdentifier.hpp" +#include "jvmfwk/framework.h" +#include "jvmfwk.hxx" +#include <stack> +#include <stdio.h> + +#include "osl/thread.hxx" +#define OUSTR(x) rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( x )) + +#define SERVICE_NAME "com.sun.star.migration.Java" +#define IMPL_NAME "com.sun.star.comp.desktop.migration.Java" + +#define ENABLE_JAVA 1 +#define USER_CLASS_PATH 2 + +namespace css = com::sun::star; +using namespace rtl; +using namespace com::sun::star::uno; +using namespace com::sun::star::beans; +using namespace com::sun::star::lang; +using namespace com::sun::star::configuration::backend; + +namespace migration +{ + +class CJavaInfo +{ + CJavaInfo(const CJavaInfo&); + CJavaInfo& operator = (const CJavaInfo&); +public: + JavaInfo* pData; + CJavaInfo(); + ~CJavaInfo(); + operator JavaInfo* (); +}; + +CJavaInfo::CJavaInfo(): pData(NULL) +{ +} + +CJavaInfo::~CJavaInfo() +{ + jfw_freeJavaInfo(pData); +} + +CJavaInfo::operator JavaInfo*() +{ + return pData; +} + + +class JavaMigration : public ::cppu::WeakImplHelper4< + css::lang::XServiceInfo, + css::lang::XInitialization, + css::task::XJob, + css::configuration::backend::XLayerHandler> +{ +public: + // XServiceInfo + virtual OUString SAL_CALL getImplementationName() + throw (css::uno::RuntimeException); + virtual sal_Bool SAL_CALL supportsService( const OUString & rServiceName ) + throw (css::uno::RuntimeException); + virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() + throw (css::uno::RuntimeException); + + //XInitialization + virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) + throw(css::uno::Exception, css::uno::RuntimeException); + + //XJob + virtual css::uno::Any SAL_CALL execute( + const css::uno::Sequence<css::beans::NamedValue >& Arguments ) + throw (css::lang::IllegalArgumentException, css::uno::Exception, + css::uno::RuntimeException); + + // XLayerHandler + virtual void SAL_CALL startLayer() + throw(::com::sun::star::lang::WrappedTargetException); + + virtual void SAL_CALL endLayer() + throw( + ::com::sun::star::configuration::backend::MalformedDataException, + ::com::sun::star::lang::WrappedTargetException ); + + virtual void SAL_CALL overrideNode( + const rtl::OUString& aName, + sal_Int16 aAttributes, + sal_Bool bClear) + throw( + ::com::sun::star::configuration::backend::MalformedDataException, + ::com::sun::star::lang::WrappedTargetException ); + + virtual void SAL_CALL addOrReplaceNode( + const rtl::OUString& aName, + sal_Int16 aAttributes) + throw( + ::com::sun::star::configuration::backend::MalformedDataException, + ::com::sun::star::lang::WrappedTargetException ); + + virtual void SAL_CALL addOrReplaceNodeFromTemplate( + const rtl::OUString& aName, + const ::com::sun::star::configuration::backend::TemplateIdentifier& aTemplate, + sal_Int16 aAttributes ) + throw( + ::com::sun::star::configuration::backend::MalformedDataException, + ::com::sun::star::lang::WrappedTargetException ); + + virtual void SAL_CALL endNode() + throw( + ::com::sun::star::configuration::backend::MalformedDataException, + ::com::sun::star::lang::WrappedTargetException ); + + virtual void SAL_CALL dropNode( + const rtl::OUString& aName ) + throw( + ::com::sun::star::configuration::backend::MalformedDataException, + ::com::sun::star::lang::WrappedTargetException ); + + virtual void SAL_CALL overrideProperty( + const rtl::OUString& aName, + sal_Int16 aAttributes, + const css::uno::Type& aType, + sal_Bool bClear ) + throw( + ::com::sun::star::configuration::backend::MalformedDataException, + ::com::sun::star::lang::WrappedTargetException ); + + virtual void SAL_CALL setPropertyValue( + const css::uno::Any& aValue ) + throw( + ::com::sun::star::configuration::backend::MalformedDataException, + ::com::sun::star::lang::WrappedTargetException ); + + virtual void SAL_CALL setPropertyValueForLocale( + const css::uno::Any& aValue, + const rtl::OUString& aLocale ) + throw( + ::com::sun::star::configuration::backend::MalformedDataException, + ::com::sun::star::lang::WrappedTargetException ); + + virtual void SAL_CALL endProperty() + throw( + ::com::sun::star::configuration::backend::MalformedDataException, + ::com::sun::star::lang::WrappedTargetException ); + + virtual void SAL_CALL addProperty( + const rtl::OUString& aName, + sal_Int16 aAttributes, + const css::uno::Type& aType ) + throw( + ::com::sun::star::configuration::backend::MalformedDataException, + ::com::sun::star::lang::WrappedTargetException ); + + virtual void SAL_CALL addPropertyWithValue( + const rtl::OUString& aName, + sal_Int16 aAttributes, + const css::uno::Any& aValue ) + throw( + ::com::sun::star::configuration::backend::MalformedDataException, + ::com::sun::star::lang::WrappedTargetException ); + + + + //---------------- + ~JavaMigration(); + +private: + OUString m_sUserDir; + css::uno::Reference< ::css::configuration::backend::XLayer> m_xLayer; + + void migrateJavarc(); + typedef ::std::pair< ::rtl::OUString, sal_Int16> TElementType; + typedef ::std::stack< TElementType > TElementStack; + TElementStack m_aStack; + +}; + +JavaMigration::~JavaMigration() +{ + OSL_ASSERT(m_aStack.empty()); +} + +OUString jvmfwk_getImplementationName() +{ + return OUSTR(IMPL_NAME); +} + +css::uno::Sequence< OUString > jvmfwk_getSupportedServiceNames() +{ + OUString str_name = OUSTR(SERVICE_NAME); + return css::uno::Sequence< OUString >( &str_name, 1 ); +} + +// XServiceInfo +OUString SAL_CALL JavaMigration::getImplementationName() + throw (css::uno::RuntimeException) +{ + return jvmfwk_getImplementationName(); +} + +sal_Bool SAL_CALL JavaMigration::supportsService( const OUString & rServiceName ) + throw (css::uno::RuntimeException) +{ + css::uno::Sequence< OUString > const & rSNL = getSupportedServiceNames(); + OUString const * pArray = rSNL.getConstArray(); + for ( sal_Int32 nPos = rSNL.getLength(); nPos--; ) + { + if (rServiceName.equals( pArray[ nPos ] )) + return true; + } + return false; + +} + +css::uno::Sequence< OUString > SAL_CALL JavaMigration::getSupportedServiceNames() + throw (css::uno::RuntimeException) +{ + return jvmfwk_getSupportedServiceNames(); +} + +//XInitialization ---------------------------------------------------------------------- +void SAL_CALL JavaMigration::initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) + throw(css::uno::Exception, css::uno::RuntimeException) +{ + const css::uno::Any* pIter = aArguments.getConstArray(); + const css::uno::Any* pEnd = pIter + aArguments.getLength(); + css::uno::Sequence<css::beans::NamedValue> aOldConfigValues; + css::beans::NamedValue aValue; + for(;pIter != pEnd;++pIter) + { + *pIter >>= aValue; + if (aValue.Name.equalsAscii("OldConfiguration")) + { + sal_Bool bSuccess = aValue.Value >>= aOldConfigValues; + OSL_ENSURE(bSuccess == sal_True, "[Service implementation " IMPL_NAME + "] XInitialization::initialize: Argument OldConfiguration has wrong type."); + if (bSuccess) + { + const css::beans::NamedValue* pIter2 = aOldConfigValues.getConstArray(); + const css::beans::NamedValue* pEnd2 = pIter2 + aOldConfigValues.getLength(); + for(;pIter2 != pEnd2;++pIter2) + { + if ( pIter2->Name.equalsAscii("org.openoffice.Office.Java") ) + { + pIter2->Value >>= m_xLayer; + break; + } + } + } + } + else if (aValue.Name.equalsAscii("UserData")) + { + if ( !(aValue.Value >>= m_sUserDir) ) + { + OSL_ENSURE( + false, + "[Service implementation " IMPL_NAME + "] XInitialization::initialize: Argument UserData has wrong type."); + } + } + } + +} + +//XJob +css::uno::Any SAL_CALL JavaMigration::execute( + const css::uno::Sequence<css::beans::NamedValue >& ) + throw (css::lang::IllegalArgumentException, css::uno::Exception, + css::uno::RuntimeException) +{ + migrateJavarc(); + if (m_xLayer.is()) + m_xLayer->readData(this); + + return css::uno::Any(); +} + +void JavaMigration::migrateJavarc() +{ + if (m_sUserDir.getLength() == 0) + return; + + OUString sValue; + rtl::Bootstrap javaini(m_sUserDir + OUSTR("/user/config/"SAL_CONFIGFILE("java"))); + sal_Bool bSuccess = javaini.getFrom(OUSTR("Home"), sValue); + OSL_ENSURE(bSuccess, "[Service implementation " IMPL_NAME + "] XJob::execute: Could not get Home entry from java.ini/javarc."); + if (bSuccess == sal_True && sValue.getLength() > 0) + { + //get the directory + CJavaInfo aInfo; + javaFrameworkError err = jfw_getJavaInfoByPath(sValue.pData, &aInfo.pData); + + if (err == JFW_E_NONE) + { + if (jfw_setSelectedJRE(aInfo) != JFW_E_NONE) + { + OSL_ENSURE(0, "[Service implementation " IMPL_NAME + "] XJob::execute: jfw_setSelectedJRE failed."); + fprintf(stderr, "\nCannot migrate Java. An error occured.\n"); + } + } + else if (err == JFW_E_FAILED_VERSION) + { + fprintf(stderr, "\nCannot migrate Java settings because the version of the Java " + "is not supported anymore.\n"); + } + } +} + + +// XLayerHandler +void SAL_CALL JavaMigration::startLayer() + throw(css::lang::WrappedTargetException) +{ +} +// ----------------------------------------------------------------------------- + +void SAL_CALL JavaMigration::endLayer() + throw( + MalformedDataException, + WrappedTargetException ) +{ +} +// ----------------------------------------------------------------------------- + +void SAL_CALL JavaMigration::overrideNode( + const ::rtl::OUString&, + sal_Int16, + sal_Bool) + throw( + MalformedDataException, + WrappedTargetException ) + +{ + +} +// ----------------------------------------------------------------------------- + +void SAL_CALL JavaMigration::addOrReplaceNode( + const ::rtl::OUString&, + sal_Int16) + throw( + MalformedDataException, + WrappedTargetException ) +{ + +} +void SAL_CALL JavaMigration::endNode() + throw( + MalformedDataException, + WrappedTargetException ) +{ +} +// ----------------------------------------------------------------------------- + +void SAL_CALL JavaMigration::dropNode( + const ::rtl::OUString& ) + throw( + MalformedDataException, + WrappedTargetException ) +{ +} +// ----------------------------------------------------------------------------- + +void SAL_CALL JavaMigration::overrideProperty( + const ::rtl::OUString& aName, + sal_Int16, + const Type&, + sal_Bool ) + throw( + MalformedDataException, + WrappedTargetException ) +{ + if (aName.equalsAscii("Enable")) + m_aStack.push(TElementStack::value_type(aName,ENABLE_JAVA)); + else if (aName.equalsAscii("UserClassPath")) + m_aStack.push(TElementStack::value_type(aName, USER_CLASS_PATH)); +} +// ----------------------------------------------------------------------------- + +void SAL_CALL JavaMigration::setPropertyValue( + const Any& aValue ) + throw( + MalformedDataException, + WrappedTargetException ) +{ + if ( !m_aStack.empty()) + { + switch (m_aStack.top().second) + { + case ENABLE_JAVA: + { + sal_Bool val = sal_Bool(); + if ((aValue >>= val) == sal_False) + throw MalformedDataException( + OUSTR("[Service implementation " IMPL_NAME + "] XLayerHandler::setPropertyValue received wrong type for Enable property"), 0, Any()); + if (jfw_setEnabled(val) != JFW_E_NONE) + throw WrappedTargetException( + OUSTR("[Service implementation " IMPL_NAME + "] XLayerHandler::setPropertyValue: jfw_setEnabled failed."), 0, Any()); + + break; + } + case USER_CLASS_PATH: + { + OUString cp; + if ((aValue >>= cp) == sal_False) + throw MalformedDataException( + OUSTR("[Service implementation " IMPL_NAME + "] XLayerHandler::setPropertyValue received wrong type for UserClassPath property"), 0, Any()); + + if (jfw_setUserClassPath(cp.pData) != JFW_E_NONE) + throw WrappedTargetException( + OUSTR("[Service implementation " IMPL_NAME + "] XLayerHandler::setPropertyValue: jfw_setUserClassPath failed."), 0, Any()); + break; + } + default: + OSL_ASSERT(0); + } + } +} +// ----------------------------------------------------------------------------- + +void SAL_CALL JavaMigration::setPropertyValueForLocale( + const Any&, + const ::rtl::OUString& ) + throw( + MalformedDataException, + WrappedTargetException ) +{ +} +// ----------------------------------------------------------------------------- + +void SAL_CALL JavaMigration::endProperty() + throw( + MalformedDataException, + WrappedTargetException ) +{ + if (!m_aStack.empty()) + m_aStack.pop(); +} +// ----------------------------------------------------------------------------- + +void SAL_CALL JavaMigration::addProperty( + const rtl::OUString&, + sal_Int16, + const Type& ) + throw( + MalformedDataException, + WrappedTargetException ) +{ +} +// ----------------------------------------------------------------------------- + +void SAL_CALL JavaMigration::addPropertyWithValue( + const rtl::OUString&, + sal_Int16, + const Any& ) + throw( + MalformedDataException, + WrappedTargetException ) +{ +} + +void SAL_CALL JavaMigration::addOrReplaceNodeFromTemplate( + const rtl::OUString&, + const TemplateIdentifier&, + sal_Int16 ) + throw( + MalformedDataException, + WrappedTargetException ) +{ +} + +// ----------------------------------------------------------------------------- +//ToDo enable java, user class path + +} //end namespace jfw + diff --git a/desktop/source/migration/services/jvmfwk.hxx b/desktop/source/migration/services/jvmfwk.hxx new file mode 100644 index 000000000000..a79d36b8b86b --- /dev/null +++ b/desktop/source/migration/services/jvmfwk.hxx @@ -0,0 +1,50 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "cppuhelper/implbase3.hxx" +#include "cppuhelper/implementationentry.hxx" +#include "rtl/ustrbuf.hxx" +#include "rtl/ustring.h" +#include "rtl/ustring.hxx" +#include "sal/types.h" +#include "boost/scoped_array.hpp" +#include "com/sun/star/lang/XServiceInfo.hpp" +#include "com/sun/star/lang/XInitialization.hpp" +#include "com/sun/star/task/XJob.hpp" + + +namespace css = com::sun::star; + +namespace migration +{ + +rtl::OUString jvmfwk_getImplementationName(); + +css::uno::Sequence< rtl::OUString > jvmfwk_getSupportedServiceNames(); + +} //end blind namespace + diff --git a/desktop/source/migration/services/makefile.mk b/desktop/source/migration/services/makefile.mk new file mode 100644 index 000000000000..64adfe70b7b2 --- /dev/null +++ b/desktop/source/migration/services/makefile.mk @@ -0,0 +1,121 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=..$/..$/.. + +PRJNAME=desktop +TARGET = migrationoo2.uno +ENABLE_EXCEPTIONS=TRUE +COMP1TYPELIST = migrationoo2 +LIBTARGET=NO + +# --- Settings ----------------------------------------------------- +.INCLUDE : ..$/..$/deployment/inc/dp_misc.mk +.INCLUDE : settings.mk +DLLPRE = + +# ------------------------------------------------------------------ + +.INCLUDE : cppumaker.mk + +.IF "$(SYSTEM_DB)" == "YES" +CFLAGS+=-DSYSTEM_DB -I$(DB_INCLUDES) +.ENDIF + +SLOFILES= \ + $(SLO)$/jvmfwk.obj \ + $(SLO)$/cexports.obj \ + $(SLO)$/basicmigration.obj \ + $(SLO)$/wordbookmigration.obj \ + $(SLO)$/extensionmigration.obj \ + $(SLO)$/autocorrmigration.obj \ + $(SLO)$/oo3extensionmigration.obj \ + $(SLO)$/cexportsoo3.obj + +SHL1OBJS= \ + $(SLO)$/jvmfwk.obj \ + $(SLO)$/cexports.obj \ + $(SLO)$/basicmigration.obj \ + $(SLO)$/wordbookmigration.obj \ + $(SLO)$/extensionmigration.obj \ + $(SLO)$/autocorrmigration.obj + +SHL1TARGET=$(TARGET) +SHL1VERSIONMAP = migrationoo2.map + +SHL1STDLIBS= \ + $(DEPLOYMENTMISCLIB) \ + $(CPPULIB) \ + $(CPPUHELPERLIB) \ + $(SALLIB) \ + $(UCBHELPERLIB) \ + $(UNOTOOLSLIB) \ + $(TOOLSLIB) \ + $(I18NISOLANGLIB) \ + $(JVMFWKLIB) \ + $(XMLSCRIPTLIB) \ + $(BERKELEYLIB) + +SHL1DEPN= +SHL1IMPLIB=imigrationoo2 +#SHL1LIBS=$(SLB)$/$(TARGET).lib +SHL1DEF=$(MISC)$/$(SHL1TARGET).def + +DEF1NAME=$(SHL1TARGET) + +COMP2TYPELIST = migrationoo3 +SHL2TARGET=migrationoo3.uno +SHL2VERSIONMAP = migrationoo3.map + +SHL2OBJS= \ + $(SLO)$/cexportsoo3.obj \ + $(SLO)$/oo3extensionmigration.obj + +SHL2STDLIBS= \ + $(DEPLOYMENTMISCLIB) \ + $(CPPULIB) \ + $(CPPUHELPERLIB) \ + $(SALLIB) \ + $(UCBHELPERLIB) \ + $(UNOTOOLSLIB) \ + $(TOOLSLIB) \ + $(I18NISOLANGLIB) \ + $(JVMFWKLIB) \ + $(XMLSCRIPTLIB) \ + $(BERKELEYLIB) + +SHL2DEPN= +SHL2IMPLIB=imigrationoo3 +#SHL2LIBS=$(SLB)$/$(SHL2TARGET).lib +SHL2DEF=$(MISC)$/$(SHL2TARGET).def + +DEF2NAME=$(SHL2TARGET) + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk + diff --git a/desktop/source/migration/services/migrationoo2.map b/desktop/source/migration/services/migrationoo2.map new file mode 100644 index 000000000000..ac2c3750bfe0 --- /dev/null +++ b/desktop/source/migration/services/migrationoo2.map @@ -0,0 +1,8 @@ +UDK_3_0_0 { + global: + component_getImplementationEnvironment; + component_writeInfo; + component_getFactory; + local: + *; +}; diff --git a/desktop/source/migration/services/migrationoo2.xml b/desktop/source/migration/services/migrationoo2.xml new file mode 100644 index 000000000000..5bda732f0fba --- /dev/null +++ b/desktop/source/migration/services/migrationoo2.xml @@ -0,0 +1,78 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE module-description PUBLIC "-//StarOffice//DTD ComponentDescription 1.0//EN" "module-description.dtd"> +<module-description xmlns:xlink="http://www.w3.org/1999/xlink"> + <module-name> migrationoo2.uno </module-name> + <component-description> + <author> Joachim Lingner </author> + <name> com.sun.star.comp.jvmfwk.MigrationOO2</name> + <description> +Specifies a factory object to create proxy objects. +These proxy object represent a given target object and can be +be aggregated. The proxy objects act UNO conform and do NOT provide +original target interfaces on queryInterface() calls. +</description> + <loader-name> com.sun.star.loader.SharedLibrary </loader-name> + <language> C++ </language> + <status value="final"/> + <supported-service> com.sun.star.reflection.ProxyFactory </supported-service> + <service-dependency> ... </service-dependency> + <type> com.sun.star.lang.XTypeProvider </type> + <type> com.sun.star.lang.XServiceInfo </type> + <type> com.sun.star.lang.XSingleServiceFactory </type> + <type> com.sun.star.lang.XMultiServiceFactory </type> + <type> com.sun.star.lang.XInitialization </type> + <type> com.sun.star.lang.WrappedTargetException </type> + <type> com.sun.star.registry.XRegistryKey </type> + <type> com.sun.star.lang.XSingleComponentFactory </type> + <type> com.sun.star.task.XJob </type> + <type> com.sun.star.beans.NamedValue </type> + <type> com.sun.star.configuration.backend.XLayer </type> + <type> com.sun.star.configuration.backend.XLayerHandler </type> + <type> com.sun.star.configuration.backend.MalformedDataException </type> + <type> com.sun.star.configuration.backend.TemplateIdentifier </type> + </component-description> + <component-description> + <author>Thomas Benisch</author> + <name>com.sun.star.comp.desktop.migration.Basic</name> + <description>migration service for OpenOffice.org Basic and dialogs</description> + <loader-name>com.sun.star.loader.SharedLibrary</loader-name> + <language>c++</language> + <status value="final"/> + <supported-service>com.sun.star.migration.Basic</supported-service> + <service-dependency>...</service-dependency> + <type>com.sun.star.beans.NamedValue</type> + <type>com.sun.star.lang.IllegalArgumentException</type> + <type>com.sun.star.lang.XInitialization</type> + <type>com.sun.star.task.XJob</type> + <type>com.sun.star.lang.XServiceInfo</type> + <type>com.sun.star.lang.XTypeProvider</type> + <type>com.sun.star.uno.XComponentContext</type> + </component-description> + <component-description> + <author>Thomas Benisch</author> + <name>com.sun.star.comp.desktop.migration.Autocorrection</name> + <description>migration service for OpenOffice.org autocorrection</description> + <loader-name>com.sun.star.loader.SharedLibrary</loader-name> + <language>c++</language> + <status value="final"/> + <supported-service>com.sun.star.migration.Autocorrection</supported-service> + <service-dependency>...</service-dependency> + <type>com.sun.star.beans.NamedValue</type> + <type>com.sun.star.lang.IllegalArgumentException</type> + <type>com.sun.star.lang.XInitialization</type> + <type>com.sun.star.task.XJob</type> + <type>com.sun.star.lang.XServiceInfo</type> + <type>com.sun.star.lang.XTypeProvider</type> + <type>com.sun.star.uno.XComponentContext</type> + </component-description> + <project-build-dependency>unotools</project-build-dependency> + <project-build-dependency>tools</project-build-dependency> + <project-build-dependency>cppuhelper</project-build-dependency> + <project-build-dependency>cppu</project-build-dependency> + <project-build-dependency>sal</project-build-dependency> + <runtime-module-dependency>utl</runtime-module-dependency> + <runtime-module-dependency>tl</runtime-module-dependency> + <runtime-module-dependency>cppuhelper3$(COM)</runtime-module-dependency> + <runtime-module-dependency>cppu3</runtime-module-dependency> + <runtime-module-dependency>sal3</runtime-module-dependency> +</module-description> diff --git a/desktop/source/migration/services/migrationoo3.map b/desktop/source/migration/services/migrationoo3.map new file mode 100755 index 000000000000..ac2c3750bfe0 --- /dev/null +++ b/desktop/source/migration/services/migrationoo3.map @@ -0,0 +1,8 @@ +UDK_3_0_0 { + global: + component_getImplementationEnvironment; + component_writeInfo; + component_getFactory; + local: + *; +}; diff --git a/desktop/source/migration/services/misc.hxx b/desktop/source/migration/services/misc.hxx new file mode 100644 index 000000000000..8bab95c09a57 --- /dev/null +++ b/desktop/source/migration/services/misc.hxx @@ -0,0 +1,48 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _DESKTOP_MISC_HXX_ +#define _DESKTOP_MISC_HXX_ + +#include <rtl/ustring.hxx> + +#include <vector> +#include <memory> + +//......................................................................... +namespace migration +{ +//......................................................................... + + typedef ::std::vector< ::rtl::OUString > TStringVector; + typedef ::std::auto_ptr< TStringVector > TStringVectorPtr; + +//......................................................................... +} // namespace migration +//......................................................................... + +#endif // _DESKTOP_MISC_HXX_ diff --git a/desktop/source/migration/services/oo3extensionmigration.cxx b/desktop/source/migration/services/oo3extensionmigration.cxx new file mode 100755 index 000000000000..11bf8129cc04 --- /dev/null +++ b/desktop/source/migration/services/oo3extensionmigration.cxx @@ -0,0 +1,656 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: extensionmigration.cxx,v $ + * $Revision: 1.2 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_desktop.hxx" + +#include "oo3extensionmigration.hxx" +#include <rtl/instance.hxx> +#include <osl/file.hxx> +#include <osl/thread.h> +#include <tools/urlobj.hxx> +#include <unotools/bootstrap.hxx> +#include <unotools/ucbstreamhelper.hxx> +#include <unotools/textsearch.hxx> +#include <comphelper/sequence.hxx> +#include <comphelper/processfactory.hxx> +#include <ucbhelper/content.hxx> + +#include <com/sun/star/deployment/thePackageManagerFactory.hpp> +#include <com/sun/star/deployment/XPackageManagerFactory.hpp> +#include <com/sun/star/task/XInteractionApprove.hpp> +#include <com/sun/star/task/XInteractionAbort.hpp> +#include <com/sun/star/ucb/XCommandInfo.hpp> +#include <com/sun/star/ucb/TransferInfo.hpp> +#include <com/sun/star/ucb/NameClash.hpp> +#include <com/sun/star/ucb/XCommandEnvironment.hpp> +#include <com/sun/star/xml/xpath/XXPathAPI.hpp> + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; + +namespace migration +{ + +static ::rtl::OUString sExtensionSubDir = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/user/uno_packages/" ) ); +static ::rtl::OUString sSubDirName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "cache" ) ); +static ::rtl::OUString sConfigDir = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/user/registry/data" ) ); +static ::rtl::OUString sOrgDir = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/user/registry/data/org" ) ); +static ::rtl::OUString sExcludeDir1 = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/user/registry/data/org" ) ); +static ::rtl::OUString sExcludeDir2 = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/user/registry/data/org/openoffice" ) ); +static ::rtl::OUString sDescriptionXmlFile = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/description.xml" ) ); +static ::rtl::OUString sExtensionRootSubDirName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/uno_packages" ) ); + +static ::rtl::OUString sConfigurationDataType = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("application/vnd.sun.star.configuration-data")); +static ::rtl::OUString sConfigurationSchemaType = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("application/vnd.sun.star.configuration-schema")); + +// ============================================================================= +// component operations +// ============================================================================= + +::rtl::OUString OO3ExtensionMigration_getImplementationName() +{ + static ::rtl::OUString* pImplName = 0; + if ( !pImplName ) + { + ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); + if ( !pImplName ) + { + static ::rtl::OUString aImplName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.desktop.migration.OOo3Extensions" ) ); + pImplName = &aImplName; + } + } + return *pImplName; +} + +// ----------------------------------------------------------------------------- + +Sequence< ::rtl::OUString > OO3ExtensionMigration_getSupportedServiceNames() +{ + static Sequence< ::rtl::OUString >* pNames = 0; + if ( !pNames ) + { + ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); + if ( !pNames ) + { + static Sequence< ::rtl::OUString > aNames(1); + aNames.getArray()[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.migration.Extensions" ) ); + pNames = &aNames; + } + } + return *pNames; +} + +// ============================================================================= +// ExtensionMigration +// ============================================================================= + +OO3ExtensionMigration::OO3ExtensionMigration(Reference< XComponentContext > const & ctx) : +m_ctx(ctx) +{ +} + +// ----------------------------------------------------------------------------- + +OO3ExtensionMigration::~OO3ExtensionMigration() +{ +} + +::osl::FileBase::RC OO3ExtensionMigration::checkAndCreateDirectory( INetURLObject& rDirURL ) +{ + ::osl::FileBase::RC aResult = ::osl::Directory::create( rDirURL.GetMainURL( INetURLObject::DECODE_TO_IURI ) ); + if ( aResult == ::osl::FileBase::E_NOENT ) + { + INetURLObject aBaseURL( rDirURL ); + aBaseURL.removeSegment(); + checkAndCreateDirectory( aBaseURL ); + return ::osl::Directory::create( rDirURL.GetMainURL( INetURLObject::DECODE_TO_IURI ) ); + } + else + { + return aResult; + } +} + +void OO3ExtensionMigration::registerConfigurationPackage( const uno::Reference< deployment::XPackage > & xPkg) +{ + const ::rtl::OUString sMediaType = xPkg->getPackageType()->getMediaType(); + if ( (sMediaType.equals(sConfigurationDataType) || sMediaType.equals(sConfigurationSchemaType) ) ) + { + xPkg->revokePackage(uno::Reference< task::XAbortChannel >(), uno::Reference< ucb::XCommandEnvironment> ()); + xPkg->registerPackage(uno::Reference< task::XAbortChannel >(), uno::Reference< ucb::XCommandEnvironment> ()); + } +} + + void OO3ExtensionMigration::scanUserExtensions( const ::rtl::OUString& sSourceDir, TStringVector& aMigrateExtensions ) +{ + osl::Directory aScanRootDir( sSourceDir ); + osl::FileStatus fs(FileStatusMask_Type | FileStatusMask_FileURL); + osl::FileBase::RC nRetCode = aScanRootDir.open(); + if ( nRetCode == osl::Directory::E_None ) + { + sal_uInt32 nHint( 0 ); + osl::DirectoryItem aItem; + while ( aScanRootDir.getNextItem( aItem, nHint ) == osl::Directory::E_None ) + { + if (( aItem.getFileStatus(fs) == osl::FileBase::E_None ) && + ( fs.getFileType() == osl::FileStatus::Directory )) + { + //Check next folder as the "real" extension folder is below a temp folder! + ::rtl::OUString sExtensionFolderURL = fs.getFileURL(); + + osl::DirectoryItem aExtDirItem; + osl::Directory aExtensionRootDir( sExtensionFolderURL ); + + nRetCode = aExtensionRootDir.open(); + if (( nRetCode == osl::Directory::E_None ) && + ( aExtensionRootDir.getNextItem( aExtDirItem, nHint ) == osl::Directory::E_None )) + { + bool bFileStatus = aExtDirItem.getFileStatus(fs) == osl::FileBase::E_None; + bool bIsDir = fs.getFileType() == osl::FileStatus::Directory; + + if ( bFileStatus && bIsDir ) + { + sExtensionFolderURL = fs.getFileURL(); + ScanResult eResult = scanExtensionFolder( sExtensionFolderURL ); + if ( eResult == SCANRESULT_MIGRATE_EXTENSION ) + aMigrateExtensions.push_back( sExtensionFolderURL ); + } + } + } + } + } +} + +OO3ExtensionMigration::ScanResult OO3ExtensionMigration::scanExtensionFolder( const ::rtl::OUString& sExtFolder ) +{ + ScanResult aResult = SCANRESULT_NOTFOUND; + osl::Directory aDir(sExtFolder); + + // get sub dirs + if (aDir.open() == osl::FileBase::E_None) + { + // work through directory contents... + osl::DirectoryItem item; + osl::FileStatus fs(FileStatusMask_Type | FileStatusMask_FileURL); + TStringVector aDirectories; + while ((aDir.getNextItem(item) == osl::FileBase::E_None ) && + ( aResult == SCANRESULT_NOTFOUND )) + { + if (item.getFileStatus(fs) == osl::FileBase::E_None) + { + ::rtl::OUString aDirEntryURL; + if (fs.getFileType() == osl::FileStatus::Directory) + aDirectories.push_back( fs.getFileURL() ); + else + { + aDirEntryURL = fs.getFileURL(); + if ( aDirEntryURL.indexOf( sDescriptionXmlFile ) > 0 ) + aResult = scanDescriptionXml( aDirEntryURL ) ? SCANRESULT_MIGRATE_EXTENSION : SCANRESULT_DONTMIGRATE_EXTENSION; + } + } + } + + TStringVector::const_iterator pIter = aDirectories.begin(); + while ( pIter != aDirectories.end() && aResult == SCANRESULT_NOTFOUND ) + { + aResult = scanExtensionFolder( *pIter ); + ++pIter; + } + } + return aResult; +} + +bool OO3ExtensionMigration::scanDescriptionXml( const ::rtl::OUString& sDescriptionXmlURL ) +{ + if ( !m_xDocBuilder.is() ) + { + m_xDocBuilder = uno::Reference< xml::dom::XDocumentBuilder >( + m_ctx->getServiceManager()->createInstanceWithContext( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.xml.dom.DocumentBuilder")), + m_ctx ), uno::UNO_QUERY ); + } + + if ( !m_xSimpleFileAccess.is() ) + { + m_xSimpleFileAccess = uno::Reference< ucb::XSimpleFileAccess >( + m_ctx->getServiceManager()->createInstanceWithContext( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.ucb.SimpleFileAccess")), + m_ctx ), uno::UNO_QUERY ); + } + + ::rtl::OUString aExtIdentifier; + if ( m_xDocBuilder.is() && m_xSimpleFileAccess.is() ) + { + try + { + uno::Reference< io::XInputStream > xIn = + m_xSimpleFileAccess->openFileRead( sDescriptionXmlURL ); + + if ( xIn.is() ) + { + uno::Reference< xml::dom::XDocument > xDoc = m_xDocBuilder->parse( xIn ); + if ( xDoc.is() ) + { + uno::Reference< xml::dom::XElement > xRoot = xDoc->getDocumentElement(); + if ( xRoot.is() && + xRoot->getTagName().equals(::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("description"))) ) + { + uno::Reference< xml::xpath::XXPathAPI > xPath( + m_ctx->getServiceManager()->createInstanceWithContext( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.xml.xpath.XPathAPI")), + m_ctx), + uno::UNO_QUERY); + + xPath->registerNS( + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("desc")), + xRoot->getNamespaceURI()); + xPath->registerNS( + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("xlink")), + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("http://www.w3.org/1999/xlink"))); + + try + { + uno::Reference< xml::dom::XNode > xRootNode( xRoot, uno::UNO_QUERY ); + uno::Reference< xml::dom::XNode > xNode( + xPath->selectSingleNode( + xRootNode, + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("desc:identifier/@value")) )); + if ( xNode.is() ) + aExtIdentifier = xNode->getNodeValue(); + } + catch ( xml::xpath::XPathException& ) + { + } + catch ( xml::dom::DOMException& ) + { + } + } + } + } + + if ( aExtIdentifier.getLength() > 0 ) + { + // scan extension identifier and try to match with our black list entries + for ( sal_uInt32 i = 0; i < m_aBlackList.size(); i++ ) + { + utl::SearchParam param(m_aBlackList[i], utl::SearchParam::SRCH_REGEXP); + utl::TextSearch ts(param, LANGUAGE_DONTKNOW); + + xub_StrLen start = 0; + xub_StrLen end = static_cast<USHORT>(aExtIdentifier.getLength()); + if (ts.SearchFrwrd(aExtIdentifier, &start, &end)) + return false; + } + } + } + catch ( ucb::CommandAbortedException& ) + { + } + catch ( uno::RuntimeException& ) + { + } + + if ( aExtIdentifier.getLength() == 0 ) + { + // Fallback: + // Try to use the folder name to match our black list + // as some extensions don't provide an identifier in the + // description.xml! + for ( sal_uInt32 i = 0; i < m_aBlackList.size(); i++ ) + { + utl::SearchParam param(m_aBlackList[i], utl::SearchParam::SRCH_REGEXP); + utl::TextSearch ts(param, LANGUAGE_DONTKNOW); + + xub_StrLen start = 0; + xub_StrLen end = static_cast<USHORT>(sDescriptionXmlURL.getLength()); + if (ts.SearchFrwrd(sDescriptionXmlURL, &start, &end)) + return false; + } + } + } + + return true; +} + +bool OO3ExtensionMigration::migrateExtension( const ::rtl::OUString& sSourceDir ) +{ + if ( !m_xPackageManager.is() ) + { + try + { + m_xPackageManager = deployment::thePackageManagerFactory::get( m_ctx )->getPackageManager( + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "user" )) ); + } + catch ( ucb::CommandFailedException & ){} + catch ( uno::RuntimeException & ) {} + } + + if ( m_xPackageManager.is() ) + { + try + { + TmpRepositoryCommandEnv* pCmdEnv = new TmpRepositoryCommandEnv(); + + uno::Reference< ucb::XCommandEnvironment > xCmdEnv( + static_cast< cppu::OWeakObject* >( pCmdEnv ), uno::UNO_QUERY ); + uno::Reference< task::XAbortChannel > xAbortChannel; + uno::Reference< deployment::XPackage > xPackage = + m_xPackageManager->addPackage( sSourceDir, ::rtl::OUString(), xAbortChannel, xCmdEnv ); + + if ( xPackage.is() ) + return true; + } + catch ( ucb::CommandFailedException& ) + { + } + catch ( ucb::CommandAbortedException& ) + { + } + catch ( lang::IllegalArgumentException& ) + { + } + } + + return false; +} + +bool OO3ExtensionMigration::copy( const ::rtl::OUString& sSourceDir, const ::rtl::OUString& sTargetDir ) +{ + bool bRet = false; + + INetURLObject aSourceObj( sSourceDir ); + INetURLObject aDestObj( sTargetDir ); + String aName = aDestObj.getName(); + aDestObj.removeSegment(); + aDestObj.setFinalSlash(); + + try + { + ::ucbhelper::Content aDestPath( aDestObj.GetMainURL( INetURLObject::NO_DECODE ), uno::Reference< ucb::XCommandEnvironment > () ); + uno::Reference< ucb::XCommandInfo > xInfo = aDestPath.getCommands(); + ::rtl::OUString aTransferName = ::rtl::OUString::createFromAscii( "transfer" ); + if ( xInfo->hasCommandByName( aTransferName ) ) + { + aDestPath.executeCommand( aTransferName, uno::makeAny( + ucb::TransferInfo( sal_False, aSourceObj.GetMainURL( INetURLObject::NO_DECODE ), aName, ucb::NameClash::OVERWRITE ) ) ); + bRet = true; + } + } + catch( uno::Exception& ) + { + } + + return bRet; +} + + +// ----------------------------------------------------------------------------- +// XServiceInfo +// ----------------------------------------------------------------------------- + +::rtl::OUString OO3ExtensionMigration::getImplementationName() throw (RuntimeException) +{ + return OO3ExtensionMigration_getImplementationName(); +} + +// ----------------------------------------------------------------------------- + +sal_Bool OO3ExtensionMigration::supportsService( const ::rtl::OUString& rServiceName ) throw (RuntimeException) +{ + Sequence< ::rtl::OUString > aNames( getSupportedServiceNames() ); + const ::rtl::OUString* pNames = aNames.getConstArray(); + const ::rtl::OUString* pEnd = pNames + aNames.getLength(); + for ( ; pNames != pEnd && !pNames->equals( rServiceName ); ++pNames ) + ; + + return pNames != pEnd; +} + +// ----------------------------------------------------------------------------- + +Sequence< ::rtl::OUString > OO3ExtensionMigration::getSupportedServiceNames() throw (RuntimeException) +{ + return OO3ExtensionMigration_getSupportedServiceNames(); +} + +// ----------------------------------------------------------------------------- +// XInitialization +// ----------------------------------------------------------------------------- + +void OO3ExtensionMigration::initialize( const Sequence< Any >& aArguments ) throw (Exception, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + const Any* pIter = aArguments.getConstArray(); + const Any* pEnd = pIter + aArguments.getLength(); + for ( ; pIter != pEnd ; ++pIter ) + { + beans::NamedValue aValue; + *pIter >>= aValue; + if ( aValue.Name.equalsAscii( "UserData" ) ) + { + if ( !(aValue.Value >>= m_sSourceDir) ) + { + OSL_ENSURE( false, "ExtensionMigration::initialize: argument UserData has wrong type!" ); + } + } + else if ( aValue.Name.equalsAscii( "ExtensionBlackList" ) ) + { + Sequence< ::rtl::OUString > aBlackList; + if ( (aValue.Value >>= aBlackList ) && ( aBlackList.getLength() > 0 )) + { + m_aBlackList.resize( aBlackList.getLength() ); + ::comphelper::sequenceToArray< ::rtl::OUString >( &m_aBlackList[0], aBlackList ); + } + } + } +} + +// ----------------------------------------------------------------------------- + +TStringVectorPtr getContent( const ::rtl::OUString& rBaseURL ) +{ + TStringVectorPtr aResult( new TStringVector ); + ::osl::Directory aDir( rBaseURL); + if ( aDir.open() == ::osl::FileBase::E_None ) + { + // iterate over directory content + TStringVector aSubDirs; + ::osl::DirectoryItem aItem; + while ( aDir.getNextItem( aItem ) == ::osl::FileBase::E_None ) + { + ::osl::FileStatus aFileStatus( FileStatusMask_Type | FileStatusMask_FileURL ); + if ( aItem.getFileStatus( aFileStatus ) == ::osl::FileBase::E_None ) + aResult->push_back( aFileStatus.getFileURL() ); + } + } + + return aResult; +} + +// ----------------------------------------------------------------------------- +// XJob +// ----------------------------------------------------------------------------- + +void OO3ExtensionMigration::copyConfig( const ::rtl::OUString& sSourceDir, const ::rtl::OUString& sTargetDir ) +{ + ::rtl::OUString sEx1( m_sSourceDir ); + sEx1 += sExcludeDir1; + ::rtl::OUString sEx2( m_sSourceDir ); + sEx2 += sExcludeDir2; + + TStringVectorPtr aList = getContent( sSourceDir ); + TStringVector::const_iterator aI = aList->begin(); + while ( aI != aList->end() ) + { + ::rtl::OUString sSourceLocalName = aI->copy( sSourceDir.getLength() ); + ::rtl::OUString aTemp = aI->copy( m_sSourceDir.getLength() ); + if ( aTemp != sExcludeDir1 && aTemp != sExcludeDir2 ) + { + ::rtl::OUString sTargetName = sTargetDir + sSourceLocalName; + copy( (*aI), sTargetName ); + } + ++aI; + } +} + +Any OO3ExtensionMigration::execute( const Sequence< beans::NamedValue >& ) + throw (lang::IllegalArgumentException, Exception, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + ::utl::Bootstrap::PathStatus aStatus = ::utl::Bootstrap::locateUserInstallation( m_sTargetDir ); + if ( aStatus == ::utl::Bootstrap::PATH_EXISTS ) + { + // copy all extensions + ::rtl::OUString sSourceDir( m_sSourceDir ); + sSourceDir += sExtensionSubDir; + sSourceDir += sSubDirName; + sSourceDir += sExtensionRootSubDirName; + TStringVector aExtensionToMigrate; + scanUserExtensions( sSourceDir, aExtensionToMigrate ); + if ( aExtensionToMigrate.size() > 0 ) + { + TStringVector::iterator pIter = aExtensionToMigrate.begin(); + while ( pIter != aExtensionToMigrate.end() ) + { + migrateExtension( *pIter ); + ++pIter; + } + } + } + + return Any(); +} + +// ----------------------------------------------------------------------------- +// TmpRepositoryCommandEnv +// ----------------------------------------------------------------------------- + +TmpRepositoryCommandEnv::TmpRepositoryCommandEnv() +{ +} + +TmpRepositoryCommandEnv::TmpRepositoryCommandEnv( + uno::Reference< task::XInteractionHandler> const & handler) + : m_forwardHandler(handler) +{ +} + +TmpRepositoryCommandEnv::~TmpRepositoryCommandEnv() +{ +} +// XCommandEnvironment +//______________________________________________________________________________ +uno::Reference< task::XInteractionHandler > TmpRepositoryCommandEnv::getInteractionHandler() +throw ( uno::RuntimeException ) +{ + return this; +} + +//______________________________________________________________________________ +uno::Reference< ucb::XProgressHandler > TmpRepositoryCommandEnv::getProgressHandler() +throw ( uno::RuntimeException ) +{ + return this; +} + +// XInteractionHandler +void TmpRepositoryCommandEnv::handle( + uno::Reference< task::XInteractionRequest> const & xRequest ) + throw ( uno::RuntimeException ) +{ + uno::Any request( xRequest->getRequest() ); + OSL_ASSERT( request.getValueTypeClass() == uno::TypeClass_EXCEPTION ); + + bool approve = true; + bool abort = false; + + // select: + uno::Sequence< Reference< task::XInteractionContinuation > > conts( + xRequest->getContinuations() ); + Reference< task::XInteractionContinuation > const * pConts = + conts.getConstArray(); + sal_Int32 len = conts.getLength(); + for ( sal_Int32 pos = 0; pos < len; ++pos ) + { + if (approve) { + uno::Reference< task::XInteractionApprove > xInteractionApprove( + pConts[ pos ], uno::UNO_QUERY ); + if (xInteractionApprove.is()) { + xInteractionApprove->select(); + // don't query again for ongoing continuations: + approve = false; + } + } + else if (abort) { + uno::Reference< task::XInteractionAbort > xInteractionAbort( + pConts[ pos ], uno::UNO_QUERY ); + if (xInteractionAbort.is()) { + xInteractionAbort->select(); + // don't query again for ongoing continuations: + abort = false; + } + } + } +} + +// XProgressHandler +void TmpRepositoryCommandEnv::push( uno::Any const & /*Status*/ ) +throw (uno::RuntimeException) +{ +} + + +void TmpRepositoryCommandEnv::update( uno::Any const & /*Status */) +throw (uno::RuntimeException) +{ +} + +void TmpRepositoryCommandEnv::pop() throw (uno::RuntimeException) +{ +} + +// ============================================================================= +// component operations +// ============================================================================= + +Reference< XInterface > SAL_CALL OO3ExtensionMigration_create( + Reference< XComponentContext > const & ctx ) + SAL_THROW( () ) +{ + return static_cast< lang::XTypeProvider * >( new OO3ExtensionMigration( + ctx) ); +} + +// ----------------------------------------------------------------------------- + +} // namespace migration diff --git a/desktop/source/migration/services/oo3extensionmigration.hxx b/desktop/source/migration/services/oo3extensionmigration.hxx new file mode 100755 index 000000000000..a001f41d92c5 --- /dev/null +++ b/desktop/source/migration/services/oo3extensionmigration.hxx @@ -0,0 +1,171 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: extensionmigration.hxx,v $ + * $Revision: 1.2 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _DESKTOP_OO3EXTENSIONMIGRATION_HXX_ +#define _DESKTOP_OO3EXTENSIONMIGRATION_HXX_ + +#include "misc.hxx" +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/task/XJob.hpp> +#include <com/sun/star/lang/XInitialization.hpp> +#include <com/sun/star/xml/dom/XDocumentBuilder.hpp> +#include <com/sun/star/ucb/XSimpleFileAccess.hpp> +#include <com/sun/star/deployment/XPackageManager.hpp> + +#include <osl/mutex.hxx> +#include <osl/file.hxx> +#include <cppuhelper/implbase3.hxx> +#include <cppuhelper/compbase3.hxx> +#include <ucbhelper/content.hxx> +#include <xmlscript/xmllib_imexp.hxx> + +namespace com { namespace sun { namespace star { + namespace uno { + class XComponentContext; + } + namespace deployment { + class XPackage; + } +}}} + +class INetURLObject; + + +namespace migration +{ + + ::rtl::OUString SAL_CALL OO3ExtensionMigration_getImplementationName(); + ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL OO3ExtensionMigration_getSupportedServiceNames(); + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL OO3ExtensionMigration_create( + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > const & xContext ) + SAL_THROW( (::com::sun::star::uno::Exception) ); + + + // ============================================================================= + // class ExtensionMigration + // ============================================================================= + + typedef ::cppu::WeakImplHelper3< + ::com::sun::star::lang::XServiceInfo, + ::com::sun::star::lang::XInitialization, + ::com::sun::star::task::XJob > ExtensionMigration_BASE; + + class OO3ExtensionMigration : public ExtensionMigration_BASE + { + private: + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > m_ctx; + ::com::sun::star::uno::Reference< ::com::sun::star::xml::dom::XDocumentBuilder > m_xDocBuilder; + ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XSimpleFileAccess > m_xSimpleFileAccess; + ::com::sun::star::uno::Reference< ::com::sun::star::deployment::XPackageManager > m_xPackageManager; + ::osl::Mutex m_aMutex; + ::rtl::OUString m_sSourceDir; + ::rtl::OUString m_sTargetDir; + TStringVector m_aBlackList; + + enum ScanResult + { + SCANRESULT_NOTFOUND, + SCANRESULT_MIGRATE_EXTENSION, + SCANRESULT_DONTMIGRATE_EXTENSION + }; + + ::osl::FileBase::RC checkAndCreateDirectory( INetURLObject& rDirURL ); + void copyConfig( const ::rtl::OUString& sSourceDir, const ::rtl::OUString& sTargetDir ); + bool copy( const ::rtl::OUString& sSourceDir, const ::rtl::OUString& sTargetDir ); + ScanResult scanExtensionFolder( const ::rtl::OUString& sExtFolder ); + void scanUserExtensions( const ::rtl::OUString& sSourceDir, TStringVector& aMigrateExtensions ); + bool scanDescriptionXml( const ::rtl::OUString& sDescriptionXmlFilePath ); + bool migrateExtension( const ::rtl::OUString& sSourceDir ); + /* fills m_scriptElements and m_dialogElements + */ + void registerConfigurationPackage( + const ::com::sun::star::uno::Reference< ::com::sun::star::deployment::XPackage > & xPkg); + + public: + OO3ExtensionMigration(::com::sun::star::uno::Reference< + ::com::sun::star::uno::XComponentContext > const & ctx); + virtual ~OO3ExtensionMigration(); + + // XServiceInfo + virtual ::rtl::OUString SAL_CALL getImplementationName() + throw (::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& rServiceName ) + throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() + throw (::com::sun::star::uno::RuntimeException); + + // XInitialization + virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) + throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); + + // XJob + virtual ::com::sun::star::uno::Any SAL_CALL execute( + const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& Arguments ) + throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::Exception, + ::com::sun::star::uno::RuntimeException); + }; + + class TmpRepositoryCommandEnv + : public ::cppu::WeakImplHelper3< ::com::sun::star::ucb::XCommandEnvironment, + ::com::sun::star::task::XInteractionHandler, + ::com::sun::star::ucb::XProgressHandler > + { + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > m_xContext; + ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler> m_forwardHandler; + public: + virtual ~TmpRepositoryCommandEnv(); + TmpRepositoryCommandEnv(); + TmpRepositoryCommandEnv( + ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler> const & handler); + + // XCommandEnvironment + virtual ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler > SAL_CALL + getInteractionHandler() throw ( ::com::sun::star::uno::RuntimeException ); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XProgressHandler > + SAL_CALL getProgressHandler() throw ( ::com::sun::star::uno::RuntimeException ); + + // XInteractionHandler + virtual void SAL_CALL handle( + ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionRequest > const & xRequest ) + throw (::com::sun::star::uno::RuntimeException); + + // XProgressHandler + virtual void SAL_CALL push( ::com::sun::star::uno::Any const & Status ) + throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL update( ::com::sun::star::uno::Any const & Status ) + throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL pop() throw (::com::sun::star::uno::RuntimeException); + }; + +//......................................................................... +} // namespace migration +//......................................................................... + +#endif // _DESKTOP_OO3EXTENSIONMIGRATION_HXX_ diff --git a/desktop/source/migration/services/wordbookmigration.cxx b/desktop/source/migration/services/wordbookmigration.cxx new file mode 100755 index 000000000000..1ac8f38dca56 --- /dev/null +++ b/desktop/source/migration/services/wordbookmigration.cxx @@ -0,0 +1,322 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_desktop.hxx" +#include "wordbookmigration.hxx" +#include <tools/urlobj.hxx> +#include <unotools/bootstrap.hxx> +#include <unotools/ucbstreamhelper.hxx> + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; + + +//......................................................................... +namespace migration +{ +//......................................................................... + + + static ::rtl::OUString sSourceSubDir = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/user/wordbook" ) ); + static ::rtl::OUString sTargetSubDir = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/user/wordbook" ) ); + static ::rtl::OUString sBaseName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/wordbook" ) ); + static ::rtl::OUString sSuffix = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".dic" ) ); + + + // ============================================================================= + // component operations + // ============================================================================= + + ::rtl::OUString WordbookMigration_getImplementationName() + { + static ::rtl::OUString* pImplName = 0; + if ( !pImplName ) + { + ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); + if ( !pImplName ) + { + static ::rtl::OUString aImplName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.desktop.migration.Wordbooks" ) ); + pImplName = &aImplName; + } + } + return *pImplName; + } + + // ----------------------------------------------------------------------------- + + Sequence< ::rtl::OUString > WordbookMigration_getSupportedServiceNames() + { + static Sequence< ::rtl::OUString >* pNames = 0; + if ( !pNames ) + { + ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); + if ( !pNames ) + { + static Sequence< ::rtl::OUString > aNames(1); + aNames.getArray()[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.migration.Wordbooks" ) ); + pNames = &aNames; + } + } + return *pNames; + } + + // ============================================================================= + // WordbookMigration + // ============================================================================= + + WordbookMigration::WordbookMigration() + { + } + + // ----------------------------------------------------------------------------- + + WordbookMigration::~WordbookMigration() + { + } + + // ----------------------------------------------------------------------------- + + TStringVectorPtr WordbookMigration::getFiles( const ::rtl::OUString& rBaseURL ) const + { + TStringVectorPtr aResult( new TStringVector ); + ::osl::Directory aDir( rBaseURL); + + if ( aDir.open() == ::osl::FileBase::E_None ) + { + // iterate over directory content + TStringVector aSubDirs; + ::osl::DirectoryItem aItem; + while ( aDir.getNextItem( aItem ) == ::osl::FileBase::E_None ) + { + ::osl::FileStatus aFileStatus( FileStatusMask_Type | FileStatusMask_FileURL ); + if ( aItem.getFileStatus( aFileStatus ) == ::osl::FileBase::E_None ) + { + if ( aFileStatus.getFileType() == ::osl::FileStatus::Directory ) + aSubDirs.push_back( aFileStatus.getFileURL() ); + else + aResult->push_back( aFileStatus.getFileURL() ); + } + } + + // iterate recursive over subfolders + TStringVector::const_iterator aI = aSubDirs.begin(); + while ( aI != aSubDirs.end() ) + { + TStringVectorPtr aSubResult = getFiles( *aI ); + aResult->insert( aResult->end(), aSubResult->begin(), aSubResult->end() ); + ++aI; + } + } + + return aResult; + } + + // ----------------------------------------------------------------------------- + + ::osl::FileBase::RC WordbookMigration::checkAndCreateDirectory( INetURLObject& rDirURL ) + { + ::osl::FileBase::RC aResult = ::osl::Directory::create( rDirURL.GetMainURL( INetURLObject::DECODE_TO_IURI ) ); + if ( aResult == ::osl::FileBase::E_NOENT ) + { + INetURLObject aBaseURL( rDirURL ); + aBaseURL.removeSegment(); + checkAndCreateDirectory( aBaseURL ); + return ::osl::Directory::create( rDirURL.GetMainURL( INetURLObject::DECODE_TO_IURI ) ); + } + else + { + return aResult; + } + } + +#define MAX_HEADER_LENGTH 16 +bool IsUserWordbook( const ::rtl::OUString& rFile ) +{ + static const sal_Char* pVerStr2 = "WBSWG2"; + static const sal_Char* pVerStr5 = "WBSWG5"; + static const sal_Char* pVerStr6 = "WBSWG6"; + static const sal_Char* pVerOOo7 = "OOoUserDict1"; + + bool bRet = false; + SvStream* pStream = ::utl::UcbStreamHelper::CreateStream( String(rFile), STREAM_STD_READ ); + if ( pStream && !pStream->GetError() ) + { + sal_Size nSniffPos = pStream->Tell(); + static sal_Size nVerOOo7Len = sal::static_int_cast< sal_Size >(strlen( pVerOOo7 )); + sal_Char pMagicHeader[MAX_HEADER_LENGTH]; + pMagicHeader[ nVerOOo7Len ] = '\0'; + if ((pStream->Read((void *) pMagicHeader, nVerOOo7Len) == nVerOOo7Len)) + { + if ( !strcmp(pMagicHeader, pVerOOo7) ) + bRet = true; + else + { + USHORT nLen; + pStream->Seek (nSniffPos); + *pStream >> nLen; + if ( nLen < MAX_HEADER_LENGTH ) + { + pStream->Read(pMagicHeader, nLen); + pMagicHeader[nLen] = '\0'; + if ( !strcmp(pMagicHeader, pVerStr2) + || !strcmp(pMagicHeader, pVerStr5) + || !strcmp(pMagicHeader, pVerStr6) ) + bRet = true; + } + } + } + } + + delete pStream; + return bRet; +} + + + // ----------------------------------------------------------------------------- + + void WordbookMigration::copyFiles() + { + ::rtl::OUString sTargetDir; + ::utl::Bootstrap::PathStatus aStatus = ::utl::Bootstrap::locateUserInstallation( sTargetDir ); + if ( aStatus == ::utl::Bootstrap::PATH_EXISTS ) + { + sTargetDir += sTargetSubDir; + TStringVectorPtr aFileList = getFiles( m_sSourceDir ); + TStringVector::const_iterator aI = aFileList->begin(); + while ( aI != aFileList->end() ) + { + if (IsUserWordbook(*aI) ) + { + ::rtl::OUString sSourceLocalName = aI->copy( m_sSourceDir.getLength() ); + ::rtl::OUString sTargetName = sTargetDir + sSourceLocalName; + INetURLObject aURL( sTargetName ); + aURL.removeSegment(); + checkAndCreateDirectory( aURL ); + ::osl::FileBase::RC aResult = ::osl::File::copy( *aI, sTargetName ); + if ( aResult != ::osl::FileBase::E_None ) + { + ::rtl::OString aMsg( "WordbookMigration::copyFiles: cannot copy " ); + aMsg += ::rtl::OUStringToOString( *aI, RTL_TEXTENCODING_UTF8 ) + " to " + + ::rtl::OUStringToOString( sTargetName, RTL_TEXTENCODING_UTF8 ); + OSL_ENSURE( sal_False, aMsg.getStr() ); + } + } + ++aI; + } + } + else + { + OSL_ENSURE( sal_False, "WordbookMigration::copyFiles: no user installation!" ); + } + } + + // ----------------------------------------------------------------------------- + // XServiceInfo + // ----------------------------------------------------------------------------- + + ::rtl::OUString WordbookMigration::getImplementationName() throw (RuntimeException) + { + return WordbookMigration_getImplementationName(); + } + + // ----------------------------------------------------------------------------- + + sal_Bool WordbookMigration::supportsService( const ::rtl::OUString& rServiceName ) throw (RuntimeException) + { + Sequence< ::rtl::OUString > aNames( getSupportedServiceNames() ); + const ::rtl::OUString* pNames = aNames.getConstArray(); + const ::rtl::OUString* pEnd = pNames + aNames.getLength(); + for ( ; pNames != pEnd && !pNames->equals( rServiceName ); ++pNames ) + ; + + return pNames != pEnd; + } + + // ----------------------------------------------------------------------------- + + Sequence< ::rtl::OUString > WordbookMigration::getSupportedServiceNames() throw (RuntimeException) + { + return WordbookMigration_getSupportedServiceNames(); + } + + // ----------------------------------------------------------------------------- + // XInitialization + // ----------------------------------------------------------------------------- + + void WordbookMigration::initialize( const Sequence< Any >& aArguments ) throw (Exception, RuntimeException) + { + ::osl::MutexGuard aGuard( m_aMutex ); + + const Any* pIter = aArguments.getConstArray(); + const Any* pEnd = pIter + aArguments.getLength(); + for ( ; pIter != pEnd ; ++pIter ) + { + beans::NamedValue aValue; + *pIter >>= aValue; + if ( aValue.Name.equalsAscii( "UserData" ) ) + { + if ( !(aValue.Value >>= m_sSourceDir) ) + { + OSL_ENSURE( false, "WordbookMigration::initialize: argument UserData has wrong type!" ); + } + m_sSourceDir += sSourceSubDir; + break; + } + } + } + + // ----------------------------------------------------------------------------- + // XJob + // ----------------------------------------------------------------------------- + + Any WordbookMigration::execute( const Sequence< beans::NamedValue >& ) + throw (lang::IllegalArgumentException, Exception, RuntimeException) + { + ::osl::MutexGuard aGuard( m_aMutex ); + + copyFiles(); + + return Any(); + } + + // ============================================================================= + // component operations + // ============================================================================= + + Reference< XInterface > SAL_CALL WordbookMigration_create( + Reference< XComponentContext > const & ) + SAL_THROW( () ) + { + return static_cast< lang::XTypeProvider * >( new WordbookMigration() ); + } + + // ----------------------------------------------------------------------------- + +//......................................................................... +} // namespace migration +//......................................................................... diff --git a/desktop/source/migration/services/wordbookmigration.hxx b/desktop/source/migration/services/wordbookmigration.hxx new file mode 100755 index 000000000000..f4dc4c0d2628 --- /dev/null +++ b/desktop/source/migration/services/wordbookmigration.hxx @@ -0,0 +1,102 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _DESKTOP_WORDBOOKMIGRATION_HXX_ +#define _DESKTOP_WORDBOOKMIGRATION_HXX_ + +#include "misc.hxx" +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/lang/XInitialization.hpp> +#include <com/sun/star/task/XJob.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <cppuhelper/implbase3.hxx> +#include <osl/mutex.hxx> +#include <osl/file.hxx> + + +class INetURLObject; + + +//......................................................................... +namespace migration +{ +//......................................................................... + + ::rtl::OUString SAL_CALL WordbookMigration_getImplementationName(); + ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL WordbookMigration_getSupportedServiceNames(); + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL WordbookMigration_create( + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > const & xContext ) + SAL_THROW( (::com::sun::star::uno::Exception) ); + + + // ============================================================================= + // class WordbookMigration + // ============================================================================= + + typedef ::cppu::WeakImplHelper3< + ::com::sun::star::lang::XServiceInfo, + ::com::sun::star::lang::XInitialization, + ::com::sun::star::task::XJob > WordbookMigration_BASE; + + class WordbookMigration : public WordbookMigration_BASE + { + private: + ::osl::Mutex m_aMutex; + ::rtl::OUString m_sSourceDir; + + TStringVectorPtr getFiles( const ::rtl::OUString& rBaseURL ) const; + ::osl::FileBase::RC checkAndCreateDirectory( INetURLObject& rDirURL ); + void copyFiles(); + + public: + WordbookMigration(); + virtual ~WordbookMigration(); + + // XServiceInfo + virtual ::rtl::OUString SAL_CALL getImplementationName() + throw (::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& rServiceName ) + throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() + throw (::com::sun::star::uno::RuntimeException); + + // XInitialization + virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) + throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); + + // XJob + virtual ::com::sun::star::uno::Any SAL_CALL execute( + const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& Arguments ) + throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::Exception, + ::com::sun::star::uno::RuntimeException); + }; + +//......................................................................... +} // namespace migration +//......................................................................... + +#endif // _DESKTOP_AUTOCORRMIGRATION_HXX_ diff --git a/desktop/source/migration/wizard.cxx b/desktop/source/migration/wizard.cxx new file mode 100644 index 000000000000..48ee2abc71ca --- /dev/null +++ b/desktop/source/migration/wizard.cxx @@ -0,0 +1,659 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_desktop.hxx" + +#include <migration.hxx> +#include "wizard.hxx" +#include "wizard.hrc" +#include "pages.hxx" +#include "app.hxx" + +#include <rtl/ustring.hxx> +#include <rtl/ustrbuf.hxx> +#include <rtl/string.hxx> +#include <rtl/strbuf.hxx> +#include <rtl/bootstrap.hxx> + +#include <comphelper/processfactory.hxx> +#include <tools/date.hxx> +#include <tools/time.hxx> +#include <tools/datetime.hxx> +#include <osl/file.hxx> +#include <osl/time.h> +#include <osl/module.hxx> +#include <unotools/bootstrap.hxx> +#include <vcl/msgbox.hxx> + +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Sequence.hxx> +#include <com/sun/star/beans/NamedValue.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/beans/XPropertyState.hpp> +#include <com/sun/star/frame/XDesktop.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/lang/XInitialization.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/util/XChangesBatch.hpp> +#include <com/sun/star/container/XNameReplace.hpp> +#include <com/sun/star/awt/WindowDescriptor.hpp> +#include <com/sun/star/awt/WindowAttribute.hpp> + +using namespace svt; +using namespace rtl; +using namespace osl; +using namespace utl; +using namespace com::sun::star; +using namespace com::sun::star::uno; +using namespace com::sun::star::lang; +using namespace com::sun::star::beans; +using namespace com::sun::star::util; +using namespace com::sun::star::container; + +#define UNISTRING(s) rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(s)) + +namespace desktop +{ + +const FirstStartWizard::WizardState FirstStartWizard::STATE_WELCOME = 0; +const FirstStartWizard::WizardState FirstStartWizard::STATE_LICENSE = 1; +const FirstStartWizard::WizardState FirstStartWizard::STATE_MIGRATION = 2; +const FirstStartWizard::WizardState FirstStartWizard::STATE_USER = 3; +const FirstStartWizard::WizardState FirstStartWizard::STATE_UPDATE_CHECK = 4; +const FirstStartWizard::WizardState FirstStartWizard::STATE_REGISTRATION = 5; + +static uno::Reference< uno::XComponentContext > getComponentContext( const uno::Reference< lang::XMultiServiceFactory >& rFactory ) +{ + uno::Reference< uno::XComponentContext > rContext; + uno::Reference< beans::XPropertySet > rPropSet( rFactory, uno::UNO_QUERY ); + uno::Any a = rPropSet->getPropertyValue( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ) ) ); + a >>= rContext; + return rContext; +} + +static sal_Int32 getBuildId() +{ + ::rtl::OUString aDefault; + ::rtl::OUString aBuildIdData = utl::Bootstrap::getBuildIdData( aDefault ); + sal_Int32 nBuildId( 0 ); + sal_Int32 nIndex1 = aBuildIdData.indexOf(':'); + sal_Int32 nIndex2 = aBuildIdData.indexOf(')'); + if (( nIndex1 > 0 ) && ( nIndex2 > 0 ) && ( nIndex2-1 > nIndex1+1 )) + { + ::rtl::OUString aBuildId = aBuildIdData.copy( nIndex1+1, nIndex2-nIndex1-1 ); + nBuildId = aBuildId.toInt32(); + } + return nBuildId; +} + +WizardResId::WizardResId( USHORT nId ) : + ResId( nId, *FirstStartWizard::GetResManager() ) +{ +} + +ResMgr *FirstStartWizard::pResMgr = 0; + +ResMgr *FirstStartWizard::GetResManager() +{ + if ( !FirstStartWizard::pResMgr ) + { + String aMgrName = String::CreateFromAscii( "dkt" ); + FirstStartWizard::pResMgr = ResMgr::CreateResMgr( OUStringToOString( aMgrName, RTL_TEXTENCODING_UTF8 )); + } + return FirstStartWizard::pResMgr; +} + +FirstStartWizard::FirstStartWizard( Window* pParent, sal_Bool bLicenseNeedsAcceptance, const rtl::OUString &rLicensePath ) + :RoadmapWizard( pParent, WizardResId(DLG_FIRSTSTART_WIZARD), + WZB_NEXT|WZB_PREVIOUS|WZB_FINISH|WZB_CANCEL|WZB_HELP) + ,m_bOverride(sal_False) + ,m_aDefaultPath(0) + ,m_aMigrationPath(0) + ,m_bDone(sal_False) + ,m_bLicenseNeedsAcceptance( bLicenseNeedsAcceptance ) + ,m_bLicenseWasAccepted(sal_False) + ,m_bAutomaticUpdChk(sal_True) + ,m_aLicensePath( rLicensePath ) +{ + // --- + // FreeResource(); +// enableState(STATE_USER, sal_False); +// enableState(STATE_REGISTRATION, sal_False); + + try + { + Point pos(5, 210 ); + Size size(11, 11 ); + + pos = LogicToPixel( pos, MAP_APPFONT ); + size = LogicToPixel( size, MAP_APPFONT ); + + uno::Reference< lang::XMultiServiceFactory > xFactory = ::comphelper::getProcessServiceFactory(); + uno::Reference< awt::XToolkit > xToolkit( + uno::Reference< lang::XMultiComponentFactory >( + xFactory, uno::UNO_QUERY_THROW)-> + createInstanceWithContext( + rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.Toolkit")), + getComponentContext(xFactory)), + uno::UNO_QUERY_THROW); + + m_xThrobber = uno::Reference< awt::XThrobber >( + xToolkit->createWindow( + awt::WindowDescriptor( + awt::WindowClass_SIMPLE, + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Throbber")), + GetComponentInterface(), 0, + awt::Rectangle( + pos.X(), pos.Y(), size.Width(), size.Height()), + awt::WindowAttribute::SHOW)), + uno::UNO_QUERY_THROW); + } + catch (uno::RuntimeException &) + { + throw; + } + catch (Exception& ) + { + } + + uno::Reference< awt::XWindow > xThrobberWin( m_xThrobber, uno::UNO_QUERY ); + if ( xThrobberWin.is() ) + xThrobberWin->setVisible( false ); + + Size aTPSize(TP_WIDTH, TP_HEIGHT); + SetPageSizePixel(LogicToPixel(aTPSize, MAP_APPFONT)); + + //set help id + m_pPrevPage->SetHelpId(HID_FIRSTSTART_PREV); + m_pNextPage->SetHelpId(HID_FIRSTSTART_NEXT); + m_pCancel->SetHelpId(HID_FIRSTSTART_CANCEL); + m_pFinish->SetHelpId(HID_FIRSTSTART_FINISH); + // m_pHelp->SetUniqueId(UID_FIRSTSTART_HELP); + m_pHelp->Hide(); + m_pHelp->Disable(); + + // save button lables + m_sNext = m_pNextPage->GetText(); + m_sCancel = m_pCancel->GetText(); + + // save cancel click handler + m_lnkCancel = m_pCancel->GetClickHdl(); + + m_aDefaultPath = defineWizardPagesDependingFromContext(); + activatePath(m_aDefaultPath, sal_True); + + enterState(STATE_WELCOME); + ActivatePage(); + + // set text of finish putton: + m_pFinish->SetText(String(WizardResId(STR_FINISH))); + // disable "finish button" + enableButtons(WZB_FINISH, sal_False); + defaultButton(WZB_NEXT); +} + +void FirstStartWizard::EnableButtonsWhileMigration() +{ + enableButtons(0xff, sal_True); +} + +void FirstStartWizard::DisableButtonsWhileMigration() +{ + enableButtons(0xff, sal_False); +} + +::svt::RoadmapWizardTypes::PathId FirstStartWizard::defineWizardPagesDependingFromContext() +{ + ::svt::RoadmapWizardTypes::PathId aDefaultPath = 0; + + sal_Bool bPage_Welcome = sal_True; + sal_Bool bPage_License = sal_True; + sal_Bool bPage_Migration = sal_True; + sal_Bool bPage_User = sal_True; + sal_Bool bPage_UpdateCheck = sal_True; + sal_Bool bPage_Registration = sal_True; + + bPage_License = m_bLicenseNeedsAcceptance; + bPage_Migration = Migration::checkMigration(); + bPage_UpdateCheck = showOnlineUpdatePage(); + + WizardPath aPath; + if (bPage_Welcome) + aPath.push_back(STATE_WELCOME); + if (bPage_License) + aPath.push_back(STATE_LICENSE); + if (bPage_Migration) + aPath.push_back(STATE_MIGRATION); + if (bPage_User) + aPath.push_back(STATE_USER); + if (bPage_UpdateCheck) + aPath.push_back(STATE_UPDATE_CHECK); + if (bPage_Registration) + aPath.push_back(STATE_REGISTRATION); + + declarePath(aDefaultPath, aPath); + + // a) If license must be accepted by the user, all direct links + // to wizard tab pages must be disabled. Because such pages + // should be accessible only in case license was accepted ! + // b) But if no license should be shown at all ... + // such direct links can be enabled by default. + sal_Bool bAllowDirectLink = ( ! bPage_License); + + if (bPage_User) + enableState(STATE_USER, bAllowDirectLink); + if (bPage_UpdateCheck) + enableState(STATE_UPDATE_CHECK, bAllowDirectLink); + if (bPage_Migration) + enableState(STATE_MIGRATION, bAllowDirectLink); + if (bPage_Registration) + enableState(STATE_REGISTRATION, bAllowDirectLink); + + return aDefaultPath; +} + +// catch F1 and disable help +long FirstStartWizard::PreNotify( NotifyEvent& rNEvt ) +{ + if( rNEvt.GetType() == EVENT_KEYINPUT ) + { + const KeyCode& rKey = rNEvt.GetKeyEvent()->GetKeyCode(); + if( rKey.GetCode() == KEY_F1 && ! rKey.GetModifier() ) + return TRUE; + } + return RoadmapWizard::PreNotify(rNEvt); +} + + +void FirstStartWizard::enterState(WizardState _nState) +{ + RoadmapWizard::enterState(_nState); + // default state + // all on + enableButtons(0xff, sal_True); + // finish off + enableButtons(WZB_FINISH, sal_False); + // default text + m_pCancel->SetText(m_sCancel); + m_pCancel->SetClickHdl(m_lnkCancel); + m_pNextPage->SetText(m_sNext); + + // default + defaultButton(WZB_NEXT); + + // specialized state + switch (_nState) + { + case STATE_WELCOME: + enableButtons(WZB_PREVIOUS, sal_False); + break; + case STATE_LICENSE: + m_pCancel->SetText(String(WizardResId(STR_LICENSE_DECLINE))); + m_pNextPage->SetText(String(WizardResId(STR_LICENSE_ACCEPT))); + enableButtons(WZB_NEXT, sal_False); + // attach warning dialog to cancel/decline button + m_pCancel->SetClickHdl( LINK(this, FirstStartWizard, DeclineHdl) ); + break; + case STATE_REGISTRATION: + enableButtons(WZB_NEXT, sal_False); + enableButtons(WZB_FINISH, sal_True); + defaultButton(WZB_FINISH); + break; + } + + // focus + +} + +IMPL_LINK( FirstStartWizard, DeclineHdl, PushButton *, EMPTYARG ) +{ + QueryBox aBox(this, WizardResId(QB_ASK_DECLINE)); + sal_Int32 ret = aBox.Execute(); + if ( ret == BUTTON_OK || ret == BUTTON_YES) + { + Close(); + return sal_False; + } + else + return sal_True; +} + + +TabPage* FirstStartWizard::createPage(WizardState _nState) +{ + TabPage *pTabPage = 0; + switch (_nState) + { + case STATE_WELCOME: + pTabPage = new WelcomePage(this, WizardResId(TP_WELCOME), m_bLicenseNeedsAcceptance); + break; + case STATE_LICENSE: + pTabPage = new LicensePage(this, WizardResId(TP_LICENSE), m_aLicensePath); + break; + case STATE_MIGRATION: + pTabPage = new MigrationPage(this, WizardResId(TP_MIGRATION), m_xThrobber ); + break; + case STATE_USER: + pTabPage = new UserPage(this, WizardResId(TP_USER)); + break; + case STATE_UPDATE_CHECK: + pTabPage = new UpdateCheckPage(this, WizardResId(TP_UPDATE_CHECK)); + break; + case STATE_REGISTRATION: + pTabPage = new RegistrationPage(this, WizardResId(TP_REGISTRATION)); + break; + } + pTabPage->Show(); + + return pTabPage; +} + +String FirstStartWizard::getStateDisplayName( WizardState _nState ) const +{ + String sName; + switch(_nState) + { + case STATE_WELCOME: + sName = String(WizardResId(STR_STATE_WELCOME)); + break; + case STATE_LICENSE: + sName = String(WizardResId(STR_STATE_LICENSE)); + break; + case STATE_MIGRATION: + sName = String(WizardResId(STR_STATE_MIGRATION)); + break; + case STATE_USER: + sName = String(WizardResId(STR_STATE_USER)); + break; + case STATE_UPDATE_CHECK: + sName = String(WizardResId(STR_STATE_UPDATE_CHECK)); + break; + case STATE_REGISTRATION: + sName = String(WizardResId(STR_STATE_REGISTRATION)); + break; + } + return sName; +} + +sal_Bool FirstStartWizard::prepareLeaveCurrentState( CommitPageReason _eReason ) +{ + // the license acceptance is handled here, because it needs to change the state + // of the roadmap wizard which the page implementation does not know. + if ( + (_eReason == eTravelForward) && + (getCurrentState() == STATE_LICENSE ) && + (m_bLicenseWasAccepted == sal_False ) + ) + { + if (Migration::checkMigration()) + enableState(FirstStartWizard::STATE_MIGRATION, sal_True); + if ( showOnlineUpdatePage() ) + enableState(FirstStartWizard::STATE_UPDATE_CHECK, sal_True); + enableState(FirstStartWizard::STATE_USER, sal_True); + enableState(FirstStartWizard::STATE_REGISTRATION, sal_True); + + storeAcceptDate(); + m_bLicenseWasAccepted = sal_True; + } + + return svt::RoadmapWizard::prepareLeaveCurrentState(_eReason); +} + +sal_Bool FirstStartWizard::leaveState(WizardState) +{ + if (( getCurrentState() == STATE_MIGRATION ) && m_bLicenseWasAccepted ) + { + // Store accept date and patch level now as it has been + // overwritten by the migration process! + storeAcceptDate(); + setPatchLevel(); + } + + return sal_True; +} + +sal_Bool FirstStartWizard::onFinish(sal_Int32 _nResult) +{ + // return sal_True; + if (svt::RoadmapWizard::onFinish(_nResult)) + { +#ifndef OS2 // cannot enable quickstart on first startup, see shutdownicon.cxx comments. + enableQuickstart(); +#endif + disableWizard(); + return sal_True; + } + else + return sal_False; +} + +short FirstStartWizard::Execute() +{ + return svt::RoadmapWizard::Execute(); +} + +static OUString _makeDateTimeString (const DateTime& aDateTime, sal_Bool bUTC = sal_False) +{ + OStringBuffer aDateTimeString; + aDateTimeString.append((sal_Int32)aDateTime.GetYear()); + aDateTimeString.append("-"); + if (aDateTime.GetMonth()<10) aDateTimeString.append("0"); + aDateTimeString.append((sal_Int32)aDateTime.GetMonth()); + aDateTimeString.append("-"); + if (aDateTime.GetDay()<10) aDateTimeString.append("0"); + aDateTimeString.append((sal_Int32)aDateTime.GetDay()); + aDateTimeString.append("T"); + if (aDateTime.GetHour()<10) aDateTimeString.append("0"); + aDateTimeString.append((sal_Int32)aDateTime.GetHour()); + aDateTimeString.append(":"); + if (aDateTime.GetMin()<10) aDateTimeString.append("0"); + aDateTimeString.append((sal_Int32)aDateTime.GetMin()); + aDateTimeString.append(":"); + if (aDateTime.GetSec()<10) aDateTimeString.append("0"); + aDateTimeString.append((sal_Int32)aDateTime.GetSec()); + if (bUTC) aDateTimeString.append("Z"); + + return OStringToOUString(aDateTimeString.makeStringAndClear(), RTL_TEXTENCODING_ASCII_US); +} + +static OUString _getCurrentDateString() +{ + OUString aString; + return _makeDateTimeString(DateTime()); +} + + +static const OUString sConfigSrvc( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.configuration.ConfigurationProvider" ) ); +static const OUString sAccessSrvc( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.configuration.ConfigurationUpdateAccess" ) ); +static const OUString sReadSrvc ( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.configuration.ConfigurationAccess" ) ); + +void FirstStartWizard::storeAcceptDate() +{ + + try { + Reference < XMultiServiceFactory > xFactory = ::comphelper::getProcessServiceFactory(); + // get configuration provider + Reference< XMultiServiceFactory > theConfigProvider = Reference< XMultiServiceFactory >( + xFactory->createInstance(sConfigSrvc), UNO_QUERY_THROW); + Sequence< Any > theArgs(1); + NamedValue v(OUString::createFromAscii("NodePath"), + makeAny(OUString::createFromAscii("org.openoffice.Setup/Office"))); + theArgs[0] <<= v; + Reference< XPropertySet > pset = Reference< XPropertySet >( + theConfigProvider->createInstanceWithArguments(sAccessSrvc, theArgs), UNO_QUERY_THROW); + Any result = pset->getPropertyValue(OUString::createFromAscii("LicenseAcceptDate")); + + OUString aAcceptDate = _getCurrentDateString(); + pset->setPropertyValue(OUString::createFromAscii("LicenseAcceptDate"), makeAny(aAcceptDate)); + Reference< XChangesBatch >(pset, UNO_QUERY_THROW)->commitChanges(); + + // since the license is accepted the local user registry can be cleaned if required + cleanOldOfficeRegKeys(); + } catch (const Exception&) + { + } + +} + +void FirstStartWizard::setPatchLevel() +{ + try { + Reference < XMultiServiceFactory > xFactory = ::comphelper::getProcessServiceFactory(); + // get configuration provider + Reference< XMultiServiceFactory > theConfigProvider = Reference< XMultiServiceFactory >( + xFactory->createInstance(sConfigSrvc), UNO_QUERY_THROW); + Sequence< Any > theArgs(1); + NamedValue v(OUString::createFromAscii("NodePath"), + makeAny(OUString::createFromAscii("org.openoffice.Office.Common/Help/Registration"))); + theArgs[0] <<= v; + Reference< XPropertySet > pset = Reference< XPropertySet >( + theConfigProvider->createInstanceWithArguments(sAccessSrvc, theArgs), UNO_QUERY_THROW); + Any result = pset->getPropertyValue(OUString::createFromAscii("ReminderDate")); + + OUString aPatchLevel( RTL_CONSTASCII_USTRINGPARAM( "Patch" )); + aPatchLevel += OUString::valueOf( getBuildId(), 10 ); + pset->setPropertyValue(OUString::createFromAscii("ReminderDate"), makeAny(aPatchLevel)); + Reference< XChangesBatch >(pset, UNO_QUERY_THROW)->commitChanges(); + } catch (const Exception&) + { + } +} + +#ifdef WNT +typedef int ( __stdcall * CleanCurUserRegProc ) ( wchar_t* ); +#endif + +void FirstStartWizard::cleanOldOfficeRegKeys() +{ +#ifdef WNT + // after the wizard is completed clean OOo1.1.x entries in the current user registry if required + // issue i47658 + + OUString aBaseLocationPath; + OUString aSharedLocationPath; + OUString aInstallMode; + + ::utl::Bootstrap::PathStatus aBaseLocateResult = + ::utl::Bootstrap::locateBaseInstallation( aBaseLocationPath ); + ::utl::Bootstrap::PathStatus aSharedLocateResult = + ::utl::Bootstrap::locateSharedData( aSharedLocationPath ); + aInstallMode = ::utl::Bootstrap::getAllUsersValue( ::rtl::OUString() ); + + // TODO: replace the checking for install mode + if ( aBaseLocateResult == ::utl::Bootstrap::PATH_EXISTS && aSharedLocateResult == ::utl::Bootstrap::PATH_EXISTS + && aInstallMode.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "1" ) ) ) ) + { + ::rtl::OUString aDeregCompletePath = + aBaseLocationPath + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/program/regcleanold.dll" ) ); + ::rtl::OUString aExecCompletePath = + aSharedLocationPath + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/regdeinstall/userdeinst.exe" ) ); + + osl::Module aCleanModule( aDeregCompletePath ); + CleanCurUserRegProc pNativeProc = ( CleanCurUserRegProc )( + aCleanModule.getFunctionSymbol( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CleanCurUserOldSystemRegistry" ) ) ) ); + + if( pNativeProc!=NULL ) + { + ::rtl::OUString aExecCompleteSysPath; + if ( osl::File::getSystemPathFromFileURL( aExecCompletePath, aExecCompleteSysPath ) == FileBase::E_None + && aExecCompleteSysPath.getLength() ) + { + ( *pNativeProc )( (wchar_t*)( aExecCompleteSysPath.getStr() ) ); + } + } + } +#endif +} + +void FirstStartWizard::disableWizard() +{ + + try { + Reference < XMultiServiceFactory > xFactory = ::comphelper::getProcessServiceFactory(); + // get configuration provider + Reference< XMultiServiceFactory > theConfigProvider = Reference< XMultiServiceFactory >( + xFactory->createInstance(sConfigSrvc), UNO_QUERY_THROW); + Sequence< Any > theArgs(1); + NamedValue v(OUString::createFromAscii("NodePath"), + makeAny(OUString::createFromAscii("org.openoffice.Setup/Office"))); + theArgs[0] <<= v; + Reference< XPropertySet > pset = Reference< XPropertySet >( + theConfigProvider->createInstanceWithArguments(sAccessSrvc, theArgs), UNO_QUERY_THROW); + pset->setPropertyValue(OUString::createFromAscii("FirstStartWizardCompleted"), makeAny(sal_True)); + Reference< XChangesBatch >(pset, UNO_QUERY_THROW)->commitChanges(); + } catch (const Exception&) + { + } + +} + + +void FirstStartWizard::enableQuickstart() +{ + sal_Bool bQuickstart( sal_True ); + sal_Bool bAutostart( sal_True ); + Sequence< Any > aSeq( 2 ); + aSeq[0] <<= bQuickstart; + aSeq[1] <<= bAutostart; + + Reference < XInitialization > xQuickstart( ::comphelper::getProcessServiceFactory()->createInstance( + OUString::createFromAscii( "com.sun.star.office.Quickstart" )),UNO_QUERY ); + if ( xQuickstart.is() ) + xQuickstart->initialize( aSeq ); + +} + +sal_Bool FirstStartWizard::showOnlineUpdatePage() +{ + try { + Reference < XNameReplace > xUpdateAccess; + Reference < XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory() ); + + xUpdateAccess = Reference < XNameReplace >( + xFactory->createInstance( UNISTRING( "com.sun.star.setup.UpdateCheckConfig" ) ), UNO_QUERY_THROW ); + + if ( xUpdateAccess.is() ) + { + sal_Bool bAutoUpdChk = sal_False; + Any result = xUpdateAccess->getByName( UNISTRING( "AutoCheckEnabled" ) ); + result >>= bAutoUpdChk; + if ( bAutoUpdChk == sal_False ) + return sal_True; + else + return sal_False; + } + } catch (const Exception&) + { + } + return sal_False; +} + +} diff --git a/desktop/source/migration/wizard.hrc b/desktop/source/migration/wizard.hrc new file mode 100644 index 000000000000..fdad97a8174b --- /dev/null +++ b/desktop/source/migration/wizard.hrc @@ -0,0 +1,99 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "desktop.hrc" +#include "helpid.hrc" + +#define TP_WIDTH 220 +#define TP_HEIGHT 205 + +#define DLG_FIRSTSTART_WIZARD RID_FIRSTSTSTART_START+1 + // FREE +#define TP_WELCOME RID_FIRSTSTSTART_START+3 +#define TP_REGISTRATION RID_FIRSTSTSTART_START+4 +#define TP_MIGRATION RID_FIRSTSTSTART_START+5 +#define TP_USER RID_FIRSTSTSTART_START+6 +#define TP_LICENSE RID_FIRSTSTSTART_START+7 +#define TP_UPDATE_CHECK RID_FIRSTSTSTART_START+8 +#define ERRBOX_REG_NOSYSBROWSER RID_FIRSTSTSTART_START+29 +#define QB_ASK_DECLINE RID_FIRSTSTSTART_START+30 + +// local resIDs + +#define FT_WELCOME_HEADER 1 +#define FT_WELCOME_BODY 2 +#define FT_LICENSE_HEADER 1 +#define FT_LICENSE_BODY_1 2 +#define FT_LICENSE_BODY_1_TXT 3 +#define FT_LICENSE_BODY_2 4 +#define FT_LICENSE_BODY_2_TXT 5 +#define ML_LICENSE 6 +#define PB_LICENSE_DOWN 7 +#define FT_MIGRATION_HEADER 1 +#define FT_MIGRATION_BODY 2 +#define CB_MIGRATION 3 +#define FT_UPDATE_CHECK_HEADER 1 +#define FT_UPDATE_CHECK_BODY 2 +#define CB_UPDATE_CHECK 3 +#define FT_REGISTRATION_HEADER 1 +#define FT_REGISTRATION_BODY 2 +#define FL_REGISTRATION 3 +#define FT_REGISTRATION_END 4 +#define RB_REGISTRATION_NOW 5 +#define RB_REGISTRATION_LATER 6 +#define RB_REGISTRATION_NEVER 7 +#define RB_REGISTRATION_REG 8 +#define IMG_REGISTRATION 9 +#define FT_USER_HEADER 10 +#define FT_USER_BODY 11 +#define FT_USER_FIRST 12 +#define FT_USER_LAST 13 +#define FT_USER_FATHER 14 +#define FT_USER_INITIALS 15 +#define ED_USER_FIRST 16 +#define ED_USER_LAST 17 +#define ED_USER_FATHER 18 +#define ED_USER_INITIALS 19 +#define TR_WAITING 20 + +// global strings +#define STR_STATE_WELCOME RID_FIRSTSTSTART_START+100 +#define STR_STATE_LICENSE RID_FIRSTSTSTART_START+101 +#define STR_STATE_MIGRATION RID_FIRSTSTSTART_START+102 +#define STR_STATE_REGISTRATION RID_FIRSTSTSTART_START+103 +#define STR_WELCOME_MIGRATION RID_FIRSTSTSTART_START+104 +// FREE RID_FIRSTSTSTART_START+105 +// FREE RID_FIRSTSTSTART_START+106 +#define STR_LICENSE_ACCEPT RID_FIRSTSTSTART_START+107 +#define STR_LICENSE_DECLINE RID_FIRSTSTSTART_START+108 +#define STR_FINISH RID_FIRSTSTSTART_START+109 +#define STR_STATE_USER RID_FIRSTSTSTART_START+110 +// FREE RID_FIRSTSTSTART_START+111 +#define STR_STATE_UPDATE_CHECK RID_FIRSTSTSTART_START+112 +#define STR_WELCOME_WITHOUT_LICENSE RID_FIRSTSTSTART_START+113 +#define STR_REGISTRATION_OOO RID_FIRSTSTSTART_START+114 + diff --git a/desktop/source/migration/wizard.hxx b/desktop/source/migration/wizard.hxx new file mode 100644 index 000000000000..e41bfe373cde --- /dev/null +++ b/desktop/source/migration/wizard.hxx @@ -0,0 +1,107 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _WIZARD_HXX_ +#define _WIZARD_HXX_ + +#include <rtl/ustring.hxx> +#include <svtools/roadmapwizard.hxx> +#include <vcl/window.hxx> +#include <tools/resid.hxx> +#include <com/sun/star/awt/XThrobber.hpp> + +namespace desktop +{ + +class WizardResId : public ResId +{ +public: + WizardResId( USHORT nId ); +}; + +class FirstStartWizard : public svt::RoadmapWizard +{ + +public: + static const WizardState STATE_WELCOME; + static const WizardState STATE_LICENSE; + static const WizardState STATE_MIGRATION; + static const WizardState STATE_USER; + static const WizardState STATE_UPDATE_CHECK; + static const WizardState STATE_REGISTRATION; + + static ResMgr* pResMgr; + static ResMgr* GetResManager(); + + FirstStartWizard( Window* pParent, sal_Bool bLicenseNeedsAcceptance, const rtl::OUString &rLicensePath ); + + virtual short Execute(); + virtual long PreNotify( NotifyEvent& rNEvt ); + + void EnableButtonsWhileMigration(); + void DisableButtonsWhileMigration(); + +private: + sal_Bool m_bOverride; + WizardState _currentState; + ::svt::RoadmapWizardTypes::PathId m_aDefaultPath; + ::svt::RoadmapWizardTypes::PathId m_aMigrationPath; + String m_sNext; + String m_sCancel; + sal_Bool m_bDone; + sal_Bool m_bLicenseNeedsAcceptance; + sal_Bool m_bLicenseWasAccepted; + sal_Bool m_bAutomaticUpdChk; + Link m_lnkCancel; + ::com::sun::star::uno::Reference< ::com::sun::star::awt::XThrobber > m_xThrobber; + + rtl::OUString m_aLicensePath; + + void storeAcceptDate(); + void setPatchLevel(); + void disableWizard(); + void enableQuickstart(); + + DECL_LINK(DeclineHdl, PushButton*); + + void cleanOldOfficeRegKeys(); + sal_Bool showOnlineUpdatePage(); + ::svt::RoadmapWizardTypes::PathId defineWizardPagesDependingFromContext(); + +protected: + // from svt::WizardMachine + virtual TabPage* createPage(WizardState _nState); + virtual sal_Bool prepareLeaveCurrentState( CommitPageReason _eReason ); + virtual sal_Bool leaveState(WizardState _nState ); + virtual sal_Bool onFinish(sal_Int32 _nResult); + virtual void enterState(WizardState _nState); + + // from svt::RoadmapWizard + virtual String getStateDisplayName( WizardState _nState ) const; +}; +} +#endif diff --git a/desktop/source/migration/wizard.src b/desktop/source/migration/wizard.src new file mode 100644 index 000000000000..9c1ab5496d39 --- /dev/null +++ b/desktop/source/migration/wizard.src @@ -0,0 +1,424 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + + /* + * encoding for resources: windows-1252 + */ + +#include "wizard.hrc" +#include <svtools/controldims.hrc> + +ModalDialog DLG_FIRSTSTART_WIZARD +{ + Text [ en-US ] = "Welcome to %PRODUCTNAME %PRODUCTVERSION"; + + OutputSize = TRUE ; + SVLook = TRUE ; + Moveable = TRUE ; + Closeable = TRUE ; + Hide = TRUE; + HelpID = HID_FIRSTSTART_DIALOG; +}; + +String STR_STATE_WELCOME +{ + Text [ en-US ] = "Welcome"; +}; +String STR_STATE_LICENSE +{ + Text [ en-US ] = "License Agreement"; +}; +String STR_STATE_MIGRATION +{ + Text [ en-US ] = "Personal Data"; +}; +String STR_STATE_USER +{ + Text [ en-US ] = "User name"; +}; + +String STR_STATE_UPDATE_CHECK +{ + Text [ en-US ] = "Online Update"; +}; + +String STR_STATE_REGISTRATION +{ + Text [ en-US ] = "Registration"; +}; + +String STR_WELCOME_MIGRATION +{ + Text [ en-US ] = "This wizard will guide you through the license agreement, the transfer of user data from %OLD_VERSION and the registration of %PRODUCTNAME.\n\nClick 'Next' to continue."; + +}; + +String STR_WELCOME_WITHOUT_LICENSE +{ + Text [ en-US ] = "This wizard will guide you through the registration of %PRODUCTNAME.\n\nClick 'Next' to continue."; +}; + +String STR_FINISH +{ + Text [ en-US ] = "~Finish"; +}; + +String STR_REGISTRATION_OOO +{ + Text [ en-US ] = "You now have the opportunity to support and contribute to the fastest growing open source community in the world.\n\nHelp us prove that %PRODUCTNAME has already gained significant market share by registering.\n\nRegistering is voluntary and without obligation."; +}; + +ErrorBox ERRBOX_REG_NOSYSBROWSER +{ + BUTTONS = WB_OK ; + DEFBUTTON = WB_DEF_OK ; + + Message [ en-US ] = "An error occurred in starting the web browser.\nPlease check the %PRODUCTNAME and web browser settings."; +}; + +QueryBox QB_ASK_DECLINE +{ + Buttons = WB_YES_NO; + DefButton = WB_DEF_NO; + + Message [ en-US ] = "Do you really want to decline?"; +}; + + +#define ROWHEIGHT 8 +#define MARGINLEFT 10 +#define MARGINRIGHT 10 +#define BODYWIDTH TP_WIDTH-MARGINLEFT-MARGINRIGHT +#define MARGINTOP 10 +#define MARGINBOTTOM 2 +#define BODYHEIGHT TP_HEIGHT-MARGINTOP-MARGINBOTTOM +#define INDENT 10 +#define INDENT2 12 + +TabPage TP_WELCOME +{ + SVLook = TRUE ; + Hide = TRUE ; + Size = MAP_APPFONT(TP_WIDTH, TP_HEIGHT); + HelpID = HID_FIRSTSTART_WELCOME; + // bold fixedtext for header + FixedText FT_WELCOME_HEADER + { + NoLabel = TRUE; + Pos = MAP_APPFONT(MARGINRIGHT, MARGINTOP); + Size = MAP_APPFONT( BODYWIDTH, ROWHEIGHT ); + Text [ en-US ] = "Welcome to %PRODUCTNAME %PRODUCTVERSION"; + }; + FixedText FT_WELCOME_BODY + { + NoLabel = TRUE; + Pos = MAP_APPFONT(MARGINLEFT, MARGINTOP + 2*ROWHEIGHT); + Size = MAP_APPFONT( BODYWIDTH, BODYHEIGHT-MARGINTOP - 2*ROWHEIGHT ); + WordBreak = TRUE; + Text [ en-US ] = "This wizard will guide you through the license agreement and the registration of %PRODUCTNAME.\n\nClick 'Next' to continue."; + }; +}; + +TabPage TP_LICENSE +{ + SVLook = TRUE ; + Hide = TRUE ; + Size = MAP_APPFONT(TP_WIDTH, TP_HEIGHT); + HelpID = HID_FIRSTSTART_LICENSE; + FixedText FT_LICENSE_HEADER + { + Pos = MAP_APPFONT(MARGINLEFT, MARGINTOP); + Size = MAP_APPFONT( BODYWIDTH, ROWHEIGHT ); + NoLabel = TRUE; + Text [ en-US ] = "Please follow these steps to accept the license"; + }; + FixedText FT_LICENSE_BODY_1 + { + Pos = MAP_APPFONT(MARGINLEFT, MARGINTOP + 2*ROWHEIGHT); + Size = MAP_APPFONT( INDENT, ROWHEIGHT ); + NoLabel = TRUE; + Text [ en-US ] = "1."; + }; + FixedText FT_LICENSE_BODY_1_TXT + { + Pos = MAP_APPFONT(MARGINLEFT+INDENT, MARGINTOP +2*ROWHEIGHT); + Size = MAP_APPFONT( BODYWIDTH-INDENT, 3*ROWHEIGHT); + WordBreak = TRUE; + NoLabel = TRUE; + Text [ en-US ] = "View the complete License Agreement. Please use the scrollbar or the '%PAGEDOWN' button in this dialog to view the entire license text."; + }; + FixedText FT_LICENSE_BODY_2 + { + Pos = MAP_APPFONT(MARGINLEFT, MARGINTOP + 5*ROWHEIGHT); + Size = MAP_APPFONT(INDENT, ROWHEIGHT ); + NoLabel = TRUE; + Text [ en-US ] = "2."; + }; + FixedText FT_LICENSE_BODY_2_TXT + { + Pos = MAP_APPFONT(MARGINLEFT+INDENT, MARGINTOP + 5*ROWHEIGHT); + Size = MAP_APPFONT( BODYWIDTH-INDENT, 2*ROWHEIGHT); + WordBreak = TRUE; + NoLabel = TRUE; + Text [ en-US ] = "Click 'Accept' to accept the terms of the Agreement."; + }; + MultiLineEdit ML_LICENSE + { + PosSize = MAP_APPFONT (MARGINLEFT+INDENT, MARGINTOP + 8*ROWHEIGHT, BODYWIDTH-INDENT , BODYHEIGHT - 8*ROWHEIGHT - 20-2*MARGINBOTTOM) ; + Border = TRUE; + VScroll = TRUE; + ReadOnly = TRUE; + }; + PushButton PB_LICENSE_DOWN + { + TabStop = TRUE ; + Pos = MAP_APPFONT ( TP_WIDTH-MARGINRIGHT-50 , TP_HEIGHT-MARGINBOTTOM-18 ) ; + Size = MAP_APPFONT ( 50, 15 ) ; + Text [ en-US ] = "Scroll Do~wn"; + }; +}; + +String STR_LICENSE_ACCEPT +{ + Text [ en-US ] = "~Accept"; +}; +String STR_LICENSE_DECLINE +{ + Text [ en-US ] = "~Decline"; +}; + + +TabPage TP_MIGRATION +{ + SVLook = TRUE ; + Hide = TRUE ; + Size = MAP_APPFONT(TP_WIDTH, TP_HEIGHT); + HelpID = HID_FIRSTSTART_MIGRATION; + + FixedText FT_MIGRATION_HEADER + { + NoLabel = TRUE; + Pos = MAP_APPFONT(MARGINLEFT, MARGINTOP); + Size = MAP_APPFONT( BODYWIDTH, ROWHEIGHT ); + Text [ en-US ] = "Transfer personal data"; + + }; + + FixedText FT_MIGRATION_BODY + { + NoLabel = TRUE; + Pos = MAP_APPFONT(MARGINLEFT, MARGINTOP+ROWHEIGHT*2); + Size = MAP_APPFONT(BODYWIDTH, ROWHEIGHT*8); + WordBreak = TRUE; + Text [ en-US ] = "Most personal data from %OLDPRODUCT installation can be reused in %PRODUCTNAME %PRODUCTVERSION.\n\nIf you do not want to reuse any settings in %PRODUCTNAME %PRODUCTVERSION, unmark the check box."; + + }; + + CheckBox CB_MIGRATION + { + Pos = MAP_APPFONT(MARGINLEFT, MARGINTOP+ROWHEIGHT*10); + Size = MAP_APPFONT(BODYWIDTH, ROWHEIGHT*2); + Check = TRUE; + Text [ en-US ] = "Transfer personal data"; + }; +}; + +TabPage TP_UPDATE_CHECK +{ + SVLook = TRUE ; + Hide = TRUE ; + Size = MAP_APPFONT(TP_WIDTH, TP_HEIGHT); + HelpID = HID_FIRSTSTART_UPDATE_CHECK; + + FixedText FT_UPDATE_CHECK_HEADER + { + NoLabel = TRUE; + Pos = MAP_APPFONT(MARGINLEFT, MARGINTOP); + Size = MAP_APPFONT( BODYWIDTH, ROWHEIGHT ); + Text [ en-US ] = "Online Update"; + + }; + + FixedText FT_UPDATE_CHECK_BODY + { + NoLabel = TRUE; + Pos = MAP_APPFONT(MARGINLEFT, MARGINTOP+ROWHEIGHT*2); + Size = MAP_APPFONT(BODYWIDTH, ROWHEIGHT*8); + WordBreak = TRUE; + Text [ en-US ] = "%PRODUCTNAME searches automatically at regular intervals for new versions.\nIn doing so online update does not transfer personal data.\nAs soon as a new version is available, you will be notified.\n\nYou can configure this feature at Tools / Options... / %PRODUCTNAME / Online Update."; + + }; + + CheckBox CB_UPDATE_CHECK + { + Pos = MAP_APPFONT(MARGINLEFT, MARGINTOP+ROWHEIGHT*10); + Size = MAP_APPFONT(BODYWIDTH, ROWHEIGHT*2); + Check = TRUE; + Text [ en-US ] = "~Check for updates automatically"; + }; +}; + +#define USERINDENT 40 +#define EDHEIGHT 12 +#define INITIALSWIDTH 50 +#define FTADD 2 + +TabPage TP_USER +{ + SVLook = TRUE ; + Hide = TRUE ; + Size = MAP_APPFONT(TP_WIDTH, TP_HEIGHT); + HelpID = HID_FIRSTSTART_USER; + + FixedText FT_USER_HEADER + { + NoLabel = TRUE; + Pos = MAP_APPFONT(MARGINLEFT, MARGINTOP); + Size = MAP_APPFONT( BODYWIDTH, ROWHEIGHT ); + Text [ en-US ] = "Provide your full name and initials below"; + + }; + + FixedText FT_USER_BODY + { + NoLabel = TRUE; + Pos = MAP_APPFONT(MARGINLEFT, MARGINTOP+ROWHEIGHT*2); + Size = MAP_APPFONT(BODYWIDTH, ROWHEIGHT*3); + WordBreak = TRUE; + Text [ en-US ] = "The user name will be used in the document properties, templates and when you record changes made to documents."; + }; + + + FixedText FT_USER_FIRST + { + Pos = MAP_APPFONT(MARGINLEFT, MARGINTOP+ROWHEIGHT*7+FTADD); + Size = MAP_APPFONT(USERINDENT, ROWHEIGHT); + Text [ en-US ] = "~First name"; + }; + Edit ED_USER_FIRST + { + Border = TRUE; + Pos = MAP_APPFONT(MARGINLEFT+USERINDENT, MARGINTOP+ROWHEIGHT*7); + Size = MAP_APPFONT(BODYWIDTH-USERINDENT, EDHEIGHT); + }; + FixedText FT_USER_LAST + { + Pos = MAP_APPFONT(MARGINLEFT, MARGINTOP+ROWHEIGHT*9+FTADD); + Size = MAP_APPFONT(USERINDENT, ROWHEIGHT); + Text [ en-US ] = "~Last name"; + }; + Edit ED_USER_LAST + { + Border = TRUE; + Pos = MAP_APPFONT(MARGINLEFT+USERINDENT, MARGINTOP+ROWHEIGHT*9); + Size = MAP_APPFONT(BODYWIDTH-USERINDENT, EDHEIGHT); + }; + FixedText FT_USER_INITIALS + { + Pos = MAP_APPFONT(MARGINLEFT, MARGINTOP+ROWHEIGHT*11+FTADD); + Size = MAP_APPFONT(USERINDENT, ROWHEIGHT); + Text [ en-US ] = "~Initials"; + }; + Edit ED_USER_INITIALS + { + Border = TRUE; + Pos = MAP_APPFONT(MARGINLEFT+USERINDENT, MARGINTOP+ROWHEIGHT*11); + Size = MAP_APPFONT(INITIALSWIDTH, EDHEIGHT); + }; + + FixedText FT_USER_FATHER + { + Hide = TRUE; + Pos = MAP_APPFONT(MARGINLEFT+USERINDENT+INITIALSWIDTH+10, MARGINTOP+ROWHEIGHT*11+FTADD); + Size = MAP_APPFONT(USERINDENT, ROWHEIGHT); + Text [ en-US ] = "~Father's name"; + }; + Edit ED_USER_FATHER + { + Border = TRUE; + Hide = TRUE; + Pos = MAP_APPFONT(MARGINLEFT+USERINDENT*2+INITIALSWIDTH+10, MARGINTOP+ROWHEIGHT*11); + Size = MAP_APPFONT(BODYWIDTH-10-USERINDENT*2-INITIALSWIDTH, EDHEIGHT); + }; +}; + +#define RB_HEIGHT (RSC_CD_CHECKBOX_HEIGHT+RSC_SP_GRP_SPACE_Y) + +TabPage TP_REGISTRATION +{ + SVLook = TRUE ; + Hide = TRUE ; + Size = MAP_APPFONT(TP_WIDTH, TP_HEIGHT); + HelpID = HID_FIRSTSTART_REGISTRATION; + FixedText FT_REGISTRATION_HEADER + { + NoLabel = TRUE; + Text [ en-US ] = "%PRODUCTNAME Registration"; + Pos = MAP_APPFONT(MARGINLEFT, MARGINRIGHT); + Size = MAP_APPFONT(BODYWIDTH, MARGINRIGHT); + }; + FixedText FT_REGISTRATION_BODY + { + NoLabel = TRUE; + Text [ en-US ] = "You now have the opportunity to register as a %PRODUCTNAME user. Registration is voluntary and is without obligation.\n\nIf you register, we can inform you about new developments concerning this product."; + WordBreak = TRUE; + Pos = MAP_APPFONT(MARGINLEFT, MARGINTOP+ROWHEIGHT*2); + Size = MAP_APPFONT(BODYWIDTH, ROWHEIGHT*8); + }; + RadioButton RB_REGISTRATION_NOW + { + Text [ en-US ] = "I want to register ~now"; + Pos = MAP_APPFONT(MARGINLEFT+INDENT2, ROWHEIGHT*12+2); + Size = MAP_APPFONT(BODYWIDTH-INDENT2, RSC_CD_CHECKBOX_HEIGHT); + Check = TRUE; + }; + RadioButton RB_REGISTRATION_LATER + { + Text [ en-US ] = "I want to register ~later"; + Pos = MAP_APPFONT(MARGINLEFT+INDENT2, ROWHEIGHT*12+2+RB_HEIGHT); + Size = MAP_APPFONT(BODYWIDTH-INDENT2, RSC_CD_CHECKBOX_HEIGHT); + }; + RadioButton RB_REGISTRATION_NEVER + { + Text [ en-US ] = "I do not want to ~register"; + Pos = MAP_APPFONT(MARGINLEFT+INDENT2, ROWHEIGHT*12+2+RB_HEIGHT*2); + Size = MAP_APPFONT(BODYWIDTH-INDENT2, RSC_CD_CHECKBOX_HEIGHT); + }; + FixedLine FL_REGISTRATION + { + Pos = MAP_APPFONT(MARGINLEFT, TP_HEIGHT-MARGINBOTTOM-ROWHEIGHT*6); + Size = MAP_APPFONT(BODYWIDTH, ROWHEIGHT); + }; + FixedText FT_REGISTRATION_END + { + NoLabel = TRUE; + Text [ en-US ] = "We hope you enjoy working with %PRODUCTNAME.\n\nTo exit the wizard, click 'Finish'."; + Pos = MAP_APPFONT(MARGINLEFT, TP_HEIGHT-MARGINBOTTOM-ROWHEIGHT*4); + Size = MAP_APPFONT(BODYWIDTH, ROWHEIGHT*4); + }; +}; + |