Skip to content

Commit 1d001d3

Browse files
committed
Scrap host classes
1 parent 447460b commit 1d001d3

21 files changed

+264
-292
lines changed

pcsx2/SIO/Memcard/Memcard.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44
#include "SIO/Memcard/Memcard.h"
55

66
#include "SIO/Sio.h"
7+
#include "SIO/Memcard/MemcardBase.h"
78
#include "SIO/Memcard/MemcardPS2.h"
89
#include "SIO/Memcard/MemcardPS1.h"
910
#include "SIO/Memcard/MemcardNotConnected.h"
10-
#include "SIO/Memcard/MemcardHostFile.h"
11-
#include "SIO/Memcard/MemcardHostFolder.h"
1211

1312
#include "Common.h"
1413
#include "common/Path.h"
@@ -42,18 +41,13 @@ bool Memcard::Initialize()
4241
{
4342
s_memcards.at(i) = std::make_unique<MemcardPS1>(i, fullPath);
4443
}
45-
46-
// If a host was not built because no such file or folder existed,
47-
// or a file card failed to open, then ditch the card
48-
if (!s_memcards.at(i)->GetHost() || !s_memcards.at(i)->GetHost()->IsOpened())
44+
else
4945
{
5046
s_memcards.at(i) = std::make_unique<MemcardNotConnected>(i);
5147

52-
// Translation note: detailed description should mention that the memory card will be disabled
53-
// for the duration of this session.
5448
Host::ReportFormattedErrorAsync("Memory Card",
5549
"Access denied to memory card: \n\n%s\n\n"
56-
"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",
50+
"PCSX2 cannot access your memory card. Either you do not have permission to open it, or another program is currently accessign it.%s",
5751
fullPath.c_str(),
5852
#ifdef WIN32
5953
"\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\"."

pcsx2/SIO/Memcard/Memcard.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#pragma once
33

44
class MemcardBase;
5-
class MemcardHostBase;
65

76
namespace Memcard
87
{
@@ -39,7 +38,10 @@ namespace Memcard
3938
AUTH_F7 = 0xf7
4039
};
4140

42-
enum class HostType
41+
// The storage type to use on the host PC.
42+
// - File type uses a single to emulate the entire memcard as a continuous binary blob
43+
// - Folder type uses a folder on the host filesystem to rebuild the PS2 filesystem on the PC
44+
enum class StorageType
4345
{
4446
NOT_SET = 0,
4547
FILE = 1,

pcsx2/SIO/Memcard/MemcardBase.cpp

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,49 @@
33

44
#include "SIO/Memcard/MemcardBase.h"
55

6-
#include "SIO/Memcard/MemcardHostFile.h"
7-
#include "SIO/Memcard/MemcardHostFolder.h"
8-
96
#include "common/FileSystem.h"
107
#include "common/Path.h"
118
#include "Host.h"
129
#include "fmt/core.h"
1310
#include "IconsFontAwesome5.h"
1411

12+
bool MemcardBase::IsOpened()
13+
{
14+
switch (this->storageType)
15+
{
16+
case Memcard::StorageType::FILE:
17+
{
18+
return this->filePtr;
19+
}
20+
case Memcard::StorageType::FOLDER:
21+
{
22+
return true;
23+
}
24+
default:
25+
{
26+
return false;
27+
}
28+
}
29+
}
30+
1531
MemcardBase::MemcardBase(u32 unifiedSlot, std::string fullPath)
1632
{
1733
this->unifiedSlot = unifiedSlot;
34+
this->fullPath = fullPath;
1835
this->autoEjectTicks = 0;
1936
this->lastWriteTime = std::chrono::system_clock::now();
2037

21-
if (fullPath == "")
38+
if (fullPath.empty())
2239
{
23-
return;
40+
this->storageType = Memcard::StorageType::NOT_SET;
2441
}
2542
else if (FileSystem::FileExists(fullPath.c_str()))
2643
{
27-
this->hostType = Memcard::HostType::FILE;
28-
this->memcardHost = std::make_unique<MemcardHostFile>(fullPath);
44+
this->storageType = Memcard::StorageType::FILE;
2945
}
3046
else if (FileSystem::DirectoryExists(fullPath.c_str()))
3147
{
32-
this->hostType = Memcard::HostType::FOLDER;
33-
this->memcardHost = std::make_unique<MemcardHostFolder>(fullPath);
48+
this->storageType = Memcard::StorageType::FOLDER;
3449
}
3550
}
3651

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

44-
MemcardHostBase* MemcardBase::GetHost()
45-
{
46-
return this->memcardHost.get();
47-
}
48-
4959
void MemcardBase::SendWriteMessageToHost()
5060
{
5161
const std::chrono::duration<float> elapsed = std::chrono::system_clock::now() - this->lastWriteTime;
@@ -59,7 +69,7 @@ void MemcardBase::SendWriteMessageToHost()
5969
ICON_FA_SD_CARD,
6070
fmt::format(
6171
TRANSLATE_FS("MemoryCard", "Memory Card '{}' written to storage."),
62-
Path::GetFileName(this->memcardHost->GetPath())),
72+
Path::GetFileName(this->fullPath)),
6373
Host::OSD_INFO_DURATION);
6474
this->lastWriteTime = std::chrono::system_clock::now();
6575
}

pcsx2/SIO/Memcard/MemcardBase.h

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,38 @@
22
#pragma once
33

44
#include "SIO/Memcard/Memcard.h"
5-
#include "SIO/Memcard/MemcardHostBase.h"
65

76
class MemcardBase
87
{
98
private:
109
u32 unifiedSlot;
10+
std::string fullPath;
1111

1212
protected:
13-
Memcard::HostType hostType;
14-
std::unique_ptr<MemcardHostBase> memcardHost;
13+
Memcard::StorageType storageType;
14+
std::FILE* filePtr;
1515
u32 autoEjectTicks;
1616
std::chrono::time_point<std::chrono::system_clock> lastWriteTime;
1717

18+
bool IsOpened();
19+
20+
virtual bool Seek(u32 addr) = 0;
21+
virtual bool SeekFile(u32 addr) = 0;
22+
virtual bool SeekFolder(u32 addr) = 0;
23+
24+
virtual void Write(u32 addr, std::vector<u8>& src) = 0;
25+
virtual void WriteFile(u32 addr, std::vector<u8>& src) = 0;
26+
virtual void WriteFolder(u32 addr, std::vector<u8>& src) = 0;
27+
28+
virtual void Read(u32 addr, std::vector<u8>& dest) = 0;
29+
virtual void ReadFile(u32 addr, std::vector<u8>& dest) = 0;
30+
virtual void ReadFolder(u32 addr, std::vector<u8>& dest) = 0;
31+
1832
public:
1933
MemcardBase(u32 unifiedSlot, std::string fullPath);
2034
virtual ~MemcardBase();
2135

2236
u32 GetUnifiedSlot();
23-
MemcardHostBase* GetHost();
2437
void SendWriteMessageToHost();
2538
u32 GetAutoEjectTicks();
2639
void SetAutoEject();

pcsx2/SIO/Memcard/MemcardFile.cpp

Whitespace-only changes.

pcsx2/SIO/Memcard/MemcardFile.h

Lines changed: 0 additions & 16 deletions
This file was deleted.

pcsx2/SIO/Memcard/MemcardFolder.cpp

Whitespace-only changes.

pcsx2/SIO/Memcard/MemcardFolder.h

Lines changed: 0 additions & 16 deletions
This file was deleted.

pcsx2/SIO/Memcard/MemcardHostBase.cpp

Lines changed: 0 additions & 18 deletions
This file was deleted.

pcsx2/SIO/Memcard/MemcardHostBase.h

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)