mirror of
https://github.com/loot/libloot-python.git
synced 2026-07-27 14:14:13 -07:00
Fix get_plugin_cleanliness never returning dirty
This commit is contained in:
+18
-17
@@ -57,26 +57,27 @@ PluginTags GetPluginTags(const std::shared_ptr<DatabaseInterface> db, const std:
|
|||||||
PluginCleanliness GetPluginCleanliness(const std::shared_ptr<DatabaseInterface> db, const std::string& plugin, bool evaluateConditions) {
|
PluginCleanliness GetPluginCleanliness(const std::shared_ptr<DatabaseInterface> db, const std::string& plugin, bool evaluateConditions) {
|
||||||
auto metadata = db->GetPluginMetadata(plugin, true, evaluateConditions);
|
auto metadata = db->GetPluginMetadata(plugin, true, evaluateConditions);
|
||||||
|
|
||||||
if (metadata.has_value()) {
|
if (!metadata.has_value()) {
|
||||||
if (metadata.value().GetDirtyInfo().empty()) {
|
return PluginCleanliness::unknown;
|
||||||
if (metadata.value().GetCleanInfo().empty()) {
|
}
|
||||||
return PluginCleanliness::unknown;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return PluginCleanliness::clean;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (!metadata.value().GetCleanInfo().empty()) {
|
|
||||||
return PluginCleanliness::unknown;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const auto& info : metadata.value().GetDirtyInfo()) {
|
auto dirtyInfo = metadata.value().GetDirtyInfo();
|
||||||
if (info.ChooseInfo("en").GetText().find("Do not clean") != std::string::npos) {
|
auto cleanInfo = metadata.value().GetCleanInfo();
|
||||||
return PluginCleanliness::do_not_clean;
|
|
||||||
}
|
if (dirtyInfo.empty() == cleanInfo.empty()) {
|
||||||
|
return PluginCleanliness::unknown;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!cleanInfo.empty()) {
|
||||||
|
return PluginCleanliness::clean;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const auto& info : dirtyInfo) {
|
||||||
|
if (info.ChooseInfo("en").GetText().find("Do not clean") != std::string::npos) {
|
||||||
|
return PluginCleanliness::do_not_clean;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return PluginCleanliness::unknown;
|
return PluginCleanliness::dirty;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,3 +28,27 @@ plugins:
|
|||||||
- Scripts
|
- Scripts
|
||||||
- Stats
|
- Stats
|
||||||
- -C.Water
|
- -C.Water
|
||||||
|
|
||||||
|
- name: clean_and_dirty.esp
|
||||||
|
dirty:
|
||||||
|
- crc: 0xDEADBEEF
|
||||||
|
util: '[TES4Edit v4.0.0](https://www.nexusmods.com/oblivion/mods/11536)'
|
||||||
|
clean:
|
||||||
|
- crc: 0xFEEDFACE
|
||||||
|
util: 'TES4Edit v4.0.0'
|
||||||
|
|
||||||
|
- name: clean.esp
|
||||||
|
clean:
|
||||||
|
- crc: 0xFEEDFACE
|
||||||
|
util: 'TES4Edit v4.0.0'
|
||||||
|
|
||||||
|
- name: dirty.esp
|
||||||
|
dirty:
|
||||||
|
- crc: 0xDEADBEEF
|
||||||
|
util: '[TES4Edit v4.0.0](https://www.nexusmods.com/oblivion/mods/11536)'
|
||||||
|
|
||||||
|
- name: do_not_clean.esp
|
||||||
|
dirty:
|
||||||
|
- crc: 0xDEADBEEF
|
||||||
|
util: '[TES4Edit v4.0.0](https://www.nexusmods.com/oblivion/mods/11536)'
|
||||||
|
info: 'Do not clean. This plugin is intentionally left dirty.'
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ from loot_api import WrapperVersion
|
|||||||
from loot_api import GameType
|
from loot_api import GameType
|
||||||
from loot_api import SimpleMessage
|
from loot_api import SimpleMessage
|
||||||
from loot_api import MessageType
|
from loot_api import MessageType
|
||||||
|
from loot_api import PluginCleanliness
|
||||||
from loot_api import create_game_handle
|
from loot_api import create_game_handle
|
||||||
from loot_api import is_compatible
|
from loot_api import is_compatible
|
||||||
from loot_api import set_logging_callback
|
from loot_api import set_logging_callback
|
||||||
@@ -121,6 +122,40 @@ class TestDatabaseInterface(GameFixture):
|
|||||||
self.assertEqual(messages[0].type, MessageType.error)
|
self.assertEqual(messages[0].type, MessageType.error)
|
||||||
self.assertEqual(messages[0].text, u'This must not be activated. However, it can be useful when porting Oblivion mods to Nehrim.')
|
self.assertEqual(messages[0].text, u'This must not be activated. However, it can be useful when porting Oblivion mods to Nehrim.')
|
||||||
|
|
||||||
|
def test_get_plugin_cleanliness_should_be_unknown_if_no_dirty_or_clean_metadata_exists(self):
|
||||||
|
self.db.load_lists(self.masterlist_path, u'')
|
||||||
|
|
||||||
|
cleanliness = self.db.get_plugin_cleanliness(u'unknown.esp')
|
||||||
|
|
||||||
|
self.assertEqual(cleanliness, PluginCleanliness.unknown)
|
||||||
|
|
||||||
|
def test_get_plugin_cleanliness_should_be_unknown_if_dirty_and_clean_metadata_exists(self):
|
||||||
|
self.db.load_lists(self.masterlist_path, u'')
|
||||||
|
|
||||||
|
cleanliness = self.db.get_plugin_cleanliness(u'clean_and_dirty.esp')
|
||||||
|
|
||||||
|
self.assertEqual(cleanliness, PluginCleanliness.unknown)
|
||||||
|
|
||||||
|
def test_get_plugin_cleanliness_should_be_clean_if_only_clean_metadata_exists(self):
|
||||||
|
self.db.load_lists(self.masterlist_path, u'')
|
||||||
|
|
||||||
|
cleanliness = self.db.get_plugin_cleanliness(u'clean.esp')
|
||||||
|
|
||||||
|
self.assertEqual(cleanliness, PluginCleanliness.clean)
|
||||||
|
|
||||||
|
def test_get_plugin_cleanliness_should_be_dirty_if_only_dirty_metadata_exists(self):
|
||||||
|
self.db.load_lists(self.masterlist_path, u'')
|
||||||
|
|
||||||
|
cleanliness = self.db.get_plugin_cleanliness(u'dirty.esp')
|
||||||
|
|
||||||
|
self.assertEqual(cleanliness, PluginCleanliness.dirty)
|
||||||
|
|
||||||
|
def test_get_plugin_cleanliness_should_be_do_not_clean_if_dirty_do_not_clean_info_exists(self):
|
||||||
|
self.db.load_lists(self.masterlist_path, u'')
|
||||||
|
|
||||||
|
cleanliness = self.db.get_plugin_cleanliness(u'do_not_clean.esp')
|
||||||
|
|
||||||
|
self.assertEqual(cleanliness, PluginCleanliness.do_not_clean)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|||||||
Reference in New Issue
Block a user