mirror of
https://github.com/loot/libloot.git
synced 2026-07-27 14:16:01 -07:00
Add PluginInterface::GetHeaderVersion()
This commit is contained in:
@@ -45,6 +45,14 @@ public:
|
||||
*/
|
||||
virtual std::string GetName() const = 0;
|
||||
|
||||
/**
|
||||
* Get the value of the version field in the HEDR subrecord of the plugin's
|
||||
* TES4 record.
|
||||
* @return The value of the version field, or NaN if the field could not be
|
||||
* found.
|
||||
*/
|
||||
virtual float GetHeaderVersion() const = 0;
|
||||
|
||||
/**
|
||||
* Get the plugin's version number from its description field.
|
||||
*
|
||||
|
||||
@@ -131,6 +131,17 @@ Plugin::Plugin(const GameType gameType,
|
||||
|
||||
std::string Plugin::GetName() const { return name_; }
|
||||
|
||||
float Plugin::GetHeaderVersion() const {
|
||||
float version;
|
||||
auto ret = esp_plugin_header_version(esPlugin.get(), &version);
|
||||
if (ret != ESP_OK) {
|
||||
throw FileAccessError(name_ +
|
||||
" : esplugin error code: " + std::to_string(ret));
|
||||
}
|
||||
|
||||
return version;
|
||||
}
|
||||
|
||||
std::optional<std::string> Plugin::GetVersion() const {
|
||||
std::string version = Version(GetDescription()).AsString();
|
||||
if (version.empty()) {
|
||||
|
||||
@@ -50,6 +50,7 @@ public:
|
||||
const bool headerOnly);
|
||||
|
||||
std::string GetName() const;
|
||||
float GetHeaderVersion() const;
|
||||
std::optional<std::string> GetVersion() const;
|
||||
std::vector<std::string> GetMasters() const;
|
||||
std::set<Tag> GetBashTags() const;
|
||||
|
||||
@@ -125,6 +125,7 @@ private:
|
||||
class OtherPluginType : public PluginInterface {
|
||||
public:
|
||||
std::string GetName() const { return ""; }
|
||||
float GetHeaderVersion() const { return 0.0f; }
|
||||
std::optional<std::string> GetVersion() const { return std::nullopt; }
|
||||
std::vector<std::string> GetMasters() const {
|
||||
return std::vector<std::string>();
|
||||
@@ -173,6 +174,12 @@ TEST_P(PluginTest, loadingHeaderOnlyShouldReadHeaderData) {
|
||||
EXPECT_TRUE(plugin.IsMaster());
|
||||
EXPECT_FALSE(plugin.IsEmpty());
|
||||
EXPECT_EQ("5.0", plugin.GetVersion());
|
||||
|
||||
if (GetParam() == GameType::tes4) {
|
||||
EXPECT_FLOAT_EQ(0.8f, plugin.GetHeaderVersion());
|
||||
} else {
|
||||
EXPECT_FLOAT_EQ(0.94f, plugin.GetHeaderVersion());
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(PluginTest, loadingHeaderOnlyShouldNotReadFieldsOrCalculateCrc) {
|
||||
@@ -197,6 +204,12 @@ TEST_P(PluginTest, loadingWholePluginShouldReadHeaderData) {
|
||||
EXPECT_TRUE(plugin.IsMaster());
|
||||
EXPECT_FALSE(plugin.IsEmpty());
|
||||
EXPECT_EQ("5.0", plugin.GetVersion());
|
||||
|
||||
if (GetParam() == GameType::tes4) {
|
||||
EXPECT_FLOAT_EQ(0.8f, plugin.GetHeaderVersion());
|
||||
} else {
|
||||
EXPECT_FLOAT_EQ(0.94f, plugin.GetHeaderVersion());
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(PluginTest, loadingWholePluginShouldReadFields) {
|
||||
|
||||
Reference in New Issue
Block a user