MCPcopy Create free account
hub / github.com/PolyMC/PolyMC / executeTask

Method executeTask

launcher/modplatform/flame/FlameCheckUpdate.cpp:115–179  ·  view source on GitHub ↗

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 * */

Source from the content-addressed store, hash-verified

113 * - If equal, no updates, else, there's updates, so add to the list
114 * */
115void FlameCheckUpdate::executeTask()
116{
117 setStatus(tr("Preparing mods for CurseForge..."));
118
119 int i = 0;
120 for (auto* mod : m_mods) {
121 if (!mod->enabled()) {
122 emit checkFailed(mod, tr("Disabled mods won't be updated, to prevent mod duplication issues!"));
123 continue;
124 }
125
126 setStatus(tr("Getting API response from CurseForge for '%1'...").arg(mod->name()));
127 setProgress(i++, m_mods.size());
128
129 auto latest_ver = api.getLatestVersion({ mod->metadata()->project_id.toString(), m_game_versions, m_loaders });
130
131 // Check if we were aborted while getting the latest version
132 if (m_was_aborted) {
133 aborted();
134 return;
135 }
136
137 setStatus(tr("Parsing the API response from CurseForge for '%1'...").arg(mod->name()));
138
139 if (!latest_ver.addonId.isValid()) {
140 emit checkFailed(mod, tr("No valid version found for this mod. It's probably unavailable for the current game "
141 "version / mod loader."));
142 continue;
143 }
144
145 if (latest_ver.downloadUrl.isEmpty() && latest_ver.fileId != mod->metadata()->file_id) {
146 auto pack = getProjectInfo(latest_ver);
147 auto recover_url = QString("%1/download/%2").arg(pack.websiteUrl, latest_ver.fileId.toString());
148 emit checkFailed(mod, tr("Mod has a new update available, but is not downloadable using CurseForge."), recover_url);
149
150 continue;
151 }
152
153 if (!latest_ver.hash.isEmpty() && (mod->metadata()->hash != latest_ver.hash || mod->status() == ModStatus::NotInstalled)) {
154 // Fake pack with the necessary info to pass to the download task :)
155 ModPlatform::IndexedPack pack;
156 pack.name = mod->name();
157 pack.slug = mod->metadata()->slug;
158 pack.addonId = mod->metadata()->project_id;
159 pack.websiteUrl = mod->homeurl();
160 for (auto& author : mod->authors())
161 pack.authors.append({ author, "" });
162 pack.description = mod->description();
163 pack.provider = ModPlatform::Provider::FLAME;
164
165 auto old_version = mod->version();
166 if (old_version.isEmpty() && mod->status() != ModStatus::NotInstalled) {
167 auto current_ver = getFileInfo(latest_ver.addonId.toInt(), mod->metadata()->file_id.toInt());
168 old_version = current_ver.version;
169 }
170
171 auto download_task = new ModDownloadTask(pack, latest_ver, m_mods_folder);
172 m_updatable.emplace_back(pack.name, mod->metadata()->hash, old_version, latest_ver.version,

Callers

nothing calls this directly

Calls 15

getProjectInfoFunction · 0.85
QStringClass · 0.85
getFileInfoFunction · 0.85
enabledMethod · 0.80
getLatestVersionMethod · 0.80
metadataMethod · 0.80
isEmptyMethod · 0.80
homeurlMethod · 0.80
authorsMethod · 0.80
appendMethod · 0.80
getModFileChangelogMethod · 0.80
nameMethod · 0.45

Tested by

no test coverage detected