DiscIO: Make use of fmt where applicable
Once nice benefit of fmt is that we can use positional arguments in localizable strings. This a feature which has been requested for the Korean translation of strings like "Errors were found in %zu blocks in the %s partition." and which will no doubt be useful for other languages too.
This commit is contained in:
parent
c9b2fbb64b
commit
d100c1dc37
|
@ -63,6 +63,7 @@ PUBLIC
|
||||||
zstd
|
zstd
|
||||||
|
|
||||||
PRIVATE
|
PRIVATE
|
||||||
|
fmt::fmt
|
||||||
minizip
|
minizip
|
||||||
pugixml
|
pugixml
|
||||||
ZLIB::ZLIB
|
ZLIB::ZLIB
|
||||||
|
|
|
@ -15,6 +15,8 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include <fmt/format.h>
|
||||||
#include <zlib.h>
|
#include <zlib.h>
|
||||||
|
|
||||||
#include "Common/Assert.h"
|
#include "Common/Assert.h"
|
||||||
|
@ -24,7 +26,6 @@
|
||||||
#include "Common/Hash.h"
|
#include "Common/Hash.h"
|
||||||
#include "Common/Logging/Log.h"
|
#include "Common/Logging/Log.h"
|
||||||
#include "Common/MsgHandler.h"
|
#include "Common/MsgHandler.h"
|
||||||
#include "Common/StringUtil.h"
|
|
||||||
#include "DiscIO/Blob.h"
|
#include "DiscIO/Blob.h"
|
||||||
#include "DiscIO/CompressedBlob.h"
|
#include "DiscIO/CompressedBlob.h"
|
||||||
#include "DiscIO/DiscScrubber.h"
|
#include "DiscIO/DiscScrubber.h"
|
||||||
|
@ -256,8 +257,8 @@ static ConversionResultCode Output(OutputParameters parameters, File::IOFile* ou
|
||||||
parameters.inpos == 0 ? 0 : static_cast<int>(100 * *position / parameters.inpos);
|
parameters.inpos == 0 ? 0 : static_cast<int>(100 * *position / parameters.inpos);
|
||||||
|
|
||||||
const std::string text =
|
const std::string text =
|
||||||
StringFromFormat(Common::GetStringT("%i of %i blocks. Compression ratio %i%%").c_str(),
|
fmt::format(Common::GetStringT("{0} of {1} blocks. Compression ratio {2}%"),
|
||||||
parameters.block_number, num_blocks, ratio);
|
parameters.block_number, num_blocks, ratio);
|
||||||
|
|
||||||
const float completion = static_cast<float>(parameters.block_number) / num_blocks;
|
const float completion = static_cast<float>(parameters.block_number) / num_blocks;
|
||||||
|
|
||||||
|
|
|
@ -9,10 +9,11 @@
|
||||||
#include <locale>
|
#include <locale>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
|
#include <fmt/format.h>
|
||||||
|
|
||||||
#include "Common/CommonTypes.h"
|
#include "Common/CommonTypes.h"
|
||||||
#include "Common/File.h"
|
#include "Common/File.h"
|
||||||
#include "Common/FileUtil.h"
|
#include "Common/FileUtil.h"
|
||||||
#include "Common/StringUtil.h"
|
|
||||||
#include "DiscIO/Enums.h"
|
#include "DiscIO/Enums.h"
|
||||||
#include "DiscIO/Filesystem.h"
|
#include "DiscIO/Filesystem.h"
|
||||||
#include "DiscIO/Volume.h"
|
#include "DiscIO/Volume.h"
|
||||||
|
@ -45,7 +46,7 @@ std::string NameForPartitionType(u32 partition_type, bool include_prefix)
|
||||||
return include_prefix ? "P-" + type_as_game_id : type_as_game_id;
|
return include_prefix ? "P-" + type_as_game_id : type_as_game_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
return StringFromFormat(include_prefix ? "P%u" : "%u", partition_type);
|
return fmt::format(include_prefix ? "P{}" : "{}", partition_type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,12 +9,13 @@
|
||||||
#include <cinttypes>
|
#include <cinttypes>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
|
#include <fmt/format.h>
|
||||||
|
|
||||||
#include "Common/Crypto/AES.h"
|
#include "Common/Crypto/AES.h"
|
||||||
#include "Common/File.h"
|
#include "Common/File.h"
|
||||||
#include "Common/FileUtil.h"
|
#include "Common/FileUtil.h"
|
||||||
#include "Common/Logging/Log.h"
|
#include "Common/Logging/Log.h"
|
||||||
#include "Common/MsgHandler.h"
|
#include "Common/MsgHandler.h"
|
||||||
#include "Common/StringUtil.h"
|
|
||||||
#include "Common/Swap.h"
|
#include "Common/Swap.h"
|
||||||
#include "Core/IOS/ES/Formats.h"
|
#include "Core/IOS/ES/Formats.h"
|
||||||
|
|
||||||
|
@ -132,9 +133,10 @@ std::string NANDImporter::GetPath(const NANDFSTEntry& entry, const std::string&
|
||||||
|
|
||||||
std::string NANDImporter::FormatDebugString(const NANDFSTEntry& entry)
|
std::string NANDImporter::FormatDebugString(const NANDFSTEntry& entry)
|
||||||
{
|
{
|
||||||
return StringFromFormat("%12.12s 0x%02x 0x%02x 0x%04x 0x%04x 0x%08x 0x%04x 0x%04x 0x%04x 0x%08x",
|
return fmt::format(
|
||||||
entry.name, entry.mode, entry.attr, entry.sub, entry.sib, entry.size,
|
"{:12.12} {:#04x} {:#04x} {:#06x} {:#06x} {:#010x} {:#06x} {:#06x} {:#06x} {:#010x}",
|
||||||
entry.x1, entry.uid, entry.gid, entry.x3);
|
entry.name, entry.mode, entry.attr, entry.sub, entry.sib, entry.size, entry.x1, entry.uid,
|
||||||
|
entry.gid, entry.x3);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NANDImporter::ProcessEntry(u16 entry_number, const std::string& parent_path)
|
void NANDImporter::ProcessEntry(u16 entry_number, const std::string& parent_path)
|
||||||
|
@ -216,7 +218,7 @@ bool NANDImporter::ExtractCertificates(const std::string& nand_root)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
File::IOFile content_file(content_dir + StringFromFormat("%08x.app", content_metadata.id), "rb");
|
File::IOFile content_file(content_dir + fmt::format("{:08x}.app", content_metadata.id), "rb");
|
||||||
std::vector<u8> content_bytes(content_file.GetSize());
|
std::vector<u8> content_bytes(content_file.GetSize());
|
||||||
if (!content_file.ReadBytes(content_bytes.data(), content_bytes.size()))
|
if (!content_file.ReadBytes(content_bytes.data(), content_bytes.size()))
|
||||||
{
|
{
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
|
|
||||||
|
#include <fmt/format.h>
|
||||||
#include <mbedtls/md5.h>
|
#include <mbedtls/md5.h>
|
||||||
#include <mbedtls/sha1.h>
|
#include <mbedtls/sha1.h>
|
||||||
#include <pugixml.hpp>
|
#include <pugixml.hpp>
|
||||||
|
@ -519,10 +520,8 @@ bool VolumeVerifier::CheckPartition(const Partition& partition)
|
||||||
if (partition.offset % VolumeWii::BLOCK_TOTAL_SIZE != 0 ||
|
if (partition.offset % VolumeWii::BLOCK_TOTAL_SIZE != 0 ||
|
||||||
m_volume.PartitionOffsetToRawOffset(0, partition) % VolumeWii::BLOCK_TOTAL_SIZE != 0)
|
m_volume.PartitionOffsetToRawOffset(0, partition) % VolumeWii::BLOCK_TOTAL_SIZE != 0)
|
||||||
{
|
{
|
||||||
AddProblem(
|
AddProblem(Severity::Medium,
|
||||||
Severity::Medium,
|
fmt::format(Common::GetStringT("The {0} partition is not properly aligned."), name));
|
||||||
StringFromFormat(Common::GetStringT("The %s partition is not properly aligned.").c_str(),
|
|
||||||
name.c_str()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!m_is_datel)
|
if (!m_is_datel)
|
||||||
|
@ -542,16 +541,14 @@ bool VolumeVerifier::CheckPartition(const Partition& partition)
|
||||||
{
|
{
|
||||||
AddProblem(
|
AddProblem(
|
||||||
Severity::Low,
|
Severity::Low,
|
||||||
StringFromFormat(Common::GetStringT("The %s partition is not correctly signed.").c_str(),
|
fmt::format(Common::GetStringT("The {0} partition is not correctly signed."), name));
|
||||||
name.c_str()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_volume.SupportsIntegrityCheck() && !m_volume.CheckH3TableIntegrity(partition))
|
if (m_volume.SupportsIntegrityCheck() && !m_volume.CheckH3TableIntegrity(partition))
|
||||||
{
|
{
|
||||||
std::string text = StringFromFormat(
|
std::string text = fmt::format(
|
||||||
Common::GetStringT("The H3 hash table for the %s partition is not correct.").c_str(),
|
Common::GetStringT("The H3 hash table for the {0} partition is not correct."), name);
|
||||||
name.c_str());
|
|
||||||
AddProblem(Severity::Low, std::move(text));
|
AddProblem(Severity::Low, std::move(text));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -584,9 +581,8 @@ bool VolumeVerifier::CheckPartition(const Partition& partition)
|
||||||
// This can happen when certain programs that create WBFS files scrub the entirety of
|
// This can happen when certain programs that create WBFS files scrub the entirety of
|
||||||
// the Masterpiece partitions in Super Smash Bros. Brawl without removing them from
|
// the Masterpiece partitions in Super Smash Bros. Brawl without removing them from
|
||||||
// the partition table. https://bugs.dolphin-emu.org/issues/8733
|
// the partition table. https://bugs.dolphin-emu.org/issues/8733
|
||||||
std::string text = StringFromFormat(
|
std::string text = fmt::format(
|
||||||
Common::GetStringT("The %s partition does not seem to contain valid data.").c_str(),
|
Common::GetStringT("The {0} partition does not seem to contain valid data."), name);
|
||||||
name.c_str());
|
|
||||||
AddProblem(severity, std::move(text));
|
AddProblem(severity, std::move(text));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -614,9 +610,8 @@ bool VolumeVerifier::CheckPartition(const Partition& partition)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string text = StringFromFormat(
|
std::string text = fmt::format(
|
||||||
Common::GetStringT("The %s partition does not have a valid file system.").c_str(),
|
Common::GetStringT("The {0} partition does not have a valid file system."), name);
|
||||||
name.c_str());
|
|
||||||
AddProblem(severity, std::move(text));
|
AddProblem(severity, std::move(text));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -675,7 +670,7 @@ std::string VolumeVerifier::GetPartitionName(std::optional<u32> type) const
|
||||||
// (French), Clásicos (Spanish), Capolavori (Italian), 클래식 게임 체험판 (Korean).
|
// (French), Clásicos (Spanish), Capolavori (Italian), 클래식 게임 체험판 (Korean).
|
||||||
// If your language is not one of the languages above, consider leaving the string untranslated
|
// If your language is not one of the languages above, consider leaving the string untranslated
|
||||||
// so that people will recognize it as the name of the game mode.
|
// so that people will recognize it as the name of the game mode.
|
||||||
name = StringFromFormat(Common::GetStringT("%s (Masterpiece)").c_str(), name.c_str());
|
name = fmt::format(Common::GetStringT("{0} (Masterpiece)"), name);
|
||||||
}
|
}
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
@ -903,10 +898,9 @@ void VolumeVerifier::CheckMisc()
|
||||||
// Hacked version of the Wii Backup Disc (aka "pinkfish" disc).
|
// Hacked version of the Wii Backup Disc (aka "pinkfish" disc).
|
||||||
std::string proper_game_id = game_id_unencrypted;
|
std::string proper_game_id = game_id_unencrypted;
|
||||||
proper_game_id[0] = '4';
|
proper_game_id[0] = '4';
|
||||||
AddProblem(
|
AddProblem(Severity::Low,
|
||||||
Severity::Low,
|
fmt::format(Common::GetStringT("The game ID is {0} but should be {1}."),
|
||||||
StringFromFormat(Common::GetStringT("The game ID is %s but should be %s.").c_str(),
|
game_id_unencrypted, proper_game_id));
|
||||||
game_id_unencrypted.c_str(), proper_game_id.c_str()));
|
|
||||||
inconsistent_game_id = false;
|
inconsistent_game_id = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1000,9 +994,9 @@ void VolumeVerifier::CheckMisc()
|
||||||
{
|
{
|
||||||
// Many fakesigned WADs have the common key index set to a (random?) bogus value.
|
// Many fakesigned WADs have the common key index set to a (random?) bogus value.
|
||||||
// For WADs, Dolphin will detect this and use the correct key, making this low severity.
|
// For WADs, Dolphin will detect this and use the correct key, making this low severity.
|
||||||
std::string text = StringFromFormat(
|
std::string text = fmt::format(
|
||||||
// i18n: This is "common" as in "shared", not the opposite of "uncommon"
|
// i18n: This is "common" as in "shared", not the opposite of "uncommon"
|
||||||
Common::GetStringT("The specified common key index is %u but should be %u.").c_str(),
|
Common::GetStringT("The specified common key index is {0} but should be {1}."),
|
||||||
specified_common_key_index, fixed_common_key_index);
|
specified_common_key_index, fixed_common_key_index);
|
||||||
AddProblem(Severity::Low, std::move(text));
|
AddProblem(Severity::Low, std::move(text));
|
||||||
}
|
}
|
||||||
|
@ -1214,9 +1208,8 @@ void VolumeVerifier::Process()
|
||||||
m_content_future = std::async(std::launch::async, [this, read_succeeded, content] {
|
m_content_future = std::async(std::launch::async, [this, read_succeeded, content] {
|
||||||
if (!read_succeeded || !m_volume.CheckContentIntegrity(content, m_data, m_ticket))
|
if (!read_succeeded || !m_volume.CheckContentIntegrity(content, m_data, m_ticket))
|
||||||
{
|
{
|
||||||
AddProblem(
|
AddProblem(Severity::High,
|
||||||
Severity::High,
|
fmt::format(Common::GetStringT("Content {0:08x} is corrupt."), content.id));
|
||||||
StringFromFormat(Common::GetStringT("Content %08x is corrupt.").c_str(), content.id));
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1331,9 +1324,9 @@ void VolumeVerifier::Finish()
|
||||||
if (blocks > 0)
|
if (blocks > 0)
|
||||||
{
|
{
|
||||||
const std::string name = GetPartitionName(m_volume.GetPartitionType(partition));
|
const std::string name = GetPartitionName(m_volume.GetPartitionType(partition));
|
||||||
std::string text = StringFromFormat(
|
std::string text =
|
||||||
Common::GetStringT("Errors were found in %zu blocks in the %s partition.").c_str(),
|
fmt::format(Common::GetStringT("Errors were found in {0} blocks in the {1} partition."),
|
||||||
blocks, name.c_str());
|
blocks, name);
|
||||||
AddProblem(Severity::Medium, std::move(text));
|
AddProblem(Severity::Medium, std::move(text));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1343,9 +1336,9 @@ void VolumeVerifier::Finish()
|
||||||
if (blocks > 0)
|
if (blocks > 0)
|
||||||
{
|
{
|
||||||
const std::string name = GetPartitionName(m_volume.GetPartitionType(partition));
|
const std::string name = GetPartitionName(m_volume.GetPartitionType(partition));
|
||||||
std::string text = StringFromFormat(
|
std::string text = fmt::format(
|
||||||
Common::GetStringT("Errors were found in %zu unused blocks in the %s partition.").c_str(),
|
Common::GetStringT("Errors were found in {0} unused blocks in the {1} partition."),
|
||||||
blocks, name.c_str());
|
blocks, name);
|
||||||
AddProblem(Severity::Low, std::move(text));
|
AddProblem(Severity::Low, std::move(text));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
|
#include <fmt/format.h>
|
||||||
#include <mbedtls/sha1.h>
|
#include <mbedtls/sha1.h>
|
||||||
#include <zstd.h>
|
#include <zstd.h>
|
||||||
|
|
||||||
|
@ -27,7 +28,6 @@
|
||||||
#include "Common/Logging/Log.h"
|
#include "Common/Logging/Log.h"
|
||||||
#include "Common/MsgHandler.h"
|
#include "Common/MsgHandler.h"
|
||||||
#include "Common/ScopeGuard.h"
|
#include "Common/ScopeGuard.h"
|
||||||
#include "Common/StringUtil.h"
|
|
||||||
#include "Common/Swap.h"
|
#include "Common/Swap.h"
|
||||||
|
|
||||||
#include "DiscIO/Blob.h"
|
#include "DiscIO/Blob.h"
|
||||||
|
@ -617,9 +617,9 @@ std::string WIARVZFileReader<RVZ>::VersionToString(u32 version)
|
||||||
const u8 d = version & 0xff;
|
const u8 d = version & 0xff;
|
||||||
|
|
||||||
if (d == 0 || d == 0xff)
|
if (d == 0 || d == 0xff)
|
||||||
return StringFromFormat("%u.%02x.%02x", a, b, c);
|
return fmt::format("{}.{:02x}.{:02x}", a, b, c);
|
||||||
else
|
else
|
||||||
return StringFromFormat("%u.%02x.%02x.beta%u", a, b, c, d);
|
return fmt::format("{}.{:02x}.{:02x}.beta{}", a, b, c, d);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <bool RVZ>
|
template <bool RVZ>
|
||||||
|
@ -1695,8 +1695,8 @@ ConversionResultCode WIARVZFileReader<RVZ>::RunCallback(size_t groups_written, u
|
||||||
ratio = static_cast<int>(100 * bytes_written / bytes_read);
|
ratio = static_cast<int>(100 * bytes_written / bytes_read);
|
||||||
|
|
||||||
const std::string text =
|
const std::string text =
|
||||||
StringFromFormat(Common::GetStringT("%i of %i blocks. Compression ratio %i%%").c_str(),
|
fmt::format(Common::GetStringT("{0} of {1} blocks. Compression ratio {2}%"), groups_written,
|
||||||
groups_written, total_groups, ratio);
|
total_groups, ratio);
|
||||||
|
|
||||||
const float completion = static_cast<float>(bytes_read) / iso_size;
|
const float completion = static_cast<float>(bytes_read) / iso_size;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue