Compare commits
5 commits
0ed8a758af
...
1f2d64db25
Author | SHA1 | Date | |
---|---|---|---|
1f2d64db25 | |||
051b41b92f | |||
689127ffe9 | |||
|
adad232b4b | ||
|
1c50d4d779 |
3 changed files with 34 additions and 33 deletions
|
@ -48,13 +48,13 @@ void Regex(cmd *inputCmd) {
|
||||||
|
|
||||||
// Count the number of lines
|
// Count the number of lines
|
||||||
while (std::getline(inputStream, line)) {
|
while (std::getline(inputStream, line)) {
|
||||||
inputCmd->slashtp++;
|
inputCmd->totalmods++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void filerestort(cmd *inputCmd) {
|
void filerestort(cmd *inputCmd, std::string idnumber, std::string idname) {
|
||||||
std::filesystem::path steamdir = std::string(inputCmd->userHome) + "/.cache/steamapps/workshop/content/" + inputCmd->gameid + "/" + inputCmd->idnumber;
|
std::filesystem::path steamdir = std::string(inputCmd->userHome) + "/.cache/steamapps/workshop/content/" + inputCmd->gameid + "/" + idnumber;
|
||||||
std::filesystem::path modname = inputCmd->dir + "/" + inputCmd->idname;
|
std::filesystem::path modname = inputCmd->dir + "/" + idname;
|
||||||
|
|
||||||
// renames and moves the files.
|
// renames and moves the files.
|
||||||
try {
|
try {
|
||||||
|
@ -63,29 +63,37 @@ void filerestort(cmd *inputCmd) {
|
||||||
std::filesystem::remove_all(modname);
|
std::filesystem::remove_all(modname);
|
||||||
}
|
}
|
||||||
std::filesystem::rename(steamdir, modname);
|
std::filesystem::rename(steamdir, modname);
|
||||||
|
inputCmd->threadsCompleted++;
|
||||||
} else {
|
} else {
|
||||||
std::cerr << "Error: The directory " << steamdir << " does not exist." << std::endl;
|
std::cerr << "Error: The directory " << steamdir << " does not exist." << std::endl;
|
||||||
|
inputCmd->threadsCompleted++;
|
||||||
}
|
}
|
||||||
} catch (const std::filesystem::filesystem_error& e) {
|
} catch (const std::filesystem::filesystem_error& e) {
|
||||||
std::cerr << "Filesystem error: " << e.what() << std::endl;
|
std::cerr << "Filesystem error: " << e.what() << std::endl;
|
||||||
|
inputCmd->threadsCompleted++;
|
||||||
|
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
std::cerr << "Error: " << e.what() << std::endl;
|
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()) {
|
if (!inputCmd->sucids.empty()) {
|
||||||
std::regex downloadItemRegex(R"(Downloaded item (\d+))");
|
std::regex downloadItemRegex(R"(Downloaded item (\d+))");
|
||||||
|
|
||||||
std::smatch match;
|
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();
|
std::string downloadItemNumber = match[1].str();
|
||||||
inputCmd->idnumber = downloadItemNumber;
|
idnumber = downloadItemNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::istringstream inputStream(inputCmd->source);
|
std::istringstream inputStream(inputCmd->source);
|
||||||
|
|
||||||
std::regex grepRegex("\"id\":\"" + inputCmd->idnumber + "\",\"title\":\"");
|
std::regex grepRegex("\"id\":\"" + idnumber + "\",\"title\":\"");
|
||||||
std::string line;
|
std::string line;
|
||||||
|
|
||||||
while (std::getline(inputStream, line)) {
|
while (std::getline(inputStream, line)) {
|
||||||
|
@ -102,9 +110,9 @@ void Modname(cmd *inputCmd, std::string input) {
|
||||||
if (idPos != std::string::npos) {
|
if (idPos != std::string::npos) {
|
||||||
line = line.substr(idPos + idPrefix.length()); // Keep everything after "id="
|
line = line.substr(idPos + idPrefix.length()); // Keep everything after "id="
|
||||||
}
|
}
|
||||||
|
idname = line;
|
||||||
inputCmd->idname = line;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
filerestort(inputCmd, idnumber, idname);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef REGEX_H
|
#ifndef REGEX_H
|
||||||
#define REGEX_H
|
#define REGEX_H
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
// all the var's
|
// all the var's
|
||||||
struct cmd {
|
struct cmd {
|
||||||
const char* userHome = getenv("HOME");
|
const char* userHome = getenv("HOME");
|
||||||
|
@ -19,22 +19,20 @@ std::string dir;
|
||||||
|
|
||||||
bool ab = false;
|
bool ab = false;
|
||||||
|
|
||||||
// slashing
|
// total mods
|
||||||
int slashtp = 0;
|
int totalmods = 0;
|
||||||
std::string slash;
|
|
||||||
|
|
||||||
// counter
|
// Modnamestuff
|
||||||
std::string sucids;
|
std::vector<std::string> sucids;
|
||||||
std::string idnumber;
|
|
||||||
std::string idname;
|
|
||||||
|
|
||||||
int successes = 0;
|
int successes = 0;
|
||||||
int timedout = 0;
|
int timedout = 0;
|
||||||
int errors = 0;
|
int errors = 0;
|
||||||
int totalmeow = 0;
|
int totalmeow = 0;
|
||||||
|
|
||||||
|
size_t threadsCompleted = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
void Regex(cmd *inputCmd);
|
void Regex(cmd *inputCmd);
|
||||||
void filerestort(cmd *inputCmd);
|
void Modname(cmd *inputCmd, size_t index);
|
||||||
void Modname(cmd *inputCmd, std::string input);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
@ -24,7 +23,7 @@ void execAndDisplay(cmd *inputCmd, const std::string& cmd, std::atomic<bool>& ru
|
||||||
// checks for success.
|
// checks for success.
|
||||||
if (line.find("Success") != std::string::npos) {
|
if (line.find("Success") != std::string::npos) {
|
||||||
inputCmd->successes++;
|
inputCmd->successes++;
|
||||||
inputCmd->sucids += line + "\n";
|
inputCmd->sucids.push_back( line + "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
// checks for timed out ones.
|
// 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"};
|
std::ofstream meow{"/home/rander/.cache/errors.txt"};
|
||||||
meow << "start:\n" + line;
|
meow << "start:\n" + line;
|
||||||
}
|
}
|
||||||
|
|
||||||
inputCmd->totalmeow++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
running = false;
|
running = false;
|
||||||
|
@ -83,7 +80,7 @@ void maincommand(cmd *inputCmd) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// mod or collection?
|
// mod or collection?
|
||||||
std::string total = (inputCmd->ab == true) ? "Total: 1" : "Total: " + std::to_string(inputCmd->slashtp -1) + "\n";
|
std::string total = (inputCmd->ab == true) ? "Total: 1" : "Total: " + std::to_string(inputCmd->totalmods -1) + "\n";
|
||||||
std::string colm = (inputCmd->ab == true) ? R"(Mod)" : R"(Collection)";
|
std::string colm = (inputCmd->ab == true) ? R"(Mod)" : R"(Collection)";
|
||||||
|
|
||||||
// shows how much and what has downloaded
|
// shows how much and what has downloaded
|
||||||
|
@ -93,15 +90,13 @@ void maincommand(cmd *inputCmd) {
|
||||||
+ "Timed out: " + std::to_string(inputCmd->timedout) + "\n"
|
+ "Timed out: " + std::to_string(inputCmd->timedout) + "\n"
|
||||||
+ "Errored: " + std::to_string(inputCmd->errors) + "\n" + "\n";
|
+ "Errored: " + std::to_string(inputCmd->errors) + "\n" + "\n";
|
||||||
|
|
||||||
// mod names
|
//start the threads
|
||||||
std::istringstream inputStream(inputCmd->sucids);
|
for(size_t nya{0}; nya < inputCmd->sucids.size(); ++nya){
|
||||||
std::string line;
|
inputCmd->totalmods++;
|
||||||
|
std::thread meowT {Modname, inputCmd, nya};
|
||||||
while (std::getline(inputStream, line)) {
|
meowT.detach();
|
||||||
inputCmd->slashtp++;
|
|
||||||
Modname(inputCmd, line);
|
|
||||||
filerestort(inputCmd);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
while(inputCmd->threadsCompleted != inputCmd->sucids.size()){}
|
||||||
std::cout << "\n\n" + mods + colm + " has been downloaded too: " + inputCmd->dir + "\n";
|
std::cout << "\n\n" + mods + colm + " has been downloaded too: " + inputCmd->dir + "\n";
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue