| 442 | m_thumbnailThread = new std::thread(allocateThumbnail, id, onFetch); |
| 443 | } |
| 444 | bool WebAPI::DownloadShaderProject(const std::string& id) |
| 445 | { |
| 446 | Logger::Get().Log("Downloading shader project with WebAPI"); |
| 447 | |
| 448 | std::string outputPath = Settings::Instance().ConvertPath("temp/"); |
| 449 | |
| 450 | // first clear the old data and create new directory |
| 451 | std::error_code ec; |
| 452 | std::filesystem::remove_all(outputPath, ec); |
| 453 | std::filesystem::create_directory(outputPath); |
| 454 | |
| 455 | httplib::Client cli(WebAPI::URL.c_str()); |
| 456 | auto response = cli.Get(("/download.php?type=shader&id=" + id).c_str()); |
| 457 | |
| 458 | if (response && response->status == 200) { |
| 459 | const std::string& src = response->body; |
| 460 | |
| 461 | miniz_cpp::zip_file zipFile((unsigned char*)src.c_str(), src.size()); |
| 462 | std::vector<std::string> files = zipFile.namelist(); |
| 463 | for (int i = 0; i < files.size(); i++) { |
| 464 | miniz_cpp::zip_info fileInfo = zipFile.getinfo(files[i]); |
| 465 | |
| 466 | if (fileInfo.flag_bits == 0 && fileInfo.file_size == 0) |
| 467 | std::filesystem::create_directories(std::filesystem::path(outputPath) / fileInfo.filename); |
| 468 | } |
| 469 | zipFile.extractall(outputPath); |
| 470 | |
| 471 | return true; |
| 472 | } |
| 473 | |
| 474 | return false; |
| 475 | } |
| 476 | void WebAPI::SearchPlugins(const std::string& query, int page, const std::string& sort, const std::string& owner, std::function<void(const std::vector<WebAPI::PluginResult>&)> onFetch) |
| 477 | { |
| 478 | Logger::Get().Log("Searching SHADERed plugins with WebAPI"); |
no test coverage detected