summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOskar <[email protected]>2024-10-23 21:34:19 +0200
committerOskar <[email protected]>2024-10-23 21:34:19 +0200
commit3581ae48ebe6a451ec2e7294ea82cc1c09950211 (patch)
tree7db630c5ee358877f787feb61cf64c677e827617
parentaef128d457d4a033c331f7a98a8fadd9cf0e204b (diff)
units done
-rw-r--r--trashsystem2.cpp30
-rw-r--r--trashsystem2.hpp22
2 files changed, 51 insertions, 1 deletions
diff --git a/trashsystem2.cpp b/trashsystem2.cpp
index 91eb72e..9d29587 100644
--- a/trashsystem2.cpp
+++ b/trashsystem2.cpp
@@ -300,12 +300,40 @@ TS_FUNCTION_RESULT get_file_info_from_log(const initial_path_info &ipi,
return FUNCTION_SUCCESS;
}
+filesize_unit to_filesize_unit(std::uintmax_t bytes) {
+
+ double d_bytes = bytes;
+ int count = 0;
+ std::vector<int> unit = {1, 2, 3, 4};
+ while(d_bytes >= 1024) {
+ d_bytes = d_bytes / 1024;
+ count++;
+ }
+
+ filesize_unit size(d_bytes);
+ if(unit[count] == 1) { size.set_is_bytes(true); }
+
+ if(unit[count] == 2) { size.set_is_kib(true); }
+
+ if(unit[count] == 3) { size.set_is_mib(true); }
+
+ if(unit[count] == 4) { size.set_is_gib(true); }
+
+ return size;
+}
+
TS_FUNCTION_RESULT list_trashed(const std::vector<trashsys_log_info> &vtli) {
for(auto &a : vtli) {
+ filesize_unit fu = to_filesize_unit(a.rget_logfsz());
+ std::string unit;
+ if(fu.is_bytes()) { unit = "B"; }
+ if(fu.is_kib()) { unit = "KiB"; }
+ if(fu.is_mib()) { unit = "MiB"; }
+ if(fu.is_gib()) { unit = "GiB"; }
std::cout << "ID: " << a.rget_logid() << " "
<< std::string(a.rget_logfn()) << " "
- << a.rget_logfsz() << " " // temporary, will create function to return human readable filesize
+ << fu.get_number() << " " << unit << " " // temporary, will create function to return human readable filesize
<< "Trashed at: " << a.rget_logtt() << " " // temporary, will create function to return human readable date
<< a.rget_isdir() << std::endl; // temporary, will create function to return human readable 'file' or 'directory
}
diff --git a/trashsystem2.hpp b/trashsystem2.hpp
index c8fd6b3..83c1ead 100644
--- a/trashsystem2.hpp
+++ b/trashsystem2.hpp
@@ -36,6 +36,28 @@ const TS_FUNCTION_RESULT FUNCTION_SUCCESS = 0;
#include <vector>
#include <cstdlib>
+class filesize_unit { // not dealing with this now. Ill figure it out later.
+public:
+ filesize_unit() = default;
+ filesize_unit(double number, bool bytes = false, bool kib = false, bool mib = false, bool gib = false):
+ _number(number), _is_bytes(bytes), _is_kib(kib), _is_mib(mib), _is_gib(gib) {}
+ double get_number() const { return _number; }
+ bool is_bytes() const { return _is_bytes; }
+ bool is_kib() const { return _is_kib; }
+ bool is_mib() const { return _is_mib; }
+ bool is_gib() const { return _is_gib; }
+ void set_is_bytes(bool a) { _is_bytes = a; }
+ void set_is_kib(bool a) { _is_kib = a; }
+ void set_is_mib(bool a) { _is_mib = a; }
+ void set_is_gib(bool a) { _is_gib = a; }
+private:
+ double _number = 0;
+ bool _is_bytes = false;
+ bool _is_kib = false;
+ bool _is_mib = false;
+ bool _is_gib = false;
+};
+
class directory_entry {
public:
directory_entry(std::filesystem::path dep, bool isd = false, bool isr = false, bool iso = false):