From a2a18bbc34a8b7292edfe11e2be92dd01084efa6 Mon Sep 17 00:00:00 2001 From: localhorst Date: Sun, 23 Aug 2020 11:04:10 +0200 Subject: [PATCH] delete task --- include/delete.h | 25 +++++++++++++++++++++++++ include/drive.h | 2 +- include/reHDD.h | 1 + include/tui.h | 4 ++-- src/delete.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ src/reHDD.cpp | 10 +++++----- 6 files changed, 75 insertions(+), 8 deletions(-) create mode 100644 include/delete.h create mode 100644 src/delete.cpp diff --git a/include/delete.h b/include/delete.h new file mode 100644 index 0000000..d1e1381 --- /dev/null +++ b/include/delete.h @@ -0,0 +1,25 @@ +/** + * @file delete.h + * @brief delete drive + * @author hendrik schutter + * @date 23.08.2020 + */ + +#ifndef DELETE_H_ +#define DELETE_H_ + +#include "reHDD.h" + +class Delete +{ +protected: + +public: + static void deleteDrive(Drive* drive); + +private: + Delete(void); + +}; + +#endif // DELETE_H_ diff --git a/include/drive.h b/include/drive.h index ba11ce0..a2b66c6 100644 --- a/include/drive.h +++ b/include/drive.h @@ -20,7 +20,7 @@ public: DELETE_SELECTED, DELETE_ACTIVE } state; - + bool bWasShredded = false; bool bWasDeleteted = false; diff --git a/include/reHDD.h b/include/reHDD.h index 5bf31ea..793a77e 100644 --- a/include/reHDD.h +++ b/include/reHDD.h @@ -37,6 +37,7 @@ using namespace std; #include "drive.h" #include "smart.h" #include "shred.h" +#include "delete.h" #include "tui.h" diff --git a/include/tui.h b/include/tui.h index c5f25dd..c90d005 100644 --- a/include/tui.h +++ b/include/tui.h @@ -45,7 +45,7 @@ private: static string sRamUsage; static string sLocalTime; - + WINDOW* overview; WINDOW* systemview; WINDOW* detailview; @@ -59,7 +59,7 @@ private: static WINDOW *createSystemStats(int iXSize, int iYSize, int iYStart); static WINDOW *createMenuView(int iXSize, int iYSize, int iXStart, int iYStart, struct MenuState menustate); static WINDOW *createDialog(int iXSize, int iYSize, int iXStart, int iYStart, string selectedTask, string optionA, string optionB); - + void displaySelectedDrive(Drive drive, int stdscrX, int stdscrY); }; diff --git a/src/delete.cpp b/src/delete.cpp new file mode 100644 index 0000000..a34db6e --- /dev/null +++ b/src/delete.cpp @@ -0,0 +1,41 @@ +/** + * @file delete.cpp + * @brief delete drive + * @author hendrik schutter + * @date 23.08.2020 + */ + +#include "../include/reHDD.h" + +/** + * \brief delete drive with wipefs + * \param pointer of Drive instance + * \return void + */ +void Delete::deleteDrive(Drive* drive) + +{ + size_t len = 0; //lenght of found line + char* cLine = NULL; //found line + +#ifndef DRYRUN + string sCMD = ("wipefs -af "); + sCMD.append(drive->getPath()); +#endif + +#ifdef DRYRUN + //cout << "dryrun for " << drive->getPath() << endl; + string sCMD = ("echo"); +#endif + + const char* cpComand = sCMD.c_str(); + //cout << "delete: " << cpComand << endl; + + FILE* deleteCmdOutput = popen(cpComand, "r"); + + while ((getline(&cLine, &len, deleteCmdOutput)) != -1) + { + //wipefs running + } + fclose(deleteCmdOutput); +} diff --git a/src/reHDD.cpp b/src/reHDD.cpp index dd44883..bfaf6c8 100644 --- a/src/reHDD.cpp +++ b/src/reHDD.cpp @@ -163,7 +163,7 @@ void reHDD::ThreadUserInput() void reHDD::ThreadShred() { - Shred::shredDrive(&vecDrives.at(i32SelectedEntry), &fdShredInformPipe[1]); + Shred::shredDrive(&SELECTED_DRIVE, &fdShredInformPipe[1]); } void reHDD::filterNewDrives(vector * pvecOldDrives, vector * pvecNewDrives) @@ -191,7 +191,6 @@ void reHDD::filterNewDrives(vector * pvecOldDrives, vector * pvecN if(bOldDriveIsOffline == true) { //cout << "offline drive found: " << itOld->getPath() << endl; - //TODO kill task thread if running itOld->state = Drive::NONE; } } @@ -396,7 +395,9 @@ void reHDD::handleEnter() { SELECTED_DRIVE.state = Drive::TaskState::DELETE_ACTIVE; //task for drive is running --> donĀ“t show more task options - //TODO start deleting + Delete::deleteDrive(&SELECTED_DRIVE); //blocking, no thread + SELECTED_DRIVE.state = Drive::TaskState::NONE; //delete finished + SELECTED_DRIVE.bWasDeleteted = true; } } @@ -419,7 +420,6 @@ void reHDD::handleAbort() { if(SELECTED_DRIVE.state == Drive::SHRED_ACTIVE || SELECTED_DRIVE.state == Drive::DELETE_ACTIVE ) { - // TODO cancle shred or delete SELECTED_DRIVE.state = Drive::NONE; //task for drive is running --> remove selection } @@ -435,7 +435,7 @@ void reHDD::checkShredComplete(vector * pvecDrives) { it->bWasShredded = true; //mark this drive as shredded it->setTaskPercentage(0); //reset for an other shredding - it->state = Drive::NONE; //reset for an other task# + it->state = Drive::NONE; //reset for an other task } } } \ No newline at end of file