-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🚨Fix : use httplib and remove curl
- Loading branch information
Showing
3 changed files
with
77 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,76 @@ | ||
#include "download.hpp" | ||
#include "release.hpp" | ||
#include "utils.hpp" | ||
#include <cstdlib> | ||
#include <curl/curl.h> | ||
#include <filesystem> | ||
#include <iostream> | ||
#include <vector> | ||
#include "httplib.h" | ||
#include "release.hpp" | ||
#include "utils.hpp" | ||
|
||
namespace fs = std::filesystem; | ||
|
||
// download file from url | ||
auto download_zip(nlohmann::basic_json<> const &release) | ||
-> tl::expected<std::vector<char>, std::string> { | ||
auto const url = get_coollab_download_url(release); | ||
std::cout << url << std::endl; | ||
CURL *curl; | ||
curl = curl_easy_init(); | ||
std::vector<char> out_data; | ||
if (curl) { | ||
curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); | ||
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); | ||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_memory_callback); | ||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &out_data); | ||
CURLcode res; | ||
res = curl_easy_perform(curl); | ||
curl_easy_cleanup(curl); | ||
if (res == CURLE_OK) | ||
return out_data; | ||
else { | ||
std::cerr << "Failed to download zip file from URL: " << url << std::endl; | ||
std::cerr << curl_easy_strerror(res) << std::endl; | ||
return tl::make_unexpected("error"); // TODO : set a correct error message | ||
auto download_zip(nlohmann::json const& release) -> tl::expected<std::vector<char>, std::string> | ||
{ | ||
std::string url = "https://github.com"; | ||
httplib::Client cli(url); | ||
auto const path = get_coollab_download_url(release); | ||
|
||
cli.set_follow_location(true); // Allow the client to follow redirects | ||
|
||
auto res = cli.Get(path); | ||
if (res && res->status == 200) | ||
{ | ||
// Copy the response body into a vector | ||
std::vector<char> zip_data(res->body.begin(), res->body.end()); | ||
return zip_data; | ||
} | ||
} else { | ||
std::cerr << "Failed to initialize curl." << std::endl; | ||
return tl::make_unexpected("error"); // TODO : set a correct error message | ||
} | ||
return tl::unexpected("Failed to download the file. Status code: " + std::to_string(res->status)); | ||
} | ||
|
||
auto install_macos_dependencies_if_necessary() -> void { | ||
// Check if Homebrew is already installed | ||
if (std::system("command -v brew >/dev/null 2>&1")) | ||
install_homebrew(); | ||
else | ||
std::cout << "Homebrew is already installed." << std::endl; | ||
auto install_macos_dependencies_if_necessary() -> void | ||
{ | ||
// Check if Homebrew is already installed | ||
if (std::system("command -v brew >/dev/null 2>&1")) | ||
install_homebrew(); | ||
else | ||
std::cout << "Homebrew is already installed." << std::endl; | ||
|
||
// Check if FFmpeg is already installed | ||
if (std::system("command -v ffmpeg >/dev/null 2>&1")) | ||
install_ffmpeg(); | ||
else | ||
std::cout << "FFmpeg is already installed." << std::endl; | ||
// Check if FFmpeg is already installed | ||
if (std::system("command -v ffmpeg >/dev/null 2>&1")) | ||
install_ffmpeg(); | ||
else | ||
std::cout << "FFmpeg is already installed." << std::endl; | ||
} | ||
|
||
auto install_homebrew() -> void { | ||
std::cout << "Installing Homebrew..." << std::endl; | ||
int result = std::system( | ||
"/bin/bash -c \"$(curl -fsSL " | ||
"https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)\""); | ||
if (result != 0) { | ||
std::cerr << "Homebrew installation failed!" << std::endl; | ||
exit(result); | ||
} | ||
std::cout << "Homebrew successfully installed." << std::endl; | ||
auto install_homebrew() -> void | ||
{ | ||
std::cout << "Installing Homebrew..." << std::endl; | ||
int result = std::system( | ||
"/bin/bash -c \"$(curl -fsSL " | ||
"https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)\"" | ||
); | ||
if (result != 0) | ||
{ | ||
std::cerr << "Homebrew installation failed!" << std::endl; | ||
exit(result); | ||
} | ||
std::cout << "Homebrew successfully installed." << std::endl; | ||
} | ||
|
||
auto install_ffmpeg() -> void { | ||
std::cout << "Installing FFmpeg via Homebrew..." << std::endl; | ||
int result = std::system("brew install ffmpeg"); | ||
if (result != 0) { | ||
std::cerr << "FFmpeg installation failed!" << std::endl; | ||
exit(result); | ||
} | ||
std::cout << "FFmpeg successfully installed." << std::endl; | ||
auto install_ffmpeg() -> void | ||
{ | ||
std::cout << "Installing FFmpeg via Homebrew..." << std::endl; | ||
int result = std::system("brew install ffmpeg"); | ||
if (result != 0) | ||
{ | ||
std::cerr << "FFmpeg installation failed!" << std::endl; | ||
exit(result); | ||
} | ||
std::cout << "FFmpeg successfully installed." << std::endl; | ||
} | ||
|
||
auto coollab_version_is_installed(std::string_view const &version) -> bool { | ||
return fs::exists(get_PATH() + std::string(version)); | ||
auto coollab_version_is_installed(std::string_view const& version) -> bool | ||
{ | ||
return fs::exists(get_PATH() + std::string(version)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters