summaryrefslogtreecommitdiff
path: root/src/executableslist.h
diff options
context:
space:
mode:
authorSilarn <jrim@rimpo.org>2019-07-22 01:00:42 -0500
committerSilarn <jrim@rimpo.org>2019-07-22 01:00:42 -0500
commitdcd6d624672019727d7effd17aac86f72bff438b (patch)
tree1e8d3856f657d898c5992631599cf272d785f973 /src/executableslist.h
parent179a73857125ee604f42b0d5c2d765183c86d2c7 (diff)
parente73c309f08eff98f0dbd2590f594a83b67431eac (diff)
Merge branch 'Develop'
Diffstat (limited to 'src/executableslist.h')
-rw-r--r--src/executableslist.h204
1 files changed, 111 insertions, 93 deletions
diff --git a/src/executableslist.h b/src/executableslist.h
index 0534c09e..2d1dd28e 100644
--- a/src/executableslist.h
+++ b/src/executableslist.h
@@ -23,41 +23,61 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
#include "executableinfo.h"
#include <vector>
+#include <optional>
#include <QFileInfo>
#include <QMetaType>
-namespace MOBase { class IPluginGame; }
+namespace MOBase { class IPluginGame; class ExecutableInfo; }
/*!
* @brief Information about an executable
**/
-struct Executable {
- QString m_Title;
- QFileInfo m_BinaryInfo;
- QString m_Arguments;
- QString m_SteamAppID;
- QString m_WorkingDirectory;
-
- enum Flag {
- CustomExecutable = 0x01,
+class Executable
+{
+public:
+ enum Flag
+ {
ShowInToolbar = 0x02,
- UseApplicationIcon = 0x04,
-
- AllFlags = 0xff //I know, I know
+ UseApplicationIcon = 0x04
};
- Q_DECLARE_FLAGS(Flags, Flag)
+ Q_DECLARE_FLAGS(Flags, Flag);
+
+ Executable(QString title={});
+
+ /**
+ * @brief Executable from plugin
+ */
+ Executable(const MOBase::ExecutableInfo& info, Flags flags);
- Flags m_Flags;
+ const QString& title() const;
+ const QFileInfo& binaryInfo() const;
+ const QString& arguments() const;
+ const QString& steamAppID() const;
+ const QString& workingDirectory() const;
+ Flags flags() const;
- bool isCustom() const { return m_Flags.testFlag(CustomExecutable); }
+ 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 { return m_Flags.testFlag(ShowInToolbar); }
+ bool isShownOnToolbar() const;
+ void setShownOnToolbar(bool state);
+ bool usesOwnIcon() const;
- void showOnToolbar(bool state);
+ void mergeFrom(const Executable& other);
- bool usesOwnIcon() const { return m_Flags.testFlag(UseApplicationIcon); }
+private:
+ QString m_title;
+ QFileInfo m_binaryInfo;
+ QString m_arguments;
+ QString m_steamAppID;
+ QString m_workingDirectory;
+ Flags m_flags;
};
@@ -66,28 +86,44 @@ struct Executable {
**/
class ExecutablesList {
public:
+ using vector_type = std::vector<Executable>;
+ using iterator = vector_type::iterator;
+ using const_iterator = vector_type::const_iterator;
/**
- * @brief constructor
- *
- **/
- ExecutablesList();
+ * standard container interface
+ */
+ iterator begin();
+ const_iterator begin() const;
+ iterator end();
+ const_iterator end() const;
+ std::size_t size() const;
+ bool empty() const;
- ~ExecutablesList();
+ /**
+ * @brief initializes the list from the settings and the given plugin
+ **/
+ void load(const MOBase::IPluginGame* game, QSettings& settings);
/**
- * @brief initialise the list with the executables preconfigured for this game
+ * @brief re-adds all the executables from the plugin and renames existing
+ * executables that are in the way
**/
- void init(MOBase::IPluginGame const *game);
+ void resetFromPlugin(MOBase::IPluginGame const *game);
/**
- * @brief find an executable by its name
+ * @brief writes the current list to the settings
+ */
+ void store(QSettings& 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 name is not correct
+ * @exception runtime_error will throw an exception if the executable is not found
**/
- const Executable &find(const QString &title) const;
+ const Executable &get(const QString &title) const;
/**
* @brief find an executable by its name
@@ -96,7 +132,7 @@ public:
* @return the executable
* @exception runtime_error will throw an exception if the name is not correct
**/
- Executable &find(const QString &title);
+ Executable &get(const QString &title);
/**
* @brief find an executable by a fileinfo structure
@@ -104,7 +140,13 @@ public:
* @return the executable
* @exception runtime_error will throw an exception if the name is not correct
*/
- Executable &findByBinary(const QFileInfo &info);
+ Executable &getByBinary(const QFileInfo &info);
+
+ /**
+ * @brief returns an iterator for the given executable by title, or end()
+ */
+ iterator find(const QString &title);
+ const_iterator find(const QString &title) const;
/**
* @brief determine if an executable exists
@@ -117,85 +159,61 @@ public:
* @brief add a new executable to the list
* @param executable
*/
- void addExecutable(const Executable &executable);
+ void setExecutable(const Executable &executable);
/**
- * @brief add a new executable to the list
+ * @brief remove the executable with the specified file name. This needs to
+ * be an absolute file path
*
- * @param title name displayed in the UI
- * @param executableName the actual filename to execute
- * @param arguments arguments to pass to the executable
+ * @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 addExecutable(const QString &title,
- const QString &executableName,
- const QString &arguments,
- const QString &workingDirectory,
- const QString &steamAppID,
- Executable::Flags flags)
- {
- updateExecutable(title, executableName, arguments, workingDirectory,
- steamAppID, Executable::AllFlags, flags);
- }
+ void remove(const QString &title);
/**
- * @brief Update an executable to the list
- *
- * @param title name displayed in the UI
- * @param executableName the actual filename to execute
- * @param arguments arguments to pass to the executable
- * @param closeMO if true, MO will be closed when the binary is started
- **/
- void updateExecutable(const QString &title,
- const QString &executableName,
- const QString &arguments,
- const QString &workingDirectory,
- const QString &steamAppID,
- Executable::Flags mask,
- Executable::Flags flags);
+ * 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 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
+ * @brief add the executables preconfigured for this game
**/
- void remove(const QString &title);
+ void addFromPlugin(MOBase::IPluginGame const *game, SetFlags flags);
/**
- * @brief retrieve begin and end iterators of the configured executables
- *
- * @param begin iterator to the first executable
- * @param end iterator one past the last executable
- **/
- void getExecutables(std::vector<Executable>::const_iterator &begin, std::vector<Executable>::const_iterator &end) const;
+ * @brief add a new executable to the list
+ * @param executable
+ */
+ void setExecutable(const Executable &exe, SetFlags flags);
/**
- * @brief retrieve begin and end iterators of the configured executables
- *
- * @param begin iterator to the first executable
- * @param end iterator one past the last executable
+ * returns the executables provided by the game plugin
**/
- void getExecutables(std::vector<Executable>::iterator &begin, std::vector<Executable>::iterator &end);
+ std::vector<Executable> getPluginExecutables(
+ MOBase::IPluginGame const *game) const;
/**
- * @brief get the number of executables (custom or otherwise)
+ * called when MO is still using the old custom executables from 2.2.0
**/
- size_t size() const {
- return m_Executables.size();
- }
-
-private:
-
- std::vector<Executable>::iterator findExe(const QString &title);
-
- void addExecutableInternal(const QString &title, const QString &executableName, const QString &arguments,
- const QString &workingDirectory,
- const QString &steamAppID);
-
-private:
-
- std::vector<Executable> m_Executables;
-
+ void upgradeFromCustom(const MOBase::IPluginGame* game);
};
Q_DECLARE_OPERATORS_FOR_FLAGS(Executable::Flags)