DiscIO: Make use of fmt-capable panic alerts

Migrates the DiscIO code over to fmt.
This commit is contained in:
Lioncash 2020-11-11 01:06:33 -05:00
parent ae83685b0b
commit 689eec5304
10 changed files with 49 additions and 49 deletions

View File

@ -8,7 +8,6 @@
#endif #endif
#include <algorithm> #include <algorithm>
#include <cinttypes>
#include <cstdio> #include <cstdio>
#include <cstring> #include <cstring>
#include <memory> #include <memory>
@ -84,7 +83,7 @@ u64 CompressedBlobReader::GetBlockCompressedSize(u64 block_num) const
else if (block_num == m_header.num_blocks - 1) else if (block_num == m_header.num_blocks - 1)
return m_header.compressed_data_size - start; return m_header.compressed_data_size - start;
else else
PanicAlert("GetBlockCompressedSize - illegal block number %i", (int)block_num); PanicAlertFmt("{} - illegal block number {}", __func__, block_num);
return 0; return 0;
} }
@ -97,7 +96,7 @@ bool CompressedBlobReader::GetBlock(u64 block_num, u8* out_ptr)
if (offset & (1ULL << 63)) if (offset & (1ULL << 63))
{ {
if (comp_block_size != m_header.block_size) if (comp_block_size != m_header.block_size)
PanicAlert("Uncompressed block with wrong size"); PanicAlertFmt("Uncompressed block with wrong size");
uncompressed = true; uncompressed = true;
offset &= ~(1ULL << 63); offset &= ~(1ULL << 63);
} }
@ -108,18 +107,19 @@ bool CompressedBlobReader::GetBlock(u64 block_num, u8* out_ptr)
m_file.Seek(offset, SEEK_SET); m_file.Seek(offset, SEEK_SET);
if (!m_file.ReadBytes(m_zlib_buffer.data(), comp_block_size)) if (!m_file.ReadBytes(m_zlib_buffer.data(), comp_block_size))
{ {
PanicAlertT("The disc image \"%s\" is truncated, some of the data is missing.", PanicAlertFmtT("The disc image \"{}\" is truncated, some of the data is missing.", m_file_name);
m_file_name.c_str());
m_file.Clear(); m_file.Clear();
return false; return false;
} }
// First, check hash. // First, check hash.
u32 block_hash = Common::HashAdler32(m_zlib_buffer.data(), comp_block_size); const u32 block_hash = Common::HashAdler32(m_zlib_buffer.data(), comp_block_size);
if (block_hash != m_hashes[block_num]) if (block_hash != m_hashes[block_num])
PanicAlertT("The disc image \"%s\" is corrupt.\n" {
"Hash of block %" PRIu64 " is %08x instead of %08x.", PanicAlertFmtT("The disc image \"{}\" is corrupt.\n"
m_file_name.c_str(), block_num, block_hash, m_hashes[block_num]); "Hash of block {} is {:08x} instead of {:08x}.",
m_file_name, block_num, block_hash, m_hashes[block_num]);
}
if (uncompressed) if (uncompressed)
{ {
@ -132,7 +132,7 @@ bool CompressedBlobReader::GetBlock(u64 block_num, u8* out_ptr)
z.avail_in = comp_block_size; z.avail_in = comp_block_size;
if (z.avail_in > m_header.block_size) if (z.avail_in > m_header.block_size)
{ {
PanicAlert("We have a problem"); PanicAlertFmt("We have a problem");
} }
z.next_out = out_ptr; z.next_out = out_ptr;
z.avail_out = m_header.block_size; z.avail_out = m_header.block_size;
@ -143,12 +143,12 @@ bool CompressedBlobReader::GetBlock(u64 block_num, u8* out_ptr)
{ {
// this seem to fire wrongly from time to time // this seem to fire wrongly from time to time
// to be sure, don't use compressed isos :P // to be sure, don't use compressed isos :P
PanicAlert("Failure reading block %" PRIu64 " - out of data and not at end.", block_num); PanicAlertFmt("Failure reading block {} - out of data and not at end.", block_num);
} }
inflateEnd(&z); inflateEnd(&z);
if (uncomp_size != m_header.block_size) if (uncomp_size != m_header.block_size)
{ {
PanicAlert("Wrong block size"); PanicAlertFmt("Wrong block size");
return false; return false;
} }
} }
@ -276,10 +276,11 @@ bool ConvertToGCZ(BlobReader* infile, const std::string& infile_path,
File::IOFile outfile(outfile_path, "wb"); File::IOFile outfile(outfile_path, "wb");
if (!outfile) if (!outfile)
{ {
PanicAlertT("Failed to open the output file \"%s\".\n" PanicAlertFmtT(
"Check that you have permissions to write the target folder and that the media can " "Failed to open the output file \"{}\".\n"
"be written.", "Check that you have permissions to write the target folder and that the media can "
outfile_path.c_str()); "be written.",
outfile_path);
return false; return false;
} }
@ -367,13 +368,13 @@ bool ConvertToGCZ(BlobReader* infile, const std::string& infile_path,
} }
if (result == ConversionResultCode::ReadFailed) if (result == ConversionResultCode::ReadFailed)
PanicAlertT("Failed to read from the input file \"%s\".", infile_path.c_str()); PanicAlertFmtT("Failed to read from the input file \"{}\".", infile_path);
if (result == ConversionResultCode::WriteFailed) if (result == ConversionResultCode::WriteFailed)
{ {
PanicAlertT("Failed to write the output file \"%s\".\n" PanicAlertFmtT("Failed to write the output file \"{}\".\n"
"Check that you have enough space available on the target drive.", "Check that you have enough space available on the target drive.",
outfile_path.c_str()); outfile_path);
} }
return result == ConversionResultCode::Success; return result == ConversionResultCode::Success;

