Compare commits

..

No commits in common. "25ff91d4c9a743f2c37e6e08b9c6ac2920bb02ab" and "ad59d9149e2578397f60e262fec90280936dd5d9" have entirely different histories.

2 changed files with 39 additions and 32 deletions

View File

@ -17,23 +17,17 @@ using namespace Qtk;
QtkIOStream::QtkIOStream(const char * pFile, const char * pMode) : QtkIOStream::QtkIOStream(const char * pFile, const char * pMode) :
mFile(pFile) { mFile(pFile) {
QString mode(pMode); QString mode(pMode);
bool open = false; bool read = mode.contains('r');
if(mode == "w" || mode == "wb") { bool write = mode.contains('w');
open = mFile.open(QIODeviceBase::WriteOnly); if(read && write) {
} else if(mode == "r" || mode == "rb") { mFile.open(QIODevice::ReadWrite);
open = mFile.open(QIODeviceBase::ReadOnly); } else if(read) {
} else if(mode == "wt") { mFile.open(QIODevice::ReadOnly);
open = mFile.open(QIODeviceBase::WriteOnly | QIODeviceBase::Text); } else if(write) {
} else if(mode == "rt") { mFile.open(QIODevice::WriteOnly);
open = mFile.open(QIODeviceBase::ReadOnly | QIODeviceBase::Text);
} else { } else {
open = false;
qDebug() << "[Qtk::QtkIOStream] Invalid file open mode: " << mode << "\n"; qDebug() << "[Qtk::QtkIOStream] Invalid file open mode: " << mode << "\n";
} }
if(!open) {
qDebug() << "[Qtk::QtkIOStream] Could not open file: " << QString(pFile)
<< "\n";
}
} }
/******************************************************************************* /*******************************************************************************
@ -41,24 +35,34 @@ QtkIOStream::QtkIOStream(const char * pFile, const char * pMode) :
******************************************************************************/ ******************************************************************************/
size_t QtkIOStream::Read(void * pvBuffer, size_t pSize, size_t pCount) { size_t QtkIOStream::Read(void * pvBuffer, size_t pSize, size_t pCount) {
qint64 readSize = mFile.read((char *)pvBuffer, pSize * pCount); size_t read = 0;
if(readSize < 0) { do {
qDebug() << "[Qtk::QtkIOStream] Failed to read (" << pSize auto readSize = mFile.read((char *)pvBuffer + read, pSize);
<< ") bytes from file at: " << mFile.filesystemFileName().c_str() if(readSize < 0) {
<< "\n"; qDebug() << "[Qtk::QtkIOStream] Failed to read (" << pSize
return -1; << ") bytes from file at: " << mFile.filesystemFileName().c_str()
} << "\n";
return readSize; return -1;
}
read += readSize;
} while(pCount--);
return read;
} }
size_t QtkIOStream::Write(const 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); size_t wrote = 0;
if(writeSize < 0) { do {
qDebug() << "[Qtk::QtkIOStream] Failed to write buffer with size (" << pSize auto writeSize = mFile.write((char *)pvBuffer + wrote, pSize);
<< ") to file at: " << mFile.filesystemFileName().c_str() << "\n"; if(writeSize < 0) {
return -1; qDebug() << "[Qtk::QtkIOStream] Failed to write buffer with size ("
} << pSize
return writeSize; << ") to file at: " << mFile.filesystemFileName().c_str()
<< "\n";
return -1;
}
wrote += writeSize;
} while(pCount--);
return wrote;
} }
aiReturn QtkIOStream::Seek(size_t pOffset, aiOrigin pOrigin) { aiReturn QtkIOStream::Seek(size_t pOffset, aiOrigin pOrigin) {

View File

@ -7,7 +7,6 @@
##############################################################################*/ ##############################################################################*/
#include "qtkiosystem.h" #include "qtkiosystem.h"
#include <QDir>
using namespace Qtk; using namespace Qtk;
@ -20,11 +19,15 @@ bool QtkIOSystem::Exists(const char * pFile) const {
} }
char QtkIOSystem::getOsSeparator() const { char QtkIOSystem::getOsSeparator() const {
return QDir::separator().toLatin1(); #ifndef _WIN32
return '/';
#else
return '\\';
#endif
} }
Assimp::IOStream * QtkIOSystem::Open(const char * pFile, const char * pMode) { Assimp::IOStream * QtkIOSystem::Open(const char * pFile, const char * pMode) {
if(!Exists(pFile)) { if(!QFileInfo::exists(pFile)) {
qDebug() << "[Qtk::QtkIOSystem] failed to open file: " << pFile << "\n"; qDebug() << "[Qtk::QtkIOSystem] failed to open file: " << pFile << "\n";
return nullptr; return nullptr;
} }