forgot try catch statement

This commit is contained in:
Luna 2024-10-06 20:55:16 +03:00
parent 0509d16de9
commit 89c280a785
2 changed files with 23 additions and 9 deletions

View file

@ -2,13 +2,13 @@
#include <curl/easy.h>
#include <fstream>
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<char *>(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);
}

View file

@ -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;