From 04f46bb9d6fc3a907e2895a507af3330093200d0 Mon Sep 17 00:00:00 2001 From: localhorst Date: Fri, 18 Sep 2020 14:42:45 +0200 Subject: [PATCH 1/7] fixed delete cmd --- src/delete.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/delete.cpp b/src/delete.cpp index a34db6e..68b2984 100644 --- a/src/delete.cpp +++ b/src/delete.cpp @@ -21,6 +21,7 @@ void Delete::deleteDrive(Drive* drive) #ifndef DRYRUN string sCMD = ("wipefs -af "); sCMD.append(drive->getPath()); + sCMD.append("*"); #endif #ifdef DRYRUN -- 2.47.1 From 66cfbb5da2daea10ac4791c05bc949ec4dc89c77 Mon Sep 17 00:00:00 2001 From: localhorst Date: Sun, 20 Sep 2020 00:12:18 +0200 Subject: [PATCH 2/7] ls instead hwinfo; update UI even mutex is locked --- include/reHDD.h | 7 +++++-- include/tui.h | 2 +- src/reHDD.cpp | 35 +++++++++++++++++------------------ src/tui.cpp | 9 +++++++-- 4 files changed, 30 insertions(+), 23 deletions(-) diff --git a/include/reHDD.h b/include/reHDD.h index f10f157..5bb3344 100644 --- a/include/reHDD.h +++ b/include/reHDD.h @@ -10,8 +10,6 @@ #define REHDD_VERSION "bV0.1.0" -//#define DRYRUN - // Drive handling Settings #define WORSE_HOURS 19200 //mark drive if at this limit or beyond #define WORSE_POWERUP 10000 //mark drive if at this limit or beyond @@ -25,6 +23,11 @@ #define SOFTWARE_VERSION "alpha" #define HARDWARE_VERSION "generic" +// Logic +//#define DRYRUN //don´t touch the drives +#define FROZEN_ALERT //show alert if drive is frozen + + #define LOG_LEVEL_HIGH //log everything, like drive scann thread #ifndef LOG_LEVEL_HIGH #define LOG_LEVEL_LOW //log only user actions and tasks diff --git a/include/tui.h b/include/tui.h index 135ff0d..33f95b4 100644 --- a/include/tui.h +++ b/include/tui.h @@ -60,7 +60,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); - static WINDOW* createFrozenWarning(int iXSize, int iYSize, int iXStart, int iYStart, string sPath, string sModelFamily, string sModelName, string sSerial); + static WINDOW* createFrozenWarning(int iXSize, int iYSize, int iXStart, int iYStart, string sPath, string sModelFamily, string sModelName, string sSerial, string sProgress); void displaySelectedDrive(Drive drive, int stdscrX, int stdscrY); diff --git a/src/reHDD.cpp b/src/reHDD.cpp index e1f91bc..8405708 100644 --- a/src/reHDD.cpp +++ b/src/reHDD.cpp @@ -23,8 +23,6 @@ static uint8_t u8SelectedEntry; static fd_set selectSet; -//static struct TUI::MenuState menustate; - /** * \brief app constructor * \param void @@ -61,23 +59,27 @@ void reHDD::app_logic(void) FD_SET(fdShredInformPipe[0], &selectSet); select(FD_SETSIZE, &selectSet, NULL, NULL, NULL); - mxScannDrives.lock(); - if( FD_ISSET(fdNewDrivesInformPipe[0], &selectSet)) + + if(FD_ISSET(fdNewDrivesInformPipe[0], &selectSet)) { + mxScannDrives.lock(); char dummy; read (fdNewDrivesInformPipe[0],&dummy,1); filterNewDrives(&vecDrives, &vecNewDrives); //filter and copy to app logic vector printDrives(&vecDrives); - + mxScannDrives.unlock(); } - - if (FD_ISSET(fdShredInformPipe[0], &selectSet)) + if(FD_ISSET(fdShredInformPipe[0], &selectSet)) { char dummy; read (fdShredInformPipe[0],&dummy,1); +#ifdef LOG_LEVEL_HIGH + Logger::logThis()->info("got progress signal from a shred task"); +#endif } + //mxScannDrives.lock(); ui->updateTUI(&vecDrives, u8SelectedEntry); - mxScannDrives.unlock(); + //mxScannDrives.unlock(); } //endless loop thDevices.join(); thUserInput.join(); @@ -112,8 +114,6 @@ void reHDD::ThreadScannDevices() } } - - void reHDD::ThreadCheckFrozenDrives() { while(true) @@ -127,7 +127,7 @@ void reHDD::ThreadCheckFrozenDrives() } } mxScannDrives.unlock(); - sleep(5); //sleep 5 sec + sleep(13); //sleep 13 sec } } @@ -284,18 +284,19 @@ void reHDD::searchDrives(vector * pvecDrives) char * cLine = NULL; size_t len = 0; - FILE* outputfileHwinfo = popen("hwinfo --short --disk", "r"); + FILE* outputfileHwinfo = popen("ls -1 /dev/sd*", "r"); if (outputfileHwinfo == NULL) { + Logger::logThis()->error("Unable to scann attached drives"); exit(EXIT_FAILURE); } while ((getline(&cLine, &len, outputfileHwinfo)) != -1) { - if (string(cLine).find("/dev/sd") != string::npos) + if (string(cLine).length() == 9) { - Drive* tmpDrive = new Drive(string(cLine).substr (2,8)); + Drive* tmpDrive = new Drive(string(cLine).substr(0, 8)); tmpDrive->state = Drive::NONE; tmpDrive->bIsOffline = false; pvecDrives->push_back(*tmpDrive); @@ -397,7 +398,7 @@ void reHDD::filterIgnoredDrives(vector * pvecDrives) void reHDD::printDrives(vector * pvecDrives) { #ifdef LOG_LEVEL_HIGH - Logger::logThis()->info("------------DRIVES---------------"); + Logger::logThis()->info("------------DRIVES START------------"); //cout << "------------DRIVES---------------" << endl; vector ::iterator it; for (it = pvecDrives->begin(); it != pvecDrives->end(); ++it) @@ -416,11 +417,9 @@ void reHDD::printDrives(vector * pvecDrives) ostringstream address; address << (void const *)&pvecDrives->at(it - pvecDrives->begin()); - - Logger::logThis()->info(to_string(it - pvecDrives->begin()) + ": " + it->getPath() + " - " + it->getModelFamily() + " - " + it->getSerial() + " @" + address.str()); } - Logger::logThis()->info("---------------------------------"); + Logger::logThis()->info("------------DRIVES END--------------"); //cout << "---------------------------------" << endl; #endif } diff --git a/src/tui.cpp b/src/tui.cpp index 1f962cc..902f252 100644 --- a/src/tui.cpp +++ b/src/tui.cpp @@ -112,8 +112,11 @@ void TUI::updateTUI(vector * pvecDrives, uint8_t u8SelectedEntry) } break; case Drive::FROZEN: - dialog=createFrozenWarning(70, 16, ((stdscrX)-(int)(stdscrX/2)-35),(int)(stdscrY/2)-8, it->getPath(), it->getModelFamily(), it->getModelName(), it->getSerial()); +#ifdef FROZEN_ALERT + stream << fixed << setprecision(2) << (it->getTaskPercentage()); + dialog=createFrozenWarning(70, 16, ((stdscrX)-(int)(stdscrX/2)-35),(int)(stdscrY/2)-8, it->getPath(), it->getModelFamily(), it->getModelName(), it->getSerial(), stream.str() + "%"); wrefresh(dialog); +#endif break; default: break; @@ -399,7 +402,7 @@ WINDOW* TUI::createDialog(int iXSize, int iYSize, int iXStart, int iYStart, stri return newWindow; } -WINDOW* TUI::createFrozenWarning(int iXSize, int iYSize, int iXStart, int iYStart, string sPath, string sModelFamily, string sModelName, string sSerial) +WINDOW* TUI::createFrozenWarning(int iXSize, int iYSize, int iXStart, int iYStart, string sPath, string sModelFamily, string sModelName, string sSerial, string sProgress) { WINDOW *newWindow; newWindow = newwin(iYSize, iXSize, iYStart, iXStart); @@ -409,6 +412,7 @@ WINDOW* TUI::createFrozenWarning(int iXSize, int iYSize, int iXStart, int iYStar string sHeader = "Drive " + sPath + " is frozen"; string sLine01 = "Please detach this drive and check it manually:"; + string sShredState = "Shredding stopped after " + sProgress; string sLinePath = "Path: " +sPath; string sLineModelFamlily = "ModelFamily: " + sModelFamily; string sLineModelName = "ModelName: " + sModelName; @@ -429,6 +433,7 @@ WINDOW* TUI::createFrozenWarning(int iXSize, int iYSize, int iXStart, int iYStar u16Line++; mvwaddstr(newWindow,u16Line++, 3, sLine02.c_str()); mvwaddstr(newWindow,u16Line++, 3, sLine03.c_str()); + mvwaddstr(newWindow,u16Line++, 3, sShredState.c_str()); return newWindow; } -- 2.47.1 From 65c19f6fb9879f84db89fded557608b51f67518f Mon Sep 17 00:00:00 2001 From: localhorst Date: Sun, 20 Sep 2020 22:40:05 +0200 Subject: [PATCH 3/7] define-switch for frozen alert --- astyle.sh | 24 ++++++++++++++++++++++++ makefile | 6 ++++-- src/tui.cpp | 10 +++++++--- 3 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 astyle.sh diff --git a/astyle.sh b/astyle.sh new file mode 100644 index 0000000..dee3705 --- /dev/null +++ b/astyle.sh @@ -0,0 +1,24 @@ +#! /bin/bash + +echo starting astyle for $PWD + +astyle --style=gnu src/*.cpp +rm -f src/*.orig + +astyle --style=gnu src/shred/*.cpp +rm -f src/shred/*.orig + +astyle --style=gnu src/logger/*.cpp +rm -f src/logger/*.orig + + +astyle --style=gnu include/*.h +rm -f include//*.orig + +astyle --style=gnu include//shred/*.h +rm -f include//shred/*.orig + +astyle --style=gnu include//logger/*.h +rm -f include//logger/*.orig + +echo finished astyle for $PWD diff --git a/makefile b/makefile index 4e3c0b5..fe3ada5 100644 --- a/makefile +++ b/makefile @@ -167,6 +167,7 @@ clean: @echo "Deleting directories" @$(RM) -r build @$(RM) -r bin + @$(RM) -f reHDD.log # Main rule, checks the executable and symlinks to the output all: $(BIN_PATH)/$(BIN_NAME) @@ -199,6 +200,7 @@ $(BUILD_PATH)/%.o: $(SRC_PATH)/%.$(SRC_EXT) docs: @$(RM) -r $(DOCDIR)/html @doxygen $(DOCDIR)/doxyfile - - +.PHONY: style +style: + @bash astyle.sh diff --git a/src/tui.cpp b/src/tui.cpp index 902f252..4004e72 100644 --- a/src/tui.cpp +++ b/src/tui.cpp @@ -112,11 +112,15 @@ void TUI::updateTUI(vector * pvecDrives, uint8_t u8SelectedEntry) } break; case Drive::FROZEN: -#ifdef FROZEN_ALERT stream << fixed << setprecision(2) << (it->getTaskPercentage()); - dialog=createFrozenWarning(70, 16, ((stdscrX)-(int)(stdscrX/2)-35),(int)(stdscrY/2)-8, it->getPath(), it->getModelFamily(), it->getModelName(), it->getSerial(), stream.str() + "%"); - wrefresh(dialog); +#ifdef FROZEN_ALERT + if(bSelectedEntry) + { + dialog=createFrozenWarning(70, 16, ((stdscrX)-(int)(stdscrX/2)-20),(int)(stdscrY/2)-8, it->getPath(), it->getModelFamily(), it->getModelName(), it->getSerial(), stream.str() + "%"); + wrefresh(dialog); + } #endif + sState = "FROZEN " + stream.str() + "%"; //mark drive as frozen and reached progress break; default: break; -- 2.47.1 From ade79add2a42a7ebb7aacebb3ebcccb909060eaf Mon Sep 17 00:00:00 2001 From: localhorst Date: Mon, 21 Sep 2020 14:45:52 +0200 Subject: [PATCH 4/7] increase visibility of smart values --- include/tui.h | 3 +- src/drive.cpp | 11 +++-- src/tui.cpp | 124 +++++++++++++++++++++++++++++++------------------- 3 files changed, 87 insertions(+), 51 deletions(-) diff --git a/include/tui.h b/include/tui.h index 33f95b4..5d073ae 100644 --- a/include/tui.h +++ b/include/tui.h @@ -45,12 +45,12 @@ private: static string sRamUsage; static string sLocalTime; - WINDOW* overview; WINDOW* systemview; WINDOW* detailview; WINDOW* menuview; WINDOW* dialog; + WINDOW* smartWarning; static void centerTitle(WINDOW *pwin, const char * title); static WINDOW *createOverViewWindow( int iXSize, int iYSize); @@ -61,6 +61,7 @@ private: 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); static WINDOW* createFrozenWarning(int iXSize, int iYSize, int iXStart, int iYStart, string sPath, string sModelFamily, string sModelName, string sSerial, string sProgress); + 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); diff --git a/src/drive.cpp b/src/drive.cpp index 36cd7c9..c7b4e45 100644 --- a/src/drive.cpp +++ b/src/drive.cpp @@ -69,14 +69,19 @@ string Drive::sErrorCountToText() string Drive::sPowerOnHoursToText() { + double dDays = 0U; double dYears = 0U; uint32_t u32Hours = getPowerOnHours(); - stringstream stream; + stringstream streamDays; + stringstream streamYears; + dDays = (double) ((double)u32Hours/(double)24U); dYears = (double) ((double)u32Hours/(double)8760U); - stream << fixed << setprecision(2) << dYears; - string sRet = to_string(getPowerOnHours()) + " hours or " + stream.str() + " years"; + streamDays << fixed << setprecision(0) << dDays; + streamYears << fixed << setprecision(1) << dYears; + + string sRet = to_string(getPowerOnHours()) + " hours or " + streamDays.str() + " days or " + streamYears.str() + " years"; return sRet; } diff --git a/src/tui.cpp b/src/tui.cpp index 4004e72..688299c 100644 --- a/src/tui.cpp +++ b/src/tui.cpp @@ -53,18 +53,18 @@ void TUI::initTUI() void TUI::updateTUI(vector * pvecDrives, uint8_t u8SelectedEntry) { mxUIrefresh.lock(); - int stdscrX, stdscrY; - getmaxyx(stdscr, stdscrY, stdscrX); + uint16_t u16StdscrX, u16StdscrY; + getmaxyx(stdscr, u16StdscrY, u16StdscrX); init_pair(COLOR_AREA_STDSCR,COLOR_WHITE, COLOR_BLUE); wbkgd(stdscr, COLOR_PAIR(COLOR_AREA_STDSCR)); refresh(); - overview=createOverViewWindow((int)(stdscrX/3), (stdscrY-15)); + overview=createOverViewWindow((int)(u16StdscrX/3), (u16StdscrY-15)); wrefresh(overview); - systemview=createSystemStats((int)(stdscrX/3), 10, (stdscrY-11)); + systemview=createSystemStats((int)(u16StdscrX/3), 10, (u16StdscrY-11)); wrefresh(systemview); delwin(detailview); @@ -82,7 +82,14 @@ void TUI::updateTUI(vector * pvecDrives, uint8_t u8SelectedEntry) if(u8SelectedEntry == (it - pvecDrives->begin())) { bSelectedEntry = true; //mark this drive in entries list - displaySelectedDrive(pvecDrives->at(u8SelectedEntry), stdscrX, stdscrY); + displaySelectedDrive(pvecDrives->at(u8SelectedEntry), u16StdscrX, u16StdscrY); + + if((it->getPowerOnHours() >= WORSE_HOURS) || (it->getPowerCycles() >= WORSE_POWERUP) || (it->getErrorCount() > 0)) + { + // smart values are bad --> show warning + smartWarning=createSmartWarning(50, 10, ((u16StdscrX)-(int)(u16StdscrX/2)+35),(int)(u16StdscrY/2)-5, it->getPath(), it->getPowerOnHours(), it->getPowerCycles(), it->getErrorCount()); + wrefresh(smartWarning); + } } stringstream stream; @@ -116,7 +123,7 @@ void TUI::updateTUI(vector * pvecDrives, uint8_t u8SelectedEntry) #ifdef FROZEN_ALERT if(bSelectedEntry) { - dialog=createFrozenWarning(70, 16, ((stdscrX)-(int)(stdscrX/2)-20),(int)(stdscrY/2)-8, it->getPath(), it->getModelFamily(), it->getModelName(), it->getSerial(), stream.str() + "%"); + dialog=createFrozenWarning(70, 16, ((u16StdscrX)-(int)(u16StdscrX/2)-20),(int)(u16StdscrY/2)-8, it->getPath(), it->getModelFamily(), it->getModelName(), it->getSerial(), stream.str() + "%"); wrefresh(dialog); } #endif @@ -126,7 +133,7 @@ void TUI::updateTUI(vector * pvecDrives, uint8_t u8SelectedEntry) break; } - WINDOW * tmp = createEntryWindow( ((int)(stdscrX/3) - 2), 5, 3, (5* (it - pvecDrives->begin()) )+3, sModelFamily, sModelName, sCapacity, sState, bSelectedEntry); + WINDOW * tmp = createEntryWindow( ((int)(u16StdscrX/3) - 2), 5, 3, (5* (it - pvecDrives->begin()) )+3, sModelFamily, sModelName, sCapacity, sState, bSelectedEntry); wrefresh(tmp); }//end loop though drives @@ -141,10 +148,10 @@ void TUI::updateTUI(vector * pvecDrives, uint8_t u8SelectedEntry) menustate.bDelete = false; menustate.bShred = false; - menuview=createMenuView(((stdscrX)-(int)(stdscrX/3)-7), 10, (int)(stdscrX/3)+5,(stdscrY-11), menustate); + menuview=createMenuView(((u16StdscrX)-(int)(u16StdscrX/3)-7), 10, (int)(u16StdscrX/3)+5,(u16StdscrY-11), menustate); wrefresh(menuview); - detailview=overwriteDetailViewWindow(((stdscrX)-(int)(stdscrX/3)-7), (stdscrY-15), (int)(stdscrX/3)+5); + detailview=overwriteDetailViewWindow(((u16StdscrX)-(int)(u16StdscrX/3)-7), (u16StdscrY-15), (int)(u16StdscrX/3)+5); wrefresh(detailview); } @@ -239,38 +246,9 @@ WINDOW* TUI::createDetailViewWindow( int iXSize, int iYSize, int iXStart, Drive attroff(COLOR_PAIR(COLOR_AREA_DETAIL)); - if(drive.getPowerOnHours() >= WORSE_HOURS) - { - mvwaddstr(newWindow,u16Line++, 3, "------------> WARNING: OPERATING HOURS <-----------"); - mvwaddstr(newWindow,u16Line++, 3, sPowerOnHours.c_str()); - mvwaddstr(newWindow,u16Line++, 3, "---------------------------------------------------"); - } - else - { - mvwaddstr(newWindow,u16Line++, 3, sPowerOnHours.c_str()); - } - - if(drive.getPowerCycles() >= WORSE_POWERUP) - { - mvwaddstr(newWindow,u16Line++, 3, "------------> WARNING: POWER-ON <------------------"); - mvwaddstr(newWindow,u16Line++, 3, sPowerCycle.c_str()); - mvwaddstr(newWindow,u16Line++, 3, "---------------------------------------------------"); - } - else - { - mvwaddstr(newWindow,u16Line++, 3, sPowerCycle.c_str()); - } - - if(drive.getErrorCount() > 0) - { - mvwaddstr(newWindow,u16Line++, 3, "------------> WARNING: S.M.A.R.T ERROR <-----------"); - mvwaddstr(newWindow,u16Line++, 3, sErrorCount.c_str()); - mvwaddstr(newWindow,u16Line++, 3, "---------------------------------------------------"); - } - else - { - mvwaddstr(newWindow,u16Line++, 3, sErrorCount.c_str()); - } + mvwaddstr(newWindow,u16Line++, 3, sPowerOnHours.c_str()); + mvwaddstr(newWindow,u16Line++, 3, sPowerCycle.c_str()); + mvwaddstr(newWindow,u16Line++, 3, sErrorCount.c_str()); return newWindow; } @@ -355,7 +333,19 @@ WINDOW* TUI::createSystemStats(int iXSize, int iYSize, int iYStart) strftime(buffer,sizeof(buffer),"Date: %d-%m-%Y Time: %H:%M",timeinfo); string time(buffer); - mvwaddstr(newWindow,2, 2, time.c_str()); + string sLine01 = "reHDD - hard drive refurbishing tool"; + string sLine02 = "Version: " + string(REHDD_VERSION); + string sLine03 = "Available under GPL 3.0"; + string sLine04 = "https://git.mosad.xyz/localhorst/reHDD"; + + uint16_t u16Line = 2; + + mvwaddstr(newWindow,u16Line++, (iXSize/2)-(sLine01.size()/2), sLine01.c_str()); + mvwaddstr(newWindow,u16Line++, (iXSize/2)-(sLine01.size()/2), sLine02.c_str()); + mvwaddstr(newWindow,u16Line++, (iXSize/2)-(sLine01.size()/2), sLine03.c_str()); + mvwaddstr(newWindow,u16Line++, (iXSize/2)-(sLine01.size()/2), sLine04.c_str()); + u16Line++; + mvwaddstr(newWindow,u16Line++, (iXSize/2)-(sLine01.size()/2), time.c_str()); return newWindow; } @@ -399,9 +389,10 @@ WINDOW* TUI::createDialog(int iXSize, int iYSize, int iXStart, int iYStart, stri centerTitle(newWindow, task.c_str()); - uint16_t u16Line = 2; - mvwaddstr(newWindow,u16Line++, 3, optionA.c_str()); - mvwaddstr(newWindow,u16Line++, 3, optionB.c_str()); + uint16_t u16Line = 3; + mvwaddstr(newWindow,u16Line++, (iXSize/2)-(optionA.size()/2), optionA.c_str()); + u16Line++; + mvwaddstr(newWindow,u16Line++, (iXSize/2)-(optionB.size()/2), optionB.c_str()); return newWindow; } @@ -485,12 +476,12 @@ void TUI::displaySelectedDrive(Drive drive, int stdscrX, int stdscrY) if(menustate.bConfirmShred == true) { - dialog=createDialog(70, 10, ((stdscrX)-(int)(stdscrX/3)-7)-(int)((stdscrX/3)+5)/2,(int)(stdscrY/2)-5, "Confirm SHRED", "Press ENTER for SHRED", "Press ESC for cancel"); + dialog=createDialog(40, 10, ((stdscrX)-(int)(stdscrX/3)-7)-(int)((stdscrX/3)+5)/2,(int)(stdscrY/2)-5, "Confirm SHRED", "Press ENTER for SHRED", "Press ESC for cancel"); wrefresh(dialog); } else if(menustate.bConfirmDelete == true) { - dialog=createDialog(70, 10, ((stdscrX)-(int)(stdscrX/3)-7)-(int)((stdscrX/3)+5)/2,(int)(stdscrY/2)-5, "Confirm DELETE", "Press ENTER for DELETE", "Press ESC for cancel"); + dialog=createDialog(40, 10, ((stdscrX)-(int)(stdscrX/3)-7)-(int)((stdscrX/3)+5)/2,(int)(stdscrY/2)-5, "Confirm DELETE", "Press ENTER for DELETE", "Press ESC for cancel"); wrefresh(dialog); } else @@ -498,3 +489,42 @@ void TUI::displaySelectedDrive(Drive drive, int stdscrX, int stdscrY) delwin(dialog); } } + +WINDOW* TUI::createSmartWarning(int iXSize, int iYSize, int iXStart, int iYStart, string sPath, uint32_t u32PowerOnHours, uint32_t u32PowerCycles, uint32_t u32ErrorCount) +{ + WINDOW *newWindow; + newWindow = newwin(iYSize, iXSize, iYStart, iXStart); + + wbkgd(newWindow, COLOR_PAIR(COLOR_AREA_ENTRY_SELECTED)); + box(newWindow, ACS_VLINE, ACS_HLINE); + + string sHeader = "Drive " + sPath + " is suspicious"; + string sLine01 = "Please evaluate this drive carefully."; + + centerTitle(newWindow, sHeader.c_str()); + + uint16_t u16Line = 2; + mvwaddstr(newWindow,u16Line++, (iXSize/2)-(sLine01.size()/2), sLine01.c_str()); + u16Line++; + + if(u32PowerOnHours > WORSE_HOURS) + { + string sLineTmp = "Operating hours exceeded " + to_string(WORSE_HOURS) + " hours: " + to_string(u32PowerOnHours); + mvwaddstr(newWindow,u16Line++, (iXSize/2)-(sLine01.size()/2), sLineTmp.c_str()); + u16Line++; + } + + if(u32PowerCycles > WORSE_POWERUP) + { + string sLineTmp = "Power-on exceeded " + to_string(WORSE_POWERUP) + " cycles: " + to_string(u32PowerCycles); + mvwaddstr(newWindow,u16Line++, (iXSize/2)-(sLine01.size()/2), sLineTmp.c_str()); + u16Line++; + } + + if(u32ErrorCount > 0) + { + string sLineTmp = "S.M.A.R.T. erros detected: " + to_string(u32ErrorCount); + mvwaddstr(newWindow,u16Line++, (iXSize/2)-(sLine01.size()/2), sLineTmp.c_str()); + } + return newWindow; +} \ No newline at end of file -- 2.47.1 From 13304c4705cc26f139239ee2ab0426d8c543c885 Mon Sep 17 00:00:00 2001 From: localhorst Date: Mon, 21 Sep 2020 16:11:31 +0200 Subject: [PATCH 5/7] update ui layout --- include/tui.h | 2 +- src/tui.cpp | 22 +++++++++++++--------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/include/tui.h b/include/tui.h index 5d073ae..d65e6a4 100644 --- a/include/tui.h +++ b/include/tui.h @@ -57,7 +57,7 @@ private: static WINDOW *createDetailViewWindow( int iXSize, int iYSize, int iXStart, Drive drive); static WINDOW *overwriteDetailViewWindow( int iXSize, int iYSize, int iXStart); static WINDOW *createEntryWindow(int iXSize, int iYSize, int iXStart, int iYStart, string sModelFamily, string sModelName, string sCapacity, string sState, bool bSelected); - static WINDOW *createSystemStats(int iXSize, int iYSize, int iYStart); + static WINDOW *createSystemStats(int iXSize, int iYSize, int iXStart, 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); static WINDOW* createFrozenWarning(int iXSize, int iYSize, int iXStart, int iYStart, string sPath, string sModelFamily, string sModelName, string sSerial, string sProgress); diff --git a/src/tui.cpp b/src/tui.cpp index 688299c..8244961 100644 --- a/src/tui.cpp +++ b/src/tui.cpp @@ -61,10 +61,10 @@ void TUI::updateTUI(vector * pvecDrives, uint8_t u8SelectedEntry) refresh(); - overview=createOverViewWindow((int)(u16StdscrX/3), (u16StdscrY-15)); + overview=createOverViewWindow((int)(u16StdscrX/3), (u16StdscrY-3)); wrefresh(overview); - systemview=createSystemStats((int)(u16StdscrX/3), 10, (u16StdscrY-11)); + systemview=createSystemStats((int)(u16StdscrX/3), 10, u16StdscrX-(int)(u16StdscrX/3)-2, (u16StdscrY-11 )); wrefresh(systemview); delwin(detailview); @@ -315,10 +315,10 @@ WINDOW* TUI::createEntryWindow(int iXSize, int iYSize, int iXStart, int iYStart, return newWindow; } -WINDOW* TUI::createSystemStats(int iXSize, int iYSize, int iYStart) +WINDOW* TUI::createSystemStats(int iXSize, int iYSize, int iXStart, int iYStart) { WINDOW *newWindow; - newWindow = newwin(iYSize, iXSize, iYStart, 2); + newWindow = newwin(iYSize, iXSize, iYStart, iXStart); wbkgd(newWindow, COLOR_PAIR(COLOR_AREA_OVERVIEW)); box(newWindow, ACS_VLINE, ACS_HLINE); @@ -360,20 +360,24 @@ WINDOW* TUI::createMenuView(int iXSize, int iYSize, int iXStart, int iYStart, st centerTitle(newWindow, "Controls"); - uint16_t u16Line = 2; if(menustate.bAbort) { - mvwaddstr(newWindow,u16Line++, 3, "Press A for Abort"); + string sLineTmp = "Press A for Abort"; + mvwaddstr(newWindow,u16Line++, (iXSize/2)-(sLineTmp.size()/2), sLineTmp.c_str()); + u16Line++; } if(menustate.bShred) { - mvwaddstr(newWindow,u16Line++, 3, "Press S for Shred"); + string sLineTmp = "Press S for Shred "; + mvwaddstr(newWindow,u16Line++, (iXSize/2)-(sLineTmp.size()/2), sLineTmp.c_str()); + u16Line++; } if(menustate.bDelete) { - mvwaddstr(newWindow,u16Line++, 3, "Press D for Delete"); + string sLineTmp = "Press D for Delete"; + mvwaddstr(newWindow,u16Line++, (iXSize/2)-(sLineTmp.size()/2), sLineTmp.c_str()); } return newWindow; @@ -471,7 +475,7 @@ void TUI::displaySelectedDrive(Drive drive, int stdscrX, int stdscrY) detailview=createDetailViewWindow(((stdscrX)-(int)(stdscrX/3)-7), (stdscrY-15), (int)(stdscrX/3)+5, drive); wrefresh(detailview); - menuview=createMenuView(((stdscrX)-(int)(stdscrX/3)-7), 10, (int)(stdscrX/3)+5,(stdscrY-11), menustate); + menuview=createMenuView(((int)(stdscrX/3)-10 ), 10, (int)(stdscrX/3)+5,(stdscrY-11), menustate); wrefresh(menuview); if(menustate.bConfirmShred == true) -- 2.47.1 From 2a2bfc6fe6d1742d54b66312bbe94a52fcfa7d22 Mon Sep 17 00:00:00 2001 From: localhorst Date: Mon, 21 Sep 2020 16:50:33 +0200 Subject: [PATCH 6/7] delete task thread --- include/reHDD.h | 1 + src/reHDD.cpp | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/include/reHDD.h b/include/reHDD.h index 5bb3344..7432005 100644 --- a/include/reHDD.h +++ b/include/reHDD.h @@ -89,6 +89,7 @@ private: static void ThreadScannDevices(); static void ThreadUserInput(); static void ThreadShred(); + static void ThreadDelete(); static void ThreadCheckFrozenDrives(); static void handleArrowKey(TUI::UserInput userInput); static void handleEnter(); diff --git a/src/reHDD.cpp b/src/reHDD.cpp index 8405708..8e1bd06 100644 --- a/src/reHDD.cpp +++ b/src/reHDD.cpp @@ -207,6 +207,18 @@ void reHDD::ThreadShred() } } +void reHDD::ThreadDelete() +{ + if (getSelectedDrive() != nullptr) + { + Delete::deleteDrive(getSelectedDrive()); //blocking, no thread + getSelectedDrive()->state = Drive::TaskState::NONE; //delete finished + getSelectedDrive()->bWasDeleteted = true; + Logger::logThis()->info("Finished delete for: " + getSelectedDrive()->getModelName() + "-" + getSelectedDrive()->getSerial()); + ui->updateTUI(&vecDrives, u8SelectedEntry); + } +} + void reHDD::filterNewDrives(vector * pvecOldDrives, vector * pvecNewDrives) { vector ::iterator itOld; //Iterator for current (old) drive list @@ -486,10 +498,7 @@ void reHDD::handleEnter() Logger::logThis()->info("Started delete for: " + getSelectedDrive()->getModelName() + "-" + getSelectedDrive()->getSerial()); getSelectedDrive()->state = Drive::TaskState::DELETE_ACTIVE; //task for drive is running --> don´t show more task options - Delete::deleteDrive(getSelectedDrive()); //blocking, no thread - getSelectedDrive()->state = Drive::TaskState::NONE; //delete finished - getSelectedDrive()->bWasDeleteted = true; - Logger::logThis()->info("Finished delete for: " + getSelectedDrive()->getModelName() + "-" + getSelectedDrive()->getSerial()); + thread(ThreadDelete).detach(); } } } -- 2.47.1 From e65af04488f26ccb6fc7b3b2d62fb48ddbc33a60 Mon Sep 17 00:00:00 2001 From: localhorst Date: Mon, 21 Sep 2020 21:47:29 +0200 Subject: [PATCH 7/7] changed vector to list; again --- include/reHDD.h | 12 +++--- include/tui.h | 2 +- src/reHDD.cpp | 107 ++++++++++++++++++++++++------------------------ src/tui.cpp | 18 ++++---- 4 files changed, 71 insertions(+), 68 deletions(-) diff --git a/include/reHDD.h b/include/reHDD.h index 7432005..35024e8 100644 --- a/include/reHDD.h +++ b/include/reHDD.h @@ -41,7 +41,7 @@ #include #include #include -#include +#include #include #include #include @@ -81,11 +81,11 @@ public: private: - static void searchDrives(vector * pvecDrives); - static void printDrives(vector * pvecDrives); - static void filterIgnoredDrives(vector * pvecDrives); - static void filterNewDrives(vector * pvecOldDrives, vector * pvecNewDrives); - static void addSMARTData(vector * pvecDrives); + static void searchDrives(list * plistDrives); + static void printDrives(list * plistDrives); + static void filterIgnoredDrives(list * plistDrives); + static void filterNewDrives(list * plistOldDrives, list * plistNewDrives); + static void addSMARTData(list * plistDrives); static void ThreadScannDevices(); static void ThreadUserInput(); static void ThreadShred(); diff --git a/include/tui.h b/include/tui.h index d65e6a4..8eb9038 100644 --- a/include/tui.h +++ b/include/tui.h @@ -36,7 +36,7 @@ public: static void initTUI(); - void updateTUI(vector * pvecDrives, uint8_t u8SelectedEntry); + void updateTUI(list * plistDrives, uint8_t u8SelectedEntry); static enum UserInput readUserInput(); diff --git a/src/reHDD.cpp b/src/reHDD.cpp index 8e1bd06..2489dd2 100644 --- a/src/reHDD.cpp +++ b/src/reHDD.cpp @@ -13,9 +13,9 @@ static int fdShredInformPipe[2];//File descriptor for pipe that informs if a wip static std::mutex mxScannDrives; -vector vecNewDrives; //store found drives that are updated every 5sec +list listNewDrives; //store found drives that are updated every 5sec -static vector vecDrives; //stores all drive data from scann thread +static list listDrives; //stores all drive data from scann thread TUI *ui; @@ -31,8 +31,6 @@ static fd_set selectSet; reHDD::reHDD(void) { u8SelectedEntry = 0U; - - vecDrives.reserve(128); } /** @@ -65,8 +63,8 @@ void reHDD::app_logic(void) mxScannDrives.lock(); char dummy; read (fdNewDrivesInformPipe[0],&dummy,1); - filterNewDrives(&vecDrives, &vecNewDrives); //filter and copy to app logic vector - printDrives(&vecDrives); + filterNewDrives(&listDrives, &listNewDrives); //filter and copy to app logic vector + printDrives(&listDrives); mxScannDrives.unlock(); } if(FD_ISSET(fdShredInformPipe[0], &selectSet)) @@ -78,7 +76,7 @@ void reHDD::app_logic(void) #endif } //mxScannDrives.lock(); - ui->updateTUI(&vecDrives, u8SelectedEntry); + ui->updateTUI(&listDrives, u8SelectedEntry); //mxScannDrives.unlock(); } //endless loop thDevices.join(); @@ -88,9 +86,11 @@ void reHDD::app_logic(void) Drive* reHDD::getSelectedDrive() { - if(u8SelectedEntry < vecDrives.size() ) + if(u8SelectedEntry < listDrives.size() ) { - return &(vecDrives.at(u8SelectedEntry)); + list::iterator it = listDrives.begin(); + advance(it, u8SelectedEntry); + return &(*it); } else { @@ -104,10 +104,10 @@ void reHDD::ThreadScannDevices() while(true) { mxScannDrives.lock(); - vecNewDrives.clear(); - searchDrives(&vecNewDrives); //search for new drives and store them in list - filterIgnoredDrives(&vecNewDrives); //filter out ignored drives - addSMARTData(&vecNewDrives); //add S.M.A.R.T. Data to the drives + listNewDrives.clear(); + searchDrives(&listNewDrives); //search for new drives and store them in list + filterIgnoredDrives(&listNewDrives); //filter out ignored drives + addSMARTData(&listNewDrives); //add S.M.A.R.T. Data to the drives mxScannDrives.unlock(); write(fdNewDrivesInformPipe[1], "A",1); sleep(5); //sleep 5 sec @@ -119,7 +119,7 @@ void reHDD::ThreadCheckFrozenDrives() while(true) { mxScannDrives.lock(); - for(auto it = begin(vecDrives); it != end(vecDrives); ++it) + for(auto it = begin(listDrives); it != end(listDrives); ++it) { if(it->state == Drive::SHRED_ACTIVE) { @@ -141,12 +141,12 @@ void reHDD::ThreadUserInput() case TUI::UserInput::DownKey: //cout << "Down" << endl; handleArrowKey(TUI::UserInput::DownKey); - ui->updateTUI(&vecDrives, u8SelectedEntry); + ui->updateTUI(&listDrives, u8SelectedEntry); break; case TUI::UserInput::UpKey: //cout << "Up" << endl; handleArrowKey(TUI::UserInput::UpKey); - ui->updateTUI(&vecDrives, u8SelectedEntry); + ui->updateTUI(&listDrives, u8SelectedEntry); break; case TUI::UserInput::Undefined: //cout << "Undefined" << endl; @@ -154,7 +154,7 @@ void reHDD::ThreadUserInput() case TUI::UserInput::Abort: //cout << "Abort" << endl; handleAbort(); - ui->updateTUI(&vecDrives, u8SelectedEntry); + ui->updateTUI(&listDrives, u8SelectedEntry); break; case TUI::UserInput::Delete: //cout << "Delete" << endl; @@ -166,7 +166,7 @@ void reHDD::ThreadUserInput() getSelectedDrive()->state = Drive::DELETE_SELECTED; } } - ui->updateTUI(&vecDrives, u8SelectedEntry); + ui->updateTUI(&listDrives, u8SelectedEntry); break; case TUI::UserInput::Shred: //cout << "Shred" << endl; @@ -178,17 +178,17 @@ void reHDD::ThreadUserInput() getSelectedDrive()->state = Drive::SHRED_SELECTED; } } - ui->updateTUI(&vecDrives, u8SelectedEntry); + ui->updateTUI(&listDrives, u8SelectedEntry); break; case TUI::UserInput::Enter: //cout << "Enter" << endl; handleEnter(); - ui->updateTUI(&vecDrives, u8SelectedEntry); + ui->updateTUI(&listDrives, u8SelectedEntry); break; case TUI::UserInput::ESC: //cout << "ESC" << endl; handleESC(); - ui->updateTUI(&vecDrives, u8SelectedEntry); + ui->updateTUI(&listDrives, u8SelectedEntry); break; default: break; @@ -203,7 +203,7 @@ void reHDD::ThreadShred() Shred* pShredTask = new Shred(); //create new shred task pShredTask->shredDrive(getSelectedDrive(), &fdShredInformPipe[1]); //start new shred task delete pShredTask; //delete shred task - ui->updateTUI(&vecDrives, u8SelectedEntry); + ui->updateTUI(&listDrives, u8SelectedEntry);; } } @@ -215,24 +215,24 @@ void reHDD::ThreadDelete() getSelectedDrive()->state = Drive::TaskState::NONE; //delete finished getSelectedDrive()->bWasDeleteted = true; Logger::logThis()->info("Finished delete for: " + getSelectedDrive()->getModelName() + "-" + getSelectedDrive()->getSerial()); - ui->updateTUI(&vecDrives, u8SelectedEntry); + ui->updateTUI(&listDrives, u8SelectedEntry); } } -void reHDD::filterNewDrives(vector * pvecOldDrives, vector * pvecNewDrives) +void reHDD::filterNewDrives(list * plistOldDrives, list * plistNewDrives) { - vector ::iterator itOld; //Iterator for current (old) drive list - vector ::iterator itNew; //Iterator for new drive list that was created from to scann thread + list ::iterator itOld; //Iterator for current (old) drive list + list ::iterator itNew; //Iterator for new drive list that was created from to scann thread //remove offline old drives from previously run - for (itOld = pvecOldDrives->begin(); itOld != pvecOldDrives->end();) + for (itOld = plistOldDrives->begin(); itOld != plistOldDrives->end();) { if(itOld->bIsOffline == true) { Logger::logThis()->warning("Offline drive found: " + itOld->getPath()); - itOld = pvecOldDrives->erase(itOld); + itOld = plistOldDrives->erase(itOld); /* - if(pvecOldDrives->size() > 0){ //This can be a risk if the user starts a task for the selected drive and the selected drive changes + if(plistOldDrives->size() > 0){ //This can be a risk if the user starts a task for the selected drive and the selected drive changes u8SelectedEntry = 0U; } */ @@ -244,10 +244,10 @@ void reHDD::filterNewDrives(vector * pvecOldDrives, vector * pvecN } //search offline drives and mark them - for (itOld = pvecOldDrives->begin(); itOld != pvecOldDrives->end(); ++itOld) + for (itOld = plistOldDrives->begin(); itOld != plistOldDrives->end(); ++itOld) { itOld->bIsOffline = true; //set offline befor seachring in the new list - for (itNew = pvecNewDrives->begin(); itNew != pvecNewDrives->end();) + for (itNew = plistNewDrives->begin(); itNew != plistNewDrives->end();) { if((itOld->getSerial() == itNew->getSerial()) || (itOld->getPath() == itNew->getPath())) { @@ -255,7 +255,7 @@ void reHDD::filterNewDrives(vector * pvecOldDrives, vector * pvecN #ifdef LOG_LEVEL_HIGH Logger::logThis()->info("Delete new drive, because allready attached: " + itNew->getModelName()); #endif - itNew = pvecNewDrives->erase(itNew); //This drive is allready attached, remove from new list + itNew = plistNewDrives->erase(itNew); //This drive is allready attached, remove from new list } else { @@ -265,7 +265,7 @@ void reHDD::filterNewDrives(vector * pvecOldDrives, vector * pvecN } //mark offline old drives - for (itOld = pvecOldDrives->begin(); itOld != pvecOldDrives->end(); ++itOld) + for (itOld = plistOldDrives->begin(); itOld != plistOldDrives->end(); ++itOld) { if(itOld->bIsOffline == true) { @@ -276,12 +276,12 @@ void reHDD::filterNewDrives(vector * pvecOldDrives, vector * pvecN } //add new drives to drive list - for (itNew = pvecNewDrives->begin(); itNew != pvecNewDrives->end(); ++itNew) + for (itNew = plistNewDrives->begin(); itNew != plistNewDrives->end(); ++itNew) { - pvecOldDrives->push_back(pvecNewDrives->at(itNew - pvecNewDrives->begin())); + plistOldDrives->push_back(*itNew); Logger::logThis()->info("Add new drive: " + itNew->getModelName()); } - pvecNewDrives->clear(); + plistNewDrives->clear(); } /** @@ -289,7 +289,7 @@ void reHDD::filterNewDrives(vector * pvecOldDrives, vector * pvecN * \param pointer of vector * pvecDrives * \return void */ -void reHDD::searchDrives(vector * pvecDrives) +void reHDD::searchDrives(list * plistDrives) { // cout << "search drives ..." << endl; Logger::logThis()->info("--> search drives <--"); @@ -311,7 +311,7 @@ void reHDD::searchDrives(vector * pvecDrives) Drive* tmpDrive = new Drive(string(cLine).substr(0, 8)); tmpDrive->state = Drive::NONE; tmpDrive->bIsOffline = false; - pvecDrives->push_back(*tmpDrive); + plistDrives->push_back(*tmpDrive); } } fclose(outputfileHwinfo); @@ -322,13 +322,13 @@ void reHDD::searchDrives(vector * pvecDrives) * \param pointer of vector * pvecDrives * \return void */ -void reHDD::filterIgnoredDrives(vector * pvecDrives) +void reHDD::filterIgnoredDrives(list * plistDrives) { string sDelimiter = ":"; string sIgnoredDrivePath; string sIgnoredDriveUUID; - vector> vtlIgnoredDevices; //store drives from ingnore file + list> vtlIgnoredDevices; //store drives from ingnore file ifstream input( "ignoreDrives.conf" ); //read ingnore file @@ -351,8 +351,8 @@ void reHDD::filterIgnoredDrives(vector * pvecDrives) //loop through found entries in ingnore file for(auto row : vtlIgnoredDevices) { - vector ::iterator it; - for (it = pvecDrives->begin(); it != pvecDrives->end(); ++it) + list ::iterator it; + for (it = plistDrives->begin(); it != plistDrives->end(); ++it) { string sUUID; if (!get<0>(row).compare(it->getPath())) //find same drive based on path @@ -394,7 +394,7 @@ void reHDD::filterIgnoredDrives(vector * pvecDrives) #ifdef LOG_LEVEL_HIGH Logger::logThis()->info("same uuid found than in ignore file --> ignore this drive: " + it->getPath()); #endif - it = pvecDrives->erase(it); + it = plistDrives->erase(it); it--; } } @@ -407,13 +407,14 @@ void reHDD::filterIgnoredDrives(vector * pvecDrives) * \param pointer of vector * pvecDrives * \return void */ -void reHDD::printDrives(vector * pvecDrives) +void reHDD::printDrives(list * plistDrives) { #ifdef LOG_LEVEL_HIGH Logger::logThis()->info("------------DRIVES START------------"); //cout << "------------DRIVES---------------" << endl; - vector ::iterator it; - for (it = pvecDrives->begin(); it != pvecDrives->end(); ++it) + list ::iterator it; + uint8_t u8Index = 0; + for (it = plistDrives->begin(); it != plistDrives->end(); ++it) { /* cout << " Drive: " << distance(pvecDrives->begin(), it) << endl; @@ -428,8 +429,8 @@ void reHDD::printDrives(vector * pvecDrives) cout << endl;*/ ostringstream address; - address << (void const *)&pvecDrives->at(it - pvecDrives->begin()); - Logger::logThis()->info(to_string(it - pvecDrives->begin()) + ": " + it->getPath() + " - " + it->getModelFamily() + " - " + it->getSerial() + " @" + address.str()); + address << (void const *)&(*it); + Logger::logThis()->info(to_string(u8Index++) + ": " + it->getPath() + " - " + it->getModelFamily() + " - " + it->getSerial() + " @" + address.str()); } Logger::logThis()->info("------------DRIVES END--------------"); //cout << "---------------------------------" << endl; @@ -441,19 +442,19 @@ void reHDD::printDrives(vector * pvecDrives) * \param pointer of vector * pvecDrives * \return void */ -void reHDD::addSMARTData(vector * pvecDrives) +void reHDD::addSMARTData(list * plistDrives) { - vector ::iterator it; - for (it = pvecDrives->begin(); it != pvecDrives->end(); ++it) + list ::iterator it; + for (it = plistDrives->begin(); it != plistDrives->end(); ++it) { - Drive* pTmpDrive = iterator_to_pointer::iterator > (it); + Drive* pTmpDrive = iterator_to_pointer::iterator > (it); SMART::readSMARTData(pTmpDrive); } } void reHDD::handleArrowKey(TUI::UserInput userInput) { - int8_t u8EntrySize = (int8_t) vecDrives.size(); + int8_t u8EntrySize = (int8_t) listDrives.size(); switch (userInput) { case TUI::UserInput::DownKey: diff --git a/src/tui.cpp b/src/tui.cpp index 8244961..d171801 100644 --- a/src/tui.cpp +++ b/src/tui.cpp @@ -50,7 +50,7 @@ void TUI::initTUI() Logger::logThis()->info("UI successfully initialized"); } -void TUI::updateTUI(vector * pvecDrives, uint8_t u8SelectedEntry) +void TUI::updateTUI(list * plistDrives, uint8_t u8SelectedEntry) { mxUIrefresh.lock(); uint16_t u16StdscrX, u16StdscrY; @@ -69,8 +69,9 @@ void TUI::updateTUI(vector * pvecDrives, uint8_t u8SelectedEntry) delwin(detailview); - vector ::iterator it; - for (it = pvecDrives->begin(); it != pvecDrives->end(); ++it) + list ::iterator it; + uint8_t u8Index = 0U; + for (it = plistDrives->begin(); it != plistDrives->end(); ++it) { string sModelFamily = it->getModelFamily(); string sModelName = it->getModelName(); @@ -79,10 +80,10 @@ void TUI::updateTUI(vector * pvecDrives, uint8_t u8SelectedEntry) bool bSelectedEntry = false; - if(u8SelectedEntry == (it - pvecDrives->begin())) + if(u8SelectedEntry == u8Index) { bSelectedEntry = true; //mark this drive in entries list - displaySelectedDrive(pvecDrives->at(u8SelectedEntry), u16StdscrX, u16StdscrY); + displaySelectedDrive(*it, u16StdscrX, u16StdscrY); if((it->getPowerOnHours() >= WORSE_HOURS) || (it->getPowerCycles() >= WORSE_POWERUP) || (it->getErrorCount() > 0)) { @@ -133,11 +134,12 @@ void TUI::updateTUI(vector * pvecDrives, uint8_t u8SelectedEntry) break; } - WINDOW * tmp = createEntryWindow( ((int)(u16StdscrX/3) - 2), 5, 3, (5* (it - pvecDrives->begin()) )+3, sModelFamily, sModelName, sCapacity, sState, bSelectedEntry); + WINDOW * tmp = createEntryWindow( ((int)(u16StdscrX/3) - 2), 5, 3, (5* (u8Index) )+3, sModelFamily, sModelName, sCapacity, sState, bSelectedEntry); wrefresh(tmp); + u8Index++; }//end loop though drives - if(pvecDrives->size() == 0) + if(plistDrives->size() == 0) { //no selected drive present Logger::logThis()->warning("no selected drive present"); @@ -148,7 +150,7 @@ void TUI::updateTUI(vector * pvecDrives, uint8_t u8SelectedEntry) menustate.bDelete = false; menustate.bShred = false; - menuview=createMenuView(((u16StdscrX)-(int)(u16StdscrX/3)-7), 10, (int)(u16StdscrX/3)+5,(u16StdscrY-11), menustate); + menuview=createMenuView(((int)(u16StdscrX/3)-10 ), 10, (int)(u16StdscrX/3)+5,(u16StdscrY-11), menustate); wrefresh(menuview); detailview=overwriteDetailViewWindow(((u16StdscrX)-(int)(u16StdscrX/3)-7), (u16StdscrY-15), (int)(u16StdscrX/3)+5); -- 2.47.1