Check for update: * - Get latest version available * - Compare hash of the latest version with the current hash * - If equal, no updates, else, there's updates, so add to the list * */
| 120 | * - If equal, no updates, else, there's updates, so add to the list |
| 121 | * */ |
| 122 | void FlameCheckUpdate::executeTask() |
| 123 | { |
| 124 | setStatus(tr("Preparing mods for CurseForge...")); |
| 125 | |
| 126 | int i = 0; |
| 127 | for (auto* mod : m_mods) { |
| 128 | setStatus(tr("Getting API response from CurseForge for '%1'...").arg(mod->name())); |
| 129 | setProgress(i++, m_mods.size()); |
| 130 | |
| 131 | auto latest_vers = api.getLatestVersions({ { mod->metadata()->project_id.toString() }, m_game_versions }); |
| 132 | |
| 133 | // Check if we were aborted while getting the latest version |
| 134 | if (m_was_aborted) { |
| 135 | aborted(); |
| 136 | return; |
| 137 | } |
| 138 | auto latest_ver = api.getLatestVersion(latest_vers, m_loaders_list, mod->loaders()); |
| 139 | |
| 140 | setStatus(tr("Parsing the API response from CurseForge for '%1'...").arg(mod->name())); |
| 141 | |
| 142 | if (!latest_ver.has_value() || !latest_ver->addonId.isValid()) { |
| 143 | emit checkFailed(mod, tr("No valid version found for this mod. It's probably unavailable for the current game " |
| 144 | "version / mod loader.")); |
| 145 | continue; |
| 146 | } |
| 147 | |
| 148 | if (latest_ver->downloadUrl.isEmpty() && latest_ver->fileId != mod->metadata()->file_id) { |
| 149 | auto pack = getProjectInfo(latest_ver.value()); |
| 150 | auto recover_url = QString("%1/download/%2").arg(pack.websiteUrl, latest_ver->fileId.toString()); |
| 151 | emit checkFailed(mod, tr("Mod has a new update available, but is not downloadable using CurseForge."), recover_url); |
| 152 | |
| 153 | continue; |
| 154 | } |
| 155 | |
| 156 | // Fake pack with the necessary info to pass to the download task :) |
| 157 | auto pack = std::make_shared<ModPlatform::IndexedPack>(); |
| 158 | pack->name = mod->name(); |
| 159 | pack->slug = mod->metadata()->slug; |
| 160 | pack->addonId = mod->metadata()->project_id; |
| 161 | pack->websiteUrl = mod->homeurl(); |
| 162 | for (auto& author : mod->authors()) |
| 163 | pack->authors.append({ author }); |
| 164 | pack->description = mod->description(); |
| 165 | pack->provider = ModPlatform::ResourceProvider::FLAME; |
| 166 | if (!latest_ver->hash.isEmpty() && (mod->metadata()->hash != latest_ver->hash || mod->status() == ModStatus::NotInstalled)) { |
| 167 | auto old_version = mod->version(); |
| 168 | if (old_version.isEmpty() && mod->status() != ModStatus::NotInstalled) { |
| 169 | auto current_ver = getFileInfo(latest_ver->addonId.toInt(), mod->metadata()->file_id.toInt()); |
| 170 | old_version = current_ver.version; |
| 171 | } |
| 172 | |
| 173 | auto download_task = makeShared<ResourceDownloadTask>(pack, latest_ver.value(), m_mods_folder); |
| 174 | m_updatable.emplace_back(pack->name, mod->metadata()->hash, old_version, latest_ver->version, latest_ver->version_type, |
| 175 | api.getModFileChangelog(latest_ver->addonId.toInt(), latest_ver->fileId.toInt()), |
| 176 | ModPlatform::ResourceProvider::FLAME, download_task, mod->enabled()); |
| 177 | } |
| 178 | m_deps.append(std::make_shared<GetModDependenciesTask::PackDependency>(pack, latest_ver.value())); |
| 179 | } |
nothing calls this directly
no test coverage detected