| 348 | |
| 349 | |
| 350 | void syncUpdate(std::string slug) { |
| 351 | if (!updateMutex.try_lock()) |
| 352 | return; |
| 353 | DEFER({updateMutex.unlock();}); |
| 354 | |
| 355 | if (settings::token.empty()) |
| 356 | return; |
| 357 | |
| 358 | isSyncing = true; |
| 359 | DEFER({isSyncing = false;}); |
| 360 | |
| 361 | // Get the UpdateInfo object |
| 362 | auto it = updateInfos.find(slug); |
| 363 | if (it == updateInfos.end()) |
| 364 | return; |
| 365 | UpdateInfo update = it->second; |
| 366 | |
| 367 | // Don't update if not compatible with Rack version |
| 368 | if (update.minRackVersion != "") |
| 369 | return; |
| 370 | |
| 371 | updateSlug = slug; |
| 372 | DEFER({updateSlug = "";}); |
| 373 | |
| 374 | // Set progress to 0% |
| 375 | updateProgress = 0.f; |
| 376 | DEFER({updateProgress = 0.f;}); |
| 377 | |
| 378 | INFO("Downloading plugin %s v%s for %s-%s", slug.c_str(), update.version.c_str(), APP_OS.c_str(), APP_CPU.c_str()); |
| 379 | |
| 380 | // Get download URL |
| 381 | std::string downloadUrl = API_URL + "/download"; |
| 382 | downloadUrl += "?slug=" + network::encodeUrl(slug); |
| 383 | downloadUrl += "&version=" + network::encodeUrl(update.version); |
| 384 | downloadUrl += "&arch=" + network::encodeUrl(APP_OS + "-" + APP_CPU); |
| 385 | |
| 386 | // Get file path |
| 387 | std::string packageFilename = slug + "-" + update.version + "-" + APP_OS + "-" + APP_CPU + ".vcvplugin"; |
| 388 | std::string packagePath = system::join(plugin::pluginsPath, packageFilename); |
| 389 | |
| 390 | // Download plugin package |
| 391 | if (!network::requestDownload(downloadUrl, packagePath, &updateProgress, getTokenCookies())) { |
| 392 | WARN("Plugin %s download was unsuccessful", slug.c_str()); |
| 393 | return; |
| 394 | } |
| 395 | |
| 396 | // updateInfos could possibly change in the checkUpdates() thread, so re-get the UpdateInfo to modify it. |
| 397 | it = updateInfos.find(slug); |
| 398 | if (it == updateInfos.end()) |
| 399 | return; |
| 400 | it->second.downloaded = true; |
| 401 | } |
| 402 | |
| 403 | |
| 404 | void syncUpdates() { |
no test coverage detected