aboutsummaryrefslogtreecommitdiffstats
path: root/src/StateFile.cxx
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/StateFile.cxx (renamed from src/state_file.c)31
1 files changed, 13 insertions, 18 deletions
diff --git a/src/state_file.c b/src/StateFile.cxx
index de0e70538..cd344eb0e 100644
--- a/src/state_file.c
+++ b/src/StateFile.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2011 The Music Player Daemon Project
+ * Copyright (C) 2003-2013 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -18,12 +18,15 @@
*/
#include "config.h"
-#include "state_file.h"
-#include "output_state.h"
+#include "StateFile.hxx"
+#include "OutputState.hxx"
#include "playlist.h"
-#include "playlist_state.h"
+#include "PlaylistState.hxx"
+#include "TextFile.hxx"
+
+extern "C" {
#include "volume.h"
-#include "text_file.h"
+}
#include <glib.h>
#include <assert.h>
@@ -75,39 +78,31 @@ state_file_write(struct player_control *pc)
static void
state_file_read(struct player_control *pc)
{
- FILE *fp;
bool success;
assert(state_file_path != NULL);
g_debug("Loading state file %s", state_file_path);
- fp = fopen(state_file_path, "r");
- if (G_UNLIKELY(!fp)) {
+ TextFile file(state_file_path);
+ if (file.HasFailed()) {
g_warning("failed to open %s: %s",
state_file_path, g_strerror(errno));
return;
}
- GString *buffer = g_string_sized_new(1024);
const char *line;
- while ((line = read_text_line(fp, buffer)) != NULL) {
+ while ((line = file.ReadLine()) != NULL) {
success = read_sw_volume_state(line) ||
audio_output_state_read(line) ||
- playlist_state_restore(line, fp, buffer,
- &g_playlist, pc);
+ playlist_state_restore(line, file, &g_playlist, pc);
if (!success)
g_warning("Unrecognized line in state file: %s", line);
}
- fclose(fp);
-
prev_volume_version = sw_volume_state_get_hash();
prev_output_version = audio_output_state_get_version();
prev_playlist_version = playlist_state_get_hash(&g_playlist, pc);
-
-
- g_string_free(buffer, true);
}
/**
@@ -117,7 +112,7 @@ state_file_read(struct player_control *pc)
static gboolean
timer_save_state_file(gpointer data)
{
- struct player_control *pc = data;
+ struct player_control *pc = (struct player_control *)data;
if (prev_volume_version == sw_volume_state_get_hash() &&
prev_output_version == audio_output_state_get_version() &&