Track checked EsmFile pointers instead of full paths

pull/3233/head
Evil Eye 12 months ago
parent 521394d67b
commit 672cefd594

@ -64,6 +64,7 @@
Bug #7084: Resurrecting an actor doesn't take into account base record changes Bug #7084: Resurrecting an actor doesn't take into account base record changes
Bug #7088: Deleting last save game of last character doesn't clear character name/details Bug #7088: Deleting last save game of last character doesn't clear character name/details
Bug #7092: BSA archives from higher priority directories don't take priority Bug #7092: BSA archives from higher priority directories don't take priority
Bug #7103: Multiple paths pointing to the same plugin but with different cases lead to automatically removed config entries
Bug #7122: Teleportation to underwater should cancel active water walking effect Bug #7122: Teleportation to underwater should cancel active water walking effect
Bug #7131: MyGUI log spam when post processing HUD is open Bug #7131: MyGUI log spam when post processing HUD is open
Bug #7134: Saves with an invalid last generated RefNum can be loaded Bug #7134: Saves with an invalid last generated RefNum can be loaded

@ -125,27 +125,6 @@ namespace Launcher
{ {
return Settings::navigator().mMaxNavmeshdbFileSize / (1024 * 1024); return Settings::navigator().mMaxNavmeshdbFileSize / (1024 * 1024);
} }
std::optional<QString> findFirstPath(const QStringList& directories, const QString& fileName)
{
for (const QString& directoryPath : directories)
{
const QString filePath = QDir(directoryPath).absoluteFilePath(fileName);
if (QFile::exists(filePath))
return filePath;
}
return std::nullopt;
}
QStringList findAllFilePaths(const QStringList& directories, const QStringList& fileNames)
{
QStringList result;
result.reserve(fileNames.size());
for (const QString& fileName : fileNames)
if (const auto filepath = findFirstPath(directories, fileName))
result.append(*filepath);
return result;
}
} }
} }
@ -366,8 +345,7 @@ void Launcher::DataFilesPage::populateFileViews(const QString& contentModelName)
row++; row++;
} }
mSelector->setProfileContent( mSelector->setProfileContent(mLauncherSettings.getContentListFiles(contentModelName));
findAllFilePaths(directories, mLauncherSettings.getContentListFiles(contentModelName)));
} }
void Launcher::DataFilesPage::saveSettings(const QString& profile) void Launcher::DataFilesPage::saveSettings(const QString& profile)

