Fix stand alone compiling, minor code updates

This commit is contained in:
Phillip Stephens 2019-12-08 13:32:50 -08:00
parent 9771af88ed
commit eb41d349dc
Signed by: Antidote
GPG Key ID: F8BEE4C83DACA60D
6 changed files with 27 additions and 27 deletions

View File

@ -215,7 +215,7 @@ endforeach()
# Define installs # Define installs
install(DIRECTORY include DESTINATION ${INSTALL_INCLUDE_DIR}/athena COMPONENT athena) install(DIRECTORY include DESTINATION ${INSTALL_INCLUDE_DIR}/athena COMPONENT athena)
install(DIRECTORY extern/fmt/include DESTINATION ${INSTALL_INCLUDE_DIR}/fmt COMPONENT athena) install(DIRECTORY extern/fmt/include DESTINATION ${INSTALL_INCLUDE_DIR}/fmt COMPONENT athena)
install(TARGETS athena-core install(TARGETS athena-core fmt
DESTINATION ${INSTALL_LIB_DIR} EXPORT AthenaTargets COMPONENT athena) DESTINATION ${INSTALL_LIB_DIR} EXPORT AthenaTargets COMPONENT athena)
if(WIN32 AND NOT CYGWIN) if(WIN32 AND NOT CYGWIN)
install(FILES Athena.ico DESTINATION ${INSTALL_LIB_DIR} COMPONENT athena) install(FILES Athena.ico DESTINATION ${INSTALL_LIB_DIR} COMPONENT athena)

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#if _WIN32 #ifdef _WIN32
#ifndef WIN32_LEAN_AND_MEAN #ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
#endif #endif
@ -20,14 +20,14 @@ public:
~FileWriter() override; ~FileWriter() override;
std::string filename() const { std::string filename() const {
#if _WIN32 #ifdef _WIN32
return utility::wideToUtf8(m_filename); return utility::wideToUtf8(m_filename);
#else #else
return m_filename; return m_filename;
#endif #endif
} }
std::wstring wfilename() const { std::wstring wfilename() const {
#if _WIN32 #ifdef _WIN32
return m_filename; return m_filename;
#else #else
return utility::utf8ToWide(m_filename); return utility::utf8ToWide(m_filename);
@ -36,13 +36,13 @@ public:
void open(bool overwrite = true); void open(bool overwrite = true);
void close(); void close();
bool isOpen() const { return m_fileHandle != 0; } bool isOpen() const { return m_fileHandle != nullptr; }
void seek(atInt64 pos, SeekOrigin origin = SeekOrigin::Current) override; void seek(atInt64 pos, SeekOrigin origin = SeekOrigin::Current) override;
atUint64 position() const override; atUint64 position() const override;
atUint64 length() const override; atUint64 length() const override;
void writeUBytes(const atUint8* data, atUint64 len) override; void writeUBytes(const atUint8* data, atUint64 len) override;
#if _WIN32 #ifdef _WIN32
using HandleType = HANDLE; using HandleType = HANDLE;
#else #else
using HandleType = FILE*; using HandleType = FILE*;
@ -51,7 +51,7 @@ public:
HandleType _fileHandle() { return m_fileHandle; } HandleType _fileHandle() { return m_fileHandle; }
private: private:
#if _WIN32 #ifdef _WIN32
std::wstring m_filename; std::wstring m_filename;
#else #else
std::string m_filename; std::string m_filename;
@ -61,7 +61,7 @@ private:
}; };
class TransactionalFileWriter : public IStreamWriter { class TransactionalFileWriter : public IStreamWriter {
#if _WIN32 #ifdef _WIN32
std::wstring m_filename; std::wstring m_filename;
#else #else
std::string m_filename; std::string m_filename;
@ -73,7 +73,7 @@ class TransactionalFileWriter : public IStreamWriter {
public: public:
explicit TransactionalFileWriter(std::string_view filename, bool overwrite = true, bool globalErr = true) explicit TransactionalFileWriter(std::string_view filename, bool overwrite = true, bool globalErr = true)
: m_overwrite(overwrite), m_globalErr(globalErr) { : m_overwrite(overwrite), m_globalErr(globalErr) {
#if _WIN32 #ifdef _WIN32
m_filename = utility::utf8ToWide(filename); m_filename = utility::utf8ToWide(filename);
#else #else
m_filename = filename; m_filename = filename;
@ -81,7 +81,7 @@ public:
} }
explicit TransactionalFileWriter(std::wstring_view filename, bool overwrite = true, bool globalErr = true) explicit TransactionalFileWriter(std::wstring_view filename, bool overwrite = true, bool globalErr = true)
: m_overwrite(overwrite), m_globalErr(globalErr) { : m_overwrite(overwrite), m_globalErr(globalErr) {
#if _WIN32 #ifdef _WIN32
m_filename = filename; m_filename = filename;
#else #else
m_filename = utility::wideToUtf8(filename); m_filename = utility::wideToUtf8(filename);

View File

@ -43,7 +43,7 @@ public:
/*! @brief Writes the given buffer with the specified length, buffers can be bigger than the length /*! @brief Writes the given buffer with the specified length, buffers can be bigger than the length
* however it's undefined behavior to try and write a buffer which is smaller than the given length. * however it's undefined behavior to try and write a buffer which is smaller than the given length.
* If you are needing to fill in an area please use IStreamWriter::fill(atUint64) instead. * If you are needing to fill in an area please use @sa IStreamWriter::fill(atUint64) instead.
* *
* @param data The buffer to write * @param data The buffer to write
* @param length The amount to write * @param length The amount to write

View File

@ -85,7 +85,7 @@ void FileReader::seek(atInt64 pos, SeekOrigin origin) {
fread(m_cacheData.get(), 1, m_blockSize, m_fileHandle); fread(m_cacheData.get(), 1, m_blockSize, m_fileHandle);
m_curBlock = atInt32(block); m_curBlock = atInt32(block);
} }
} else if (fseeko64(m_fileHandle, pos, (int)origin) != 0) { } else if (fseeko64(m_fileHandle, pos, int(origin)) != 0) {
if (m_globalErr) if (m_globalErr)
atError(fmt("Unable to seek in file")); atError(fmt("Unable to seek in file"));
setError(); setError();
@ -102,7 +102,7 @@ atUint64 FileReader::position() const {
if (m_blockSize > 0) if (m_blockSize > 0)
return m_offset; return m_offset;
else else
return ftello64(m_fileHandle); return atUint64(ftello64(m_fileHandle));
} }
atUint64 FileReader::length() const { atUint64 FileReader::length() const {
@ -156,7 +156,7 @@ atUint64 FileReader::readUBytesToBuf(void* buf, atUint64 len) {
++block; ++block;
} }
m_offset += len; m_offset += len;
return dst - (atUint8*)buf; return atUint64(dst - reinterpret_cast<atUint8*>(buf));
} }
} }

View File

@ -1,8 +1,8 @@
#include "athena/FileWriter.hpp" #include "athena/FileWriter.hpp"
#if __APPLE__ || __FreeBSD__ #if defined(__APPLE__) || defined(__FreeBSD__)
#include "osx_largefilewrapper.h" #include "osx_largefilewrapper.h"
#elif GEKKO || __SWITCH__ #elif defined(GEKKO) || defined(__SWITCH__)
#include "gekko_support.h" #include "gekko_support.h"
#include "osx_largefilewrapper.h" #include "osx_largefilewrapper.h"
#endif #endif
@ -11,8 +11,8 @@
namespace athena::io { namespace athena::io {
FileWriter::FileWriter(std::string_view filename, bool overwrite, bool globalErr) FileWriter::FileWriter(std::string_view filename, bool overwrite, bool globalErr)
: m_fileHandle(NULL), m_globalErr(globalErr) { : m_fileHandle(nullptr), m_globalErr(globalErr) {
#if _WIN32 #ifdef _WIN32
m_filename = utility::utf8ToWide(filename); m_filename = utility::utf8ToWide(filename);
#else #else
m_filename = filename; m_filename = filename;
@ -21,8 +21,8 @@ FileWriter::FileWriter(std::string_view filename, bool overwrite, bool globalErr
} }
FileWriter::FileWriter(std::wstring_view filename, bool overwrite, bool globalErr) FileWriter::FileWriter(std::wstring_view filename, bool overwrite, bool globalErr)
: m_fileHandle(NULL), m_globalErr(globalErr) { : m_fileHandle(nullptr), m_globalErr(globalErr) {
#if _WIN32 #ifdef _WIN32
m_filename = filename; m_filename = filename;
#else #else
m_filename = utility::wideToUtf8(filename); m_filename = utility::wideToUtf8(filename);
@ -67,7 +67,7 @@ void FileWriter::close() {
} }
fclose(m_fileHandle); fclose(m_fileHandle);
m_fileHandle = NULL; m_fileHandle = nullptr;
std::string tmpFilename = m_filename + '~'; std::string tmpFilename = m_filename + '~';
#ifdef __SWITCH__ #ifdef __SWITCH__
@ -86,14 +86,14 @@ void FileWriter::seek(atInt64 pos, SeekOrigin origin) {
return; return;
} }
if (fseeko64(m_fileHandle, pos, (int)origin) != 0) { if (fseeko64(m_fileHandle, pos, int(origin)) != 0) {
if (m_globalErr) if (m_globalErr)
atError(fmt("Unable to seek in file")); atError(fmt("Unable to seek in file"));
setError(); setError();
} }
} }
atUint64 FileWriter::position() const { return ftello64(m_fileHandle); } atUint64 FileWriter::position() const { return atUint64(ftello64(m_fileHandle)); }
atUint64 FileWriter::length() const { return utility::fileSize(m_filename); } atUint64 FileWriter::length() const { return utility::fileSize(m_filename); }

View File

@ -40,7 +40,7 @@ MemoryCopyReader::MemoryCopyReader(const void* data, atUint64 length) : MemoryRe
void MemoryReader::seek(atInt64 position, SeekOrigin origin) { void MemoryReader::seek(atInt64 position, SeekOrigin origin) {
switch (origin) { switch (origin) {
case SeekOrigin::Begin: case SeekOrigin::Begin:
if ((position < 0 || (atInt64)position > (atInt64)m_length)) { if ((position < 0 || atInt64(position) > atInt64(m_length))) {
if (m_globalErr) if (m_globalErr)
atFatal(fmt("Position {:08X} outside stream bounds "), position); atFatal(fmt("Position {:08X} outside stream bounds "), position);
m_position = m_length; m_position = m_length;
@ -48,14 +48,14 @@ void MemoryReader::seek(atInt64 position, SeekOrigin origin) {
return; return;
} }
m_position = position; m_position = atUint64(position);
break; break;
case SeekOrigin::Current: case SeekOrigin::Current:
if ((((atInt64)m_position + position) < 0 || (m_position + position) > m_length)) { if (((atInt64(m_position) + position) < 0 || (m_position + atUint64(position)) > m_length)) {
if (m_globalErr) if (m_globalErr)
atFatal(fmt("Position {:08X} outside stream bounds "), position); atFatal(fmt("Position {:08X} outside stream bounds "), position);
m_position = m_length; m_position = (position < 0 ? 0 ? m_length;
setError(); setError();
return; return;
} }