summaryrefslogtreecommitdiff
path: root/src/profile.h
diff options
context:
space:
mode:
authorMikaƫl Capelle <capelle.mikael@gmail.com>2021-01-29 19:29:21 +0100
committerGitHub <noreply@github.com>2021-01-29 19:29:21 +0100
commitf53e5406d4292f484257178ec5733f6ceb116673 (patch)
treef08dfdba6a38986a93612a5aa0166f3008110ad7 /src/profile.h
parent8606bf70c76252e20f888264bfbdedde0f1c8754 (diff)
parent48fae18ac6baced388b1fa7cee6c18e6aa8dbab3 (diff)
Merge pull request #1378 from Holt59/fix-priority-management
Increase robustness of mods priority in profile.
Diffstat (limited to 'src/profile.h')
-rw-r--r--src/profile.h69
1 files changed, 31 insertions, 38 deletions
diff --git a/src/profile.h b/src/profile.h
index 04452ff6..672a2c13 100644
--- a/src/profile.h
+++ b/src/profile.h
@@ -52,7 +52,14 @@ class Profile : public QObject, public MOBase::IProfile
public:
- typedef boost::shared_ptr<Profile> Ptr;
+ using Ptr = boost::shared_ptr<Profile>;
+
+public:
+
+ // the minimum and maximum priority achievable by mods
+ //
+ static constexpr int MinimumPriority = 0;
+ static constexpr int MaximumPriority = std::numeric_limits<int>::max();
public:
@@ -243,7 +250,7 @@ public:
*
* @return list of active mods sorted by priority (ascending). "first" is the mod name, "second" is its path
**/
- std::vector<std::tuple<QString, QString, int> > getActiveMods();
+ std::vector<std::tuple<QString, QString, int>> getActiveMods();
/**
* @brief retrieve a mod of the indexes ordered by priority
@@ -262,20 +269,6 @@ public:
size_t numMods() const { return m_ModStatus.size(); }
/**
- * @return the number of mods that can be enabled and where the priority can be modified
- */
- unsigned int numRegularMods() const { return m_NumRegularMods; }
-
- /**
- * @brief retrieve the mod index based on the priority
- *
- * @param priority priority to look up
- * @return the index of the mod
- * @throw std::exception an exception is thrown if there is no mod with the specified priority
- **/
- unsigned int modIndexByPriority(int priority) const;
-
- /**
* @brief enable or disable a mod
*
* @param index index of the mod to enable/disable
@@ -293,17 +286,18 @@ public:
**/
void setModsEnabled(const QList<unsigned int> &modsToEnable, const QList<unsigned int> &modsToDisable);
- /**
- * change the priority of a mod. Of course this also changes the priority of other mods.
- * The priority of the mods in the range ]old, new priority] are shifted so that no gaps
- * are possible.
- *
- * @param index index of the mod to change
- * @param newPriority the new priority value
- *
- * @todo what happens if the new priority is outside the range?
- **/
- void setModPriority(unsigned int index, int &newPriority);
+ // set the priority of a mod, and the priority of other mods in the range
+ // [old priority, new priority] such that no gaps are possible
+ //
+ // the priority is clamped in the range of valid priority (>= 0, and lower than
+ // the number of "regular" mods), you should use MinimumPriority or MaximumPriority
+ // to send a mod to the "top" or "bottom" of the priority list
+ //
+ // the function returns true if the priority was changed, or false if the mod
+ // was already at the given priority (or if the priority of the mod cannot be
+ // set)
+ //
+ bool setModPriority(unsigned int index, int& newPriority);
/**
* @brief determine if a mod is enabled
@@ -338,8 +332,6 @@ public:
QList<QVariantMap> settingsByArray(const QString &prefix) const;
void storeSettingsByArray(const QString &prefix, const QList<QVariantMap> &values);
- int getPriorityMinimum() const;
-
bool forcedLibrariesEnabled(const QString &executable) const;
void setForcedLibrariesEnabled(const QString &executable, bool enabled);
QList<MOBase::ExecutableForcedLoadSetting> determineForcedLibraries(const QString &executable) const;
@@ -348,6 +340,9 @@ public:
void debugDump() const;
+
+ Profile& operator=(const Profile& reference) = delete;
+
signals:
/**
@@ -364,7 +359,7 @@ signals:
**/
void modStatusChanged(QList<unsigned int> index);
-public slots:
+protected slots:
// should only be called by DelayedFileWriter, use writeModlist() and writeModlistNow() instead
void doWriteModlist();
@@ -374,17 +369,13 @@ private:
class ModStatus {
friend class Profile;
public:
- ModStatus() : m_Overwrite(false), m_Enabled(false), m_Priority(-1) {}
+ ModStatus() : m_Enabled(false), m_Priority(-1) {}
private:
- bool m_Overwrite;
bool m_Enabled;
int m_Priority;
};
private:
- Profile& operator=(const Profile &reference); // not implemented
-
- void initTimer();
void updateIndices();
@@ -394,7 +385,6 @@ private:
void mergeTweak(const QString &tweakName, const QString &tweakedIni) const;
void mergeTweaks(ModInfo::Ptr modInfo, const QString &tweakedIni) const;
void touchFile(QString fileName);
- void finishChangeStatus() const;
static void renameModInList(QFile &modList, const QString &oldName, const QString &newName);
@@ -406,11 +396,14 @@ private:
const MOBase::IPluginGame *m_GamePlugin;
- mutable QByteArray m_LastModlistHash;
std::vector<ModStatus> m_ModStatus;
std::map<int, unsigned int> m_ModIndexByPriority;
- unsigned int m_NumRegularMods;
+ // "regular" here means mods with modifiable priority (i.e. not backups
+ // or overwrite)
+ std::size_t m_NumRegularMods;
+
+ mutable QByteArray m_LastModlistHash;
MOBase::DelayedFileWriter m_ModListWriter;
};