From 89c280a7856f7971147146c7e40b8695d99276c7 Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 6 Oct 2024 20:55:16 +0300 Subject: [PATCH] forgot try catch statement --- src/getHttp.cpp | 11 +++++++---- src/main.cpp | 21 ++++++++++++++++----- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/getHttp.cpp b/src/getHttp.cpp index b1df58f..2d6a774 100644 --- a/src/getHttp.cpp +++ b/src/getHttp.cpp @@ -2,13 +2,13 @@ #include #include -size_t appendCurlOutputToString(void *ptr, size_t size, size_t nmemb, std::string *woof){ +size_t appendCurlOutputToString(void *ptr, size_t size, size_t nmemb, std::string *woof) { // append the output from curl to a string woof->append(static_cast(ptr), size*nmemb); return size*nmemb; } -void writeHtmlFile(std::string* woof, std::string *outputfile){ +void writeHtmlFile(std::string* woof, std::string *outputfile) { // check for nullptrs if (!woof || !outputfile){ throw("string is null\n"); @@ -18,7 +18,7 @@ void writeHtmlFile(std::string* woof, std::string *outputfile){ meow << *woof; } -void getHttp(std::string url, std::string *outputfile){ +void getHttp(std::string url, std::string *outputfile) { //initialize curl object and curlcode CURL *meow = curl_easy_init(); CURLcode res; @@ -33,7 +33,10 @@ void getHttp(std::string url, std::string *outputfile){ curl_easy_setopt(meow, CURLOPT_WRITEFUNCTION, appendCurlOutputToString); curl_easy_setopt(meow, CURLOPT_WRITEDATA, &woof); // perform the request - curl_easy_perform(meow); + res = curl_easy_perform(meow); + if (res != CURLE_OK){ + throw("failed to perform the request\n"); + } writeHtmlFile(&woof, outputfile); curl_easy_cleanup(meow); } diff --git a/src/main.cpp b/src/main.cpp index b6763fe..239df08 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -85,8 +85,13 @@ int main(int argc, char **argv, char **envp) { if (argc == 7) { dir = ARGS[1+5]; } - - getHttp(std::string {"https://steamcommunity.com/sharedfiles/filedetails/?id=" + collectionid}, &cachesc); + try { + getHttp(std::string {"https://steamcommunity.com/sharedfiles/filedetails/?id=" + collectionid}, &cachesc); + } + catch(std::string& meow) { + std::cout << meow; + return 1; + } std::cout << collectionid << user << pass << gameid << dir; std::cout << "success1\n"; break; @@ -100,9 +105,15 @@ int main(int argc, char **argv, char **envp) { if (argc == 5) { dir = ARGS[1+3]; } - - getHttp(std::string {"https://steamcommunity.com/sharedfiles/filedetails/?id=" + collectionid}, &cachesc); - std::cout << collectionid << gameid << dir; + try { + getHttp(std::string {"https://steamcommunity.com/sharedfiles/filedetails/?id=" + collectionid}, &cachesc); + } + catch(std::string& meow) { + std::cout << meow; + return 1; + } + + std::cout << collectionid << gameid << dir << '\n'; std::cout << "success\n"; break;