AGS: Tidied Library class

From upstream 58a6f421e3b97f6e2db49b88a6434686c62f5142
This commit is contained in:
Thierry Crozat 2022-06-25 23:27:59 +01:00
parent 57fb47275b
commit 817ddb19c9
3 changed files with 26 additions and 13 deletions

View File

@ -29,17 +29,25 @@ namespace AGS3 {
namespace AGS {
namespace Engine {
using AGS::Shared::String;
class BaseLibrary {
public:
BaseLibrary() {}
virtual ~BaseLibrary() {}
virtual AGS::Shared::String GetFilenameForLib(const AGS::Shared::String &libraryName) = 0;
String GetName() const { return _name; }
String GetFilePath() const { return _path; }
virtual bool Load(const AGS::Shared::String &libraryName) = 0;
virtual String GetFilenameForLib(const String &libname) = 0;
virtual bool Load(const String &libname) = 0;
virtual void Unload() = 0;
virtual bool IsLoaded() const = 0;
virtual bool Unload() = 0;
protected:
String _name;
String _path;
};
} // namespace Engine

View File

@ -55,20 +55,26 @@ public:
if (error)
AGS::Shared::Debug::Printf("pluginOpen returned: %s", error);
return (_library != nullptr);
if (_library == nullptr)
return false;
_name = libraryName;
_path = GetFilenameForLib(libraryName);;
return true;
}
bool Unload() override {
void Unload() override {
if (_library) {
Plugins::PluginBase *lib = _library;
Plugins::pluginClose(_library);
_library = nullptr;
return (Plugins::pluginClose(lib) == 0);
} else {
return true;
_name = "";
_path = "";
}
}
bool IsLoaded() const override {
return _library != nullptr;
}
Plugins::PluginBase *getPlugin() const {
return _library;
}

View File

@ -858,12 +858,11 @@ Engine::GameInitError pl_register_plugins(const std::vector<Shared::PluginInfo>
apl->filename = "ags_snowrain";
}
String expect_filename = apl->library.GetFilenameForLib(apl->filename);
if (apl->library.Load(apl->filename)) {
apl->_plugin = apl->library.getPlugin();
AGS::Shared::Debug::Printf(kDbgMsg_Info, "Plugin '%s' loaded as '%s', resolving imports...", apl->filename.GetCStr(), expect_filename.GetCStr());
AGS::Shared::Debug::Printf(kDbgMsg_Info, "Plugin '%s' loaded from '%s', resolving imports...", apl->filename.GetCStr(), apl->library.GetFilePath().GetCStr());
} else {
String expect_filename = apl->library.GetFilenameForLib(apl->filename);
AGS::Shared::Debug::Printf(kDbgMsg_Info, "Plugin '%s' could not be loaded (expected '%s')",
apl->filename.GetCStr(), expect_filename.GetCStr());
_GP(plugins).pop_back();