*: use BufferedOutputStream::Fmt()
This commit is contained in:
parent
9a30286289
commit
b52b0ac85a
|
@ -33,10 +33,10 @@ void
|
||||||
playlist_vector_save(BufferedOutputStream &os, const PlaylistVector &pv)
|
playlist_vector_save(BufferedOutputStream &os, const PlaylistVector &pv)
|
||||||
{
|
{
|
||||||
for (const PlaylistInfo &pi : pv) {
|
for (const PlaylistInfo &pi : pv) {
|
||||||
os.Format(PLAYLIST_META_BEGIN "%s\n", pi.name.c_str());
|
os.Fmt(FMT_STRING(PLAYLIST_META_BEGIN "{}\n"), pi.name);
|
||||||
if (!IsNegative(pi.mtime))
|
if (!IsNegative(pi.mtime))
|
||||||
os.Format("mtime: %li\n",
|
os.Fmt(FMT_STRING("mtime: {}\n"),
|
||||||
(long)std::chrono::system_clock::to_time_t(pi.mtime));
|
std::chrono::system_clock::to_time_t(pi.mtime));
|
||||||
os.Write("playlist_end\n");
|
os.Write("playlist_end\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,11 +40,11 @@ playlist_print_path(BufferedOutputStream &os, const Path path)
|
||||||
"narrow" charset (i.e. CP_ACP) is incapable of storing all
|
"narrow" charset (i.e. CP_ACP) is incapable of storing all
|
||||||
Unicode paths */
|
Unicode paths */
|
||||||
try {
|
try {
|
||||||
os.Format("%s\n", path.ToUTF8Throw().c_str());
|
os.Fmt(FMT_STRING("{}\n"), path.ToUTF8Throw());
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
os.Format("%s\n", path.c_str());
|
os.Fmt(FMT_STRING("{}\n"), path.c_str());
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#include "db/plugins/simple/Song.hxx"
|
#include "db/plugins/simple/Song.hxx"
|
||||||
#include "song/DetachedSong.hxx"
|
#include "song/DetachedSong.hxx"
|
||||||
#include "TagSave.hxx"
|
#include "TagSave.hxx"
|
||||||
|
#include "lib/fmt/AudioFormatFormatter.hxx"
|
||||||
#include "io/LineReader.hxx"
|
#include "io/LineReader.hxx"
|
||||||
#include "io/BufferedOutputStream.hxx"
|
#include "io/BufferedOutputStream.hxx"
|
||||||
#include "tag/ParseName.hxx"
|
#include "tag/ParseName.hxx"
|
||||||
|
@ -43,45 +44,45 @@ static void
|
||||||
range_save(BufferedOutputStream &os, unsigned start_ms, unsigned end_ms)
|
range_save(BufferedOutputStream &os, unsigned start_ms, unsigned end_ms)
|
||||||
{
|
{
|
||||||
if (end_ms > 0)
|
if (end_ms > 0)
|
||||||
os.Format("Range: %u-%u\n", start_ms, end_ms);
|
os.Fmt(FMT_STRING("Range: {}-{}\n"), start_ms, end_ms);
|
||||||
else if (start_ms > 0)
|
else if (start_ms > 0)
|
||||||
os.Format("Range: %u-\n", start_ms);
|
os.Fmt(FMT_STRING("Range: {}-\n"), start_ms);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
song_save(BufferedOutputStream &os, const Song &song)
|
song_save(BufferedOutputStream &os, const Song &song)
|
||||||
{
|
{
|
||||||
os.Format(SONG_BEGIN "%s\n", song.filename.c_str());
|
os.Fmt(FMT_STRING(SONG_BEGIN "{}\n"), song.filename);
|
||||||
|
|
||||||
if (!song.target.empty())
|
if (!song.target.empty())
|
||||||
os.Format("Target: %s\n", song.target.c_str());
|
os.Fmt(FMT_STRING("Target: {}\n"), song.target);
|
||||||
|
|
||||||
range_save(os, song.start_time.ToMS(), song.end_time.ToMS());
|
range_save(os, song.start_time.ToMS(), song.end_time.ToMS());
|
||||||
|
|
||||||
tag_save(os, song.tag);
|
tag_save(os, song.tag);
|
||||||
|
|
||||||
if (song.audio_format.IsDefined())
|
if (song.audio_format.IsDefined())
|
||||||
os.Format("Format: %s\n", ToString(song.audio_format).c_str());
|
os.Fmt(FMT_STRING("Format: {}\n"), song.audio_format);
|
||||||
|
|
||||||
if (!IsNegative(song.mtime))
|
if (!IsNegative(song.mtime))
|
||||||
os.Format(SONG_MTIME ": %li\n",
|
os.Fmt(FMT_STRING(SONG_MTIME ": {}\n"),
|
||||||
(long)std::chrono::system_clock::to_time_t(song.mtime));
|
std::chrono::system_clock::to_time_t(song.mtime));
|
||||||
os.Format(SONG_END "\n");
|
os.Write(SONG_END "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
song_save(BufferedOutputStream &os, const DetachedSong &song)
|
song_save(BufferedOutputStream &os, const DetachedSong &song)
|
||||||
{
|
{
|
||||||
os.Format(SONG_BEGIN "%s\n", song.GetURI());
|
os.Fmt(FMT_STRING(SONG_BEGIN "{}\n"), song.GetURI());
|
||||||
|
|
||||||
range_save(os, song.GetStartTime().ToMS(), song.GetEndTime().ToMS());
|
range_save(os, song.GetStartTime().ToMS(), song.GetEndTime().ToMS());
|
||||||
|
|
||||||
tag_save(os, song.GetTag());
|
tag_save(os, song.GetTag());
|
||||||
|
|
||||||
if (!IsNegative(song.GetLastModified()))
|
if (!IsNegative(song.GetLastModified()))
|
||||||
os.Format(SONG_MTIME ": %li\n",
|
os.Fmt(FMT_STRING(SONG_MTIME ": {}\n"),
|
||||||
(long)std::chrono::system_clock::to_time_t(song.GetLastModified()));
|
std::chrono::system_clock::to_time_t(song.GetLastModified()));
|
||||||
os.Format(SONG_END "\n");
|
os.Write(SONG_END "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
DetachedSong
|
DetachedSong
|
||||||
|
|
|
@ -27,11 +27,12 @@ void
|
||||||
tag_save(BufferedOutputStream &os, const Tag &tag)
|
tag_save(BufferedOutputStream &os, const Tag &tag)
|
||||||
{
|
{
|
||||||
if (!tag.duration.IsNegative())
|
if (!tag.duration.IsNegative())
|
||||||
os.Format(SONG_TIME "%f\n", tag.duration.ToDoubleS());
|
os.Fmt(FMT_STRING(SONG_TIME "{}\n"), tag.duration.ToDoubleS());
|
||||||
|
|
||||||
if (tag.has_playlist)
|
if (tag.has_playlist)
|
||||||
os.Format("Playlist: yes\n");
|
os.Write("Playlist: yes\n");
|
||||||
|
|
||||||
for (const auto &i : tag)
|
for (const auto &i : tag)
|
||||||
os.Format("%s: %s\n", tag_item_names[i.type], i.value);
|
os.Fmt(FMT_STRING("{}: {}\n"),
|
||||||
|
tag_item_names[i.type], i.value);
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,16 +49,17 @@ static constexpr unsigned OLDEST_DB_FORMAT = 1;
|
||||||
void
|
void
|
||||||
db_save_internal(BufferedOutputStream &os, const Directory &music_root)
|
db_save_internal(BufferedOutputStream &os, const Directory &music_root)
|
||||||
{
|
{
|
||||||
os.Format("%s\n", DIRECTORY_INFO_BEGIN);
|
os.Write(DIRECTORY_INFO_BEGIN "\n");
|
||||||
os.Format(DB_FORMAT_PREFIX "%u\n", DB_FORMAT);
|
os.Fmt(FMT_STRING(DB_FORMAT_PREFIX "{}\n"), DB_FORMAT);
|
||||||
os.Format("%s%s\n", DIRECTORY_MPD_VERSION, VERSION);
|
os.Write(DIRECTORY_MPD_VERSION VERSION "\n");
|
||||||
os.Format("%s%s\n", DIRECTORY_FS_CHARSET, GetFSCharset());
|
os.Fmt(FMT_STRING(DIRECTORY_FS_CHARSET "{}\n"), GetFSCharset());
|
||||||
|
|
||||||
for (unsigned i = 0; i < TAG_NUM_OF_ITEM_TYPES; ++i)
|
for (unsigned i = 0; i < TAG_NUM_OF_ITEM_TYPES; ++i)
|
||||||
if (IsTagEnabled(i))
|
if (IsTagEnabled(i))
|
||||||
os.Format(DB_TAG_PREFIX "%s\n", tag_item_names[i]);
|
os.Fmt(FMT_STRING(DB_TAG_PREFIX "{}\n"),
|
||||||
|
tag_item_names[i]);
|
||||||
|
|
||||||
os.Format("%s\n", DIRECTORY_INFO_END);
|
os.Write(DIRECTORY_INFO_END "\n");
|
||||||
|
|
||||||
directory_save(os, music_root);
|
directory_save(os, music_root);
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,20 +78,20 @@ directory_save(BufferedOutputStream &os, const Directory &directory)
|
||||||
if (!directory.IsRoot()) {
|
if (!directory.IsRoot()) {
|
||||||
const char *type = DeviceToTypeString(directory.device);
|
const char *type = DeviceToTypeString(directory.device);
|
||||||
if (type != nullptr)
|
if (type != nullptr)
|
||||||
os.Format(DIRECTORY_TYPE "%s\n", type);
|
os.Fmt(FMT_STRING(DIRECTORY_TYPE "{}\n"), type);
|
||||||
|
|
||||||
if (!IsNegative(directory.mtime))
|
if (!IsNegative(directory.mtime))
|
||||||
os.Format(DIRECTORY_MTIME "%lu\n",
|
os.Fmt(FMT_STRING(DIRECTORY_MTIME "{}\n"),
|
||||||
(unsigned long)std::chrono::system_clock::to_time_t(directory.mtime));
|
std::chrono::system_clock::to_time_t(directory.mtime));
|
||||||
|
|
||||||
os.Format("%s%s\n", DIRECTORY_BEGIN, directory.GetPath());
|
os.Fmt(FMT_STRING(DIRECTORY_BEGIN "{}\n"), directory.GetPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const auto &child : directory.children) {
|
for (const auto &child : directory.children) {
|
||||||
if (child.IsMount())
|
if (child.IsMount())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
os.Format(DIRECTORY_DIR "%s\n", child.GetName());
|
os.Fmt(FMT_STRING(DIRECTORY_DIR "{}\n"), child.GetName());
|
||||||
directory_save(os, child);
|
directory_save(os, child);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,7 +101,7 @@ directory_save(BufferedOutputStream &os, const Directory &directory)
|
||||||
playlist_vector_save(os, directory.playlists);
|
playlist_vector_save(os, directory.playlists);
|
||||||
|
|
||||||
if (!directory.IsRoot())
|
if (!directory.IsRoot())
|
||||||
os.Format(DIRECTORY_END "%s\n", directory.GetPath());
|
os.Fmt(FMT_STRING(DIRECTORY_END "{}\n"), directory.GetPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
|
|
|
@ -114,7 +114,7 @@ read_sw_volume_state(const char *line, MultipleOutputs &outputs)
|
||||||
void
|
void
|
||||||
save_sw_volume_state(BufferedOutputStream &os)
|
save_sw_volume_state(BufferedOutputStream &os)
|
||||||
{
|
{
|
||||||
os.Format(SW_VOLUME_STATE "%u\n", volume_software_set);
|
os.Fmt(FMT_STRING(SW_VOLUME_STATE "{}\n"), volume_software_set);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned
|
unsigned
|
||||||
|
|
|
@ -43,8 +43,8 @@ audio_output_state_save(BufferedOutputStream &os,
|
||||||
const auto &ao = outputs.Get(i);
|
const auto &ao = outputs.Get(i);
|
||||||
const std::scoped_lock<Mutex> lock(ao.mutex);
|
const std::scoped_lock<Mutex> lock(ao.mutex);
|
||||||
|
|
||||||
os.Format(AUDIO_DEVICE_STATE "%d:%s\n",
|
os.Fmt(FMT_STRING(AUDIO_DEVICE_STATE "{}:{}\n"),
|
||||||
ao.IsEnabled(), ao.GetName());
|
(unsigned)ao.IsEnabled(), ao.GetName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -73,29 +73,32 @@ playlist_state_save(BufferedOutputStream &os, const struct playlist &playlist,
|
||||||
default:
|
default:
|
||||||
os.Write(PLAYLIST_STATE_FILE_STATE_PLAY "\n");
|
os.Write(PLAYLIST_STATE_FILE_STATE_PLAY "\n");
|
||||||
}
|
}
|
||||||
os.Format(PLAYLIST_STATE_FILE_CURRENT "%i\n",
|
os.Fmt(FMT_STRING(PLAYLIST_STATE_FILE_CURRENT "{}\n"),
|
||||||
playlist.queue.OrderToPosition(playlist.current));
|
playlist.queue.OrderToPosition(playlist.current));
|
||||||
os.Format(PLAYLIST_STATE_FILE_TIME "%f\n",
|
os.Fmt(FMT_STRING(PLAYLIST_STATE_FILE_TIME "{}\n"),
|
||||||
player_status.elapsed_time.ToDoubleS());
|
player_status.elapsed_time.ToDoubleS());
|
||||||
} else {
|
} else {
|
||||||
os.Write(PLAYLIST_STATE_FILE_STATE_STOP "\n");
|
os.Write(PLAYLIST_STATE_FILE_STATE_STOP "\n");
|
||||||
|
|
||||||
if (playlist.current >= 0)
|
if (playlist.current >= 0)
|
||||||
os.Format(PLAYLIST_STATE_FILE_CURRENT "%i\n",
|
os.Fmt(FMT_STRING(PLAYLIST_STATE_FILE_CURRENT "{}\n"),
|
||||||
playlist.queue.OrderToPosition(playlist.current));
|
playlist.queue.OrderToPosition(playlist.current));
|
||||||
}
|
}
|
||||||
|
|
||||||
os.Format(PLAYLIST_STATE_FILE_RANDOM "%i\n", playlist.queue.random);
|
os.Fmt(FMT_STRING(PLAYLIST_STATE_FILE_RANDOM "{}\n"),
|
||||||
os.Format(PLAYLIST_STATE_FILE_REPEAT "%i\n", playlist.queue.repeat);
|
(unsigned)playlist.queue.random);
|
||||||
os.Format(PLAYLIST_STATE_FILE_SINGLE "%i\n",
|
os.Fmt(FMT_STRING(PLAYLIST_STATE_FILE_REPEAT "{}\n"),
|
||||||
|
(unsigned)playlist.queue.repeat);
|
||||||
|
os.Fmt(FMT_STRING(PLAYLIST_STATE_FILE_SINGLE "{}\n"),
|
||||||
(int)playlist.queue.single);
|
(int)playlist.queue.single);
|
||||||
os.Format(PLAYLIST_STATE_FILE_CONSUME "%i\n", playlist.queue.consume);
|
os.Fmt(FMT_STRING(PLAYLIST_STATE_FILE_CONSUME "{}\n"),
|
||||||
os.Format(PLAYLIST_STATE_FILE_CROSSFADE "%i\n",
|
(unsigned)playlist.queue.consume);
|
||||||
(int)pc.GetCrossFade().count());
|
os.Fmt(FMT_STRING(PLAYLIST_STATE_FILE_CROSSFADE "{}\n"),
|
||||||
os.Format(PLAYLIST_STATE_FILE_MIXRAMPDB "%f\n",
|
pc.GetCrossFade().count());
|
||||||
(double)pc.GetMixRampDb());
|
os.Fmt(FMT_STRING(PLAYLIST_STATE_FILE_MIXRAMPDB "{}\n"),
|
||||||
os.Format(PLAYLIST_STATE_FILE_MIXRAMPDELAY "%f\n",
|
pc.GetMixRampDb());
|
||||||
pc.GetMixRampDelay().count());
|
os.Fmt(FMT_STRING(PLAYLIST_STATE_FILE_MIXRAMPDELAY "{}\n"),
|
||||||
|
pc.GetMixRampDelay().count());
|
||||||
os.Write(PLAYLIST_STATE_FILE_PLAYLIST_BEGIN "\n");
|
os.Write(PLAYLIST_STATE_FILE_PLAYLIST_BEGIN "\n");
|
||||||
queue_save(os, playlist.queue);
|
queue_save(os, playlist.queue);
|
||||||
os.Write(PLAYLIST_STATE_FILE_PLAYLIST_END "\n");
|
os.Write(PLAYLIST_STATE_FILE_PLAYLIST_END "\n");
|
||||||
|
|
|
@ -38,7 +38,7 @@ static void
|
||||||
queue_save_database_song(BufferedOutputStream &os,
|
queue_save_database_song(BufferedOutputStream &os,
|
||||||
int idx, const DetachedSong &song)
|
int idx, const DetachedSong &song)
|
||||||
{
|
{
|
||||||
os.Format("%i:%s\n", idx, song.GetURI());
|
os.Fmt(FMT_STRING("{}:{}\n"), idx, song.GetURI());
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -67,7 +67,7 @@ queue_save(BufferedOutputStream &os, const Queue &queue)
|
||||||
for (unsigned i = 0; i < queue.GetLength(); i++) {
|
for (unsigned i = 0; i < queue.GetLength(); i++) {
|
||||||
uint8_t prio = queue.GetPriorityAtPosition(i);
|
uint8_t prio = queue.GetPriorityAtPosition(i);
|
||||||
if (prio != 0)
|
if (prio != 0)
|
||||||
os.Format(PRIO_LABEL "%u\n", prio);
|
os.Fmt(FMT_STRING(PRIO_LABEL "{}\n"), prio);
|
||||||
|
|
||||||
queue_save_song(os, i, queue.Get(i));
|
queue_save_song(os, i, queue.Get(i));
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,11 +62,11 @@ storage_state_save(BufferedOutputStream &os, const Instance &instance)
|
||||||
if (uri.empty() || StringIsEmpty(mount_uri))
|
if (uri.empty() || StringIsEmpty(mount_uri))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
os.Format(
|
os.Fmt(FMT_STRING(MOUNT_STATE_BEGIN "\n"
|
||||||
MOUNT_STATE_BEGIN "\n"
|
MOUNT_STATE_STORAGE_URI "{}\n"
|
||||||
MOUNT_STATE_STORAGE_URI "%s\n"
|
MOUNT_STATE_MOUNTED_URL "{}\n"
|
||||||
MOUNT_STATE_MOUNTED_URL "%s\n"
|
MOUNT_STATE_END "\n"),
|
||||||
MOUNT_STATE_END "\n", mount_uri, uri.c_str());
|
mount_uri, uri);
|
||||||
};
|
};
|
||||||
|
|
||||||
((CompositeStorage*)instance.storage)->VisitMounts(visitor);
|
((CompositeStorage*)instance.storage)->VisitMounts(visitor);
|
||||||
|
|
Loading…
Reference in New Issue