Misc: Swap most C format strings for fmt

This commit is contained in:
Stenzek
2023-09-21 00:32:39 +10:00
parent 92440bdfcf
commit 184b0a1a52
19 changed files with 107 additions and 116 deletions

View File

@@ -269,7 +269,7 @@ std::string Achievements::GetGameHash(CDImage* image)
std::memcpy(&header, executable_data.data(), sizeof(header));
if (!BIOS::IsValidPSExeHeader(header, static_cast<u32>(executable_data.size())))
{
Log_ErrorPrintf("PS-EXE header is invalid in '%s' (%zu bytes)", executable_name.c_str(), executable_data.size());
Log_ErrorFmt("PS-EXE header is invalid in '{}' ({} bytes)", executable_name, executable_data.size());
return {};
}
@@ -286,12 +286,11 @@ std::string Achievements::GetGameHash(CDImage* image)
u8 hash[16];
digest.Final(hash);
std::string hash_str(StringUtil::StdStringFromFormat(
"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", hash[0], hash[1], hash[2], hash[3], hash[4],
hash[5], hash[6], hash[7], hash[8], hash[9], hash[10], hash[11], hash[12], hash[13], hash[14], hash[15]));
const std::string hash_str = fmt::format(
"{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}", hash[0], hash[1], hash[2], hash[3], hash[4],
hash[5], hash[6], hash[7], hash[8], hash[9], hash[10], hash[11], hash[12], hash[13], hash[14], hash[15]);
Log_InfoPrintf("Hash for '%s' (%zu bytes, %u bytes hashed): %s", executable_name.c_str(), executable_data.size(),
hash_size, hash_str.c_str());
Log_InfoFmt("Hash for '{}' ({} bytes, {} bytes hashed): {}", executable_name, executable_data.size(), hash_size, hash_str);
return hash_str;
}
@@ -304,7 +303,7 @@ void Achievements::DownloadImage(std::string url, std::string cache_filename)
if (!FileSystem::WriteBinaryFile(cache_filename.c_str(), data.data(), data.size()))
{
Log_ErrorPrintf("Failed to write badge image to '%s'", cache_filename.c_str());
Log_ErrorFmt("Failed to write badge image to '{}'", cache_filename);
return;
}

View File

@@ -8,6 +8,7 @@
#include "system.h"
#include "common/log.h"
#include "common/small_string.h"
#include "common/string_util.h"
#include <functional>
@@ -65,7 +66,7 @@ static std::optional<std::string_view> DeserializePacket(const std::string_view&
static std::string SerializePacket(const std::string_view& in)
{
std::stringstream ss;
ss << '$' << in << '#' << StringUtil::StdStringFromFormat("%02x", ComputeChecksum(in));
ss << '$' << in << '#' << TinyString::from_fmt("{:02x}", ComputeChecksum(in));
return ss.str();
}

View File

@@ -511,9 +511,8 @@ void GPU::FinishVRAMWrite()
{
if (g_settings.debugging.dump_cpu_to_vram_copies)
{
DumpVRAMToFile(StringUtil::StdStringFromFormat("cpu_to_vram_copy_%u.png", s_cpu_to_vram_dump_id++).c_str(),
m_vram_transfer.width, m_vram_transfer.height, sizeof(u16) * m_vram_transfer.width,
m_blit_buffer.data(), true);
DumpVRAMToFile(TinyString::from_fmt("cpu_to_vram_copy_{}.png", s_cpu_to_vram_dump_id++), m_vram_transfer.width,
m_vram_transfer.height, sizeof(u16) * m_vram_transfer.width, m_blit_buffer.data(), true);
}
if (g_settings.texture_replacements.ShouldDumpVRAMWrite(m_vram_transfer.width, m_vram_transfer.height))
@@ -580,8 +579,8 @@ bool GPU::HandleCopyRectangleVRAMToCPUCommand()
if (g_settings.debugging.dump_vram_to_cpu_copies)
{
DumpVRAMToFile(StringUtil::StdStringFromFormat("vram_to_cpu_copy_%u.png", s_vram_to_cpu_dump_id++).c_str(),
m_vram_transfer.width, m_vram_transfer.height, sizeof(u16) * VRAM_WIDTH,
DumpVRAMToFile(TinyString::from_fmt("vram_to_cpu_copy_{}.png", s_vram_to_cpu_dump_id++), m_vram_transfer.width,
m_vram_transfer.height, sizeof(u16) * VRAM_WIDTH,
&m_vram_ptr[m_vram_transfer.y * VRAM_WIDTH + m_vram_transfer.x], true);
}

View File

@@ -773,8 +773,7 @@ void SaveStateSelectorUI::RefreshHotkeyLegend()
setting = setting.substr(slash_pos + 1);
}
return StringUtil::StdStringFromFormat("%.*s - %.*s", static_cast<int>(setting.size()), setting.data(),
static_cast<int>(caption.size()), caption.data());
return fmt::format("{} - {}", setting, caption);
};
s_load_legend = format_legend_entry(Host::GetStringSettingValue("Hotkeys", "LoadSelectedSaveState"),

View File

@@ -542,7 +542,7 @@ ConsoleRegion System::GetConsoleRegionForDiscRegion(DiscRegion region)
std::string System::GetGameHashId(GameHash hash)
{
return StringUtil::StdStringFromFormat("HASH-%" PRIX64, hash);
return fmt::format("HASH-{:X}", hash);
}
bool System::GetGameDetailsFromImage(CDImage* cdi, std::string* out_id, GameHash* out_hash)
@@ -4255,10 +4255,9 @@ std::optional<ExtendedSaveStateInfo> System::InternalGetExtendedSaveStateInfo(By
ExtendedSaveStateInfo ssi;
if (header.version < SAVE_STATE_MINIMUM_VERSION || header.version > SAVE_STATE_VERSION)
{
ssi.title = StringUtil::StdStringFromFormat(
TRANSLATE("CommonHostInterface", "Invalid version %u (%s version %u)"), header.version,
header.version > SAVE_STATE_VERSION ? "maximum" : "minimum",
header.version > SAVE_STATE_VERSION ? SAVE_STATE_VERSION : SAVE_STATE_MINIMUM_VERSION);
ssi.title = fmt::format(TRANSLATE_FS("System", "Invalid version {} ({} version {})"), header.version,
header.version > SAVE_STATE_VERSION ? "maximum" : "minimum",
header.version > SAVE_STATE_VERSION ? SAVE_STATE_VERSION : SAVE_STATE_MINIMUM_VERSION);
return ssi;
}