@ -128,7 +128,7 @@ Qt::ItemFlags ContentSelectorModel::ContentModel::flags(const QModelIndex& index
continue; continue;
noGameFiles = false; noGameFiles = false;
if (isChecked(depFile->filePath())) if (mCheckedFiles.contains(depFile))
{ {
gamefileChecked = true; gamefileChecked = true;
break; break;
@ -215,7 +215,7 @@ QVariant ContentSelectorModel::ContentModel::data(const QModelIndex& index, int
if (file == mGameFile) if (file == mGameFile)
return QVariant(); return QVariant();
return mCheckStates[file->filePath()]; return mCheckedFiles.contains(file) ? Qt::Checked : Qt::Unchecked;
} }
case Qt::UserRole: case Qt::UserRole:
@ -229,7 +229,7 @@ QVariant ContentSelectorModel::ContentModel::data(const QModelIndex& index, int
} }
case Qt::UserRole + 1: case Qt::UserRole + 1:
return isChecked(file->filePath()); return mCheckedFiles.contains(file);
} }
return QVariant(); return QVariant();
} }
@ -277,12 +277,12 @@ bool ContentSelectorModel::ContentModel::setData(const QModelIndex& index, const
{ {
int checkValue = value.toInt(); int checkValue = value.toInt();
bool setState = false; bool setState = false;
if ((checkValue == Qt::Checked) && !isChecked(file->filePath())) if (checkValue == Qt::Checked && !mCheckedFiles.contains(file))
{ {
setState = true; setState = true;
success = true; success = true;
} }
else if ((checkValue == Qt::Checked) && isChecked(file->filePath())) else if (checkValue == Qt::Checked && mCheckedFiles.contains(file))
setState = true; setState = true;
else if (checkValue == Qt::Unchecked) else if (checkValue == Qt::Unchecked)
setState = true; setState = true;
@ -628,14 +628,6 @@ void ContentSelectorModel::ContentModel::sortFiles()
emit layoutChanged(); emit layoutChanged();
} }
bool ContentSelectorModel::ContentModel::isChecked(const QString& filepath) const
{
const auto it = mCheckStates.find(filepath);
if (it == mCheckStates.end())
return false;
return it.value() == Qt::Checked;
}
bool ContentSelectorModel::ContentModel::isEnabled(const QModelIndex& index) const bool ContentSelectorModel::ContentModel::isEnabled(const QModelIndex& index) const
{ {
return (flags(index) & Qt::ItemIsEnabled); return (flags(index) & Qt::ItemIsEnabled);
@ -723,7 +715,7 @@ QList<ContentSelectorModel::LoadOrderError> ContentSelectorModel::ContentModel::
} }
else else
{ {
if (!isChecked(dependentFile->filePath())) if (!mCheckedFiles.contains(dependentFile))
{ {
errors.append(LoadOrderError(LoadOrderError::ErrorCode_InactiveDependency, dependentfileName)); errors.append(LoadOrderError(LoadOrderError::ErrorCode_InactiveDependency, dependentfileName));
} }
@ -776,9 +768,13 @@ bool ContentSelectorModel::ContentModel::setCheckState(const QString& filepath,
Qt::CheckState state = Qt::Unchecked; Qt::CheckState state = Qt::Unchecked;
if (checkState) if (checkState)
{
state = Qt::Checked; state = Qt::Checked;
mCheckedFiles.insert(file);
}
else
mCheckedFiles.erase(file);
mCheckStates[filepath] = state;
emit dataChanged(indexFromItem(item(filepath)), indexFromItem(item(filepath))); emit dataChanged(indexFromItem(item(filepath)), indexFromItem(item(filepath)));
if (file->isGameFile()) if (file->isGameFile())
@ -794,8 +790,7 @@ bool ContentSelectorModel::ContentModel::setCheckState(const QString& filepath,
if (!upstreamFile) if (!upstreamFile)
continue; continue;
if (!isChecked(upstreamFile->filePath())) mCheckedFiles.insert(upstreamFile);
mCheckStates[upstreamFile->filePath()] = Qt::Checked;
emit dataChanged(indexFromItem(upstreamFile), indexFromItem(upstreamFile)); emit dataChanged(indexFromItem(upstreamFile), indexFromItem(upstreamFile));
} }
@ -810,8 +805,7 @@ bool ContentSelectorModel::ContentModel::setCheckState(const QString& filepath,
if (downstreamFile->gameFiles().contains(filename, Qt::CaseInsensitive)) if (downstreamFile->gameFiles().contains(filename, Qt::CaseInsensitive))
{ {
if (mCheckStates.contains(downstreamFile->filePath())) mCheckedFiles.erase(downstreamFile);
mCheckStates[downstreamFile->filePath()] = Qt::Unchecked;
emit dataChanged(indexFromItem(downstreamFile), indexFromItem(downstreamFile)); emit dataChanged(indexFromItem(downstreamFile), indexFromItem(downstreamFile));
} }
@ -829,7 +823,7 @@ ContentSelectorModel::ContentFileList ContentSelectorModel::ContentModel::checke
// First search for game files and next addons, // First search for game files and next addons,
// so we get more or less correct game files vs addons order. // so we get more or less correct game files vs addons order.
for (EsmFile* file : mFiles) for (EsmFile* file : mFiles)
if (isChecked(file->filePath())) if (mCheckedFiles.contains(file))
list << file; list << file;
return list; return list;
@ -838,6 +832,6 @@ ContentSelectorModel::ContentFileList ContentSelectorModel::ContentModel::checke
void ContentSelectorModel::ContentModel::uncheckAll() void ContentSelectorModel::ContentModel::uncheckAll()
{ {
emit layoutAboutToBeChanged(); emit layoutAboutToBeChanged();
mCheckStates.clear(); mCheckedFiles.clear();
emit layoutChanged(); emit layoutChanged();
} }

@ -7,6 +7,8 @@
#include <QSet> #include <QSet>
#include <QStringList> #include <QStringList>
#include <set>
namespace ContentSelectorModel namespace ContentSelectorModel
{ {
class EsmFile; class EsmFile;
@ -57,7 +59,6 @@ namespace ContentSelectorModel
void setCurrentGameFile(const EsmFile* file); void setCurrentGameFile(const EsmFile* file);
bool isEnabled(const QModelIndex& index) const; bool isEnabled(const QModelIndex& index) const;
bool isChecked(const QString& filepath) const;
bool setCheckState(const QString& filepath, bool isChecked); bool setCheckState(const QString& filepath, bool isChecked);
bool isNew(const QString& filepath) const; bool isNew(const QString& filepath) const;
void setNew(const QString& filepath, bool isChecked); void setNew(const QString& filepath, bool isChecked);
@ -85,7 +86,7 @@ namespace ContentSelectorModel
const EsmFile* mGameFile; const EsmFile* mGameFile;
ContentFileList mFiles; ContentFileList mFiles;
QStringList mArchives; QStringList mArchives;
QHash<QString, Qt::CheckState> mCheckStates; std::set<const EsmFile*> mCheckedFiles;
QHash<QString, bool> mNewFiles; QHash<QString, bool> mNewFiles;
QSet<QString> mPluginsWithLoadOrderError; QSet<QString> mPluginsWithLoadOrderError;
QString mEncoding; QString mEncoding;

Loading…
Cancel
Save