aboutsummaryrefslogtreecommitdiffstats
path: root/src/playlist_state.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2009-07-15 16:57:37 +0200
committerMax Kellermann <max@duempel.org>2009-07-15 16:57:37 +0200
commitf7cc5b2efddece7cdc4fc5b7fc5324d33b7dfa8f (patch)
treec3b528d0972f857c1d80f0d26eff3491b6929777 /src/playlist_state.c
parentdf7d7732c61deec0102950cb3d79b9bd114e73a9 (diff)
downloadmpd-f7cc5b2efddece7cdc4fc5b7fc5324d33b7dfa8f.tar.gz
mpd-f7cc5b2efddece7cdc4fc5b7fc5324d33b7dfa8f.tar.xz
mpd-f7cc5b2efddece7cdc4fc5b7fc5324d33b7dfa8f.zip
state_file: don't rewind the stream while reading the state file
Parse the state file line by line, let each subsystem probe a line. Only the playlist_state code gets the FILE pointer to read the following lines.
Diffstat (limited to 'src/playlist_state.c')
-rw-r--r--src/playlist_state.c29
1 files changed, 15 insertions, 14 deletions
diff --git a/src/playlist_state.c b/src/playlist_state.c
index c9d3303ac..cbf77813e 100644
--- a/src/playlist_state.c
+++ b/src/playlist_state.c
@@ -115,8 +115,8 @@ playlist_state_load(FILE *fp, struct playlist *playlist, char *buffer)
queue_increment_version(&playlist->queue);
}
-void
-playlist_state_restore(FILE *fp, struct playlist *playlist)
+bool
+playlist_state_restore(const char *line, FILE *fp, struct playlist *playlist)
{
int current = -1;
int seek_time = 0;
@@ -124,21 +124,20 @@ playlist_state_restore(FILE *fp, struct playlist *playlist)
char buffer[PLAYLIST_BUFFER_SIZE];
bool random_mode = false;
+ if (!g_str_has_prefix(line, PLAYLIST_STATE_FILE_STATE))
+ return false;
+
+ line += sizeof(PLAYLIST_STATE_FILE_STATE) - 1;
+
+ if (strcmp(line, PLAYLIST_STATE_FILE_STATE_PLAY) == 0)
+ state = PLAYER_STATE_PLAY;
+ else if (strcmp(line, PLAYLIST_STATE_FILE_STATE_PAUSE) == 0)
+ state = PLAYER_STATE_PAUSE;
+
while (fgets(buffer, sizeof(buffer), fp)) {
g_strchomp(buffer);
- if (g_str_has_prefix(buffer, PLAYLIST_STATE_FILE_STATE)) {
- if (strcmp(&(buffer[strlen(PLAYLIST_STATE_FILE_STATE)]),
- PLAYLIST_STATE_FILE_STATE_PLAY) == 0) {
- state = PLAYER_STATE_PLAY;
- } else
- if (strcmp
- (&(buffer[strlen(PLAYLIST_STATE_FILE_STATE)]),
- PLAYLIST_STATE_FILE_STATE_PAUSE)
- == 0) {
- state = PLAYER_STATE_PAUSE;
- }
- } else if (g_str_has_prefix(buffer, PLAYLIST_STATE_FILE_TIME)) {
+ if (g_str_has_prefix(buffer, PLAYLIST_STATE_FILE_TIME)) {
seek_time =
atoi(&(buffer[strlen(PLAYLIST_STATE_FILE_TIME)]));
} else if (g_str_has_prefix(buffer, PLAYLIST_STATE_FILE_REPEAT)) {
@@ -198,4 +197,6 @@ playlist_state_restore(FILE *fp, struct playlist *playlist)
if (state == PLAYER_STATE_PAUSE)
playerPause();
}
+
+ return true;
}