Skip to content

Commit

Permalink
Scrap host classes
Browse files Browse the repository at this point in the history
  • Loading branch information
RedPanda4552 committed Jan 12, 2025
1 parent 447460b commit 1d001d3
Show file tree
Hide file tree
Showing 21 changed files with 264 additions and 292 deletions.
12 changes: 3 additions & 9 deletions pcsx2/SIO/Memcard/Memcard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
#include "SIO/Memcard/Memcard.h"

#include "SIO/Sio.h"
#include "SIO/Memcard/MemcardBase.h"
#include "SIO/Memcard/MemcardPS2.h"
#include "SIO/Memcard/MemcardPS1.h"
#include "SIO/Memcard/MemcardNotConnected.h"
#include "SIO/Memcard/MemcardHostFile.h"
#include "SIO/Memcard/MemcardHostFolder.h"

#include "Common.h"
#include "common/Path.h"
Expand Down Expand Up @@ -42,18 +41,13 @@ bool Memcard::Initialize()
{
s_memcards.at(i) = std::make_unique<MemcardPS1>(i, fullPath);
}

// If a host was not built because no such file or folder existed,
// or a file card failed to open, then ditch the card
if (!s_memcards.at(i)->GetHost() || !s_memcards.at(i)->GetHost()->IsOpened())
else
{
s_memcards.at(i) = std::make_unique<MemcardNotConnected>(i);

// Translation note: detailed description should mention that the memory card will be disabled
// for the duration of this session.
Host::ReportFormattedErrorAsync("Memory Card",
"Access denied to memory card: \n\n%s\n\n"
"PCSX2 will treat this memory card as ejected for this session. Another instance of PCSX2 may be using this memory card. Close any other instances of PCSX2, or restart your computer.%s",
"PCSX2 cannot access your memory card. Either you do not have permission to open it, or another program is currently accessign it.%s",
fullPath.c_str(),
#ifdef WIN32
"\n\nIf your memory card is in a write-protected folder such as \"Program Files\" or \"Program Files (x86)\", move it to another folder, such as \"Documents\" or \"Desktop\"."
Expand Down
6 changes: 4 additions & 2 deletions pcsx2/SIO/Memcard/Memcard.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#pragma once

class MemcardBase;
class MemcardHostBase;

namespace Memcard
{
Expand Down Expand Up @@ -39,7 +38,10 @@ namespace Memcard
AUTH_F7 = 0xf7
};

enum class HostType
// The storage type to use on the host PC.
// - File type uses a single to emulate the entire memcard as a continuous binary blob
// - Folder type uses a folder on the host filesystem to rebuild the PS2 filesystem on the PC
enum class StorageType
{
NOT_SET = 0,
FILE = 1,
Expand Down
40 changes: 25 additions & 15 deletions pcsx2/SIO/Memcard/MemcardBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,49 @@

#include "SIO/Memcard/MemcardBase.h"

#include "SIO/Memcard/MemcardHostFile.h"
#include "SIO/Memcard/MemcardHostFolder.h"

#include "common/FileSystem.h"
#include "common/Path.h"
#include "Host.h"
#include "fmt/core.h"
#include "IconsFontAwesome5.h"

bool MemcardBase::IsOpened()
{
switch (this->storageType)
{
case Memcard::StorageType::FILE:
{
return this->filePtr;
}
case Memcard::StorageType::FOLDER:
{
return true;
}
default:
{
return false;
}
}
}

MemcardBase::MemcardBase(u32 unifiedSlot, std::string fullPath)
{
this->unifiedSlot = unifiedSlot;
this->fullPath = fullPath;
this->autoEjectTicks = 0;
this->lastWriteTime = std::chrono::system_clock::now();

if (fullPath == "")
if (fullPath.empty())
{
return;
this->storageType = Memcard::StorageType::NOT_SET;
}
else if (FileSystem::FileExists(fullPath.c_str()))
{
this->hostType = Memcard::HostType::FILE;
this->memcardHost = std::make_unique<MemcardHostFile>(fullPath);
this->storageType = Memcard::StorageType::FILE;
}
else if (FileSystem::DirectoryExists(fullPath.c_str()))
{
this->hostType = Memcard::HostType::FOLDER;
this->memcardHost = std::make_unique<MemcardHostFolder>(fullPath);
this->storageType = Memcard::StorageType::FOLDER;
}
}

Expand All @@ -41,11 +56,6 @@ u32 MemcardBase::GetUnifiedSlot()
return this->unifiedSlot;
}

MemcardHostBase* MemcardBase::GetHost()
{
return this->memcardHost.get();
}

void MemcardBase::SendWriteMessageToHost()
{
const std::chrono::duration<float> elapsed = std::chrono::system_clock::now() - this->lastWriteTime;
Expand All @@ -59,7 +69,7 @@ void MemcardBase::SendWriteMessageToHost()
ICON_FA_SD_CARD,
fmt::format(
TRANSLATE_FS("MemoryCard", "Memory Card '{}' written to storage."),
Path::GetFileName(this->memcardHost->GetPath())),
Path::GetFileName(this->fullPath)),
Host::OSD_INFO_DURATION);
this->lastWriteTime = std::chrono::system_clock::now();
}
Expand Down
21 changes: 17 additions & 4 deletions pcsx2/SIO/Memcard/MemcardBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,38 @@
#pragma once

