diff --git a/src/PlaylistState.cxx b/src/PlaylistState.cxx index 4a4e37345..f5c798e3e 100644 --- a/src/PlaylistState.cxx +++ b/src/PlaylistState.cxx @@ -103,7 +103,8 @@ playlist_state_save(FILE *fp, const struct playlist &playlist, } static void -playlist_state_load(TextFile &file, struct playlist &playlist) +playlist_state_load(TextFile &file, const SongLoader &song_loader, + struct playlist &playlist) { const char *line = file.ReadLine(); if (line == nullptr) { @@ -112,7 +113,7 @@ playlist_state_load(TextFile &file, struct playlist &playlist) } while (!StringStartsWith(line, PLAYLIST_STATE_FILE_PLAYLIST_END)) { - queue_load_song(file, line, playlist.queue); + queue_load_song(file, song_loader, line, playlist.queue); line = file.ReadLine(); if (line == nullptr) { @@ -128,6 +129,7 @@ playlist_state_load(TextFile &file, struct playlist &playlist) bool playlist_state_restore(const char *line, TextFile &file, + const SongLoader &song_loader, struct playlist &playlist, PlayerControl &pc) { int current = -1; @@ -183,7 +185,7 @@ playlist_state_restore(const char *line, TextFile &file, (PLAYLIST_STATE_FILE_CURRENT)])); } else if (StringStartsWith(line, PLAYLIST_STATE_FILE_PLAYLIST_BEGIN)) { - playlist_state_load(file, playlist); + playlist_state_load(file, song_loader, playlist); } } diff --git a/src/PlaylistState.hxx b/src/PlaylistState.hxx index bd48e4543..8d3f88ae2 100644 --- a/src/PlaylistState.hxx +++ b/src/PlaylistState.hxx @@ -30,6 +30,7 @@ struct playlist; struct PlayerControl; class TextFile; +class SongLoader; void playlist_state_save(FILE *fp, const playlist &playlist, @@ -37,6 +38,7 @@ playlist_state_save(FILE *fp, const playlist &playlist, bool playlist_state_restore(const char *line, TextFile &file, + const SongLoader &song_loader, playlist &playlist, PlayerControl &pc); /** diff --git a/src/StateFile.cxx b/src/StateFile.cxx index 7c0e24439..4d2813136 100644 --- a/src/StateFile.cxx +++ b/src/StateFile.cxx @@ -24,7 +24,7 @@ #include "fs/TextFile.hxx" #include "Partition.hxx" #include "mixer/Volume.hxx" - +#include "SongLoader.hxx" #include "fs/FileSystem.hxx" #include "util/Domain.hxx" #include "Log.hxx" @@ -97,11 +97,14 @@ StateFile::Read() return; } + const SongLoader song_loader(nullptr); + const char *line; while ((line = file.ReadLine()) != NULL) { success = read_sw_volume_state(line, partition.outputs) || audio_output_state_read(line, partition.outputs) || - playlist_state_restore(line, file, partition.playlist, + playlist_state_restore(line, file, song_loader, + partition.playlist, partition.pc); if (!success) FormatError(state_file_domain, diff --git a/src/queue/QueueSave.cxx b/src/queue/QueueSave.cxx index 051054da2..28fc361d7 100644 --- a/src/queue/QueueSave.cxx +++ b/src/queue/QueueSave.cxx @@ -23,10 +23,10 @@ #include "PlaylistError.hxx" #include "DetachedSong.hxx" #include "SongSave.hxx" -#include "db/DatabaseSong.hxx" +#include "SongLoader.hxx" +#include "playlist/PlaylistSong.hxx" #include "fs/TextFile.hxx" #include "util/StringUtil.hxx" -#include "util/UriUtil.hxx" #include "util/Error.hxx" #include "fs/Traits.hxx" #include "Log.hxx" @@ -69,7 +69,8 @@ queue_save(FILE *fp, const Queue &queue) } void -queue_load_song(TextFile &file, const char *line, Queue &queue) +queue_load_song(TextFile &file, const SongLoader &loader, + const char *line, Queue &queue) { if (queue.IsFull()) return; @@ -87,8 +88,6 @@ queue_load_song(TextFile &file, const char *line, Queue &queue) if (StringStartsWith(line, SONG_BEGIN)) { const char *uri = line + sizeof(SONG_BEGIN) - 1; - if (!uri_has_scheme(uri) && !PathTraitsUTF8::IsAbsolute(uri)) - return; Error error; song = song_load(file, uri, error); @@ -107,15 +106,12 @@ queue_load_song(TextFile &file, const char *line, Queue &queue) const char *uri = endptr + 1; - if (uri_has_scheme(uri)) { - song = new DetachedSong(uri); - } else { -#ifdef ENABLE_DATABASE - song = DatabaseDetachSong(uri, IgnoreError()); - if (song == nullptr) -#endif - return; - } + song = new DetachedSong(uri); + } + + if (!playlist_check_translate_song(*song, nullptr, loader)) { + delete song; + return; } queue.Append(std::move(*song), priority); diff --git a/src/queue/QueueSave.hxx b/src/queue/QueueSave.hxx index c9a646369..470823a24 100644 --- a/src/queue/QueueSave.hxx +++ b/src/queue/QueueSave.hxx @@ -29,6 +29,7 @@ struct Queue; class TextFile; +class SongLoader; void queue_save(FILE *fp, const Queue &queue); @@ -37,6 +38,7 @@ queue_save(FILE *fp, const Queue &queue); * Loads one song from the state file and appends it to the queue. */ void -queue_load_song(TextFile &file, const char *line, Queue &queue); +queue_load_song(TextFile &file, const SongLoader &loader, + const char *line, Queue &queue); #endif