all repos — mgba @ 879d6983d180e597c06c1a46c528138328b47646

mGBA Game Boy Advance Emulator

src/platform/qt/VFileDevice.cpp (view raw)

 1/* Copyright (c) 2013-2014 Jeffrey Pfau
 2 *
 3 * This Source Code Form is subject to the terms of the Mozilla Public
 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 6#include "VFileDevice.h"
 7
 8#include <mgba-util/vfs.h>
 9
10using namespace QGBA;
11
12VFileDevice::VFileDevice(VFile* vf, QObject* parent)
13	: QIODevice(parent)
14	, m_vf(vf)
15{
16	// TODO: Correct mode
17	if (vf) {
18		setOpenMode(QIODevice::ReadWrite);
19	}
20}
21
22void VFileDevice::close() {
23	if (!m_vf) {
24		return;
25	}
26	QIODevice::close();
27	m_vf->close(m_vf);
28	m_vf = nullptr;
29}
30
31bool VFileDevice::resize(qint64 sz) {
32	m_vf->truncate(m_vf, sz);
33	return true;
34}
35
36bool VFileDevice::seek(qint64 pos) {
37	QIODevice::seek(pos);
38	return m_vf->seek(m_vf, pos, SEEK_SET) == pos;
39}
40
41VFileDevice& VFileDevice::operator=(VFile* vf) {
42	close();
43	m_vf = vf;
44	setOpenMode(QIODevice::ReadWrite);
45	return *this;
46}
47
48qint64 VFileDevice::readData(char* data, qint64 maxSize) {
49	return m_vf->read(m_vf, data, maxSize);
50}
51
52qint64 VFileDevice::writeData(const char* data, qint64 maxSize) {
53	return m_vf->write(m_vf, data, maxSize);
54}
55
56qint64 VFileDevice::size() const {
57	return m_vf->size(m_vf);
58}
59
60VFile* VFileDevice::open(const QString& path, int mode) {
61	return VFileOpen(path.toUtf8().constData(), mode);
62}
63
64VDir* VFileDevice::openDir(const QString& path) {
65	return VDirOpen(path.toUtf8().constData());
66}
67VDir* VFileDevice::openArchive(const QString& path) {
68	return VDirOpenArchive(path.toUtf8().constData());
69}