| 495 | return allocated; |
| 496 | } |
| 497 | void WebAPI::DownloadPlugin(const std::string& id) |
| 498 | { |
| 499 | Logger::Get().Log("Downloading a plugin with WebAPI"); |
| 500 | |
| 501 | std::string body = "/download?type=plugin&id=" + id + "&os="; |
| 502 | #if defined(_WIN64) |
| 503 | body += "w64"; |
| 504 | #elif defined(_WIN32) |
| 505 | body += "w32"; |
| 506 | #elif defined(__linux__) || defined(__unix__) |
| 507 | body += "lin"; |
| 508 | #endif |
| 509 | |
| 510 | std::string outputDir = Settings::Instance().ConvertPath("."); |
| 511 | |
| 512 | httplib::Client cli(WebAPI::URL.c_str()); |
| 513 | auto response = cli.Get(body.c_str()); |
| 514 | |
| 515 | if (response && response->status == 200) { |
| 516 | const std::string& src = response->body; |
| 517 | |
| 518 | miniz_cpp::zip_file zipFile((unsigned char*)src.c_str(), src.size()); |
| 519 | std::vector<std::string> files = zipFile.namelist(); |
| 520 | for (int i = 0; i < files.size(); i++) { |
| 521 | miniz_cpp::zip_info fileInfo = zipFile.getinfo(files[i]); |
| 522 | |
| 523 | if (fileInfo.flag_bits == 0 && fileInfo.file_size == 0) |
| 524 | std::filesystem::create_directories(std::filesystem::path(outputDir) / fileInfo.filename); |
| 525 | } |
| 526 | zipFile.extractall(outputDir); |
| 527 | } |
| 528 | } |
| 529 | void WebAPI::SearchThemes(const std::string& query, int page, const std::string& sort, const std::string& owner, std::function<void(const std::vector<ThemeResult>&)> onFetch) |
| 530 | { |
| 531 | Logger::Get().Log("Searching SHADERed themes with WebAPI"); |
no test coverage detected