This commit is contained in:
Kaley, Fischer 2024-10-23 03:14:33 +02:00
commit 051b41b92f
3 changed files with 30 additions and 28 deletions

View file

@ -52,9 +52,9 @@ void Regex(cmd *inputCmd) {
}
}
void filerestort(cmd *inputCmd) {
std::filesystem::path steamdir = std::string(inputCmd->userHome) + "/.cache/steamapps/workshop/content/" + inputCmd->gameid + "/" + inputCmd->idnumber;
std::filesystem::path modname = inputCmd->dir + "/" + inputCmd->idname;
void filerestort(cmd *inputCmd, std::string idnumber, std::string idname) {
std::filesystem::path steamdir = std::string(inputCmd->userHome) + "/.cache/steamapps/workshop/content/" + inputCmd->gameid + "/" + idnumber;
std::filesystem::path modname = inputCmd->dir + "/" + idname;
// renames and moves the files.
try {
@ -63,29 +63,37 @@ void filerestort(cmd *inputCmd) {
std::filesystem::remove_all(modname);
}
std::filesystem::rename(steamdir, modname);
inputCmd->threadsCompleted++;
} else {
std::cerr << "Error: The directory " << steamdir << " does not exist." << std::endl;
inputCmd->threadsCompleted++;
}
} catch (const std::filesystem::filesystem_error& e) {
std::cerr << "Filesystem error: " << e.what() << std::endl;
inputCmd->threadsCompleted++;
} catch (const std::exception& e) {
std::cerr << "Error: " << e.what() << std::endl;
inputCmd->threadsCompleted++;
}
}
void Modname(cmd *inputCmd, std::string input) {
void Modname(cmd *inputCmd, size_t index) {
std::string idnumber;
std::string idname;
if (!inputCmd->sucids.empty()) {
std::regex downloadItemRegex(R"(Downloaded item (\d+))");
std::smatch match;
if (std::regex_search(input, match, downloadItemRegex)) {
if (std::regex_search(inputCmd->sucids[index], match, downloadItemRegex)) {
std::string downloadItemNumber = match[1].str();
inputCmd->idnumber = downloadItemNumber;
idnumber = downloadItemNumber;
}
std::istringstream inputStream(inputCmd->source);
std::regex grepRegex("\"id\":\"" + inputCmd->idnumber + "\",\"title\":\"");
std::regex grepRegex("\"id\":\"" + idnumber + "\",\"title\":\"");
std::string line;
while (std::getline(inputStream, line)) {
@ -102,9 +110,9 @@ void Modname(cmd *inputCmd, std::string input) {
if (idPos != std::string::npos) {
line = line.substr(idPos + idPrefix.length()); // Keep everything after "id="
}
inputCmd->idname = line;
idname = line;
}
}
filerestort(inputCmd, idnumber, idname);
}
}

View file

@ -1,7 +1,7 @@
#ifndef REGEX_H
#define REGEX_H
#include <string>
#include <vector>
// all the var's
struct cmd {
const char* userHome = getenv("HOME");
@ -22,18 +22,17 @@ bool ab = false;
// total mods
int totalmods = 0;
// counter
std::string sucids;
std::string idnumber;
std::string idname;
// Modnamestuff
std::vector<std::string> sucids;
int successes = 0;
int timedout = 0;
int errors = 0;
int totalmeow = 0;
size_t threadsCompleted = 0;
};
void Regex(cmd *inputCmd);
void filerestort(cmd *inputCmd);
void Modname(cmd *inputCmd, std::string input);
void Modname(cmd *inputCmd, size_t index);
#endif

View file

@ -1,7 +1,6 @@
#include <filesystem>
#include <fstream>
#include <iostream>
#include <sstream>
#include <stdexcept>
#include <string>
#include <thread>
@ -24,7 +23,7 @@ void execAndDisplay(cmd *inputCmd, const std::string& cmd, std::atomic<bool>& ru
// checks for success.
if (line.find("Success") != std::string::npos) {
inputCmd->successes++;
inputCmd->sucids += line + "\n";
inputCmd->sucids.push_back( line + "\n");
}
// checks for timed out ones.
@ -39,8 +38,6 @@ void execAndDisplay(cmd *inputCmd, const std::string& cmd, std::atomic<bool>& ru
std::ofstream meow{"/home/rander/.cache/errors.txt"};
meow << "start:\n" + line;
}
inputCmd->totalmeow++;
}
running = false;
@ -93,15 +90,13 @@ void maincommand(cmd *inputCmd) {
+ "Timed out: " + std::to_string(inputCmd->timedout) + "\n"
+ "Errored: " + std::to_string(inputCmd->errors) + "\n" + "\n";
// mod names
std::istringstream inputStream(inputCmd->sucids);
std::string line;
while (std::getline(inputStream, line)) {
inputCmd->totalmods++;
Modname(inputCmd, line);
filerestort(inputCmd);
//start the threads
for(size_t nya{0}; nya < inputCmd->sucids.size(); ++nya){
inputCmd->totalmods++;
std::thread meowT {Modname, inputCmd, nya};
meowT.detach();
}
while(inputCmd->threadsCompleted != inputCmd->sucids.size()){}
std::cout << "\n\n" + mods + colm + " has been downloaded too: " + inputCmd->dir + "\n";
}