fix: removes cache ones executed and added comments

This commit is contained in:
Kaley, Fischer 2024-10-05 19:42:00 +02:00
parent 7f70c29987
commit 09d4f4fe52

View file

@ -11,8 +11,11 @@
#include <limits>
#include <ostream>
#include <stdexcept>
#include "regex"
#include <string>
// should be in an alphabatical order ^^^
// clear buffers might not be needed
void clearBuffer() {
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
}
@ -40,12 +43,17 @@ LISTING COMMANDS:
-b: Make a executable out of a config.
)#";
// strings are kinda broken
const std::string invalidvalue = "Invalid value in config: ";
const std::string invalidconfig = "Not a valid config: ";
int main(int argc, char **argv, char **envp) {
// need some cleaning in the future ata
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";
std::string collectionid;
std::string user = "anonymous";
@ -54,6 +62,15 @@ int main(int argc, char **argv, char **envp) {
std::string dir;
dir = std::filesystem::current_path();
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());
} else {
int status = remove(std::string {cacheid}.c_str());
int status2 = remove(std::string {cachesc}.c_str());
}
std::vector<std::string> ARGS{argv, argv + argc};
for (int i = 0; i < argc; ++i) {
ARGS[i] = std::string{argv[i]};
@ -63,16 +80,20 @@ int main(int argc, char **argv, char **envp) {
std::cout << USAGE;
return 1;
}
// the args
for (int i = 1; i < argc; ++i) {
std::string arg = argv[i];
if (ARGS[i] == "-ci") {
if (ARGS[i] == "-ci") { // collection id
collectionid = ARGS[1+1];
std::cout << collectionid;
// should be done with libcurl in the future ata
system(std::string {"curl https://steamcommunity.com/sharedfiles/filedetails/?id=" + collectionid + " -o " + cachesc}.c_str());
if (ARGS[i+2] == "-u") {
if (ARGS[i+2] == "-u") { // user if required [OPTIONAL]
user = ARGS[i+3];
std::cout << user;
} else if (ARGS[i+2] == "-gi") {
} else if (ARGS[i+2] == "-gi") { // game id
gameid = ARGS[i+3];
std::cout << gameid;
if (ARGS[i+4] == "-d") {
@ -82,25 +103,45 @@ int main(int argc, char **argv, char **envp) {
break;
}
if (ARGS[i+4] == "-p") {
if (ARGS[i+4] == "-p") { // pass [OPTIONAL]
pass = ARGS[i+5];
std::cout << pass;
}
if (ARGS[i+6] == "-gi") {
if (ARGS[i+6] == "-gi") { // game id
gameid = ARGS[i+7];
std::cout << gameid;
}
if (ARGS[i+8] == "-d") {
if (ARGS[i+8] == "-d") { // download dir [OPTIONAL]
dir = ARGS[i+9];
std::cout << dir;
}
}
}
// std::cerr << USAGE.c_str();
std::ifstream ids{"ids.txt"};
// Not Working idk why hope someone can help with regex
// std::ifstream file(cachesc);
// std::ofstream outputFile(cacheid);
//
// if (file.is_open() && outputFile.is_open()) {
// std::string line;
// while (std::getline(file, line)) {
// std::regex pattern(R"(<div class=\"workshopItemPreviewHolder.*?id=\"(.*?)\"")");
// std::smatch match;
// if (std::regex_search(line, match, pattern)) {
// outputFile << "+workshop_download_item 294100 " << match[1] << " /\n";
// }
// }
// outputFile << "+quit\n";
// file.close();
// outputFile.close();
// } else {
// std::cerr << "Unable to open file";
// }
// 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());
}