regex: made regex work and added a modid option.
This commit is contained in:
parent
09d4f4fe52
commit
4b057fbed5
1 changed files with 94 additions and 50 deletions
144
src/main.cpp
144
src/main.cpp
|
@ -56,12 +56,14 @@ int main(int argc, char **argv, char **envp) {
|
||||||
std::string cachesc = std::string(userCache) + "sources.html";
|
std::string cachesc = std::string(userCache) + "sources.html";
|
||||||
|
|
||||||
std::string collectionid;
|
std::string collectionid;
|
||||||
|
std::string modid;
|
||||||
std::string user = "anonymous";
|
std::string user = "anonymous";
|
||||||
std::string pass;
|
std::string pass;
|
||||||
std::string gameid;
|
std::string gameid;
|
||||||
std::string dir;
|
std::string dir;
|
||||||
dir = std::filesystem::current_path();
|
dir = std::filesystem::current_path();
|
||||||
|
|
||||||
|
// 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());
|
||||||
|
@ -83,63 +85,105 @@ int main(int argc, char **argv, char **envp) {
|
||||||
|
|
||||||
// the args
|
// the args
|
||||||
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 (ARGS[i] == "-ci") { // collection id
|
if (ARGS[i] == "-ci") { // collection id
|
||||||
collectionid = ARGS[1+1];
|
collectionid = ARGS[1+1];
|
||||||
std::cout << collectionid;
|
std::cout << collectionid;
|
||||||
// should be done with libcurl in the future ata
|
// should be done with libcurl in the future ata
|
||||||
system(std::string {"curl https://steamcommunity.com/sharedfiles/filedetails/?id=" + collectionid + " -o " + cachesc}.c_str());
|
system(std::string {"curl https://steamcommunity.com/sharedfiles/filedetails/?id=" + collectionid + " -o " + cachesc}.c_str());
|
||||||
|
} else if (ARGS[i] == "-mi") {
|
||||||
if (ARGS[i+2] == "-u") { // user if required [OPTIONAL]
|
modid = ARGS[1+1];
|
||||||
user = ARGS[i+3];
|
std::cout << modid;
|
||||||
std::cout << user;
|
}
|
||||||
} else if (ARGS[i+2] == "-gi") { // game id
|
|
||||||
gameid = ARGS[i+3];
|
|
||||||
std::cout << gameid;
|
|
||||||
if (ARGS[i+4] == "-d") {
|
|
||||||
dir = ARGS[i+5];
|
|
||||||
std::cout << dir;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ARGS[i+4] == "-p") { // pass [OPTIONAL]
|
if (ARGS[i+2] == "-u") { // user if required [OPTIONAL]
|
||||||
pass = ARGS[i+5];
|
user = ARGS[i+3];
|
||||||
std::cout << pass;
|
std::cout << user;
|
||||||
}
|
} else if (ARGS[i+2] == "-gi") { // game id
|
||||||
|
gameid = ARGS[i+3];
|
||||||
if (ARGS[i+6] == "-gi") { // game id
|
std::cout << gameid;
|
||||||
gameid = ARGS[i+7];
|
if (ARGS[i+4] == "-d") {
|
||||||
std::cout << gameid;
|
dir = ARGS[i+5];
|
||||||
}
|
|
||||||
|
|
||||||
if (ARGS[i+8] == "-d") { // download dir [OPTIONAL]
|
|
||||||
dir = ARGS[i+9];
|
|
||||||
std::cout << dir;
|
std::cout << dir;
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ARGS[i+4] == "-p") { // pass [OPTIONAL]
|
||||||
|
pass = ARGS[i+5];
|
||||||
|
std::cout << pass;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ARGS[i+6] == "-gi") { // game id
|
||||||
|
gameid = ARGS[i+7];
|
||||||
|
std::cout << gameid;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ARGS[i+8] == "-d") { // download dir [OPTIONAL]
|
||||||
|
dir = ARGS[i+9];
|
||||||
|
std::cout << dir;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Not Working idk why hope someone can help with regex
|
if (!collectionid.empty()) {
|
||||||
// std::ifstream file(cachesc);
|
// Input and output file paths
|
||||||
// std::ofstream outputFile(cacheid);
|
std::string inputFilePath = cachesc;
|
||||||
//
|
std::string outputFilePath = cacheid;
|
||||||
// if (file.is_open() && outputFile.is_open()) {
|
|
||||||
// std::string line;
|
// Open the input file (source.html)
|
||||||
// while (std::getline(file, line)) {
|
std::ifstream inputFile(inputFilePath);
|
||||||
// std::regex pattern(R"(<div class=\"workshopItemPreviewHolder.*?id=\"(.*?)\"")");
|
std::ofstream outputFile(outputFilePath, std::ios::app);
|
||||||
// std::smatch match;
|
|
||||||
// if (std::regex_search(line, match, pattern)) {
|
if (!inputFile.is_open() && !outputFile.is_open()) {
|
||||||
// outputFile << "+workshop_download_item 294100 " << match[1] << " /\n";
|
std::cerr << "Unable to open file";
|
||||||
// }
|
return 1;
|
||||||
// }
|
}
|
||||||
// outputFile << "+quit\n";
|
|
||||||
// file.close();
|
std::regex grepRegex(R"(<div class="workshopItemPreviewHolder ")");
|
||||||
// outputFile.close();
|
|
||||||
// } else {
|
std::string line;
|
||||||
// std::cerr << "Unable to open file";
|
|
||||||
// }
|
// 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)) {
|
||||||
|
|
||||||
|
//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
|
||||||
|
outputFile << "+quit" << std::endl;
|
||||||
|
|
||||||
|
// Close the input and output files
|
||||||
|
inputFile.close();
|
||||||
|
outputFile.close();
|
||||||
|
|
||||||
|
} else if (!modid.empty()) {
|
||||||
|
std::string wpd = " +workshop_download_item " + gameid + " " + modid /*+ R"( \)"*/;
|
||||||
|
system(std::string {"sh ~/Steam/steamcmd.sh +force_install_dir " + dir + " +login " + user + pass + wpd + " +quit"}.c_str());
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
// main command
|
// main command
|
||||||
std::ifstream ids{cacheid};
|
std::ifstream ids{cacheid};
|
||||||
|
|
Loading…
Add table
Reference in a new issue