*: 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)
|
||||
{
|
||||
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))
|
||||
os.Format("mtime: %li\n",
|
||||
(long)std::chrono::system_clock::to_time_t(pi.mtime));
|
||||
os.Fmt(FMT_STRING("mtime: {}\n"),
|
||||
std::chrono::system_clock::to_time_t(pi.mtime));
|
||||
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
|
||||
Unicode paths */
|
||||
try {
|
||||
os.Format("%s\n", path.ToUTF8Throw().c_str());
|
||||
os.Fmt(FMT_STRING("{}\n"), path.ToUTF8Throw());
|
||||
} catch (...) {
|
||||
}
|
||||
#else
|
||||
os.Format("%s\n", path.c_str());
|
||||
os.Fmt(FMT_STRING("{}\n"), path.c_str());
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include "db/plugins/simple/Song.hxx"
|
||||
#include "song/DetachedSong.hxx"
|
||||
#include "TagSave.hxx"
|
||||
#include "lib/fmt/AudioFormatFormatter.hxx"
|
||||
#include "io/LineReader.hxx"
|
||||
#include "io/BufferedOutputStream.hxx"
|
||||
#include "tag/ParseName.hxx"
|
||||
|
@ -43,45 +44,45 @@ static void
|
|||
range_save(BufferedOutputStream &os, unsigned start_ms, unsigned end_ms)
|
||||
{
|
||||
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)
|
||||
os.Format("Range: %u-\n", start_ms);
|
||||
os.Fmt(FMT_STRING("Range: {}-\n"), start_ms);
|
||||
}
|
||||
|
||||
void
|
||||
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())
|
||||
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());
|
||||
|
||||
tag_save(os, song.tag);
|
||||
|
||||
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))
|
||||
os.Format(SONG_MTIME ": %li\n",
|
||||
(long)std::chrono::system_clock::to_time_t(song.mtime));
|
||||
os.Format(SONG_END "\n");
|
||||
os.Fmt(FMT_STRING(SONG_MTIME ": {}\n"),
|
||||
std::chrono::system_clock::to_time_t(song.mtime));
|
||||
os.Write(SONG_END "\n");
|
||||
}
|
||||
|
||||
void
|
||||
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());
|
||||
|
||||
tag_save(os, song.GetTag());
|
||||
|
||||
if (!IsNegative(song.GetLastModified()))
|
||||
os.Format(SONG_MTIME ": %li\n",
|
||||
(long)std::chrono::system_clock::to_time_t(song.GetLastModified()));
|
||||
os.Format(SONG_END "\n");
|
||||
os.Fmt(FMT_STRING(SONG_MTIME ": {}\n"),
|
||||
std::chrono::system_clock::to_time_t(song.GetLastModified()));
|
||||
os.Write(SONG_END "\n");
|
||||
}
|
||||
|
||||
DetachedSong
|
||||
|
|
|
@ -27,11 +27,12 @@ void
|
|||
tag_save(BufferedOutputStream &os, const Tag &tag)
|
||||
{
|
||||
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)
|
||||
os.Format("Playlist: yes\n");
|
||||
os.Write("Playlist: yes\n");
|
||||
|
||||
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
|
||||
db_save_internal(BufferedOutputStream &os, const Directory &music_root)
|
||||
{
|
||||
os.Format("%s\n", DIRECTORY_INFO_BEGIN);
|
||||
os.Format(DB_FORMAT_PREFIX "%u\n", DB_FORMAT);
|
||||
os.Format("%s%s\n", DIRECTORY_MPD_VERSION, VERSION);
|
||||
os.Format("%s%s\n", DIRECTORY_FS_CHARSET, GetFSCharset());
|
||||
os.Write(DIRECTORY_INFO_BEGIN "\n");
|
||||
os.Fmt(FMT_STRING(DB_FORMAT_PREFIX "{}\n"), DB_FORMAT);
|
||||
os.Write(DIRECTORY_MPD_VERSION VERSION "\n");
|
||||
os.Fmt(FMT_STRING(DIRECTORY_FS_CHARSET "{}\n"), GetFSCharset());
|
||||
|
||||
for (unsigned i = 0; i < TAG_NUM_OF_ITEM_TYPES; ++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);
|
||||
}
|
||||
|
|
|
@ -78,20 +78,20 @@ directory_save(BufferedOutputStream &os, const Directory &directory)
|
|||
if (!directory.IsRoot()) {
|
||||
const char *type = DeviceToTypeString(directory.device);
|
||||
if (type != nullptr)
|
||||
os.Format(DIRECTORY_TYPE "%s\n", type);
|
||||
os.Fmt(FMT_STRING(DIRECTORY_TYPE "{}\n"), type);
|
||||
|
||||
if (!IsNegative(directory.mtime))
|
||||
os.Format(DIRECTORY_MTIME "%lu\n",
|
||||
(unsigned long)std::chrono::system_clock::to_time_t(directory.mtime));
|
||||
os.Fmt(FMT_STRING(DIRECTORY_MTIME "{}\n"),
|
||||
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) {
|
||||
if (child.IsMount())
|
||||
continue;
|
||||
|
||||
os.Format(DIRECTORY_DIR "%s\n", child.GetName());
|
||||
os.Fmt(FMT_STRING(DIRECTORY_DIR "{}\n"), child.GetName());
|
||||
directory_save(os, child);
|
||||
}
|
||||
|
||||
|
@ -101,7 +101,7 @@ directory_save(BufferedOutputStream &os, const Directory &directory)
|
|||
playlist_vector_save(os, directory.playlists);
|
||||
|
||||
if (!directory.IsRoot())
|
||||
os.Format(DIRECTORY_END "%s\n", directory.GetPath());
|
||||
os.Fmt(FMT_STRING(DIRECTORY_END "{}\n"), directory.GetPath());
|
||||
}
|
||||
|
||||
static bool
|
||||
|
|
|
@ -114,7 +114,7 @@ read_sw_volume_state(const char *line, MultipleOutputs &outputs)
|
|||
void
|
||||
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
|
||||
|
|
|
@ -43,8 +43,8 @@ audio_output_state_save(BufferedOutputStream &os,
|
|||
const auto &ao = outputs.Get(i);
|
||||
const std::scoped_lock<Mutex> lock(ao.mutex);
|
||||
|
||||
os.Format(AUDIO_DEVICE_STATE "%d:%s\n",
|
||||
ao.IsEnabled(), ao.GetName());
|
||||
os.Fmt(FMT_STRING(AUDIO_DEVICE_STATE "{}:{}\n"),
|
||||
(unsigned)ao.IsEnabled(), ao.GetName());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -73,29 +73,32 @@ playlist_state_save(BufferedOutputStream &os, const struct playlist &playlist,
|
|||
default:
|
||||
os.Write(PLAYLIST_STATE_FILE_STATE_PLAY "\n");
|
||||
}
|
||||
os.Format(PLAYLIST_STATE_FILE_CURRENT "%i\n",
|
||||
playlist.queue.OrderToPosition(playlist.current));
|
||||
os.Format(PLAYLIST_STATE_FILE_TIME "%f\n",
|
||||
player_status.elapsed_time.ToDoubleS());
|
||||
os.Fmt(FMT_STRING(PLAYLIST_STATE_FILE_CURRENT "{}\n"),
|
||||
playlist.queue.OrderToPosition(playlist.current));
|
||||
os.Fmt(FMT_STRING(PLAYLIST_STATE_FILE_TIME "{}\n"),
|
||||
player_status.elapsed_time.ToDoubleS());
|
||||
} else {
|
||||
os.Write(PLAYLIST_STATE_FILE_STATE_STOP "\n");
|
||||
|
||||
if (playlist.current >= 0)
|
||||
os.Format(PLAYLIST_STATE_FILE_CURRENT "%i\n",
|
||||
playlist.queue.OrderToPosition(playlist.current));
|
||||
os.Fmt(FMT_STRING(PLAYLIST_STATE_FILE_CURRENT "{}\n"),
|
||||
playlist.queue.OrderToPosition(playlist.current));
|
||||
}
|
||||
|
||||
os.Format(PLAYLIST_STATE_FILE_RANDOM "%i\n", playlist.queue.random);
|
||||
os.Format(PLAYLIST_STATE_FILE_REPEAT "%i\n", playlist.queue.repeat);
|
||||
os.Format(PLAYLIST_STATE_FILE_SINGLE "%i\n",
|
||||
os.Fmt(FMT_STRING(PLAYLIST_STATE_FILE_RANDOM "{}\n"),
|
||||
(unsigned)playlist.queue.random);
|
||||
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);
|
||||
os.Format(PLAYLIST_STATE_FILE_CONSUME "%i\n", playlist.queue.consume);
|
||||
os.Format(PLAYLIST_STATE_FILE_CROSSFADE "%i\n",
|
||||
(int)pc.GetCrossFade().count());
|
||||
os.Format(PLAYLIST_STATE_FILE_MIXRAMPDB "%f\n",
|
||||
(double)pc.GetMixRampDb());
|
||||
os.Format(PLAYLIST_STATE_FILE_MIXRAMPDELAY "%f\n",
|
||||
pc.GetMixRampDelay().count());
|
||||
os.Fmt(FMT_STRING(PLAYLIST_STATE_FILE_CONSUME "{}\n"),
|
||||
(unsigned)playlist.queue.consume);
|
||||
os.Fmt(FMT_STRING(PLAYLIST_STATE_FILE_CROSSFADE "{}\n"),
|
||||
pc.GetCrossFade().count());
|
||||
os.Fmt(FMT_STRING(PLAYLIST_STATE_FILE_MIXRAMPDB "{}\n"),
|
||||
pc.GetMixRampDb());
|
||||
os.Fmt(FMT_STRING(PLAYLIST_STATE_FILE_MIXRAMPDELAY "{}\n"),
|
||||
pc.GetMixRampDelay().count());
|
||||
os.Write(PLAYLIST_STATE_FILE_PLAYLIST_BEGIN "\n");
|
||||
queue_save(os, playlist.queue);
|
||||
os.Write(PLAYLIST_STATE_FILE_PLAYLIST_END "\n");
|
||||
|
|
|
@ -38,7 +38,7 @@ static void
|
|||
queue_save_database_song(BufferedOutputStream &os,
|
||||
int idx, const DetachedSong &song)
|
||||
{
|
||||
os.Format("%i:%s\n", idx, song.GetURI());
|
||||
os.Fmt(FMT_STRING("{}:{}\n"), idx, song.GetURI());
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -67,7 +67,7 @@ queue_save(BufferedOutputStream &os, const Queue &queue)
|
|||
for (unsigned i = 0; i < queue.GetLength(); i++) {
|
||||
uint8_t prio = queue.GetPriorityAtPosition(i);
|
||||
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));
|
||||
}
|
||||
|
|
|
@ -62,11 +62,11 @@ storage_state_save(BufferedOutputStream &os, const Instance &instance)
|
|||
if (uri.empty() || StringIsEmpty(mount_uri))
|
||||
return;
|
||||
|
||||
os.Format(
|
||||
MOUNT_STATE_BEGIN "\n"
|
||||
MOUNT_STATE_STORAGE_URI "%s\n"
|
||||
MOUNT_STATE_MOUNTED_URL "%s\n"
|
||||
MOUNT_STATE_END "\n", mount_uri, uri.c_str());
|
||||
os.Fmt(FMT_STRING(MOUNT_STATE_BEGIN "\n"
|
||||
MOUNT_STATE_STORAGE_URI "{}\n"
|
||||
MOUNT_STATE_MOUNTED_URL "{}\n"
|
||||
MOUNT_STATE_END "\n"),
|
||||
mount_uri, uri);
|
||||
};
|
||||
|
||||
((CompositeStorage*)instance.storage)->VisitMounts(visitor);
|
||||
|
|
Loading…
Reference in New Issue