12 using error::throwTrace;
19 FileLoader() =
default;
20 virtual ~FileLoader() =
default;
21 virtual std::vector<uint8_t>
loadFile(
const wchar_t *fileName) = 0;
24 class FsFileLoader :
public FileLoader {
26 FsFileLoader(
const wchar_t *rootDir) : m_rootDir(rootDir) {}
27 virtual ~FsFileLoader()
override {}
28 virtual std::vector<uint8_t>
loadFile(
const wchar_t *fileName)
override;
30 std::wstring m_rootDir;
33 class ArchiveFileLoader :
public FileLoader {
41 if (fileName[0] == L
'/') {
45 else if (fileName[0] == L
'@') {
47 std::array<wchar_t, MAX_PATH> dir;
48 DWORD ret = ::GetModuleFileName(
nullptr, dir.data(),
static_cast<DWORD
>(dir.size()));
50 *(::wcsrchr(dir.data(), L
'\\') + 1) = L
'\0';
61 HANDLE tmphFile = ::CreateFile(
62 path.c_str(), GENERIC_READ, FILE_SHARE_READ,
nullptr, OPEN_EXISTING,
63 FILE_ATTRIBUTE_NORMAL,
nullptr);
69 LARGE_INTEGER fileSize = { 0 };
70 b = ::GetFileSizeEx(hFile.get(), &fileSize);
76 Bytes bin(fileSize.LowPart);
78 b = ::ReadFile(hFile.get(), bin.data(), fileSize.LowPart, &readSize,
nullptr);
87 std::unique_ptr<FileLoader> s_fileLoader(
nullptr);
94 s_fileLoader.reset(
new FsFileLoader(rootDir));
100 throwTrace<std::logic_error>(
"Not implemented");
103 std::vector<uint8_t>
loadFile(
const wchar_t *fileName)
105 if (s_fileLoader ==
nullptr) {
106 throwTrace<std::logic_error>(
"FileLoader is not initialized.");
108 return s_fileLoader->loadFile(fileName);
std::vector< uint8_t > loadFile(const wchar_t *fileName)
Load file from abstract file system.
void initWithFileSystem(const wchar_t *rootDir)
Uses real file system.
void initWithArchiveFile(const wchar_t *archiveFile)
Uses archive file.
std::unique_ptr< HANDLE, HandleDeleter > HandlePtr
unique_ptr of HANDLE with HandleDeleter.
std::vector< uint8_t > Bytes
File byte sequence. Vector of uint8_t.
void checkWin32Result(bool cond, const std::string &msg)