From f2350d97390e342599927a5930834e4e690e97e8 Mon Sep 17 00:00:00 2001 From: Transporter Date: Sun, 21 Jan 2024 20:25:01 +0100 Subject: [PATCH 1/3] Improve seperator function --- src/qtk/qtkiosystem.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/qtk/qtkiosystem.cpp b/src/qtk/qtkiosystem.cpp index 342d9f3..2d3bd31 100644 --- a/src/qtk/qtkiosystem.cpp +++ b/src/qtk/qtkiosystem.cpp @@ -7,6 +7,7 @@ ##############################################################################*/ #include "qtkiosystem.h" +#include using namespace Qtk; @@ -19,15 +20,11 @@ bool QtkIOSystem::Exists(const char * pFile) const { } char QtkIOSystem::getOsSeparator() const { -#ifndef _WIN32 - return '/'; -#else - return '\\'; -#endif + return QDir::separator().toLatin1(); } Assimp::IOStream * QtkIOSystem::Open(const char * pFile, const char * pMode) { - if(!QFileInfo::exists(pFile)) { + if(!Exists(pFile)) { qDebug() << "[Qtk::QtkIOSystem] failed to open file: " << pFile << "\n"; return nullptr; } From d6b17cdf874deb6995abd72821d68071f361dc6a Mon Sep 17 00:00:00 2001 From: Transporter Date: Sun, 21 Jan 2024 20:35:53 +0100 Subject: [PATCH 2/3] Fix open IOStream (required modes are: "wb", "w", "wt", "rb", "r", "rt") and improve read and write --- src/qtk/qtkiostream.cpp | 63 ++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 33 deletions(-) diff --git a/src/qtk/qtkiostream.cpp b/src/qtk/qtkiostream.cpp index de79a2d..c1ad537 100644 --- a/src/qtk/qtkiostream.cpp +++ b/src/qtk/qtkiostream.cpp @@ -17,17 +17,22 @@ using namespace Qtk; QtkIOStream::QtkIOStream(const char * pFile, const char * pMode) : mFile(pFile) { QString mode(pMode); - bool read = mode.contains('r'); - bool write = mode.contains('w'); - if(read && write) { - mFile.open(QIODevice::ReadWrite); - } else if(read) { - mFile.open(QIODevice::ReadOnly); - } else if(write) { - mFile.open(QIODevice::WriteOnly); + bool open = false; + if (mode == "w" || mode == "wb") { + open = mFile.open(QIODeviceBase::WriteOnly); + } else if (mode == "r" || mode == "rb") { + open = mFile.open(QIODeviceBase::ReadOnly); + } else if (mode == "wt") { + open = mFile.open(QIODeviceBase::WriteOnly | QIODeviceBase::Text); + } else if (mode == "rt") { + open = mFile.open(QIODeviceBase::ReadOnly | QIODeviceBase::Text); } else { + open = false; qDebug() << "[Qtk::QtkIOStream] Invalid file open mode: " << mode << "\n"; } + if(!open) { + qDebug() << "[Qtk::QtkIOStream] Could not open file: " << QString(pFile) << "\n"; + } } /******************************************************************************* @@ -35,34 +40,26 @@ QtkIOStream::QtkIOStream(const char * pFile, const char * pMode) : ******************************************************************************/ size_t QtkIOStream::Read(void * pvBuffer, size_t pSize, size_t pCount) { - size_t read = 0; - do { - auto readSize = mFile.read((char *)pvBuffer + read, pSize); - if(readSize < 0) { - qDebug() << "[Qtk::QtkIOStream] Failed to read (" << pSize - << ") bytes from file at: " << mFile.filesystemFileName().c_str() - << "\n"; - return -1; - } - read += readSize; - } while(pCount--); - return read; + qint64 readSize = mFile.read((char*)pvBuffer, pSize * pCount); + if(readSize < 0) { + qDebug() << "[Qtk::QtkIOStream] Failed to read (" << pSize + << ") bytes from file at: " << mFile.filesystemFileName().c_str() + << "\n"; + return -1; + } + return readSize; } size_t QtkIOStream::Write(const void * pvBuffer, size_t pSize, size_t pCount) { - size_t wrote = 0; - do { - auto writeSize = mFile.write((char *)pvBuffer + wrote, pSize); - if(writeSize < 0) { - qDebug() << "[Qtk::QtkIOStream] Failed to write buffer with size (" - << pSize - << ") to file at: " << mFile.filesystemFileName().c_str() - << "\n"; - return -1; - } - wrote += writeSize; - } while(pCount--); - return wrote; + qint64 writeSize = mFile.write((char*)pvBuffer, pSize * pCount); + if(writeSize < 0) { + qDebug() << "[Qtk::QtkIOStream] Failed to write buffer with size (" + << pSize + << ") to file at: " << mFile.filesystemFileName().c_str() + << "\n"; + return -1; + } + return writeSize; } aiReturn QtkIOStream::Seek(size_t pOffset, aiOrigin pOrigin) { From 1c6a3ffcc702f709813022255183ee0a5da09efc Mon Sep 17 00:00:00 2001 From: Shaun Reed Date: Wed, 24 Jan 2024 23:25:14 -0500 Subject: [PATCH 3/3] clang-format --- src/qtk/qtkiostream.cpp | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/qtk/qtkiostream.cpp b/src/qtk/qtkiostream.cpp index c1ad537..b4844eb 100644 --- a/src/qtk/qtkiostream.cpp +++ b/src/qtk/qtkiostream.cpp @@ -18,20 +18,21 @@ QtkIOStream::QtkIOStream(const char * pFile, const char * pMode) : mFile(pFile) { QString mode(pMode); bool open = false; - if (mode == "w" || mode == "wb") { + if(mode == "w" || mode == "wb") { open = mFile.open(QIODeviceBase::WriteOnly); - } else if (mode == "r" || mode == "rb") { + } else if(mode == "r" || mode == "rb") { open = mFile.open(QIODeviceBase::ReadOnly); - } else if (mode == "wt") { + } else if(mode == "wt") { open = mFile.open(QIODeviceBase::WriteOnly | QIODeviceBase::Text); - } else if (mode == "rt") { + } else if(mode == "rt") { open = mFile.open(QIODeviceBase::ReadOnly | QIODeviceBase::Text); } else { open = false; qDebug() << "[Qtk::QtkIOStream] Invalid file open mode: " << mode << "\n"; } if(!open) { - qDebug() << "[Qtk::QtkIOStream] Could not open file: " << QString(pFile) << "\n"; + qDebug() << "[Qtk::QtkIOStream] Could not open file: " << QString(pFile) + << "\n"; } } @@ -40,7 +41,7 @@ QtkIOStream::QtkIOStream(const char * pFile, const char * pMode) : ******************************************************************************/ size_t QtkIOStream::Read(void * pvBuffer, size_t pSize, size_t pCount) { - qint64 readSize = mFile.read((char*)pvBuffer, pSize * pCount); + qint64 readSize = mFile.read((char *)pvBuffer, pSize * pCount); if(readSize < 0) { qDebug() << "[Qtk::QtkIOStream] Failed to read (" << pSize << ") bytes from file at: " << mFile.filesystemFileName().c_str() @@ -51,12 +52,10 @@ size_t QtkIOStream::Read(void * pvBuffer, size_t pSize, size_t pCount) { } size_t QtkIOStream::Write(const void * pvBuffer, size_t pSize, size_t pCount) { - qint64 writeSize = mFile.write((char*)pvBuffer, pSize * pCount); + qint64 writeSize = mFile.write((char *)pvBuffer, pSize * pCount); if(writeSize < 0) { - qDebug() << "[Qtk::QtkIOStream] Failed to write buffer with size (" - << pSize - << ") to file at: " << mFile.filesystemFileName().c_str() - << "\n"; + qDebug() << "[Qtk::QtkIOStream] Failed to write buffer with size (" << pSize + << ") to file at: " << mFile.filesystemFileName().c_str() << "\n"; return -1; } return writeSize;