@brief Check if the name of the file at path matches the name of a blocked mod we are searching for @param path the path to check @return boolean: did the path match the name of a blocked mod?
| 312 | /// @param path the path to check |
| 313 | /// @return boolean: did the path match the name of a blocked mod? |
| 314 | bool BlockedModsDialog::checkValidPath(QString path) |
| 315 | { |
| 316 | const QFileInfo file = QFileInfo(path); |
| 317 | const QString filename = file.fileName(); |
| 318 | |
| 319 | auto compare = [](QString fsFilename, QString metadataFilename) { |
| 320 | return metadataFilename.compare(fsFilename, Qt::CaseInsensitive) == 0; |
| 321 | }; |
| 322 | |
| 323 | // super lax compare (but not fuzzy) |
| 324 | // convert to lowercase |
| 325 | // convert all speratores to whitespace |
| 326 | // simplify sequence of internal whitespace to a single space |
| 327 | // efectivly compare two strings ignoring all separators and case |
| 328 | auto laxCompare = [](QString fsfilename, QString metadataFilename) { |
| 329 | // allowed character seperators |
| 330 | QList<QChar> allowedSeperators = { '-', '+', '.', '_' }; |
| 331 | |
| 332 | // copy in lowercase |
| 333 | auto fsName = fsfilename.toLower(); |
| 334 | auto metaName = metadataFilename.toLower(); |
| 335 | |
| 336 | // replace all potential allowed seperatores with whitespace |
| 337 | for (auto sep : allowedSeperators) { |
| 338 | fsName = fsName.replace(sep, ' '); |
| 339 | metaName = metaName.replace(sep, ' '); |
| 340 | } |
| 341 | |
| 342 | // remove extraneous whitespace |
| 343 | fsName = fsName.simplified(); |
| 344 | metaName = metaName.simplified(); |
| 345 | |
| 346 | return fsName.compare(metaName) == 0; |
| 347 | }; |
| 348 | |
| 349 | for (auto& mod : m_mods) { |
| 350 | if (compare(filename, mod.name)) { |
| 351 | // if the mod is not yet matched and doesn't have a hash then |
| 352 | // just match it with the file that has the exact same name |
| 353 | if (!mod.matched && mod.hash.isEmpty()) { |
| 354 | mod.matched = true; |
| 355 | mod.localPath = path; |
| 356 | return false; |
| 357 | } |
| 358 | qDebug() << "[Blocked Mods Dialog] Name match found:" << mod.name << "| From path:" << path; |
| 359 | return true; |
| 360 | } |
| 361 | if (laxCompare(filename, mod.name)) { |
| 362 | qDebug() << "[Blocked Mods Dialog] Lax name match found:" << mod.name << "| From path:" << path; |
| 363 | return true; |
| 364 | } |
| 365 | } |
| 366 | |
| 367 | return false; |
| 368 | } |
| 369 | |
| 370 | bool BlockedModsDialog::allModsMatched() |
| 371 | { |