Add missing nostalgia directory level in src tree
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
cmake_minimum_required(VERSION 2.8.11)
|
||||
|
||||
project(NostalgiaStudio)
|
||||
|
||||
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
|
||||
add_library(
|
||||
NostalgiaStudio
|
||||
newwizard.cpp
|
||||
oxfstreeview.cpp
|
||||
project.cpp
|
||||
)
|
||||
|
||||
set_property(
|
||||
TARGET
|
||||
NostalgiaStudio
|
||||
PROPERTY
|
||||
POSITION_INDEPENDENT_CODE ON
|
||||
)
|
||||
|
||||
target_link_libraries(
|
||||
NostalgiaStudio
|
||||
Qt5::Core
|
||||
Qt5::Widgets
|
||||
OxFS
|
||||
OxStd
|
||||
)
|
||||
|
||||
install(
|
||||
FILES
|
||||
newwizard.hpp
|
||||
oxfstreeview.hpp
|
||||
project.hpp
|
||||
DESTINATION
|
||||
include/nostalgia/studio/lib
|
||||
)
|
||||
@@ -0,0 +1,259 @@
|
||||
/*
|
||||
* Copyright 2016-2017 gtalent2@gmail.com
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#include <QFileDialog>
|
||||
#include <QHBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include <QListWidget>
|
||||
#include <QPushButton>
|
||||
#include <QVBoxLayout>
|
||||
#include "newwizard.hpp"
|
||||
|
||||
namespace nostalgia {
|
||||
namespace studio {
|
||||
|
||||
using std::function;
|
||||
|
||||
WizardSelect::WizardSelect() {
|
||||
m_listWidget = new QListWidget(this);
|
||||
auto layout = new QVBoxLayout(this);
|
||||
layout->addWidget(m_listWidget);
|
||||
setLayout(layout);
|
||||
|
||||
connect(m_listWidget, &QListWidget::currentRowChanged, this, &WizardSelect::itemSelected);
|
||||
connect(m_listWidget, &QListWidget::itemSelectionChanged, [this]() {
|
||||
m_complete = true;
|
||||
emit completeChanged();
|
||||
}
|
||||
);
|
||||
connect(m_listWidget, &QListWidget::doubleClicked, [this]() {
|
||||
wizard()->next();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void WizardSelect::initializePage() {
|
||||
emit completeChanged();
|
||||
}
|
||||
|
||||
void WizardSelect::addOption(QString name, function<QVector<QWizardPage*>()> makePage) {
|
||||
m_options[name] = makePage;
|
||||
m_listWidget->addItem(name);
|
||||
}
|
||||
|
||||
bool WizardSelect::isComplete() const {
|
||||
return m_complete;
|
||||
}
|
||||
|
||||
void WizardSelect::itemSelected(int row) {
|
||||
if (row > -1) {
|
||||
auto w = wizard();
|
||||
|
||||
if (nextId() > -1) {
|
||||
w->removePage(nextId());
|
||||
}
|
||||
|
||||
auto selected = m_listWidget->currentItem()->text();
|
||||
if (m_options.contains(selected)) {
|
||||
for (auto p : m_options[selected]()) {
|
||||
w->addPage(p);
|
||||
}
|
||||
// for some reason the continue button only appears correctly after remove runs
|
||||
w->removePage(w->addPage(new QWizardPage()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
WizardConclusionPage::WizardConclusionPage(QString msg, QVector<QString> fields) {
|
||||
m_baseMsg = msg;
|
||||
m_fields = fields;
|
||||
setLayout(new QVBoxLayout(this));
|
||||
}
|
||||
|
||||
WizardConclusionPage::~WizardConclusionPage() {
|
||||
}
|
||||
|
||||
void WizardConclusionPage::initializePage() {
|
||||
QString msg = m_baseMsg;
|
||||
for (auto field : m_fields) {
|
||||
msg = msg.arg(this->field(field).toString());
|
||||
}
|
||||
|
||||
auto text = new QLabel(msg, this);
|
||||
if (m_text) {
|
||||
layout()->replaceWidget(m_text, text);
|
||||
delete m_text;
|
||||
} else {
|
||||
layout()->addWidget(text);
|
||||
}
|
||||
m_text = text;
|
||||
}
|
||||
|
||||
|
||||
WizardFormPage::WizardFormPage() {
|
||||
m_layout = new QGridLayout(this);
|
||||
m_layout->setColumnMinimumWidth(0, 20);
|
||||
this->setLayout(m_layout);
|
||||
}
|
||||
|
||||
WizardFormPage::~WizardFormPage() {
|
||||
for (auto l : m_subLayout) {
|
||||
delete l;
|
||||
}
|
||||
}
|
||||
|
||||
void WizardFormPage::initializePage() {
|
||||
for (auto it = m_fields.begin(); it != m_fields.end(); it++) {
|
||||
auto key = it.key();
|
||||
auto le = m_fields[key].lineEdit;
|
||||
auto defaultVal = it.value().defaultValue;
|
||||
if (le) {
|
||||
le->setText(defaultVal);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool WizardFormPage::validatePage() {
|
||||
bool retval = true;
|
||||
|
||||
// check validators
|
||||
for (auto f : m_fields) {
|
||||
if (f.validator != nullptr) {
|
||||
if (f.validator(f.lineEdit->text()) != 0) {
|
||||
retval = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// clear error
|
||||
if (retval) {
|
||||
showValidationError("");
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
void WizardFormPage::addLineEdit(QString displayName, QString fieldName, QString defaultVal, function<int(QString)> validator) {
|
||||
auto lbl = new QLabel(displayName, this);
|
||||
auto le = new QLineEdit(this);
|
||||
lbl->setBuddy(le);
|
||||
|
||||
m_layout->addWidget(lbl, m_currentLine, 0);
|
||||
m_layout->addWidget(le, m_currentLine, 1);
|
||||
|
||||
auto field = &m_fields[fieldName];
|
||||
|
||||
field->defaultValue = defaultVal;
|
||||
field->lineEdit = le;
|
||||
field->validator = validator;
|
||||
|
||||
registerField(fieldName, le);
|
||||
|
||||
connect(le, &QLineEdit::textChanged, [this, fieldName, le, field](QString txt) {
|
||||
if (field->value == "" && txt != "") {
|
||||
m_validFields++;
|
||||
} else if (field->value != "" && txt == "") {
|
||||
m_validFields--;
|
||||
}
|
||||
field->value = txt;
|
||||
emit completeChanged();
|
||||
}
|
||||
);
|
||||
|
||||
m_currentLine++;
|
||||
}
|
||||
|
||||
void WizardFormPage::addDirBrowse(QString displayName, QString fieldName, QString defaultVal) {
|
||||
auto layout = new QHBoxLayout();
|
||||
auto lbl = new QLabel(displayName, this);
|
||||
auto le = new QLineEdit("", this);
|
||||
auto btn = new QPushButton("Browse...", this);
|
||||
lbl->setBuddy(le);
|
||||
|
||||
layout->addWidget(le);
|
||||
layout->addWidget(btn);
|
||||
m_layout->addWidget(lbl, m_currentLine, 0);
|
||||
m_layout->addLayout(layout, m_currentLine, 1);
|
||||
|
||||
m_subLayout.push_back(layout);
|
||||
m_fields[fieldName].defaultValue = defaultVal;
|
||||
m_fields[fieldName].lineEdit = le;
|
||||
m_fields[fieldName].validator = [this](QString path) {
|
||||
if (!QDir(path).exists()) {
|
||||
showValidationError(tr("Specified Project Path directory does not exist."));
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
registerField(fieldName, le);
|
||||
|
||||
connect(le, &QLineEdit::textChanged, [this, fieldName, le](QString txt) {
|
||||
if (m_fields[fieldName].value == "" && txt != "") {
|
||||
m_validFields++;
|
||||
} else if (m_fields[fieldName].value != "" && txt == "") {
|
||||
m_validFields--;
|
||||
}
|
||||
m_fields[fieldName].value = txt;
|
||||
emit completeChanged();
|
||||
}
|
||||
);
|
||||
|
||||
connect(btn, &QPushButton::clicked, [this, defaultVal, le]() {
|
||||
auto p = QFileDialog::getExistingDirectory(this, tr("Select Directory..."), defaultVal);
|
||||
if (p != "") {
|
||||
le->setText(p);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
m_currentLine++;
|
||||
}
|
||||
|
||||
void WizardFormPage::showValidationError(QString msg) {
|
||||
// create label if it is null
|
||||
if (!m_errorMsg) {
|
||||
m_errorMsg = new QLabel(this);
|
||||
m_layout->addWidget(m_errorMsg, m_currentLine, 0, m_currentLine, 2);
|
||||
|
||||
// set text color
|
||||
auto pal = m_errorMsg->palette();
|
||||
pal.setColor(m_errorMsg->backgroundRole(), Qt::red);
|
||||
pal.setColor(m_errorMsg->foregroundRole(), Qt::red);
|
||||
m_errorMsg->setPalette(pal);
|
||||
}
|
||||
|
||||
// set message
|
||||
if (msg != "") {
|
||||
m_errorMsg->setText(tr("Error: ") + msg);
|
||||
} else {
|
||||
m_errorMsg->setText("");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Wizard::Wizard(QWidget *parent): QWizard(parent) {
|
||||
setWindowTitle(tr("New..."));
|
||||
setModal(true);
|
||||
}
|
||||
|
||||
void Wizard::setAccept(std::function<void()> acceptFunc) {
|
||||
m_acceptFunc = acceptFunc;
|
||||
}
|
||||
|
||||
void Wizard::accept() {
|
||||
m_acceptFunc();
|
||||
QDialog::accept();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* Copyright 2016-2017 gtalent2@gmail.com
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
#include <QDir>
|
||||
#include <QGridLayout>
|
||||
#include <QLabel>
|
||||
#include <QListWidget>
|
||||
#include <QMap>
|
||||
#include <QVector>
|
||||
#include <QWizard>
|
||||
|
||||
namespace nostalgia {
|
||||
namespace studio {
|
||||
|
||||
class WizardSelect: public QWizardPage {
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
QMap<QString, std::function<QVector<QWizardPage*>()>> m_options;
|
||||
QListWidget *m_listWidget = nullptr;
|
||||
bool m_complete = false;
|
||||
|
||||
public:
|
||||
WizardSelect();
|
||||
|
||||
void addOption(QString name, std::function<QVector<QWizardPage*>()> makePage);
|
||||
|
||||
void initializePage() override;
|
||||
|
||||
bool isComplete() const override;
|
||||
|
||||
private slots:
|
||||
void itemSelected(int row);
|
||||
};
|
||||
|
||||
|
||||
class WizardFormPage: public QWizardPage {
|
||||
Q_OBJECT
|
||||
private:
|
||||
struct Field {
|
||||
QString defaultValue = "";
|
||||
QString value = "";
|
||||
QLineEdit *lineEdit = nullptr;
|
||||
std::function<int(QString)> validator;
|
||||
};
|
||||
QLabel *m_errorMsg = nullptr;
|
||||
QGridLayout *m_layout = nullptr;
|
||||
QVector<QLayout*> m_subLayout;
|
||||
QMap<QString, Field> m_fields;
|
||||
int m_currentLine = 0;
|
||||
int m_validFields = 0;
|
||||
|
||||
public:
|
||||
WizardFormPage();
|
||||
|
||||
~WizardFormPage();
|
||||
|
||||
void initializePage() override;
|
||||
|
||||
bool validatePage() override;
|
||||
|
||||
void addLineEdit(QString displayName, QString fieldName,
|
||||
QString defaultVal = "",
|
||||
std::function<int(QString)> validator = [](QString) { return 0; });
|
||||
|
||||
void addDirBrowse(QString displayName, QString fieldName, QString defaultVal = QDir::homePath());
|
||||
|
||||
void showValidationError(QString msg);
|
||||
};
|
||||
|
||||
|
||||
class WizardConclusionPage: public QWizardPage {
|
||||
Q_OBJECT
|
||||
private:
|
||||
QString m_baseMsg = "";
|
||||
QLabel *m_text = nullptr;
|
||||
QVector<QString> m_fields;
|
||||
|
||||
public:
|
||||
WizardConclusionPage(QString msg, QVector<QString> field);
|
||||
|
||||
virtual ~WizardConclusionPage();
|
||||
|
||||
void initializePage() override;
|
||||
};
|
||||
|
||||
|
||||
class Wizard: public QWizard {
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
std::function<void()> m_acceptFunc;
|
||||
|
||||
public:
|
||||
Wizard(QWidget *parent = 0);
|
||||
|
||||
void setAccept(std::function<void()> acceptFunc);
|
||||
|
||||
void accept();
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,173 @@
|
||||
/*
|
||||
* Copyright 2016-2017 gtalent2@gmail.com
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#include <QVector>
|
||||
|
||||
#include "oxfstreeview.hpp"
|
||||
|
||||
namespace nostalgia {
|
||||
namespace studio {
|
||||
|
||||
using namespace ox;
|
||||
|
||||
OxFSFile::OxFSFile(FileSystem *fs, QString path, OxFSFile *parentItem) {
|
||||
m_fs = fs;
|
||||
m_path = path;
|
||||
m_parentItem = parentItem;
|
||||
}
|
||||
|
||||
OxFSFile::~OxFSFile() {
|
||||
qDeleteAll(m_childItems);
|
||||
}
|
||||
|
||||
void OxFSFile::appendChild(OxFSFile*) {
|
||||
}
|
||||
|
||||
OxFSFile *OxFSFile::child(int row) {
|
||||
if (m_fs) {
|
||||
QVector<DirectoryListing<QString>> ls;
|
||||
m_fs->ls(m_path.toUtf8(), &ls);
|
||||
auto ch = new OxFSFile(m_fs, m_path + "/" + ls[row].name, this);
|
||||
m_childItems.push_back(ch);
|
||||
return ch;
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
int OxFSFile::childCount() const {
|
||||
if (m_fs) {
|
||||
QVector<DirectoryListing<QString>> ls;
|
||||
m_fs->ls(m_path.toUtf8(), &ls);
|
||||
return ls.size();
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int OxFSFile::columnCount() const {
|
||||
return 1;
|
||||
}
|
||||
|
||||
QVariant OxFSFile::data(int) const {
|
||||
return m_path.mid(m_path.lastIndexOf('/') + 1);
|
||||
}
|
||||
|
||||
int OxFSFile::row() const {
|
||||
if (m_parentItem) {
|
||||
return m_parentItem->m_childItems.indexOf(const_cast<OxFSFile*>(this));
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
OxFSFile *OxFSFile::parentItem() {
|
||||
return m_parentItem;
|
||||
}
|
||||
|
||||
|
||||
// OxFSModel
|
||||
|
||||
OxFSModel::OxFSModel(FileSystem *fs, QObject *parent) {
|
||||
m_rootItem = new OxFSFile(fs, "");
|
||||
}
|
||||
|
||||
OxFSModel::~OxFSModel() {
|
||||
if (m_rootItem) {
|
||||
delete m_rootItem;
|
||||
}
|
||||
}
|
||||
|
||||
QVariant OxFSModel::data(const QModelIndex &index, int role) const {
|
||||
if (!index.isValid() || role != Qt::DisplayRole) {
|
||||
return QVariant();
|
||||
} else {
|
||||
OxFSFile *item = static_cast<OxFSFile*>(index.internalPointer());
|
||||
return item->data(index.column());
|
||||
}
|
||||
}
|
||||
|
||||
Qt::ItemFlags OxFSModel::flags(const QModelIndex &index) const {
|
||||
if (!index.isValid()) {
|
||||
return 0;
|
||||
} else {
|
||||
return QAbstractItemModel::flags(index);
|
||||
}
|
||||
}
|
||||
|
||||
QVariant OxFSModel::headerData(int section, Qt::Orientation orientation, int role) const {
|
||||
return QVariant();
|
||||
if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
|
||||
return m_rootItem->data(section);
|
||||
} else {
|
||||
return QVariant();
|
||||
}
|
||||
}
|
||||
|
||||
QModelIndex OxFSModel::index(int row, int column, const QModelIndex &parent) const {
|
||||
if (!hasIndex(row, column, parent)) {
|
||||
return QModelIndex();
|
||||
}
|
||||
|
||||
OxFSFile *parentItem;
|
||||
if (!parent.isValid()) {
|
||||
parentItem = m_rootItem;
|
||||
} else {
|
||||
parentItem = static_cast<OxFSFile*>(parent.internalPointer());
|
||||
}
|
||||
|
||||
OxFSFile *childItem = parentItem->child(row);
|
||||
if (childItem) {
|
||||
return createIndex(row, column, childItem);
|
||||
} else {
|
||||
return QModelIndex();
|
||||
}
|
||||
}
|
||||
|
||||
QModelIndex OxFSModel::parent(const QModelIndex &index) const {
|
||||
if (!index.isValid()) {
|
||||
return QModelIndex();
|
||||
}
|
||||
|
||||
OxFSFile *childItem = static_cast<OxFSFile*>(index.internalPointer());
|
||||
OxFSFile *parentItem = childItem->parentItem();
|
||||
if (parentItem == m_rootItem) {
|
||||
return QModelIndex();
|
||||
}
|
||||
|
||||
return createIndex(parentItem->row(), 0, parentItem);
|
||||
}
|
||||
|
||||
int OxFSModel::rowCount(const QModelIndex &parent) const {
|
||||
if (parent.column() > 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
OxFSFile *parentItem;
|
||||
if (!parent.isValid()) {
|
||||
parentItem = m_rootItem;
|
||||
} else {
|
||||
parentItem = static_cast<OxFSFile*>(parent.internalPointer());
|
||||
}
|
||||
|
||||
return parentItem->childCount();
|
||||
}
|
||||
|
||||
int OxFSModel::columnCount(const QModelIndex &parent) const {
|
||||
if (parent.isValid()) {
|
||||
return static_cast<OxFSFile*>(parent.internalPointer())->columnCount();
|
||||
} else {
|
||||
return m_rootItem->columnCount();
|
||||
}
|
||||
}
|
||||
|
||||
void OxFSModel::setupModelData(const QStringList &lines, OxFSFile *parent) {
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright 2016-2017 gtalent2@gmail.com
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QModelIndex>
|
||||
#include <QVector>
|
||||
#include <QVariant>
|
||||
|
||||
#include <ox/fs/filesystem.hpp>
|
||||
|
||||
namespace nostalgia {
|
||||
namespace studio {
|
||||
|
||||
class OxFSFile {
|
||||
private:
|
||||
ox::FileSystem *m_fs = nullptr;
|
||||
OxFSFile *m_parentItem = nullptr;
|
||||
QString m_path;
|
||||
QVector<OxFSFile*> m_childItems;
|
||||
|
||||
public:
|
||||
OxFSFile(ox::FileSystem *fs, QString path, OxFSFile *parentItem = nullptr);
|
||||
|
||||
~OxFSFile();
|
||||
|
||||
void appendChild(OxFSFile *child);
|
||||
|
||||
OxFSFile *child(int row);
|
||||
|
||||
int childCount() const;
|
||||
|
||||
int columnCount() const;
|
||||
|
||||
QVariant data(int column) const;
|
||||
|
||||
int row() const;
|
||||
|
||||
OxFSFile *parentItem();
|
||||
};
|
||||
|
||||
class OxFSModel: public QAbstractItemModel {
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
OxFSFile *m_rootItem = nullptr;
|
||||
|
||||
public:
|
||||
explicit OxFSModel(ox::FileSystem *fs, QObject *parent = 0);
|
||||
|
||||
~OxFSModel();
|
||||
|
||||
QVariant data(const QModelIndex &index, int role) const override;
|
||||
|
||||
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
||||
|
||||
QVariant headerData(int section, Qt::Orientation orientation,
|
||||
int role = Qt::DisplayRole) const override;
|
||||
|
||||
QModelIndex index(int row, int column,
|
||||
const QModelIndex &parent = QModelIndex()) const override;
|
||||
|
||||
QModelIndex parent(const QModelIndex &index) const override;
|
||||
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
|
||||
private:
|
||||
void setupModelData(const QStringList &lines, OxFSFile *parent);
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright 2016-2017 gtalent2@gmail.com
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#include <QByteArray>
|
||||
#include <QDir>
|
||||
#include <project.hpp>
|
||||
|
||||
namespace nostalgia {
|
||||
namespace studio {
|
||||
|
||||
using namespace ox;
|
||||
|
||||
QString Project::ROM_FILE = "/ROM.oxfs";
|
||||
|
||||
Project::Project(QString path) {
|
||||
m_path = path;
|
||||
}
|
||||
|
||||
Project::~Project() {
|
||||
if (m_fs) {
|
||||
delete m_fs;
|
||||
}
|
||||
}
|
||||
|
||||
void Project::create() {
|
||||
QDir().mkpath(m_path);
|
||||
|
||||
m_romBuff = QSharedPointer<QByteArray>(new QByteArray(1024, 0));
|
||||
FileSystem32::format(m_romBuff->data(), m_romBuff->size(), true);
|
||||
m_fs = createFileSystem(m_romBuff->data(), m_romBuff->size());
|
||||
|
||||
m_fs->mkdir("/Tilesets");
|
||||
|
||||
QFile file(m_path + ROM_FILE);
|
||||
file.open(QIODevice::WriteOnly);
|
||||
file.write(*m_romBuff);
|
||||
file.close();
|
||||
}
|
||||
|
||||
int Project::open() {
|
||||
QFile file(m_path + ROM_FILE);
|
||||
m_romBuff = QSharedPointer<QByteArray>(new QByteArray(file.size(), 0));
|
||||
if (file.exists()) {
|
||||
file.open(QIODevice::ReadOnly);
|
||||
if (file.read(m_romBuff->data(), file.size()) > 0) {
|
||||
m_fs = createFileSystem(m_romBuff->data(), m_romBuff->size());
|
||||
|
||||
m_fs->mkdir("/Tilesets");
|
||||
return 0;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
void Project::save() {
|
||||
QFile file(m_path + ROM_FILE);
|
||||
file.open(QIODevice::WriteOnly);
|
||||
file.write(*m_romBuff);
|
||||
file.close();
|
||||
}
|
||||
|
||||
FileSystem *Project::romFS() {
|
||||
return m_fs;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 2016-2017 gtalent2@gmail.com
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QSharedPointer>
|
||||
|
||||
#include <ox/fs/filesystem.hpp>
|
||||
|
||||
namespace nostalgia {
|
||||
namespace studio {
|
||||
|
||||
class Project: public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
static QString ROM_FILE;
|
||||
|
||||
QString m_path = "";
|
||||
QSharedPointer<QByteArray> m_romBuff;
|
||||
ox::FileSystem *m_fs = nullptr;
|
||||
|
||||
public:
|
||||
Project(QString path);
|
||||
|
||||
~Project();
|
||||
|
||||
void create();
|
||||
|
||||
int open();
|
||||
|
||||
void save();
|
||||
|
||||
ox::FileSystem *romFS();
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user