summaryrefslogtreecommitdiff
path: root/music.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'music.cpp')
-rw-r--r--music.cpp39
1 files changed, 14 insertions, 25 deletions
diff --git a/music.cpp b/music.cpp
index bd50719..f1623c4 100644
--- a/music.cpp
+++ b/music.cpp
@@ -1,44 +1,33 @@
#include "music.h"
-#include <cstdio>
-#include <stdexcept>
-#include <sys/types.h>
-#include <dirent.h>
-#include <errno.h>
-#include <string.h>
+#include <iostream>
namespace music {
MusicDirectory *root_directory = NULL;
-void init(const std::string root) {
+void init(const fs::path root) {
root_directory = new MusicDirectory(root);
}
};
-MusicTrack::MusicTrack(const std::string filename) {
- printf("%s\n", filename.c_str());
- this->filename = filename;
+MusicTrack::MusicTrack(const fs::path path) {
+ std::cout << path << std::endl;
+ this->path = path;
}
-MusicDirectory::MusicDirectory(const std::string root) {
- printf("%s\n", root.c_str());
+MusicDirectory::MusicDirectory(const fs::path root) {
+ std::cout << root << std::endl;
- DIR *d = opendir(root.c_str());
- if(!d) {
- throw std::runtime_error(strerror(errno));
- }
+ fs::path p(root);
- struct dirent *dir;
- while((dir = readdir(d)) != NULL) {
- if(strcmp(dir->d_name, ".") == 0 || strcmp(dir->d_name, "..") == 0) continue;
- if(dir->d_type == DT_DIR) {
- directories.push_back(MusicDirectory(root + "/" + dir->d_name));
- } else if(dir->d_type == DT_REG) {
- tracks.push_back(MusicTrack(root + "/" + dir->d_name));
+ fs::directory_iterator end_itr;
+ for(fs::directory_iterator it(p); it != end_itr; it++) {
+ if(fs::is_directory(it->status())) {
+ directories.push_back(MusicDirectory(it->path().string()));
+ } else if(fs::is_regular_file(it->status())) {
+ tracks.push_back(MusicTrack(it->path().string()));
}
}
-
- closedir(d);
}