libsaria: Create generic function for reading numbered directories
I create directories with numbered files for the library and playlist, this patch creates generic code for reading them during startup. Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
parent
261316fb5f
commit
851aa10ae1
|
@ -21,6 +21,7 @@ namespace libsaria
|
|||
void init(string);
|
||||
|
||||
void list_dir(string &, list<string> &);
|
||||
unsigned int read_numdir(string &, void (*)(ifstream &));
|
||||
void mkdir(string);
|
||||
void mkdir();
|
||||
void rm(string);
|
||||
|
|
|
@ -39,6 +39,13 @@ static void handle_entry(string &dir, list<string> &file_list, struct dirent *di
|
|||
};
|
||||
}
|
||||
|
||||
static bool compare_files(string &one, string &two)
|
||||
{
|
||||
unsigned int a = atoi(one.c_str());
|
||||
unsigned int b = atoi(two.c_str());
|
||||
return a < b;
|
||||
}
|
||||
|
||||
namespace libsaria
|
||||
{
|
||||
|
||||
|
@ -78,6 +85,24 @@ namespace libsaria
|
|||
file_list.push_back( (*it).substr(d.size() + 1) );
|
||||
}
|
||||
|
||||
unsigned int app::read_numdir(string &dir, void (*func)(ifstream &))
|
||||
{
|
||||
list<string> files;
|
||||
list<string>::iterator it;
|
||||
|
||||
list_dir(dir, files);
|
||||
if (files.size() == 0)
|
||||
return 0;
|
||||
files.sort(compare_files);
|
||||
|
||||
for (it = files.begin(); it != files.end(); it++) {
|
||||
println("Reading path: " + dir + "/" + (*it));
|
||||
read(dir + "/" + (*it), func);
|
||||
}
|
||||
|
||||
return atoi(files.back().c_str()) + 1;
|
||||
}
|
||||
|
||||
void app::mkdir()
|
||||
{
|
||||
make_dir(appdir.c_str());
|
||||
|
|
|
@ -80,29 +80,9 @@ void read_path(ifstream &stream)
|
|||
lib_playlist.add_tracks(tracks);
|
||||
}
|
||||
|
||||
static bool compare_libfiles(string one, string two)
|
||||
{
|
||||
unsigned int a = atoi(one.c_str());
|
||||
unsigned int b = atoi(two.c_str());
|
||||
return a < b;
|
||||
}
|
||||
|
||||
unsigned int schedule_load()
|
||||
{
|
||||
list<string> paths;
|
||||
list<string>::iterator it;
|
||||
|
||||
libsaria::app::list_dir(libdir, paths);
|
||||
if (paths.size() == 0)
|
||||
return 0;
|
||||
paths.sort(compare_libfiles);
|
||||
|
||||
for (it = paths.begin(); it != paths.end(); it++) {
|
||||
println("Reading library path: " + libdir + "/" + (*it));
|
||||
libsaria::app::read(libdir + "/" + (*it), read_path);
|
||||
}
|
||||
|
||||
return atoi(paths.back().c_str()) + 1;
|
||||
return libsaria::app::read_numdir(libdir, read_path);
|
||||
}
|
||||
|
||||
void remove_file(libsaria::library::Path *path)
|
||||
|
|
|
@ -46,13 +46,6 @@ void read_plist(ifstream &stream)
|
|||
libsaria::create_new_playlist(tracks, (PlaylistType)type);
|
||||
}
|
||||
|
||||
static bool compare_plists(string one, string two)
|
||||
{
|
||||
unsigned int a = atoi(one.c_str());
|
||||
unsigned int b = atoi(two.c_str());
|
||||
return a < b;
|
||||
}
|
||||
|
||||
namespace libsaria
|
||||
{
|
||||
|
||||
|
@ -92,18 +85,7 @@ namespace libsaria
|
|||
|
||||
void deck::load_all()
|
||||
{
|
||||
list<string> plists;
|
||||
list<string>::iterator it;
|
||||
|
||||
libsaria::app::list_dir(plistdir, plists);
|
||||
if (plists.size() == 0)
|
||||
return;
|
||||
plists.sort(compare_plists);
|
||||
|
||||
for (it = plists.begin(); it != plists.end(); it++) {
|
||||
println("Reading plist path: " + plistdir + "/" + (*it));
|
||||
libsaria::app::read(plistdir + "/" + (*it), read_plist);
|
||||
}
|
||||
app::read_numdir(plistdir, read_plist);
|
||||
}
|
||||
|
||||
}; /* Namespace: libsaria */
|
||||
|
|
Loading…
Reference in New Issue