From 897a303ec7101b0f3d15514837adf3de9fc0748d Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Thu, 6 May 2021 21:03:02 +0100 Subject: [PATCH] Deprecate PluginInterface::IsLightMaster() and PluginInterface::IsValidAsLightMaster() In favour of IsLightPlugin() and IsValidAsLightPlugin() respectively. The new functions are identical to the old besides their names, which now more clearly indicate that plugins can be light without being masters. --- include/loot/plugin_interface.h | 20 +++++++++++++++-- src/api/plugin.cpp | 22 +++++++++++++------ src/api/plugin.h | 6 +++++ src/api/sorting/plugin_sorting_data.cpp | 2 +- src/tests/api/internals/plugin_test.h | 14 +++++++----- .../sorting/plugin_sorting_data_test.h | 6 ++--- 6 files changed, 51 insertions(+), 19 deletions(-) diff --git a/include/loot/plugin_interface.h b/include/loot/plugin_interface.h index 8303a7a2..aa7f972e 100644 --- a/include/loot/plugin_interface.h +++ b/include/loot/plugin_interface.h @@ -91,18 +91,34 @@ public: virtual bool IsMaster() const = 0; /** - * Check if the plugin is a light master. - * @return True if plugin is a light master, false otherwise. + * Check if the plugin is a light plugin. + * @return True if plugin is a light plugin, false otherwise. + * @deprecated Use IsLightPlugin() instead. */ + [[deprecated("Use IsLightPlugin() instead.")]] virtual bool IsLightMaster() const = 0; + /** + * Check if the plugin is a light plugin. + * @return True if plugin is a light plugin, false otherwise. + */ + virtual bool IsLightPlugin() const = 0; + /** * Check if the plugin is or would be valid as a light master. * @return True if the plugin is a valid light master or would be a valid * light master, false otherwise. */ + [[deprecated("Use IsValidAsLightPlugin() instead.")]] virtual bool IsValidAsLightMaster() const = 0; + /** + * Check if the plugin is or would be valid as a light master. + * @return True if the plugin is a valid light master or would be a valid + * light master, false otherwise. + */ + virtual bool IsValidAsLightPlugin() const = 0; + /** * Check if the plugin contains any records other than its TES4 header. * @return True if the plugin only contains a TES4 header, false otherwise. diff --git a/src/api/plugin.cpp b/src/api/plugin.cpp index b079eb37..ece4d379 100644 --- a/src/api/plugin.cpp +++ b/src/api/plugin.cpp @@ -136,19 +136,27 @@ bool Plugin::IsMaster() const { } bool Plugin::IsLightMaster() const { - bool isLightMaster; - auto ret = esp_plugin_is_light_master(esPlugin.get(), &isLightMaster); + return IsLightPlugin(); +} + +bool Plugin::IsLightPlugin() const { + bool isLightPlugin; + auto ret = esp_plugin_is_light_plugin(esPlugin.get(), &isLightPlugin); if (ret != ESP_OK) { throw FileAccessError(name_ + " : esplugin error code: " + std::to_string(ret)); } - return isLightMaster; + return isLightPlugin; } bool Plugin::IsValidAsLightMaster() const { + return IsValidAsLightPlugin(); +} + +bool Plugin::IsValidAsLightPlugin() const { bool isValid; - auto ret = esp_plugin_is_valid_as_light_master(esPlugin.get(), &isValid); + auto ret = esp_plugin_is_valid_as_light_plugin(esPlugin.get(), &isValid); if (ret != ESP_OK) { throw FileAccessError(name_ + " : esplugin error code: " + std::to_string(ret)); @@ -422,13 +430,13 @@ bool hasPluginFileExtension(std::string filename, GameType gameType) { filename = filename.substr(0, filename.length() - 6); } - bool espOrEsm = boost::iends_with(filename, ".esp") || + bool isEspOrEsm = boost::iends_with(filename, ".esp") || boost::iends_with(filename, ".esm"); - bool lightMaster = + bool isEsl = (gameType == GameType::fo4 || gameType == GameType::fo4vr || gameType == GameType::tes5se || gameType == GameType::tes5vr) && boost::iends_with(filename, ".esl"); - return espOrEsm || lightMaster; + return isEspOrEsm || isEsl; } } diff --git a/src/api/plugin.h b/src/api/plugin.h index b481cb97..0ec246bf 100644 --- a/src/api/plugin.h +++ b/src/api/plugin.h @@ -56,8 +56,14 @@ public: std::optional GetCRC() const; bool IsMaster() const; + + [[deprecated("Use IsLightPlugin() instead.")]] bool IsLightMaster() const; + bool IsLightPlugin() const; + + [[deprecated("Use IsValidAsLightPlugin() instead.")]] bool IsValidAsLightMaster() const; + bool IsValidAsLightPlugin() const; bool IsEmpty() const; bool LoadsArchive() const; bool DoFormIDsOverlap(const PluginInterface& plugin) const; diff --git a/src/api/sorting/plugin_sorting_data.cpp b/src/api/sorting/plugin_sorting_data.cpp index 9e45bf62..23bd2c5a 100644 --- a/src/api/sorting/plugin_sorting_data.cpp +++ b/src/api/sorting/plugin_sorting_data.cpp @@ -103,7 +103,7 @@ PluginSortingData::PluginSortingData( std::string PluginSortingData::GetName() const { return plugin_.GetName(); } bool PluginSortingData::IsMaster() const { - return plugin_.IsMaster() || (plugin_.IsLightMaster() && + return plugin_.IsMaster() || (plugin_.IsLightPlugin() && !boost::iends_with(plugin_.GetName(), ".esp")); } diff --git a/src/tests/api/internals/plugin_test.h b/src/tests/api/internals/plugin_test.h index d2119fd1..00758e12 100644 --- a/src/tests/api/internals/plugin_test.h +++ b/src/tests/api/internals/plugin_test.h @@ -150,7 +150,9 @@ public: bool IsMaster() const { return false; } bool IsLightMaster() const { return false; } + bool IsLightPlugin() const { return false; } bool IsValidAsLightMaster() const { return false; } + bool IsValidAsLightPlugin() const { return false; } bool IsEmpty() const { return false; } bool LoadsArchive() const { return false; } bool DoFormIDsOverlap(const PluginInterface& plugin) const { return true; } @@ -254,7 +256,7 @@ TEST_P(PluginTest, loadingANonMasterPluginShouldReadTheMasterFlagAsFalse) { TEST_P( PluginTest, - isLightMasterShouldBeTrueForAPluginWithEslFileExtensionForFallout4AndSkyrimSeAndFalseOtherwise) { + isLightPluginShouldBeTrueForAPluginWithEslFileExtensionForFallout4AndSkyrimSeAndFalseOtherwise) { Plugin plugin1( game_.Type(), game_.GetCache(), game_.DataPath() / blankEsm, true); Plugin plugin2(game_.Type(), @@ -264,10 +266,10 @@ TEST_P( Plugin plugin3( game_.Type(), game_.GetCache(), game_.DataPath() / blankEsl, true); - EXPECT_FALSE(plugin1.IsLightMaster()); - EXPECT_FALSE(plugin2.IsLightMaster()); + EXPECT_FALSE(plugin1.IsLightPlugin()); + EXPECT_FALSE(plugin2.IsLightPlugin()); EXPECT_EQ(GetParam() == GameType::fo4 || GetParam() == GameType::tes5se, - plugin3.IsLightMaster()); + plugin3.IsLightPlugin()); } TEST_P(PluginTest, loadingAPluginWithMastersShouldReadThemCorrectly) { @@ -410,10 +412,10 @@ TEST_P(PluginTest, isValidShouldReturnFalseForAnEmptyFile) { TEST_P( PluginTest, - isValidAsLightMasterShouldReturnTrueOnlyForASkyrimSEOrFallout4PluginWithNewFormIdsBetween0x800And0xFFFInclusive) { + isValidAsLightPluginShouldReturnTrueOnlyForASkyrimSEOrFallout4PluginWithNewFormIdsBetween0x800And0xFFFInclusive) { bool valid = Plugin(game_.Type(), game_.GetCache(), game_.DataPath() / blankEsm, true) - .IsValidAsLightMaster(); + .IsValidAsLightPlugin(); if (GetParam() == GameType::fo4 || GetParam() == GameType::tes5se) { EXPECT_TRUE(valid); } else { diff --git a/src/tests/api/internals/sorting/plugin_sorting_data_test.h b/src/tests/api/internals/sorting/plugin_sorting_data_test.h index 8185c789..200778f1 100644 --- a/src/tests/api/internals/sorting/plugin_sorting_data_test.h +++ b/src/tests/api/internals/sorting/plugin_sorting_data_test.h @@ -78,7 +78,7 @@ INSTANTIATE_TEST_CASE_P(, GameType::fo4)); TEST_P(PluginSortingDataTest, - lightMasterFlaggedEspFilesShouldNotBeTreatedAsMasters) { + lightFlaggedEspFilesShouldNotBeTreatedAsMasters) { if (GetParam() == GameType::fo4 || GetParam() == GameType::tes5se) { ASSERT_NO_THROW( std::filesystem::copy(dataPath / blankEsl, dataPath / blankEslEsp)); @@ -114,14 +114,14 @@ TEST_P(PluginSortingDataTest, game_.GetCache()->GetPlugins()); EXPECT_TRUE(lightMaster.IsMaster()); - auto lightMasterEsp = PluginSortingData( + auto lightPlugin = PluginSortingData( *dynamic_cast(game_.GetPlugin(blankEslEsp).get()), PluginMetadata(), PluginMetadata(), getLoadOrder(), game_.Type(), game_.GetCache()->GetPlugins()); - EXPECT_FALSE(lightMasterEsp.IsMaster()); + EXPECT_FALSE(lightPlugin.IsMaster()); } }