Use std functions

This commit is contained in:
zvon 2018-09-23 10:59:30 +02:00
parent 3e36697b06
commit b6141fd238
3 changed files with 7 additions and 20 deletions

View File

@ -33,16 +33,6 @@ std::string getSource(const std::string &url) {
return source;
}
std::string absolutePath(const std::string &path) {
char *buff = static_cast<char*>(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<std::experimental::filesystem::path> &files, int season, const std::string &path) {
namespace fs = std::experimental::filesystem;
std::smatch match;

View File

@ -6,7 +6,6 @@
#include <experimental/filesystem>
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<std::experimental::filesystem::path> &files, int season, const std::string &path);
void iterateFS(std::set<int> &seasons, const std::string &path);

View File

@ -17,6 +17,7 @@ bool trust{false};
bool linux{false};
int main(int argc, char** argv) {
namespace fs = std::experimental::filesystem;
std::map<std::string, std::string> 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;