DiscIO: Migrate logging over to fmt

Eliminates quite a bit of the PRI* macros used for handling 64-bit
values.
This commit is contained in:
Lioncash 2020-10-21 14:58:08 -04:00
parent 09e87b79f1
commit e93fbb7c5e
12 changed files with 79 additions and 85 deletions

View file

@ -105,8 +105,8 @@ void NANDImporter::FindSuperblock()
{
if (!memcmp(m_nand.data() + pos, "SFFS", 4))
{
u32 version = Common::swap32(&m_nand[pos + 4]);
INFO_LOG(DISCIO, "Found superblock at 0x%zx with version 0x%x", pos, version);
const u32 version = Common::swap32(&m_nand[pos + 4]);
INFO_LOG_FMT(DISCIO, "Found superblock at {:#x} with version {:#x}", pos, version);
if (superblock == 0 || version > newest_version)
{
superblock = pos;
@ -117,8 +117,9 @@ void NANDImporter::FindSuperblock()
m_nand_fat_offset = superblock + 0xC;
m_nand_fst_offset = m_nand_fat_offset + 0x10000;
INFO_LOG(DISCIO, "Using superblock version 0x%x at position 0x%zx. FAT/FST offset: 0x%zx/0x%zx",
newest_version, superblock, m_nand_fat_offset, m_nand_fst_offset);
INFO_LOG_FMT(DISCIO,
"Using superblock version {:#x} at position {:#x}. FAT/FST offset: {:#x}/{:#x}",
newest_version, superblock, m_nand_fat_offset, m_nand_fst_offset);
}
std::string NANDImporter::GetPath(const NANDFSTEntry& entry, const std::string& parent_path)
@ -153,13 +154,13 @@ void NANDImporter::ProcessEntry(u16 entry_number, const std::string& parent_path
else if ((entry.mode & 3) == 2)
ProcessDirectory(entry, parent_path);
else
ERROR_LOG(DISCIO, "Unknown mode: %s", FormatDebugString(entry).c_str());
ERROR_LOG_FMT(DISCIO, "Unknown mode: {}", FormatDebugString(entry));
}
void NANDImporter::ProcessDirectory(const NANDFSTEntry& entry, const std::string& parent_path)
{
m_update_callback();
INFO_LOG(DISCIO, "Path: %s", FormatDebugString(entry).c_str());
INFO_LOG_FMT(DISCIO, "Path: {}", FormatDebugString(entry));
const std::string path = GetPath(entry, parent_path);
File::CreateDir(path);
@ -167,7 +168,7 @@ void NANDImporter::ProcessDirectory(const NANDFSTEntry& entry, const std::string
if (entry.sub != 0xffff)
ProcessEntry(entry.sub, path);
INFO_LOG(DISCIO, "Path: %s", parent_path.c_str() + m_nand_root_length);
INFO_LOG_FMT(DISCIO, "Path: {}", parent_path.data() + m_nand_root_length);
}
void NANDImporter::ProcessFile(const NANDFSTEntry& entry, const std::string& parent_path)
@ -176,7 +177,7 @@ void NANDImporter::ProcessFile(const NANDFSTEntry& entry, const std::string& par
constexpr size_t NAND_FAT_BLOCK_SIZE = 0x4000;
m_update_callback();
INFO_LOG(DISCIO, "File: %s", FormatDebugString(entry).c_str());
INFO_LOG_FMT(DISCIO, "File: {}", FormatDebugString(entry));
const std::string path = GetPath(entry, parent_path);
File::IOFile file(path, "wb");
@ -206,7 +207,7 @@ bool NANDImporter::ExtractCertificates(const std::string& nand_root)
std::vector<u8> tmd_bytes(tmd_file.GetSize());
if (!tmd_file.ReadBytes(tmd_bytes.data(), tmd_bytes.size()))
{
ERROR_LOG(DISCIO, "ExtractCertificates: Could not read IOS13 TMD");
ERROR_LOG_FMT(DISCIO, "ExtractCertificates: Could not read IOS13 TMD");
return false;
}
@ -214,7 +215,7 @@ bool NANDImporter::ExtractCertificates(const std::string& nand_root)
IOS::ES::Content content_metadata;
if (!tmd.GetContent(tmd.GetBootIndex(), &content_metadata))
{
ERROR_LOG(DISCIO, "ExtractCertificates: Could not get content ID from TMD");
ERROR_LOG_FMT(DISCIO, "ExtractCertificates: Could not get content ID from TMD");
return false;
}
@ -222,17 +223,17 @@ bool NANDImporter::ExtractCertificates(const std::string& nand_root)
std::vector<u8> content_bytes(content_file.GetSize());
if (!content_file.ReadBytes(content_bytes.data(), content_bytes.size()))
{
ERROR_LOG(DISCIO, "ExtractCertificates: Could not read IOS13 contents");
ERROR_LOG_FMT(DISCIO, "ExtractCertificates: Could not read IOS13 contents");
return false;
}
struct PEMCertificate
{
std::string filename;
std::string_view filename;
std::array<u8, 4> search_bytes;
};
std::array<PEMCertificate, 3> certificates = {{
static constexpr std::array<PEMCertificate, 3> certificates{{
{"/clientca.pem", {{0x30, 0x82, 0x03, 0xE9}}},
{"/clientcakey.pem", {{0x30, 0x82, 0x02, 0x5D}}},
{"/rootca.pem", {{0x30, 0x82, 0x03, 0x7D}}},
@ -246,21 +247,21 @@ bool NANDImporter::ExtractCertificates(const std::string& nand_root)
if (search_result == content_bytes.end())
{
ERROR_LOG(DISCIO, "ExtractCertificates: Could not find offset for certficate '%s'",
certificate.filename.c_str());
ERROR_LOG_FMT(DISCIO, "ExtractCertificates: Could not find offset for certficate '{}'",
certificate.filename);
return false;
}
const std::string pem_file_path = nand_root + certificate.filename;
const std::string pem_file_path = nand_root + std::string(certificate.filename);
const ptrdiff_t certificate_offset = std::distance(content_bytes.begin(), search_result);
const u16 certificate_size = Common::swap16(&content_bytes[certificate_offset - 2]);
INFO_LOG(DISCIO, "ExtractCertificates: '%s' offset: 0x%tx size: 0x%x",
certificate.filename.c_str(), certificate_offset, certificate_size);
INFO_LOG_FMT(DISCIO, "ExtractCertificates: '{}' offset: {:#x} size: {:#x}",
certificate.filename, certificate_offset, certificate_size);
File::IOFile pem_file(pem_file_path, "wb");
if (!pem_file.WriteBytes(&content_bytes[certificate_offset], certificate_size))
{
ERROR_LOG(DISCIO, "ExtractCertificates: Unable to write to file %s", pem_file_path.c_str());
ERROR_LOG_FMT(DISCIO, "ExtractCertificates: Unable to write to file {}", pem_file_path);
return false;
}
}