diff --git a/CMakeLists.txt b/CMakeLists.txt index f58d817..4fb4d38 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) @@ -114,7 +116,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 diff --git a/include/Athena/DNA.hpp b/include/Athena/DNA.hpp index f4479e6..0cc0f7c 100644 --- a/include/Athena/DNA.hpp +++ b/include/Athena/DNA.hpp @@ -53,16 +53,16 @@ struct DNA using Vector = std::vector; template - using Buffer = struct Buffer; + using Buffer = struct Athena::io::Buffer; template - using String = struct String; + using String = struct Athena::io::String; template - using WString = struct WString; + using WString = struct Athena::io::WString; template - using WStringAsString = struct WStringAsString; + using WStringAsString = struct Athena::io::WStringAsString; template struct Seek {}; diff --git a/include/Athena/FileReader.hpp b/include/Athena/FileReader.hpp index e3acec0..461c1c2 100644 --- a/include/Athena/FileReader.hpp +++ b/include/Athena/FileReader.hpp @@ -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 m_cacheData; atInt32 m_blockSize; diff --git a/include/Athena/FileWriter.hpp b/include/Athena/FileWriter.hpp index 04faceb..e09c2fb 100644 --- a/include/Athena/FileWriter.hpp +++ b/include/Athena/FileWriter.hpp @@ -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; diff --git a/src/Athena/Compression.cpp b/src/Athena/Compression.cpp index 21885c9..c28b7dd 100644 --- a/src/Athena/Compression.cpp +++ b/src/Athena/Compression.cpp @@ -98,7 +98,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; } diff --git a/src/Athena/FileReader.cpp b/src/Athena/FileReader.cpp index 4a803e8..361d8df 100644 --- a/src/Athena/FileReader.cpp +++ b/src/Athena/FileReader.cpp @@ -24,6 +24,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()) @@ -32,7 +44,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) THROW_FILE_NOT_FOUND_EXCEPTION(m_filename); @@ -80,7 +99,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) @@ -127,7 +146,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; @@ -150,7 +169,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) diff --git a/src/Athena/FileWriter.cpp b/src/Athena/FileWriter.cpp index 50ace89..7fca42d 100644 --- a/src/Athena/FileWriter.cpp +++ b/src/Athena/FileWriter.cpp @@ -22,6 +22,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()) @@ -30,10 +40,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) THROW_FILE_NOT_FOUND_EXCEPTION(m_filename);