diff --git a/include/drive.h b/include/drive.h index 88f527c..11419eb 100644 --- a/include/drive.h +++ b/include/drive.h @@ -38,6 +38,7 @@ private: time_t u32Timestamp = 0U; //unix timestamp for detecting a frozen drive double d32TaskPercentage = 0U; //in percent for Shred (1 to 100) time_t u32TimestampTaskStart = 0U; //unix timestamp for duration of an action + time_t u32TaskDuration = 0U; //time needed to complete the task private: void setTimestamp(); @@ -79,6 +80,9 @@ public: void setActionStartTimestamp(); time_t getActionStartTimestamp(); + void calculateTaskDuration(); + time_t getTaskDuration(); + }; #endif // DRIVE_H_ \ No newline at end of file diff --git a/include/reHDD.h b/include/reHDD.h index b213dc9..755ce7a 100644 --- a/include/reHDD.h +++ b/include/reHDD.h @@ -29,7 +29,7 @@ #endif // Logic -#define DRYRUN //don´t touch the drives +//#define DRYRUN //don´t touch the drives #define FROZEN_ALERT //show alert if drive is frozen //IPC pipes diff --git a/include/tui.h b/include/tui.h index bb4573f..58312ce 100644 --- a/include/tui.h +++ b/include/tui.h @@ -64,8 +64,7 @@ private: static WINDOW* createSmartWarning(int iXSize, int iYSize, int iXStart, int iYStart, string sPath, uint32_t u32PowerOnHours, uint32_t u32PowerCycles, uint32_t u32ErrorCount); void displaySelectedDrive(Drive drive, int stdscrX, int stdscrY); - - string calculateTimeDelta(time_t start, time_t end); + string formatTimeDuration(time_t u32Duration); }; #endif // TUI_H_ \ No newline at end of file diff --git a/src/drive.cpp b/src/drive.cpp index 2579c4d..964e8b2 100644 --- a/src/drive.cpp +++ b/src/drive.cpp @@ -134,7 +134,6 @@ void Drive::setDriveSMARTData( string modelFamily, u32PowerCycles = powerCycle; } - void Drive::setTimestamp() { time(&this->u32Timestamp); @@ -150,6 +149,19 @@ time_t Drive::getActionStartTimestamp() return this->u32TimestampTaskStart; } +void Drive::calculateTaskDuration() +{ + time_t u32localtime; + time(&u32localtime); + + this->u32TaskDuration = u32localtime - this->u32TimestampTaskStart; +} + +time_t Drive::getTaskDuration() +{ + return this->u32TaskDuration; +} + void Drive::checkFrozenDrive(void) { time_t u32localtime; diff --git a/src/tui.cpp b/src/tui.cpp index e989ceb..a5ce501 100644 --- a/src/tui.cpp +++ b/src/tui.cpp @@ -96,7 +96,7 @@ void TUI::updateTUI(list * plistDrives, uint8_t u8SelectedEntry) } stringstream stream; - time_t u32localtime; + switch (it->state) { @@ -105,13 +105,13 @@ void TUI::updateTUI(list * plistDrives, uint8_t u8SelectedEntry) stream << fixed << setprecision(2) << (it->getTaskPercentage()); sState = "Shredding: " + stream.str() + "%"; - time(&u32localtime); - sTime = this->calculateTimeDelta(it->getActionStartTimestamp(), u32localtime); + it->calculateTaskDuration(); + sTime = this->formatTimeDuration(it->getTaskDuration()); break; case Drive::DELETE_ACTIVE: sState = "Deleting ..."; - time(&u32localtime); - sTime = this->calculateTimeDelta(it->getActionStartTimestamp(), u32localtime); + it->calculateTaskDuration(); + sTime = this->formatTimeDuration(it->getTaskDuration()); break; case Drive::NONE: @@ -124,6 +124,7 @@ void TUI::updateTUI(list * plistDrives, uint8_t u8SelectedEntry) if (it->bWasShredded) { sState = "SHREDDED"; //mark drive as shreded previously, overwrite if deleted + sTime = this->formatTimeDuration(it->getTaskDuration()); } break; case Drive::FROZEN: @@ -447,18 +448,15 @@ WINDOW* TUI::createFrozenWarning(int iXSize, int iYSize, int iXStart, int iYStar return newWindow; } -string TUI::calculateTimeDelta(time_t start, time_t end) +string TUI::formatTimeDuration(time_t u32Duration) { std::ostringstream out; - - int hr=(int)((end - start)/3600); - int min=((int)((end - start)/60))%60; - int sec=(int)((end - start)%60); - + int hr=(int)((u32Duration)/3600); + int min=((int)((u32Duration)/60))%60; + int sec=(int)((u32Duration)%60); char s[25]; sprintf(s, "%02d:%02d:%02d", hr, min, sec); out << s; - return out.str(); }