View File

@ -6,7 +6,6 @@
#include <algorithm> #include <algorithm>
#include <array> #include <array>
#include <cinttypes>
#include <cstring> #include <cstring>
#include <locale> #include <locale>
#include <map> #include <map>

View File

@ -146,7 +146,7 @@ bool DriveReader::ReadMultipleAlignedBlocks(u64 block_num, u64 num_blocks, u8* o
!ReadFile(m_disc_handle, out_ptr, static_cast<DWORD>(GetSectorSize() * num_blocks), !ReadFile(m_disc_handle, out_ptr, static_cast<DWORD>(GetSectorSize() * num_blocks),
&bytes_read, nullptr)) &bytes_read, nullptr))
{ {
PanicAlertT("Disc Read Error"); PanicAlertFmtT("Disc Read Error");
return false; return false;
} }
return bytes_read == GetSectorSize() * num_blocks; return bytes_read == GetSectorSize() * num_blocks;

View File

@ -49,10 +49,11 @@ bool ConvertToPlain(BlobReader* infile, const std::string& infile_path,
File::IOFile outfile(outfile_path, "wb"); File::IOFile outfile(outfile_path, "wb");
if (!outfile) if (!outfile)
{ {
PanicAlertT("Failed to open the output file \"%s\".\n" PanicAlertFmtT(
"Check that you have permissions to write the target folder and that the media can " "Failed to open the output file \"{}\".\n"
"be written.", "Check that you have permissions to write the target folder and that the media can "
outfile_path.c_str()); "be written.",
outfile_path);
return false; return false;
} }
@ -89,15 +90,15 @@ bool ConvertToPlain(BlobReader* infile, const std::string& infile_path,
const u64 sz = std::min(buffer_size, infile->GetDataSize() - inpos); const u64 sz = std::min(buffer_size, infile->GetDataSize() - inpos);
if (!infile->Read(inpos, sz, buffer.data())) if (!infile->Read(inpos, sz, buffer.data()))
{ {
PanicAlertT("Failed to read from the input file \"%s\".", infile_path.c_str()); PanicAlertFmtT("Failed to read from the input file \"{}\".", infile_path);
success = false; success = false;
break; break;
} }
if (!outfile.WriteBytes(buffer.data(), sz)) if (!outfile.WriteBytes(buffer.data(), sz))
{ {
PanicAlertT("Failed to write the output file \"%s\".\n" PanicAlertFmtT("Failed to write the output file \"{}\".\n"
"Check that you have enough space available on the target drive.", "Check that you have enough space available on the target drive.",
outfile_path.c_str()); outfile_path);
success = false; success = false;
break; break;
} }

View File

@ -3,7 +3,6 @@
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include <algorithm> #include <algorithm>
#include <cinttypes>
#include <cstddef> #include <cstddef>
#include <cstring> #include <cstring>
#include <locale> #include <locale>

View File

@ -6,7 +6,6 @@
#include <algorithm> #include <algorithm>
#include <array> #include <array>
#include <cinttypes>
#include <cstring> #include <cstring>
#include <fmt/format.h> #include <fmt/format.h>
@ -60,7 +59,7 @@ bool NANDImporter::ReadNANDBin(const std::string& path_to_bin,
const u64 image_size = file.GetSize(); const u64 image_size = file.GetSize();
if (image_size != NAND_BIN_SIZE + NAND_KEYS_SIZE && image_size != NAND_BIN_SIZE) if (image_size != NAND_BIN_SIZE + NAND_KEYS_SIZE && image_size != NAND_BIN_SIZE)
{ {
PanicAlertT("This file does not look like a BootMii NAND backup."); PanicAlertFmtT("This file does not look like a BootMii NAND backup.");
return false; return false;
} }
@ -273,6 +272,6 @@ void NANDImporter::ExportKeys(const std::string& nand_root)
const std::string file_path = nand_root + "/keys.bin"; const std::string file_path = nand_root + "/keys.bin";
File::IOFile file(file_path, "wb"); File::IOFile file(file_path, "wb");
if (!file.WriteBytes(m_nand_keys.data(), NAND_KEYS_SIZE)) if (!file.WriteBytes(m_nand_keys.data(), NAND_KEYS_SIZE))
PanicAlertT("Unable to write to file %s", file_path.c_str()); PanicAlertFmtT("Unable to write to file {}", file_path);
} }
} // namespace DiscIO } // namespace DiscIO

