From ca36ac2ba196ee2bbe4b54ee9a71d49174803277 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sun, 2 Feb 2014 14:37:52 +0100 Subject: SongLoader: new class that merges duplicate code There was quite a lot of duplicate code for loading DetachedSong objects, with different semantics for "securely" loading local files. --- src/PlaylistSave.cxx | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) (limited to 'src/PlaylistSave.cxx') diff --git a/src/PlaylistSave.cxx b/src/PlaylistSave.cxx index f2541e71b..d3369c9b6 100644 --- a/src/PlaylistSave.cxx +++ b/src/PlaylistSave.cxx @@ -23,6 +23,7 @@ #include "PlaylistError.hxx" #include "Playlist.hxx" #include "DetachedSong.hxx" +#include "SongLoader.hxx" #include "Mapper.hxx" #include "Idle.hxx" #include "fs/AllocatedPath.hxx" @@ -117,19 +118,12 @@ 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) + if ((playlist.AppendURI(pc, loader, uri_utf8.c_str())) != PlaylistResult::SUCCESS) FormatError(playlist_domain, "can't add file \"%s\"", uri_utf8.c_str()); } -- cgit v1.2.3