bumped: 0.1.3 reformatted code and cleanup
This commit is contained in:
parent
ede3b04552
commit
b0afcafb5b
7 changed files with 1170 additions and 166 deletions
2
PKGBUILD
2
PKGBUILD
|
@ -1,6 +1,6 @@
|
||||||
pkgname=stc-git
|
pkgname=stc-git
|
||||||
_gitname=stc
|
_gitname=stc
|
||||||
pkgver=0.1.2
|
pkgver=0.1.3
|
||||||
pkgrel=1
|
pkgrel=1
|
||||||
pkgdesc="Easily download collections and mods from steam."
|
pkgdesc="Easily download collections and mods from steam."
|
||||||
url="https://github.com/DRAGONTOS/stc"
|
url="https://github.com/DRAGONTOS/stc"
|
||||||
|
|
10
assets/ids.txt
Normal file
10
assets/ids.txt
Normal 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
1034
assets/sources.html
Normal file
File diff suppressed because it is too large
Load diff
35
ids.txt
35
ids.txt
|
@ -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
|
|
|
@ -1,3 +1,3 @@
|
||||||
{
|
{
|
||||||
"version": "0.1.2"
|
"version": "0.1.3"
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,27 +4,27 @@
|
||||||
|
|
||||||
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");
|
||||||
}
|
}
|
||||||
// open file and write to it
|
// open file and write to it
|
||||||
std::ofstream meow{*outputfile};
|
std::ofstream meow{*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;
|
||||||
std::string woof;
|
std::string woof;
|
||||||
// check for nullptr and if nullptr throw an exception
|
// check for nullptr and if nullptr throw an exception
|
||||||
if (!outputfile){
|
if (!outputfile) {
|
||||||
curl_easy_cleanup(meow);
|
curl_easy_cleanup(meow);
|
||||||
throw("outputfile is null\n");
|
throw("outputfile is null\n");
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ void getHttp(std::string url, std::string *outputfile) {
|
||||||
curl_easy_setopt(meow, CURLOPT_WRITEDATA, &woof);
|
curl_easy_setopt(meow, CURLOPT_WRITEDATA, &woof);
|
||||||
// perform the request
|
// perform the request
|
||||||
res = curl_easy_perform(meow);
|
res = curl_easy_perform(meow);
|
||||||
if (res != CURLE_OK){
|
if (res != CURLE_OK) {
|
||||||
throw("failed to perform the request\n");
|
throw("failed to perform the request\n");
|
||||||
}
|
}
|
||||||
writeHtmlFile(&woof, outputfile);
|
writeHtmlFile(&woof, outputfile);
|
||||||
|
|
237
src/main.cpp
237
src/main.cpp
|
@ -1,3 +1,5 @@
|
||||||
|
#include "includes/getHttp.h"
|
||||||
|
#include "regex"
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
#include <cpptoml.h>
|
#include <cpptoml.h>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
@ -5,14 +7,12 @@
|
||||||
#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>
|
||||||
#include "regex"
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
std::string woof(std::ifstream& meow){
|
std::string woof(std::ifstream &meow) {
|
||||||
std::ostringstream nya;
|
std::ostringstream nya;
|
||||||
nya << meow.rdbuf();
|
nya << meow.rdbuf();
|
||||||
return nya.str();
|
return nya.str();
|
||||||
|
@ -24,14 +24,10 @@ LISTING COMMANDS:
|
||||||
-m: Install a specific mod.
|
-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) {
|
int main(int argc, char **argv, char **envp) {
|
||||||
|
|
||||||
// need some cleaning in the future ata
|
// 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 userCache = std::string(userHome) + "/.cache/";
|
||||||
std::string cacheid = std::string(userCache) + "ids.txt";
|
std::string cacheid = std::string(userCache) + "ids.txt";
|
||||||
std::string cachesc = std::string(userCache) + "sources.html";
|
std::string cachesc = std::string(userCache) + "sources.html";
|
||||||
|
@ -47,11 +43,11 @@ int main(int argc, char **argv, char **envp) {
|
||||||
// Removes cache
|
// Removes cache
|
||||||
if (std::filesystem::exists(cacheid) &&
|
if (std::filesystem::exists(cacheid) &&
|
||||||
std::filesystem::is_directory(cacheid)) {
|
std::filesystem::is_directory(cacheid)) {
|
||||||
int status = remove(std::string {cacheid}.c_str());
|
int status = remove(std::string{cacheid}.c_str());
|
||||||
int status2 = remove(std::string {cachesc}.c_str());
|
int status2 = remove(std::string{cachesc}.c_str());
|
||||||
} else {
|
} else {
|
||||||
int status = remove(std::string {cacheid}.c_str());
|
int status = remove(std::string{cacheid}.c_str());
|
||||||
int status2 = remove(std::string {cachesc}.c_str());
|
int status2 = remove(std::string{cachesc}.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> ARGS{argv, argv + argc};
|
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) {
|
for (int i = 1; i < argc; ++i) {
|
||||||
std::string arg = argv[i];
|
std::string arg = argv[i];
|
||||||
if (arg.find('-') == 0) {
|
if (arg.find('-') == 0) {
|
||||||
//collectionid
|
// collectionid
|
||||||
if (ARGS[i] == "-c") {
|
if (ARGS[i] == "-c") {
|
||||||
if (argc < 3 || argv[2][0] == '-') {
|
if (argc < 3 || argv[2][0] == '-') {
|
||||||
std::cerr << USAGE.c_str();
|
std::cerr << USAGE.c_str();
|
||||||
return 1;
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (argc == 4 || argc == 5) {
|
|
||||||
|
|
||||||
collectionid = ARGS[1+1];
|
|
||||||
gameid = ARGS[1+2];
|
|
||||||
|
|
||||||
if (argc == 5) {
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// modid
|
if (argc == 6 || argc == 7) {
|
||||||
if (ARGS[i] == "-m") {
|
|
||||||
if (argc < 3 || argv[2][0] == '-') {
|
collectionid = ARGS[1 + 1];
|
||||||
std::cerr << USAGE.c_str();
|
user = ARGS[1 + 2];
|
||||||
return 1;
|
pass = ARGS[1 + 3];
|
||||||
|
gameid = ARGS[1 + 4];
|
||||||
|
|
||||||
|
if (argc == 7) {
|
||||||
|
dir = ARGS[1 + 5];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argc == 6 || argc == 7) {
|
try {
|
||||||
|
getHttp(std::string{"https://steamcommunity.com/sharedfiles/filedetails/?id=" + collectionid}, &cachesc);
|
||||||
modid = ARGS[1+1];
|
} catch (std::string &meow) {
|
||||||
user = ARGS[1+2];
|
std::cout << meow;
|
||||||
pass = ARGS[1+3];
|
return 1;
|
||||||
gameid = ARGS[1+4];
|
|
||||||
|
|
||||||
if (argc == 7) {
|
|
||||||
dir = ARGS[1+5];
|
|
||||||
}
|
|
||||||
|
|
||||||
std::cout << "success1\n";
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argc == 4 || argc == 5) {
|
std::cout << "success1\n";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (argc == 4 || argc == 5) {
|
||||||
|
|
||||||
|
collectionid = ARGS[1 + 1];
|
||||||
|
gameid = ARGS[1 + 2];
|
||||||
|
|
||||||
modid = ARGS[1+1];
|
|
||||||
gameid = ARGS[1+2];
|
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "success\n";
|
std::cout << "success\n";
|
||||||
break;
|
break;
|
||||||
} else {
|
|
||||||
std::cerr << USAGE;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
std::cerr << USAGE;
|
std::cerr << USAGE;
|
||||||
return 1;
|
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)
|
// regex and stuff (collectionid)
|
||||||
if (!collectionid.empty()) {
|
if (!collectionid.empty()) {
|
||||||
|
@ -178,8 +172,8 @@ int main(int argc, char **argv, char **envp) {
|
||||||
std::ofstream outputFile(outputFilePath, std::ios::app);
|
std::ofstream outputFile(outputFilePath, std::ios::app);
|
||||||
|
|
||||||
if (!inputFile.is_open() && !outputFile.is_open()) {
|
if (!inputFile.is_open() && !outputFile.is_open()) {
|
||||||
std::cerr << "Unable to open file";
|
std::cerr << "Unable to open file";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::regex grepRegex(R"(<div class="workshopItemPreviewHolder ")");
|
std::regex grepRegex(R"(<div class="workshopItemPreviewHolder ")");
|
||||||
|
@ -188,27 +182,28 @@ int main(int argc, char **argv, char **envp) {
|
||||||
|
|
||||||
// Process each line
|
// Process each line
|
||||||
while (std::getline(inputFile, line)) {
|
while (std::getline(inputFile, line)) {
|
||||||
//grep-like behavior (only process lines containing the pattern with two spaces)
|
// grep-like behavior (only process lines containing the pattern with two
|
||||||
if (std::regex_search(line, grepRegex)) {
|
// spaces)
|
||||||
|
if (std::regex_search(line, grepRegex)) {
|
||||||
|
|
||||||
//sed 's/"><div class=.*//'
|
// sed 's/"><div class=.*//'
|
||||||
std::size_t divPos = line.find("\"><div class=");
|
std::size_t divPos = line.find("\"><div class=");
|
||||||
if (divPos != std::string::npos) {
|
if (divPos != std::string::npos) {
|
||||||
line = line.substr(0, divPos); // Trim everything after '"><div class='
|
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/.*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
|
// 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();
|
inputFile.close();
|
||||||
outputFile.close();
|
outputFile.close();
|
||||||
|
|
||||||
// (modid)
|
// (modid)
|
||||||
} else if (!modid.empty()) {
|
} else if (!modid.empty()) {
|
||||||
std::string wpd = " +workshop_download_item " + gameid + " " + modid /*+ R"( \)"*/;
|
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());
|
|
||||||
|
|
||||||
|
// main command
|
||||||
|
system(std::string{"sh ~/Steam/steamcmd.sh +force_install_dir " + dir + " +login " + user + pass + wpd + " +quit"}.c_str());
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// main command
|
// main command
|
||||||
std::ifstream ids{cacheid};
|
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;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue