summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/modinfo.cpp4
-rw-r--r--src/modinfo.h72
-rw-r--r--src/modinforegular.cpp6
-rw-r--r--src/organizercore.cpp2
4 files changed, 48 insertions, 36 deletions
diff --git a/src/modinfo.cpp b/src/modinfo.cpp
index 509c3837..6f3b530e 100644
--- a/src/modinfo.cpp
+++ b/src/modinfo.cpp
@@ -91,6 +91,7 @@ ModInfo::Ptr ModInfo::createFrom(PluginContainer *pluginContainer, const MOBase:
} else {
result = ModInfo::Ptr(new ModInfoRegular(pluginContainer, game, dir, directoryStructure));
}
+ result->m_Index = s_Collection.size();
s_Collection.push_back(result);
return result;
}
@@ -105,6 +106,7 @@ ModInfo::Ptr ModInfo::createFromPlugin(const QString &modName,
QMutexLocker locker(&s_Mutex);
ModInfo::Ptr result = ModInfo::Ptr(
new ModInfoForeign(modName, espName, bsaNames, modType, game, directoryStructure, pluginContainer));
+ result->m_Index = s_Collection.size();
s_Collection.push_back(result);
return result;
}
@@ -115,6 +117,7 @@ ModInfo::Ptr ModInfo::createFromOverwrite(
{
QMutexLocker locker(&s_Mutex);
ModInfo::Ptr overwrite = ModInfo::Ptr(new ModInfoOverwrite(pluginContainer, game, directoryStructure));
+ overwrite->m_Index = s_Collection.size();
s_Collection.push_back(overwrite);
return overwrite;
}
@@ -286,6 +289,7 @@ void ModInfo::updateIndices()
QString modName = s_Collection[i]->internalName();
QString game = s_Collection[i]->gameName();
int modID = s_Collection[i]->nexusId();
+ s_Collection[i]->m_Index = i;
s_ModsByName[modName] = i;
s_ModsByModID[std::pair<QString, int>(game, modID)].push_back(i);
}
diff --git a/src/modinfo.h b/src/modinfo.h
index 3981be18..f0c7bcb5 100644
--- a/src/modinfo.h
+++ b/src/modinfo.h
@@ -211,30 +211,6 @@ public: // Static functions:
QString gameName, QVariantList updateData, bool addOldMods = false, bool markUpdated = false);
/**
- * @brief Create a new mod from the specified directory and add it to the collection.
- *
- * @param dir Directory to create from.
- *
- * @return pointer to the info-structure of the newly created/added mod.
- */
- static ModInfo::Ptr createFrom(
- PluginContainer *pluginContainer, const MOBase::IPluginGame *game,
- const QDir &dir, MOShared::DirectoryEntry **directoryStructure);
-
- /**
- * @brief Create a new "foreign-managed" mod from a tuple of plugin and archives.
- *
- * @param espName Name of the plugin.
- * @param bsaNames Names of archives.
- *
- * @return a new mod.
- */
- static ModInfo::Ptr createFromPlugin(
- const QString &modName, const QString &espName, const QStringList &bsaNames,
- ModInfo::EModType modType, const MOBase::IPluginGame* game,
- MOShared::DirectoryEntry **directoryStructure, PluginContainer *pluginContainer);
-
- /**
* @brief Check wheter a name corresponds to a separator or not,
*
* @return whether the given name is used for separators.
@@ -979,33 +955,61 @@ protected:
* using multiple threads for all the mods.
*/
virtual void prefetch() = 0;
-
- static void updateIndices();
static bool ByName(const ModInfo::Ptr &LHS, const ModInfo::Ptr &RHS);
protected:
- static std::vector<ModInfo::Ptr> s_Collection;
- static ModInfo::Ptr s_Overwrite;
- static std::map<QString, unsigned int> s_ModsByName;
+ // the index of the mod in s_Collection, only valid after updateIndices()
+ int m_Index;
int m_PrimaryCategory;
std::set<int> m_Categories;
-
MOBase::VersionInfo m_Version;
-
bool m_PluginSelected = false;
-private:
+protected:
+
+ friend class OrganizerCore;
+
+ /**
+ * @brief Create a new mod from the specified directory and add it to the collection.
+ *
+ * @param dir Directory to create from.
+ *
+ * @return pointer to the info-structure of the newly created/added mod.
+ */
+ static ModInfo::Ptr createFrom(
+ PluginContainer* pluginContainer, const MOBase::IPluginGame* game,
+ const QDir& dir, MOShared::DirectoryEntry** directoryStructure);
+
+ /**
+ * @brief Create a new "foreign-managed" mod from a tuple of plugin and archives.
+ *
+ * @param espName Name of the plugin.
+ * @param bsaNames Names of archives.
+ *
+ * @return a new mod.
+ */
+ static ModInfo::Ptr createFromPlugin(
+ const QString& modName, const QString& espName, const QStringList& bsaNames,
+ ModInfo::EModType modType, const MOBase::IPluginGame* game,
+ MOShared::DirectoryEntry** directoryStructure, PluginContainer* pluginContainer);
static ModInfo::Ptr createFromOverwrite(PluginContainer* pluginContainer,
const MOBase::IPluginGame* game,
MOShared::DirectoryEntry** directoryStructure);
-private:
+ // update the m_Index attribute of all mods and the various mapping
+ //
+ static void updateIndices();
+
+protected:
static QMutex s_Mutex;
- static std::map<std::pair<QString, int>, std::vector<unsigned int> > s_ModsByModID;
+ static std::vector<ModInfo::Ptr> s_Collection;
+ static ModInfo::Ptr s_Overwrite;
+ static std::map<QString, unsigned int> s_ModsByName;
+ static std::map<std::pair<QString, int>, std::vector<unsigned int>> s_ModsByModID;
static int s_NextID;
};
diff --git a/src/modinforegular.cpp b/src/modinforegular.cpp
index c712adb1..6363dd6e 100644
--- a/src/modinforegular.cpp
+++ b/src/modinforegular.cpp
@@ -254,7 +254,7 @@ void ModInfoRegular::saveMeta()
if (m_TrackedState != TrackedState::TRACKED_UNKNOWN) {
metaFile.setValue("tracked", static_cast<std::underlying_type_t<TrackedState>>(m_TrackedState));
}
-
+
metaFile.remove("installedFiles");
metaFile.beginWriteArray("installedFiles");
int idx = 0;
@@ -462,6 +462,8 @@ bool ModInfoRegular::setName(const QString &name)
std::map<QString, unsigned int>::iterator nameIter = s_ModsByName.find(m_Name);
if (nameIter != s_ModsByName.end()) {
+ QMutexLocker locker(&s_Mutex);
+
unsigned int index = nameIter->second;
s_ModsByName.erase(nameIter);
@@ -879,7 +881,7 @@ std::vector<QString> ModInfoRegular::getIniTweaks() const
}
-std::map<QString, QVariant> ModInfoRegular::pluginSettings(const QString& pluginName) const
+std::map<QString, QVariant> ModInfoRegular::pluginSettings(const QString& pluginName) const
{
auto itp = m_PluginSettings.find(pluginName);
if (itp == std::end(m_PluginSettings)) {
diff --git a/src/organizercore.cpp b/src/organizercore.cpp
index 6eb81792..bf9308b8 100644
--- a/src/organizercore.cpp
+++ b/src/organizercore.cpp
@@ -690,6 +690,8 @@ MOBase::IModInterface *OrganizerCore::createMod(GuessedValue<QString> &name)
settingsFile.endArray();
}
+ // shouldn't this use the existing mod in case of a merge? also, this does not refresh the indices
+ // in the ModInfo structure
return ModInfo::createFrom(m_PluginContainer, m_GamePlugin, QDir(targetDirectory), &m_DirectoryStructure)
.data();
}