From b6141fd2383b24035abc3beef6148f55aafda30c Mon Sep 17 00:00:00 2001 From: zvon Date: Sun, 23 Sep 2018 10:59:30 +0200 Subject: [PATCH] Use std functions --- functions.cpp | 10 ---------- functions.hpp | 1 - tv_rename.cpp | 16 +++++++--------- 3 files changed, 7 insertions(+), 20 deletions(-) diff --git a/functions.cpp b/functions.cpp index 3cd5afe..de531dc 100644 --- a/functions.cpp +++ b/functions.cpp @@ -33,16 +33,6 @@ std::string getSource(const std::string &url) { return source; } -std::string absolutePath(const std::string &path) { - char *buff = static_cast(malloc(PATH_MAX)); - char *ptr = realpath(path.c_str(), buff); - if( ptr == nullptr ) - return ""; - std::string abs_path(buff); - free(buff); - return abs_path; -} - void findSeason(std::set &files, int season, const std::string &path) { namespace fs = std::experimental::filesystem; std::smatch match; diff --git a/functions.hpp b/functions.hpp index 74f6376..6119f0a 100644 --- a/functions.hpp +++ b/functions.hpp @@ -6,7 +6,6 @@ #include std::string getSource(const std::string &url); -std::string absolutePath(const std::string &path); std::string getDefUrl( const std::string &show, const std::string &language ); void findSeason(std::set &files, int season, const std::string &path); void iterateFS(std::set &seasons, const std::string &path); diff --git a/tv_rename.cpp b/tv_rename.cpp index 924ecac..ee51077 100644 --- a/tv_rename.cpp +++ b/tv_rename.cpp @@ -17,6 +17,7 @@ bool trust{false}; bool linux{false}; int main(int argc, char** argv) { + namespace fs = std::experimental::filesystem; std::map languages{ {"en", "English"}, {"sv", "Svenska"}, {"no", "Norsk"}, {"da", "Dansk"}, {"fi", "Suomeksi"}, {"nl", "Nederlands"}, {"de", "Deutsch"}, {"it", "Italiano"}, {"es", "Español"}, {"fr", "Français"}, @@ -43,10 +44,8 @@ int main(int argc, char** argv) { change_dir = false; } else if ( !(strcmp("-sp", argv[x]) && strcmp("--show-path", argv[x])) ) { path = std::string(argv[x+1]); - if ( path[0] != '/' && path[0] != '.' ) - path = "./" + path; x++; - if( absolutePath(path).empty() ) + if( !fs::exists(fs::absolute(path)) ) change_dir = true; } else if ( !(strcmp("-t", argv[x]) && strcmp("--trust", argv[x])) ) { trust = true; @@ -73,13 +72,13 @@ int main(int argc, char** argv) { } while( change_dir ) { - auto abs = absolutePath(path); - if( abs.empty() ) { + auto abs = fs::absolute(path); + if( !fs::exists(abs) ) { std::cout << "This directory doesn't exist, please insert a correct path: " << std::endl; std::getline(std::cin, path); continue; } - std::cout << "Is this the right directory? " << absolutePath(path) << std::endl; + std::cout << "Is this the right directory? " << fs::canonical(abs) << std::endl; std::string response; std::cin >> response; std::cin.ignore(1,'\n'); @@ -89,12 +88,10 @@ int main(int argc, char** argv) { } else { std::cout << "Insert correct path:" << std::endl; std::getline(std::cin, path); - if ( path[0] != '/' && path[0] != '.' ) - path = "./" + path; } } - path = absolutePath(path); + path = fs::absolute(path); if( show.empty() ) { show = std::regex_replace(path, std::regex(".*/"), ""); @@ -180,6 +177,7 @@ void singleSeason( const std::string &path, const std::string &show, int season, name = std::regex_replace(name, std::regex("[\\?\"\\\\|\\*]"), ""); name = std::regex_replace(name, std::regex("<"), "is less than"); name = std::regex_replace(name, std::regex(">"), "is more than"); + name = std::regex_replace(name, std::regex(":"), " -"); } renamed_files.insert(dir + name); renamed_episodes[num] = name;