| 69 | } |
| 70 | |
| 71 | void PathsSettingsTab::update() |
| 72 | { |
| 73 | using Setter = void (PathSettings::*)(const QString&); |
| 74 | using Directory = std::tuple<QString, Setter, std::wstring>; |
| 75 | |
| 76 | QString basePath = settings().paths().base(); |
| 77 | |
| 78 | for (const Directory& dir : |
| 79 | {Directory{ui->downloadDirEdit->text(), &PathSettings::setDownloads, |
| 80 | AppConfig::downloadPath()}, |
| 81 | Directory{ui->cacheDirEdit->text(), &PathSettings::setCache, |
| 82 | AppConfig::cachePath()}, |
| 83 | Directory{ui->modDirEdit->text(), &PathSettings::setMods, |
| 84 | AppConfig::modsPath()}, |
| 85 | Directory{ui->overwriteDirEdit->text(), &PathSettings::setOverwrite, |
| 86 | AppConfig::overwritePath()}, |
| 87 | Directory{ui->profilesDirEdit->text(), &PathSettings::setProfiles, |
| 88 | AppConfig::profilesPath()}}) { |
| 89 | QString path; |
| 90 | Setter setter; |
| 91 | std::wstring defaultName; |
| 92 | std::tie(path, setter, defaultName) = dir; |
| 93 | |
| 94 | QString realPath = path; |
| 95 | realPath = PathSettings::resolve(realPath, ui->baseDirEdit->text()); |
| 96 | |
| 97 | if (!QDir(realPath).exists()) { |
| 98 | if (!QDir().mkpath(realPath)) { |
| 99 | QMessageBox::warning( |
| 100 | parentWidget(), QObject::tr("Error"), |
| 101 | QObject::tr("Failed to create \"%1\", you may not have the " |
| 102 | "necessary permissions. Path remains unchanged.") |
| 103 | .arg(realPath)); |
| 104 | |
| 105 | continue; |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | if (QFileInfo(realPath) != |
| 110 | QFileInfo(basePath + "/" + QString::fromStdWString(defaultName))) { |
| 111 | (settings().paths().*setter)(path); |
| 112 | } else { |
| 113 | (settings().paths().*setter)(""); |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | if (QFileInfo(ui->baseDirEdit->text()) != |
| 118 | QFileInfo(qApp->property("dataPath").toString())) { |
| 119 | settings().paths().setBase(ui->baseDirEdit->text()); |
| 120 | } else { |
| 121 | settings().paths().setBase(""); |
| 122 | } |
| 123 | |
| 124 | if (m_gameDir != settings().game().plugin()->gameDirectory()) { |
| 125 | settings().game().setDirectory(m_gameDir.absolutePath()); |
| 126 | } |
| 127 | } |
| 128 |
nothing calls this directly
no test coverage detected