diff options
Diffstat (limited to 'plugingui/directory.cc')
-rw-r--r-- | plugingui/directory.cc | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/plugingui/directory.cc b/plugingui/directory.cc index 5f80508..7e7d7e1 100644 --- a/plugingui/directory.cc +++ b/plugingui/directory.cc @@ -53,8 +53,7 @@ void Directory::refresh() { bool Directory::cd(std::string dir) { DEBUG(directory, "Changing to '%s'\n", dir.c_str()); - int r = chdir( (path() + "/" + dir).c_str() ); - if(!r) { + if(exists(path() + "/" + dir)) { _path += "/" + dir; refresh(); return true; @@ -114,9 +113,12 @@ std::string Directory::cleanPath(std::string path) { } Directory::EntryList Directory::listFiles(std::string path) { + DEBUG(directory, "Listing files in '%s'\n", path.c_str()); + Directory::EntryList entries; - DIR *dir = opendir("."); + DIR *dir = opendir(path.c_str()); if(!dir) { + DEBUG(directory, "Couldn't open directory '%s\n", path.c_str()); return entries; } @@ -129,6 +131,8 @@ Directory::EntryList Directory::listFiles(std::string path) { } bool Directory::isRoot(std::string path) { + //TODO: Handle WIN32 + if(path == "/") return true; else return false; } @@ -160,10 +164,18 @@ bool Directory::isDir() return isDir(path()); } -bool Directory::exists(std::string filename) { +bool Directory::fileExists(std::string filename) { return !isDir(path() + "/" + filename); } +bool Directory::exists(std::string path) { + struct stat st; + if(stat(path.c_str(), &st) == 0) { + return true; + } + else return false; +} + bool Directory::isDir(std::string path) { DEBUG(directory, "Is '%s' dir?\n", path.c_str()); struct stat st; |