diff options
Diffstat (limited to 'src/PlaylistSave.cxx')
-rw-r--r-- | src/PlaylistSave.cxx | 55 |
1 files changed, 20 insertions, 35 deletions
diff --git a/src/PlaylistSave.cxx b/src/PlaylistSave.cxx index 29bf193fd..d3369c9b6 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 @@ -22,30 +22,31 @@ #include "PlaylistFile.hxx" #include "PlaylistError.hxx" #include "Playlist.hxx" -#include "Song.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()) { + if (playlist_saveAbsolutePaths && + song.IsInDatabase() && song.IsFile()) { 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()); + const auto uri_fs = AllocatedPath::FromUTF8(uri_utf8); if (!uri_fs.IsNull()) fprintf(file, "%s\n", uri_fs.c_str()); @@ -55,10 +56,14 @@ playlist_print_song(FILE *file, const Song &song) 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 +118,14 @@ playlist_load_spl(struct playlist &playlist, PlayerControl &pc, if (end_index > contents.size()) end_index = contents.size(); + const SongLoader loader(nullptr); + 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); - } + if ((playlist.AppendURI(pc, loader, uri_utf8.c_str())) != PlaylistResult::SUCCESS) + FormatError(playlist_domain, + "can't add file \"%s\"", uri_utf8.c_str()); } return true; |