bumped: (0.1.6) added auto renaming closing (5)

This commit is contained in:
Kaley, Fischer 2024-10-22 23:40:46 +02:00
parent 220fab1f22
commit 0ed8a758af
7 changed files with 88 additions and 9 deletions

View file

@ -1,6 +1,6 @@
pkgname=stc-git pkgname=stc-git
_gitname=stc _gitname=stc
pkgver=0.1.5 pkgver=0.1.6
pkgrel=1 pkgrel=1
pkgdesc="Easily download collections and mods from steam." pkgdesc="Easily download collections and mods from steam."
url="https://github.com/DRAGONTOS/stc" url="https://github.com/DRAGONTOS/stc"

View file

@ -1,8 +1,8 @@
=============================================================================== ===============================================================================
Language Files Lines Code Comments Blanks Language Files Lines Code Comments Blanks
=============================================================================== ===============================================================================
C++ 4 319 251 21 47 C++ 4 389 320 21 48
C++ Header 4 66 53 5 8 C++ Header 4 73 59 5 9
=============================================================================== ===============================================================================
Total 8 385 304 26 55 Total 8 462 379 26 57
=============================================================================== ===============================================================================

View file

@ -1,3 +1,3 @@
{ {
"version": "0.1.5" "version": "0.1.6"
} }

View file

@ -1,3 +1,6 @@
#include <filesystem>
#include <iostream>
#include <ostream>
#include <string> #include <string>
#include <sstream> #include <sstream>
#include "regex" #include "regex"
@ -48,3 +51,60 @@ void Regex(cmd *inputCmd) {
inputCmd->slashtp++; inputCmd->slashtp++;
} }
} }
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;
// renames and moves the files.
try {
if (std::filesystem::exists(steamdir)) {
if (std::filesystem::exists(modname)) {
std::filesystem::remove_all(modname);
}
std::filesystem::rename(steamdir, modname);
} else {
std::cerr << "Error: The directory " << steamdir << " does not exist." << std::endl;
}
} catch (const std::filesystem::filesystem_error& e) {
std::cerr << "Filesystem error: " << e.what() << std::endl;
} catch (const std::exception& e) {
std::cerr << "Error: " << e.what() << std::endl;
}
}
void Modname(cmd *inputCmd, std::string input) {
if (!inputCmd->sucids.empty()) {
std::regex downloadItemRegex(R"(Downloaded item (\d+))");
std::smatch match;
if (std::regex_search(input, match, downloadItemRegex)) {
std::string downloadItemNumber = match[1].str();
inputCmd->idnumber = downloadItemNumber;
}
std::istringstream inputStream(inputCmd->source);
std::regex grepRegex("\"id\":\"" + inputCmd->idnumber + "\",\"title\":\"");
std::string line;
while (std::getline(inputStream, line)) {
if (std::regex_search(line, grepRegex)) {
std::size_t divPos = line.find("\",\"description\":");
if (divPos != std::string::npos) {
line = line.substr(0, divPos); // Trim everything after '"><div class='
}
std::string idPrefix = "\",\"title\":\""; // The prefix to search for
std::size_t idPos = line.find(idPrefix);
if (idPos != std::string::npos) {
line = line.substr(idPos + idPrefix.length()); // Keep everything after "id="
}
inputCmd->idname = line;
}
}
}
}

View file

@ -4,6 +4,7 @@
// all the var's // all the var's
struct cmd { struct cmd {
const char* userHome = getenv("HOME");
// buffers // buffers
std::string ids; std::string ids;
std::string source; std::string source;
@ -23,6 +24,10 @@ int slashtp = 0;
std::string slash; std::string slash;
// counter // counter
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;
@ -30,4 +35,6 @@ int totalmeow = 0;
}; };
void Regex(cmd *inputCmd); void Regex(cmd *inputCmd);
void filerestort(cmd *inputCmd);
void Modname(cmd *inputCmd, std::string input);
#endif #endif

View file

@ -2,7 +2,6 @@
#include <cstdio> #include <cstdio>
#include <cstdlib> #include <cstdlib>
#include <cstring> #include <cstring>
#include <filesystem>
#include <iostream> #include <iostream>
#include <string> #include <string>
#include <vector> #include <vector>
@ -14,8 +13,6 @@
int main(int argc, char **argv, char **envp) { int main(int argc, char **argv, char **envp) {
// struct cmd // struct cmd
cmd inputCmd; cmd inputCmd;
inputCmd.dir = std::filesystem::current_path();
std::vector<std::string> ARGS{argv, argv + argc}; std::vector<std::string> ARGS{argv, argv + argc};
for (int i = 0; i < argc; ++i) { for (int i = 0; i < argc; ++i) {
ARGS[i] = std::string{argv[i]}; ARGS[i] = std::string{argv[i]};

View file

@ -1,5 +1,7 @@
#include <filesystem>
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
#include <sstream>
#include <stdexcept> #include <stdexcept>
#include <string> #include <string>
#include <thread> #include <thread>
@ -22,6 +24,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";
} }
// checks for timed out ones. // checks for timed out ones.
@ -58,8 +61,10 @@ void showLoadingCursor(std::atomic<bool>& running) {
void maincommand(cmd *inputCmd) { void maincommand(cmd *inputCmd) {
std::string idsm = R"( +workshop_download_item )" + inputCmd->gameid + " " + inputCmd->modid + " +quit"; std::string idsm = R"( +workshop_download_item )" + inputCmd->gameid + " " + inputCmd->modid + " +quit";
std::filesystem::remove_all(std::string(inputCmd->userHome) + "/.cache/steamapps");
std::string maincommand2 = std::string{"sh ~/Steam/steamcmd.sh +force_install_dir " std::string maincommand2 = std::string{"sh ~/Steam/steamcmd.sh +force_install_dir "
+ inputCmd->dir + std::string(inputCmd->userHome) + "/.cache"
+ " +login " + " +login "
+ inputCmd->user + inputCmd->user
+ ((inputCmd->pass.empty()) ? "" : inputCmd->pass) + ((inputCmd->pass.empty()) ? "" : inputCmd->pass)
@ -88,5 +93,15 @@ 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
std::istringstream inputStream(inputCmd->sucids);
std::string line;
while (std::getline(inputStream, line)) {
inputCmd->slashtp++;
Modname(inputCmd, line);
filerestort(inputCmd);
}
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";
} }