StateFile: move code to RememberVersions(), IsModified()
This commit is contained in:
parent
484841fc9e
commit
96882175f1
@ -44,6 +44,24 @@ StateFile::StateFile(Path &&_path, const char *_path_utf8,
|
|||||||
ScheduleSeconds(5 * 60);
|
ScheduleSeconds(5 * 60);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
StateFile::RememberVersions()
|
||||||
|
{
|
||||||
|
prev_volume_version = sw_volume_state_get_hash();
|
||||||
|
prev_output_version = audio_output_state_get_version();
|
||||||
|
prev_playlist_version = playlist_state_get_hash(&partition.playlist,
|
||||||
|
&partition.pc);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
StateFile::IsModified() const
|
||||||
|
{
|
||||||
|
return prev_volume_version != sw_volume_state_get_hash() ||
|
||||||
|
prev_output_version != audio_output_state_get_version() ||
|
||||||
|
prev_playlist_version != playlist_state_get_hash(&partition.playlist,
|
||||||
|
&partition.pc);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
StateFile::Write()
|
StateFile::Write()
|
||||||
{
|
{
|
||||||
@ -62,10 +80,7 @@ StateFile::Write()
|
|||||||
|
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
||||||
prev_volume_version = sw_volume_state_get_hash();
|
RememberVersions();
|
||||||
prev_output_version = audio_output_state_get_version();
|
|
||||||
prev_playlist_version = playlist_state_get_hash(&partition.playlist,
|
|
||||||
&partition.pc);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -92,19 +107,13 @@ StateFile::Read()
|
|||||||
g_warning("Unrecognized line in state file: %s", line);
|
g_warning("Unrecognized line in state file: %s", line);
|
||||||
}
|
}
|
||||||
|
|
||||||
prev_volume_version = sw_volume_state_get_hash();
|
RememberVersions();
|
||||||
prev_output_version = audio_output_state_get_version();
|
|
||||||
prev_playlist_version = playlist_state_get_hash(&partition.playlist,
|
|
||||||
&partition.pc);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void
|
inline void
|
||||||
StateFile::AutoWrite()
|
StateFile::AutoWrite()
|
||||||
{
|
{
|
||||||
if (prev_volume_version == sw_volume_state_get_hash() &&
|
if (!IsModified())
|
||||||
prev_output_version == audio_output_state_get_version() &&
|
|
||||||
prev_playlist_version == playlist_state_get_hash(&partition.playlist,
|
|
||||||
&partition.pc))
|
|
||||||
/* nothing has changed - don't save the state file,
|
/* nothing has changed - don't save the state file,
|
||||||
don't spin up the hard disk */
|
don't spin up the hard disk */
|
||||||
return;
|
return;
|
||||||
|
@ -49,6 +49,18 @@ public:
|
|||||||
void Write();
|
void Write();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
/**
|
||||||
|
* Save the current state versions for use with IsModified().
|
||||||
|
*/
|
||||||
|
void RememberVersions();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if MPD's state was modified since the last
|
||||||
|
* RememberVersions() call.
|
||||||
|
*/
|
||||||
|
gcc_pure
|
||||||
|
bool IsModified() const;
|
||||||
|
|
||||||
void AutoWrite();
|
void AutoWrite();
|
||||||
|
|
||||||
/* virtual methods from TimeoutMonitor */
|
/* virtual methods from TimeoutMonitor */
|
||||||
|
Loading…
Reference in New Issue
Block a user