bumped: (0.1.6) added auto renaming closing (5)
This commit is contained in:
parent
220fab1f22
commit
0ed8a758af
7 changed files with 88 additions and 9 deletions
2
PKGBUILD
2
PKGBUILD
|
@ -1,6 +1,6 @@
|
|||
pkgname=stc-git
|
||||
_gitname=stc
|
||||
pkgver=0.1.5
|
||||
pkgver=0.1.6
|
||||
pkgrel=1
|
||||
pkgdesc="Easily download collections and mods from steam."
|
||||
url="https://github.com/DRAGONTOS/stc"
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
===============================================================================
|
||||
Language Files Lines Code Comments Blanks
|
||||
===============================================================================
|
||||
C++ 4 319 251 21 47
|
||||
C++ Header 4 66 53 5 8
|
||||
C++ 4 389 320 21 48
|
||||
C++ Header 4 73 59 5 9
|
||||
===============================================================================
|
||||
Total 8 385 304 26 55
|
||||
Total 8 462 379 26 57
|
||||
===============================================================================
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
{
|
||||
"version": "0.1.5"
|
||||
"version": "0.1.6"
|
||||
}
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
#include <filesystem>
|
||||
#include <iostream>
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include "regex"
|
||||
|
@ -48,3 +51,60 @@ void Regex(cmd *inputCmd) {
|
|||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
// all the var's
|
||||
struct cmd {
|
||||
const char* userHome = getenv("HOME");
|
||||
// buffers
|
||||
std::string ids;
|
||||
std::string source;
|
||||
|
@ -23,6 +24,10 @@ int slashtp = 0;
|
|||
std::string slash;
|
||||
|
||||
// counter
|
||||
std::string sucids;
|
||||
std::string idnumber;
|
||||
std::string idname;
|
||||
|
||||
int successes = 0;
|
||||
int timedout = 0;
|
||||
int errors = 0;
|
||||
|
@ -30,4 +35,6 @@ int totalmeow = 0;
|
|||
};
|
||||
|
||||
void Regex(cmd *inputCmd);
|
||||
void filerestort(cmd *inputCmd);
|
||||
void Modname(cmd *inputCmd, std::string input);
|
||||
#endif
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <filesystem>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
@ -14,8 +13,6 @@
|
|||
int main(int argc, char **argv, char **envp) {
|
||||
// struct cmd
|
||||
cmd inputCmd;
|
||||
inputCmd.dir = std::filesystem::current_path();
|
||||
|
||||
std::vector<std::string> ARGS{argv, argv + argc};
|
||||
for (int i = 0; i < argc; ++i) {
|
||||
ARGS[i] = std::string{argv[i]};
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
|
@ -22,6 +24,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";
|
||||
}
|
||||
|
||||
// checks for timed out ones.
|
||||
|
@ -58,8 +61,10 @@ void showLoadingCursor(std::atomic<bool>& running) {
|
|||
void maincommand(cmd *inputCmd) {
|
||||
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 "
|
||||
+ inputCmd->dir
|
||||
+ std::string(inputCmd->userHome) + "/.cache"
|
||||
+ " +login "
|
||||
+ inputCmd->user
|
||||
+ ((inputCmd->pass.empty()) ? "" : inputCmd->pass)
|
||||
|
@ -88,5 +93,15 @@ 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->slashtp++;
|
||||
Modname(inputCmd, line);
|
||||
filerestort(inputCmd);
|
||||
}
|
||||
|
||||
std::cout << "\n\n" + mods + colm + " has been downloaded too: " + inputCmd->dir + "\n";
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue