From 1ce1732e681ff9599dfb8372bcfd5767e6e0b3ab Mon Sep 17 00:00:00 2001 From: "stefan.haustein@gmail.com" Date: Sun, 29 Jul 2018 23:55:46 +0200 Subject: [PATCH] Support directories (instead of crashing) --- src/main/cpp/Makefile | 4 ++-- src/main/cpp/tiv.cpp | 12 +++++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main/cpp/Makefile b/src/main/cpp/Makefile index 2cd121f..e3b7754 100644 --- a/src/main/cpp/Makefile +++ b/src/main/cpp/Makefile @@ -1,10 +1,10 @@ default: tiv tiv.o: tiv.cpp CImg.h - g++ -std=c++11 -Wall -fexceptions -O2 -c tiv.cpp -o tiv.o + g++ -std=c++17 -Wall -fpermissive -fexceptions -O2 -c tiv.cpp -o tiv.o tiv : tiv.o - g++ tiv.o -o tiv -pthread -s + g++ tiv.o -o tiv -lstdc++fs -pthread -s install: tiv cp tiv /usr/local/bin/tiv diff --git a/src/main/cpp/tiv.cpp b/src/main/cpp/tiv.cpp index ff1cd4d..783723c 100644 --- a/src/main/cpp/tiv.cpp +++ b/src/main/cpp/tiv.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #define cimg_display 0 #include "CImg.h" @@ -435,10 +436,19 @@ int main(int argc, char* argv[]) { } else if (arg[0] == '-') { std::cerr << "Unrecognized argument: " << arg << std::endl; } else { - file_names.push_back(arg); + if (std::experimental::filesystem::is_directory(arg)) { + for (auto & p : std::experimental::filesystem::directory_iterator(arg)) { + if (std::experimental::filesystem::is_regular_file(p.path())) { + file_names.push_back(p.path().string()); + } + } + } else { + file_names.push_back(arg); + } } } + if (mode == FULL_SIZE || (mode == AUTO && file_names.size() == 1)) { for (unsigned int i = 0; i < file_names.size(); i++) { try {