Qt: Unified VFile opening interface

This commit is contained in:
Jeffrey Pfau 2015-05-29 00:16:42 -07:00
parent 3c65ac986e
commit 87313041c0
5 changed files with 21 additions and 13 deletions

View File

@ -5,12 +5,13 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "CheatsModel.h"
#include "VFileDevice.h"
#include <QFont>
#include <QSet>
extern "C" {
#include "gba/cheats.h"
#include "util/vfs.h"
}
using namespace QGBA;
@ -201,7 +202,7 @@ void CheatsModel::endAppendRow() {
}
void CheatsModel::loadFile(const QString& path) {
VFile* vf = VFileOpen(path.toLocal8Bit().constData(), O_RDONLY);
VFile* vf = VFileDevice::open(path, O_RDONLY);
if (!vf) {
return;
}
@ -212,7 +213,7 @@ void CheatsModel::loadFile(const QString& path) {
}
void CheatsModel::saveFile(const QString& path) {
VFile* vf = VFileOpen(path.toLocal8Bit().constData(), O_TRUNC | O_CREAT | O_WRONLY);
VFile* vf = VFileDevice::open(path, O_TRUNC | O_CREAT | O_WRONLY);
if (!vf) {
return;
}

View File

@ -8,6 +8,7 @@
#include "AudioProcessor.h"
#include "InputController.h"
#include "MultiplayerController.h"
#include "VFileDevice.h"
#include <QDateTime>
#include <QThread>
@ -280,13 +281,13 @@ void GameController::openGame() {
}
if (!m_bios.isNull() &&m_useBios) {
m_threadContext.bios = VFileOpen(m_bios.toLocal8Bit().constData(), O_RDONLY);
m_threadContext.bios = VFileDevice::open(m_bios, O_RDONLY);
} else {
m_threadContext.bios = nullptr;
}
if (!m_patch.isNull()) {
m_threadContext.patch = VFileOpen(m_patch.toLocal8Bit().constData(), O_RDONLY);
m_threadContext.patch = VFileDevice::open(m_patch, O_RDONLY);
}
m_inputController->recalibrateAxes();
@ -322,7 +323,7 @@ void GameController::importSharkport(const QString& path) {
if (!m_gameOpen) {
return;
}
VFile* vf = VFileOpen(path.toLocal8Bit().constData(), O_RDONLY);
VFile* vf = VFileDevice::open(path, O_RDONLY);
if (!vf) {
return;
}
@ -336,7 +337,7 @@ void GameController::exportSharkport(const QString& path) {
if (!m_gameOpen) {
return;
}
VFile* vf = VFileOpen(path.toLocal8Bit().constData(), O_WRONLY | O_CREAT | O_TRUNC);
VFile* vf = VFileDevice::open(path, O_WRONLY | O_CREAT | O_TRUNC);
if (!vf) {
return;
}

View File

@ -5,6 +5,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "PaletteView.h"
#include "VFileDevice.h"
#include <QFileDialog>
#include <QFontDatabase>
@ -86,7 +88,7 @@ void PaletteView::exportPalette(int start, int length) {
m_controller->threadContinue();
return;
}
VFile* vf = VFileOpen(filename.toLocal8Bit().constData(), O_WRONLY | O_CREAT | O_TRUNC);
VFile* vf = VFileDevice::open(filename, O_WRONLY | O_CREAT | O_TRUNC);
if (!vf) {
m_controller->threadContinue();
return;

View File

@ -5,10 +5,6 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "VFileDevice.h"
extern "C" {
#include "util/vfs.h"
}
using namespace QGBA;
VFileDevice::VFileDevice(VFile* vf, QObject* parent)
@ -29,3 +25,7 @@ qint64 VFileDevice::writeData(const char* data, qint64 maxSize) {
qint64 VFileDevice::size() const {
return m_vf->size(m_vf);
}
VFile* VFileDevice::open(QString path, int mode) {
return VFileOpen(path.toLocal8Bit().constData(), mode);
}

View File

@ -8,7 +8,9 @@
#include <QFileDevice>
struct VFile;
extern "C" {
#include "util/vfs.h"
}
namespace QGBA {
@ -18,6 +20,8 @@ Q_OBJECT
public:
VFileDevice(VFile* vf, QObject* parent = nullptr);
static VFile* open(QString path, int mode);
protected:
virtual qint64 readData(char* data, qint64 maxSize) override;
virtual qint64 writeData(const char* data, qint64 maxSize) override;