bumped: 0.1.3 reformatted code and cleanup

This commit is contained in:
Kaley, Fischer 2024-10-06 23:23:52 +02:00
parent ede3b04552
commit b0afcafb5b
7 changed files with 1170 additions and 166 deletions

View file

@ -1,6 +1,6 @@
pkgname=stc-git
_gitname=stc
pkgver=0.1.2
pkgver=0.1.3
pkgrel=1
pkgdesc="Easily download collections and mods from steam."
url="https://github.com/DRAGONTOS/stc"

10
assets/ids.txt Normal file
View file

@ -0,0 +1,10 @@
+workshop_download_item 244850 2710575211 \
+workshop_download_item 244850 2742890728 \
+workshop_download_item 244850 2779162581 \
+workshop_download_item 244850 2949388346 \
+workshop_download_item 244850 2821153519 \
+workshop_download_item 244850 3171146773 \
+workshop_download_item 244850 3318269325 \
+workshop_download_item 244850 3342484040 \
+workshop_download_item 244850 2657577202 \
+quit

1034
assets/sources.html Normal file

File diff suppressed because it is too large Load diff

35
ids.txt
View file

@ -1,35 +0,0 @@
+workshop_download_item 294100 2275310562 \
+workshop_download_item 294100 2662457442 \
+workshop_download_item 294100 2873235836 \
+workshop_download_item 294100 2068281501 \
+workshop_download_item 294100 2893572291 \
+workshop_download_item 294100 2748834409 \
+workshop_download_item 294100 2777098392 \
+workshop_download_item 294100 1635901197 \
+workshop_download_item 294100 2816938779 \
+workshop_download_item 294100 3302079637 \
+workshop_download_item 294100 2877292196 \
+workshop_download_item 294100 2944488802 \
+workshop_download_item 294100 3228047321 \
+workshop_download_item 294100 2475965842 \
+workshop_download_item 294100 3302328100 \
+workshop_download_item 294100 2610120706 \
+workshop_download_item 294100 2917732219 \
+workshop_download_item 294100 2865361569 \
+workshop_download_item 294100 3061095040 \
+workshop_download_item 294100 2989238251 \
+workshop_download_item 294100 2888638004 \
+workshop_download_item 294100 2850840457 \
+workshop_download_item 294100 3272822831 \
+workshop_download_item 294100 2016436324 \
+workshop_download_item 294100 3276562906 \
+workshop_download_item 294100 1677616980 \
+workshop_download_item 294100 2937674636 \
+workshop_download_item 294100 1446523594 \
+workshop_download_item 294100 1508850027 \
+workshop_download_item 294100 1569605867 \
+workshop_download_item 294100 3266720501 \
+workshop_download_item 294100 1678847247 \
+workshop_download_item 294100 2775017012 \
+workshop_download_item 294100 2853407446 \
+quit

View file

@ -1,3 +1,3 @@
{
"version": "0.1.2"
"version": "0.1.3"
}

View file

