summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--SConstruct1
-rw-r--r--music.cpp39
-rw-r--r--music.h14
3 files changed, 23 insertions, 31 deletions
diff --git a/SConstruct b/SConstruct
index 325abe5..23aacb8 100644
--- a/SConstruct
+++ b/SConstruct
@@ -4,6 +4,7 @@ env = Environment(CPPPATH = ['.'], CCFLAGS = ['-pthread'], LINKFLAGS = ['-pthrea
conf = Configure(env)
conf.CheckLib('boost_system')
+conf.CheckLib('boost_filesystem')
env = conf.Finish()
if GetOption('release'):
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);
}
diff --git a/music.h b/music.h
index 8e0bd9e..8ce93c1 100644
--- a/music.h
+++ b/music.h
@@ -1,13 +1,15 @@
#ifndef MUSIC_H
#define MUSIC_H
-#include <string>
+#include <boost/filesystem.hpp>
#include <vector>
+namespace fs = boost::filesystem;
+
class MusicTrack {
public:
- MusicTrack(const std::string filename);
- std::string filename;
+ MusicTrack(const fs::path path);
+ fs::path path;
};
class MusicDirectory;
@@ -16,15 +18,15 @@ typedef std::vector<MusicTrack> MusicTracks;
class MusicDirectory {
public:
- MusicDirectory(const std::string root);
- std::string path;
+ MusicDirectory(const fs::path root);
+ fs::path path;
MusicDirectories directories;
MusicTracks tracks;
};
namespace music {
extern MusicDirectory *root_directory;
- void init(const std::string root);
+ void init(const fs::path root);
};
#endif