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
install(DIRECTORY include DESTINATION ${INSTALL_INCLUDE_DIR}/athena 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)
if(WIN32 AND NOT CYGWIN)
install(FILES Athena.ico DESTINATION ${INSTALL_LIB_DIR} COMPONENT athena)

View File

@ -1,6 +1,6 @@
#pragma once
#if _WIN32
#ifdef _WIN32
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
@ -20,14 +20,14 @@ public:
~FileWriter() override;
std::string filename() const {
#if _WIN32
#ifdef _WIN32
return utility::wideToUtf8(m_filename);
#else
return m_filename;
#endif
}
std::wstring wfilename() const {
#if _WIN32
#ifdef _WIN32
return m_filename;
#else
return utility::utf8ToWide(m_filename);
@ -36,13 +36,13 @@ public:
void open(bool overwrite = true);
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;
atUint64 position() const override;
atUint64 length() const override;
void writeUBytes(const atUint8* data, atUint64 len) override;
#if _WIN32
#ifdef _WIN32
using HandleType = HANDLE;
#else
using HandleType = FILE*;
@ -51,7 +51,7 @@ public:
HandleType _fileHandle() { return m_fileHandle; }
private:
#if _WIN32
#ifdef _WIN32
std::wstring m_filename;
#else
std::string m_filename;
@ -61,7 +61,7 @@ private:
};
class TransactionalFileWriter : public IStreamWriter {
#if _WIN32
#ifdef _WIN32
std::wstring m_filename;
#else
std::string m_filename;
@ -73,7 +73,7 @@ class TransactionalFileWriter : public IStreamWriter {
public:
explicit TransactionalFileWriter(std::string_view filename, bool overwrite = true, bool globalErr = true)
: m_overwrite(overwrite), m_globalErr(globalErr) {
#if _WIN32
#ifdef _WIN32
m_filename = utility::utf8ToWide(filename);
#else
m_filename = filename;
@ -81,7 +81,7 @@ public:
}
explicit TransactionalFileWriter(std::wstring_view filename, bool overwrite = true, bool globalErr = true)
: m_overwrite(overwrite), m_globalErr(globalErr) {
#if _WIN32
#ifdef _WIN32
m_filename = filename;
#else
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
* 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 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);
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)
atError(fmt("Unable to seek in file"));
setError();
@ -102,7 +102,7 @@ atUint64 FileReader::position() const {
if (m_blockSize > 0)
return m_offset;
else
return ftello64(m_fileHandle);
return atUint64(ftello64(m_fileHandle));
}
atUint64 FileReader::length() const {
@ -156,7 +156,7 @@ atUint64 FileReader::readUBytesToBuf(void* buf, atUint64 len) {
++block;
}
m_offset += len;
return dst - (atUint8*)buf;
return atUint64(dst - reinterpret_cast<atUint8*>(buf));
}
}

View File

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

View File

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