blob: a2a11ef5960fe1b3058240043e2bbeccde691b68 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
#include <uibase/pluginrequirements.h>
#include <QCoreApplication>
#include <uibase/imoinfo.h>
#include <uibase/iplugindiagnose.h>
#include <uibase/iplugingame.h>
using namespace MOBase;
// Plugin and Game dependencies
PluginDependencyRequirement::PluginDependencyRequirement(QStringList const& pluginNames)
: m_PluginNames(pluginNames)
{}
std::optional<IPluginRequirement::Problem>
PluginDependencyRequirement::check(IOrganizer* o) const
{
for (auto const& pluginName : m_PluginNames) {
if (o->isPluginEnabled(pluginName)) {
return {};
}
}
return Problem(message());
}
QString PluginDependencyRequirement::message() const
{
if (m_PluginNames.size() > 1) {
return QObject::tr("One of the following plugins must be enabled: %1.")
.arg(m_PluginNames.join(", "));
} else {
return QObject::tr("This plugin can only be enabled if the '%1' plugin is "
"installed and enabled.")
.arg(m_PluginNames[0]);
}
}
GameDependencyRequirement::GameDependencyRequirement(QStringList const& gameNames)
: m_GameNames(gameNames)
{}
std::optional<IPluginRequirement::Problem>
GameDependencyRequirement::check(IOrganizer* o) const
{
auto* game = o->managedGame();
if (!game) {
return Problem(message());
}
QString gameName = game->gameName();
for (auto const& pluginName : m_GameNames) {
if (pluginName.compare(gameName, Qt::CaseInsensitive) == 0) {
return {};
}
}
return Problem(message());
}
QString GameDependencyRequirement::message() const
{
return QObject::tr("This plugin can only be enabled for the following game(s): %1.",
"", static_cast<int>(m_GameNames.size()))
.arg(m_GameNames.join(", "));
}
// Diagnose requirements
DiagnoseRequirement::DiagnoseRequirement(const IPluginDiagnose* diagnose)
: m_Diagnose(diagnose)
{}
std::optional<IPluginRequirement::Problem> DiagnoseRequirement::check(IOrganizer*) const
{
auto activeProblems = m_Diagnose->activeProblems();
if (activeProblems.empty()) {
return {};
}
QStringList shortDescriptions, longDescriptions;
for (auto i : activeProblems) {
shortDescriptions.append(m_Diagnose->shortDescription(i));
longDescriptions.append(m_Diagnose->fullDescription(i));
}
return Problem(shortDescriptions.join("\n"), longDescriptions.join("\n"));
}
// Basic requirements
class BasicPluginRequirement : public IPluginRequirement
{
public:
BasicPluginRequirement(std::function<bool(IOrganizer*)> const& checker,
QString const description)
: m_Checker(checker), m_Description(description)
{}
std::optional<Problem> check(IOrganizer* o) const
{
if (m_Checker(o)) {
return {};
}
return Problem(m_Description);
}
private:
std::function<bool(IOrganizer*)> m_Checker;
QString m_Description;
};
// Factory
std::shared_ptr<const IPluginRequirement>
PluginRequirementFactory::pluginDependency(QStringList const& pluginNames)
{
return std::make_shared<PluginDependencyRequirement>(pluginNames);
}
std::shared_ptr<const IPluginRequirement>
PluginRequirementFactory::gameDependency(QStringList const& pluginGameNames)
{
return std::make_shared<GameDependencyRequirement>(pluginGameNames);
}
std::shared_ptr<const IPluginRequirement>
PluginRequirementFactory::diagnose(const IPluginDiagnose* diagnose)
{
return std::make_shared<DiagnoseRequirement>(diagnose);
}
std::shared_ptr<const IPluginRequirement>
PluginRequirementFactory::basic(std::function<bool(IOrganizer*)> const& checker,
QString const description)
{
return std::make_shared<BasicPluginRequirement>(checker, description);
}
|