Compare commits

..

No commits in common. "8d4edf3cbfae3e9ee1de664a42303017608d81bc" and "532e3e408f16514faeecae17275c7b54a162cf19" have entirely different histories.

5 changed files with 68 additions and 86 deletions

View file

@ -1,8 +1,8 @@
===============================================================================
Language Files Lines Code Comments Blanks
===============================================================================
C++ 3 313 236 25 52
C++ Header 3 33 30 0 3
C Header 1 6 5 0 1
C++ 2 289 217 24 48
===============================================================================
Total 6 346 266 25 55
Total 3 295 222 24 49
===============================================================================

View file

@ -3,3 +3,4 @@
#include <string>
void getHttp(std::string url, std::string *outputfile);
#endif

View file

@ -1,6 +0,0 @@
#ifndef REGEX_H
#define REGEX_H
#include <string>
void regex(std::string collectionid, std::string gameid, std::string cacheid, std::string cachesc);
#endif

View file

@ -5,12 +5,13 @@
#include <cstring>
#include <filesystem>
#include <fstream>
#include <ios>
#include <iostream>
#include <ostream>
#include <string>
#include "includes/getHttp.hpp"
#include "includes/getHttp.h"
#include "includes/Strings.hpp"
#include "includes/regex.hpp"
#include "regex"
std::string woof(std::ifstream &meow) {
std::ostringstream nya;
@ -23,9 +24,9 @@ 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 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 modid;
@ -41,11 +42,11 @@ int main(int argc, char **argv, char **envp) {
// Removes cache
if (std::filesystem::exists(cacheid) &&
std::filesystem::is_directory(cacheid)) {
std::filesystem::remove(cacheid);
std::filesystem::remove(cachesc);
int status = remove(std::string{cacheid}.c_str());
int status2 = remove(std::string{cachesc}.c_str());
} else {
std::filesystem::remove(cacheid);
std::filesystem::remove(cachesc);
int status = remove(std::string{cacheid}.c_str());
int status2 = remove(std::string{cachesc}.c_str());
}
std::vector<std::string> ARGS{argv, argv + argc};
@ -176,8 +177,59 @@ int main(int argc, char **argv, char **envp) {
}
}
regex({collectionid}, {gameid}, {cacheid}, {cachesc});
// regex and stuff (collectionid)
if (!collectionid.empty()) {
// Input and output file paths
std::string inputFilePath = cachesc;
std::string outputFilePath = cacheid;
// Open the input file (source.html)
std::ifstream inputFile(inputFilePath);
std::ofstream outputFile(outputFilePath, std::ios::app);
if (!inputFile.is_open() && !outputFile.is_open()) {
std::cerr << "Unable to open file";
return 1;
}
std::regex grepRegex(R"(<div class="workshopItemPreviewHolder ")");
std::string line;
// 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();
}
//checks if a "\" is needed or not
std::ifstream idscount{cacheid};
int step = 0;
@ -185,9 +237,9 @@ int main(int argc, char **argv, char **envp) {
for (std::string line; std::getline(idscount, line); ) {
step++;
}
std::string slash = (step == 2) ? R"( )": R"( \ )";
idscount.close();
idscount.close();
//gets the ids
std::ifstream ids{cacheid};

View file

@ -1,65 +0,0 @@
#include <cctype>
#include <cpptoml.h>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <ios>
#include <iostream>
#include <ostream>
#include <string>
#include "regex"
// regex and stuff (collectionid)
void regex(std::string collectionid, std::string gameid, std::string cacheid, std::string cachesc) {
if (!collectionid.empty()) {
// Input and output file paths
std::string inputFilePath = cachesc;
std::string outputFilePath = cacheid;
// Open the input file (source.html)
std::ifstream inputFile(inputFilePath);
std::ofstream outputFile(outputFilePath, std::ios::app);
if (!inputFile.is_open() && !outputFile.is_open()) {
throw("Unable to open file\n");
}
std::regex grepRegex(R"(<div class="workshopItemPreviewHolder ")");
std::string line;
// 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();
}
}