aboutsummaryrefslogtreecommitdiffstats
path: root/src/DirectorySave.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'src/DirectorySave.cxx')
-rw-r--r--src/DirectorySave.cxx42
1 files changed, 17 insertions, 25 deletions
diff --git a/src/DirectorySave.cxx b/src/DirectorySave.cxx
index fa330d126..499f84734 100644
--- a/src/DirectorySave.cxx
+++ b/src/DirectorySave.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2013 The Music Player Daemon Project
+ * Copyright (C) 2003-2014 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -22,16 +22,15 @@
#include "Directory.hxx"
#include "Song.hxx"
#include "SongSave.hxx"
+#include "DetachedSong.hxx"
#include "PlaylistDatabase.hxx"
-#include "TextFile.hxx"
+#include "fs/TextFile.hxx"
+#include "util/StringUtil.hxx"
#include "util/NumberParser.hxx"
#include "util/Error.hxx"
#include "util/Domain.hxx"
-#include <glib.h>
-
-#include <assert.h>
-#include <string.h>
+#include <stddef.h>
#define DIRECTORY_DIR "directory: "
#define DIRECTORY_MTIME "mtime: "
@@ -91,7 +90,7 @@ directory_load_subdir(TextFile &file, Directory &parent, const char *name,
return nullptr;
}
- if (g_str_has_prefix(line, DIRECTORY_MTIME)) {
+ if (StringStartsWith(line, DIRECTORY_MTIME)) {
directory->mtime =
ParseUint64(line + sizeof(DIRECTORY_MTIME) - 1);
@@ -103,7 +102,7 @@ directory_load_subdir(TextFile &file, Directory &parent, const char *name,
}
}
- if (!g_str_has_prefix(line, DIRECTORY_BEGIN)) {
+ if (!StringStartsWith(line, DIRECTORY_BEGIN)) {
error.Format(directory_domain, "Malformed line: %s", line);
directory->Delete();
return nullptr;
@@ -124,17 +123,16 @@ directory_load(TextFile &file, Directory &directory, Error &error)
const char *line;
while ((line = file.ReadLine()) != nullptr &&
- !g_str_has_prefix(line, DIRECTORY_END)) {
- if (g_str_has_prefix(line, DIRECTORY_DIR)) {
+ !StringStartsWith(line, DIRECTORY_END)) {
+ if (StringStartsWith(line, DIRECTORY_DIR)) {
Directory *subdir =
directory_load_subdir(file, directory,
line + sizeof(DIRECTORY_DIR) - 1,
error);
if (subdir == nullptr)
return false;
- } else if (g_str_has_prefix(line, SONG_BEGIN)) {
+ } else if (StringStartsWith(line, SONG_BEGIN)) {
const char *name = line + sizeof(SONG_BEGIN) - 1;
- Song *song;
if (directory.FindSong(name) != nullptr) {
error.Format(directory_domain,
@@ -142,24 +140,18 @@ directory_load(TextFile &file, Directory &directory, Error &error)
return false;
}
- song = song_load(file, &directory, name, error);
+ DetachedSong *song = song_load(file, name, error);
if (song == nullptr)
return false;
- directory.AddSong(song);
- } else if (g_str_has_prefix(line, PLAYLIST_META_BEGIN)) {
- /* duplicate the name, because
- playlist_metadata_load() will overwrite the
- buffer */
- char *name = g_strdup(line + sizeof(PLAYLIST_META_BEGIN) - 1);
-
+ directory.AddSong(Song::NewFrom(std::move(*song),
+ directory));
+ delete song;
+ } else if (StringStartsWith(line, PLAYLIST_META_BEGIN)) {
+ const char *name = line + sizeof(PLAYLIST_META_BEGIN) - 1;
if (!playlist_metadata_load(file, directory.playlists,
- name, error)) {
- g_free(name);
+ name, error))
return false;
- }
-
- g_free(name);
} else {
error.Format(directory_domain,
"Malformed line: %s", line);