if-else: removed the else and added a mod count

This commit is contained in:
Kaley, Fischer 2024-10-08 16:06:47 +02:00
parent 73b66a4a4c
commit 6004794ac9

View file

@ -1,5 +1,3 @@
#include "includes/getHttp.h"
#include "regex"
#include <cctype> #include <cctype>
#include <cpptoml.h> #include <cpptoml.h>
#include <cstdio> #include <cstdio>
@ -11,6 +9,8 @@
#include <iostream> #include <iostream>
#include <ostream> #include <ostream>
#include <string> #include <string>
#include "includes/getHttp.h"
#include "regex"
std::string woof(std::ifstream &meow) { std::string woof(std::ifstream &meow) {
std::ostringstream nya; std::ostringstream nya;
@ -40,6 +40,8 @@ int main(int argc, char **argv, char **envp) {
std::string dir; std::string dir;
dir = std::filesystem::current_path(); dir = std::filesystem::current_path();
int ab = 0;
// Removes cache // Removes cache
if (std::filesystem::exists(cacheid) && if (std::filesystem::exists(cacheid) &&
std::filesystem::is_directory(cacheid)) { std::filesystem::is_directory(cacheid)) {
@ -82,6 +84,7 @@ int main(int argc, char **argv, char **envp) {
dir = ARGS[1 + 5]; dir = ARGS[1 + 5];
} }
ab = 0;
try { 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) { } catch (std::string &meow) {
@ -89,7 +92,7 @@ int main(int argc, char **argv, char **envp) {
return 1; return 1;
} }
std::cout << "success1\n"; std::cout << "success\n";
break; break;
} }
@ -102,6 +105,7 @@ int main(int argc, char **argv, char **envp) {
dir = ARGS[1 + 3]; dir = ARGS[1 + 3];
} }
ab = 0;
try { 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) { } catch (std::string &meow) {
@ -135,7 +139,8 @@ int main(int argc, char **argv, char **envp) {
dir = ARGS[1 + 5]; dir = ARGS[1 + 5];
} }
std::cout << "success1\n"; ab = 1;
std::cout << "success\n";
break; break;
} }
@ -148,6 +153,7 @@ int main(int argc, char **argv, char **envp) {
dir = ARGS[1 + 3]; dir = ARGS[1 + 3];
} }
ab = 1;
std::cout << "success\n"; std::cout << "success\n";
break; break;
} else { } else {
@ -181,12 +187,12 @@ int main(int argc, char **argv, char **envp) {
std::string line; std::string line;
// 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 // grep-like behavior (only process lines containing the pattern with two
// spaces) // spaces)
if (std::regex_search(line, grepRegex)) { 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='
@ -212,18 +218,27 @@ int main(int argc, char **argv, char **envp) {
// Close the input and output files // Close the input and output files
inputFile.close(); inputFile.close();
outputFile.close(); outputFile.close();
}
//checks if a "\" is needed or not
std::ifstream idscount{cacheid};
int step = 0;
// (modid) for (std::string line; std::getline(idscount, line); ) {
} else if (!modid.empty()) { step++;
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());
return 1;
} }
std::string slash = (step == 2) ? R"( )": R"( \ )";
idscount.close();
// 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()); std::string idsm = (ab == 1) ? R"( +workshop_download_item )" + gameid + " " + modid + " +quit": R"()";
system(std::string{"sh ~/Steam/steamcmd.sh +force_install_dir " + dir + " +login " + user + pass + slash + idsm + woof(ids)}.c_str());
std::string mods = (!modid.empty()) ? "" : R"(Mods: )" + std::to_string(step -1) + "\n";
std::string colm = (ab == 1) ? R"(Mod)": R"(Collection)";
std::cout << "\n\n" + mods + colm + " has been downloaded too: " + dir + "\n";
return 1; return 1;
} }