Merge pull request #8418 from lioncash/core-fmt

Core: Replace usages of StringFromFormat with fmt where applicable
This commit is contained in:
Léo Lam 2019-11-16 18:09:58 +01:00 committed by GitHub
commit a77108236e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
31 changed files with 221 additions and 165 deletions

View File

@ -1,13 +1,14 @@
#include "Core/Analytics.h"
#include <array>
#include <cinttypes>
#include <mbedtls/sha1.h>
#include <memory>
#include <mutex>
#include <string>
#include <vector>
#include <fmt/format.h>
#include <mbedtls/sha1.h>
#if defined(_WIN32)
#include <windows.h>
#elif defined(__APPLE__)
@ -21,7 +22,6 @@
#include "Common/CPUDetect.h"
#include "Common/CommonTypes.h"
#include "Common/Random.h"
#include "Common/StringUtil.h"
#include "Common/Timer.h"
#include "Common/Version.h"
#include "Core/Config/MainSettings.h"
@ -87,7 +87,7 @@ void DolphinAnalytics::GenerateNewIdentity()
{
const u64 id_high = Common::Random::GenerateValue<u64>();
const u64 id_low = Common::Random::GenerateValue<u64>();
m_unique_id = StringFromFormat("%016" PRIx64 "%016" PRIx64, id_high, id_low);
m_unique_id = fmt::format("{:016x}{:016x}", id_high, id_low);
// Save the new id in the configuration.
SConfig::GetInstance().m_analytics_id = m_unique_id;
@ -104,7 +104,7 @@ std::string DolphinAnalytics::MakeUniqueId(std::string_view data) const
std::string out;
for (int i = 0; i < 8; ++i)
{
out += StringFromFormat("%02hhx", digest[i]);
out += fmt::format("{:02x}", digest[i]);
}
return out;
}

View File

