Skip to content

Commit 78959f6

Browse files
committed
MemoryCardImage: Swap over to fmt
1 parent cecae91 commit 78959f6

File tree

2 files changed

+55
-45
lines changed

2 files changed

+55
-45
lines changed

src/core/memory_card_image.cpp

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,11 @@ bool LoadFromFile(DataArray* data, const char* filename)
112112
const size_t num_read = stream->Read(data->data(), DATA_SIZE);
113113
if (num_read != DATA_SIZE)
114114
{
115-
Log_ErrorPrintf("Only read %zu of %u sectors from '%s'", num_read / FRAME_SIZE, NUM_FRAMES, filename);
115+
Log_ErrorFmt("Only read {} of {} sectors from '{}'", num_read / FRAME_SIZE, static_cast<u32>(NUM_FRAMES), filename);
116116
return false;
117117
}
118118

119-
Log_InfoPrintf("Loaded memory card from %s", filename);
119+
Log_VerboseFmt("Loaded memory card from {}", filename);
120120
return true;
121121
}
122122

@@ -127,18 +127,18 @@ bool SaveToFile(const DataArray& data, const char* filename)
127127
BYTESTREAM_OPEN_ATOMIC_UPDATE | BYTESTREAM_OPEN_STREAMED);
128128
if (!stream)
129129
{
130-
Log_ErrorPrintf("Failed to open '%s' for writing.", filename);
130+
Log_ErrorFmt("Failed to open '{}' for writing.", filename);
131131
return false;
132132
}
133133

134134
if (!stream->Write2(data.data(), DATA_SIZE) || !stream->Commit())
135135
{
136-
Log_ErrorPrintf("Failed to write sectors to '%s'", filename);
136+
Log_ErrorFmt("Failed to write sectors to '{}'", filename);
137137
stream->Discard();
138138
return false;
139139
}
140140

141-
Log_InfoPrintf("Saved memory card to '%s'", filename);
141+
Log_VerboseFmt("Saved memory card to '{}'", filename);
142142
return true;
143143
}
144144

