2023-02-25 17:39:39 +08:00
|
|
|
#pragma once
|
|
|
|
|
2023-08-25 21:57:22 +08:00
|
|
|
#include "../VTAll.hpp"
|
2023-02-25 17:39:39 +08:00
|
|
|
#if defined(LIBCMO_OS_WIN32)
|
|
|
|
#include <Windows.h>
|
2023-09-12 17:03:06 +08:00
|
|
|
// disable annoy macro at the same time
|
|
|
|
#undef GetObject
|
|
|
|
#undef GetClassName
|
|
|
|
#undef LoadImage
|
|
|
|
#undef GetTempPath
|
2023-02-25 17:39:39 +08:00
|
|
|
#else
|
|
|
|
#include <sys/mman.h>
|
2023-03-04 14:08:16 +08:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
2023-02-25 17:39:39 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <string>
|
2023-02-25 22:58:28 +08:00
|
|
|
#include <filesystem>
|
2023-02-25 17:39:39 +08:00
|
|
|
|
2023-02-26 21:48:03 +08:00
|
|
|
namespace LibCmo::VxMath {
|
2023-02-25 17:39:39 +08:00
|
|
|
|
|
|
|
class VxMemoryMappedFile {
|
|
|
|
private:
|
|
|
|
|
|
|
|
#if defined(LIBCMO_OS_WIN32)
|
|
|
|
HANDLE m_hFile;
|
|
|
|
DWORD m_dwFileSizeLow, m_dwFileSizeHigh;
|
|
|
|
HANDLE m_hFileMapping;
|
|
|
|
LPVOID m_hFileMapView;
|
|
|
|
#else
|
2023-03-04 14:08:16 +08:00
|
|
|
int m_hFile;
|
|
|
|
off_t m_offFileSize;
|
|
|
|
void* m_pFileAddr;
|
2023-02-25 17:39:39 +08:00
|
|
|
#endif
|
|
|
|
|
2023-02-25 22:58:28 +08:00
|
|
|
std::filesystem::path m_szFilePath;
|
2023-02-25 17:39:39 +08:00
|
|
|
void* m_pMemoryMappedFileBase;
|
|
|
|
size_t m_cbFile;
|
|
|
|
bool m_bIsValid;
|
|
|
|
public:
|
|
|
|
VxMemoryMappedFile(const char* u8_filepath);
|
|
|
|
VxMemoryMappedFile(const VxMemoryMappedFile&) = delete;
|
|
|
|
VxMemoryMappedFile& operator=(const VxMemoryMappedFile&) = delete;
|
|
|
|
~VxMemoryMappedFile(void);
|
|
|
|
|
2023-08-25 21:57:22 +08:00
|
|
|
void* GetBase(void) { return this->m_pMemoryMappedFileBase; }
|
2023-08-29 14:00:34 +08:00
|
|
|
CK2::CKDWORD GetFileSize(void) { return static_cast<CK2::CKDWORD>(this->m_cbFile); }
|
2023-08-25 21:57:22 +08:00
|
|
|
bool IsValid(void) { return this->m_bIsValid; }
|
2023-02-25 17:39:39 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|