Skip to content

Commit 8737af8

Browse files
committed
Update for extensions.
1 parent 720e410 commit 8737af8

File tree

7 files changed

+127
-88
lines changed

7 files changed

+127
-88
lines changed

src/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ mo2_add_filter(NAME src/extensions GROUPS
1414
extension
1515
theme
1616
translation
17+
ipluginloader
1718
)
1819

1920
mo2_add_filter(NAME src/interfaces GROUPS
@@ -30,7 +31,6 @@ mo2_add_filter(NAME src/interfaces GROUPS
3031
ipluginlist
3132
ipluginmodpage
3233
ipluginpreview
33-
ipluginproxy
3434
iplugintool
3535
iprofile
3636
isavegame

src/extension.cpp

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,9 @@ ExtensionFactory::loadExtension(std::filesystem::path directory,
114114
return TranslationExtension::loadExtension(std::move(directory),
115115
std::move(metadata));
116116
case ExtensionType::PLUGIN:
117+
return PluginExtension::loadExtension(std::move(directory), std::move(metadata));
117118
case ExtensionType::GAME:
119+
return GameExtension::loadExtension(std::move(directory), std::move(metadata));
118120
case ExtensionType::INVALID:
119121
default:
120122
log::warn("failed to load extension from '{}': invalid type", directory.native());
@@ -197,7 +199,6 @@ TranslationExtension::loadExtension(std::filesystem::path path,
197199
new TranslationExtension(path, metadata, std::move(translations))};
198200
}
199201

200-
#pragma optimize("", off)
201202
std::shared_ptr<const Translation>
202203
TranslationExtension::parseTranslation(std::filesystem::path const& extensionFolder,
203204
const QString& identifier,
@@ -227,6 +228,36 @@ TranslationExtension::parseTranslation(std::filesystem::path const& extensionFol
227228
return std::make_shared<Translation>(identifier.toStdString(), name.toStdString(),
228229
std::move(qm_files));
229230
}
230-
#pragma optimize("", on)
231+
232+
PluginExtension::PluginExtension(
233+
std::filesystem::path path, ExtensionMetaData metadata, bool autodetect,
234+
std::vector<std::filesystem::path> plugins,
235+
std::vector<std::shared_ptr<const ThemeAddition>> themeAdditions,
236+
std::vector<std::shared_ptr<const TranslationAddition>> translationAdditions)
237+
: IExtension(std::move(path), std::move(metadata)), m_AutoDetect{autodetect},
238+
m_Plugins{std::move(plugins)}, m_ThemeAdditions{std::move(themeAdditions)},
239+
m_TranslationAdditions{std::move(translationAdditions)}
240+
{}
241+
242+
std::unique_ptr<PluginExtension>
243+
PluginExtension::loadExtension(std::filesystem::path path, ExtensionMetaData metadata)
244+
{
245+
// TODO
246+
return std::unique_ptr<PluginExtension>(
247+
new PluginExtension(std::move(path), std::move(metadata), true, {}, {}, {}));
248+
}
249+
250+
GameExtension::GameExtension(PluginExtension&& pluginExtension)
251+
: PluginExtension(std::move(pluginExtension))
252+
{}
253+
254+
std::unique_ptr<GameExtension> GameExtension::loadExtension(std::filesystem::path path,
255+
ExtensionMetaData metadata)
256+
{
257+
auto extension = PluginExtension::loadExtension(std::move(path), std::move(metadata));
258+
return extension
259+
? std::unique_ptr<GameExtension>(new GameExtension(std::move(*extension)))
260+
: nullptr;
261+
}
231262

232263
} // namespace MOBase

src/extension.h

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,17 @@ class QDLLEXPORT PluginExtension : public IExtension
217217
const auto& themeAdditions() const { return m_ThemeAdditions; }
218218
const auto& translationAdditions() const { return m_TranslationAdditions; }
219219

220+
protected:
221+
PluginExtension(
222+
std::filesystem::path path, ExtensionMetaData metadata, bool autodetect,
223+
std::vector<std::filesystem::path> plugins,
224+
std::vector<std::shared_ptr<const ThemeAddition>> themeAdditions,
225+
std::vector<std::shared_ptr<const TranslationAddition>> translationAdditions);
226+
227+
friend class ExtensionFactory;
228+
static std::unique_ptr<PluginExtension> loadExtension(std::filesystem::path path,
229+
ExtensionMetaData metadata);
230+
220231
private:
221232
// auto-detect plugins
222233
bool m_AutoDetect;
@@ -234,8 +245,12 @@ class QDLLEXPORT PluginExtension : public IExtension
234245
//
235246
class QDLLEXPORT GameExtension : public PluginExtension
236247
{
237-
public:
238-
using PluginExtension::PluginExtension;
248+
private:
249+
GameExtension(PluginExtension&& pluginExtension);
250+
251+
friend class ExtensionFactory;
252+
static std::unique_ptr<GameExtension> loadExtension(std::filesystem::path path,
253+
ExtensionMetaData metadata);
239254
};
240255

241256
} // namespace MOBase

src/ipluginloader.h

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
Mod Organizer shared UI functionality
3+
4+
Copyright (C) 2012 Sebastian Herbord. All rights reserved.
5+
6+
This library is free software; you can redistribute it and/or
7+
modify it under the terms of the GNU Lesser General Public
8+
License as published by the Free Software Foundation; either
9+
version 3 of the License, or (at your option) any later version.
10+
11+
This library is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
Lesser General Public License for more details.
15+
16+
You should have received a copy of the GNU Lesser General Public
17+
License along with this library; if not, write to the Free Software
18+
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19+
*/
20+
21+
#ifndef IPLUGINPROXY_H
22+
#define IPLUGINPROXY_H
23+
24+
#include <QDir>
25+
#include <QList>
26+
#include <QString>
27+
28+
#include "extension.h"
29+
30+
namespace MOBase
31+
{
32+
33+
class IPluginLoader : public QObject
34+
{
35+
public:
36+
// initialize the loader, set the error message on failure
37+
//
38+
virtual bool initialize(QString& errorMessage) = 0;
39+
40+
// extract and load plugins from the given extension
41+
//
42+
// if multiple QObject* corresponds to the same Plugin, they should be returned
43+
// together
44+
//
45+
virtual QList<QList<QObject*>> load(const PluginExtension& extension) = 0;
46+
47+
// unload plugins from the given extension
48+
//
49+
virtual void unload(const PluginExtension& identifier) = 0;
50+
51+
// unload all plugins from this loader
52+
//
53+
virtual void unloadAll() = 0;
54+
55+
virtual ~IPluginLoader() {}
56+
57+
protected:
58+
IPluginLoader() {}
59+
};
60+
61+
} // namespace MOBase
62+
63+
Q_DECLARE_INTERFACE(MOBase::IPluginLoader, "com.mo2.PluginLoader")
64+
65+
#endif // IPLUGINPROXY_H

src/ipluginproxy.h

Lines changed: 0 additions & 83 deletions
This file was deleted.

src/log.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,11 @@ std::string converter<QVariant>::convert(const QVariant& v)
412412
: v.toString().toStdString()));
413413
}
414414

415+
std::string converter<std::filesystem::path>::convert(const std::filesystem::path& v)
416+
{
417+
return v.string();
418+
}
419+
415420
void doLogImpl(spdlog::logger& lg, Levels lv, const std::string& s) noexcept
416421
{
417422
try {

src/log.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ struct QDLLEXPORT converter<QVariant>
108108
static std::string convert(const QVariant& v);
109109
};
110110

111+
template <>
112+
struct QDLLEXPORT converter<std::filesystem::path>
113+
{
114+
static std::string convert(const std::filesystem::path& v);
115+
};
116+
111117
// custom converter for enum and enum class that seems to not work with latest fmt
112118
template <typename T>
113119
struct QDLLEXPORT converter<T, std::enable_if_t<std::is_enum_v<T>>>

0 commit comments

Comments
 (0)