2016-04-13 06:07:23 +00:00
|
|
|
#ifndef __URDE_CDVDFILE_HPP__
|
|
|
|
#define __URDE_CDVDFILE_HPP__
|
2015-08-23 06:42:29 +00:00
|
|
|
|
|
|
|
#include "RetroTypes.hpp"
|
2017-10-25 07:47:49 +00:00
|
|
|
#include "athena/FileReader.hpp"
|
2015-08-23 06:42:29 +00:00
|
|
|
|
2016-03-07 03:12:32 +00:00
|
|
|
#include <thread>
|
|
|
|
#include <mutex>
|
|
|
|
#include <condition_variable>
|
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
namespace urde
|
2015-08-23 06:42:29 +00:00
|
|
|
{
|
|
|
|
|
2016-02-11 19:18:14 +00:00
|
|
|
static const char* DecodeARAMFile(const char* name)
|
|
|
|
{
|
|
|
|
return (strncmp(name, "aram:", 5) == 0 ? name + 5 : name);
|
|
|
|
}
|
2015-08-23 06:42:29 +00:00
|
|
|
|
2015-11-21 01:16:07 +00:00
|
|
|
enum class ESeekOrigin
|
2015-08-23 06:42:29 +00:00
|
|
|
{
|
2015-11-21 01:16:07 +00:00
|
|
|
Begin = 0,
|
|
|
|
Cur = 1,
|
|
|
|
End = 2
|
2015-08-23 06:42:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct DVDFileInfo;
|
2015-10-29 07:52:15 +00:00
|
|
|
class IDvdRequest;
|
2015-08-23 06:42:29 +00:00
|
|
|
|
|
|
|
class CDvdFile
|
|
|
|
{
|
2015-08-23 23:58:07 +00:00
|
|
|
friend class CResLoader;
|
2016-03-07 03:12:32 +00:00
|
|
|
friend class CFileDvdRequest;
|
|
|
|
static hecl::ProjectPath m_DvdRoot;
|
|
|
|
static std::thread m_WorkerThread;
|
|
|
|
static std::mutex m_WorkerMutex;
|
|
|
|
static std::condition_variable m_WorkerCV;
|
2016-03-07 22:48:54 +00:00
|
|
|
static std::mutex m_WaitMutex;
|
2016-03-07 03:12:32 +00:00
|
|
|
static bool m_WorkerRun;
|
|
|
|
static std::vector<std::shared_ptr<IDvdRequest>> m_RequestQueue;
|
|
|
|
static void WorkerProc();
|
|
|
|
|
|
|
|
std::string x18_path;
|
2016-12-14 01:10:17 +00:00
|
|
|
std::shared_ptr<athena::io::FileReader> m_reader;
|
2016-03-07 03:12:32 +00:00
|
|
|
|
2015-08-23 06:42:29 +00:00
|
|
|
public:
|
2016-03-07 03:12:32 +00:00
|
|
|
static void Initialize(const hecl::ProjectPath& path);
|
|
|
|
static void Shutdown();
|
|
|
|
|
2017-11-13 06:19:18 +00:00
|
|
|
CDvdFile(std::string_view path)
|
2016-12-14 01:10:17 +00:00
|
|
|
: x18_path(path),
|
|
|
|
m_reader(std::make_shared<athena::io::FileReader>(
|
|
|
|
hecl::ProjectPath(m_DvdRoot, path).getAbsolutePath())) {}
|
2017-01-16 08:40:33 +00:00
|
|
|
operator bool() const { return m_reader->isOpen(); }
|
2016-03-07 03:12:32 +00:00
|
|
|
void UpdateFilePos(int pos)
|
|
|
|
{
|
2016-12-14 01:10:17 +00:00
|
|
|
m_reader->seek(pos, athena::SeekOrigin::Begin);
|
2016-03-07 03:12:32 +00:00
|
|
|
}
|
2017-11-13 06:19:18 +00:00
|
|
|
static bool FileExists(std::string_view path)
|
2016-03-07 03:12:32 +00:00
|
|
|
{
|
2016-09-18 23:47:48 +00:00
|
|
|
return hecl::ProjectPath(m_DvdRoot, path).isFile();
|
2016-03-07 03:12:32 +00:00
|
|
|
}
|
|
|
|
void CloseFile()
|
|
|
|
{
|
2016-12-14 01:10:17 +00:00
|
|
|
m_reader->close();
|
2016-03-07 03:12:32 +00:00
|
|
|
}
|
2017-01-16 08:40:33 +00:00
|
|
|
std::shared_ptr<IDvdRequest> AsyncSeekRead(void* buf, u32 len, ESeekOrigin whence,
|
|
|
|
int off, std::function<void(u32)>&& cb = {});
|
|
|
|
u32 SyncSeekRead(void* buf, u32 len, ESeekOrigin whence, int offset)
|
2016-03-07 03:12:32 +00:00
|
|
|
{
|
2016-12-14 01:10:17 +00:00
|
|
|
m_reader->seek(offset, athena::SeekOrigin(whence));
|
2017-01-16 08:40:33 +00:00
|
|
|
return m_reader->readBytesToBuf(buf, len);
|
2016-03-07 03:12:32 +00:00
|
|
|
}
|
2017-01-16 08:40:33 +00:00
|
|
|
std::shared_ptr<IDvdRequest> AsyncRead(void* buf, u32 len, std::function<void(u32)>&& cb = {})
|
2016-03-07 03:12:32 +00:00
|
|
|
{
|
2017-01-16 08:40:33 +00:00
|
|
|
return AsyncSeekRead(buf, len, ESeekOrigin::Cur, 0, std::move(cb));
|
2016-03-07 03:12:32 +00:00
|
|
|
}
|
2017-01-16 08:40:33 +00:00
|
|
|
u32 SyncRead(void* buf, u32 len)
|
2016-03-07 03:12:32 +00:00
|
|
|
{
|
2017-01-16 08:40:33 +00:00
|
|
|
return m_reader->readBytesToBuf(buf, len);
|
2016-03-07 03:12:32 +00:00
|
|
|
}
|
2016-12-14 01:10:17 +00:00
|
|
|
u64 Length() {return m_reader->length();}
|
2017-11-13 06:19:18 +00:00
|
|
|
std::string_view GetPath() const { return x18_path; }
|
2015-08-23 06:42:29 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-04-13 06:07:23 +00:00
|
|
|
#endif // __URDE_CDVDFILE_HPP__
|