ScummVM API documentation
library_scummvm.h
1/* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22#ifndef AGS_ENGINE_UTIL_LIBRARY_SCUMMVM_H
23#define AGS_ENGINE_UTIL_LIBRARY_SCUMMVM_H
24
25#include "ags/shared/core/platform.h"
26#include "ags/shared/util/string.h"
27#include "ags/shared/debugging/out.h"
28#include "ags/plugins/plugin_base.h"
29#include "ags/engine/util/library.h"
30
31namespace AGS3 {
32namespace AGS {
33namespace Engine {
34
36private:
37 Plugins::PluginBase *_library = nullptr;
38
39public:
41
42 ~ScummVMLibrary() override {
43 Unload();
44 };
45
46 AGS::Shared::String GetFilenameForLib(const AGS::Shared::String &libraryName) override {
47 return AGS::Shared::String::FromFormat("%s.dll", libraryName.GetCStr());
48 }
49
50 bool Load(const AGS::Shared::String &libraryName) override {
51 Unload();
52
53 _library = Plugins::pluginOpen(libraryName.GetCStr());
54 const char *error = Plugins::pluginError();
55 if (error)
56 AGS::Shared::Debug::Printf("pluginOpen returned: %s", error);
57
58 if (_library == nullptr)
59 return false;
60 _name = libraryName;
61 _filename = GetFilenameForLib(libraryName);
62 _path = "./";
63 return true;
64 }
65
66 void Unload() override {
67 if (_library) {
68 Plugins::pluginClose(_library);
69 _library = nullptr;
70 _name = "";
71 _filename = "";
72 _path = "";
73 }
74 }
75
76 bool IsLoaded() const override {
77 return _library != nullptr;
78 }
79
80 Plugins::PluginBase *getPlugin() const {
81 return _library;
82 }
83};
84
85
87
88} // namespace Engine
89} // namespace AGS
90} // namespace AGS3
91
92#endif
Definition: library.h:34
Definition: library_scummvm.h:35
Definition: string.h:60
Definition: plugin_base.h:171
Definition: engine.h:149
void NORETURN_PRE error(MSVC_PRINTF const char *s,...) GCC_PRINTF(1