__FORCE_ALIGN_STACK__ int Download(int ID, const std::string& filename, DownloadEnum::Category cat) { currentDownloadID = ID; // FIXME: Progress is incorrectly updated when rapid is queried to check for existing packages. SetDownloadListener(UpdateProgress); LOG_L(L_DEBUG, "Going to download %s", filename.c_str()); DownloadInit(); const int count = DownloadSearch(cat, filename.c_str()); for (int i = 0; i < count; i++) { DownloadAdd(i); struct downloadInfo dl; if (DownloadGetInfo(i, dl)) { LOG_L(L_DEBUG, "Download info: %s %d", dl.filename, dl.cat); } } int result; LOG_L(L_DEBUG, "Download count: %d", count); // TODO: count will be 1 when archives already exist. We should instead return a different result with DownloadFailed/DownloadFinished? if (count == 0) { // there's nothing to download result = 2; QueueDownloadFailed(ID, result); } else { QueueDownloadStarted(ID); result = DownloadStart(); LOG_L(L_DEBUG, "Download finished %s", filename.c_str()); } DownloadShutdown(); return result; }
void StartDownload() { isDownloading = true; const DownloadItem downloadItem = queue.front(); queue.pop_front(); const std::string& filename = downloadItem.filename; DownloadEnum::Category cat = downloadItem.cat; int ID = downloadItem.ID; if (!filename.empty()) { LOG_L(L_DEBUG, "DOWNLOADING: %s", filename.c_str()); } boost::thread {[ID, filename, cat]() { const int result = Download(ID, filename, cat); if (result == 0) { QueueDownloadFinished(ID); } else { QueueDownloadFailed(ID, result); } queueMutex.lock(); if (!queue.empty()) { queueMutex.unlock(); StartDownload(); } else { isDownloading = false; queueMutex.unlock(); } } }.detach(); }
__FORCE_ALIGN_STACK__ int Download(int ID, const std::string& filename, DownloadEnum::Category cat) { currentDownloadID = ID; // FIXME: Progress is incorrectly updated when rapid is queried to check for existing packages. SetDownloadListener(UpdateProgress); LOG_L(L_DEBUG, "Going to download %s", filename.c_str()); DownloadInit(); const int count = DownloadSearch(cat, filename.c_str()); for (int i = 0; i < count; i++) { DownloadAdd(i); struct downloadInfo dl; if (DownloadGetInfo(i, dl)) { LOG_L(L_DEBUG, "Download info: %s %d", dl.filename, dl.cat); } } int result; LOG_L(L_DEBUG, "Download count: %d", count); // TODO: count will be 1 when archives already exist. We should instead return a different result with DownloadFailed/DownloadFinished? if (count == 0) { // there's nothing to download result = 2; QueueDownloadFailed(ID, result); } else { LOG_L(L_DEBUG, "Download finished %s", filename.c_str()); QueueDownloadStarted(ID); result = DownloadStart(); // TODO: This works but there are errors spammed as it's trying to clear timers in the main thread, which this is not: // Error: [Watchdog::ClearTimer(id)] Invalid thread 4 (_threadId=(nil)) archiveScanner->ScanAllDirs(); } DownloadShutdown(); return result; }