Add PluginInterface::GetHeaderVersion()

This commit is contained in:
Oliver Hamlet
2018-10-20 12:48:22 +01:00
parent a1f3b3a519
commit c147841543
4 changed files with 33 additions and 0 deletions
+8
View File
@@ -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.
*
+11
View File
@@ -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()) {
+1
View File
@@ -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;
+13
View File
@@ -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) {