mirror of
https://gitea.home.endeavr.de/Marcel/Tarstats-pp.git
synced 2025-12-10 00:39:01 +01:00
this added json output to stdout, to file and global json stats to file. tarstats is feature complete.
This commit is contained in:
39
tarfunc.cpp
39
tarfunc.cpp
@@ -87,9 +87,9 @@ void tar::consolestats (std::map<std::string, uintmax_t> &typecount, uintmax_t t
|
||||
}
|
||||
|
||||
void tar::consoleglobalstats (std::map<std::string, uintmax_t> &typecount, uintmax_t filesize,
|
||||
uintmax_t itemsize, std::vector<std::string> &files) {
|
||||
uintmax_t itemsize, size_t fileamount) {
|
||||
std::cout << "GLOBAL STATS" << '\n';
|
||||
std::cout << "File amount: " << files.size() << '\n';
|
||||
std::cout << "File amount: " << fileamount << '\n';
|
||||
std::cout << "Size of all archives: " << filesize << " Bytes" << '\n';
|
||||
std::cout << "Size of all items: " << itemsize << " Bytes" << '\n';
|
||||
for (auto &i : typecount) {
|
||||
@@ -98,6 +98,41 @@ void tar::consoleglobalstats (std::map<std::string, uintmax_t> &typecount, uintm
|
||||
std::cout << '\n' << '\n';
|
||||
}
|
||||
|
||||
void tar::jsonconsolestats (std::map<std::string, uintmax_t> &typecount, uintmax_t tarfilesize, uintmax_t sizeofall,
|
||||
std::string &filename, std::string type) {
|
||||
std::cout << "{\"type\": \"" << type << "\", \"name\": \"" << filename << "\", \"size\": " << tarfilesize
|
||||
<< ", \"itemsize\": " << sizeofall << ", \"files\": " << typecount[tarconstant::typeFile]
|
||||
<< ", \"dir\": " << typecount[tarconstant::typeDir] << ", \"symlinks\": " << typecount[tarconstant::typeSym]
|
||||
<< ", \"hardlinks\": " << typecount[tarconstant::typeHard] << ", \"other\": "
|
||||
<< typecount[tarconstant::typeOther] << "}" << '\n' << '\n';
|
||||
}
|
||||
|
||||
void tar::jsonfilestats (std::map<std::string, uintmax_t> &typecount, uintmax_t tarfilesize, uintmax_t sizeofall,
|
||||
std::string &filename, std::string type) {
|
||||
std::string jsnname = filename + ".json";
|
||||
std::ofstream jsonfile(jsnname);
|
||||
jsonfile << "{\"type\": \"" << type << "\", \"name\": \"" << filename << "\", \"size\": " << tarfilesize
|
||||
<< ", \"itemsize\": " << sizeofall << ", \"files\": " << typecount[tarconstant::typeFile]
|
||||
<< ", \"dir\": " << typecount[tarconstant::typeDir] << ", \"symlinks\": " << typecount[tarconstant::typeSym]
|
||||
<< ", \"hardlinks\": " << typecount[tarconstant::typeHard] << ", \"other\": "
|
||||
<< typecount[tarconstant::typeOther] << "}" << '\n';
|
||||
jsonfile.close();
|
||||
std::cout << "Stats written to " << jsnname << '\n' << '\n';
|
||||
}
|
||||
|
||||
void tar::jsonglobalfile (std::map<std::string, uintmax_t> &typecount, uintmax_t itemsize,
|
||||
uintmax_t filesize, size_t fileamount) {
|
||||
std::ofstream jsonfile("global.json");
|
||||
jsonfile << "{\"itemamount\": " << fileamount << ", \"itemsize\": " << itemsize << ", \"filesize\": "
|
||||
<< filesize << ", \"files\": " << typecount[tarconstant::typeFile]
|
||||
<< ", \"dir\": " << typecount[tarconstant::typeDir] << ", \"symlinks\": "
|
||||
<< typecount[tarconstant::typeSym] << ", \"hardlinks\": "
|
||||
<< typecount[tarconstant::typeHard] << ", \"other\": "
|
||||
<< typecount[tarconstant::typeOther] << "}" << '\n';
|
||||
jsonfile.close();
|
||||
std::cout << "Global stats written to global.json" << '\n' << '\n';
|
||||
}
|
||||
|
||||
// writes default console output to txt file
|
||||
void tar::txtfilestats (std::map<std::string, uintmax_t> &typecount, uintmax_t tarfilesize, uintmax_t sizeofall,
|
||||
std::string archiveName) {
|
||||
|
||||
Reference in New Issue
Block a user