88#include < QJsonObject>
99#include < QTranslator>
1010
11- #include " dllimport.h"
12- #include " iplugingame.h"
11+ #include " ../dllimport.h"
12+ #include " ../iplugingame.h"
13+ #include " ../versioning.h"
1314#include " requirements.h"
1415#include " theme.h"
1516#include " translation.h"
16- #include " versioninfo.h"
1717
1818namespace MOBase
1919{
2020class IExtension ;
2121
22+ class InvalidExtensionMetaDataException : public Exception
23+ {
24+ public:
25+ using Exception::Exception;
26+ };
27+
2228enum class ExtensionType
2329{
24- INVALID,
2530 THEME,
2631 TRANSLATION,
2732 PLUGIN,
@@ -48,10 +53,6 @@ class QDLLEXPORT ExtensionContributor
4853class QDLLEXPORT ExtensionMetaData
4954{
5055public:
51- // check if that metadata object is valid
52- //
53- bool isValid () const ;
54-
5556 // retrieve the identifier of the extension
5657 //
5758 const auto & identifier () const { return m_Identifier; }
@@ -72,18 +73,22 @@ class QDLLEXPORT ExtensionMetaData
7273 //
7374 auto type () const { return m_Type; }
7475
75- // retrieve the description of the extension.
76+ // retrieve the description of the extension
7677 //
7778 auto description () const { return localized (m_Description); }
7879
7980 // retrieve the icon for the extension (might be an empty icon)
8081 //
8182 const auto & icon () const { return m_Icon; }
8283
83- // retrieve the version of the extension.
84+ // retrieve the version of the extension
8485 //
8586 const auto & version () const { return m_Version; }
8687
88+ // retrieve the requirements of the extension
89+ //
90+ const auto & requirements () const { return m_Requirements; }
91+
8792 // retrieve the raw JSON metadata, this is mostly useful for specific extension type
8893 // to extract custom parts
8994 //
@@ -92,18 +97,16 @@ class QDLLEXPORT ExtensionMetaData
9297 // retrieve the content objects of the extension
9398 QJsonObject content () const ;
9499
95- private :
96- QString localized (QString const & value) const ;
100+ protected :
101+ ExtensionMetaData (std::filesystem::path const & path, const QJsonObject& jsonData) ;
97102
98103private:
99104 friend class ExtensionFactory ;
100105
101106 constexpr static const char * DEFAULT_TRANSLATIONS_FOLDER = " translations" ;
102107 constexpr static const char * DEFAULT_STYLESHEET_PATH = " stylesheets" ;
103108
104- ExtensionType parseType (QString const & value) const ;
105-
106- ExtensionMetaData (std::filesystem::path const & path, const QJsonObject& jsonData);
109+ std::optional<ExtensionType> parseType (QString const & value) const ;
107110
108111private:
109112 QJsonObject m_JsonData;
@@ -116,10 +119,13 @@ class QDLLEXPORT ExtensionMetaData
116119 ExtensionType m_Type;
117120 QString m_Description;
118121 QIcon m_Icon;
119- VersionInfo m_Version;
122+ Version m_Version;
123+ std::vector<ExtensionRequirement> m_Requirements;
120124
121125 std::filesystem::path m_TranslationFilesPrefix;
122126 std::filesystem::path m_StyleSheetFilePath;
127+
128+ QString localized (QString const & value) const ;
123129};
124130
125131class QDLLEXPORT IExtension
@@ -133,24 +139,19 @@ class QDLLEXPORT IExtension
133139 //
134140 const auto & metadata () const { return m_MetaData; }
135141
136- // retrieve the requirements of the extension
137- //
138- const auto & requirements () const { return m_Requirements; }
139-
140142public:
141143 virtual ~IExtension () {}
142144 IExtension& operator =(const IExtension&) = delete ;
143145
144146protected:
145- IExtension (std::filesystem::path path, ExtensionMetaData metadata);
147+ IExtension (std::filesystem::path const & path, ExtensionMetaData&& metadata);
146148
147149public:
148150 IExtension (const IExtension&) = default ;
149151
150152private:
151153 std::filesystem::path m_Path;
152154 ExtensionMetaData m_MetaData;
153- std::vector<ExtensionRequirement> m_Requirements;
154155};
155156
156157// factory for extensions
@@ -161,13 +162,14 @@ class QDLLEXPORT ExtensionFactory
161162 // load an extension from the given directory, return a null-pointer if the extension
162163 // could not be load
163164 //
164- static std::unique_ptr<IExtension> loadExtension (std::filesystem::path directory);
165+ static std::unique_ptr<IExtension>
166+ loadExtension (std::filesystem::path const & directory);
165167
166168private:
167169 // load an extension from the given directory
168170 //
169- static std::unique_ptr<IExtension> loadExtension (std::filesystem::path directory,
170- ExtensionMetaData metadata);
171+ static std::unique_ptr<IExtension>
172+ loadExtension (std::filesystem::path const & directory, ExtensionMetaData&& metadata);
171173};
172174
173175// theme extension that provides one or more base themes for MO2
@@ -180,12 +182,12 @@ class QDLLEXPORT ThemeExtension : public IExtension
180182 const auto & themes () const { return m_Themes; }
181183
182184private:
183- ThemeExtension (std::filesystem::path path, ExtensionMetaData metadata,
185+ ThemeExtension (std::filesystem::path const & path, ExtensionMetaData&& metadata,
184186 std::vector<std::shared_ptr<const Theme>> themes);
185187
186188 friend class ExtensionFactory ;
187- static std::unique_ptr<ThemeExtension> loadExtension (std::filesystem::path path,
188- ExtensionMetaData metadata);
189+ static std::unique_ptr<ThemeExtension>
190+ loadExtension (std::filesystem::path const & path, ExtensionMetaData&& metadata);
189191
190192 static std::shared_ptr<const Theme>
191193 parseTheme (std::filesystem::path const & extensionFolder, const QString& identifier,
@@ -205,12 +207,12 @@ class QDLLEXPORT TranslationExtension : public IExtension
205207 const auto & translations () const { return m_Translations; }
206208
207209private:
208- TranslationExtension (std::filesystem::path path, ExtensionMetaData metadata,
210+ TranslationExtension (std::filesystem::path const & path, ExtensionMetaData&& metadata,
209211 std::vector<std::shared_ptr<const Translation>> translations);
210212
211213 friend class ExtensionFactory ;
212214 static std::unique_ptr<TranslationExtension>
213- loadExtension (std::filesystem::path path, ExtensionMetaData metadata);
215+ loadExtension (std::filesystem::path const & path, ExtensionMetaData&& metadata);
214216
215217 static std::shared_ptr<const Translation>
216218 parseTranslation (std::filesystem::path const & extensionFolder,
@@ -241,14 +243,14 @@ class QDLLEXPORT PluginExtension : public IExtension
241243
242244protected:
243245 PluginExtension (
244- std::filesystem::path path, ExtensionMetaData metadata, bool autodetect,
246+ std::filesystem::path const & path, ExtensionMetaData&& metadata, bool autodetect,
245247 std::map<std::string, std::filesystem::path> plugins,
246248 std::vector<std::shared_ptr<const ThemeAddition>> themeAdditions,
247249 std::vector<std::shared_ptr<const TranslationAddition>> translationAdditions);
248250
249251 friend class ExtensionFactory ;
250- static std::unique_ptr<PluginExtension> loadExtension (std::filesystem::path path,
251- ExtensionMetaData metadata);
252+ static std::unique_ptr<PluginExtension>
253+ loadExtension (std::filesystem::path const & path, ExtensionMetaData&& metadata);
252254
253255private:
254256 // auto-detect plugins
@@ -271,8 +273,8 @@ class QDLLEXPORT GameExtension : public PluginExtension
271273 GameExtension (PluginExtension&& pluginExtension);
272274
273275 friend class ExtensionFactory ;
274- static std::unique_ptr<GameExtension> loadExtension (std::filesystem::path path,
275- ExtensionMetaData metadata);
276+ static std::unique_ptr<GameExtension> loadExtension (std::filesystem::path const & path,
277+ ExtensionMetaData&& metadata);
276278};
277279
278280} // namespace MOBase
0 commit comments