From bba4b5ca2f6aa376dd07f006eb9461df386a4116 Mon Sep 17 00:00:00 2001 From: Stefan Pöschel Date: Wed, 15 Feb 2017 11:25:20 +0100 Subject: Fix alphabetic slide sorting The alphabetic sorting within the slide dir was ignored so far. Now the sorting is considered while adding slides for transmission. Furthermore now also files starting with "." are added (except the ./.. dirs). --- src/odr-padenc.cpp | 51 ++++++++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 23 deletions(-) (limited to 'src/odr-padenc.cpp') diff --git a/src/odr-padenc.cpp b/src/odr-padenc.cpp index 38d2b6c..d82d4c8 100644 --- a/src/odr-padenc.cpp +++ b/src/odr-padenc.cpp @@ -100,41 +100,46 @@ static std::string list_dls_files(std::vector dls_files) { return result; } -bool read_slides_dir(const char* dir, History& history, std::list& slides) { - DIR *pDir = opendir(dir); - if (pDir == NULL) { - fprintf(stderr, "ODR-PadEnc Error: cannot open directory '%s'\n", dir); - return false; - } - // Add new slides to transmit to list - struct dirent *pDirent; - while ((pDirent = readdir(pDir)) != NULL) { - std::string slide = pDirent->d_name; +static int filter_slides(const struct dirent* file) { + std::string name = file->d_name; + + // skip '.'/'..' dirs + if(name == "." || name == "..") + return 0; - // skip dirs beginning with '.' - if(slide[0] == '.') - continue; + // skip slide params files + if(name.length() >= SLSManager::SLS_PARAMS_SUFFIX.length() && + name.substr(name.length() - SLSManager::SLS_PARAMS_SUFFIX.length()) == SLSManager::SLS_PARAMS_SUFFIX) + return 0; - // skip slide params files - if(slide.length() >= SLSManager::SLS_PARAMS_SUFFIX.length() && - slide.compare(slide.length() - SLSManager::SLS_PARAMS_SUFFIX.length(), SLSManager::SLS_PARAMS_SUFFIX.length(), SLSManager::SLS_PARAMS_SUFFIX) == 0) - continue; + return 1; +} + + +static bool read_slides_dir(const std::string& dir, History& history, std::list& slides) { + struct dirent** dir_entries; + int dir_count = scandir(dir.c_str(), &dir_entries, filter_slides, alphasort); + if(dir_count < 0) { + fprintf(stderr, "ODR-PadEnc Error: cannot open directory '%s'\n", dir.c_str()); + return false; + } - // add slide - char imagepath[256]; - sprintf(imagepath, "%s/%s", dir, slide.c_str()); + // add new slides to transmit to list + for(int i = 0; i < dir_count; i++) { + std::string imagepath = dir + "/" + std::string(dir_entries[i]->d_name); + free(dir_entries[i]); slide_metadata_t md; md.filepath = imagepath; - md.fidx = history.get_fidx(imagepath); + md.fidx = history.get_fidx(imagepath.c_str()); slides.push_back(md); if (verbose) - fprintf(stderr, "ODR-PadEnc found slide '%s', fidx %d\n", imagepath, md.fidx); + fprintf(stderr, "ODR-PadEnc found slide '%s', fidx %d\n", imagepath.c_str(), md.fidx); } - closedir(pDir); + free(dir_entries); #ifdef DEBUG slides_history.disp_database(); -- cgit v1.2.3