2
0
mirror of https://github.com/AxioDL/metaforce.git synced 2025-12-08 23:07:42 +00:00

Integrate URDEVersionInfo

This commit is contained in:
2020-04-15 06:42:44 -07:00
parent e553a9022f
commit 52b4db2f00
11 changed files with 144 additions and 87 deletions

View File

@@ -19,7 +19,7 @@ class CFileDvdRequest : public IDvdRequest {
std::function<void(u32)> m_callback;
public:
~CFileDvdRequest() override { PostCancelRequest(); }
~CFileDvdRequest() override { CFileDvdRequest::PostCancelRequest(); }
void WaitUntilComplete() override {
while (!m_complete.load() && !m_cancel.load()) {
@@ -32,14 +32,15 @@ public:
m_cancel.store(true);
}
EMediaType GetMediaType() const override { return EMediaType::File; }
[[nodiscard]] EMediaType GetMediaType() const override { return EMediaType::File; }
CFileDvdRequest(CDvdFile& file, void* buf, u32 len, ESeekOrigin whence, int off, std::function<void(u32)>&& cb)
: m_reader(file.m_reader), m_buf(buf), m_len(len), m_whence(whence), m_offset(off), m_callback(std::move(cb)) {}
void DoRequest() {
if (m_cancel.load())
if (m_cancel.load()) {
return;
}
u32 readLen;
if (m_whence == ESeekOrigin::Cur && m_offset == 0) {
readLen = m_reader->readBytesToBuf(m_buf, m_len);
@@ -47,8 +48,9 @@ public:
m_reader->seek(m_offset, athena::SeekOrigin(m_whence));
readLen = m_reader->readBytesToBuf(m_buf, m_len);
}
if (m_callback)
if (m_callback) {
m_callback(readLen);
}
m_complete.store(true);
}
};
@@ -63,21 +65,22 @@ void CDvdFile::WorkerProc() {
logvisor::RegisterThreadName("CDvdFile");
while (m_WorkerRun.load()) {
std::unique_lock<std::mutex> lk(CDvdFile::m_WorkerMutex);
while (CDvdFile::m_RequestQueue.size()) {
while (!CDvdFile::m_RequestQueue.empty()) {
std::vector<std::shared_ptr<IDvdRequest>> swapQueue;
swapQueue.swap(CDvdFile::m_RequestQueue);
lk.unlock();
std::unique_lock<std::mutex> waitlk(CDvdFile::m_WaitMutex);
for (std::shared_ptr<IDvdRequest>& req : swapQueue) {
CFileDvdRequest& concreteReq = static_cast<CFileDvdRequest&>(*req);
auto& concreteReq = static_cast<CFileDvdRequest&>(*req);
concreteReq.DoRequest();
}
waitlk.unlock();
swapQueue.clear();
lk.lock();
}
if (!m_WorkerRun.load())
if (!m_WorkerRun.load()) {
break;
}
m_WorkerCV.wait(lk);
}
}
@@ -93,13 +96,16 @@ std::shared_ptr<IDvdRequest> CDvdFile::AsyncSeekRead(void* buf, u32 len, ESeekOr
}
hecl::ProjectPath CDvdFile::ResolvePath(std::string_view path) {
auto start = path.begin();
while (*start == '/') ++start;
const char* start = path.begin();
while (*start == '/') {
++start;
}
std::string lowerChStr(start, path.end());
std::transform(lowerChStr.begin(), lowerChStr.end(), lowerChStr.begin(), ::tolower);
auto search = m_caseInsensitiveMap.find(lowerChStr);
if (search == m_caseInsensitiveMap.end())
if (search == m_caseInsensitiveMap.end()) {
return {};
}
return hecl::ProjectPath(m_DvdRoot, search->second);
}
@@ -120,19 +126,22 @@ void CDvdFile::RecursiveBuildCaseInsensitiveMap(const hecl::ProjectPath& path, s
void CDvdFile::Initialize(const hecl::ProjectPath& path) {
m_DvdRoot = path;
RecursiveBuildCaseInsensitiveMap(path, path.getAbsolutePathUTF8().length() + 1);
if (m_WorkerRun.load())
if (m_WorkerRun.load()) {
return;
}
m_WorkerRun.store(true);
m_WorkerThread = std::thread(WorkerProc);
}
void CDvdFile::Shutdown() {
if (!m_WorkerRun.load())
if (!m_WorkerRun.load()) {
return;
}
m_WorkerRun.store(false);
m_WorkerCV.notify_one();
if (m_WorkerThread.joinable())
if (m_WorkerThread.joinable()) {
m_WorkerThread.join();
}
m_RequestQueue.clear();
}