mirror of
https://github.com/loot/libloot.git
synced 2026-07-27 14:16:01 -07:00
Add plugin data access functions to API
Plugin now inherits from PluginInterface, and Plugin objects are now immutable and cached in shared_ptr objects. The Plugin class no longer inherits from PluginMetadata, so file data and metadata are kept separate and only brought together temporarily when sorting. Sorting no longer evaluates conditions and checks install validity, so such actions need to be performed before sorting (the validity checking isn't, as the data gets reloaded just before sorting) or after it. It should now be possible to reimplement the GUI using the API, though there are probably still a few holes in the API.
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
#define LOOT_GAME_INTERFACE
|
||||
|
||||
#include "loot/database_interface.h"
|
||||
#include "loot/plugin_interface.h"
|
||||
|
||||
namespace loot {
|
||||
/** @brief The interface provided for accessing game-specific functionality. */
|
||||
@@ -42,6 +43,57 @@ public:
|
||||
*/
|
||||
virtual std::shared_ptr<DatabaseInterface> GetDatabase() = 0;
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @name Plugin Data Access
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Check if a file is a valid plugin.
|
||||
* @details The validity check is not exhaustive: it checks that the file
|
||||
* extension is ``.esm`` or ``.esp`` (after trimming any ``.ghost``
|
||||
* extension), and that the ``TES4`` header can be parsed.
|
||||
* @param plugin
|
||||
* The filename of the file to check.
|
||||
* @returns True if the file is a valid plugin, false otherwise.
|
||||
*/
|
||||
virtual bool IsValidPlugin(const std::string& plugin) = 0;
|
||||
|
||||
/**
|
||||
* @brief Parses plugins and loads their data.
|
||||
* @details Any previously-loaded plugin data is discarded when this function
|
||||
* is called.
|
||||
* @param plugins
|
||||
* The filenames of the plugins to load.
|
||||
* @param loadHeadersOnly
|
||||
* If true, only the plugins' ``TES4`` headers are loaded. If false,
|
||||
* all records in the plugins are parsed, apart from the main master
|
||||
* file if it has been identified by a previous call to
|
||||
* ``IdentifyMainMasterFile()``.
|
||||
*/
|
||||
virtual void LoadPlugins(const std::vector<std::string>& plugins, bool loadHeadersOnly) = 0;
|
||||
|
||||
/**
|
||||
* @brief Get data for a loaded plugin.
|
||||
* @details Throws an exception if the given plugin has not been loaded.
|
||||
* @param pluginName
|
||||
* The filename of the plugin to get data for.
|
||||
* @returns A const PluginInterface reference. The reference remains valid
|
||||
* until the ``LoadPlugins()`` or ``SortPlugins()`` functions are
|
||||
* next called or this GameInterface is destroyed.
|
||||
*/
|
||||
virtual std::shared_ptr<const PluginInterface> GetPlugin(const std::string& pluginName) = 0;
|
||||
|
||||
/**
|
||||
* @brief Get a set of const references to all loaded plugins' PluginInterface
|
||||
* objects.
|
||||
* @returns A set of const PluginInterface references. The references remain
|
||||
* valid until the ``LoadPlugins()`` or ``SortPlugins()`` functions
|
||||
* are next called or this GameInterface is destroyed.
|
||||
*/
|
||||
virtual std::set<std::shared_ptr<const PluginInterface>> GetLoadedPlugins() = 0;
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @name Sorting
|
||||
|
||||
@@ -92,17 +92,16 @@ public:
|
||||
//Compare name string.
|
||||
bool operator == (const std::string& rhs) const;
|
||||
bool operator != (const std::string& rhs) const;
|
||||
protected:
|
||||
std::vector<Message> messages_;
|
||||
std::set<Tag> tags_;
|
||||
private:
|
||||
std::string name_;
|
||||
bool enabled_; //Default to true.
|
||||
bool enabled_;
|
||||
Priority localPriority_;
|
||||
Priority globalPriority_;
|
||||
std::set<File> loadAfter_;
|
||||
std::set<File> requirements_;
|
||||
std::set<File> incompatibilities_;
|
||||
std::vector<Message> messages_;
|
||||
std::set<Tag> tags_;
|
||||
std::set<PluginCleaningData> dirtyInfo_;
|
||||
std::set<PluginCleaningData> cleanInfo_;
|
||||
std::set<Location> locations_;
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
/* LOOT
|
||||
|
||||
A load order optimisation tool for Oblivion, Skyrim, Fallout 3 and
|
||||
Fallout: New Vegas.
|
||||
|
||||
Copyright (C) 2012-2016 WrinklyNinja
|
||||
|
||||
This file is part of LOOT.
|
||||
|
||||
LOOT is free software: you can redistribute
|
||||
it and/or modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation, either version 3 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
LOOT is distributed in the hope that it will
|
||||
be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LOOT. If not, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef LOOT_PLUGIN_INTERFACE
|
||||
#define LOOT_PLUGIN_INTERFACE
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "loot/metadata/message.h"
|
||||
#include "loot/metadata/tag.h"
|
||||
|
||||
namespace loot {
|
||||
class PluginInterface {
|
||||
public:
|
||||
virtual std::string GetName() const = 0;
|
||||
virtual std::string GetLowercasedName() const = 0;
|
||||
virtual std::string GetVersion() const = 0;
|
||||
virtual std::vector<std::string> GetMasters() const = 0;
|
||||
virtual std::vector<Message> GetStatusMessages() const = 0;
|
||||
virtual std::set<Tag> GetBashTags() const = 0;
|
||||
virtual uint32_t GetCRC() const = 0;
|
||||
|
||||
virtual bool IsMaster() const = 0;
|
||||
virtual bool IsEmpty() const = 0;
|
||||
virtual bool LoadsArchive() const = 0;
|
||||
virtual bool DoFormIDsOverlap(const PluginInterface& plugin) const = 0;
|
||||
};
|
||||
}
|
||||
|
||||
namespace std {
|
||||
template<>
|
||||
struct hash<loot::PluginInterface> {
|
||||
size_t operator() (const loot::PluginInterface& plugin) const {
|
||||
return hash<string>()(plugin.GetLowercasedName());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user