diff --git a/src/main.cpp b/src/main.cpp index a05dc0a..eed26f4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -11,8 +11,11 @@ #include #include #include +#include "regex" #include +// should be in an alphabatical order ^^^ +// clear buffers might not be needed void clearBuffer() { std::cin.ignore(std::numeric_limits::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 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"(