fixed states if drive is no longer present

This commit is contained in:
Hendrik Schutter 2020-08-26 18:38:39 +02:00
parent 424218bb23
commit 320e306d06
6 changed files with 145 additions and 56 deletions

View File

@ -15,7 +15,9 @@
#define SHRED_ITERATIONS 1 #define SHRED_ITERATIONS 1
#define SELECTED_DRIVE vecDrives.at(i32SelectedEntry)
#define READ 0 #define READ 0
#define WRITE 1 #define WRITE 1
@ -75,7 +77,7 @@ private:
static void handleESC(); static void handleESC();
static void handleAbort(); static void handleAbort();
static void checkShredComplete(vector <Drive>* pvecDrives); static void checkShredComplete(vector <Drive>* pvecDrives);
static Drive* getSelectedDrive();
}; };

View File

@ -36,7 +36,7 @@ public:
static void initTUI(); static void initTUI();
void updateTUI(vector <Drive>* pvecDrives, int32_t i32SelectedEntry); void updateTUI(vector <Drive>* pvecDrives, uint8_t u8SelectedEntry);
static enum UserInput readUserInput(); static enum UserInput readUserInput();
@ -55,6 +55,7 @@ private:
static void centerTitle(WINDOW *pwin, const char * title); static void centerTitle(WINDOW *pwin, const char * title);
static WINDOW *createOverViewWindow( int iXSize, int iYSize); static WINDOW *createOverViewWindow( int iXSize, int iYSize);
static WINDOW *createDetailViewWindow( int iXSize, int iYSize, int iXStart, Drive drive); 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 *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 iYStart);
static WINDOW *createMenuView(int iXSize, int iYSize, int iXStart, int iYStart, struct MenuState menustate); static WINDOW *createMenuView(int iXSize, int iYSize, int iXStart, int iYStart, struct MenuState menustate);

View File

@ -10,7 +10,7 @@ SRC_PATH = src
# Space-separated pkg-config libraries used by this project # Space-separated pkg-config libraries used by this project
LIBS = LIBS =
# General compiler flags # General compiler flags
COMPILE_FLAGS = -std=c++11 -Wall -Wextra -g COMPILE_FLAGS = -std=c++17 -Wall -Wextra -g
# Additional release-specific flags # Additional release-specific flags
RCOMPILE_FLAGS = -D NDEBUG RCOMPILE_FLAGS = -D NDEBUG
# Additional debug-specific flags # Additional debug-specific flags

View File

