mirror of https://github.com/PCSX2/pcsx2.git
MemoryCardFile: Log size/formatted state on load
This commit is contained in:
parent
4f0d944bb9
commit
c5a9ce6b56
|
@ -1,4 +1,4 @@
|
||||||
// SPDX-FileCopyrightText: 2002-2023 PCSX2 Dev Team
|
// SPDX-FileCopyrightText: 2002-2024 PCSX2 Dev Team
|
||||||
// SPDX-License-Identifier: LGPL-3.0+
|
// SPDX-License-Identifier: LGPL-3.0+
|
||||||
|
|
||||||
#include "SIO/Memcard/MemoryCardFile.h"
|
#include "SIO/Memcard/MemoryCardFile.h"
|
||||||
|
@ -257,6 +257,9 @@ void FileMemoryCard::Open()
|
||||||
{
|
{
|
||||||
m_filenames[slot] = {};
|
m_filenames[slot] = {};
|
||||||
|
|
||||||
|
if (EmuConfig.Mcd[slot].Type != MemoryCardType::File)
|
||||||
|
continue;
|
||||||
|
|
||||||
if (FileMcd_IsMultitapSlot(slot))
|
if (FileMcd_IsMultitapSlot(slot))
|
||||||
{
|
{
|
||||||
if (!EmuConfig.Pad.MultitapPort0_Enabled && (FileMcd_GetMtapPort(slot) == 0))
|
if (!EmuConfig.Pad.MultitapPort0_Enabled && (FileMcd_GetMtapPort(slot) == 0))
|
||||||
|
@ -265,29 +268,13 @@ void FileMemoryCard::Open()
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string fname(EmuConfig.FullpathToMcd(slot));
|
const std::string fname = EmuConfig.FullpathToMcd(slot);
|
||||||
std::string_view str(fname);
|
|
||||||
bool cont = false;
|
|
||||||
|
|
||||||
if (fname.empty())
|
if (!EmuConfig.Mcd[slot].Enabled || fname.empty())
|
||||||
{
|
{
|
||||||
str = "[empty filename]";
|
Console.WriteLnFmt("McdSlot {} [File]: [disabled/empty filename]", slot);
|
||||||
cont = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!EmuConfig.Mcd[slot].Enabled)
|
|
||||||
{
|
|
||||||
str = "[disabled]";
|
|
||||||
cont = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (EmuConfig.Mcd[slot].Type == MemoryCardType::File)
|
|
||||||
Console.WriteLn(cont ? Color_Gray : Color_Green, fmt::format("McdSlot {} [File]: {}", slot, str));
|
|
||||||
else
|
|
||||||
cont = true;
|
|
||||||
|
|
||||||
if (cont)
|
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (FileSystem::GetPathFileSize(fname.c_str()) <= 0)
|
if (FileSystem::GetPathFileSize(fname.c_str()) <= 0)
|
||||||
{
|
{
|
||||||
|
@ -302,9 +289,6 @@ void FileMemoryCard::Open()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// [TODO] : Add memcard size detection and report it to the console log.
|
|
||||||
// (8MB, 256Mb, formatted, unformatted, etc ...)
|
|
||||||
|
|
||||||
if (fname.ends_with(".bin"))
|
if (fname.ends_with(".bin"))
|
||||||
{
|
{
|
||||||
std::string newname(fname + "x");
|
std::string newname(fname + "x");
|
||||||
|
@ -339,6 +323,10 @@ void FileMemoryCard::Open()
|
||||||
}
|
}
|
||||||
else // Load checksum
|
else // Load checksum
|
||||||
{
|
{
|
||||||
|
Console.WriteLnFmt(Color_Green, "McdSlot {} [File]: {} [{} MB, {}]", slot, Path::GetFileName(fname),
|
||||||
|
(FileSystem::FSize64(m_file[slot]) + (MCD_SIZE + 1)) / MC2_MBSIZE,
|
||||||
|
FileMcd_IsMemoryCardFormatted(m_file[slot]) ? "Formatted" : "UNFORMATTED");
|
||||||
|
|
||||||
m_filenames[slot] = std::move(fname);
|
m_filenames[slot] = std::move(fname);
|
||||||
m_ispsx[slot] = FileSystem::FSize64(m_file[slot]) == 0x20000;
|
m_ispsx[slot] = FileSystem::FSize64(m_file[slot]) == 0x20000;
|
||||||
m_chkaddr = 0x210;
|
m_chkaddr = 0x210;
|
||||||
|
@ -827,18 +815,27 @@ static bool IsMemoryCardFolder(const std::string& path)
|
||||||
return FileSystem::FileExists(superblock_path.c_str());
|
return FileSystem::FileExists(superblock_path.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool IsMemoryCardFormatted(const std::string& path)
|
bool FileMcd_IsMemoryCardFormatted(const std::string& path)
|
||||||
{
|
{
|
||||||
auto fp = FileSystem::OpenManagedSharedCFile(path.c_str(), "rb", FileSystem::FileShareMode::DenyNone);
|
auto fp = FileSystem::OpenManagedSharedCFile(path.c_str(), "rb", FileSystem::FileShareMode::DenyNone);
|
||||||
if (!fp)
|
if (!fp)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
return FileMcd_IsMemoryCardFormatted(fp.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
bool FileMcd_IsMemoryCardFormatted(std::FILE* fp)
|
||||||
|
{
|
||||||
static const char formatted_psx[] = "MC";
|
static const char formatted_psx[] = "MC";
|
||||||
static const char formatted_string[] = "Sony PS2 Memory Card Format";
|
static const char formatted_string[] = "Sony PS2 Memory Card Format";
|
||||||
static constexpr size_t read_length = sizeof(formatted_string) - 1;
|
static constexpr size_t read_length = sizeof(formatted_string) - 1;
|
||||||
|
|
||||||
|
const s64 pos = FileSystem::FTell64(fp);
|
||||||
|
|
||||||
u8 data[read_length];
|
u8 data[read_length];
|
||||||
if (std::fread(data, read_length, 1, fp.get()) != 1)
|
const bool okay = (FileSystem::FSeek64(fp, 0, SEEK_SET) == 0 && std::fread(data, read_length, 1, fp) == 1);
|
||||||
|
FileSystem::FSeek64(fp, pos, SEEK_SET);
|
||||||
|
if (!okay)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return (std::memcmp(data, formatted_string, sizeof(formatted_string) - 1) == 0 ||
|
return (std::memcmp(data, formatted_string, sizeof(formatted_string) - 1) == 0 ||
|
||||||
|
@ -890,7 +887,7 @@ std::vector<AvailableMcdInfo> FileMcd_GetAvailableCards(bool include_in_use_card
|
||||||
if (fd.Size < MCD_SIZE)
|
if (fd.Size < MCD_SIZE)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
const bool formatted = IsMemoryCardFormatted(fd.FileName);
|
const bool formatted = FileMcd_IsMemoryCardFormatted(fd.FileName);
|
||||||
mcds.push_back({std::move(basename), std::move(fd.FileName), fd.ModificationTime,
|
mcds.push_back({std::move(basename), std::move(fd.FileName), fd.ModificationTime,
|
||||||
MemoryCardType::File, GetMemoryCardFileTypeFromSize(fd.Size),
|
MemoryCardType::File, GetMemoryCardFileTypeFromSize(fd.Size),
|
||||||
static_cast<u32>(fd.Size), formatted});
|
static_cast<u32>(fd.Size), formatted});
|
||||||
|
@ -923,7 +920,7 @@ std::optional<AvailableMcdInfo> FileMcd_GetCardInfo(const std::string_view& name
|
||||||
{
|
{
|
||||||
if (sd.Size >= MCD_SIZE)
|
if (sd.Size >= MCD_SIZE)
|
||||||
{
|
{
|
||||||
const bool formatted = IsMemoryCardFormatted(path);
|
const bool formatted = FileMcd_IsMemoryCardFormatted(path);
|
||||||
ret = {std::move(basename), std::move(path), sd.ModificationTime,
|
ret = {std::move(basename), std::move(path), sd.ModificationTime,
|
||||||
MemoryCardType::File, GetMemoryCardFileTypeFromSize(sd.Size),
|
MemoryCardType::File, GetMemoryCardFileTypeFromSize(sd.Size),
|
||||||
static_cast<u32>(sd.Size), formatted};
|
static_cast<u32>(sd.Size), formatted};
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
// SPDX-FileCopyrightText: 2002-2023 PCSX2 Dev Team
|
// SPDX-FileCopyrightText: 2002-2024 PCSX2 Dev Team
|
||||||
// SPDX-License-Identifier: LGPL-3.0+
|
// SPDX-License-Identifier: LGPL-3.0+
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
|
|
||||||
|
#include <cstdio>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
@ -50,6 +53,8 @@ int FileMcd_ReIndex(uint port, uint slot, const std::string& filter);
|
||||||
|
|
||||||
std::vector<AvailableMcdInfo> FileMcd_GetAvailableCards(bool include_in_use_cards);
|
std::vector<AvailableMcdInfo> FileMcd_GetAvailableCards(bool include_in_use_cards);
|
||||||
std::optional<AvailableMcdInfo> FileMcd_GetCardInfo(const std::string_view& name);
|
std::optional<AvailableMcdInfo> FileMcd_GetCardInfo(const std::string_view& name);
|
||||||
|
bool FileMcd_IsMemoryCardFormatted(const std::string& path);
|
||||||
|
bool FileMcd_IsMemoryCardFormatted(std::FILE* fp);
|
||||||
bool FileMcd_CreateNewCard(const std::string_view& name, MemoryCardType type, MemoryCardFileType file_type);
|
bool FileMcd_CreateNewCard(const std::string_view& name, MemoryCardType type, MemoryCardFileType file_type);
|
||||||
bool FileMcd_RenameCard(const std::string_view& name, const std::string_view& new_name);
|
bool FileMcd_RenameCard(const std::string_view& name, const std::string_view& new_name);
|
||||||
bool FileMcd_DeleteCard(const std::string_view& name);
|
bool FileMcd_DeleteCard(const std::string_view& name);
|
Loading…
Reference in New Issue