View File

@ -312,11 +312,11 @@ std::vector<RedumpVerifier::PotentialMatch> RedumpVerifier::ScanDatfile(const st
// so show a panic alert rather than just using ERROR_LOG // so show a panic alert rather than just using ERROR_LOG
// i18n: "Serial" refers to serial numbers, e.g. RVL-RSBE-USA // i18n: "Serial" refers to serial numbers, e.g. RVL-RSBE-USA
PanicAlertT("Serial and/or version data is missing from %s\n" PanicAlertFmtT("Serial and/or version data is missing from {}\n"
"Please append \"%s\" (without the quotes) to the datfile URL when downloading\n" "Please append \"{}\" (without the quotes) to the datfile URL when downloading\n"
"Example: %s", "Example: {}",
GetPathForSystem(system).c_str(), "serial,version", GetPathForSystem(system), "serial,version",
"http://redump.org/datfile/gc/serial,version"); "http://redump.org/datfile/gc/serial,version");
m_result = {Status::Error, Common::GetStringT("Failed to parse Redump.org data")}; m_result = {Status::Error, Common::GetStringT("Failed to parse Redump.org data")};
return {}; return {};
} }

View File

@ -92,7 +92,7 @@ VolumeWii::VolumeWii(std::unique_ptr<BlobReader> reader)
{ {
// This check is normally done by ES in ES_DiVerify, but that would happen too late // This check is normally done by ES in ES_DiVerify, but that would happen too late
// (after allocating the buffer), so we do the check here. // (after allocating the buffer), so we do the check here.
PanicAlert("Invalid TMD size"); PanicAlertFmt("Invalid TMD size");
return INVALID_TMD; return INVALID_TMD;
} }
std::vector<u8> tmd_buffer(*tmd_size); std::vector<u8> tmd_buffer(*tmd_size);

View File

@ -2032,10 +2032,11 @@ bool ConvertToWIAOrRVZ(BlobReader* infile, const std::string& infile_path,
File::IOFile outfile(outfile_path, "wb"); File::IOFile outfile(outfile_path, "wb");
if (!outfile) if (!outfile)
{ {
PanicAlertT("Failed to open the output file \"%s\".\n" PanicAlertFmtT(
"Check that you have permissions to write the target folder and that the media can " "Failed to open the output file \"{}\".\n"
"be written.", "Check that you have permissions to write the target folder and that the media can "
outfile_path.c_str()); "be written.",
outfile_path);
return false; return false;
} }
@ -2047,13 +2048,13 @@ bool ConvertToWIAOrRVZ(BlobReader* infile, const std::string& infile_path,
chunk_size, callback); chunk_size, callback);
if (result == ConversionResultCode::ReadFailed) if (result == ConversionResultCode::ReadFailed)
PanicAlertT("Failed to read from the input file \"%s\".", infile_path.c_str()); PanicAlertFmtT("Failed to read from the input file \"{}\".", infile_path);
if (result == ConversionResultCode::WriteFailed) if (result == ConversionResultCode::WriteFailed)
{ {
PanicAlertT("Failed to write the output file \"%s\".\n" PanicAlertFmtT("Failed to write the output file \"{}\".\n"
"Check that you have enough space available on the target drive.", "Check that you have enough space available on the target drive.",
outfile_path.c_str()); outfile_path);
} }
if (result != ConversionResultCode::Success) if (result != ConversionResultCode::Success)

View File

@ -166,7 +166,7 @@ File::IOFile& WbfsFileReader::SeekToCluster(u64 offset, u64* available)
} }
} }
PanicAlert("Read beyond end of disc"); PanicAlertFmt("Read beyond end of disc");
if (available) if (available)
*available = 0; *available = 0;
m_files[0].file.Seek(0, SEEK_SET); m_files[0].file.Seek(0, SEEK_SET);