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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
|
/*
Copyright (C) 2012 Sebastian Herbord. All rights reserved.
This file is part of Mod Organizer.
Mod Organizer is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Mod Organizer is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef EXECUTABLESLIST_H
#define EXECUTABLESLIST_H
#include "executableinfo.h"
#include <optional>
#include <vector>
#include <QFileInfo>
#include <QMetaType>
namespace MOBase
{
class IPluginGame;
class ExecutableInfo;
} // namespace MOBase
class Settings;
/*!
* @brief Information about an executable
**/
class Executable
{
public:
enum Flag
{
ShowInToolbar = 0x02,
UseApplicationIcon = 0x04,
Hide = 0x08,
MinimizeToSystemTray = 0x16
};
Q_DECLARE_FLAGS(Flags, Flag);
Executable(QString title = {});
/**
* @brief Executable from plugin
*/
Executable(const MOBase::ExecutableInfo& info, Flags flags);
const QString& title() const;
const QFileInfo& binaryInfo() const;
const QString& arguments() const;
const QString& steamAppID() const;
const QString& workingDirectory() const;
Flags flags() const;
Executable& title(const QString& s);
Executable& binaryInfo(const QFileInfo& fi);
Executable& arguments(const QString& s);
Executable& steamAppID(const QString& s);
Executable& workingDirectory(const QString& s);
Executable& flags(Flags f);
bool isShownOnToolbar() const;
void setShownOnToolbar(bool state);
bool usesOwnIcon() const;
bool minimizeToSystemTray() const;
bool hide() const;
void mergeFrom(const Executable& other);
private:
QString m_title;
QFileInfo m_binaryInfo;
QString m_arguments;
QString m_steamAppID;
QString m_workingDirectory;
Flags m_flags;
};
/*!
* @brief List of executables configured to by started from MO
**/
class ExecutablesList
{
public:
using vector_type = std::vector<Executable>;
using iterator = vector_type::iterator;
using const_iterator = vector_type::const_iterator;
/**
* standard container interface
*/
iterator begin();
const_iterator begin() const;
iterator end();
const_iterator end() const;
std::size_t size() const;
bool empty() const;
/**
* @brief initializes the list from the settings and the given plugin
**/
void load(const MOBase::IPluginGame* game, const Settings& settings);
/**
* @brief re-adds all the executables from the plugin and renames existing
* executables that are in the way
**/
void resetFromPlugin(MOBase::IPluginGame const* game);
/**
* @brief writes the current list to the settings
*/
void store(Settings& settings);
/**
* @brief get an executable by name
*
* @param title the title of the executable to look up
* @return the executable
* @exception runtime_error will throw an exception if the executable is not found
**/
const Executable& get(const QString& title) const;
/**
* @brief find an executable by its name
*
* @param title the title of the executable to look up
* @return the executable
* @exception runtime_error will throw an exception if the name is not correct
**/
Executable& get(const QString& title);
/**
* @brief find an executable by a fileinfo structure
* @param info the info object to search for
* @return the executable
* @exception runtime_error will throw an exception if the name is not correct
*/
Executable& getByBinary(const QFileInfo& info);
/**
* @brief returns an iterator for the given executable by title, or end()
*/
iterator find(const QString& title, bool caseSensitive = true);
const_iterator find(const QString& title, bool caseSensitive = true) const;
/**
* @brief determine if an executable exists
* @param title the title of the executable to look up
* @return true if the executable exists, false otherwise
**/
bool titleExists(const QString& title) const;
/**
* @brief add a new executable to the list
* @param executable
*/
void setExecutable(const Executable& executable);
/**
* @brief remove the executable with the specified file name. This needs to
* be an absolute file path
*
* @param title title of the executable to remove
* @note if the executable name is invalid, nothing happens. There is no way
* to determine if this was successful
**/
void remove(const QString& title);
/**
* returns a title that starts with the given prefix and does not clash with
* an existing executable, may fail
*/
std::optional<QString> makeNonConflictingTitle(const QString& prefix);
private:
enum SetFlags
{
// executables having the same name as existing ones are ignored
IgnoreExisting = 1,
// executables having the same name are merged
MergeExisting,
// an existing executable with the same name is renamed
MoveExisting
};
std::vector<Executable> m_Executables;
/**
* @brief add the executables preconfigured for this game
**/
void addFromPlugin(MOBase::IPluginGame const* game, SetFlags flags);
/**
* @brief add a new executable to the list
* @param executable
*/
void setExecutable(const Executable& exe, SetFlags flags);
/**
* returns the executables provided by the game plugin
**/
std::vector<Executable> getPluginExecutables(MOBase::IPluginGame const* game) const;
/**
* called when MO is still using the old custom executables from 2.2.0
**/
void upgradeFromCustom(const MOBase::IPluginGame* game);
// logs all executables
//
void dump() const;
};
Q_DECLARE_OPERATORS_FOR_FLAGS(Executable::Flags)
#endif // EXECUTABLESLIST_H
|