@ -19,7 +19,7 @@ static vector <Drive> vecDrives; //stores all drive data from scann thread
TUI *ui; TUI *ui;
static int32_t i32SelectedEntry; static uint8_t u8SelectedEntry;
static fd_set selectSet; static fd_set selectSet;
@ -33,7 +33,7 @@ static fd_set selectSet;
reHDD::reHDD(void) reHDD::reHDD(void)
{ {
cout << "created app" << endl; cout << "created app" << endl;
i32SelectedEntry = 0; u8SelectedEntry = 0U;
} }
/** /**
@ -78,14 +78,24 @@ void reHDD::app_logic(void)
checkShredComplete(&vecDrives); checkShredComplete(&vecDrives);
} }
ui->updateTUI(&vecDrives, u8SelectedEntry);
ui->updateTUI(&vecDrives, i32SelectedEntry);
} //endless loop } //endless loop
thDevices.join(); thDevices.join();
thUserInput.join(); thUserInput.join();
} }
Drive* reHDD::getSelectedDrive()
{
if(u8SelectedEntry < vecDrives.size() )
{
return &(vecDrives.at(u8SelectedEntry));
}
else
{
return {};
}
}
void reHDD::ThreadScannDevices() void reHDD::ThreadScannDevices()
{ {
while(true) while(true)
@ -112,12 +122,12 @@ void reHDD::ThreadUserInput()
case TUI::UserInput::DownKey: case TUI::UserInput::DownKey:
//cout << "Down" << endl; //cout << "Down" << endl;
handleArrowKey(TUI::UserInput::DownKey); handleArrowKey(TUI::UserInput::DownKey);
ui->updateTUI(&vecDrives, i32SelectedEntry); ui->updateTUI(&vecDrives, u8SelectedEntry);
break; break;
case TUI::UserInput::UpKey: case TUI::UserInput::UpKey:
//cout << "Up" << endl; //cout << "Up" << endl;
handleArrowKey(TUI::UserInput::UpKey); handleArrowKey(TUI::UserInput::UpKey);
ui->updateTUI(&vecDrives, i32SelectedEntry); ui->updateTUI(&vecDrives, u8SelectedEntry);
break; break;
case TUI::UserInput::Undefined: case TUI::UserInput::Undefined:
//cout << "Undefined" << endl; //cout << "Undefined" << endl;
@ -125,33 +135,41 @@ void reHDD::ThreadUserInput()
case TUI::UserInput::Abort: case TUI::UserInput::Abort:
//cout << "Abort" << endl; //cout << "Abort" << endl;
handleAbort(); handleAbort();
ui->updateTUI(&vecDrives, i32SelectedEntry); ui->updateTUI(&vecDrives, u8SelectedEntry);
break; break;
case TUI::UserInput::Delete: case TUI::UserInput::Delete:
//cout << "Delete" << endl; //cout << "Delete" << endl;
if(SELECTED_DRIVE.state == Drive::NONE)
if (getSelectedDrive() != nullptr)
{ {
SELECTED_DRIVE.state = Drive::DELETE_SELECTED; if(getSelectedDrive()->state == Drive::NONE)
{
getSelectedDrive()->state = Drive::DELETE_SELECTED;
}
} }
ui->updateTUI(&vecDrives, i32SelectedEntry); ui->updateTUI(&vecDrives, u8SelectedEntry);
break; break;
case TUI::UserInput::Shred: case TUI::UserInput::Shred:
//cout << "Shred" << endl; //cout << "Shred" << endl;
if(SELECTED_DRIVE.state == Drive::NONE)
if (getSelectedDrive() != nullptr)
{ {
SELECTED_DRIVE.state = Drive::SHRED_SELECTED; if(getSelectedDrive()->state == Drive::NONE)
{
getSelectedDrive()->state = Drive::SHRED_SELECTED;
}
} }
ui->updateTUI(&vecDrives, i32SelectedEntry); ui->updateTUI(&vecDrives, u8SelectedEntry);
break; break;
case TUI::UserInput::Enter: case TUI::UserInput::Enter:
//cout << "Enter" << endl; //cout << "Enter" << endl;
handleEnter(); handleEnter();
ui->updateTUI(&vecDrives, i32SelectedEntry); ui->updateTUI(&vecDrives, u8SelectedEntry);
break; break;
case TUI::UserInput::ESC: case TUI::UserInput::ESC:
//cout << "ESC" << endl; //cout << "ESC" << endl;
handleESC(); handleESC();
ui->updateTUI(&vecDrives, i32SelectedEntry); ui->updateTUI(&vecDrives, u8SelectedEntry);
break; break;
default: default:
break; break;
@ -161,7 +179,10 @@ void reHDD::ThreadUserInput()
void reHDD::ThreadShred() void reHDD::ThreadShred()
{ {
Shred::shredDrive(&SELECTED_DRIVE, &fdShredInformPipe[1]); if (getSelectedDrive() != nullptr)
{
Shred::shredDrive(getSelectedDrive(), &fdShredInformPipe[1]);
}
} }
void reHDD::filterNewDrives(vector <Drive>* pvecOldDrives, vector <Drive>* pvecNewDrives) void reHDD::filterNewDrives(vector <Drive>* pvecOldDrives, vector <Drive>* pvecNewDrives)
@ -358,69 +379,81 @@ void reHDD::addSMARTData(vector <Drive>* pvecDrives)
void reHDD::handleArrowKey(TUI::UserInput userInput) void reHDD::handleArrowKey(TUI::UserInput userInput)
{ {
int32_t i32EntrySize = (int32_t) vecDrives.size(); int8_t u8EntrySize = (int8_t) vecDrives.size();
switch (userInput) switch (userInput)
{ {
case TUI::UserInput::DownKey: case TUI::UserInput::DownKey:
i32SelectedEntry++; u8SelectedEntry++;
if(i32SelectedEntry >= i32EntrySize) if(u8SelectedEntry >= u8EntrySize)
{ {
i32SelectedEntry = 0; u8SelectedEntry = 0;
} }
break; break;
case TUI::UserInput::UpKey: case TUI::UserInput::UpKey:
i32SelectedEntry--; if(u8SelectedEntry == 0)
if(i32SelectedEntry < 0)
{ {
i32SelectedEntry = (i32EntrySize-1); u8SelectedEntry = (u8EntrySize-1);
}
else
{
u8SelectedEntry--;
} }
break; break;
default: default:
i32SelectedEntry = 0; u8SelectedEntry = 0;
break; break;
} }
} }
void reHDD::handleEnter() void reHDD::handleEnter()
{ {
if(SELECTED_DRIVE.state == Drive::TaskState::SHRED_SELECTED) if (getSelectedDrive() != nullptr)
{ {
SELECTED_DRIVE.state = Drive::TaskState::SHRED_ACTIVE; if(getSelectedDrive()->state == Drive::TaskState::SHRED_SELECTED)
//task for drive is running --> don´t show more task options {
thread(ThreadShred).detach(); getSelectedDrive()->state = Drive::TaskState::SHRED_ACTIVE;
} //task for drive is running --> don´t show more task options
thread(ThreadShred).detach();
}
if(SELECTED_DRIVE.state == Drive::TaskState::DELETE_SELECTED) if(getSelectedDrive()->state == Drive::TaskState::DELETE_SELECTED)
{ {
SELECTED_DRIVE.state = Drive::TaskState::DELETE_ACTIVE; getSelectedDrive()->state = Drive::TaskState::DELETE_ACTIVE;
//task for drive is running --> don´t show more task options //task for drive is running --> don´t show more task options
Delete::deleteDrive(&SELECTED_DRIVE); //blocking, no thread Delete::deleteDrive(getSelectedDrive()); //blocking, no thread
SELECTED_DRIVE.state = Drive::TaskState::NONE; //delete finished getSelectedDrive()->state = Drive::TaskState::NONE; //delete finished
SELECTED_DRIVE.bWasDeleteted = true; getSelectedDrive()->bWasDeleteted = true;
}
} }
} }
void reHDD::handleESC() void reHDD::handleESC()
{ {
if(SELECTED_DRIVE.state == Drive::TaskState::SHRED_SELECTED) if (getSelectedDrive() != nullptr)
{ {
SELECTED_DRIVE.state = Drive::TaskState::NONE; if(getSelectedDrive()->state == Drive::TaskState::SHRED_SELECTED)
//task for drive is selected --> remove selection {
} getSelectedDrive()->state = Drive::TaskState::NONE;
//task for drive is selected --> remove selection
}
if(SELECTED_DRIVE.state == Drive::TaskState::DELETE_SELECTED) if(getSelectedDrive()->state == Drive::TaskState::DELETE_SELECTED)
{ {
SELECTED_DRIVE.state = Drive::TaskState::NONE; getSelectedDrive()->state = Drive::TaskState::NONE;
//task for drive is selected --> remove selection //task for drive is selected --> remove selection
}
} }
} }
void reHDD::handleAbort() void reHDD::handleAbort()
{ {
if(SELECTED_DRIVE.state == Drive::SHRED_ACTIVE || SELECTED_DRIVE.state == Drive::DELETE_ACTIVE ) if (getSelectedDrive() != nullptr)
{ {
SELECTED_DRIVE.state = Drive::NONE; if(getSelectedDrive()->state == Drive::SHRED_ACTIVE || getSelectedDrive()->state == Drive::DELETE_ACTIVE )
//task for drive is running --> remove selection {
getSelectedDrive()->state = Drive::NONE;
//task for drive is running --> remove selection
}
} }
} }

View File

@ -51,7 +51,7 @@ void TUI::initTUI()
mvprintw(0, 2, "reHDD - HDD refurbishing tool - GPL 3.0 "); mvprintw(0, 2, "reHDD - HDD refurbishing tool - GPL 3.0 ");
} }
void TUI::updateTUI(vector <Drive>* pvecDrives, int32_t i32SelectedEntry) void TUI::updateTUI(vector <Drive>* pvecDrives, uint8_t u8SelectedEntry)
{ {
int stdscrX, stdscrY; int stdscrX, stdscrY;
getmaxyx(stdscr, stdscrY, stdscrX); getmaxyx(stdscr, stdscrY, stdscrX);
@ -79,10 +79,10 @@ void TUI::updateTUI(vector <Drive>* pvecDrives, int32_t i32SelectedEntry)
bool bSelectedEntry = false; bool bSelectedEntry = false;
if(i32SelectedEntry == (it - pvecDrives->begin())) if(u8SelectedEntry == (it - pvecDrives->begin()))
{ {
bSelectedEntry = true; //mark this drive in entries list bSelectedEntry = true; //mark this drive in entries list
displaySelectedDrive(pvecDrives->at(i32SelectedEntry), stdscrX, stdscrY); displaySelectedDrive(pvecDrives->at(u8SelectedEntry), stdscrX, stdscrY);
} }
@ -114,6 +114,23 @@ void TUI::updateTUI(vector <Drive>* pvecDrives, int32_t i32SelectedEntry)
WINDOW * tmp = createEntryWindow( ((int)(stdscrX/3) - 2), 5, 3, (5* (it - pvecDrives->begin()) )+3, sModelFamily, sModelName, sCapacity, sState, bSelectedEntry); WINDOW * tmp = createEntryWindow( ((int)(stdscrX/3) - 2), 5, 3, (5* (it - pvecDrives->begin()) )+3, sModelFamily, sModelName, sCapacity, sState, bSelectedEntry);
wrefresh(tmp); wrefresh(tmp);
}//end loop though drives
if(pvecDrives->size() == 0)
{
//no selected drive present
struct MenuState menustate;
menustate.bAbort = false;
menustate.bConfirmDelete = false;
menustate.bConfirmShred = false;
menustate.bDelete = false;
menustate.bShred = false;
menuview=createMenuView(((stdscrX)-(int)(stdscrX/3)-7), 10, (int)(stdscrX/3)+5,(stdscrY-11), menustate);
wrefresh(menuview);
detailview=overwriteDetailViewWindow(((stdscrX)-(int)(stdscrX/3)-7), (stdscrY-15), (int)(stdscrX/3)+5);
wrefresh(detailview);
} }
} }
@ -183,6 +200,7 @@ WINDOW* TUI::createDetailViewWindow( int iXSize, int iYSize, int iXStart, Drive
newWindow = newwin(iYSize, iXSize, 2, iXStart); newWindow = newwin(iYSize, iXSize, 2, iXStart);
wbkgd(newWindow, COLOR_PAIR(COLOR_AREA_DETAIL)); wbkgd(newWindow, COLOR_PAIR(COLOR_AREA_DETAIL));
box(newWindow, ACS_VLINE, ACS_HLINE); box(newWindow, ACS_VLINE, ACS_HLINE);
string title = "Selected Drive: " + drive.getModelName() + " " + drive.sCapacityToText(); string title = "Selected Drive: " + drive.getModelName() + " " + drive.sCapacityToText();
centerTitle(newWindow, title.c_str()); centerTitle(newWindow, title.c_str());
@ -242,6 +260,40 @@ WINDOW* TUI::createDetailViewWindow( int iXSize, int iYSize, int iXStart, Drive
return newWindow; return newWindow;
} }
WINDOW* TUI::overwriteDetailViewWindow( int iXSize, int iYSize, int iXStart)
{
WINDOW *newWindow;
newWindow = newwin(iYSize, iXSize, 2, iXStart);
wbkgd(newWindow, COLOR_PAIR(COLOR_AREA_DETAIL));
box(newWindow, ACS_VLINE, ACS_HLINE);
string title = "About this tool";
centerTitle(newWindow, title.c_str());
string sLine01 = "Path: NextLine ";
string sLine02 = "Path: NextLine ";
string sLine03 = "Path: NextLine ";
string sLine04 = "Path: NextLine ";
string sLine05 = "Path: NextLine ";
string sLine06 = "Path: NextLine ";
string sLine07 = "Path: NextLine ";
uint16_t u16Line = 5;
mvwaddstr(newWindow,u16Line++, (iXSize/2)-(sLine01.size()/2), sLine01.c_str());
mvwaddstr(newWindow,u16Line++, (iXSize/2)-(sLine02.size()/2), sLine02.c_str());
mvwaddstr(newWindow,u16Line++, (iXSize/2)-(sLine03.size()/2), sLine03.c_str());
mvwaddstr(newWindow,u16Line++, (iXSize/2)-(sLine04.size()/2), sLine04.c_str());
mvwaddstr(newWindow,u16Line++, (iXSize/2)-(sLine05.size()/2), sLine05.c_str());
mvwaddstr(newWindow,u16Line++, (iXSize/2)-(sLine06.size()/2), sLine06.c_str());
mvwaddstr(newWindow,u16Line++, (iXSize/2)-(sLine07.size()/2), sLine07.c_str());
attroff(COLOR_PAIR(COLOR_AREA_DETAIL));
keypad(newWindow, TRUE);
return newWindow;
}
WINDOW* TUI::createEntryWindow(int iXSize, int iYSize, int iXStart, int iYStart, string sModelFamily, string sModelName, string sCapacity, string sState, bool bSelected) WINDOW* TUI::createEntryWindow(int iXSize, int iYSize, int iXStart, int iYStart, string sModelFamily, string sModelName, string sCapacity, string sState, bool bSelected)
{ {
WINDOW *newWindow; WINDOW *newWindow;

View File

@ -60,7 +60,8 @@
"stdexcept": "cpp", "stdexcept": "cpp",
"stop_token": "cpp", "stop_token": "cpp",
"streambuf": "cpp", "streambuf": "cpp",
"typeinfo": "cpp" "typeinfo": "cpp",
"iomanip": "cpp"
}, },
"git.ignoreLimitWarning": true "git.ignoreLimitWarning": true
} }