#include "SIO/Memcard/Memcard.h"
#include "SIO/Memcard/MemcardHostBase.h"

class MemcardBase
{
private:
u32 unifiedSlot;
std::string fullPath;

protected:
Memcard::HostType hostType;
std::unique_ptr<MemcardHostBase> memcardHost;
Memcard::StorageType storageType;
std::FILE* filePtr;
u32 autoEjectTicks;
std::chrono::time_point<std::chrono::system_clock> lastWriteTime;

bool IsOpened();

virtual bool Seek(u32 addr) = 0;
virtual bool SeekFile(u32 addr) = 0;
virtual bool SeekFolder(u32 addr) = 0;

virtual void Write(u32 addr, std::vector<u8>& src) = 0;
virtual void WriteFile(u32 addr, std::vector<u8>& src) = 0;
virtual void WriteFolder(u32 addr, std::vector<u8>& src) = 0;

virtual void Read(u32 addr, std::vector<u8>& dest) = 0;
virtual void ReadFile(u32 addr, std::vector<u8>& dest) = 0;
virtual void ReadFolder(u32 addr, std::vector<u8>& dest) = 0;

public:
MemcardBase(u32 unifiedSlot, std::string fullPath);
virtual ~MemcardBase();

u32 GetUnifiedSlot();
MemcardHostBase* GetHost();
void SendWriteMessageToHost();
u32 GetAutoEjectTicks();
void SetAutoEject();
Expand Down
Empty file removed pcsx2/SIO/Memcard/MemcardFile.cpp
Empty file.
16 changes: 0 additions & 16 deletions pcsx2/SIO/Memcard/MemcardFile.h

This file was deleted.

Empty file.
16 changes: 0 additions & 16 deletions pcsx2/SIO/Memcard/MemcardFolder.h

This file was deleted.

18 changes: 0 additions & 18 deletions pcsx2/SIO/Memcard/MemcardHostBase.cpp

This file was deleted.

23 changes: 0 additions & 23 deletions pcsx2/SIO/Memcard/MemcardHostBase.h

This file was deleted.

86 changes: 0 additions & 86 deletions pcsx2/SIO/Memcard/MemcardHostFile.cpp

This file was deleted.

20 changes: 0 additions & 20 deletions pcsx2/SIO/Memcard/MemcardHostFile.h

This file was deleted.

32 changes: 0 additions & 32 deletions pcsx2/SIO/Memcard/MemcardHostFolder.cpp

This file was deleted.

Loading

0 comments on commit 1d001d3

Please sign in to comment.