-
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.
- Loading branch information
1 parent
1e465da
commit 5c6a431
Showing
3 changed files
with
80 additions
and
39 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 |
---|---|---|
@@ -1,73 +1,110 @@ | ||
#include "MultiFileSystem.h" | ||
|
||
MultiFileSystem::MultiFileSystem(cdc::FileSystem* pFS, cdc::FileSystem* pHookFS) | ||
#include "Hook.h" | ||
#include "modules/Log.h" | ||
|
||
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 | ||
cdc::FileSystem* MultiFileSystem::GetBestFileSystem(const char* fileName) | ||
void MultiFileSystem::Add(cdc::FileSystem* fileSystem) | ||
{ | ||
// First check the hook file system, else fall back to default filesystem | ||
if (m_pHookFS->FileExists(fileName)) | ||
m_fileSystems.push_back(fileSystem); | ||
|
||
#ifdef _DEBUG | ||
Hook::GetInstance().GetModule<Log>()->WriteLine("Mounted new file system %p, now at %d", fileSystem, m_fileSystems.size()); | ||
#endif | ||
} | ||
|
||
void MultiFileSystem::Remove(cdc::FileSystem* fileSystem) | ||
{ | ||
auto it = std::find(m_fileSystems.begin(), m_fileSystems.end(), fileSystem); | ||
|
||
if (it != m_fileSystems.end()) | ||
{ | ||
return m_pHookFS; | ||
m_fileSystems.erase(it); | ||
} | ||
|
||
return m_pFS; | ||
} | ||
|
||
cdc::FileRequest* MultiFileSystem::RequestRead(cdc::FileReceiver* receiver, const char* fileName, unsigned int startOffset) | ||
cdc::FileSystem* MultiFileSystem::GetBestFileSystem(const char* fileName) const noexcept | ||
{ | ||
auto pFS = GetBestFileSystem(fileName); | ||
for (auto fileSystem : m_fileSystems) | ||
{ | ||
if (fileSystem->FileExists(fileName)) | ||
{ | ||
return fileSystem; | ||
} | ||
} | ||
|
||
return pFS->RequestRead(receiver, fileName, startOffset); | ||
return nullptr; | ||
} | ||
|
||
cdc::File* MultiFileSystem::OpenFile(char const* fileName) | ||
cdc::FileRequest* MultiFileSystem::RequestRead(cdc::FileReceiver* receiver, const char* fileName, unsigned int startOffset) | ||
{ | ||
auto pFS = GetBestFileSystem(fileName); | ||
return GetBestFileSystem(fileName)->RequestRead(receiver, fileName, startOffset); | ||
} | ||
|
||
return pFS->OpenFile(fileName); | ||
cdc::File* MultiFileSystem::OpenFile(const char* fileName) | ||
{ | ||
return GetBestFileSystem(fileName)->OpenFile(fileName); | ||
} | ||
|
||
bool MultiFileSystem::FileExists(char const* fileName) | ||
unsigned int MultiFileSystem::GetFileSize(const char* fileName) | ||
{ | ||
return m_pFS->FileExists(fileName) || m_pHookFS->FileExists(fileName); | ||
return GetBestFileSystem(fileName)->GetFileSize(fileName); | ||
} | ||
|
||
unsigned int MultiFileSystem::GetFileSize(char const* fileName) | ||
bool MultiFileSystem::FileExists(const char* fileName) | ||
{ | ||
auto pFS = GetBestFileSystem(fileName); | ||
for (auto fileSystem : m_fileSystems) | ||
{ | ||
if (fileSystem->FileExists(fileName)) | ||
{ | ||
return true; | ||
} | ||
} | ||
|
||
return pFS->GetFileSize(fileName); | ||
return false; | ||
} | ||
|
||
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(); | ||
return m_fileSystems.empty() ? 0xFFFFFFFF : m_fileSystems[0]->GetSpecialisationMask(); | ||
} | ||
|
||
// These only need to call the default file system, both will end at the same place | ||
|
||
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