added support for wchar_t file paths and more stable windows builds

This commit is contained in:
Jack Andersen 2015-07-22 08:59:40 -10:00 committed by Phillip Stephens
parent 8e5e4d7603
commit ac36bb4f4a
7 changed files with 73 additions and 9 deletions

View File

@ -18,7 +18,9 @@ set(ATHENA_VERSION
add_subdirectory(extern)
include_directories(include ${LZO_INCLUDE_DIR} ${ZLIB_INCLUDE_DIR})
if (NOT WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
endif()
if(WIN32)
list(APPEND CORE_EXTRA src/win32_largefilewrapper.c)
@ -108,7 +110,9 @@ add_library(AthenaWiiSave
include/md5.h
include/sha1.h
)
if(NOT WIN32)
set_source_files_properties(src/aes.cpp PROPERTIES COMPILE_FLAGS -maes)
endif()
add_library(AthenaZelda
src/Athena/ALTTPFile.cpp

View File

@ -53,16 +53,16 @@ struct DNA
using Vector = std::vector<T>;
template <size_t sizeVar>
using Buffer = struct Buffer<sizeVar, DNAE>;
using Buffer = struct Athena::io::Buffer<sizeVar, DNAE>;
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>
using WString = struct WString<sizeVar, VE>;
using WString = struct Athena::io::WString<sizeVar, VE>;
template <atInt32 sizeVar = -1>
using WStringAsString = struct WStringAsString<sizeVar, DNAE>;
using WStringAsString = struct Athena::io::WStringAsString<sizeVar, DNAE>;
template <off_t offset, SeekOrigin direction>
struct Seek {};

View File

@ -14,6 +14,9 @@ class FileReader : public IStreamReader
{
public:
FileReader(const std::string& filename, atInt32 cacheSize = (32 * 1024));
#if _WIN32
FileReader(const std::wstring& filename, atInt32 cacheSize = (32 * 1024));
#endif
virtual ~FileReader();
inline const std::string& filename() const
{return m_filename;}
@ -31,6 +34,9 @@ public:
void setCacheSize(const atInt32 blockSize);
protected:
std::string m_filename;
#if _WIN32
std::wstring m_wfilename;
#endif
FILE* m_fileHandle;
std::unique_ptr<atUint8[]> m_cacheData;
atInt32 m_blockSize;

View File

@ -12,6 +12,9 @@ class FileWriter : public IStreamWriter
{
public:
FileWriter(const std::string& filename, bool overwrite = true);
#if _WIN32
FileWriter(const std::wstring& filename, bool overwrite = true);
#endif
virtual ~FileWriter();
void open(bool overwrite = true);
@ -25,6 +28,9 @@ public:
private:
std::string m_filename;
#if _WIN32
std::wstring m_wfilename;
#endif
FILE* m_fileHandle;
atUint8 m_currentByte;
atUint64 m_bytePosition;

View File

@ -97,7 +97,7 @@ atInt32 decompressLZO(const atUint8* source, const atInt32 sourceSize, atUint8*
int srcSize = sourceSize;
lzo_uint size = dstSize;
int result = lzo1x_decompress_safe(source, srcSize, dst, &size, NULL);
dstSize -= size;
dstSize -= (atInt32)size;
return result;
}

View File

@ -20,6 +20,18 @@ FileReader::FileReader(const std::string& filename, atInt32 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()
{
if (isOpen())
@ -28,7 +40,14 @@ FileReader::~FileReader()
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");
#else
m_fileHandle = fopen(m_filename.c_str(), "rb");
#endif
if (!m_fileHandle)
{
@ -85,7 +104,7 @@ void FileReader::seek(atInt64 pos, SeekOrigin origin)
{
fseeko64(m_fileHandle, block * m_blockSize, SEEK_SET);
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)
@ -142,7 +161,7 @@ atUint64 FileReader::readUBytesToBuf(void* buf, atUint64 len)
{
fseeko64(m_fileHandle, block * m_blockSize, SEEK_SET);
fread(m_cacheData.get(), 1, m_blockSize, m_fileHandle);
m_curBlock = block;
m_curBlock = (atInt32)block;
}
cacheSize = rem;
@ -165,7 +184,7 @@ void FileReader::setCacheSize(const atInt32 blockSize)
m_blockSize = blockSize;
if (m_blockSize > length())
m_blockSize = length();
m_blockSize = (atInt32)length();
m_curBlock = -1;
if (m_blockSize > 0)

View File

@ -18,6 +18,16 @@ FileWriter::FileWriter(const std::string& filename, bool 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()
{
if (isOpen())
@ -26,10 +36,29 @@ FileWriter::~FileWriter()
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)
m_fileHandle = fopen(m_filename.c_str(), "w+b");
else
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");
m_fileHandle = fopen(m_filename.c_str(), "r+b");
#endif
if (!m_fileHandle)
{