diff options
author | Bent Bisballe Nyeng <deva@aasimon.org> | 2014-05-17 21:29:53 +0200 |
---|---|---|
committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2014-05-17 21:29:53 +0200 |
commit | bcb9f8b3ae7d477a35e2baa48c5f5bcff2d98986 (patch) | |
tree | 309b57b1ad4abb89e133b08ddebabbbdd06a03c3 /plugingui/directory.cc | |
parent | 0e048dee411cc20beb2a8667e5bb339f9b7fb939 (diff) | |
parent | 488070f321b1fb24bb0a7022c321c574fd4b06ac (diff) |
Merge branch 'master' into resample
Pull in changes from master.
Diffstat (limited to 'plugingui/directory.cc')
-rw-r--r-- | plugingui/directory.cc | 61 |
1 files changed, 46 insertions, 15 deletions
diff --git a/plugingui/directory.cc b/plugingui/directory.cc index 057aead..d481d24 100644 --- a/plugingui/directory.cc +++ b/plugingui/directory.cc @@ -77,7 +77,8 @@ size_t Directory::count() void Directory::refresh() { - _files = listFiles(_path); + _files = listFiles(_path, DIRECTORY_HIDDEN); +// _files = listFiles(_path); } bool Directory::cd(std::string dir) @@ -128,7 +129,7 @@ std::string Directory::cleanPath(std::string path) return Directory::pathToStr(pathlst); } -Directory::EntryList Directory::listFiles(std::string path) +Directory::EntryList Directory::listFiles(std::string path, unsigned char filter) { DEBUG(directory, "Listing files in '%s'\n", path.c_str()); @@ -149,12 +150,19 @@ Directory::EntryList Directory::listFiles(std::string path) if(Directory::isRoot(path) && name == "..") continue; + unsigned char entryinfo = 0; + if(isHidden(name)) { + entryinfo |= DIRECTORY_HIDDEN; + } + std::string entrypath = path; entrypath += SEP; entrypath += entry->d_name; if(Directory::isDir(entrypath)) { - if(name == "..") directories.push_back(entry->d_name); - else directories.push_back(std::string(SEP) + entry->d_name); + if(!(entryinfo && filter)) { + if(name == "..") directories.push_back(entry->d_name); + else directories.push_back(std::string(SEP) + entry->d_name); + } } else { int drumkit_suffix_length = strlen(DRUMKIT_SUFFIX); @@ -164,7 +172,10 @@ Directory::EntryList Directory::listFiles(std::string path) continue; } - files.push_back(entry->d_name); + +// if(!(entryinfo && filter)) { + files.push_back(entry->d_name); +// } } } @@ -276,6 +287,20 @@ bool Directory::isDir() return isDir(_path); } +bool Directory::isDir(std::string path) +{ + DEBUG(directory, "Is '%s' dir?\n", path.c_str()); + struct stat st; + if(stat(path.c_str(), &st) == 0) { + if((st.st_mode & S_IFDIR) != 0) { + DEBUG(directory, "Yes\n"); + return true; + } + } + DEBUG(directory, "No\n"); + return false; +} + bool Directory::fileExists(std::string filename) { return !isDir(_path + SEP + filename); @@ -291,18 +316,24 @@ bool Directory::exists(std::string path) } } -bool Directory::isDir(std::string path) +bool Directory::isHidden(std::string path) { - DEBUG(directory, "Is '%s' dir?\n", path.c_str()); - struct stat st; - if(stat(path.c_str(), &st) == 0) { - if((st.st_mode & S_IFDIR) != 0) { - DEBUG(directory, "Yes\n"); - return true; - } + // TODO: Handle hidden and system files in windows +#ifdef WIN32 + return false +#else + unsigned pos = path.find_last_of("/\\"); + std::string entry = path.substr(pos+1); + + if(entry.size() > 1 && + entry.at(0) == '.' && + entry.at(1) != '.') { + return true; } - DEBUG(directory, "No\n"); - return false; + else { + return false; + } +#endif } Directory::Path Directory::parsePath(std::string path_str) |