From 6732aacdc8e4ef3d07f4858bb19ef30861ac42ca Mon Sep 17 00:00:00 2001 From: localhorst Date: Thu, 11 Dec 2025 20:48:18 +0100 Subject: [PATCH] handle user input --- include/reHDD.h | 4 +++- src/reHDD.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/include/reHDD.h b/include/reHDD.h index 059e199..eced4d0 100644 --- a/include/reHDD.h +++ b/include/reHDD.h @@ -31,7 +31,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 #define ZERO_CHECK // check drive after shred if all bytes are zero, show alert if this fails @@ -90,6 +90,8 @@ private: static void filterInvalidDrives(list *plistDrives); static void filterNewDrives(list *plistOldDrives, list *plistNewDrives); static void addSMARTData(list *plistDrives); + static void printAllDrives(list *plistDrives); + static void printDrive(Drive *const pDrive); static void ThreadScanDevices(); static void ThreadUserInput(); static void ThreadShred(Drive *const pDrive); diff --git a/src/reHDD.cpp b/src/reHDD.cpp index 57cd30a..107c90f 100644 --- a/src/reHDD.cpp +++ b/src/reHDD.cpp @@ -216,12 +216,59 @@ void reHDD::ThreadUserInput() sleep(5); // sleep 5 sec std::exit(1); // Terminates main, doesn't wait for threads break; + case TUI::UserInput::Print: + // cout << "Print" << endl; + Logger::logThis()->info("User print single"); + if (tmpSelectedDrive != nullptr) + { + // printDrive(tmpSelectedDrive); + } + // ui->updateTUI(&listDrives, u16SelectedEntry); + break; + case TUI::UserInput::PrintAll: + // cout << "PrintAll" << endl; + Logger::logThis()->info("User print all"); + // printAllDrives(&listDrives); + // ui->updateTUI(&listDrives, u16SelectedEntry); + break; default: break; } } } +/** + * \brief start shred for all drives + * \param pointer of list * plistDrives + * \return void + */ +void reHDD::printAllDrives(list *plistDrives) +{ + list::iterator it; + mxDrives.lock(); + for (it = plistDrives->begin(); it != plistDrives->end(); ++it) + { + Drive *pTmpDrive = iterator_to_pointer::iterator>(it); + printDrive(pTmpDrive); + } + mxDrives.unlock(); +} + +void reHDD::printDrive(Drive *const pDrive) +{ + if (pDrive->bWasShredded) + { +#ifdef ZERO_CHECK + if (pDrive->bWasChecked && (pDrive->u32DriveChecksumAfterShredding != 0U)) + { + return; // Drive was shredded&checked but checksum failed, don't print label + } +#endif + Logger::logThis()->info("User print for: " + pDrive->getModelName() + "-" + pDrive->getSerial()); + // TODO: Trigger printer for this drive + } +} + void reHDD::ThreadShred(Drive *const pDrive) { if (pDrive != nullptr)