@ -22,12 +22,13 @@
#include <array>
#include <string>
#include <fmt/format.h>
#include "Common/CommonTypes.h"
#include "Common/Config/Config.h"
#include "Common/FileUtil.h"
#include "Common/IniFile.h"
#include "Common/Logging/Log.h"
#include "Common/StringUtil.h"
#include "Core/Boot/Boot.h"
#include "Core/Config/MainSettings.h"
@ -288,7 +289,7 @@ bool BootCore(std::unique_ptr<BootParameters> boot, const WindowSystemInfo& wsi)
for (unsigned int i = 0; i < SerialInterface::MAX_SI_CHANNELS; ++i)
{
int source;
controls_section->Get(StringFromFormat("PadType%u", i), &source, -1);
controls_section->Get(fmt::format("PadType{}", i), &source, -1);
if (source >= SerialInterface::SIDEVICE_NONE && source < SerialInterface::SIDEVICE_COUNT)
{
StartUp.m_SIDevice[i] = static_cast<SerialInterface::SIDevices>(source);
@ -302,7 +303,7 @@ bool BootCore(std::unique_ptr<BootParameters> boot, const WindowSystemInfo& wsi)
int source;
for (unsigned int i = 0; i < MAX_WIIMOTES; ++i)
{
controls_section->Get(StringFromFormat("WiimoteSource%u", i), &source, -1);
controls_section->Get(fmt::format("WiimoteSource{}", i), &source, -1);
if (source != -1 && g_wiimote_sources[i] != (unsigned)source &&
source >= WIIMOTE_SRC_NONE && source <= WIIMOTE_SRC_REAL)
{
@ -340,12 +341,14 @@ bool BootCore(std::unique_ptr<BootParameters> boot, const WindowSystemInfo& wsi)
{
if (Movie::IsUsingMemcard(i) && Movie::IsStartingFromClearSave() && !StartUp.bWii)
{
if (File::Exists(File::GetUserPath(D_GCUSER_IDX) +
StringFromFormat("Movie%s.raw", (i == 0) ? "A" : "B")))
File::Delete(File::GetUserPath(D_GCUSER_IDX) +
StringFromFormat("Movie%s.raw", (i == 0) ? "A" : "B"));
if (File::Exists(File::GetUserPath(D_GCUSER_IDX) + "Movie"))
File::DeleteDirRecursively(File::GetUserPath(D_GCUSER_IDX) + "Movie");
const auto raw_path =
File::GetUserPath(D_GCUSER_IDX) + fmt::format("Movie{}.raw", (i == 0) ? 'A' : 'B');
if (File::Exists(raw_path))
File::Delete(raw_path);
const auto movie_path = File::GetUserPath(D_GCUSER_IDX) + "Movie";
if (File::Exists(movie_path))
File::DeleteDirRecursively(movie_path);
}
}
}

View File

@ -4,9 +4,10 @@
#include "Core/Config/MainSettings.h"
#include <fmt/format.h>
#include "AudioCommon/AudioCommon.h"
#include "Common/Config/Config.h"
#include "Common/StringUtil.h"
#include "Core/HW/EXI/EXI_Device.h"
#include "Core/HW/SI/SI_Device.h"
#include "Core/PowerPC/PowerPC.h"
@ -56,19 +57,19 @@ const ConfigInfo<std::string> MAIN_BBA_MAC{{System::Main, "Core", "BBA_MAC"}, ""
ConfigInfo<u32> GetInfoForSIDevice(u32 channel)
{
return {{System::Main, "Core", StringFromFormat("SIDevice%u", channel)},
return {{System::Main, "Core", fmt::format("SIDevice{}", channel)},
static_cast<u32>(channel == 0 ? SerialInterface::SIDEVICE_GC_CONTROLLER :
SerialInterface::SIDEVICE_NONE)};
}
ConfigInfo<bool> GetInfoForAdapterRumble(u32 channel)
{
return {{System::Main, "Core", StringFromFormat("AdapterRumble%u", channel)}, true};
return {{System::Main, "Core", fmt::format("AdapterRumble{}", channel)}, true};
}
ConfigInfo<bool> GetInfoForSimulateKonga(u32 channel)
{
return {{System::Main, "Core", StringFromFormat("SimulateKonga%u", channel)}, false};
return {{System::Main, "Core", fmt::format("SimulateKonga{}", channel)}, false};
}
const ConfigInfo<bool> MAIN_WII_SD_CARD{{System::Main, "Core", "WiiSDCard"}, false};

View File

@ -15,6 +15,8 @@
#include <utility>
#include <vector>
#include <fmt/format.h>
#include "Common/CommonPaths.h"
#include "Common/Config/Config.h"
#include "Common/FileUtil.h"
@ -23,8 +25,6 @@
#include "Common/MsgHandler.h"
#include "Common/StringUtil.h"
#include "Common/Config/Config.h"
#include "Core/Config/GraphicsSettings.h"
#include "Core/Config/SYSCONFSettings.h"
#include "Core/ConfigLoaders/IsSettingSaveable.h"
@ -54,7 +54,7 @@ std::vector<std::string> GetGameIniFilenames(const std::string& id, std::optiona
// INIs with specific revisions
if (revision)
filenames.push_back(id + StringFromFormat("r%d", *revision) + ".ini");
filenames.push_back(id + fmt::format("r{}", *revision) + ".ini");
return filenames;
}
@ -292,7 +292,7 @@ void INIGameConfigLayerLoader::Save(Config::Layer* layer)
// Try to save to the revision specific INI first, if it exists.
const std::string gameini_with_rev =
File::GetUserPath(D_GAMESETTINGS_IDX) + m_id + StringFromFormat("r%d", m_revision) + ".ini";
File::GetUserPath(D_GAMESETTINGS_IDX) + m_id + fmt::format("r{}", m_revision) + ".ini";
if (File::Exists(gameini_with_rev))
{
ini.Save(gameini_with_rev);

View File

@ -6,6 +6,8 @@
#include <memory>
#include <fmt/format.h>
#include "Common/CommonPaths.h"
#include "Common/Config/Config.h"
#include "Common/FileUtil.h"
@ -100,10 +102,12 @@ public:
layer->Set(Config::MAIN_GCI_FOLDER_A_PATH_OVERRIDE, path + "Card A");
layer->Set(Config::MAIN_GCI_FOLDER_B_PATH_OVERRIDE, path + "Card B");
const std::string file = File::GetUserPath(D_GCUSER_IDX) + GC_MEMCARD_NETPLAY + "%c." +
m_settings.m_SaveDataRegion + ".raw";
layer->Set(Config::MAIN_MEMCARD_A_PATH, StringFromFormat(file.c_str(), 'A'));
layer->Set(Config::MAIN_MEMCARD_B_PATH, StringFromFormat(file.c_str(), 'B'));
const auto make_memcard_path = [this](char letter) {
return fmt::format("{}{}{}.{}.raw", File::GetUserPath(D_GCUSER_IDX), GC_MEMCARD_NETPLAY,
letter, m_settings.m_SaveDataRegion);
};
layer->Set(Config::MAIN_MEMCARD_A_PATH, make_memcard_path('A'));
layer->Set(Config::MAIN_MEMCARD_B_PATH, make_memcard_path('B'));
}
layer->Set(Config::MAIN_GCI_FOLDER_CURRENT_GAME_ONLY, true);

View File

@ -11,6 +11,8 @@
#include <sstream>
#include <variant>
#include <fmt/format.h>
#include "AudioCommon/AudioCommon.h"
#include "Common/Assert.h"
@ -117,13 +119,13 @@ void SConfig::SaveGeneralSettings(IniFile& ini)
general->Get("ISOPaths", &oldPaths, 0);
for (int i = numPaths; i < oldPaths; i++)
{
ini.DeleteKey("General", StringFromFormat("ISOPath%i", i));
ini.DeleteKey("General", fmt::format("ISOPath{}", i));
}
general->Set("ISOPaths", numPaths);
for (int i = 0; i < numPaths; i++)
{
general->Set(StringFromFormat("ISOPath%i", i), m_ISOFolder[i]);
general->Set(fmt::format("ISOPath{}", i), m_ISOFolder[i]);
}
general->Set("RecursiveISOPaths", m_RecursiveISOFolder);
@ -224,9 +226,9 @@ void SConfig::SaveCoreSettings(IniFile& ini)
core->Set("BBA_MAC", m_bba_mac);
for (int i = 0; i < SerialInterface::MAX_SI_CHANNELS; ++i)
{
core->Set(StringFromFormat("SIDevice%i", i), m_SIDevice[i]);
core->Set(StringFromFormat("AdapterRumble%i", i), m_AdapterRumble[i]);
core->Set(StringFromFormat("SimulateKonga%i", i), m_AdapterKonga[i]);
core->Set(fmt::format("SIDevice{}", i), m_SIDevice[i]);
core->Set(fmt::format("AdapterRumble{}", i), m_AdapterRumble[i]);
core->Set(fmt::format("SimulateKonga{}", i), m_AdapterKonga[i]);
}
core->Set("WiiSDCard", m_WiiSDCard);
core->Set("WiiKeyboard", m_WiiKeyboard);
@ -323,7 +325,7 @@ void SConfig::SaveUSBPassthroughSettings(IniFile& ini)
std::ostringstream oss;
for (const auto& device : m_usb_passthrough_devices)
oss << StringFromFormat("%04x:%04x", device.first, device.second) << ',';
oss << fmt::format("{:04x}:{:04x}", device.first, device.second) << ',';
std::string devices_string = oss.str();
if (!devices_string.empty())
devices_string.pop_back();
@ -399,7 +401,7 @@ void SConfig::LoadGeneralSettings(IniFile& ini)
for (int i = 0; i < numISOPaths; i++)
{
std::string tmpPath;
general->Get(StringFromFormat("ISOPath%i", i), &tmpPath, "");
general->Get(fmt::format("ISOPath{}", i), &tmpPath, "");
m_ISOFolder.push_back(std::move(tmpPath));
}
}
@ -496,12 +498,12 @@ void SConfig::LoadCoreSettings(IniFile& ini)
core->Get("SlotB", (int*)&m_EXIDevice[1], ExpansionInterface::EXIDEVICE_NONE);
core->Get("SerialPort1", (int*)&m_EXIDevice[2], ExpansionInterface::EXIDEVICE_NONE);
core->Get("BBA_MAC", &m_bba_mac);
for (int i = 0; i < SerialInterface::MAX_SI_CHANNELS; ++i)
for (size_t i = 0; i < std::size(m_SIDevice); ++i)
{
core->Get(StringFromFormat("SIDevice%i", i), (u32*)&m_SIDevice[i],
core->Get(fmt::format("SIDevice{}", i), &m_SIDevice[i],
(i == 0) ? SerialInterface::SIDEVICE_GC_CONTROLLER : SerialInterface::SIDEVICE_NONE);
core->Get(StringFromFormat("AdapterRumble%i", i), &m_AdapterRumble[i], true);
core->Get(StringFromFormat("SimulateKonga%i", i), &m_AdapterKonga[i], false);
core->Get(fmt::format("AdapterRumble{}", i), &m_AdapterRumble[i], true);
core->Get(fmt::format("SimulateKonga{}", i), &m_AdapterKonga[i], false);
}
core->Get("WiiSDCard", &m_WiiSDCard, false);
core->Get("WiiKeyboard", &m_WiiKeyboard, false);
@ -702,7 +704,7 @@ void SConfig::SetRunningGameMetadata(const std::string& game_id, const std::stri
else if (title_id != 0)
{
m_debugger_game_id =
StringFromFormat("%08X_%08X", static_cast<u32>(title_id >> 32), static_cast<u32>(title_id));
fmt::format("{:08X}_{:08X}", static_cast<u32>(title_id >> 32), static_cast<u32>(title_id));
}
else
{

View File

@ -11,12 +11,12 @@
#include <unordered_map>
#include <vector>
#include <fmt/format.h>
#include "Common/Assert.h"
#include "Common/ChunkFile.h"
#include "Common/Logging/Log.h"
#include "Common/SPSCQueue.h"
#include "Common/StringUtil.h"
#include "Common/Thread.h"
#include "Core/ConfigManager.h"
#include "Core/Core.h"
@ -396,8 +396,7 @@ std::string GetScheduledEventsSummary()
std::sort(clone.begin(), clone.end());
for (const Event& ev : clone)
{
text += StringFromFormat("%s : %" PRIi64 " %016" PRIx64 "\n", ev.type->name->c_str(), ev.time,
ev.userdata);
text += fmt::format("{} : {} {:016x}\n", *ev.type->name, ev.time, ev.userdata);
}
return text;
}

View File

@ -17,6 +17,8 @@
#include <utility>
#include <vector>
#include <fmt/format.h>
#include "Common/CommonTypes.h"
#include "Common/FileUtil.h"
#include "Common/StringUtil.h"
@ -91,7 +93,7 @@ void DSPAssembler::ShowError(AssemblerError err_code, const char* extra_info)
if (!m_settings.force)
m_failed = true;
std::string error = StringFromFormat("%u : %s ", m_code_line, m_cur_line.c_str());
std::string error = fmt::format("{} : {} ", m_code_line, m_cur_line);
if (!extra_info)
extra_info = "-";
@ -99,11 +101,11 @@ void DSPAssembler::ShowError(AssemblerError err_code, const char* extra_info)
if (m_current_param == 0)
{
error += StringFromFormat("ERROR: %s Line: %u : %s\n", error_string, m_code_line, extra_info);
error += fmt::format("ERROR: {} Line: {} : {}\n", error_string, m_code_line, extra_info);
}
else
{
error += StringFromFormat("ERROR: %s Line: %u Param: %d : %s\n", error_string, m_code_line,
error += fmt::format("ERROR: {} Line: {} Param: {} : {}\n", error_string, m_code_line,
m_current_param, extra_info);
}
@ -958,7 +960,7 @@ bool DSPAssembler::AssemblePass(const std::string& text, int pass)
{
if (m_cur_addr > params[0].val)
{
std::string msg = StringFromFormat("WARNPC at 0x%04x, expected 0x%04x or less",
const std::string msg = fmt::format("WARNPC at 0x{:04x}, expected 0x{:04x} or less",
m_cur_addr, params[0].val);
ShowError(AssemblerError::PCOutOfRange, msg.c_str());
}

View File

@ -9,6 +9,8 @@
#include <string>
#include <vector>
#include <fmt/format.h>
#include "Common/CommonTypes.h"
#include "Common/File.h"
#include "Common/FileUtil.h"
@ -147,7 +149,7 @@ bool SaveBinary(const std::vector<u16>& code, const std::string& filename)
bool DumpDSPCode(const u8* code_be, int size_in_bytes, u32 crc)
{
const std::string root_name =
File::GetUserPath(D_DUMPDSP_IDX) + StringFromFormat("DSP_UC_%08X", crc);
File::GetUserPath(D_DUMPDSP_IDX) + fmt::format("DSP_UC_{:08X}", crc);
const std::string binary_file = root_name + ".bin";
const std::string text_file = root_name + ".txt";

View File

@ -10,6 +10,8 @@
#include <string>
#include <vector>
#include <fmt/format.h>
#include "Common/CommonTypes.h"
#include "Common/Logging/Log.h"
#include "Common/StringUtil.h"
@ -73,16 +75,16 @@ std::string DSPDisassembler::DisassembleParameters(const DSPOPCTemplate& opc, u1
{
case P_REG:
if (settings_.decode_registers)
buf += StringFromFormat("$%s", pdregname(val));
buf += fmt::format("${}", pdregname(val));
else
buf += StringFromFormat("$%d", val);
buf += fmt::format("${}", val);
break;
case P_PRG:
if (settings_.decode_registers)
buf += StringFromFormat("@$%s", pdregname(val));
buf += fmt::format("@${}", pdregname(val));
else
buf += StringFromFormat("@$%d", val);
buf += fmt::format("@${}", val);
break;
case P_VAL:
@ -94,22 +96,27 @@ std::string DSPDisassembler::DisassembleParameters(const DSPOPCTemplate& opc, u1
}
else
{
buf += StringFromFormat("0x%04x", val);
buf += fmt::format("0x{:04x}", val);
}
break;
case P_IMM:
if (opc.params[j].size != 2)
{
if (opc.params[j].mask == 0x003f) // LSL, LSR, ASL, ASR
buf += StringFromFormat("#%d",
(val & 0x20) ? (val | 0xFFFFFFC0) : val); // 6-bit sign extension
else
buf += StringFromFormat("#0x%02x", val);
// LSL, LSR, ASL, ASR
if (opc.params[j].mask == 0x003f)
{
// 6-bit sign extension
buf += fmt::format("#{}", (val & 0x20) != 0 ? (val | 0xFFFFFFC0) : val);
}
else
{
buf += StringFromFormat("#0x%04x", val);
buf += fmt::format("#0x{:02x}", val);
}
}
else
{
buf += fmt::format("#0x{:04x}", val);
}
break;
@ -118,9 +125,9 @@ std::string DSPDisassembler::DisassembleParameters(const DSPOPCTemplate& opc, u1
val = (u16)(s16)(s8)val;
if (settings_.decode_names)
buf += StringFromFormat("@%s", pdname(val));
buf += fmt::format("@{}", pdname(val));
else
buf += StringFromFormat("@0x%04x", val);
buf += fmt::format("@0x{:04x}", val);
break;
default:
@ -174,7 +181,7 @@ bool DSPDisassembler::DisassembleOpcode(const u16* binbuf, u16* pc, std::string&
// printing
if (settings_.show_pc)
dest += StringFromFormat("%04x ", *pc);
dest += fmt::format("{:04x} ", *pc);
u16 op2;
@ -183,25 +190,25 @@ bool DSPDisassembler::DisassembleOpcode(const u16* binbuf, u16* pc, std::string&
{
op2 = binbuf[(*pc + 1) & 0x0fff];
if (settings_.show_hex)
dest += StringFromFormat("%04x %04x ", op1, op2);
dest += fmt::format("{:04x} {:04x} ", op1, op2);
}
else
{
op2 = 0;
if (settings_.show_hex)
dest += StringFromFormat("%04x ", op1);
dest += fmt::format("{:04x} ", op1);
}
std::string opname = opc->name;
if (is_extended)
opname += StringFromFormat("%c%s", settings_.ext_separator, opc_ext->name);
opname += fmt::format("{}{}", settings_.ext_separator, opc_ext->name);
if (settings_.lower_case_ops)
std::transform(opname.begin(), opname.end(), opname.begin(), ::tolower);
if (settings_.print_tabs)
dest += StringFromFormat("%s\t", opname.c_str());
dest += fmt::format("{}\t", opname);
else
dest += StringFromFormat("%-12s", opname.c_str());
dest += fmt::format("{:<12}", opname);
if (opc->param_count > 0)
dest += DisassembleParameters(*opc, op1, op2);

View File

@ -8,12 +8,13 @@
#include <functional>
#include <string>
#include <fmt/format.h>
#include "Common/CommonTypes.h"
#include "Common/StringUtil.h"
#include "Core/Core.h"
#include "Core/PowerPC/MMU.h"
#include "Core/PowerPC/PPCAnalyst.h"
#include "Core/PowerPC/PPCSymbolDB.h"
#include "Core/PowerPC/PowerPC.h"
@ -81,8 +82,7 @@ bool GetCallstack(std::vector<CallstackEntry>& output)
}
CallstackEntry entry;
entry.Name =
StringFromFormat(" * %s [ LR = %08x ]\n", g_symbolDB.GetDescription(LR).c_str(), LR - 4);
entry.Name = fmt::format(" * {} [ LR = {:08x} ]\n", g_symbolDB.GetDescription(LR), LR - 4);
entry.vAddress = LR - 4;
output.push_back(entry);
@ -90,7 +90,7 @@ bool GetCallstack(std::vector<CallstackEntry>& output)
std::string func_desc = g_symbolDB.GetDescription(func_addr);
if (func_desc.empty() || func_desc == "Invalid")
func_desc = "(unknown)";
entry.Name = StringFromFormat(" * %s [ addr = %08x ]\n", func_desc.c_str(), func_addr - 4);
entry.Name = fmt::format(" * {} [ addr = {:08x} ]\n", func_desc, func_addr - 4);
entry.vAddress = func_addr - 4;
output.push_back(entry);
});
@ -150,7 +150,7 @@ void PrintDataBuffer(LogTypes::LOG_TYPE type, const u8* data, size_t size, const
std::string hex_line;
for (int i = 0; i < 16; i++)
{
hex_line += StringFromFormat("%02x ", data[j++]);
hex_line += fmt::format("{:02x} ", data[j++]);
if (j >= size)
break;

View File

@ -10,12 +10,13 @@
#include <string>
#include <unordered_set>
#include <fmt/format.h>
#include "Common/CommonTypes.h"
#include "Common/Logging/Log.h"
#include "Common/Logging/LogManager.h"
#include "Common/StringUtil.h"
#include "DiscIO/Enums.h"
#include "DiscIO/Filesystem.h"
#include "DiscIO/Volume.h"
@ -76,7 +77,7 @@ void Log(const DiscIO::Volume& volume, const DiscIO::Partition& partition, u64 o
const std::string size_string = ThousandSeparate(file_info->GetSize() / 1000, 7);
const std::string path = file_info->GetPath();
const std::string log_string = StringFromFormat("%s kB %s", size_string.c_str(), path.c_str());
const std::string log_string = fmt::format("{} kB {}", size_string, path);
if (IsSoundFile(path))
INFO_LOG(FILEMON, "%s", log_string.c_str());
else

View File

@ -11,10 +11,11 @@
#include <thread>
#include <vector>
#include <fmt/format.h>
#include "Common/ChunkFile.h"
#include "Common/CommonTypes.h"
#include "Common/Logging/Log.h"
#include "Common/StringUtil.h"
#include "Common/Thread.h"
#include "Core/Core.h"
@ -66,7 +67,7 @@ void GeckoSockServer::GeckoConnectionWaiter()
if (!server_running.IsSet())
return;
Core::DisplayMessage(StringFromFormat("USBGecko: Listening on TCP port %u", server_port), 5000);
Core::DisplayMessage(fmt::format("USBGecko: Listening on TCP port {}", server_port), 5000);
server.setBlocking(false);

View File

@ -10,6 +10,8 @@
#include <memory>
#include <string>
#include <fmt/format.h>
#include "Common/ChunkFile.h"
#include "Common/CommonPaths.h"
#include "Common/CommonTypes.h"
@ -17,8 +19,6 @@
#include "Common/FileUtil.h"
#include "Common/IniFile.h"
#include "Common/Logging/Log.h"
#include "Common/NandPaths.h"
#include "Common/StringUtil.h"
#include "Core/CommonTitles.h"
#include "Core/Config/MainSettings.h"
#include "Core/ConfigManager.h"
@ -192,7 +192,7 @@ void CEXIMemoryCard::SetupGciFolder(u16 sizeMb)
else
{
strDirectoryName = strDirectoryName + SConfig::GetDirectoryForRegion(region) + DIR_SEP +
StringFromFormat("Card %c", 'A' + card_index);
fmt::format("Card {}", char('A' + card_index));
}
const File::FileInfo file_info(strDirectoryName);
@ -234,8 +234,7 @@ void CEXIMemoryCard::SetupRawMemcard(u16 sizeMb)
Config::Get(Config::MAIN_MEMCARD_B_PATH);
if (Movie::IsPlayingInput() && Movie::IsConfigSaved() && Movie::IsUsingMemcard(card_index) &&
Movie::IsStartingFromClearSave())
filename =
File::GetUserPath(D_GCUSER_IDX) + StringFromFormat("Movie%s.raw", is_slot_a ? "A" : "B");
filename = File::GetUserPath(D_GCUSER_IDX) + fmt::format("Movie{}.raw", is_slot_a ? 'A' : 'B');
const std::string region_dir =
SConfig::GetDirectoryForRegion(SConfig::ToGameCubeRegion(SConfig::GetInstance().m_region));

View File

@ -13,6 +13,8 @@
#include <string>
#include <vector>
#include <fmt/format.h>
#include "Common/Assert.h"
#include "Common/ChunkFile.h"
#include "Common/CommonTypes.h"
@ -232,8 +234,7 @@ void GCMemcardDirectory::FlushThread()
return;
}
Common::SetCurrentThreadName(
StringFromFormat("Memcard %d flushing thread", m_card_index).c_str());
Common::SetCurrentThreadName(fmt::format("Memcard {} flushing thread", m_card_index).c_str());
constexpr std::chrono::seconds flush_interval{1};
while (true)
@ -627,15 +628,14 @@ void GCMemcardDirectory::FlushToFile()
if (gci.IsGood())
{
Core::DisplayMessage(
StringFromFormat("Wrote save contents to %s", m_saves[i].m_filename.c_str()), 4000);
Core::DisplayMessage(fmt::format("Wrote save contents to {}", m_saves[i].m_filename),
4000);
}
else
{
++errors;
Core::DisplayMessage(StringFromFormat("Failed to write save contents to %s",
m_saves[i].m_filename.c_str()),
4000);
Core::DisplayMessage(
fmt::format("Failed to write save contents to {}", m_saves[i].m_filename), 4000);
ERROR_LOG(EXPANSIONINTERFACE, "Failed to save data to %s",
m_saves[i].m_filename.c_str());
}

View File

@ -11,6 +11,8 @@
#include <string>
#include <thread>
#include <fmt/format.h>
#include "Common/ChunkFile.h"
#include "Common/CommonPaths.h"
#include "Common/CommonTypes.h"
@ -127,8 +129,7 @@ void MemoryCard::FlushThread()
return;
}
Common::SetCurrentThreadName(
StringFromFormat("Memcard %d flushing thread", m_card_index).c_str());
Common::SetCurrentThreadName(fmt::format("Memcard {} flushing thread", m_card_index).c_str());
const auto flush_interval = std::chrono::seconds(15);
@ -182,17 +183,12 @@ void MemoryCard::FlushThread()
}
file.WriteBytes(&m_flush_buffer[0], m_memory_card_size);
if (!do_exit)
{
Core::DisplayMessage(StringFromFormat("Wrote memory card %c contents to %s",
m_card_index ? 'B' : 'A', m_filename.c_str())
.c_str(),
4000);
}
else
{
if (do_exit)
return;
}
Core::DisplayMessage(
fmt::format("Wrote memory card {} contents to {}", m_card_index ? 'B' : 'A', m_filename),
4000);
}
}

View File

@ -4,12 +4,16 @@
#include "Core/HW/SI/SI_Device.h"
#include <istream>
#include <memory>
#include <ostream>
#include <string>
#include <type_traits>
#include <fmt/format.h>
#include "Common/CommonTypes.h"
#include "Common/Logging/Log.h"
#include "Common/StringUtil.h"
#include "Core/HW/SI/SI_DeviceDanceMat.h"
#include "Core/HW/SI/SI_DeviceGBA.h"
#include "Core/HW/SI/SI_DeviceGCAdapter.h"
@ -20,6 +24,28 @@
namespace SerialInterface
{
std::ostream& operator<<(std::ostream& stream, SIDevices device)
{
stream << static_cast<std::underlying_type_t<SIDevices>>(device);
return stream;
}
std::istream& operator>>(std::istream& stream, SIDevices& device)
{
std::underlying_type_t<SIDevices> value;
if (stream >> value)
{
device = static_cast<SIDevices>(value);
}
else
{
device = SIDevices::SIDEVICE_NONE;
}
return stream;
}
ISIDevice::ISIDevice(SIDevices device_type, int device_number)
: m_device_number(device_number), m_device_type(device_type)
{
@ -48,7 +74,7 @@ int ISIDevice::RunBuffer(u8* buffer, int request_length)
while (num < request_length)
{
temp += StringFromFormat("0x%02x ", buffer[num]);
temp += fmt::format("0x{:02x} ", buffer[num]);
num++;
if ((num % 8) == 0)

View File

@ -4,6 +4,7 @@
#pragma once
#include <iosfwd>
#include <memory>
#include "Common/CommonTypes.h"
@ -63,6 +64,9 @@ enum SIDevices : int
SIDEVICE_COUNT,
};
std::ostream& operator<<(std::ostream& stream, SIDevices device);
std::istream& operator>>(std::istream& stream, SIDevices& device);
class ISIDevice
{
public:

View File

@ -22,6 +22,8 @@
#include <utility>
#include <vector>
#include <fmt/format.h>
#include "Common/Align.h"
#include "Common/CommonTypes.h"
#include "Common/Crypto/ec.h"
@ -478,22 +480,22 @@ bool Import(const std::string& data_bin_path, std::function<bool()> can_overwrit
return Copy(data_bin.get(), nand.get());
}
static bool Export(u64 tid, const std::string& export_path, IOS::HLE::Kernel* ios)
static bool Export(u64 tid, std::string_view export_path, IOS::HLE::Kernel* ios)
{
std::string path = StringFromFormat("%s/private/wii/title/%c%c%c%c/data.bin", export_path.c_str(),
const std::string path = fmt::format("{}/private/wii/title/{}{}{}{}/data.bin", export_path,
static_cast<char>(tid >> 24), static_cast<char>(tid >> 16),
static_cast<char>(tid >> 8), static_cast<char>(tid));
return Copy(MakeNandStorage(ios->GetFS().get(), tid).get(),
MakeDataBinStorage(&ios->GetIOSC(), path, "w+b").get());
}
bool Export(u64 tid, const std::string& export_path)
bool Export(u64 tid, std::string_view export_path)
{
IOS::HLE::Kernel ios;
return Export(tid, export_path, &ios);
}
size_t ExportAll(const std::string& export_path)
size_t ExportAll(std::string_view export_path)
{
IOS::HLE::Kernel ios;
size_t exported_save_count = 0;

View File

@ -37,7 +37,7 @@ bool Copy(Storage* source, Storage* destination);
/// Import a save into the NAND from a .bin file.
bool Import(const std::string& data_bin_path, std::function<bool()> can_overwrite);
/// Export a save to a .bin file.
bool Export(u64 tid, const std::string& export_path);
bool Export(u64 tid, std::string_view export_path);
/// Export all saves that are in the NAND. Returns the number of exported saves.
size_t ExportAll(const std::string& export_path);
size_t ExportAll(std::string_view export_path);
} // namespace WiiSave

View File

@ -4,10 +4,10 @@
#include "Core/HW/Wiimote.h"
#include <fmt/format.h>
#include "Common/ChunkFile.h"
#include "Common/CommonTypes.h"
#include "Common/Logging/Log.h"
#include "Common/StringUtil.h"
#include "Core/ConfigManager.h"
#include "Core/Core.h"
@ -20,7 +20,6 @@
#include "Core/NetPlayClient.h"
#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h"
#include "InputCommon/ControllerInterface/ControllerInterface.h"
#include "InputCommon/InputConfig.h"
// Limit the amount of wiimote connect requests, when a button is pressed in disconnected state
@ -127,8 +126,8 @@ void Connect(unsigned int index, bool connect)
if (bluetooth)
bluetooth->AccessWiimoteByIndex(index)->Activate(connect);
const char* message = connect ? "Wii Remote %u connected" : "Wii Remote %u disconnected";
Core::DisplayMessage(StringFromFormat(message, index + 1), 3000);
const char* const message = connect ? "Wii Remote {} connected" : "Wii Remote {} disconnected";
Core::DisplayMessage(fmt::format(message, index + 1), 3000);
}
void ResetAllWiimotes()

View File

@ -8,8 +8,8 @@
#include <cassert>
#include <memory>
#include "Common/BitUtils.h"
#include "Common/ChunkFile.h"
#include <fmt/format.h>
#include "Common/CommonTypes.h"
#include "Common/Config/Config.h"
#include "Common/Logging/Log.h"
@ -245,7 +245,7 @@ Wiimote::Wiimote(const unsigned int index) : m_index(index)
std::string Wiimote::GetName() const
{
return StringFromFormat("Wiimote%d", 1 + m_index);
return fmt::format("Wiimote{}", 1 + m_index);
}
ControllerEmu::ControlGroup* Wiimote::GetWiimoteGroup(WiimoteGroup group)

View File

@ -9,6 +9,8 @@
#include <string>
#include <vector>
#include <fmt/format.h>
#include "Common/Common.h"
#include "Common/CommonTypes.h"
#include "Common/StringUtil.h"
@ -426,12 +428,12 @@ void HotkeyManager::LoadDefaults(const ControllerInterface& ciface)
set_key_expression(HK_FREELOOK_RESET, SHIFT + " & R");
// Savestates
const std::string non_fmt = NON + " & `F{}`";
const std::string shift_fmt = SHIFT + " & `F{}`";
for (int i = 0; i < 8; i++)
{
set_key_expression(HK_LOAD_STATE_SLOT_1 + i,
StringFromFormat((NON + " & `F%d`").c_str(), i + 1));
set_key_expression(HK_SAVE_STATE_SLOT_1 + i,
StringFromFormat((SHIFT + " & `F%d`").c_str(), i + 1));
set_key_expression(HK_LOAD_STATE_SLOT_1 + i, fmt::format(non_fmt, i + 1));
set_key_expression(HK_SAVE_STATE_SLOT_1 + i, fmt::format(shift_fmt, i + 1));
}
set_key_expression(HK_UNDO_LOAD_STATE, NON + " & `F12`");
set_key_expression(HK_UNDO_SAVE_STATE, SHIFT + " & `F12`");

View File

@ -15,6 +15,7 @@
#include <type_traits>
#include <vector>
#include <fmt/format.h>
#include <lzo/lzo1x.h>
#include <mbedtls/md5.h>
@ -849,7 +850,7 @@ unsigned int NetPlayClient::OnData(sf::Packet& packet)
packet >> is_slot_a >> file_count;
const std::string path = File::GetUserPath(D_GCUSER_IDX) + GC_MEMCARD_NETPLAY DIR_SEP +
StringFromFormat("Card %c", is_slot_a ? 'A' : 'B');
fmt::format("Card {}", is_slot_a ? 'A' : 'B');
if ((File::Exists(path) && !File::DeleteDirRecursively(path + DIR_SEP)) ||
!File::CreateFullPath(path + DIR_SEP))
@ -1235,9 +1236,8 @@ void NetPlayClient::DisplayPlayersPing()
if (!g_ActiveConfig.bShowNetPlayPing)
return;
OSD::AddTypedMessage(OSD::MessageType::NetPlayPing,
StringFromFormat("Ping: %u", GetPlayersMaxPing()), OSD::Duration::SHORT,
OSD::Color::CYAN);
OSD::AddTypedMessage(OSD::MessageType::NetPlayPing, fmt::format("Ping: {}", GetPlayersMaxPing()),
OSD::Duration::SHORT, OSD::Color::CYAN);
}
u32 NetPlayClient::GetPlayersMaxPing() const

View File

@ -18,6 +18,7 @@
#include <unordered_set>
#include <vector>
#include <fmt/format.h>
#include <lzo/lzo1x.h>
#include "Common/CommonPaths.h"
@ -1064,8 +1065,8 @@ unsigned int NetPlayServer::OnData(sf::Packet& packet, Client& player)
case SYNC_SAVE_DATA_FAILURE:
{
m_dialog->AppendChat(StringFromFormat(Common::GetStringT("%s failed to synchronize.").c_str(),
player.name.c_str()));
m_dialog->AppendChat(
fmt::format(Common::GetStringT("{} failed to synchronize."), player.name));
m_dialog->OnGameStartAborted();
ChunkedDataAbort();
m_start_pending = false;
@ -1108,8 +1109,8 @@ unsigned int NetPlayServer::OnData(sf::Packet& packet, Client& player)
case SYNC_CODES_FAILURE:
{
m_dialog->AppendChat(StringFromFormat(
Common::GetStringT("%s failed to synchronize codes.").c_str(), player.name.c_str()));
m_dialog->AppendChat(
fmt::format(Common::GetStringT("{} failed to synchronize codes."), player.name));
m_dialog->OnGameStartAborted();
m_start_pending = false;
}
@ -1455,15 +1456,14 @@ bool NetPlayServer::SyncSaveData()
pac << sf::Uint64{0};
}
SendChunkedToClients(
std::move(pac), 1,
StringFromFormat("Memory Card %c Synchronization", is_slot_a ? 'A' : 'B'));
SendChunkedToClients(std::move(pac), 1,
fmt::format("Memory Card {} Synchronization", is_slot_a ? 'A' : 'B'));
}
else if (SConfig::GetInstance().m_EXIDevice[i] ==
ExpansionInterface::EXIDEVICE_MEMORYCARDFOLDER)
{
const std::string path = File::GetUserPath(D_GCUSER_IDX) + region + DIR_SEP +
StringFromFormat("Card %c", is_slot_a ? 'A' : 'B');
fmt::format("Card {}", is_slot_a ? 'A' : 'B');
sf::Packet pac;
pac << static_cast<MessageId>(NP_MSG_SYNC_SAVE_DATA);
@ -1489,9 +1489,8 @@ bool NetPlayServer::SyncSaveData()
pac << static_cast<u8>(0);
}
SendChunkedToClients(
std::move(pac), 1,
StringFromFormat("GCI Folder %c Synchronization", is_slot_a ? 'A' : 'B'));
SendChunkedToClients(std::move(pac), 1,
fmt::format("GCI Folder {} Synchronization", is_slot_a ? 'A' : 'B'));
}
}

View File

@ -9,6 +9,8 @@
#include <cinttypes>
#include <string>
#include <fmt/format.h>
#include "Common/Assert.h"
#include "Common/CommonTypes.h"
#include "Common/GekkoDisassembler.h"
@ -117,18 +119,16 @@ static int startTrace = 0;
static void Trace(UGeckoInstruction& inst)
{
std::string regs;
for (int i = 0; i < 32; i++)
for (size_t i = 0; i < std::size(PowerPC::ppcState.gpr); i++)
{
regs += StringFromFormat("r%02d: %08x ", i, PowerPC::ppcState.gpr[i]);
regs += fmt::format("r{:02d}: {:08x} ", i, PowerPC::ppcState.gpr[i]);
}
std::string fregs;
for (int i = 0; i < 32; i++)
for (size_t i = 0; i < std::size(PowerPC::ppcState.ps); i++)
{
const auto& ps = PowerPC::ppcState.ps[i];
fregs +=
StringFromFormat("f%02d: %08" PRIx64 " %08" PRIx64 " ", i, ps.PS0AsU64(), ps.PS1AsU64());
fregs += fmt::format("f{:02d}: {:08x} {:08x} ", i, ps.PS0AsU64(), ps.PS1AsU64());
}
const std::string ppc_inst = Common::GekkoDisassembler::Disassemble(inst.hex, PC);

View File

@ -4,11 +4,13 @@
#include "Core/PowerPC/Jit64/Jit.h"
#include <disasm.h>
#include <map>
#include <sstream>
#include <string>
#include <disasm.h>
#include <fmt/format.h>
// for the PROFILER stuff
#ifdef _WIN32
#include <windows.h>
@ -697,16 +699,16 @@ void Jit64::Trace()
std::string fregs;
#ifdef JIT_LOG_GPR
for (int i = 0; i < 32; i++)
for (size_t i = 0; i < std::size(PowerPC::ppcState.gpr); i++)
{
regs += StringFromFormat("r%02d: %08x ", i, PowerPC::ppcState.gpr[i]);
regs += fmt::format("r{:02d}: {:08x} ", i, PowerPC::ppcState.gpr[i]);
}
#endif
#ifdef JIT_LOG_FPR
for (int i = 0; i < 32; i++)
for (size_t i = 0; i < std::size(PowerPC::ppcState.ps); i++)
{
fregs += StringFromFormat("f%02d: %016x ", i, rPS(i).PS0AsU64());
fregs += fmt::format("f{:02d}: {:016x} ", i, PowerPC::ppcState.ps[i].PS0AsU64());
}
#endif

View File

@ -10,11 +10,12 @@
#include <string>
#include <vector>
#include <fmt/format.h>
#include "Common/Assert.h"
#include "Common/CommonTypes.h"
#include "Common/Logging/Log.h"
#include "Common/StringUtil.h"
#include "Core/Config/MainSettings.h"
#include "Core/ConfigManager.h"
#include "Core/PowerPC/JitCommon/JitBase.h"
#include "Core/PowerPC/MMU.h"
@ -76,7 +77,7 @@ static u32 EvaluateBranchTarget(UGeckoInstruction instr, u32 pc)
bool AnalyzeFunction(u32 startAddr, Common::Symbol& func, u32 max_size)
{
if (func.name.empty())
func.Rename(StringFromFormat("zz_%08x_", startAddr));
func.Rename(fmt::format("zz_{:08x}_", startAddr));
if (func.analyzed)
return true; // No error, just already did it.

View File

@ -11,6 +11,8 @@
#include <cstdio>
#include <vector>
#include <fmt/format.h>
#include "Common/Assert.h"
#include "Common/CommonTypes.h"
#include "Common/File.h"
@ -163,8 +165,7 @@ void LogCompiledInstructions()
{
static unsigned int time = 0;
File::IOFile f(StringFromFormat("%sinst_log%i.txt", File::GetUserPath(D_LOGS_IDX).c_str(), time),
"w");
File::IOFile f(fmt::format("{}inst_log{}.txt", File::GetUserPath(D_LOGS_IDX), time), "w");
for (size_t i = 0; i < m_numInstructions; i++)
{
GekkoOPInfo* pInst = m_allInstructions[i];
@ -175,7 +176,7 @@ void LogCompiledInstructions()
}
}
f.Open(StringFromFormat("%sinst_not%i.txt", File::GetUserPath(D_LOGS_IDX).c_str(), time), "w");
f.Open(fmt::format("{}inst_not{}.txt", File::GetUserPath(D_LOGS_IDX), time), "w");
for (size_t i = 0; i < m_numInstructions; i++)
{
GekkoOPInfo* pInst = m_allInstructions[i];
@ -187,8 +188,7 @@ void LogCompiledInstructions()
}
#ifdef OPLOG
f.Open(StringFromFormat("%s" OP_TO_LOG "_at%i.txt", File::GetUserPath(D_LOGS_IDX).c_str(), time),
"w");
f.Open(fmt::format("{}" OP_TO_LOG "_at{}.txt", File::GetUserPath(D_LOGS_IDX), time), "w");
for (auto& rsplocation : rsplocations)
{
fprintf(f.GetHandle(), OP_TO_LOG ": %08x\n", rsplocation);

View File

@ -12,6 +12,8 @@
#include <utility>
#include <vector>
#include <fmt/format.h>
#include "Common/ChunkFile.h"
#include "Common/CommonTypes.h"
#include "Common/Event.h"
@ -19,7 +21,6 @@
#include "Common/FileUtil.h"
#include "Common/MsgHandler.h"
#include "Common/ScopeGuard.h"
#include "Common/StringUtil.h"
#include "Common/Thread.h"
#include "Common/Timer.h"
#include "Common/Version.h"
@ -163,7 +164,7 @@ static void DoState(PointerWrap& p)
p.Do(is_wii);
if (is_wii != is_wii_currently)
{
OSD::AddMessage(StringFromFormat("Cannot load a savestate created under %s mode in %s mode",
OSD::AddMessage(fmt::format("Cannot load a savestate created under {} mode in {} mode",
is_wii ? "Wii" : "GC", is_wii_currently ? "Wii" : "GC"),
OSD::Duration::NORMAL, OSD::Color::RED);
p.SetMode(PointerWrap::MODE_MEASURE);
@ -382,7 +383,7 @@ static void CompressAndDumpState(CompressAndDumpState_args save_args)
f.WriteBytes(buffer_data, buffer_size);
}
Core::DisplayMessage(StringFromFormat("Saved State to %s", filename.c_str()), 2000);
Core::DisplayMessage(fmt::format("Saved State to {}", filename), 2000);
Host_UpdateMainFrame();
}
@ -477,8 +478,9 @@ static void LoadFileStateData(const std::string& filename, std::vector<u8>& ret_
if (strncmp(SConfig::GetInstance().GetGameID().c_str(), header.gameID, 6))
{
Core::DisplayMessage(
StringFromFormat("State belongs to a different game (ID %.*s)", 6, header.gameID), 2000);
Core::DisplayMessage(fmt::format("State belongs to a different game (ID {})",
std::string_view{header.gameID, std::size(header.gameID)}),
2000);
return;
}
@ -578,7 +580,7 @@ void LoadAs(const std::string& filename)
{
if (loadedSuccessfully)
{
Core::DisplayMessage(StringFromFormat("Loaded state from %s", filename.c_str()), 2000);
Core::DisplayMessage(fmt::format("Loaded state from {}", filename), 2000);
if (File::Exists(filename + ".dtm"))
Movie::LoadInput(filename + ".dtm");
else if (!Movie::IsJustStartingRecordingInputFromSaveState() &&
@ -633,8 +635,8 @@ void Shutdown()
static std::string MakeStateFilename(int number)
{
return StringFromFormat("%s%s.s%02i", File::GetUserPath(D_STATESAVES_IDX).c_str(),
SConfig::GetInstance().GetGameID().c_str(), number);
return fmt::format("{}{}.s{:02d}", File::GetUserPath(D_STATESAVES_IDX),
SConfig::GetInstance().GetGameID(), number);
}
void Save(int slot, bool wait)

View File

@ -12,6 +12,8 @@
#include <unordered_map>
#include <utility>
#include <fmt/format.h>
#include "Common/FileUtil.h"
#include "Common/MsgHandler.h"
#include "Common/StringUtil.h"
@ -132,6 +134,6 @@ std::string TitleDatabase::Describe(const std::string& gametdb_id, DiscIO::Langu
const std::string& title_name = GetTitleName(gametdb_id, language);
if (title_name.empty())
return gametdb_id;
return StringFromFormat("%s (%s)", title_name.c_str(), gametdb_id.c_str());
return fmt::format("{} ({})", title_name, gametdb_id);
}
} // namespace Core