Fix windows problems

This commit is contained in:
zvon 2020-01-15 23:59:39 +01:00
parent 01cf6d289a
commit 758af6ff6b
4 changed files with 38 additions and 30 deletions

View File

@ -372,7 +372,7 @@ string compilePattern( const string &pattern, int season, int episode,
return output;
}
#ifdef WIN32
#ifdef _WIN32
std::wstring getDBName() {
return userHome() + L"\\tv_rename\\database.db";
@ -400,7 +400,7 @@ string sanitize( const string &str ) {
return ret;
}
void prepareDB( const std::string &_pattern ) {
void prepareDB( const string &_pattern ) {
SQLite::Database db{};
try {
db.open( getDBName(), SQLite::OPEN_READWRITE | SQLite::OPEN_CREATE );
@ -462,9 +462,13 @@ void addToDB( string &show, const string &path, const string &language,
TEXT( "INSERT OR IGNORE INTO SHOWS ( TVID, SHOW, PATH, LANGUAGE, DVD ) "
"VALUES ( '" ) +
sanitize( id ) + TEXT( "', '" ) + sanitize( show ) + TEXT( "', '" ) +
sanitize( absolute ) + TEXT( "', '" ) + sanitize( language ) + "', " +
sanitize( absolute ) + TEXT( "', '" ) + sanitize( language ) + TEXT( "', " ) +
( dvd ? TEXT( "1" ) : TEXT( "0" ) ) + TEXT( " );" ) );
#ifdef _WIN32
string show_id = std::to_wstring( db.lastRowID() );
#else
string show_id = std::to_string( db.lastRowID() );
#endif
#ifndef GUI
string pattern{};
db.exec( TEXT( "SELECT PATH FROM SHOWS WHERE TVID == 'pattern';" ),
@ -477,7 +481,7 @@ void addToDB( string &show, const string &path, const string &language,
auto size = seasons.size();
size_t i = 0;
cout << "Renaming" << std::endl;
#ifdef WIN32
#ifdef _WIN32
cout << std::endl;
#endif
#ifndef GUI
@ -498,7 +502,7 @@ void addToDB( string &show, const string &path, const string &language,
i = 0;
cout << "Adding to database" << std::endl;
#ifdef WIN32
#ifdef _WIN32
cout << std::endl;
#endif
#ifndef GUI
@ -521,7 +525,7 @@ void addToDB( string &show, const string &path, const string &language,
#endif
}
#ifdef WIN32
#ifdef _WIN32
void cleanUpLine() {
CONSOLE_SCREEN_BUFFER_INFO csbi;
int width;
@ -573,14 +577,14 @@ void refreshDB( bool linux ) {
pattern );
cout << "Refreshing database" << std::endl << std::endl << std::endl;
#ifdef WIN32
#ifdef _WIN32
cout << std::endl;
#endif
for ( auto &show : shows ) {
if ( FSLib::exists( show[TEXT( "PATH" )] ) ) {
cleanUpLine();
cout << "Refreshing " << show[TEXT( "SHOW" )] << std::endl;
#ifdef WIN32
#ifdef _WIN32
cout << std::endl;
#endif
#ifndef GUI
@ -639,7 +643,7 @@ void updateDB( bool linux ) {
pattern );
cout << "Updating database" << std::endl << std::endl << std::endl;
#ifdef WIN32
#ifdef _WIN32
cout << std::endl;
#endif
for ( auto &show : shows ) {
@ -648,7 +652,7 @@ void updateDB( bool linux ) {
}
cleanUpLine();
cout << "Updating " << show[TEXT( "SHOW" )] << std::endl;
#ifdef WIN32
#ifdef _WIN32
cout << std::endl;
#endif
std::unordered_set< string > episodes;
@ -768,7 +772,7 @@ void removeFromDB( const string &path ) {
db.exec( TEXT( "DELETE FROM SHOWS WHERE ID == " ) + show_id + TEXT( ";" ) );
}
std::vector< std::unordered_map< std::string, std::string > > dbGetShows() {
std::vector< std::unordered_map< string, string > > dbGetShows() {
SQLite::Database db{};
try {
db.open( getDBName(), SQLite::OPEN_READWRITE );
@ -776,7 +780,7 @@ std::vector< std::unordered_map< std::string, std::string > > dbGetShows() {
cerr << "Can't open database, make sure it exists" << std::endl;
throw e;
}
std::vector< std::unordered_map< std::string, std::string > > ret;
std::vector< std::unordered_map< string, string > > ret;
db.exec( TEXT( "SELECT * FROM SHOWS;" ), ret );
return ret;
}
@ -791,7 +795,7 @@ void changeDB( size_t index, const string &path, const string &language,
cerr << "Can't open database, make sure it exists" << std::endl;
throw e;
}
#ifndef WIN32
#ifndef _WIN32
string show_id = std::to_string( index );
#else
string show_id = std::to_wstring( index );
@ -801,13 +805,17 @@ void changeDB( size_t index, const string &path, const string &language,
TEXT( "', SHOW = '" ) + sanitize( real_show ) +
TEXT( "', PATH = '" ) + sanitize( absolute ) +
TEXT( "', LANGUAGE = '" ) + sanitize( language ) +
TEXT( "', DVD = " + ( dvd ? TEXT( "1" ) : TEXT( "0" ) ) +
" WHERE ID == " + show_id + ";" ) );
TEXT( "', DVD = " ) + ( dvd ? TEXT( "1" ) : TEXT( "0" ) ) +
TEXT( " WHERE ID == " ) + show_id + TEXT( ";" ) );
}
void refreshSingleDB( const size_t &index, bool linux ) {
std::vector< std::unordered_map< string, string > > shows;
#ifdef _WIN32
string show_id = std::to_wstring( index );
#else
string show_id = std::to_string( index );
#endif
SQLite::Database db{};
try {
db.open( getDBName(), SQLite::OPEN_READWRITE );
@ -815,10 +823,10 @@ void refreshSingleDB( const size_t &index, bool linux ) {
cerr << "Can't open database, make sure it exists" << std::endl;
throw e;
}
db.exec( "DELETE FROM EPISODES WHERE SHOWID == " + show_id + ";" );
db.exec( TEXT( "DELETE FROM EPISODES WHERE SHOWID == " ) + show_id + TEXT( ";" ) );
db.exec(
TEXT( "SELECT TVID, SHOW, PATH, LANGUAGE, DVD FROM SHOWS WHERE ID == " +
show_id + ";" ),
TEXT( "SELECT TVID, SHOW, PATH, LANGUAGE, DVD FROM SHOWS WHERE ID == " ) +
show_id + TEXT( ";" ),
shows );
std::unordered_map< string, string > &show = shows[0];
@ -830,11 +838,11 @@ void refreshSingleDB( const size_t &index, bool linux ) {
cout << "Refreshing " << show[TEXT( "SHOW" )] << std::endl
<< std::endl
<< std::endl;
#ifdef WIN32
#ifdef _WIN32
cout << std::endl;
#endif
if ( FSLib::exists( show[TEXT( "PATH" )] ) ) {
#ifdef WIN32
#ifdef _WIN32
cout << std::endl;
#endif
#ifndef GUI

View File

@ -45,7 +45,7 @@ getPossibleShows( string show, const string &language );
string userHome();
void prepareDB( const std::string &_pattern = "" );
void prepareDB( const string &_pattern = TEXT( "" ) );
#ifndef GUI
void addToDB( string &show, const string &path, const string &language,
bool linux, bool dvd );

View File

@ -46,7 +46,7 @@ constexpr const char_t *dir_divider = "/";
#endif
std::string api_token = "";
string api_token;
Request r;
std::vector< std::pair< string, string > >
@ -64,7 +64,7 @@ searchShow( const string &show, const string &language ) {
if( j["data"].is_array() ) {
results = j["data"].get< std::vector< json > >();
} else {
cout << j << std::endl;
cout << toString( j ) << std::endl;
return {};
}
@ -87,7 +87,7 @@ string getShowId( string &show, const string &language ) {
for( const auto &x : search_results ) {
cout << ++order << ". " << x.first << std::endl;
}
cout << "Which TV Show is the right one? ";
cout << "Which TV Show is the right one? " << std::flush;
cin >> pos;
cin.clear();
cin.ignore( 1, '\n' );
@ -133,13 +133,13 @@ std::vector< string > getEpisodeNames( const string &id, const string &season,
if( index > episodes.size() )
episodes.resize( index );
index--;
episodes[index] = toString( x["episodeName"].get< string >() );
episodes[index] = toString( x["episodeName"].get< std::string >() );
} else {
size_t index = x["airedEpisodeNumber"].get< size_t >();
if( index > episodes.size() )
episodes.resize( index );
index--;
episodes[index] = toString( x["episodeName"].get<string>() );
episodes[index] = toString( x["episodeName"].get< std::string >() );
// some eps have whitespace at the end
while( isspace( episodes[index].back() ) )
episodes[index].pop_back();
@ -332,8 +332,8 @@ void allSeasons( const string &path, string &show, const string &language,
}
}
std::vector< std::pair< std::string, std::string > > getLangs() {
std::vector< std::pair< std::string, std::string > > langs;
std::vector< std::pair< string, string > > getLangs() {
std::vector< std::pair< string, string > > langs;
r.addHeader( TEXT( "Accept: application/json" ) );
r.addHeader( TEXT( "Authorization: Bearer " ) + api_token );
auto j = json::parse( r.get( TEXT( "/languages" ) ) );
@ -361,7 +361,7 @@ bool findLanguage( const char_t *language ) {
bool authenticate( const std::string &api_key ) {
#ifdef _WIN32
r.setServer( "api.thetvdb.com" );
r.setServer( TEXT( "api.thetvdb.com" ) );
#else
r.setServer( "https://api.thetvdb.com" );
#endif

View File

@ -29,7 +29,7 @@ std::string sendRequest( HINTERNET hRequest, const std::wstring &headers,
memcpy( opt.get(), optional.c_str(), optional.length() );
auto requestSent = HttpSendRequest(
hRequest, headers.c_str(), headers.length(), opt, optional.length() );
hRequest, headers.c_str(), headers.length(), opt.get(), optional.length() );
if ( !requestSent )
std::wcerr << "ERROR HttpSendRequest: " << GetLastError() << std::endl;