forgot try catch statement
This commit is contained in:
parent
0509d16de9
commit
89c280a785
2 changed files with 23 additions and 9 deletions
|
@ -2,13 +2,13 @@
|
||||||
#include <curl/easy.h>
|
#include <curl/easy.h>
|
||||||
#include <fstream>
|
#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
|
// append the output from curl to a string
|
||||||
woof->append(static_cast<char *>(ptr), size*nmemb);
|
woof->append(static_cast<char *>(ptr), size*nmemb);
|
||||||
return size*nmemb;
|
return size*nmemb;
|
||||||
}
|
}
|
||||||
|
|
||||||
void writeHtmlFile(std::string* woof, std::string *outputfile){
|
void writeHtmlFile(std::string* woof, std::string *outputfile) {
|
||||||
// check for nullptrs
|
// check for nullptrs
|
||||||
if (!woof || !outputfile){
|
if (!woof || !outputfile){
|
||||||
throw("string is null\n");
|
throw("string is null\n");
|
||||||
|
@ -18,7 +18,7 @@ void writeHtmlFile(std::string* woof, std::string *outputfile){
|
||||||
meow << *woof;
|
meow << *woof;
|
||||||
}
|
}
|
||||||
|
|
||||||
void getHttp(std::string url, std::string *outputfile){
|
void getHttp(std::string url, std::string *outputfile) {
|
||||||
//initialize curl object and curlcode
|
//initialize curl object and curlcode
|
||||||
CURL *meow = curl_easy_init();
|
CURL *meow = curl_easy_init();
|
||||||
CURLcode res;
|
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_WRITEFUNCTION, appendCurlOutputToString);
|
||||||
curl_easy_setopt(meow, CURLOPT_WRITEDATA, &woof);
|
curl_easy_setopt(meow, CURLOPT_WRITEDATA, &woof);
|
||||||
// perform the request
|
// 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);
|
writeHtmlFile(&woof, outputfile);
|
||||||
curl_easy_cleanup(meow);
|
curl_easy_cleanup(meow);
|
||||||
}
|
}
|
||||||
|
|
19
src/main.cpp
19
src/main.cpp
|
@ -85,8 +85,13 @@ int main(int argc, char **argv, char **envp) {
|
||||||
if (argc == 7) {
|
if (argc == 7) {
|
||||||
dir = ARGS[1+5];
|
dir = ARGS[1+5];
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
getHttp(std::string {"https://steamcommunity.com/sharedfiles/filedetails/?id=" + collectionid}, &cachesc);
|
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 << collectionid << user << pass << gameid << dir;
|
||||||
std::cout << "success1\n";
|
std::cout << "success1\n";
|
||||||
break;
|
break;
|
||||||
|
@ -100,9 +105,15 @@ int main(int argc, char **argv, char **envp) {
|
||||||
if (argc == 5) {
|
if (argc == 5) {
|
||||||
dir = ARGS[1+3];
|
dir = ARGS[1+3];
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
getHttp(std::string {"https://steamcommunity.com/sharedfiles/filedetails/?id=" + collectionid}, &cachesc);
|
||||||
|
}
|
||||||
|
catch(std::string& meow) {
|
||||||
|
std::cout << meow;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
getHttp(std::string {"https://steamcommunity.com/sharedfiles/filedetails/?id=" + collectionid}, &cachesc);
|
std::cout << collectionid << gameid << dir << '\n';
|
||||||
std::cout << collectionid << gameid << dir;
|
|
||||||
|
|
||||||
std::cout << "success\n";
|
std::cout << "success\n";
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Add table
Reference in a new issue