main.cpp: Ensure show isn't empty when doing --db-add

This commit is contained in:
zvon 2020-05-11 15:31:42 +02:00
parent de2ef74938
commit de5be3e857

View File

@ -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,