mapper: make the music_directory optional

Without a music_directory, MPD is an excellent streaming client.
This commit is contained in:
Max Kellermann
2009-01-18 16:56:07 +01:00
parent 9933144de7
commit 1f0dfb4407
8 changed files with 95 additions and 35 deletions

View File

@@ -49,13 +49,17 @@ db_init(const char *path)
{
database_path = g_strdup(path);
music_root = directory_new("", NULL);
if (path != NULL)
music_root = directory_new("", NULL);
}
void
db_finish(void)
{
directory_free(music_root);
assert((database_path == NULL) == (music_root == NULL));
if (music_root != NULL)
directory_free(music_root);
g_free(database_path);
}
@@ -63,6 +67,8 @@ db_finish(void)
void
db_clear(void)
{
assert(music_root != NULL);
directory_free(music_root);
music_root = directory_new("", NULL);
}
@@ -78,6 +84,9 @@ db_get_root(void)
struct directory *
db_get_directory(const char *name)
{
if (music_root == NULL)
return NULL;
if (name == NULL)
return music_root;
@@ -89,14 +98,20 @@ db_get_song(const char *file)
{
struct song *song = NULL;
struct directory *directory;
char *dir = NULL;
char *duplicated = g_strdup(file);
char *shortname = strrchr(duplicated, '/');
char *duplicated, *shortname, *dir;
assert(file != NULL);
g_debug("get song: %s", file);
if (music_root == NULL)
return NULL;
duplicated = g_strdup(file);
shortname = strrchr(duplicated, '/');
if (!shortname) {
shortname = duplicated;
dir = NULL;
} else {
*shortname = '\0';
++shortname;
@@ -121,6 +136,9 @@ db_walk(const char *name,
{
struct directory *directory;
if (music_root == NULL)
return -1;
if ((directory = db_get_directory(name)) == NULL) {
struct song *song;
if ((song = db_get_song(name)) && forEachSong) {