From 7f04bb393f830a2983e3e26485bbe217c66006ff Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Wed, 14 Sep 2022 13:16:31 +0200 Subject: [PATCH] Clean up color scheme migration ...avoiding to have code in configmgr that knows about the details of the data stored in the configuration. (See the comments starting at "Migrating product name related color schemes between different versions" for details.) This reverts the dubious changes of 583ea856f2aa227bb04581c5bcdc3a402f5a184f "Migrating product name related color schemes between different versions" in configmgr and offapi. (Also, this moves the computation of sMigratedProductName in MigrationImpl::copyConfig, desktop/source/migration/migration.cxx, to a saner location than in the middle of the "check if the shared registrymodifications.xcu file exists" block where that 583ea856f2aa227bb04581c5bcdc3a402f5a184f had placed it.) Change-Id: I7ab3d57db19065c7c818e697300a2abd9e7f72bc Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139963 Tested-by: Jenkins Reviewed-by: Stephan Bergmann --- configmgr/Library_configmgr.mk | 4 - configmgr/source/components.cxx | 32 +++---- configmgr/source/components.hxx | 5 +- configmgr/source/data.cxx | 18 +--- configmgr/source/data.hxx | 2 +- configmgr/source/parsemanager.cxx | 6 +- configmgr/source/parsemanager.hxx | 3 +- configmgr/source/parser.hxx | 4 +- configmgr/source/update.cxx | 4 +- configmgr/source/xcdparser.cxx | 8 +- configmgr/source/xcdparser.hxx | 2 +- configmgr/source/xcsparser.cxx | 2 +- configmgr/source/xcsparser.hxx | 2 +- configmgr/source/xcuparser.cxx | 8 +- configmgr/source/xcuparser.hxx | 4 +- desktop/source/migration/migration.cxx | 94 +++++++++++++++++-- offapi/com/sun/star/configuration/XUpdate.idl | 4 +- 17 files changed, 127 insertions(+), 75 deletions(-) diff --git a/configmgr/Library_configmgr.mk b/configmgr/Library_configmgr.mk index 1c4b216a3740..11bba5f0f4cf 100644 --- a/configmgr/Library_configmgr.mk +++ b/configmgr/Library_configmgr.mk @@ -51,10 +51,6 @@ $(eval $(call gb_Library_use_externals,configmgr, \ dconf \ )) -$(eval $(call gb_Library_use_custom_headers,configmgr, \ - officecfg/registry \ -)) - $(eval $(call gb_Library_use_sdk_api,configmgr)) $(eval $(call gb_Library_use_libraries,configmgr, \ diff --git a/configmgr/source/components.cxx b/configmgr/source/components.cxx index 8d933d2c1651..3c35a258c12c 100644 --- a/configmgr/source/components.cxx +++ b/configmgr/source/components.cxx @@ -95,23 +95,23 @@ typedef std::vector< UnresolvedVectorItem > UnresolvedVector; void parseXcsFile( OUString const & url, int layer, Data & data, Partial const * partial, - Modifications * modifications, Additions * additions, OUString const & oldProductName) + Modifications * modifications, Additions * additions) { assert(partial == nullptr && modifications == nullptr && additions == nullptr); (void) partial; (void) modifications; (void) additions; bool ok = rtl::Reference< ParseManager >( - new ParseManager(url, oldProductName, new XcsParser(layer, data)))->parse(nullptr); + new ParseManager(url, new XcsParser(layer, data)))->parse(nullptr); assert(ok); (void) ok; // avoid warnings } void parseXcuFile( OUString const & url, int layer, Data & data, Partial const * partial, - Modifications * modifications, Additions * additions, OUString const & oldProductName) + Modifications * modifications, Additions * additions) { bool ok = rtl::Reference< ParseManager >( new ParseManager( - url, oldProductName, + url, new XcuParser(layer, data, partial, modifications, additions)))-> parse(nullptr); assert(ok); @@ -214,7 +214,7 @@ rtl::Reference< Node > Components::resolvePathRepresentation( const { return data_.resolvePathRepresentation( - pathRepresentation, OUString(), canonicRepresentation, path, finalizedLayer); + pathRepresentation, canonicRepresentation, path, finalizedLayer); } rtl::Reference< Node > Components::getTemplate(OUString const & fullName) const @@ -311,7 +311,7 @@ void Components::insertExtensionXcsFile( { int layer = getExtensionLayer(shared); try { - parseXcsFile(fileUri, layer, data_, nullptr, nullptr, nullptr, OUString()); + parseXcsFile(fileUri, layer, data_, nullptr, nullptr, nullptr); } catch (css::container::NoSuchElementException & e) { throw css::uno::RuntimeException( "insertExtensionXcsFile does not exist: " + e.Message); @@ -325,7 +325,7 @@ void Components::insertExtensionXcuFile( int layer = getExtensionLayer(shared) + 1; Additions * adds = data_.addExtensionXcuAdditions(fileUri, layer); try { - parseXcuFile(fileUri, layer, data_, nullptr, modifications, adds, OUString()); + parseXcuFile(fileUri, layer, data_, nullptr, modifications, adds); } catch (css::container::NoSuchElementException & e) { data_.removeExtensionXcuAdditions(fileUri); throw css::uno::RuntimeException( @@ -388,7 +388,7 @@ void Components::removeExtensionXcuFile( } void Components::insertModificationXcuFile( - OUString const & fileUri, OUString const & oldProductName, + OUString const & fileUri, std::set< OUString > const & includedPaths, std::set< OUString > const & excludedPaths, Modifications * modifications) @@ -397,7 +397,7 @@ void Components::insertModificationXcuFile( Partial part(includedPaths, excludedPaths); try { parseFileLeniently( - &parseXcuFile, fileUri, Data::NO_LAYER, &part, modifications, nullptr, oldProductName); + &parseXcuFile, fileUri, Data::NO_LAYER, &part, modifications, nullptr); } catch (const css::container::NoSuchElementException &) { TOOLS_WARN_EXCEPTION( "configmgr", @@ -553,7 +553,7 @@ Components::Components( } OUString aTempFileURL; if (dumpWindowsRegistry(&aTempFileURL, eType)) { - parseFileLeniently(&parseXcuFile, aTempFileURL, layer, nullptr, nullptr, nullptr, OUString()); + parseFileLeniently(&parseXcuFile, aTempFileURL, layer, nullptr, nullptr, nullptr); if (!getenv("SAL_CONFIG_WINREG_RETAIN_TMP")) osl::File::remove(aTempFileURL); } @@ -645,11 +645,11 @@ Components::~Components() void Components::parseFileLeniently( FileParser * parseFile, OUString const & url, int layer, Partial const * partial, Modifications * modifications, - Additions * additions, OUString const & oldProductName) + Additions * additions) { assert(parseFile != nullptr); try { - (*parseFile)(url, layer, data_, partial, modifications, additions, oldProductName); + (*parseFile)(url, layer, data_, partial, modifications, additions); } catch (const css::container::NoSuchElementException &) { throw; } catch (const css::uno::Exception &) { //TODO: more specific exception catching @@ -702,7 +702,7 @@ void Components::parseFiles( if (file.endsWith(extension)) { try { parseFileLeniently( - parseFile, stat.getFileURL(), layer, nullptr, nullptr, nullptr, OUString()); + parseFile, stat.getFileURL(), layer, nullptr, nullptr, nullptr); } catch (css::container::NoSuchElementException & e) { if (stat.getFileType() == osl::FileStatus::Link) { SAL_WARN("configmgr", "dangling link <" << stat.getFileURL() << ">"); @@ -728,7 +728,7 @@ void Components::parseFileList( adds = data_.addExtensionXcuAdditions(url, layer); } try { - parseFileLeniently(parseFile, url, layer, nullptr, nullptr, adds, OUString()); + parseFileLeniently(parseFile, url, layer, nullptr, nullptr, adds); } catch (const css::container::NoSuchElementException &) { TOOLS_WARN_EXCEPTION("configmgr", "file does not exist"); if (adds != nullptr) { @@ -781,7 +781,7 @@ void Components::parseXcdFiles(int layer, OUString const & url) { rtl::Reference< ParseManager > manager; try { manager = new ParseManager( - stat.getFileURL(), OUString(), + stat.getFileURL(), new XcdParser(layer, processedDeps, data_)); } catch (css::container::NoSuchElementException & e) { if (stat.getFileType() == osl::FileStatus::Link) { @@ -865,7 +865,7 @@ void Components::parseResLayer(int layer, std::u16string_view url) { void Components::parseModificationLayer(int layer, OUString const & url) { try { - parseFileLeniently(&parseXcuFile, url, layer, nullptr, nullptr, nullptr, OUString()); + parseFileLeniently(&parseXcuFile, url, layer, nullptr, nullptr, nullptr); } catch (css::container::NoSuchElementException &) { SAL_INFO( "configmgr", "user registrymodifications.xcu does not (yet) exist"); diff --git a/configmgr/source/components.hxx b/configmgr/source/components.hxx index 87c9a1f7c7b4..5d7b6b5967ee 100644 --- a/configmgr/source/components.hxx +++ b/configmgr/source/components.hxx @@ -91,7 +91,6 @@ public: void insertModificationXcuFile( OUString const & fileUri, - OUString const & oldProductName, std::set< OUString > const & includedPaths, std::set< OUString > const & excludedPaths, Modifications * modifications); @@ -105,7 +104,7 @@ private: typedef void FileParser( OUString const &, int, Data &, Partial const *, Modifications *, - Additions *, OUString const &); + Additions *); public: explicit Components( css::uno::Reference< css::uno::XComponentContext > const & context); @@ -116,7 +115,7 @@ private: void parseFileLeniently( FileParser * parseFile, OUString const & url, int layer, Partial const * partial, Modifications * modifications, - Additions * additions, OUString const & oldProductName); + Additions * additions); void parseFiles( int layer, OUString const & extension, FileParser * parseFile, diff --git a/configmgr/source/data.cxx b/configmgr/source/data.cxx index fd4ecb0f3b0b..f173ee1556fb 100644 --- a/configmgr/source/data.cxx +++ b/configmgr/source/data.cxx @@ -24,7 +24,6 @@ #include #include -#include #include #include #include @@ -180,7 +179,7 @@ bool Data::equalTemplateNames( Data::Data(): root_(new RootNode) {} rtl::Reference< Node > Data::resolvePathRepresentation( - OUString const & pathRepresentation, OUString const & oldProductName, + OUString const & pathRepresentation, OUString * canonicRepresentation, std::vector * path, int * finalizedLayer) const { @@ -250,21 +249,6 @@ rtl::Reference< Node > Data::resolvePathRepresentation( throw css::uno::RuntimeException( "bad path " + pathRepresentation); } - // The name of the product name related color schemes need to be replaced - // with the new product name during migration. - if (path != nullptr && path->back() == "ColorSchemes") - { - OUString aDarkTheme = " Dark"; - if (seg.equals(oldProductName)) - { - seg = officecfg::Setup::Product::ooName::get(); - } - else if (seg.equals(oldProductName + aDarkTheme)) - { - seg = officecfg::Setup::Product::ooName::get() + aDarkTheme; - } - } - // For backwards compatibility, allow set members to be accessed with // simple path segments, like group members: p = p->getMember(seg); diff --git a/configmgr/source/data.hxx b/configmgr/source/data.hxx index e7af062efff8..c3614e6435da 100644 --- a/configmgr/source/data.hxx +++ b/configmgr/source/data.hxx @@ -67,7 +67,7 @@ struct Data { Data(); rtl::Reference< Node > resolvePathRepresentation( - OUString const & pathRepresentation, OUString const & oldProductName, + OUString const & pathRepresentation, OUString * canonicRepresentation, std::vector * path, int * finalizedLayer) const; diff --git a/configmgr/source/parsemanager.cxx b/configmgr/source/parsemanager.cxx index fbce29f74459..36dea373dca1 100644 --- a/configmgr/source/parsemanager.cxx +++ b/configmgr/source/parsemanager.cxx @@ -33,8 +33,8 @@ namespace configmgr { ParseManager::ParseManager( - OUString const & url, OUString const & oldProductName, rtl::Reference< Parser > const & parser) - : reader_(url), oldProductName_(oldProductName), parser_(parser), itemNamespaceId_(-1) + OUString const & url, rtl::Reference< Parser > const & parser) + : reader_(url), parser_(parser), itemNamespaceId_(-1) { assert(parser.is()); int id; @@ -64,7 +64,7 @@ bool ParseManager::parse(std::set< OUString > const * existingDependencies) { { case xmlreader::XmlReader::Result::Begin: if (!parser_->startElement( - reader_, oldProductName_, itemNamespaceId_, itemData_, existingDependencies)) + reader_, itemNamespaceId_, itemData_, existingDependencies)) { SAL_INFO("configmgr", "parsing " << reader_.getUrl() << " took " << (osl_getGlobalTimer() - startTime) << " ms, fail"); return false; diff --git a/configmgr/source/parsemanager.hxx b/configmgr/source/parsemanager.hxx index eb91cf201ee6..fba61ec07b94 100644 --- a/configmgr/source/parsemanager.hxx +++ b/configmgr/source/parsemanager.hxx @@ -36,7 +36,7 @@ class Parser; class ParseManager: public salhelper::SimpleReferenceObject { public: ParseManager( - OUString const & url, OUString const & oldProductName, rtl::Reference< Parser > const & parser); + OUString const & url, rtl::Reference< Parser > const & parser); bool parse(std::set< OUString > const * existingDependencies); @@ -46,7 +46,6 @@ private: virtual ~ParseManager() override; xmlreader::XmlReader reader_; - OUString oldProductName_; rtl::Reference< Parser > parser_; xmlreader::Span itemData_; int itemNamespaceId_; diff --git a/configmgr/source/parser.hxx b/configmgr/source/parser.hxx index d6ee654f67bf..a3984203c583 100644 --- a/configmgr/source/parser.hxx +++ b/configmgr/source/parser.hxx @@ -35,8 +35,8 @@ public: virtual xmlreader::XmlReader::Text getTextMode() = 0; virtual bool startElement( - xmlreader::XmlReader & reader, OUString const & oldProductName, int nsId, - xmlreader::Span const & name, std::set< OUString > const * existingDependencies) = 0; + xmlreader::XmlReader & reader, int nsId, xmlreader::Span const & name, + std::set< OUString > const * existingDependencies) = 0; virtual void endElement(xmlreader::XmlReader const & reader) = 0; diff --git a/configmgr/source/update.cxx b/configmgr/source/update.cxx index 4033e9dc9caf..1cc2a06fe2a2 100644 --- a/configmgr/source/update.cxx +++ b/configmgr/source/update.cxx @@ -76,7 +76,6 @@ private: virtual void SAL_CALL insertModificationXcuFile( OUString const & fileUri, - OUString const & oldProductName, css::uno::Sequence< OUString > const & includedPaths, css::uno::Sequence< OUString > const & excludedPaths) override; @@ -122,7 +121,6 @@ void Service::removeExtensionXcuFile(OUString const & fileUri) void Service::insertModificationXcuFile( OUString const & fileUri, - OUString const & oldProductName, css::uno::Sequence< OUString > const & includedPaths, css::uno::Sequence< OUString > const & excludedPaths) { @@ -132,7 +130,7 @@ void Service::insertModificationXcuFile( Components & components = Components::getSingleton(context_); Modifications mods; components.insertModificationXcuFile( - fileUri, oldProductName, seqToSet(includedPaths), seqToSet(excludedPaths), &mods); + fileUri, seqToSet(includedPaths), seqToSet(excludedPaths), &mods); components.initGlobalBroadcaster( mods, rtl::Reference< RootAccess >(), &bc); } diff --git a/configmgr/source/xcdparser.cxx b/configmgr/source/xcdparser.cxx index bd4be2de7482..a069c6b99c6f 100644 --- a/configmgr/source/xcdparser.cxx +++ b/configmgr/source/xcdparser.cxx @@ -50,14 +50,14 @@ xmlreader::XmlReader::Text XcdParser::getTextMode() { } bool XcdParser::startElement( - xmlreader::XmlReader & reader, OUString const & oldProductName, int nsId, xmlreader::Span const & name, + xmlreader::XmlReader & reader, int nsId, xmlreader::Span const & name, std::set< OUString > const * existingDependencies) { if (nestedParser_.is()) { assert(nesting_ != LONG_MAX); ++nesting_; return nestedParser_->startElement( - reader, oldProductName, nsId, name, existingDependencies); + reader, nsId, name, existingDependencies); } switch (state_) { case STATE_START: @@ -123,7 +123,7 @@ bool XcdParser::startElement( nestedParser_ = new XcsParser(layer_, data_); nesting_ = 1; return nestedParser_->startElement( - reader, oldProductName, nsId, name, existingDependencies); + reader, nsId, name, existingDependencies); } if (nsId == ParseManager::NAMESPACE_OOR && (name == "component-data" || name == "items")) @@ -131,7 +131,7 @@ bool XcdParser::startElement( nestedParser_ = new XcuParser(layer_ + 1, data_, nullptr, nullptr, nullptr); nesting_ = 1; return nestedParser_->startElement( - reader, oldProductName, nsId, name, existingDependencies); + reader, nsId, name, existingDependencies); } break; default: // STATE_DEPENDENCY diff --git a/configmgr/source/xcdparser.hxx b/configmgr/source/xcdparser.hxx index 883a0aa980bb..1ca32931ea48 100644 --- a/configmgr/source/xcdparser.hxx +++ b/configmgr/source/xcdparser.hxx @@ -47,7 +47,7 @@ private: virtual xmlreader::XmlReader::Text getTextMode() override; virtual bool startElement( - xmlreader::XmlReader & reader, OUString const & oldProductName, int nsId, xmlreader::Span const & name, + xmlreader::XmlReader & reader, int nsId, xmlreader::Span const & name, std::set< OUString > const * existingDependencies) override; virtual void endElement(xmlreader::XmlReader const & reader) override; diff --git a/configmgr/source/xcsparser.cxx b/configmgr/source/xcsparser.cxx index c3006d0258f3..947792c0a62e 100644 --- a/configmgr/source/xcsparser.cxx +++ b/configmgr/source/xcsparser.cxx @@ -119,7 +119,7 @@ xmlreader::XmlReader::Text XcsParser::getTextMode() { } bool XcsParser::startElement( - xmlreader::XmlReader & reader, OUString const & /*oldProductName*/, int nsId, xmlreader::Span const & name, + xmlreader::XmlReader & reader, int nsId, xmlreader::Span const & name, std::set< OUString > const * /*existingDependencies*/) { if (valueParser_.startElement(reader, nsId, name)) { diff --git a/configmgr/source/xcsparser.hxx b/configmgr/source/xcsparser.hxx index 385f114dda57..f2c5c77429d6 100644 --- a/configmgr/source/xcsparser.hxx +++ b/configmgr/source/xcsparser.hxx @@ -50,7 +50,7 @@ private: virtual xmlreader::XmlReader::Text getTextMode() override; virtual bool startElement( - xmlreader::XmlReader & reader, OUString const & /*oldProductName*/, int nsId, xmlreader::Span const & name, + xmlreader::XmlReader & reader, int nsId, xmlreader::Span const & name, std::set< OUString > const * existingDependencies) override; virtual void endElement(xmlreader::XmlReader const & reader) override; diff --git a/configmgr/source/xcuparser.cxx b/configmgr/source/xcuparser.cxx index 696d124127ea..af21518abd78 100644 --- a/configmgr/source/xcuparser.cxx +++ b/configmgr/source/xcuparser.cxx @@ -67,7 +67,7 @@ xmlreader::XmlReader::Text XcuParser::getTextMode() { } bool XcuParser::startElement( - xmlreader::XmlReader & reader, OUString const & oldProductName, int nsId, xmlreader::Span const & name, + xmlreader::XmlReader & reader, int nsId, xmlreader::Span const & name, std::set< OUString > const * /*existingDependencies*/) { if (valueParser_.startElement(reader, nsId, name)) { @@ -95,7 +95,7 @@ bool XcuParser::startElement( "bad items node member <" + name.convertFromUtf8() + "> in " + reader.getUrl()); } - handleItem(reader, oldProductName); + handleItem(reader); } else { switch (state_.top().node->kind()) { case Node::KIND_PROPERTY: @@ -312,7 +312,7 @@ void XcuParser::handleComponentData(xmlreader::XmlReader & reader) { state_.push(State::Modify(node)); } -void XcuParser::handleItem(xmlreader::XmlReader & reader, OUString const & oldProductName) { +void XcuParser::handleItem(xmlreader::XmlReader & reader) { xmlreader::Span attrPath; for (;;) { int attrNsId; @@ -332,7 +332,7 @@ void XcuParser::handleItem(xmlreader::XmlReader & reader, OUString const & oldPr int finalizedLayer; rtl::Reference< Node > node( data_.resolvePathRepresentation( - path, oldProductName, nullptr, &path_, &finalizedLayer)); + path, nullptr, &path_, &finalizedLayer)); if (!node.is()) { SAL_WARN( "configmgr", diff --git a/configmgr/source/xcuparser.hxx b/configmgr/source/xcuparser.hxx index 19b50e144164..e50b7b5a0fc8 100644 --- a/configmgr/source/xcuparser.hxx +++ b/configmgr/source/xcuparser.hxx @@ -61,7 +61,7 @@ private: virtual xmlreader::XmlReader::Text getTextMode() override; virtual bool startElement( - xmlreader::XmlReader & reader, OUString const & oldProductName, int nsId, xmlreader::Span const & name, + xmlreader::XmlReader & reader, int nsId, xmlreader::Span const & name, std::set< OUString > const * existingDependencies) override; virtual void endElement(xmlreader::XmlReader const & reader) override; @@ -75,7 +75,7 @@ private: void handleComponentData(xmlreader::XmlReader & reader); - void handleItem(xmlreader::XmlReader & reader, OUString const & oldProductName); + void handleItem(xmlreader::XmlReader & reader); void handlePropValue(xmlreader::XmlReader & reader, PropertyNode * prop); diff --git a/desktop/source/migration/migration.cxx b/desktop/source/migration/migration.cxx index c8f00d03bbbb..162941bfd0ea 100644 --- a/desktop/source/migration/migration.cxx +++ b/desktop/source/migration/migration.cxx @@ -36,12 +36,14 @@ #include #include #include +#include #include #include #include #include #include +#include #include #include #include @@ -616,6 +618,55 @@ bool getComponent(OUString const & path, OUString * component) return true; } +void renameMigratedSetElementTo( + css::uno::Reference const & set, OUString const & currentName, + OUString const & migratedName) +{ + // To avoid unexpected data loss, the code is careful to only rename from currentName to + // migratedName in the expected case where the currentName element exists and the migratedName + // element doesn't exist: + auto const hasCurrent = set->hasByName(currentName); + auto const hasMigrated = set->hasByName(migratedName); + if (hasCurrent && !hasMigrated) { + auto const elem = set->getByName(currentName); + set->removeByName(currentName); + set->insertByName(migratedName, elem); + } else { + SAL_INFO_IF(!hasCurrent, "desktop.migration", "unexpectedly missing " << currentName); + SAL_INFO_IF(hasMigrated, "desktop.migration", "unexpectedly present " << migratedName); + } +} + +void renameMigratedSetElementBack( + css::uno::Reference const & set, OUString const & currentName, + OUString const & migratedName) +{ + // To avoid unexpected data loss, the code is careful to ensure that in the end a currentName + // element exists, creating it from a template if the migratedName element had unexpectedly gone + // missing: + auto const hasMigrated = set->hasByName(migratedName); + css::uno::Any elem; + if (hasMigrated) { + elem = set->getByName(migratedName); + set->removeByName(migratedName); + } else { + SAL_INFO("desktop.migration", "unexpected loss of " << migratedName); + elem <<= css::uno::Reference( + set, css::uno::UNO_QUERY_THROW)->createInstance(); + } + if (set->hasByName(currentName)) { + SAL_INFO("desktop.migration", "unexpected reappearance of " << currentName); + if (hasMigrated) { + SAL_INFO( + "desktop.migration", + "reappeared " << currentName << " overwritten with " << migratedName); + set->replaceByName(currentName, elem); + } + } else { + set->insertByName(currentName, elem); + } +} + } void MigrationImpl::copyConfig() @@ -639,10 +690,6 @@ void MigrationImpl::copyConfig() // check if the shared registrymodifications.xcu file exists bool bRegistryModificationsXcuExists = false; OUString regFilePath = m_aInfo.userdata + "/user/registrymodifications.xcu"; - OUString sMigratedProductName = m_aInfo.productname; - // remove version number from the end of product name if there’s one - if (isdigit(sMigratedProductName[sMigratedProductName.getLength() - 1])) - sMigratedProductName = (sMigratedProductName.copy(0, m_aInfo.productname.getLength() - 1)).trim(); File regFile(regFilePath); ::osl::FileBase::RC nError = regFile.open(osl_File_OpenFlag_Read); if ( nError == ::osl::FileBase::E_None ) { @@ -650,6 +697,30 @@ void MigrationImpl::copyConfig() regFile.close(); } + // If the to-be-migrated data contains modifications of + // /org.openoffice.Office.UI/ColorScheme/ColorSchemes set elements named after the migrated + // product name, those modifications must instead be made to the corresponding set elements + // named after the current product name. However, if the current configuration data does not + // contain those old-named set elements at all, their modification data would silently be + // ignored by css.configuration.XUpdate::insertModificationXcuFile. So temporarily rename any + // new-named set elements to their old-named counterparts here, and rename them back again down + // below after importing the migrated data: + OUString sProductName = utl::ConfigManager::getProductName(); + OUString sProductNameDark = sProductName + " Dark"; + OUString sMigratedProductName = m_aInfo.productname; + // remove version number from the end of product name if there’s one + if (isdigit(sMigratedProductName[sMigratedProductName.getLength() - 1])) + sMigratedProductName = (sMigratedProductName.copy(0, m_aInfo.productname.getLength() - 1)).trim(); + OUString sMigratedProductNameDark = sMigratedProductName + " Dark"; + auto const tempRename = sMigratedProductName != sProductName; + if (tempRename) { + auto const batch = comphelper::ConfigurationChanges::create(); + auto const schemes = officecfg::Office::UI::ColorScheme::ColorSchemes::get(batch); + renameMigratedSetElementTo(schemes, sProductName, sMigratedProductName); + renameMigratedSetElementTo(schemes, sProductNameDark, sMigratedProductNameDark); + batch->commit(); + } + for (auto const& comp : comps) { if (!comp.second.includedPaths.empty()) { @@ -680,7 +751,6 @@ void MigrationImpl::copyConfig() comphelper::getProcessComponentContext())-> insertModificationXcuFile( regFilePath, - sMigratedProductName, comphelper::containerToSequence(comp.second.includedPaths), comphelper::containerToSequence(comp.second.excludedPaths)); @@ -690,6 +760,13 @@ void MigrationImpl::copyConfig() next: ; } + if (tempRename) { + auto const batch = comphelper::ConfigurationChanges::create(); + auto const schemes = officecfg::Office::UI::ColorScheme::ColorSchemes::get(batch); + renameMigratedSetElementBack(schemes, sProductName, sMigratedProductName); + renameMigratedSetElementBack(schemes, sProductNameDark, sMigratedProductNameDark); + batch->commit(); + } // checking the migrated (product name related) color scheme name, and replace it to the current version scheme name try { @@ -698,17 +775,16 @@ next: getConfigAccess("org.openoffice.Office.UI/ColorScheme", true), uno::UNO_QUERY_THROW); if (aPropertySet->getPropertyValue("CurrentColorScheme") >>= sMigratedColorScheme) { - OUString aDarkTheme = " Dark"; if (sMigratedColorScheme.equals(sMigratedProductName)) { aPropertySet->setPropertyValue("CurrentColorScheme", - uno::Any(utl::ConfigManager::getProductName())); + uno::Any(sProductName)); uno::Reference(aPropertySet, uno::UNO_QUERY_THROW)->commitChanges(); } - else if (sMigratedColorScheme.equals(sMigratedProductName + aDarkTheme)) + else if (sMigratedColorScheme.equals(sMigratedProductNameDark)) { aPropertySet->setPropertyValue("CurrentColorScheme", - uno::Any(utl::ConfigManager::getProductName() + aDarkTheme)); + uno::Any(sProductNameDark)); uno::Reference(aPropertySet, uno::UNO_QUERY_THROW)->commitChanges(); } } diff --git a/offapi/com/sun/star/configuration/XUpdate.idl b/offapi/com/sun/star/configuration/XUpdate.idl index 8035c9f674ac..0a0f25a2e6dc 100644 --- a/offapi/com/sun/star/configuration/XUpdate.idl +++ b/offapi/com/sun/star/configuration/XUpdate.idl @@ -35,8 +35,8 @@ interface XUpdate { // argument void insertModificationXcuFile( - [in] string fileUri, [in] string oldProductName, - [in] sequence< string > includedPaths, [in] sequence< string > excludedPaths); + [in] string fileUri, [in] sequence< string > includedPaths, + [in] sequence< string > excludedPaths); }; }; }; }; };