mirror of https://github.com/libAthena/athena.git
added support for wchar_t file paths and more stable windows builds
This commit is contained in:
parent
8e5e4d7603
commit
ac36bb4f4a
|
@ -18,7 +18,9 @@ set(ATHENA_VERSION
|
||||||
add_subdirectory(extern)
|
add_subdirectory(extern)
|
||||||
|
|
||||||
include_directories(include ${LZO_INCLUDE_DIR} ${ZLIB_INCLUDE_DIR})
|
include_directories(include ${LZO_INCLUDE_DIR} ${ZLIB_INCLUDE_DIR})
|
||||||
|
if (NOT WIN32)
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
|
||||||
|
endif()
|
||||||
|
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
list(APPEND CORE_EXTRA src/win32_largefilewrapper.c)
|
list(APPEND CORE_EXTRA src/win32_largefilewrapper.c)
|
||||||
|
@ -108,7 +110,9 @@ add_library(AthenaWiiSave
|
||||||
include/md5.h
|
include/md5.h
|
||||||
include/sha1.h
|
include/sha1.h
|
||||||
)
|
)
|
||||||
|
if(NOT WIN32)
|
||||||
set_source_files_properties(src/aes.cpp PROPERTIES COMPILE_FLAGS -maes)
|
set_source_files_properties(src/aes.cpp PROPERTIES COMPILE_FLAGS -maes)
|
||||||
|
endif()
|
||||||
|
|
||||||
add_library(AthenaZelda
|
add_library(AthenaZelda
|
||||||
src/Athena/ALTTPFile.cpp
|
src/Athena/ALTTPFile.cpp
|
||||||
|
|
|
@ -53,16 +53,16 @@ struct DNA
|
||||||
using Vector = std::vector<T>;
|
using Vector = std::vector<T>;
|
||||||
|
|
||||||
template <size_t sizeVar>
|
template <size_t sizeVar>
|
||||||
using Buffer = struct Buffer<sizeVar, DNAE>;
|
using Buffer = struct Athena::io::Buffer<sizeVar, DNAE>;
|
||||||
|
|
||||||
template <atInt32 sizeVar = -1>
|
template <atInt32 sizeVar = -1>
|
||||||
using String = struct String<sizeVar, DNAE>;
|
using String = struct Athena::io::String<sizeVar, DNAE>;
|
||||||
|
|
||||||
template <atInt32 sizeVar = -1, Endian VE = DNAE>
|
template <atInt32 sizeVar = -1, Endian VE = DNAE>
|
||||||
using WString = struct WString<sizeVar, VE>;
|
using WString = struct Athena::io::WString<sizeVar, VE>;
|
||||||
|
|
||||||
template <atInt32 sizeVar = -1>
|
template <atInt32 sizeVar = -1>
|
||||||
using WStringAsString = struct WStringAsString<sizeVar, DNAE>;
|
using WStringAsString = struct Athena::io::WStringAsString<sizeVar, DNAE>;
|
||||||
|
|
||||||
template <off_t offset, SeekOrigin direction>
|
template <off_t offset, SeekOrigin direction>
|
||||||
struct Seek {};
|
struct Seek {};
|
||||||
|
|
|
@ -14,6 +14,9 @@ class FileReader : public IStreamReader
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
FileReader(const std::string& filename, atInt32 cacheSize = (32 * 1024));
|
FileReader(const std::string& filename, atInt32 cacheSize = (32 * 1024));
|
||||||
|
#if _WIN32
|
||||||
|
FileReader(const std::wstring& filename, atInt32 cacheSize = (32 * 1024));
|
||||||
|
#endif
|
||||||
virtual ~FileReader();
|
virtual ~FileReader();
|
||||||
inline const std::string& filename() const
|
inline const std::string& filename() const
|
||||||
{return m_filename;}
|
{return m_filename;}
|
||||||
|
@ -31,6 +34,9 @@ public:
|
||||||
void setCacheSize(const atInt32 blockSize);
|
void setCacheSize(const atInt32 blockSize);
|
||||||
protected:
|
protected:
|
||||||
std::string m_filename;
|
std::string m_filename;
|
||||||
|
#if _WIN32
|
||||||
|
std::wstring m_wfilename;
|
||||||
|
#endif
|
||||||
FILE* m_fileHandle;
|
FILE* m_fileHandle;
|
||||||
std::unique_ptr<atUint8[]> m_cacheData;
|
std::unique_ptr<atUint8[]> m_cacheData;
|
||||||
atInt32 m_blockSize;
|
atInt32 m_blockSize;
|
||||||
|
|
|
@ -12,6 +12,9 @@ class FileWriter : public IStreamWriter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
FileWriter(const std::string& filename, bool overwrite = true);
|
FileWriter(const std::string& filename, bool overwrite = true);
|
||||||
|
#if _WIN32
|
||||||
|
FileWriter(const std::wstring& filename, bool overwrite = true);
|
||||||
|
#endif
|
||||||
virtual ~FileWriter();
|
virtual ~FileWriter();
|
||||||
|
|
||||||
void open(bool overwrite = true);
|
void open(bool overwrite = true);
|
||||||
|
@ -25,6 +28,9 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string m_filename;
|
std::string m_filename;
|
||||||
|
#if _WIN32
|
||||||
|
std::wstring m_wfilename;
|
||||||
|
#endif
|
||||||
FILE* m_fileHandle;
|
FILE* m_fileHandle;
|
||||||
atUint8 m_currentByte;
|
atUint8 m_currentByte;
|
||||||
atUint64 m_bytePosition;
|
atUint64 m_bytePosition;
|
||||||
|
|
|
@ -97,7 +97,7 @@ atInt32 decompressLZO(const atUint8* source, const atInt32 sourceSize, atUint8*
|
||||||
int srcSize = sourceSize;
|
int srcSize = sourceSize;
|
||||||
lzo_uint size = dstSize;
|
lzo_uint size = dstSize;
|
||||||
int result = lzo1x_decompress_safe(source, srcSize, dst, &size, NULL);
|
int result = lzo1x_decompress_safe(source, srcSize, dst, &size, NULL);
|
||||||
dstSize -= size;
|
dstSize -= (atInt32)size;
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,18 @@ FileReader::FileReader(const std::string& filename, atInt32 cacheSize)
|
||||||
setCacheSize(cacheSize);
|
setCacheSize(cacheSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if _WIN32
|
||||||
|
FileReader::FileReader(const std::wstring& filename, atInt32 cacheSize)
|
||||||
|
: m_wfilename(filename),
|
||||||
|
m_fileHandle(nullptr),
|
||||||
|
m_cacheData(nullptr),
|
||||||
|
m_offset(0)
|
||||||
|
{
|
||||||
|
open();
|
||||||
|
setCacheSize(cacheSize);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
FileReader::~FileReader()
|
FileReader::~FileReader()
|
||||||
{
|
{
|
||||||
if (isOpen())
|
if (isOpen())
|
||||||
|
@ -28,7 +40,14 @@ FileReader::~FileReader()
|
||||||
|
|
||||||
void FileReader::open()
|
void FileReader::open()
|
||||||
{
|
{
|
||||||
|
#if _WIN32
|
||||||
|
if (m_wfilename.size())
|
||||||
|
m_fileHandle = _wfopen(m_wfilename.c_str(), L"rb");
|
||||||
|
else
|
||||||
m_fileHandle = fopen(m_filename.c_str(), "rb");
|
m_fileHandle = fopen(m_filename.c_str(), "rb");
|
||||||
|
#else
|
||||||
|
m_fileHandle = fopen(m_filename.c_str(), "rb");
|
||||||
|
#endif
|
||||||
|
|
||||||
if (!m_fileHandle)
|
if (!m_fileHandle)
|
||||||
{
|
{
|
||||||
|
@ -85,7 +104,7 @@ void FileReader::seek(atInt64 pos, SeekOrigin origin)
|
||||||
{
|
{
|
||||||
fseeko64(m_fileHandle, block * m_blockSize, SEEK_SET);
|
fseeko64(m_fileHandle, block * m_blockSize, SEEK_SET);
|
||||||
fread(m_cacheData.get(), 1, m_blockSize, m_fileHandle);
|
fread(m_cacheData.get(), 1, m_blockSize, m_fileHandle);
|
||||||
m_curBlock = block;
|
m_curBlock = (atInt32)block;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (fseeko64(m_fileHandle, pos, (int)origin) != 0)
|
else if (fseeko64(m_fileHandle, pos, (int)origin) != 0)
|
||||||
|
@ -142,7 +161,7 @@ atUint64 FileReader::readUBytesToBuf(void* buf, atUint64 len)
|
||||||
{
|
{
|
||||||
fseeko64(m_fileHandle, block * m_blockSize, SEEK_SET);
|
fseeko64(m_fileHandle, block * m_blockSize, SEEK_SET);
|
||||||
fread(m_cacheData.get(), 1, m_blockSize, m_fileHandle);
|
fread(m_cacheData.get(), 1, m_blockSize, m_fileHandle);
|
||||||
m_curBlock = block;
|
m_curBlock = (atInt32)block;
|
||||||
}
|
}
|
||||||
|
|
||||||
cacheSize = rem;
|
cacheSize = rem;
|
||||||
|
@ -165,7 +184,7 @@ void FileReader::setCacheSize(const atInt32 blockSize)
|
||||||
m_blockSize = blockSize;
|
m_blockSize = blockSize;
|
||||||
|
|
||||||
if (m_blockSize > length())
|
if (m_blockSize > length())
|
||||||
m_blockSize = length();
|
m_blockSize = (atInt32)length();
|
||||||
|
|
||||||
m_curBlock = -1;
|
m_curBlock = -1;
|
||||||
if (m_blockSize > 0)
|
if (m_blockSize > 0)
|
||||||
|
|
|
@ -18,6 +18,16 @@ FileWriter::FileWriter(const std::string& filename, bool overwrite)
|
||||||
open(overwrite);
|
open(overwrite);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if _WIN32
|
||||||
|
FileWriter::FileWriter(const std::wstring& filename, bool overwrite)
|
||||||
|
: m_wfilename(filename),
|
||||||
|
m_fileHandle(NULL),
|
||||||
|
m_bytePosition(0)
|
||||||
|
{
|
||||||
|
open(overwrite);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
FileWriter::~FileWriter()
|
FileWriter::~FileWriter()
|
||||||
{
|
{
|
||||||
if (isOpen())
|
if (isOpen())
|
||||||
|
@ -25,11 +35,30 @@ FileWriter::~FileWriter()
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileWriter::open(bool overwrite)
|
void FileWriter::open(bool overwrite)
|
||||||
|
{
|
||||||
|
#if _WIN32
|
||||||
|
if (m_wfilename.size())
|
||||||
|
{
|
||||||
|
if (overwrite)
|
||||||
|
m_fileHandle = _wfopen(m_wfilename.c_str(), L"w+b");
|
||||||
|
else
|
||||||
|
m_fileHandle = _wfopen(m_wfilename.c_str(), L"r+b");
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
if (overwrite)
|
if (overwrite)
|
||||||
m_fileHandle = fopen(m_filename.c_str(), "w+b");
|
m_fileHandle = fopen(m_filename.c_str(), "w+b");
|
||||||
else
|
else
|
||||||
m_fileHandle = fopen(m_filename.c_str(), "r+b");
|
m_fileHandle = fopen(m_filename.c_str(), "r+b");
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
if (overwrite)
|
||||||
|
m_fileHandle = fopen(m_filename.c_str(), "w+b");
|
||||||
|
else
|
||||||
|
m_fileHandle = fopen(m_filename.c_str(), "r+b");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (!m_fileHandle)
|
if (!m_fileHandle)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue