mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-26 09:35:28 +00:00
Modify the content file sorting algorithm to finish in finite time when encountering circular dependencies
This commit is contained in:
parent
2d3c6faec4
commit
ad44142dda
@ -504,40 +504,27 @@ QStringList ContentSelectorModel::ContentModel::gameFiles() const
|
|||||||
|
|
||||||
void ContentSelectorModel::ContentModel::sortFiles()
|
void ContentSelectorModel::ContentModel::sortFiles()
|
||||||
{
|
{
|
||||||
//first, sort the model such that all dependencies are ordered upstream (gamefile) first.
|
|
||||||
bool movedFiles = true;
|
|
||||||
int fileCount = mFiles.size();
|
|
||||||
|
|
||||||
//Dependency sort
|
//Dependency sort
|
||||||
//iterate until no sorting of files occurs
|
int sorted = 0;
|
||||||
while (movedFiles)
|
//iterate each file, obtaining a reference to its gamefiles list
|
||||||
|
for(int i = sorted; i < mFiles.size(); ++i)
|
||||||
{
|
{
|
||||||
movedFiles = false;
|
const QStringList& gameFiles = mFiles.at(i)->gameFiles();
|
||||||
//iterate each file, obtaining a reference to it's gamefiles list
|
int j = sorted;
|
||||||
for (int i = 0; i < fileCount; i++)
|
for(;j > 0; --j)
|
||||||
{
|
{
|
||||||
QModelIndex idx1 = index (i, 0, QModelIndex());
|
const auto file = mFiles.at(j - 1);
|
||||||
const QStringList &gamefiles = mFiles.at(i)->gameFiles();
|
if(gameFiles.contains(file->fileName(), Qt::CaseInsensitive)
|
||||||
//iterate each file after the current file, verifying that none of it's
|
|| (!mFiles.at(i)->isGameFile() && gameFiles.isEmpty()
|
||||||
//dependencies appear.
|
&& file->fileName().compare("Morrowind.esm", Qt::CaseInsensitive) == 0)) // Hack: implicit dependency on Morrowind.esm for dependency-less files
|
||||||
for (int j = i + 1; j < fileCount; j++)
|
|
||||||
{
|
|
||||||
if (gamefiles.contains(mFiles.at(j)->fileName(), Qt::CaseInsensitive)
|
|
||||||
|| (!mFiles.at(i)->isGameFile() && gamefiles.isEmpty()
|
|
||||||
&& mFiles.at(j)->fileName().compare("Morrowind.esm", Qt::CaseInsensitive) == 0)) // Hack: implicit dependency on Morrowind.esm for dependency-less files
|
|
||||||
{
|
|
||||||
mFiles.move(j, i);
|
|
||||||
|
|
||||||
QModelIndex idx2 = index (j, 0, QModelIndex());
|
|
||||||
|
|
||||||
emit dataChanged (idx1, idx2);
|
|
||||||
|
|
||||||
movedFiles = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (movedFiles)
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if(i != j)
|
||||||
|
{
|
||||||
|
mFiles.move(i, j);
|
||||||
|
emit dataChanged(index(i, 0, QModelIndex()), index(j, 0, QModelIndex()));
|
||||||
|
}
|
||||||
|
++sorted;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user