\brief Download multiple files with progress tracking \param downloads the downloads \param progress_cb the progress callback \return true if the files are downloaded, false otherwise
| 250 | /// \param progress_cb the progress callback |
| 251 | /// \return true if the files are downloaded, false otherwise |
| 252 | bool download_multiple_files(const nlohmann::json downloads, |
| 253 | std::function<void(size_t, size_t)> progress_cb) { |
| 254 | size_t total_files = downloads.size(); |
| 255 | size_t completed_files = 0; |
| 256 | |
| 257 | // Hide cursor before starting downloads |
| 258 | //hide_cursor(); |
| 259 | |
| 260 | for (auto& file : downloads) { |
| 261 | std::string url = file["url"]; |
| 262 | std::string local_path = file["localpath"]; |
| 263 | std::string filename = std::filesystem::path(url).filename().string(); |
| 264 | std::string remote_oid = file["oid"]; |
| 265 | bool is_lfs = file["is_lfs"]; |
| 266 | |
| 267 | // cut "?download=true" |
| 268 | if (filename.find("?download=true") != std::string::npos) { |
| 269 | filename = filename.substr(0, filename.find("?download=true")); |
| 270 | } |
| 271 | header_print("FLM", "Downloading " << (completed_files + 1) << "/" << total_files |
| 272 | << ": " << filename); |
| 273 | |
| 274 | auto file_progress = [&](double percentage) { |
| 275 | if (progress_cb) { |
| 276 | progress_cb(completed_files, total_files); |
| 277 | } |
| 278 | }; |
| 279 | |
| 280 | if (!download_with_retry(url, local_path, is_lfs, remote_oid, file_progress)) { |
| 281 | std::cerr << "Failed to download: " << url << std::endl; |
| 282 | //show_cursor(); // Show cursor on error |
| 283 | return false; |
| 284 | } |
| 285 | |
| 286 | completed_files++; |
| 287 | if (progress_cb) { |
| 288 | progress_cb(completed_files, total_files); |
| 289 | } |
| 290 | } |
| 291 | |
| 292 | // Show cursor after all downloads complete |
| 293 | show_cursor(); |
| 294 | header_print("FLM", "All downloads completed successfully!"); |
| 295 | return true; |
| 296 | } |
| 297 | |
| 298 | /// \brief Initialize CURL library (call this once at program startup) |
| 299 | /// \return true if the CURL library is initialized, false otherwise |
no test coverage detected