| 388 | } |
| 389 | |
| 390 | void Profile::refreshModStatus() |
| 391 | { |
| 392 | // this function refreshes mod status (enabled/disabled) and priority |
| 393 | // using the profile mod list file and the mods in the mods folder using |
| 394 | // the following steps |
| 395 | // |
| 396 | // 1) the mod list file is read and mods status/priority are updated by |
| 397 | // considering the content of the file (for status) and the order (for |
| 398 | // priority), missing or invalid mods are discarded (with a warning) |
| 399 | // 2) the priority are reversed to match the plugin list (highest wins) |
| 400 | // since the mod list is written in reverse order |
| 401 | // 3) at the same time, new mods (not in the mod list file) are added |
| 402 | // - foreign mods are given low priority (below 0) |
| 403 | // - regular mods are given high priority (above mods from the mod list) |
| 404 | // 4) the priority are shifted to ensure that the minimum priority is 0 |
| 405 | // 5) the priority of backups are computed such that the first backup is |
| 406 | // above all regular mods |
| 407 | // |
| 408 | // in the context of the profile, "regular mods" means a mod whose priority |
| 409 | // can be set by the user (i.e. not a backup or overwrite) |
| 410 | // |
| 411 | // this method ensures that the mods priority is as follow |
| 412 | // |
| 413 | // 0 mod1 |
| 414 | // 1 mod2 |
| 415 | // ... |
| 416 | // K-1 modK (K = m_NumRegularMods) |
| 417 | // K backup1 |
| 418 | // K+1 backup2 |
| 419 | // ... |
| 420 | // N-2 backupX |
| 421 | // N-1 overwrite (N = number of mods) |
| 422 | // |
| 423 | |
| 424 | writeModlistNow(true); // if there are pending changes write them first |
| 425 | |
| 426 | QFile file(getModlistFileName()); |
| 427 | if (!file.open(QIODevice::ReadOnly)) { |
| 428 | throw MyException( |
| 429 | tr("\"%1\" is missing or inaccessible").arg(getModlistFileName())); |
| 430 | } |
| 431 | |
| 432 | bool modStatusModified = false; |
| 433 | m_ModStatus.clear(); |
| 434 | m_ModStatus.resize(ModInfo::getNumMods()); |
| 435 | |
| 436 | std::set<QString> namesRead; |
| 437 | |
| 438 | bool warnAboutOverwrite = false; |
| 439 | |
| 440 | // load mods from file and update enabled state and priority for them |
| 441 | int index = 0; |
| 442 | while (!file.atEnd()) { |
| 443 | QByteArray line = file.readLine().trimmed(); |
| 444 | |
| 445 | // find the mod name and the enabled status |
| 446 | bool enabled = true; |
| 447 | QString modName; |
no test coverage detected