Use tuple instead of pair of pairs

This commit is contained in:
zvon 2020-01-31 22:51:43 +01:00
parent 267f1df204
commit 1d52ff388f
3 changed files with 26 additions and 35 deletions

View File

@ -148,15 +148,13 @@ void MainWindow::getNames() {
* orig - original filenames * orig - original filenames
* renamed - renamed filenames (sorted in the same order as `orig`) * renamed - renamed filenames (sorted in the same order as `orig`)
*/ */
void renameFiles( void renameFiles( const std::vector<
const std::vector< std::pair< std::pair< int, std::string >, std::tuple< int, std::string, std::string, std::string > >
std::pair< std::string, std::string > > > &renamed_files ) {
&renamed ) { for ( const auto &renamed : renamed_files ) {
for ( auto renamed_it = renamed.begin(); renamed_it != renamed.end();
++renamed_it ) {
FSLib::rename( FSLib::rename(
renamed_it->first.second + "/" + renamed_it->second.first, std::get< 1 >( renamed ) + "/" + std::get< 2 >( renamed ),
renamed_it->first.second + "/" + renamed_it->second.second ); std::get< 1 >( renamed ) + "/" + std::get< 3 >( renamed ) );
} }
} }
@ -222,15 +220,15 @@ void MainWindow::finishedSelection() {
auto buff = tx->get_buffer(); auto buff = tx->get_buffer();
buff->place_cursor( buff->begin() ); buff->place_cursor( buff->begin() );
buff->insert_at_cursor( renamed_files[0].second.first.c_str() ); buff->insert_at_cursor( std::get< 2 >( renamed_files[0] ).c_str() );
buff->insert_at_cursor( " --> " ); buff->insert_at_cursor( " --> " );
buff->insert_at_cursor( renamed_files[0].second.second.c_str() ); buff->insert_at_cursor( std::get< 3 >( renamed_files[0] ).c_str() );
for ( size_t i = 1; i < renamed_files.size(); i++ ) { for ( size_t i = 1; i < renamed_files.size(); i++ ) {
buff->insert_at_cursor( "\n" ); buff->insert_at_cursor( "\n" );
buff->insert_at_cursor( renamed_files[i].second.first.c_str() ); buff->insert_at_cursor( std::get< 2 >( renamed_files[i] ).c_str() );
buff->insert_at_cursor( " --> " ); buff->insert_at_cursor( " --> " );
buff->insert_at_cursor( renamed_files[i].second.second.c_str() ); buff->insert_at_cursor( std::get< 3 >( renamed_files[i] ).c_str() );
} }
auto response = dialog->run(); auto response = dialog->run();

View File

@ -177,8 +177,7 @@ std::vector< string > getEpisodeNames( const string &id, const string &season,
return episodes; return episodes;
} }
std::vector< std::vector< std::tuple< int, string, string, string > >
std::pair< std::pair< int, string >, std::pair< string, string > > >
getRenamedFiles( const string &show, int season, const string id, getRenamedFiles( const string &show, int season, const string id,
const string &language, const string &pattern, const string &language, const string &pattern,
const bool &linux, const std::map< int, string > &files, const bool &linux, const std::map< int, string > &files,
@ -193,9 +192,7 @@ getRenamedFiles( const string &show, int season, const string id,
return {}; return {};
// vector of pairs <ep_num,dir>,<original_name,new_name> // vector of pairs <ep_num,dir>,<original_name,new_name>
std::vector< std::vector< std::tuple< int, string, string, string > > renamed_files;
std::pair< std::pair< int, string >, std::pair< string, string > > >
renamed_files;
for ( const auto &x : files ) { for ( const auto &x : files ) {
auto last = x.second.find_last_of( _tv_rename_dir_divider ); auto last = x.second.find_last_of( _tv_rename_dir_divider );
@ -257,9 +254,7 @@ getRenamedFiles( const string &show, int season, const string id,
} }
} }
} }
renamed_files.emplace_back( renamed_files.emplace_back( x.first, dir, og_name, name );
std::pair< int, string >( x.first, dir ),
std::pair< string, string >( og_name, name ) );
} }
} }
return renamed_files; return renamed_files;
@ -335,10 +330,9 @@ void singleSeason( const string &path, const string &show, int season,
goto end; goto end;
if ( print || !trust ) { if ( print || !trust ) {
for ( auto renamed = renamed_files.begin(); for ( const auto renamed : renamed_files ) {
renamed != renamed_files.end(); ++renamed ) { cout << std::get< 2 >( renamed ) << " --> "
cout << renamed->second.first << " --> " << renamed->second.second << std::get< 3 >( renamed ) << std::endl;
<< std::endl;
} }
if ( !trust ) { if ( !trust ) {
@ -352,16 +346,15 @@ void singleSeason( const string &path, const string &show, int season,
} }
} }
for ( auto renamed = renamed_files.begin(); renamed != renamed_files.end(); for ( const auto renamed : renamed_files ) {
++renamed ) { FSLib::rename( std::get< 1 >( renamed ) + _tv_rename_dir_divider +
FSLib::rename( renamed->first.second + _tv_rename_dir_divider + std::get< 2 >( renamed ),
renamed->second.first, std::get< 1 >( renamed ) + _tv_rename_dir_divider +
renamed->first.second + _tv_rename_dir_divider + std::get< 3 >( renamed ) );
renamed->second.second );
if ( found_files == nullptr ) { if ( found_files == nullptr ) {
files_ptr[0][renamed->first.first] = renamed->first.second + files_ptr[0][std::get< 0 >( renamed )] = std::get< 1 >( renamed ) +
_tv_rename_dir_divider + _tv_rename_dir_divider +
renamed->second.second; std::get< 3 >( renamed );
} }
} }

View File

@ -3,6 +3,7 @@
#include <map> #include <map>
#include <set> #include <set>
#include <tuple>
#include <vector> #include <vector>
#include "network.hpp" #include "network.hpp"
@ -39,8 +40,7 @@ void singleSeason( const string &path, const string &show, int season,
#ifdef GUI #ifdef GUI
std::vector< std::vector< std::tuple< int, string, string, string > >
std::pair< std::pair< int, string >, std::pair< string, string > > >
getRenamedFiles( const string &show, int season, const string id, getRenamedFiles( const string &show, int season, const string id,
const string &language, const string &pattern, const string &language, const string &pattern,
const bool &linux, const std::map< int, string > &files, const bool &linux, const std::map< int, string > &files,