Core/IOS: Use fmt where applicable

This commit is contained in:
Lioncash 2019-06-20 09:03:19 -04:00
parent 3cafd0ae81
commit 980085e106
11 changed files with 131 additions and 139 deletions

View File

@ -16,6 +16,7 @@
#include <utility>
#include <vector>
#include <fmt/format.h>
#include <mbedtls/sha1.h>
#include "Common/Assert.h"
@ -320,7 +321,7 @@ std::string TMDReader::GetGameID() const
if (all_printable)
return std::string(game_id, sizeof(game_id));
return StringFromFormat("%016" PRIx64, GetTitleId());
return fmt::format("{:016x}", GetTitleId());
}
std::string TMDReader::GetGameTDBID() const
@ -334,7 +335,7 @@ std::string TMDReader::GetGameTDBID() const
if (all_printable)
return std::string(begin, end);
return StringFromFormat("%016" PRIx64, GetTitleId());
return fmt::format("{:016x}", GetTitleId());
}
u16 TMDReader::GetNumContents() const
@ -547,7 +548,7 @@ struct SharedContentMap::Entry
std::array<u8, 20> sha1;
};
static const std::string CONTENT_MAP_PATH = "/shared1/content.map";
constexpr char CONTENT_MAP_PATH[] = "/shared1/content.map";
SharedContentMap::SharedContentMap(std::shared_ptr<HLE::FS::FileSystem> fs) : m_fs{fs}
{
static_assert(sizeof(Entry) == 28, "SharedContentMap::Entry has the wrong size");
@ -572,7 +573,7 @@ SharedContentMap::GetFilenameFromSHA1(const std::array<u8, 20>& sha1) const
return {};
const std::string id_string(it->id.begin(), it->id.end());
return StringFromFormat("/shared1/%s.app", id_string.c_str());
return fmt::format("/shared1/{}.app", id_string);
}
std::vector<std::array<u8, 20>> SharedContentMap::GetHashes() const
@ -591,14 +592,14 @@ std::string SharedContentMap::AddSharedContent(const std::array<u8, 20>& sha1)
if (filename)
return *filename;
const std::string id = StringFromFormat("%08x", m_last_id);
const std::string id = fmt::format("{:08x}", m_last_id);
Entry entry;
std::copy(id.cbegin(), id.cend(), entry.id.begin());
entry.sha1 = sha1;
m_entries.push_back(entry);
WriteEntries();
filename = StringFromFormat("/shared1/%s.app", id.c_str());
filename = fmt::format("/shared1/{}.app", id);
m_last_id++;
return *filename;
}
@ -640,7 +641,7 @@ static std::pair<u32, u64> ReadUidSysEntry(const HLE::FS::FileHandle& file)
return {Common::swap32(uid), Common::swap64(title_id)};
}
static const std::string UID_MAP_PATH = "/sys/uid.sys";
constexpr char UID_MAP_PATH[] = "/sys/uid.sys";
UIDSys::UIDSys(std::shared_ptr<HLE::FS::FileSystem> fs) : m_fs{fs}
{
if (const auto file = fs->OpenFile(PID_KERNEL, PID_KERNEL, UID_MAP_PATH, HLE::FS::Mode::Read))

View File

@ -12,6 +12,8 @@
#include <unordered_set>
#include <vector>
#include <fmt/format.h>
#include "Common/CommonTypes.h"
#include "Common/Logging/Log.h"
#include "Common/NandPaths.h"
@ -86,8 +88,8 @@ static std::vector<u64> GetTitlesInTitleOrImport(FS::FileSystem* fs, const std::
if (!IsValidPartOfTitleID(title_type))
continue;
const auto title_entries =
fs->ReadDirectory(PID_KERNEL, PID_KERNEL, titles_dir + '/' + title_type);
const std::string title_dir = fmt::format("{}/{}", titles_dir, title_type);
const auto title_entries = fs->ReadDirectory(PID_KERNEL, PID_KERNEL, title_dir);
if (!title_entries)
continue;
@ -96,8 +98,10 @@ static std::vector<u64> GetTitlesInTitleOrImport(FS::FileSystem* fs, const std::
if (!IsValidPartOfTitleID(title_identifier))
continue;
if (!fs->ReadDirectory(PID_KERNEL, PID_KERNEL,
titles_dir + '/' + title_type + '/' + title_identifier))
fmt::format("{}/{}", title_dir, title_identifier)))
{
continue;
}
const u32 type = std::stoul(title_type, nullptr, 16);
const u32 identifier = std::stoul(title_identifier, nullptr, 16);
@ -150,7 +154,8 @@ std::vector<u64> ES::GetTitlesWithTickets() const
for (const std::string& file_name : *sub_entries)
{
const std::string name_without_ext = file_name.substr(0, 8);
if (fs->ReadDirectory(PID_KERNEL, PID_KERNEL, "/ticket/" + title_type + '/' + file_name) ||
if (fs->ReadDirectory(PID_KERNEL, PID_KERNEL,
fmt::format("/ticket/{}/{}", title_type, file_name)) ||
!IsValidPartOfTitleID(name_without_ext) || name_without_ext + ".tik" != file_name)
{
continue;
@ -299,13 +304,13 @@ bool ES::FinishImport(const IOS::ES::TMDReader& tmd)
// Remove everything not listed in the TMD.
std::unordered_set<std::string> expected_entries = {"title.tmd"};
for (const auto& content_info : tmd.GetContents())
expected_entries.insert(StringFromFormat("%08x.app", content_info.id));
expected_entries.insert(fmt::format("{:08x}.app", content_info.id));
const auto entries = fs->ReadDirectory(PID_KERNEL, PID_KERNEL, import_content_dir);
if (!entries)
return false;
for (const std::string& name : *entries)
{
const std::string absolute_path = import_content_dir + '/' + name;
const std::string absolute_path = fmt::format("{}/{}", import_content_dir, name);
// There should not be any directory in there. Remove it.
if (fs->ReadDirectory(PID_KERNEL, PID_KERNEL, absolute_path))
fs->Delete(PID_KERNEL, PID_KERNEL, absolute_path);
@ -333,7 +338,8 @@ bool ES::WriteImportTMD(const IOS::ES::TMDReader& tmd)
return false;
}
const std::string dest = Common::GetImportTitlePath(tmd.GetTitleId()) + "/content/title.tmd";
const std::string dest =
fmt::format("{}/content/title.tmd", Common::GetImportTitlePath(tmd.GetTitleId()));
return fs->Rename(PID_KERNEL, PID_KERNEL, tmd_path, dest) == FS::ResultCode::Success;
}
@ -365,7 +371,7 @@ std::string ES::GetContentPath(const u64 title_id, const IOS::ES::Content& conte
{
if (content.IsShared())
return content_map.GetFilenameFromSHA1(content.sha1).value_or("");
return Common::GetTitleContentPath(title_id) + StringFromFormat("/%08x.app", content.id);
return fmt::format("{}/{:08x}.app", Common::GetTitleContentPath(title_id), content.id);
}
std::string ES::GetContentPath(const u64 title_id, const IOS::ES::Content& content) const

View File

@ -10,12 +10,12 @@
#include <utility>
#include <vector>
#include <fmt/format.h>
#include <mbedtls/sha1.h>
#include "Common/Align.h"
#include "Common/Logging/Log.h"
#include "Common/NandPaths.h"
#include "Common/StringUtil.h"
#include "Core/CommonTitles.h"
#include "Core/HW/Memmap.h"
#include "Core/IOS/ES/Formats.h"
@ -350,7 +350,7 @@ static bool CheckIfContentHashMatches(const std::vector<u8>& content, const IOS:
static std::string GetImportContentPath(u64 title_id, u32 content_id)
{
return Common::GetImportTitlePath(title_id) + StringFromFormat("/content/%08x.app", content_id);
return fmt::format("{}/content/{:08x}.app", Common::GetImportTitlePath(title_id), content_id);
}
ReturnCode ES::ImportContentEnd(Context& context, u32 content_fd)
@ -438,8 +438,7 @@ static bool HasAllRequiredContents(IOS::HLE::Kernel& ios, const IOS::ES::TMDRead
// Note: the import hasn't been finalised yet, so the whole title directory
// is still in /import, not /title.
const std::string path =
Common::GetImportTitlePath(title_id) + StringFromFormat("/content/%08x.app", content.id);
const std::string path = GetImportContentPath(title_id, content.id);
return ios.GetFS()->GetMetadata(PID_KERNEL, PID_KERNEL, path).Succeeded();
});
}
@ -567,7 +566,7 @@ ReturnCode ES::DeleteTicket(const u8* ticket_view)
// Delete the ticket directory if it is now empty.
const std::string ticket_parent_dir =
StringFromFormat("/ticket/%08x", static_cast<u32>(title_id >> 32));
fmt::format("/ticket/{:08x}", static_cast<u32>(title_id >> 32));
const auto ticket_parent_dir_entries =
fs->ReadDirectory(PID_KERNEL, PID_KERNEL, ticket_parent_dir);
if (ticket_parent_dir_entries && ticket_parent_dir_entries->empty())
@ -625,9 +624,9 @@ ReturnCode ES::DeleteContent(u64 title_id, u32 content_id) const
if (!tmd.FindContentById(content_id, &content))
return ES_EINVAL;
return FS::ConvertResult(m_ios.GetFS()->Delete(PID_KERNEL, PID_KERNEL,
Common::GetTitleContentPath(title_id) +
StringFromFormat("/%08x.app", content_id)));
const std::string path =
fmt::format("{}/{:08x}.app", Common::GetTitleContentPath(title_id), content_id);
return FS::ConvertResult(m_ios.GetFS()->Delete(PID_KERNEL, PID_KERNEL, path));
}
IPCCommandResult ES::DeleteContent(const IOCtlVRequest& request)

View File

@ -6,8 +6,10 @@
#include <algorithm>
#include <cstring>
#include <string_view>
#include <fmt/format.h>
#include "Common/Assert.h"
#include "Common/ChunkFile.h"
#include "Common/StringUtil.h"
#include "Common/Swap.h"
@ -45,16 +47,19 @@ void FS::DoState(PointerWrap& p)
p.Do(m_dirty_cache);
}
static void LogResult(const std::string& command, ResultCode code)
template <typename... Args>
static void LogResult(ResultCode code, std::string_view format, Args&&... args)
{
const std::string command = fmt::format(format, std::forward<Args>(args)...);
GENERIC_LOG(LogTypes::IOS_FS, (code == ResultCode::Success ? LogTypes::LINFO : LogTypes::LERROR),
"%s: result %d", command.c_str(), ConvertResult(code));
}
template <typename T>
static void LogResult(const std::string& command, const Result<T>& result)
template <typename T, typename... Args>
static void LogResult(const Result<T>& result, std::string_view format, Args&&... args)
{
LogResult(command, result.Succeeded() ? ResultCode::Success : result.Error());
const auto result_code = result.Succeeded() ? ResultCode::Success : result.Error();
LogResult(result_code, format, std::forward<Args>(args)...);
}
enum class FileLookupMode
@ -108,7 +113,7 @@ IPCCommandResult FS::Open(const OpenRequest& request)
auto backend_fd = m_ios.GetFS()->OpenFile(request.uid, request.gid, request.path,
static_cast<Mode>(request.flags & 3));
LogResult(StringFromFormat("OpenFile(%s)", request.path.c_str()), backend_fd);
LogResult(backend_fd, "OpenFile({})", request.path);
if (!backend_fd)
return GetFSReply(ConvertResult(backend_fd.Error()), ticks);
@ -132,7 +137,7 @@ IPCCommandResult FS::Close(u32 fd)
ticks += SUPERBLOCK_WRITE_TICKS;
const ResultCode result = m_ios.GetFS()->Close(m_fd_map[fd].fs_fd);
LogResult(StringFromFormat("Close(%s)", m_fd_map[fd].name.data()), result);
LogResult(result, "Close({})", m_fd_map[fd].name.data());
m_fd_map.erase(fd);
if (result != ResultCode::Success)
return GetFSReply(ConvertResult(result));
@ -227,9 +232,7 @@ IPCCommandResult FS::Read(const ReadWriteRequest& request)
const Result<u32> result = m_ios.GetFS()->ReadBytesFromFile(
handle.fs_fd, Memory::GetPointer(request.buffer), request.size);
LogResult(
StringFromFormat("Read(%s, 0x%08x, %u)", handle.name.data(), request.buffer, request.size),
result);
LogResult(result, "Read({}, 0x{:08x}, {})", handle.name.data(), request.buffer, request.size);
if (!result)
return GetFSReply(ConvertResult(result.Error()));
@ -247,9 +250,7 @@ IPCCommandResult FS::Write(const ReadWriteRequest& request)
const Result<u32> result = m_ios.GetFS()->WriteBytesToFile(
handle.fs_fd, Memory::GetPointer(request.buffer), request.size);
LogResult(
StringFromFormat("Write(%s, 0x%08x, %u)", handle.name.data(), request.buffer, request.size),
result);
LogResult(result, "Write({}, 0x{:08x}, {})", handle.name.data(), request.buffer, request.size);
if (!result)
return GetFSReply(ConvertResult(result.Error()));
@ -264,9 +265,7 @@ IPCCommandResult FS::Seek(const SeekRequest& request)
const Result<u32> result =
m_ios.GetFS()->SeekFile(handle.fs_fd, request.offset, IOS::HLE::FS::SeekMode(request.mode));
LogResult(
StringFromFormat("Seek(%s, 0x%08x, %u)", handle.name.data(), request.offset, request.mode),
result);
LogResult(result, "Seek({}, 0x{:08x}, {})", handle.name.data(), request.offset, request.mode);
if (!result)
return GetFSReply(ConvertResult(result.Error()));
return GetFSReply(*result);
@ -378,7 +377,7 @@ IPCCommandResult FS::GetStats(const Handle& handle, const IOCtlRequest& request)
return GetFSReply(ConvertResult(ResultCode::Invalid));
const Result<NandStats> stats = m_ios.GetFS()->GetNandStats();
LogResult("GetNandStats", stats);
LogResult(stats, "GetNandStats");
if (!stats)
return GetDefaultReply(ConvertResult(stats.Error()));
@ -402,7 +401,7 @@ IPCCommandResult FS::CreateDirectory(const Handle& handle, const IOCtlRequest& r
const ResultCode result = m_ios.GetFS()->CreateDirectory(handle.uid, handle.gid, params->path,
params->attribute, params->modes);
LogResult(StringFromFormat("CreateDirectory(%s)", params->path), result);
LogResult(result, "CreateDirectory({})", params->path);
return GetReplyForSuperblockOperation(result);
}
@ -438,7 +437,7 @@ IPCCommandResult FS::ReadDirectory(const Handle& handle, const IOCtlVRequest& re
const std::string directory = Memory::GetString(request.in_vectors[0].address, 64);
const Result<std::vector<std::string>> list =
m_ios.GetFS()->ReadDirectory(handle.uid, handle.gid, directory);
LogResult(StringFromFormat("ReadDirectory(%s)", directory.c_str()), list);
LogResult(list, "ReadDirectory({})", directory);
if (!list)
return GetFSReply(ConvertResult(list.Error()));
@ -468,7 +467,7 @@ IPCCommandResult FS::SetAttribute(const Handle& handle, const IOCtlRequest& requ
const ResultCode result = m_ios.GetFS()->SetMetadata(
handle.uid, params->path, params->uid, params->gid, params->attribute, params->modes);
LogResult(StringFromFormat("SetMetadata(%s)", params->path), result);
LogResult(result, "SetMetadata({})", params->path);
return GetReplyForSuperblockOperation(result);
}
@ -480,7 +479,7 @@ IPCCommandResult FS::GetAttribute(const Handle& handle, const IOCtlRequest& requ
const std::string path = Memory::GetString(request.buffer_in, 64);
const u64 ticks = EstimateFileLookupTicks(path, FileLookupMode::Split);
const Result<Metadata> metadata = m_ios.GetFS()->GetMetadata(handle.uid, handle.gid, path);
LogResult(StringFromFormat("GetMetadata(%s)", path.c_str()), metadata);
LogResult(metadata, "GetMetadata({})", path);
if (!metadata)
return GetFSReply(ConvertResult(metadata.Error()), ticks);
@ -503,7 +502,7 @@ IPCCommandResult FS::DeleteFile(const Handle& handle, const IOCtlRequest& reques
const std::string path = Memory::GetString(request.buffer_in, 64);
const ResultCode result = m_ios.GetFS()->Delete(handle.uid, handle.gid, path);
LogResult(StringFromFormat("Delete(%s)", path.c_str()), result);
LogResult(result, "Delete({})", path);
return GetReplyForSuperblockOperation(result);
}
@ -515,7 +514,7 @@ IPCCommandResult FS::RenameFile(const Handle& handle, const IOCtlRequest& reques
const std::string old_path = Memory::GetString(request.buffer_in, 64);
const std::string new_path = Memory::GetString(request.buffer_in + 64, 64);
const ResultCode result = m_ios.GetFS()->Rename(handle.uid, handle.gid, old_path, new_path);
LogResult(StringFromFormat("Rename(%s, %s)", old_path.c_str(), new_path.c_str()), result);
LogResult(result, "Rename({}, {})", old_path, new_path);
return GetReplyForSuperblockOperation(result);
}
@ -527,7 +526,7 @@ IPCCommandResult FS::CreateFile(const Handle& handle, const IOCtlRequest& reques
const ResultCode result = m_ios.GetFS()->CreateFile(handle.uid, handle.gid, params->path,
params->attribute, params->modes);
LogResult(StringFromFormat("CreateFile(%s)", params->path), result);
LogResult(result, "CreateFile({})", params->path);
return GetReplyForSuperblockOperation(result);
}
@ -548,7 +547,7 @@ IPCCommandResult FS::GetFileStats(const Handle& handle, const IOCtlRequest& requ
return GetFSReply(ConvertResult(ResultCode::Invalid));
const Result<FileStatus> status = m_ios.GetFS()->GetFileStatus(handle.fs_fd);
LogResult(StringFromFormat("GetFileStatus(%s)", handle.name.data()), status);
LogResult(status, "GetFileStatus({})", handle.name.data());
if (!status)
return GetDefaultReply(ConvertResult(status.Error()));
@ -569,7 +568,7 @@ IPCCommandResult FS::GetUsage(const Handle& handle, const IOCtlVRequest& request
const std::string directory = Memory::GetString(request.in_vectors[0].address, 64);
const Result<DirectoryStats> stats = m_ios.GetFS()->GetDirectoryStats(directory);
LogResult(StringFromFormat("GetDirectoryStats(%s)", directory.c_str()), stats);
LogResult(stats, "GetDirectoryStats({})", directory);
if (!stats)
return GetFSReply(ConvertResult(stats.Error()));

View File

@ -13,6 +13,7 @@
#include <utility>
#include <vector>
#include <fmt/format.h>
#include <mbedtls/md.h>
#include <mbedtls/rsa.h>
#include <mbedtls/sha1.h>
@ -24,7 +25,6 @@
#include "Common/File.h"
#include "Common/FileUtil.h"
#include "Common/ScopeGuard.h"
#include "Common/StringUtil.h"
#include "Common/Swap.h"
#include "Core/IOS/Device.h"
#include "Core/IOS/ES/Formats.h"
@ -430,8 +430,8 @@ static CertECC MakeBlankEccCert(const std::string& issuer, const std::string& na
CertECC IOSC::GetDeviceCertificate() const
{
const std::string name = StringFromFormat("NG%08x", GetDeviceId());
auto cert = MakeBlankEccCert(StringFromFormat("Root-CA%08x-MS%08x", m_ca_id, m_ms_id), name,
const std::string name = fmt::format("NG{:08x}", GetDeviceId());
auto cert = MakeBlankEccCert(fmt::format("Root-CA{:08x}-MS{:08x}", m_ca_id, m_ms_id), name,
m_key_entries[HANDLE_CONSOLE_KEY].data.data(), m_console_key_id);
cert.signature.sig = m_console_signature;
return cert;
@ -448,8 +448,8 @@ void IOSC::Sign(u8* sig_out, u8* ap_cert_out, u64 title_id, const u8* data, u32
// ap_priv[0] &= 1;
const std::string signer =
StringFromFormat("Root-CA%08x-MS%08x-NG%08x", m_ca_id, m_ms_id, GetDeviceId());
const std::string name = StringFromFormat("AP%016" PRIx64, title_id);
fmt::format("Root-CA{:08x}-MS{:08x}-NG{:08x}", m_ca_id, m_ms_id, GetDeviceId());
const std::string name = fmt::format("AP{:016x}", title_id);
CertECC cert = MakeBlankEccCert(signer, name, ap_priv.data(), 0);
// Sign the AP cert.
const size_t skip = offsetof(CertECC, signature.issuer);

View File

@ -18,6 +18,8 @@
#include <poll.h>
#endif
#include <fmt/format.h>
#include "Common/Assert.h"
#include "Common/CommonTypes.h"
#include "Common/Logging/Log.h"
@ -697,9 +699,9 @@ IPCCommandResult NetIPTop::HandleGetHostByNameRequest(const IOCtlRequest& reques
for (int i = 0; remoteHost->h_addr_list[i]; ++i)
{
u32 ip = Common::swap32(*(u32*)(remoteHost->h_addr_list[i]));
std::string ip_s =
StringFromFormat("%i.%i.%i.%i", ip >> 24, (ip >> 16) & 0xff, (ip >> 8) & 0xff, ip & 0xff);
const u32 ip = Common::swap32(*(u32*)(remoteHost->h_addr_list[i]));
const std::string ip_s =
fmt::format("{}.{}.{}.{}", ip >> 24, (ip >> 16) & 0xff, (ip >> 8) & 0xff, ip & 0xff);
DEBUG_LOG(IOS_NET, "addr%i:%s", i, ip_s.c_str());
}

View File

@ -5,11 +5,12 @@
#include "Core/IOS/USB/Bluetooth/BTEmu.h"
#include <algorithm>
#include <cstdint>
#include <cstring>
#include <memory>
#include <string>
#include <fmt/format.h>
#include "Common/Assert.h"
#include "Common/Logging/Log.h"
#include "Common/MsgHandler.h"
@ -21,7 +22,6 @@
#include "Core/HW/Memmap.h"
#include "Core/HW/SystemTimers.h"
#include "Core/HW/Wiimote.h"
#include "Core/Host.h"
#include "Core/IOS/Device.h"
#include "Core/IOS/IOS.h"
#include "Core/SysConf.h"
@ -1781,7 +1781,7 @@ void BluetoothEmu::DisplayDisconnectMessage(const int wiimote_number, const int
// mean
// and display things like "Wii Remote %i disconnected due to inactivity!" etc.
Core::DisplayMessage(
StringFromFormat("Wii Remote %i disconnected by emulated software", wiimote_number), 3000);
fmt::format("Wii Remote {} disconnected by emulated software", wiimote_number), 3000);
}
} // namespace Device
} // namespace IOS::HLE

View File

@ -6,9 +6,10 @@
#include <algorithm>
#include <fmt/format.h>
#include "Common/Assert.h"
#include "Common/CommonTypes.h"
#include "Common/StringUtil.h"
#include "Common/Swap.h"
#include "Core/HW/Memmap.h"
@ -89,6 +90,6 @@ void EndpointDescriptor::Swap()
std::string Device::GetErrorName(const int error_code) const
{
return StringFromFormat("unknown error %d", error_code);
return fmt::format("unknown error {}", error_code);
}
} // namespace IOS::HLE::USB

View File

@ -11,6 +11,8 @@
#include <utility>
#include <vector>
#include <fmt/format.h>
#include "Common/CommonTypes.h"
#include "Common/File.h"
#include "Common/FileUtil.h"
@ -25,13 +27,13 @@ namespace
{
std::string TitleIdStr(u64 tid)
{
return StringFromFormat("%c%c%c%c", static_cast<char>(tid >> 24), static_cast<char>(tid >> 16),
return fmt::format("{}{}{}{}", static_cast<char>(tid >> 24), static_cast<char>(tid >> 16),
static_cast<char>(tid >> 8), static_cast<char>(tid));
}
std::string GroupIdStr(u16 gid)
{
return StringFromFormat("%c%c", gid >> 8, gid & 0xFF);
return fmt::format("{}{}", static_cast<char>(gid >> 8), static_cast<char>(gid & 0xFF));
}
} // namespace
@ -119,9 +121,8 @@ void WFSI::SetImportTitleIdAndGroupId(u64 tid, u16 gid)
void WFSI::FinalizePatchInstall()
{
const std::string current_title_dir =
StringFromFormat("/vol/%s/title/%s/%s", m_device_name.c_str(), m_current_group_id_str.c_str(),
m_current_title_id_str.c_str());
const std::string current_title_dir = fmt::format("/vol/{}/title/{}/{}", m_device_name,
m_current_group_id_str, m_current_title_id_str);
const std::string patch_dir = current_title_dir + "/_patch";
File::CopyDir(WFS::NativePath(patch_dir), WFS::NativePath(current_title_dir), true);
}
@ -145,9 +146,8 @@ IPCCommandResult WFSI::IOCtl(const IOCtlRequest& request)
if (m_patch_type == PatchType::PATCH_TYPE_2)
{
const std::string content_dir =
StringFromFormat("/vol/%s/title/%s/%s/content", m_device_name.c_str(),
m_current_group_id_str.c_str(), m_current_title_id_str.c_str());
const std::string content_dir = fmt::format("/vol/{}/title/{}/{}/content", m_device_name,
m_current_group_id_str, m_current_title_id_str);
File::Rename(WFS::NativePath(content_dir + "/default.dol"),
WFS::NativePath(content_dir + "/_default.dol"));
@ -185,7 +185,7 @@ IPCCommandResult WFSI::IOCtl(const IOCtlRequest& request)
}
case IOCTL_WFSI_PREPARE_PROFILE:
m_base_extract_path = StringFromFormat("/vol/%s/tmp/", m_device_name.c_str());
m_base_extract_path = fmt::format("/vol/{}/tmp/", m_device_name);
[[fallthrough]];
case IOCTL_WFSI_PREPARE_CONTENT:
@ -274,14 +274,13 @@ IPCCommandResult WFSI::IOCtl(const IOCtlRequest& request)
{
// Delete content's default.dol
const std::string title_content_dir =
StringFromFormat("/vol/%s/title/%s/%s/content/", m_device_name.c_str(),
m_current_group_id_str.c_str(), m_current_title_id_str.c_str());
fmt::format("/vol/{}/title/{}/{}/content/", m_device_name, m_current_group_id_str,
m_current_title_id_str);
File::Delete(WFS::NativePath(title_content_dir + "default.dol"));
// Copy content's _default.dol to patch's directory
const std::string patch_dir =
StringFromFormat("/vol/%s/title/%s/%s/_patch/", m_device_name.c_str(),
m_current_group_id_str.c_str(), m_current_title_id_str.c_str());
const std::string patch_dir = fmt::format("/vol/{}/title/{}/{}/_patch/", m_device_name,
m_current_group_id_str, m_current_title_id_str);
const std::string patch_content_dir = patch_dir + "content/";
File::CreateDir(WFS::NativePath(patch_dir));
File::CreateDir(WFS::NativePath(patch_content_dir));
@ -293,28 +292,24 @@ IPCCommandResult WFSI::IOCtl(const IOCtlRequest& request)
}
case PATCH_TYPE_1:
{
std::string patch_dir =
StringFromFormat("/vol/%s/title/%s/%s/_patch", m_device_name.c_str(),
m_current_group_id_str.c_str(), m_current_title_id_str.c_str());
const std::string patch_dir = fmt::format("/vol/{}/title/{}/{}/_patch", m_device_name,
m_current_group_id_str, m_current_title_id_str);
File::DeleteDirRecursively(WFS::NativePath(patch_dir));
tmd_path = StringFromFormat("/vol/%s/title/%s/%s/meta/%016" PRIx64 ".tmd",
m_device_name.c_str(), m_current_group_id_str.c_str(),
m_current_title_id_str.c_str(), m_import_title_id);
tmd_path = fmt::format("/vol/{}/title/{}/{}/meta/{:016x}.tmd", m_device_name,
m_current_group_id_str, m_current_title_id_str, m_import_title_id);
break;
}
case NOT_A_PATCH:
{
std::string title_install_dir = StringFromFormat("/vol/%s/_install/%s", m_device_name.c_str(),
m_import_title_id_str.c_str());
std::string title_final_dir =
StringFromFormat("/vol/%s/title/%s/%s", m_device_name.c_str(),
m_import_group_id_str.c_str(), m_import_title_id_str.c_str());
const std::string title_install_dir =
fmt::format("/vol/{}/_install/{}", m_device_name, m_import_title_id_str);
const std::string title_final_dir = fmt::format("/vol/{}/title/{}/{}", m_device_name,
m_import_group_id_str, m_import_title_id_str);
File::Rename(WFS::NativePath(title_install_dir), WFS::NativePath(title_final_dir));
tmd_path = StringFromFormat("/vol/%s/title/%s/%s/meta/%016" PRIx64 ".tmd",
m_device_name.c_str(), m_import_group_id_str.c_str(),
m_import_title_id_str.c_str(), m_import_title_id);
tmd_path = fmt::format("/vol/{}/title/{}/{}/meta/{:016x}.tmd", m_device_name,
m_import_group_id_str, m_import_title_id_str, m_import_title_id);
break;
}
}
@ -348,9 +343,8 @@ IPCCommandResult WFSI::IOCtl(const IOCtlRequest& request)
SetCurrentTitleIdAndGroupId(title_id, group_id);
// Change home directory
const std::string homedir_path =
StringFromFormat("/vol/%s/title/%s/%s/", m_device_name.c_str(),
m_current_group_id_str.c_str(), m_current_title_id_str.c_str());
const std::string homedir_path = fmt::format("/vol/{}/title/{}/{}/", m_device_name,
m_current_group_id_str, m_current_title_id_str);
const u16 homedir_path_len = static_cast<u16>(homedir_path.size());
INFO_LOG(IOS_WFS, "IOCTL_WFSI_CHANGE_TITLE: %s (path_len: 0x%x)", homedir_path.c_str(),
homedir_path_len);
@ -414,34 +408,32 @@ IPCCommandResult WFSI::IOCtl(const IOCtlRequest& request)
if (m_patch_type == NOT_A_PATCH)
{
std::string install_directory = StringFromFormat("/vol/%s/_install", m_device_name.c_str());
const std::string install_directory = fmt::format("/vol/{}/_install", m_device_name);
if (!m_continue_install && File::IsDirectory(WFS::NativePath(install_directory)))
{
File::DeleteDirRecursively(WFS::NativePath(install_directory));
}
m_base_extract_path = StringFromFormat("%s/%s/content", install_directory.c_str(),
m_import_title_id_str.c_str());
m_base_extract_path = fmt::format("{}/{}/content", install_directory, m_import_title_id_str);
File::CreateFullPath(WFS::NativePath(m_base_extract_path));
File::CreateDir(WFS::NativePath(m_base_extract_path));
for (auto dir : {"work", "meta", "save"})
for (const auto dir : {"work", "meta", "save"})
{
std::string path = StringFromFormat("%s/%s/%s", install_directory.c_str(),
m_import_title_id_str.c_str(), dir);
const std::string path =
fmt::format("{}/{}/{}", install_directory, m_import_title_id_str, dir);
File::CreateDir(WFS::NativePath(path));
}
std::string group_path = StringFromFormat("/vol/%s/title/%s", m_device_name.c_str(),
m_import_group_id_str.c_str());
const std::string group_path =
fmt::format("/vol/{}/title/{}", m_device_name, m_import_group_id_str);
File::CreateFullPath(WFS::NativePath(group_path));
File::CreateDir(WFS::NativePath(group_path));
}
else
{
m_base_extract_path =
StringFromFormat("/vol/%s/title/%s/%s/_patch/content", m_device_name.c_str(),
m_current_group_id_str.c_str(), m_current_title_id_str.c_str());
m_base_extract_path = fmt::format("/vol/{}/title/{}/{}/_patch/content", m_device_name,
m_current_group_id_str, m_current_title_id_str);
File::CreateFullPath(WFS::NativePath(m_base_extract_path));
File::CreateDir(WFS::NativePath(m_base_extract_path));
}
@ -489,13 +481,12 @@ IPCCommandResult WFSI::IOCtl(const IOCtlRequest& request)
case IOCTL_WFSI_LOAD_DOL:
{
std::string path =
StringFromFormat("/vol/%s/title/%s/%s/content", m_device_name.c_str(),
m_current_group_id_str.c_str(), m_current_title_id_str.c_str());
std::string path = fmt::format("/vol/{}/title/{}/{}/content", m_device_name,
m_current_group_id_str, m_current_title_id_str);
u32 dol_addr = Memory::Read_U32(request.buffer_in + 0x18);
u32 max_dol_size = Memory::Read_U32(request.buffer_in + 0x14);
u16 dol_extension_id = Memory::Read_U16(request.buffer_in + 0x1e);
const u32 dol_addr = Memory::Read_U32(request.buffer_in + 0x18);
const u32 max_dol_size = Memory::Read_U32(request.buffer_in + 0x14);
const u16 dol_extension_id = Memory::Read_U16(request.buffer_in + 0x1e);
if (dol_extension_id == 0)
{
@ -503,7 +494,7 @@ IPCCommandResult WFSI::IOCtl(const IOCtlRequest& request)
}
else
{
path += StringFromFormat("/extension%d.dol", dol_extension_id);
path += fmt::format("/extension{}.dol", dol_extension_id);
}
INFO_LOG(IOS_WFS, "IOCTL_WFSI_LOAD_DOL: loading %s at address %08x (size %d)", path.c_str(),
@ -562,9 +553,8 @@ IPCCommandResult WFSI::IOCtl(const IOCtlRequest& request)
u32 WFSI::GetTmd(u16 group_id, u32 title_id, u64 subtitle_id, u32 address, u32* size) const
{
std::string path =
StringFromFormat("/vol/%s/title/%s/%s/meta/%016" PRIx64 ".tmd", m_device_name.c_str(),
GroupIdStr(group_id).c_str(), TitleIdStr(title_id).c_str(), subtitle_id);
const std::string path = fmt::format("/vol/{}/title/{}/{}/meta/{:016x}.tmd", m_device_name,
GroupIdStr(group_id), TitleIdStr(title_id), subtitle_id);
File::IOFile fp(WFS::NativePath(path), "rb");
if (!fp)
{
@ -581,10 +571,8 @@ u32 WFSI::GetTmd(u16 group_id, u32 title_id, u64 subtitle_id, u32 address, u32*
static s32 DeleteTemporaryFiles(const std::string& device_name, u64 title_id)
{
File::Delete(WFS::NativePath(
StringFromFormat("/vol/%s/tmp/%016" PRIx64 ".ini", device_name.c_str(), title_id)));
File::Delete(WFS::NativePath(
StringFromFormat("/vol/%s/tmp/%016" PRIx64 ".ppcini", device_name.c_str(), title_id)));
File::Delete(WFS::NativePath(fmt::format("/vol/{}/tmp/{:016x}.ini", device_name, title_id)));
File::Delete(WFS::NativePath(fmt::format("/vol/{}/tmp/{:016x}.ppcini", device_name, title_id)));
return IPC_SUCCESS;
}
@ -594,8 +582,7 @@ s32 WFSI::CancelTitleImport(bool continue_install)
if (!continue_install)
{
File::DeleteDirRecursively(
WFS::NativePath(StringFromFormat("/vol/%s/_install", m_device_name.c_str())));
File::DeleteDirRecursively(WFS::NativePath(fmt::format("/vol/{}/_install", m_device_name)));
}
DeleteTemporaryFiles(m_device_name, m_import_title_id);
@ -609,16 +596,15 @@ s32 WFSI::CancelPatchImport(bool continue_install)
if (!continue_install)
{
File::DeleteDirRecursively(WFS::NativePath(
StringFromFormat("/vol/%s/title/%s/%s/_patch", m_device_name.c_str(),
m_current_group_id_str.c_str(), m_current_title_id_str.c_str())));
File::DeleteDirRecursively(
WFS::NativePath(fmt::format("/vol/{}/title/{}/{}/_patch", m_device_name,
m_current_group_id_str, m_current_title_id_str)));
if (m_patch_type == PatchType::PATCH_TYPE_2)
{
// Move back _default.dol to default.dol.
const std::string content_dir =
StringFromFormat("/vol/%s/title/%s/%s/content", m_device_name.c_str(),
m_current_group_id_str.c_str(), m_current_title_id_str.c_str());
const std::string content_dir = fmt::format("/vol/{}/title/{}/{}/content", m_device_name,
m_current_group_id_str, m_current_title_id_str);
File::Rename(WFS::NativePath(content_dir + "/_default.dol"),
WFS::NativePath(content_dir + "/default.dol"));
}

View File

@ -8,13 +8,14 @@
#include <string>
#include <vector>
#include <fmt/format.h>
#include "Common/CommonPaths.h"
#include "Common/CommonTypes.h"
#include "Common/File.h"
#include "Common/FileUtil.h"
#include "Common/Logging/Log.h"
#include "Common/NandPaths.h"
#include "Common/StringUtil.h"
#include "Core/ConfigManager.h"
#include "Core/HW/WiiSave.h"
#include "Core/IOS/ES/ES.h"
@ -268,7 +269,7 @@ void CleanUpWiiFileSystemContents()
const auto user_save = WiiSave::MakeNandStorage(configured_fs.get(), title_id);
const std::string backup_path =
File::GetUserPath(D_BACKUP_IDX) + StringFromFormat("/%016" PRIx64 ".bin", title_id);
fmt::format("{}/{:016x}.bin", File::GetUserPath(D_BACKUP_IDX), title_id);
const auto backup_save = WiiSave::MakeDataBinStorage(&ios->GetIOSC(), backup_path, "w+b");
// Backup the existing save just in case it's still needed.

View File

@ -8,7 +8,6 @@
#include <bitset>
#include <cinttypes>
#include <cstddef>
#include <cstring>
#include <map>
#include <memory>
#include <optional>
@ -18,10 +17,10 @@
#include <utility>
#include <vector>
#include <fmt/format.h>
#include <pugixml.hpp>
#include "Common/Assert.h"
#include "Common/CommonPaths.h"
#include "Common/CommonTypes.h"
#include "Common/FileUtil.h"
#include "Common/HttpRequest.h"
@ -43,7 +42,6 @@
#include "DiscIO/Filesystem.h"
#include "DiscIO/Volume.h"
#include "DiscIO/VolumeFileBlobReader.h"
#include "DiscIO/VolumeWii.h"
#include "DiscIO/WiiWad.h"
namespace WiiUtils
@ -232,7 +230,7 @@ std::string SystemUpdater::GetDeviceId()
u32 ios_device_id;
if (m_ios.GetES()->GetDeviceId(&ios_device_id) < 0)
return "";
return StringFromFormat("%" PRIu64, (u64(1) << 32) | ios_device_id);
return std::to_string((u64(1) << 32) | ios_device_id);
}
class OnlineSystemUpdater final : public SystemUpdater
@ -531,10 +529,9 @@ UpdateResult OnlineSystemUpdater::InstallTitleFromNUS(const std::string& prefix_
std::pair<IOS::ES::TMDReader, std::vector<u8>>
OnlineSystemUpdater::DownloadTMD(const std::string& prefix_url, const TitleInfo& title)
{
const std::string url =
(title.version == 0) ?
prefix_url + StringFromFormat("/%016" PRIx64 "/tmd", title.id) :
prefix_url + StringFromFormat("/%016" PRIx64 "/tmd.%u", title.id, title.version);
const std::string url = (title.version == 0) ?
fmt::format("{}/{:016x}/tmd", prefix_url, title.id) :
fmt::format("{}/{:016x}/tmd.{}", prefix_url, title.id, title.version);
const Common::HttpRequest::Response response = m_http.Get(url);
if (!response)
return {};
@ -559,7 +556,7 @@ OnlineSystemUpdater::DownloadTMD(const std::string& prefix_url, const TitleInfo&
std::pair<std::vector<u8>, std::vector<u8>>
OnlineSystemUpdater::DownloadTicket(const std::string& prefix_url, const TitleInfo& title)
{
const std::string url = prefix_url + StringFromFormat("/%016" PRIx64 "/cetk", title.id);
const std::string url = fmt::format("{}/{:016x}/cetk", prefix_url, title.id);
const Common::HttpRequest::Response response = m_http.Get(url);
if (!response)
return {};
@ -576,7 +573,7 @@ OnlineSystemUpdater::DownloadTicket(const std::string& prefix_url, const TitleIn
std::optional<std::vector<u8>> OnlineSystemUpdater::DownloadContent(const std::string& prefix_url,
const TitleInfo& title, u32 cid)
{
const std::string url = prefix_url + StringFromFormat("/%016" PRIx64 "/%08x", title.id, cid);
const std::string url = fmt::format("{}/{:016x}/{:08x}", prefix_url, title.id, cid);
return m_http.Get(url);
}