-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve MultiFileSystem to allow more file systems
- Loading branch information
1 parent
8e53227
commit b3091ee
Showing
6 changed files
with
97 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#include "ArchiveFileSystem.h" | ||
|
||
#include "util/Hooking.h" | ||
|
||
cdc::ArchiveFileSystem::ArchiveFileSystem(FileSystem* pDiskFS) | ||
{ | ||
// Call the original constructor | ||
Hooking::ThisCall(0x47E0D0, this, pDiskFS); | ||
} | ||
|
||
bool cdc::ArchiveFileSystem::Open(const char* archiveFileName) | ||
{ | ||
return Hooking::ThisCallReturn<bool>(0x47DDF0, this, archiveFileName); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#pragma once | ||
|
||
#include "FileSystem.h" | ||
|
||
namespace cdc | ||
{ | ||
class ArchiveFileSystem : public FileSystem | ||
{ | ||
public: | ||
ArchiveFileSystem(FileSystem* pDiskFS); | ||
|
||
bool Open(const char* archiveFileName); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,105 @@ | ||
#include "MultiFileSystem.h" | ||
#include "MultiFileSystem.h" | ||
|
||
MultiFileSystem::MultiFileSystem(cdc::FileSystem* pFS, cdc::FileSystem* pHookFS) | ||
MultiFileSystem::MultiFileSystem() : m_fileSystems() | ||
{ | ||
m_pFS = pFS; | ||
m_pHookFS = pHookFS; | ||
} | ||
|
||
// Gets the best file system for a file simply by checking the hook file system first | ||
// Gets the best file system for a file by checking all file systems | ||
cdc::FileSystem* MultiFileSystem::GetBestFileSystem(const char* fileName) | ||
{ | ||
// First check the hook file system, else fall back to default filesystem | ||
if (m_pHookFS->FileExists(fileName)) | ||
for (auto fileSystem : m_fileSystems) | ||
{ | ||
return m_pHookFS; | ||
if (fileSystem->FileExists(fileName)) | ||
{ | ||
return fileSystem; | ||
} | ||
} | ||
|
||
return m_pFS; | ||
return nullptr; | ||
} | ||
|
||
void MultiFileSystem::Add(cdc::FileSystem* fileSystem) | ||
{ | ||
m_fileSystems.push_back(fileSystem); | ||
} | ||
|
||
cdc::FileRequest* MultiFileSystem::RequestRead(cdc::FileReceiver* receiver, const char* fileName, unsigned int startOffset) | ||
{ | ||
auto pFS = GetBestFileSystem(fileName); | ||
auto fileSystem = GetBestFileSystem(fileName); | ||
|
||
return pFS->RequestRead(receiver, fileName, startOffset); | ||
return fileSystem->RequestRead(receiver, fileName, startOffset); | ||
} | ||
|
||
cdc::File* MultiFileSystem::OpenFile(char const* fileName) | ||
{ | ||
auto pFS = GetBestFileSystem(fileName); | ||
auto fileSystem = GetBestFileSystem(fileName); | ||
|
||
return pFS->OpenFile(fileName); | ||
return fileSystem->OpenFile(fileName); | ||
} | ||
|
||
bool MultiFileSystem::FileExists(char const* fileName) | ||
{ | ||
return m_pFS->FileExists(fileName) || m_pHookFS->FileExists(fileName); | ||
for (auto fileSystem : m_fileSystems) | ||
{ | ||
if (fileSystem->FileExists(fileName)) | ||
{ | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
unsigned int MultiFileSystem::GetFileSize(char const* fileName) | ||
{ | ||
auto pFS = GetBestFileSystem(fileName); | ||
auto fileSystem = GetBestFileSystem(fileName); | ||
|
||
return pFS->GetFileSize(fileName); | ||
return fileSystem->GetFileSize(fileName); | ||
} | ||
|
||
void MultiFileSystem::SetSpecialisationMask(unsigned int specMask) | ||
{ | ||
m_pFS->SetSpecialisationMask(specMask); | ||
m_pHookFS->SetSpecialisationMask(specMask); | ||
for (auto fileSystem : m_fileSystems) | ||
{ | ||
fileSystem->SetSpecialisationMask(specMask); | ||
} | ||
} | ||
|
||
unsigned int MultiFileSystem::GetSpecialisationMask() | ||
{ | ||
return m_pFS->GetSpecialisationMask(); | ||
} | ||
if (m_fileSystems.empty()) | ||
{ | ||
return 0xFFFFFFFF; | ||
} | ||
|
||
// These only need to call the default file system, both will end at the same place | ||
return m_fileSystems[0]->GetSpecialisationMask(); | ||
} | ||
|
||
cdc::FileSystem::Status MultiFileSystem::GetStatus() | ||
{ | ||
return m_pFS->GetStatus(); | ||
for (auto fileSystem : m_fileSystems) | ||
{ | ||
if (fileSystem->GetStatus() == BUSY) | ||
{ | ||
return BUSY; | ||
} | ||
} | ||
|
||
return IDLE; | ||
} | ||
|
||
void MultiFileSystem::Update() | ||
{ | ||
m_pFS->Update(); | ||
for (auto fileSystem : m_fileSystems) | ||
{ | ||
fileSystem->Update(); | ||
} | ||
} | ||
|
||
void MultiFileSystem::Synchronize() | ||
{ | ||
m_pFS->Synchronize(); | ||
for (auto fileSystem : m_fileSystems) | ||
{ | ||
fileSystem->Synchronize(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters