QtkIOSystem improvements
This commit is contained in:
parent
ad59d9149e
commit
d0c8316f79
|
@ -17,17 +17,23 @@ 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 read = mode.contains('r');
|
bool open = false;
|
||||||
bool write = mode.contains('w');
|
if(mode == "w" || mode == "wb") {
|
||||||
if(read && write) {
|
open = mFile.open(QIODeviceBase::WriteOnly);
|
||||||
mFile.open(QIODevice::ReadWrite);
|
} else if(mode == "r" || mode == "rb") {
|
||||||
} else if(read) {
|
open = mFile.open(QIODeviceBase::ReadOnly);
|
||||||
mFile.open(QIODevice::ReadOnly);
|
} else if(mode == "wt") {
|
||||||
} else if(write) {
|
open = mFile.open(QIODeviceBase::WriteOnly | QIODeviceBase::Text);
|
||||||
mFile.open(QIODevice::WriteOnly);
|
} else if(mode == "rt") {
|
||||||
|
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";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
|
@ -35,34 +41,24 @@ 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) {
|
||||||
size_t read = 0;
|
qint64 readSize = mFile.read((char *)pvBuffer, pSize * pCount);
|
||||||
do {
|
if(readSize < 0) {
|
||||||
auto readSize = mFile.read((char *)pvBuffer + read, pSize);
|
qDebug() << "[Qtk::QtkIOStream] Failed to read (" << pSize
|
||||||
if(readSize < 0) {
|
<< ") bytes from file at: " << mFile.filesystemFileName().c_str()
|
||||||
qDebug() << "[Qtk::QtkIOStream] Failed to read (" << pSize
|
<< "\n";
|
||||||
<< ") bytes from file at: " << mFile.filesystemFileName().c_str()
|
return -1;
|
||||||
<< "\n";
|
}
|
||||||
return -1;
|
return readSize;
|
||||||
}
|
|
||||||
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) {
|
||||||
size_t wrote = 0;
|
qint64 writeSize = mFile.write((char *)pvBuffer, pSize * pCount);
|
||||||
do {
|
if(writeSize < 0) {
|
||||||
auto writeSize = mFile.write((char *)pvBuffer + wrote, pSize);
|
qDebug() << "[Qtk::QtkIOStream] Failed to write buffer with size (" << pSize
|
||||||
if(writeSize < 0) {
|
<< ") to file at: " << mFile.filesystemFileName().c_str() << "\n";
|
||||||
qDebug() << "[Qtk::QtkIOStream] Failed to write buffer with size ("
|
return -1;
|
||||||
<< pSize
|
}
|
||||||
<< ") to file at: " << mFile.filesystemFileName().c_str()
|
return writeSize;
|
||||||
<< "\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) {
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
##############################################################################*/
|
##############################################################################*/
|
||||||
|
|
||||||
#include "qtkiosystem.h"
|
#include "qtkiosystem.h"
|
||||||
|
#include <QDir>
|
||||||
|
|
||||||
using namespace Qtk;
|
using namespace Qtk;
|
||||||
|
|
||||||
|
@ -19,15 +20,11 @@ bool QtkIOSystem::Exists(const char * pFile) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
char QtkIOSystem::getOsSeparator() const {
|
char QtkIOSystem::getOsSeparator() const {
|
||||||
#ifndef _WIN32
|
return QDir::separator().toLatin1();
|
||||||
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(!QFileInfo::exists(pFile)) {
|
if(!Exists(pFile)) {
|
||||||
qDebug() << "[Qtk::QtkIOSystem] failed to open file: " << pFile << "\n";
|
qDebug() << "[Qtk::QtkIOSystem] failed to open file: " << pFile << "\n";
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue