diff options
Diffstat (limited to 'src/PlaylistSave.cxx')
-rw-r--r-- | src/PlaylistSave.cxx | 73 |
1 files changed, 28 insertions, 45 deletions
diff --git a/src/PlaylistSave.cxx b/src/PlaylistSave.cxx index 29bf193fd..78a8fdb91 100644 --- a/src/PlaylistSave.cxx +++ b/src/PlaylistSave.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 @@ -21,44 +21,44 @@ #include "PlaylistSave.hxx" #include "PlaylistFile.hxx" #include "PlaylistError.hxx" -#include "Playlist.hxx" -#include "Song.hxx" +#include "queue/Playlist.hxx" +#include "DetachedSong.hxx" +#include "SongLoader.hxx" #include "Mapper.hxx" #include "Idle.hxx" #include "fs/AllocatedPath.hxx" #include "fs/Traits.hxx" #include "fs/FileSystem.hxx" +#include "util/Alloc.hxx" #include "util/UriUtil.hxx" #include "util/Error.hxx" #include "Log.hxx" -#include <glib.h> - #include <string.h> void -playlist_print_song(FILE *file, const Song &song) +playlist_print_song(FILE *file, const DetachedSong &song) { - if (playlist_saveAbsolutePaths && song.IsInDatabase()) { - const auto path = map_song_fs(song); - if (!path.IsNull()) - fprintf(file, "%s\n", path.c_str()); - } else { - const auto uri_utf8 = song.GetURI(); - const auto uri_fs = AllocatedPath::FromUTF8(uri_utf8.c_str()); - - if (!uri_fs.IsNull()) - fprintf(file, "%s\n", uri_fs.c_str()); - } + const char *uri_utf8 = playlist_saveAbsolutePaths + ? song.GetRealURI() + : song.GetURI(); + + const auto uri_fs = AllocatedPath::FromUTF8(uri_utf8); + if (!uri_fs.IsNull()) + fprintf(file, "%s\n", uri_fs.c_str()); } void playlist_print_uri(FILE *file, const char *uri) { - auto path = playlist_saveAbsolutePaths && !uri_has_scheme(uri) && - !PathTraits::IsAbsoluteUTF8(uri) + auto path = +#ifdef ENABLE_DATABASE + playlist_saveAbsolutePaths && !uri_has_scheme(uri) && + !PathTraitsUTF8::IsAbsolute(uri) ? map_uri_fs(uri) - : AllocatedPath::FromUTF8(uri); + : +#endif + AllocatedPath::FromUTF8(uri); if (!path.IsNull()) fprintf(file, "%s\n", path.c_str()); @@ -113,34 +113,17 @@ playlist_load_spl(struct playlist &playlist, PlayerControl &pc, if (end_index > contents.size()) end_index = contents.size(); + const SongLoader loader(nullptr, nullptr); + Error error2; + for (unsigned i = start_index; i < end_index; ++i) { const auto &uri_utf8 = contents[i]; - if (memcmp(uri_utf8.c_str(), "file:///", 8) == 0) { - const char *path_utf8 = uri_utf8.c_str() + 7; - - if (playlist.AppendFile(pc, path_utf8) != PlaylistResult::SUCCESS) - FormatError(playlist_domain, - "can't add file \"%s\"", path_utf8); - continue; - } - - if ((playlist.AppendURI(pc, uri_utf8.c_str())) != PlaylistResult::SUCCESS) { - /* for windows compatibility, convert slashes */ - char *temp2 = g_strdup(uri_utf8.c_str()); - char *p = temp2; - while (*p) { - if (*p == '\\') - *p = '/'; - p++; - } - - if (playlist.AppendURI(pc, temp2) != PlaylistResult::SUCCESS) - FormatError(playlist_domain, - "can't add file \"%s\"", temp2); - - g_free(temp2); - } + unsigned id = playlist.AppendURI(pc, loader, uri_utf8.c_str(), + error2); + if (id == 0) + FormatError(error2, "can't add file \"%s\"", + uri_utf8.c_str()); } return true; |