From d100c1dc37596bce348d93e376b00d4a56458613 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Wed, 14 Oct 2020 18:34:45 +0200 Subject: 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. --- Source/Core/DiscIO/VolumeVerifier.cpp | 55 +++++++++++++++-------------------- 1 file changed, 24 insertions(+), 31 deletions(-) (limited to 'Source/Core/DiscIO/VolumeVerifier.cpp') diff --git a/Source/Core/DiscIO/VolumeVerifier.cpp b/Source/Core/DiscIO/VolumeVerifier.cpp index 6dee5b8796..e28159050b 100644 --- a/Source/Core/DiscIO/VolumeVerifier.cpp +++ b/Source/Core/DiscIO/VolumeVerifier.cpp @@ -16,6 +16,7 @@ #include #include +#include #include #include #include @@ -519,10 +520,8 @@ bool VolumeVerifier::CheckPartition(const Partition& partition) if (partition.offset % VolumeWii::BLOCK_TOTAL_SIZE != 0 || m_volume.PartitionOffsetToRawOffset(0, partition) % VolumeWii::BLOCK_TOTAL_SIZE != 0) { - AddProblem( - Severity::Medium, - StringFromFormat(Common::GetStringT("The %s partition is not properly aligned.").c_str(), - name.c_str())); + AddProblem(Severity::Medium, + fmt::format(Common::GetStringT("The {0} partition is not properly aligned."), name)); } if (!m_is_datel) @@ -542,16 +541,14 @@ bool VolumeVerifier::CheckPartition(const Partition& partition) { AddProblem( Severity::Low, - StringFromFormat(Common::GetStringT("The %s partition is not correctly signed.").c_str(), - name.c_str())); + fmt::format(Common::GetStringT("The {0} partition is not correctly signed."), name)); } } if (m_volume.SupportsIntegrityCheck() && !m_volume.CheckH3TableIntegrity(partition)) { - std::string text = StringFromFormat( - Common::GetStringT("The H3 hash table for the %s partition is not correct.").c_str(), - name.c_str()); + std::string text = fmt::format( + Common::GetStringT("The H3 hash table for the {0} partition is not correct."), name); 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 // the Masterpiece partitions in Super Smash Bros. Brawl without removing them from // the partition table. https://bugs.dolphin-emu.org/issues/8733 - std::string text = StringFromFormat( - Common::GetStringT("The %s partition does not seem to contain valid data.").c_str(), - name.c_str()); + std::string text = fmt::format( + Common::GetStringT("The {0} partition does not seem to contain valid data."), name); AddProblem(severity, std::move(text)); return false; } @@ -614,9 +610,8 @@ bool VolumeVerifier::CheckPartition(const Partition& partition) return true; } - std::string text = StringFromFormat( - Common::GetStringT("The %s partition does not have a valid file system.").c_str(), - name.c_str()); + std::string text = fmt::format( + Common::GetStringT("The {0} partition does not have a valid file system."), name); AddProblem(severity, std::move(text)); return false; } @@ -675,7 +670,7 @@ std::string VolumeVerifier::GetPartitionName(std::optional type) const // (French), Clásicos (Spanish), Capolavori (Italian), 클래식 게임 체험판 (Korean). // 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. - name = StringFromFormat(Common::GetStringT("%s (Masterpiece)").c_str(), name.c_str()); + name = fmt::format(Common::GetStringT("{0} (Masterpiece)"), name); } return name; } @@ -903,10 +898,9 @@ void VolumeVerifier::CheckMisc() // Hacked version of the Wii Backup Disc (aka "pinkfish" disc). std::string proper_game_id = game_id_unencrypted; proper_game_id[0] = '4'; - AddProblem( - Severity::Low, - StringFromFormat(Common::GetStringT("The game ID is %s but should be %s.").c_str(), - game_id_unencrypted.c_str(), proper_game_id.c_str())); + AddProblem(Severity::Low, + fmt::format(Common::GetStringT("The game ID is {0} but should be {1}."), + game_id_unencrypted, proper_game_id)); 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. // 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" - 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); 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] { if (!read_succeeded || !m_volume.CheckContentIntegrity(content, m_data, m_ticket)) { - AddProblem( - Severity::High, - StringFromFormat(Common::GetStringT("Content %08x is corrupt.").c_str(), content.id)); + AddProblem(Severity::High, + fmt::format(Common::GetStringT("Content {0:08x} is corrupt."), content.id)); } }); @@ -1331,9 +1324,9 @@ void VolumeVerifier::Finish() if (blocks > 0) { const std::string name = GetPartitionName(m_volume.GetPartitionType(partition)); - std::string text = StringFromFormat( - Common::GetStringT("Errors were found in %zu blocks in the %s partition.").c_str(), - blocks, name.c_str()); + std::string text = + fmt::format(Common::GetStringT("Errors were found in {0} blocks in the {1} partition."), + blocks, name); AddProblem(Severity::Medium, std::move(text)); } } @@ -1343,9 +1336,9 @@ void VolumeVerifier::Finish() if (blocks > 0) { const std::string name = GetPartitionName(m_volume.GetPartitionType(partition)); - std::string text = StringFromFormat( - Common::GetStringT("Errors were found in %zu unused blocks in the %s partition.").c_str(), - blocks, name.c_str()); + std::string text = fmt::format( + Common::GetStringT("Errors were found in {0} unused blocks in the {1} partition."), + blocks, name); AddProblem(Severity::Low, std::move(text)); } } -- cgit v1.2.3 From 1084cfec1aecd54daead865f56984ed5b8e5b6c0 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Wed, 14 Oct 2020 20:50:38 +0200 Subject: Add helper function for fmt::format(GetStringT(... --- Source/Core/DiscIO/VolumeVerifier.cpp | 70 +++++++++++++++-------------------- 1 file changed, 30 insertions(+), 40 deletions(-) (limited to 'Source/Core/DiscIO/VolumeVerifier.cpp') diff --git a/Source/Core/DiscIO/VolumeVerifier.cpp b/Source/Core/DiscIO/VolumeVerifier.cpp index e28159050b..c8cb3ba5bf 100644 --- a/Source/Core/DiscIO/VolumeVerifier.cpp +++ b/Source/Core/DiscIO/VolumeVerifier.cpp @@ -16,7 +16,6 @@ #include #include -#include #include #include #include @@ -521,7 +520,7 @@ bool VolumeVerifier::CheckPartition(const Partition& partition) m_volume.PartitionOffsetToRawOffset(0, partition) % VolumeWii::BLOCK_TOTAL_SIZE != 0) { AddProblem(Severity::Medium, - fmt::format(Common::GetStringT("The {0} partition is not properly aligned."), name)); + Common::FmtFormatT("The {0} partition is not properly aligned.", name)); } if (!m_is_datel) @@ -539,17 +538,15 @@ bool VolumeVerifier::CheckPartition(const Partition& partition) IOS::HLE::Device::ES::VerifyMode::DoNotUpdateCertStore, m_volume.GetTMD(partition), cert_chain)) { - AddProblem( - Severity::Low, - fmt::format(Common::GetStringT("The {0} partition is not correctly signed."), name)); + AddProblem(Severity::Low, + Common::FmtFormatT("The {0} partition is not correctly signed.", name)); } } if (m_volume.SupportsIntegrityCheck() && !m_volume.CheckH3TableIntegrity(partition)) { - std::string text = fmt::format( - Common::GetStringT("The H3 hash table for the {0} partition is not correct."), name); - AddProblem(Severity::Low, std::move(text)); + AddProblem(Severity::Low, + Common::FmtFormatT("The H3 hash table for the {0} partition is not correct.", name)); } bool invalid_disc_header = false; @@ -578,12 +575,11 @@ bool VolumeVerifier::CheckPartition(const Partition& partition) } if (invalid_disc_header) { - // 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 partition table. https://bugs.dolphin-emu.org/issues/8733 - std::string text = fmt::format( - Common::GetStringT("The {0} partition does not seem to contain valid data."), name); - AddProblem(severity, std::move(text)); + AddProblem(severity, + // 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 partition table. https://bugs.dolphin-emu.org/issues/8733 + Common::FmtFormatT("The {0} partition does not seem to contain valid data.", name)); return false; } @@ -610,9 +606,8 @@ bool VolumeVerifier::CheckPartition(const Partition& partition) return true; } - std::string text = fmt::format( - Common::GetStringT("The {0} partition does not have a valid file system."), name); - AddProblem(severity, std::move(text)); + AddProblem(severity, + Common::FmtFormatT("The {0} partition does not have a valid file system.", name)); return false; } @@ -670,7 +665,7 @@ std::string VolumeVerifier::GetPartitionName(std::optional type) const // (French), Clásicos (Spanish), Capolavori (Italian), 클래식 게임 체험판 (Korean). // 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. - name = fmt::format(Common::GetStringT("{0} (Masterpiece)"), name); + name = Common::FmtFormatT("{0} (Masterpiece)", name); } return name; } @@ -898,9 +893,8 @@ void VolumeVerifier::CheckMisc() // Hacked version of the Wii Backup Disc (aka "pinkfish" disc). std::string proper_game_id = game_id_unencrypted; proper_game_id[0] = '4'; - AddProblem(Severity::Low, - fmt::format(Common::GetStringT("The game ID is {0} but should be {1}."), - game_id_unencrypted, proper_game_id)); + AddProblem(Severity::Low, Common::FmtFormatT("The game ID is {0} but should be {1}.", + game_id_unencrypted, proper_game_id)); inconsistent_game_id = false; } } @@ -954,9 +948,9 @@ void VolumeVerifier::CheckMisc() if (region == Region::NTSC_K && ios_id < 40 && ios_id != 4 && ios_id != 9 && ios_id != 21 && ios_id != 37) { - // This is intended to catch pirated Korean games that have had the IOS slot set to 36 - // as a side effect of having to fakesign after changing the common key slot to 0. - // (IOS36 was the last IOS to have the Trucha bug.) https://bugs.dolphin-emu.org/issues/10319 + // This is intended to catch Korean games (usually but not always pirated) that have the IOS + // slot set to 36 as a side effect of having to fakesign after changing the common key slot to + // 0. (IOS36 was the last IOS with the Trucha bug.) https://bugs.dolphin-emu.org/issues/10319 AddProblem( Severity::High, // i18n: You may want to leave the term "ERROR #002" untranslated, @@ -967,7 +961,7 @@ void VolumeVerifier::CheckMisc() if (ios_id >= 0x80) { - // This is also intended to catch fakesigned pirated Korean games, + // This is intended to catch the same kind of fakesigned Korean games, // but this time with the IOS slot set to cIOS instead of IOS36. AddProblem(Severity::High, Common::GetStringT("This title is set to use an invalid IOS.")); } @@ -994,11 +988,10 @@ void VolumeVerifier::CheckMisc() { // 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. - std::string text = fmt::format( - // i18n: This is "common" as in "shared", not the opposite of "uncommon" - Common::GetStringT("The specified common key index is {0} but should be {1}."), - specified_common_key_index, fixed_common_key_index); - AddProblem(Severity::Low, std::move(text)); + AddProblem(Severity::Low, + // i18n: This is "common" as in "shared", not the opposite of "uncommon" + Common::FmtFormatT("The specified common key index is {0} but should be {1}.", + specified_common_key_index, fixed_common_key_index)); } } } @@ -1208,8 +1201,7 @@ void VolumeVerifier::Process() m_content_future = std::async(std::launch::async, [this, read_succeeded, content] { if (!read_succeeded || !m_volume.CheckContentIntegrity(content, m_data, m_ticket)) { - AddProblem(Severity::High, - fmt::format(Common::GetStringT("Content {0:08x} is corrupt."), content.id)); + AddProblem(Severity::High, Common::FmtFormatT("Content {0:08x} is corrupt.", content.id)); } }); @@ -1324,10 +1316,9 @@ void VolumeVerifier::Finish() if (blocks > 0) { const std::string name = GetPartitionName(m_volume.GetPartitionType(partition)); - std::string text = - fmt::format(Common::GetStringT("Errors were found in {0} blocks in the {1} partition."), - blocks, name); - AddProblem(Severity::Medium, std::move(text)); + AddProblem(Severity::Medium, + Common::FmtFormatT("Errors were found in {0} blocks in the {1} partition.", blocks, + name)); } } @@ -1336,10 +1327,9 @@ void VolumeVerifier::Finish() if (blocks > 0) { const std::string name = GetPartitionName(m_volume.GetPartitionType(partition)); - std::string text = fmt::format( - Common::GetStringT("Errors were found in {0} unused blocks in the {1} partition."), - blocks, name); - AddProblem(Severity::Low, std::move(text)); + AddProblem(Severity::Low, + Common::FmtFormatT("Errors were found in {0} unused blocks in the {1} partition.", + blocks, name)); } } -- cgit v1.2.3