Compare commits

...

4 commits

Author SHA1 Message Date
ede3b04552 Merge branch 'maukkis-master' 2024-10-06 23:02:57 +02:00
32f6abaf52 pull: 89c280a785 2024-10-06 23:01:22 +02:00
Luna
89c280a785 forgot try catch statement 2024-10-06 20:55:16 +03:00
Luna
0509d16de9 added getting the http file with libcurl and updated cmake 2024-10-06 20:27:24 +03:00
4 changed files with 81 additions and 9 deletions

View file

@ -4,19 +4,34 @@ cmake_minimum_required(VERSION 3.28.2)
file(READ ${CMAKE_CURRENT_SOURCE_DIR}/props.json PROPS) file(READ ${CMAKE_CURRENT_SOURCE_DIR}/props.json PROPS)
string(JSON VER GET ${PROPS} version) string(JSON VER GET ${PROPS} version)
# find curl
find_package(CURL REQUIRED)
project(stc project(stc
DESCRIPTION "Easily download collections and mods from steam." DESCRIPTION "Easily download collections and mods from steam."
VERSION ${VER}) VERSION ${VER})
set(CMAKE_CXX_STANDARD 26) set(CMAKE_CXX_STANDARD 26)
# check if build type is set if it isnt set it to release
if(NOT CMAKE_BUILD_TYPE)
set(DCKMAKE_BUILD_TYPE Release)
endif()
# Add the path to the source files for stc # Add the path to the source files for stc
file(GLOB_RECURSE STC_SOURCE_FILES "src/*.cpp") file(GLOB_RECURSE STC_SOURCE_FILES "src/*.cpp")
# add compiler flags
set(CMAKE_CXX_FLAGS_DEBUG "-g")
set(CMAKE_CXX_FLAGS_RELEASE "-03")
# Add the executable target for stc # Add the executable target for stc
add_executable(stc ${STC_SOURCE_FILES}) add_executable(stc ${STC_SOURCE_FILES})
install(TARGETS stc DESTINATION bin) install(TARGETS stc DESTINATION bin)
# add curl libraries
target_link_libraries(stc PRIVATE ${CURL_LIBRARIES})
target_include_directories(stc PRIVATE ${CURL_INCLUDE_DIRS})
# DEBIAN # DEBIAN
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "DRAGONTOS") set(CPACK_DEBIAN_PACKAGE_MAINTAINER "DRAGONTOS")
set(CPACK_DEBIAN_PACKAGE_LICENSE "GPLv3") set(CPACK_DEBIAN_PACKAGE_LICENSE "GPLv3")
@ -24,6 +39,7 @@ set(CPACK_DEBIAN_PACKAGE_DESCRIPTION ${DESCRIPTION})
set(CPACK_DEBIAN_PACKAGE_RELEASE_DIST ON) set(CPACK_DEBIAN_PACKAGE_RELEASE_DIST ON)
set(CPACK_GENERATOR DEBIAN) set(CPACK_GENERATOR DEBIAN)
set(CPACK_PACKAGING_INSTALL_PREFIX "/usr") set(CPACK_PACKAGING_INSTALL_PREFIX "/usr")
# RPM # RPM
set(CPACK_PACKAGE_VENDOR "DRAGONTOS") set(CPACK_PACKAGE_VENDOR "DRAGONTOS")
set(CPACK_RPM_PACKAGE_LICENSE "GPLv3") set(CPACK_RPM_PACKAGE_LICENSE "GPLv3")

42
src/getHttp.cpp Normal file
View file

@ -0,0 +1,42 @@
#include <curl/curl.h>
#include <curl/easy.h>
#include <fstream>
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) {
// check for nullptrs
if (!woof || !outputfile){
throw("string is null\n");
}
// open file and write to it
std::ofstream meow{*outputfile};
meow << *woof;
}
void getHttp(std::string url, std::string *outputfile) {
//initialize curl object and curlcode
CURL *meow = curl_easy_init();
CURLcode res;
std::string woof;
// check for nullptr and if nullptr throw an exception
if (!outputfile){
curl_easy_cleanup(meow);
throw("outputfile is null\n");
}
// set the options
curl_easy_setopt(meow, CURLOPT_URL, url.c_str());
curl_easy_setopt(meow, CURLOPT_WRITEFUNCTION, appendCurlOutputToString);
curl_easy_setopt(meow, CURLOPT_WRITEDATA, &woof);
// perform the request
res = curl_easy_perform(meow);
if (res != CURLE_OK){
throw("failed to perform the request\n");
}
writeHtmlFile(&woof, outputfile);
curl_easy_cleanup(meow);
}

6
src/includes/getHttp.h Normal file
View file

@ -0,0 +1,6 @@
#ifndef GETHTTP_H
#define GETHTTP_H
#include <string>
void getHttp(std::string url, std::string *outputfile);
#endif

View file

@ -5,6 +5,7 @@
#include <cstring> #include <cstring>
#include <filesystem> #include <filesystem>
#include <fstream> #include <fstream>
#include "includes/getHttp.h"
#include <ios> #include <ios>
#include <iostream> #include <iostream>
#include <ostream> #include <ostream>
@ -84,11 +85,15 @@ int main(int argc, char **argv, char **envp) {
if (argc == 7) { if (argc == 7) {
dir = ARGS[1+5]; dir = ARGS[1+5];
} }
// should be done with libcurl in the future ata
system(std::string {"curl https://steamcommunity.com/sharedfiles/filedetails/?id=" + collectionid + " -o " + cachesc}.c_str());
std::cout << collectionid << user << pass << 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 << "success1\n"; std::cout << "success1\n";
break; break;
} }
@ -102,11 +107,14 @@ int main(int argc, char **argv, char **envp) {
dir = ARGS[1+3]; dir = ARGS[1+3];
} }
// should be done with libcurl in the future ata try {
system(std::string {"curl https://steamcommunity.com/sharedfiles/filedetails/?id=" + collectionid + " -o " + cachesc}.c_str()); getHttp(std::string {"https://steamcommunity.com/sharedfiles/filedetails/?id=" + collectionid}, &cachesc);
}
std::cout << collectionid << gameid << dir; catch(std::string& meow) {
std::cout << meow;
return 1;
}
std::cout << "success\n"; std::cout << "success\n";
break; break;
} else { } else {