| 1334 | } |
| 1335 | |
| 1336 | bool GameList::DownloadCovers(const std::vector<std::string>& url_templates, bool use_serial, ProgressCallback* progress, |
| 1337 | std::function<void(const Entry*, std::string)> save_callback) |
| 1338 | { |
| 1339 | if (!progress) |
| 1340 | progress = ProgressCallback::NullProgressCallback; |
| 1341 | |
| 1342 | bool has_title = false; |
| 1343 | bool has_file_title = false; |
| 1344 | bool has_serial = false; |
| 1345 | for (const std::string& url_template : url_templates) |
| 1346 | { |
| 1347 | if (!has_title && url_template.find("${title}") != std::string::npos) |
| 1348 | has_title = true; |
| 1349 | if (!has_file_title && url_template.find("${filetitle}") != std::string::npos) |
| 1350 | has_file_title = true; |
| 1351 | if (!has_serial && url_template.find("${serial}") != std::string::npos) |
| 1352 | has_serial = true; |
| 1353 | } |
| 1354 | if (!has_title && !has_file_title && !has_serial) |
| 1355 | { |
| 1356 | progress->DisplayError("URL template must contain at least one of ${title}, ${filetitle}, or ${serial}."); |
| 1357 | return false; |
| 1358 | } |
| 1359 | |
| 1360 | if (!FileSystem::CreateDirectoryPath(EmuFolders::Covers.c_str(), false)) |
| 1361 | { |
| 1362 | progress->DisplayError(fmt::format("Failed to create covers directory: {}", EmuFolders::Covers).c_str()); |
| 1363 | return false; |
| 1364 | } |
| 1365 | |
| 1366 | std::vector<std::pair<std::string, std::string>> download_urls; |
| 1367 | { |
| 1368 | std::unique_lock lock(s_mutex); |
| 1369 | for (const GameList::Entry& entry : s_entries) |
| 1370 | { |
| 1371 | const std::string existing_path(GetCoverImagePathForEntry(&entry)); |
| 1372 | if (!existing_path.empty()) |
| 1373 | continue; |
| 1374 | |
| 1375 | for (const std::string& url_template : url_templates) |
| 1376 | { |
| 1377 | std::string url(url_template); |
| 1378 | if (has_title) |
| 1379 | StringUtil::ReplaceAll(&url, "${title}", Path::URLEncode(entry.title)); |
| 1380 | if (has_file_title) |
| 1381 | StringUtil::ReplaceAll(&url, "${filetitle}", Path::URLEncode(Path::GetFileTitle(entry.path))); |
| 1382 | if (has_serial) |
| 1383 | StringUtil::ReplaceAll(&url, "${serial}", Path::URLEncode(entry.serial)); |
| 1384 | |
| 1385 | download_urls.emplace_back(entry.path, std::move(url)); |
| 1386 | } |
| 1387 | } |
| 1388 | } |
| 1389 | if (download_urls.empty()) |
| 1390 | { |
| 1391 | progress->DisplayError("No URLs to download enumerated."); |
| 1392 | return false; |
| 1393 | } |
nothing calls this directly
no test coverage detected