From de5be3e857f3e24acc5209bc9868fd010ca7db64 Mon Sep 17 00:00:00 2001 From: zvon Date: Mon, 11 May 2020 15:31:42 +0200 Subject: [PATCH] main.cpp: Ensure show isn't empty when doing --db-add --- main.cpp | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/main.cpp b/main.cpp index 2da7df0..bbc69b8 100644 --- a/main.cpp +++ b/main.cpp @@ -244,6 +244,24 @@ int parseCommandLine( string &show, std::set< int > &seasons_num, string &path, return 0; } +void ensureShowNotEmpty( string &show, const string &path ) { + if ( show.empty() ) { + show = FSLib::canonical( path ); + auto pos = show.find_last_of( '/' ); + if ( pos != string::npos ) + show = show.substr( ++pos ); + cout << _( SHOW_CONFIRM ) << ' ' << show << std::endl; + string response; + cin >> response; + cin.ignore( 1, '\n' ); + cin.clear(); + if ( response[0] != 'y' && response[0] != 'Y' ) { + cout << _( SHOW_REENTER ) << std::endl; + std::getline( cin, show ); + } + } +} + #endif // windows needs wmain for unicode support @@ -331,6 +349,7 @@ int main removeFromDB( FSLib::canonical( path ) ); } if ( db_flags & DB_ADD ) { + ensureShowNotEmpty( show, path ); addToDB( show, path, language, tv_flags & TV_LINUX, tv_flags & TV_DVD ); cout << _( ADDED_TO_DB ) << std::endl; } @@ -371,21 +390,7 @@ int main } } - if ( show.empty() ) { - show = FSLib::canonical( path ); - auto pos = show.find_last_of( '/' ); - if ( pos != string::npos ) - show = show.substr( ++pos ); - cout << _( SHOW_CONFIRM ) << ' ' << show << std::endl; - string response; - cin >> response; - cin.ignore( 1, '\n' ); - cin.clear(); - if ( response[0] != 'y' && response[0] != 'Y' ) { - cout << _( SHOW_REENTER ) << std::endl; - std::getline( cin, show ); - } - } + ensureShowNotEmpty( show, path ); if ( seasons_num.size() == 1 ) { singleSeason( path, show, *seasons_num.begin(), string(), language,