diff options
author | Stefan Pöschel <github@basicmaster.de> | 2017-02-15 11:25:20 +0100 |
---|---|---|
committer | Stefan Pöschel <github@basicmaster.de> | 2017-02-15 11:25:20 +0100 |
commit | bba4b5ca2f6aa376dd07f006eb9461df386a4116 (patch) | |
tree | 8e2a656cc1e418bca7a87bda27e6c48d37abf68e | |
parent | 283a915a5d70d46fbcf9db1d359e978e7b82de43 (diff) | |
download | ODR-PadEnc-bba4b5ca2f6aa376dd07f006eb9461df386a4116.tar.gz ODR-PadEnc-bba4b5ca2f6aa376dd07f006eb9461df386a4116.tar.bz2 ODR-PadEnc-bba4b5ca2f6aa376dd07f006eb9461df386a4116.zip |
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).
-rw-r--r-- | src/odr-padenc.cpp | 51 |
1 files changed, 28 insertions, 23 deletions
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<std::string> dls_files) { return result; } -bool read_slides_dir(const char* dir, History& history, std::list<slide_metadata_t>& 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<slide_metadata_t>& 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(); |