@ -4,13 +4,13 @@
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;
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){
if (!woof || !outputfile) {
throw("string is null\n");
}
// open file and write to it
@ -19,12 +19,12 @@ void writeHtmlFile(std::string* woof, 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();
CURLcode res;
std::string woof;
// check for nullptr and if nullptr throw an exception
if (!outputfile){
if (!outputfile) {
curl_easy_cleanup(meow);
throw("outputfile is null\n");
}
@ -34,7 +34,7 @@ void getHttp(std::string url, std::string *outputfile) {
curl_easy_setopt(meow, CURLOPT_WRITEDATA, &woof);
// perform the request
res = curl_easy_perform(meow);
if (res != CURLE_OK){
if (res != CURLE_OK) {
throw("failed to perform the request\n");
}
writeHtmlFile(&woof, outputfile);

View file

@ -1,3 +1,5 @@
#include "includes/getHttp.h"
#include "regex"
#include <cctype>
#include <cpptoml.h>
#include <cstdio>
@ -5,14 +7,12 @@
#include <cstring>
#include <filesystem>
#include <fstream>
#include "includes/getHttp.h"
#include <ios>
#include <iostream>
#include <ostream>
#include "regex"
#include <string>
std::string woof(std::ifstream& meow){
std::string woof(std::ifstream &meow) {
std::ostringstream nya;
nya << meow.rdbuf();
return nya.str();
@ -24,14 +24,10 @@ LISTING COMMANDS:
-m: Install a specific mod.
)#";
// strings are kinda broken
const std::string invalidvalue = "Invalid value in config: \n";
const std::string invalidconfig = "Not a valid config: \n";
int main(int argc, char **argv, char **envp) {
// need some cleaning in the future ata
const char* userHome = getenv("HOME");
const char *userHome = getenv("HOME");
std::string userCache = std::string(userHome) + "/.cache/";
std::string cacheid = std::string(userCache) + "ids.txt";
std::string cachesc = std::string(userCache) + "sources.html";
@ -47,11 +43,11 @@ int main(int argc, char **argv, char **envp) {
// Removes cache
if (std::filesystem::exists(cacheid) &&
std::filesystem::is_directory(cacheid)) {
int status = remove(std::string {cacheid}.c_str());
int status2 = remove(std::string {cachesc}.c_str());
int status = remove(std::string{cacheid}.c_str());
int status2 = remove(std::string{cachesc}.c_str());
} else {
int status = remove(std::string {cacheid}.c_str());
int status2 = remove(std::string {cachesc}.c_str());
int status = remove(std::string{cacheid}.c_str());
int status2 = remove(std::string{cachesc}.c_str());
}
std::vector<std::string> ARGS{argv, argv + argc};
@ -68,104 +64,102 @@ int main(int argc, char **argv, char **envp) {
for (int i = 1; i < argc; ++i) {
std::string arg = argv[i];
if (arg.find('-') == 0) {
//collectionid
if (ARGS[i] == "-c") {
if (argc < 3 || argv[2][0] == '-') {
std::cerr << USAGE.c_str();
return 1;
}
if (argc == 6 || argc == 7) {
collectionid = ARGS[1+1];
user = ARGS[1+2];
pass = ARGS[1+3];
gameid = ARGS[1+4];
if (argc == 7) {
dir = ARGS[1+5];
}
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";
break;
// collectionid
if (ARGS[i] == "-c") {
if (argc < 3 || argv[2][0] == '-') {
std::cerr << USAGE.c_str();
return 1;
}
if (argc == 4 || argc == 5) {
if (argc == 6 || argc == 7) {
collectionid = ARGS[1+1];
gameid = ARGS[1+2];
collectionid = ARGS[1 + 1];
user = ARGS[1 + 2];
pass = ARGS[1 + 3];
gameid = ARGS[1 + 4];
if (argc == 5) {
dir = ARGS[1+3];
}
if (argc == 7) {
dir = ARGS[1 + 5];
}
try {
getHttp(std::string {"https://steamcommunity.com/sharedfiles/filedetails/?id=" + collectionid}, &cachesc);
}
catch(std::string& meow) {
std::cout << meow;
return 1;
}
try {
getHttp(std::string{"https://steamcommunity.com/sharedfiles/filedetails/?id=" + collectionid}, &cachesc);
} catch (std::string &meow) {
std::cout << meow;
return 1;
}
std::cout << "success\n";
break;
} else {
std::cerr << USAGE;
return 1;
}
std::cout << "success1\n";
break;
}
// modid
if (ARGS[i] == "-m") {
if (argc < 3 || argv[2][0] == '-') {
std::cerr << USAGE.c_str();
return 1;
}
if (argc == 4 || argc == 5) {
if (argc == 6 || argc == 7) {
modid = ARGS[1+1];
user = ARGS[1+2];
pass = ARGS[1+3];
gameid = ARGS[1+4];
if (argc == 7) {
dir = ARGS[1+5];
}
std::cout << "success1\n";
break;
}
if (argc == 4 || argc == 5) {
modid = ARGS[1+1];
gameid = ARGS[1+2];
collectionid = ARGS[1 + 1];
gameid = ARGS[1 + 2];
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;
}
std::cout << "success\n";
break;
} else {
std::cerr << USAGE;
return 1;
}
} else {
std::cerr << USAGE;
return 1;
std::cerr << USAGE;
return 1;
}
}
}
// modid
if (ARGS[i] == "-m") {
if (argc < 3 || argv[2][0] == '-') {
std::cerr << USAGE.c_str();
return 1;
}
if (argc == 6 || argc == 7) {
modid = ARGS[1 + 1];
user = ARGS[1 + 2];
pass = ARGS[1 + 3];
gameid = ARGS[1 + 4];
if (argc == 7) {
dir = ARGS[1 + 5];
}
std::cout << "success1\n";
break;
}
if (argc == 4 || argc == 5) {
modid = ARGS[1 + 1];
gameid = ARGS[1 + 2];
if (argc == 5) {
dir = ARGS[1 + 3];
}
std::cout << "success\n";
break;
} else {
std::cerr << USAGE;
return 1;
}
} else {
std::cerr << USAGE;
return 1;
}
}
}
// regex and stuff (collectionid)
if (!collectionid.empty()) {
@ -178,8 +172,8 @@ int main(int argc, char **argv, char **envp) {
std::ofstream outputFile(outputFilePath, std::ios::app);
if (!inputFile.is_open() && !outputFile.is_open()) {
std::cerr << "Unable to open file";
return 1;
std::cerr << "Unable to open file";
return 1;
}
std::regex grepRegex(R"(<div class="workshopItemPreviewHolder ")");
@ -188,27 +182,28 @@ int main(int argc, char **argv, char **envp) {
// Process each line
while (std::getline(inputFile, line)) {
//grep-like behavior (only process lines containing the pattern with two spaces)
if (std::regex_search(line, grepRegex)) {
// grep-like behavior (only process lines containing the pattern with two
// spaces)
if (std::regex_search(line, grepRegex)) {
//sed 's/"><div class=.*//'
std::size_t divPos = line.find("\"><div class=");
if (divPos != std::string::npos) {
line = line.substr(0, divPos); // Trim everything after '"><div class='
}
//sed 's/.*id=//'
std::size_t idPos = line.find("id=");
if (idPos != std::string::npos) {
line = line.substr(idPos + 3); // Trim everything before 'id=' and keep the ID
}
line = "+workshop_download_item " + gameid + " " + line;
line += " \\";
outputFile << line << std::endl;
// sed 's/"><div class=.*//'
std::size_t divPos = line.find("\"><div class=");
if (divPos != std::string::npos) {
line = line.substr(0, divPos); // Trim everything after '"><div class='
}
// sed 's/.*id=//'
std::size_t idPos = line.find("id=");
if (idPos != std::string::npos) {
line = line.substr(idPos + 3); // Trim everything before 'id=' and keep the ID
}
line = "+workshop_download_item " + gameid + " " + line;
line += " \\";
outputFile << line << std::endl;
}
}
// Step 6: Write "+quit" at the end of the output file
@ -218,17 +213,17 @@ int main(int argc, char **argv, char **envp) {
inputFile.close();
outputFile.close();
// (modid)
// (modid)
} else if (!modid.empty()) {
std::string wpd = " +workshop_download_item " + gameid + " " + modid /*+ R"( \)"*/;
// main command
system(std::string {"sh ~/Steam/steamcmd.sh +force_install_dir " + dir + " +login " + user + pass + wpd + " +quit"}.c_str());
system(std::string{"sh ~/Steam/steamcmd.sh +force_install_dir " + dir + " +login " + user + pass + wpd + " +quit"}.c_str());
return 1;
}
// main command
std::ifstream ids{cacheid};
system(std::string {"sh ~/Steam/steamcmd.sh +force_install_dir " + dir + " +login " + user + pass + R"( \ )" + woof(ids)}.c_str());
system(std::string{"sh ~/Steam/steamcmd.sh +force_install_dir " + dir + " +login " + user + pass + R"( \ )" + woof(ids)}.c_str());
return 1;
}