Skip to content
Permalink
Browse files

Merge pull request #8418 from lioncash/core-fmt

Core: Replace usages of StringFromFormat with fmt where applicable
  • Loading branch information
leoetlino committed Nov 16, 2019
2 parents fe39e1e + cfbabd4 commit a77108236ed5289f3def78495dcf387a46005e69
Showing with 221 additions and 165 deletions.
  1. +5 −5 Source/Core/Core/Analytics.cpp
  2. +12 −9 Source/Core/Core/BootManager.cpp
  3. +5 −4 Source/Core/Core/Config/MainSettings.cpp
  4. +4 −4 Source/Core/Core/ConfigLoaders/GameConfigLoader.cpp
  5. +8 −4 Source/Core/Core/ConfigLoaders/NetPlayConfigLoader.cpp
  6. +14 −12 Source/Core/Core/ConfigManager.cpp
  7. +3 −4 Source/Core/Core/CoreTiming.cpp
  8. +8 −6 Source/Core/Core/DSP/DSPAssembler.cpp
  9. +3 −1 Source/Core/Core/DSP/DSPCodeUtil.cpp
  10. +25 −18 Source/Core/Core/DSP/DSPDisassembler.cpp
  11. +5 −5 Source/Core/Core/Debugger/Debugger_SymbolMap.cpp
  12. +3 −2 Source/Core/Core/HW/DVD/FileMonitor.cpp
  13. +3 −2 Source/Core/Core/HW/EXI/EXI_DeviceGecko.cpp
  14. +4 −5 Source/Core/Core/HW/EXI/EXI_DeviceMemoryCard.cpp
  15. +7 −7 Source/Core/Core/HW/GCMemcard/GCMemcardDirectory.cpp
  16. +8 −12 Source/Core/Core/HW/GCMemcard/GCMemcardRaw.cpp
  17. +28 −2 Source/Core/Core/HW/SI/SI_Device.cpp
  18. +4 −0 Source/Core/Core/HW/SI/SI_Device.h
  19. +8 −6 Source/Core/Core/HW/WiiSave.cpp
  20. +2 −2 Source/Core/Core/HW/WiiSave.h
  21. +4 −5 Source/Core/Core/HW/Wiimote.cpp
  22. +3 −3 Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp
  23. +6 −4 Source/Core/Core/HotkeyManager.cpp
  24. +4 −4 Source/Core/Core/NetPlayClient.cpp
  25. +10 −11 Source/Core/Core/NetPlayServer.cpp
  26. +6 −6 Source/Core/Core/PowerPC/Interpreter/Interpreter.cpp
  27. +7 −5 Source/Core/Core/PowerPC/Jit64/Jit.cpp
  28. +3 −2 Source/Core/Core/PowerPC/PPCAnalyst.cpp
  29. +5 −5 Source/Core/Core/PowerPC/PPCTables.cpp
  30. +11 −9 Source/Core/Core/State.cpp
  31. +3 −1 Source/Core/Core/TitleDatabase.cpp
@@ -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;
}
@@ -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);
}
}
}
@@ -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};
@@ -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);
@@ -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 @@ class NetPlayConfigLayerLoader final : public Config::ConfigLayerLoader
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);
@@ -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
{
@@ -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;
}
@@ -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,20 +93,20 @@ 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 = "-";

const char* const error_string = err_string[static_cast<size_t>(err_code)];

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,
m_current_param, extra_info);
error += fmt::format("ERROR: {} Line: {} Param: {} : {}\n", error_string, m_code_line,
m_current_param, extra_info);
}

m_last_error_str = std::move(error);
@@ -958,8 +960,8 @@ 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",
m_cur_addr, params[0].val);
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());
}
}
@@ -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";

0 comments on commit a771082

Please sign in to comment.
You can’t perform that action at this time.