Merge pull request #1054 from Ryex/more-lax-block-mods-filename-check
This commit is contained in:
commit
ce5bb29c44
@ -203,7 +203,6 @@ void BlockedModsDialog::watchPath(QString path, bool watch_recursive)
|
|||||||
if (!to_watch.isDir() || !watch_recursive)
|
if (!to_watch.isDir() || !watch_recursive)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
||||||
QDirIterator it(to_watch_path, QDir::Filter::Dirs | QDir::Filter::NoDotAndDotDot, QDirIterator::NoIteratorFlags);
|
QDirIterator it(to_watch_path, QDir::Filter::Dirs | QDir::Filter::NoDotAndDotDot, QDirIterator::NoIteratorFlags);
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
QString watch_dir = QDir(it.next()).canonicalPath(); // resolve symlinks and relative paths
|
QString watch_dir = QDir(it.next()).canonicalPath(); // resolve symlinks and relative paths
|
||||||
@ -302,11 +301,35 @@ bool BlockedModsDialog::checkValidPath(QString path)
|
|||||||
{
|
{
|
||||||
const QFileInfo file = QFileInfo(path);
|
const QFileInfo file = QFileInfo(path);
|
||||||
const QString filename = file.fileName();
|
const QString filename = file.fileName();
|
||||||
QString laxFilename(filename);
|
|
||||||
laxFilename.replace('+', ' ');
|
|
||||||
|
|
||||||
auto compare = [](QString fsfilename, QString metadataFilename) {
|
auto compare = [](QString fsFilename, QString metadataFilename) {
|
||||||
return metadataFilename.compare(fsfilename, Qt::CaseInsensitive) == 0;
|
return metadataFilename.compare(fsFilename, Qt::CaseInsensitive) == 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
// super lax compare (but not fuzzy)
|
||||||
|
// convert to lowercase
|
||||||
|
// convert all speratores to whitespace
|
||||||
|
// simplify sequence of internal whitespace to a single space
|
||||||
|
// efectivly compare two strings ignoring all separators and case
|
||||||
|
auto laxCompare = [](QString fsfilename, QString metadataFilename) {
|
||||||
|
// allowed character seperators
|
||||||
|
QList<QChar> allowedSeperators = { '-', '+', '.' , '_'};
|
||||||
|
|
||||||
|
// copy in lowercase
|
||||||
|
auto fsName = fsfilename.toLower();
|
||||||
|
auto metaName = metadataFilename.toLower();
|
||||||
|
|
||||||
|
// replace all potential allowed seperatores with whitespace
|
||||||
|
for (auto sep : allowedSeperators) {
|
||||||
|
fsName = fsName.replace(sep, ' ');
|
||||||
|
metaName = metaName.replace(sep, ' ');
|
||||||
|
}
|
||||||
|
|
||||||
|
// remove extraneous whitespace
|
||||||
|
fsName = fsName.simplified();
|
||||||
|
metaName = metaName.simplified();
|
||||||
|
|
||||||
|
return fsName.compare(metaName) == 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
for (auto& mod : m_mods) {
|
for (auto& mod : m_mods) {
|
||||||
@ -314,7 +337,7 @@ bool BlockedModsDialog::checkValidPath(QString path)
|
|||||||
qDebug() << "[Blocked Mods Dialog] Name match found:" << mod.name << "| From path:" << path;
|
qDebug() << "[Blocked Mods Dialog] Name match found:" << mod.name << "| From path:" << path;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (compare(laxFilename, mod.name)) {
|
if (laxCompare(filename, mod.name)) {
|
||||||
qDebug() << "[Blocked Mods Dialog] Lax name match found:" << mod.name << "| From path:" << path;
|
qDebug() << "[Blocked Mods Dialog] Lax name match found:" << mod.name << "| From path:" << path;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user