@@ -266,7 +266,7 @@ std::vector<FileInfo> EnumerateFiles(const DataArray& data, bool include_deleted
266266
if (fi.num_blocks == FRAMES_PER_BLOCK)
267267
{
268268
// invalid
269-
Log_WarningPrintf("Invalid block chain in block %u", dir_frame);
269+
Log_WarningFmt("Invalid block chain in block {}", dir_frame);
270270
continue;
271271
}
272272

@@ -280,7 +280,7 @@ std::vector<FileInfo> EnumerateFiles(const DataArray& data, bool include_deleted
280280
num_icon_frames = 3;
281281
else
282282
{
283-
Log_WarningPrintf("Unknown icon flag 0x%02X", tf->icon_flag);
283+
Log_WarningFmt("Unknown icon flag 0x{:02X}", tf->icon_flag);
284284
continue;
285285
}
286286

@@ -332,14 +332,14 @@ bool WriteFile(DataArray* data, const std::string_view& filename, const std::vec
332332
{
333333
if (buffer.empty())
334334
{
335-
Log_ErrorPrintf("Failed to write file to memory card: buffer is empty");
335+
Log_ErrorPrint("Failed to write file to memory card: buffer is empty");
336336
return false;
337337
}
338338

339339
const u32 num_blocks = (static_cast<u32>(buffer.size()) + (BLOCK_SIZE - 1)) / BLOCK_SIZE;
340340
if (GetFreeBlockCount(*data) < num_blocks)
341341
{
342-
Log_ErrorPrintf("Failed to write file to memory card: insufficient free blocks");
342+
Log_ErrorPrint("Failed to write file to memory card: insufficient free blocks");
343343
return false;
344344
}
345345

@@ -382,13 +382,13 @@ bool WriteFile(DataArray* data, const std::string_view& filename, const std::vec
382382
std::memset(data_block + size_to_copy, 0, size_to_zero);
383383
}
384384

385-
Log_InfoPrintf("Wrote %zu byte (%u block) file to memory card", buffer.size(), num_blocks);
385+
Log_InfoFmt("Wrote {} byte ({} block) file to memory card", buffer.size(), num_blocks);
386386
return true;
387387
}
388388

389389
bool DeleteFile(DataArray* data, const FileInfo& fi, bool clear_sectors)
390390
{
391-
Log_InfoPrintf("Deleting '%s' from memory card (%u blocks)", fi.filename.c_str(), fi.num_blocks);
391+
Log_InfoFmt("Deleting '{}' from memory card ({} blocks)", fi.filename, fi.num_blocks);
392392

393393
u32 block_number = fi.first_block;
394394
for (u32 i = 0; i < fi.num_blocks && (block_number > 0 && block_number < NUM_BLOCKS); i++)
@@ -421,11 +421,11 @@ bool UndeleteFile(DataArray* data, const FileInfo& fi)
421421
{
422422
if (!fi.deleted)
423423
{
424-
Log_ErrorPrintf("File '%s' is not deleted", fi.filename.c_str());
424+
Log_ErrorFmt("File '{}' is not deleted", fi.filename);
425425
return false;
426426
}
427427

428-
Log_InfoPrintf("Undeleting '%s' from memory card (%u blocks)", fi.filename.c_str(), fi.num_blocks);
428+
Log_InfoFmt("Undeleting '{}' from memory card ({} blocks)", fi.filename, fi.num_blocks);
429429

430430
// check that all blocks are present first
431431
u32 block_number = fi.first_block;
@@ -439,26 +439,26 @@ bool UndeleteFile(DataArray* data, const FileInfo& fi)
439439
{
440440
if (df->block_allocation_state != 0xA1)
441441
{
442-
Log_ErrorPrintf("Incorrect block state for %u, expected 0xA1 got 0x%02X", this_block_number,
443-
df->block_allocation_state);
442+
Log_ErrorFmt("Incorrect block state for {}, expected 0xA1 got 0x{:02X}", this_block_number,
443+
df->block_allocation_state);
444444
return false;
445445
}
446446
}
447447
else if (i == (fi.num_blocks - 1))
448448
{
449449
if (df->block_allocation_state != 0xA3)
450450
{
451-
Log_ErrorPrintf("Incorrect block state for %u, expected 0xA3 got 0x%02X", this_block_number,
452-
df->block_allocation_state);
451+
Log_ErrorFmt("Incorrect block state for %u, expected 0xA3 got 0x{:02X}", this_block_number,
452+
df->block_allocation_state);
453453
return false;
454454
}
455455
}
456456
else
457457
{
458458
if (df->block_allocation_state != 0xA2)
459459
{
460-
Log_WarningPrintf("Incorrect block state for %u, expected 0xA2 got 0x%02X", this_block_number,
461-
df->block_allocation_state);
460+
Log_ErrorFmt("Incorrect block state for {}, expected 0xA2 got 0x{:02X}", this_block_number,
461+
df->block_allocation_state);
462462
return false;
463463
}
464464
}
@@ -487,7 +487,7 @@ static bool ImportCardMCD(DataArray* data, const char* filename, std::vector<u8>
487487
{
488488
if (file_data.size() != DATA_SIZE)
489489
{
490-
Log_ErrorPrintf("Failed to import memory card from '%s': file is incorrect size.", filename);
490+
Log_ErrorFmt("Failed to import memory card from '{}': file is incorrect size.", filename);
491491
return false;
492492
}
493493

@@ -513,15 +513,15 @@ static bool ImportCardGME(DataArray* data, const char* filename, std::vector<u8>
513513

514514
if (file_data.size() < (sizeof(GMEHeader) + BLOCK_SIZE))
515515
{
516-
Log_ErrorPrintf("Failed to import GME memory card from '%s': file is incorrect size.", filename);
516+
Log_ErrorFmt("Failed to import GME memory card from '{}': file is incorrect size.", filename);
517517
return false;
518518
}
519519

520520
// if it's too small, pad it
521521
const u32 expected_size = sizeof(GMEHeader) + DATA_SIZE;
522522
if (file_data.size() < expected_size)
523523
{
524-
Log_WarningPrintf("GME memory card '%s' is too small (got %zu expected %u), padding with zeroes", filename,
524+
Log_WarningFmt("GME memory card '{}' is too small (got {} expected {}), padding with zeroes", filename,
525525
file_data.size(), expected_size);
526526
file_data.resize(expected_size);
527527
}
@@ -537,14 +537,14 @@ static bool ImportCardVGS(DataArray* data, const char* filename, std::vector<u8>
537537

538538
if (file_data.size() != (HEADER_SIZE + DATA_SIZE))
539539
{
540-
Log_ErrorPrintf("Failed to import memory card from '%s': file is incorrect size.", filename);
540+
Log_ErrorFmt("Failed to import memory card from '{}': file is incorrect size.", filename);
541541
return false;
542542
}
543543

544544
// Connectix Virtual Game Station format (.MEM): "VgsM", 64 bytes
545545
if (file_data[0] != 'V' || file_data[1] != 'g' || file_data[2] != 's' || file_data[3] != 'M')
546546
{
547-
Log_ErrorPrintf("Failed to import memory card from '%s': incorrect header.", filename);
547+
Log_ErrorFmt("Failed to import memory card from '{}': incorrect header.", filename);
548548
return false;
549549
}
550550

@@ -558,14 +558,14 @@ static bool ImportCardPSX(DataArray* data, const char* filename, std::vector<u8>
558558

559559
if (file_data.size() != (HEADER_SIZE + DATA_SIZE))
560560
{
561-
Log_ErrorPrintf("Failed to import memory card from '%s': file is incorrect size.", filename);
561+
Log_ErrorFmt("Failed to import memory card from '{}': file is incorrect size.", filename);
562562
return false;
563563
}
564564

565565
// Connectix Virtual Game Station format (.MEM): "VgsM", 64 bytes
566566
if (file_data[0] != 'P' || file_data[1] != 'S' || file_data[2] != 'V')
567567
{
568-
Log_ErrorPrintf("Failed to import memory card from '%s': incorrect header.", filename);
568+
Log_ErrorFmt("Failed to import memory card from '{}': incorrect header.", filename);
569569
return false;
570570
}
571571

@@ -578,7 +578,7 @@ bool ImportCard(DataArray* data, const char* filename, std::vector<u8> file_data
578578
const char* extension = std::strrchr(filename, '.');
579579
if (!extension)
580580
{
581-
Log_ErrorPrintf("Failed to import memory card from '%s': missing extension?", filename);
581+
Log_ErrorFmt("Failed to import memory card from '{}': missing extension?", filename);
582582
return false;
583583
}
584584

@@ -603,7 +603,7 @@ bool ImportCard(DataArray* data, const char* filename, std::vector<u8> file_data
603603
}
604604
else
605605
{
606-
Log_ErrorPrintf("Failed to import memory card from '%s': unknown extension?", filename);
606+
Log_ErrorFmt("Failed to import memory card from '{}': unknown extension?", filename);
607607
return false;
608608
}
609609
}
@@ -624,7 +624,7 @@ bool ExportSave(DataArray* data, const FileInfo& fi, const char* filename)
624624
BYTESTREAM_OPEN_ATOMIC_UPDATE | BYTESTREAM_OPEN_STREAMED);
625625
if (!stream)
626626
{
627-
Log_ErrorPrintf("Failed to open '%s' for writing.", filename);
627+
Log_ErrorFmt("Failed to open '{}' for writing.", filename);
628628
return false;
629629
}
630630

@@ -635,14 +635,14 @@ bool ExportSave(DataArray* data, const FileInfo& fi, const char* filename)
635635
std::vector<u8> blocks;
636636
if (!ReadFile(*data, fi, &blocks))
637637
{
638-
Log_ErrorPrintf("Failed to read save blocks from memory card data");
638+
Log_ErrorPrint("Failed to read save blocks from memory card data");
639639
return false;
640640
}
641641

642642
if (!stream->Write(header.data(), static_cast<u32>(header.size())) ||
643643
!stream->Write(blocks.data(), static_cast<u32>(blocks.size())) || !stream->Commit())
644644
{
645-
Log_ErrorPrintf("Failed to write exported save to '%s'", filename);
645+
Log_ErrorFmt("Failed to write exported save to '{}'", filename);
646646
stream->Discard();
647647
return false;
648648
}
@@ -655,42 +655,42 @@ static bool ImportSaveWithDirectoryFrame(DataArray* data, const char* filename,
655655
// Make sure the size of the actual file is valid
656656
if (sd.Size <= FRAME_SIZE || (sd.Size - FRAME_SIZE) % BLOCK_SIZE != 0u || (sd.Size - FRAME_SIZE) / BLOCK_SIZE > 15u)
657657
{
658-
Log_ErrorPrintf("Invalid size for save file '%s'", filename);
658+
Log_ErrorFmt("Invalid size for save file '{}'", filename);
659659
return false;
660660
}
661661

662662
std::unique_ptr<ByteStream> stream = ByteStream::OpenFile(filename, BYTESTREAM_OPEN_READ | BYTESTREAM_OPEN_STREAMED);
663663
if (!stream)
664664
{
665-
Log_ErrorPrintf("Failed to open '%s' for reading", filename);
665+
Log_ErrorFmt("Failed to open '{}' for reading", filename);
666666
return false;
667667
}
668668

669669
DirectoryFrame df;
670670
if (stream->Read(&df, FRAME_SIZE) != FRAME_SIZE)
671671
{
672-
Log_ErrorPrintf("Failed to read directory frame from '%s'", filename);
672+
Log_ErrorFmt("Failed to read directory frame from '{}'", filename);
673673
return false;
674674
}
675675

676676
// Make sure the size reported by the directory frame is valid
677677
if (df.file_size < BLOCK_SIZE || df.file_size % BLOCK_SIZE != 0 || df.file_size / BLOCK_SIZE > 15u)
678678
{
679-
Log_ErrorPrintf("Invalid size (%u bytes) reported by directory frame", df.file_size);
679+
Log_ErrorFmt("Invalid size ({} bytes) reported by directory frame", df.file_size);
680680
return false;
681681
}
682682

683683
std::vector<u8> blocks = std::vector<u8>(static_cast<size_t>(df.file_size));
684684
if (stream->Read(blocks.data(), df.file_size) != df.file_size)
685685
{
686-
Log_ErrorPrintf("Failed to read block bytes from '%s'", filename);
686+
Log_ErrorFmt("Failed to read block bytes from '{}'", filename);
687687
return false;
688688
}
689689

690690
const u32 num_blocks = (static_cast<u32>(blocks.size()) + (BLOCK_SIZE - 1)) / BLOCK_SIZE;
691691
if (GetFreeBlockCount(*data) < num_blocks)
692692
{
693-
Log_ErrorPrintf("Failed to write file to memory card: insufficient free blocks");
693+
Log_ErrorPrint("Failed to write file to memory card: insufficient free blocks");
694694
return false;
695695
}
696696

@@ -702,7 +702,7 @@ static bool ImportSaveWithDirectoryFrame(DataArray* data, const char* filename,
702702
{
703703
if (!fi.deleted)
704704
{
705-
Log_ErrorPrintf("Save file with the same name '%s' already exists in memory card", fi.filename.c_str());
705+
Log_ErrorFmt("Save file with the same name '{}' already exists in memory card", fi.filename.c_str());
706706
return false;
707707
}
708708

@@ -719,7 +719,7 @@ static bool ImportRawSave(DataArray* data, const char* filename, const FILESYSTE
719719
std::string save_name(Path::GetFileTitle(filename));
720720
if (save_name.length() == 0)
721721
{
722-
Log_ErrorPrintf("Invalid filename: '%s'", filename);
722+
Log_ErrorFmt("Invalid filename: '{}'", filename);
723723
return false;
724724
}
725725

@@ -729,14 +729,14 @@ static bool ImportRawSave(DataArray* data, const char* filename, const FILESYSTE
729729
std::optional<std::vector<u8>> blocks = FileSystem::ReadBinaryFile(filename);
730730
if (!blocks.has_value())
731731
{
732-
Log_ErrorPrintf("Failed to read '%s'", filename);
732+
Log_ErrorFmt("Failed to read '{}'", filename);
733733
return false;
734734
}
735735

736736
const u32 num_blocks = (static_cast<u32>(blocks->size()) + (BLOCK_SIZE - 1)) / BLOCK_SIZE;
737737
if (GetFreeBlockCount(*data) < num_blocks)
738738
{
739-
Log_ErrorPrintf("Failed to write file to memory card: insufficient free blocks");
739+
Log_ErrorPrint("Failed to write file to memory card: insufficient free blocks");
740740
return false;
741741
}
742742

@@ -748,7 +748,7 @@ static bool ImportRawSave(DataArray* data, const char* filename, const FILESYSTE
748748
{
749749
if (!fi.deleted)
750750
{
751-
Log_ErrorPrintf("Save file with the same name '%s' already exists in memory card", fi.filename.c_str());
751+
Log_ErrorFmt("Save file with the same name '{}' already exists in memory card", fi.filename);
752752
return false;
753753
}
754754

@@ -764,14 +764,14 @@ bool ImportSave(DataArray* data, const char* filename)
764764
FILESYSTEM_STAT_DATA sd;
765765
if (!FileSystem::StatFile(filename, &sd))
766766
{
767-
Log_ErrorPrintf("Failed to stat file '%s'", filename);
767+
Log_ErrorFmt("Failed to stat file '{}'", filename);
768768
return false;
769769
}
770770

771771
// Make sure the size of the actual file is valid
772772
if (sd.Size == 0)
773773
{
774-
Log_ErrorPrintf("Invalid size for save file '%s'", filename);
774+
Log_ErrorFmt("Invalid size for save file '{}'", filename);
775775
return false;
776776
}
777777

@@ -785,7 +785,7 @@ bool ImportSave(DataArray* data, const char* filename)
785785
}
786786
else
787787
{
788-
Log_ErrorPrintf("Unknown save format for '%s'", filename);
788+
Log_ErrorFmt("Unknown save format for '{}'", filename);
789789
return false;
790790
}
791791
}

src/core/system.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3078,7 +3078,12 @@ void System::UpdateMemoryCardTypes()
30783078
const MemoryCardType type = g_settings.memory_card_types[i];
30793079
std::unique_ptr<MemoryCard> card = GetMemoryCardForSlot(i, type);
30803080
if (card)
3081+
{
3082+
if (const std::string& filename = card->GetFilename(); !filename.empty())
3083+
Log_InfoFmt("Memory Card Slot {}: {}", i + 1, filename);
3084+
30813085
Pad::SetMemoryCard(i, std::move(card));
3086+
}
30823087
}
30833088
}
30843089

@@ -3094,7 +3099,12 @@ void System::UpdatePerGameMemoryCards()
30943099

30953100
std::unique_ptr<MemoryCard> card = GetMemoryCardForSlot(i, type);
30963101
if (card)
3102+
{
3103+
if (const std::string& filename = card->GetFilename(); !filename.empty())
3104+
Log_InfoFmt("Memory Card Slot {}: {}", i + 1, filename);
3105+
30973106
Pad::SetMemoryCard(i, std::move(card));
3107+
}
30983108
}
30993109
}
31003110

0 commit comments

Comments
 (0)