[nostalgia] Switch Studio to PassThroughFS

This commit is contained in:
2019-01-15 22:33:13 -06:00
parent e5c5c0da43
commit af0e24d9bf
26 changed files with 159 additions and 107 deletions

View File

@@ -12,6 +12,7 @@ add_executable(
target_link_libraries(
nostalgia-studio
c++fs
Qt5::Core
Qt5::Widgets
OxClArgs

View File

@@ -20,10 +20,12 @@ install(TARGETS NostalgiaStudio
target_link_libraries(
NostalgiaStudio
c++fs
Qt5::Core
Qt5::Widgets
OxFS
OxMetalClaw
OxTrace
OxStd
)
@@ -48,6 +50,7 @@ add_executable(
target_link_libraries(
NostalgiaStudioJsonTest
c++fs
NostalgiaStudio
)

View File

@@ -6,30 +6,44 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <QDebug>
#include <QDir>
#include <QVector>
#include "oxfstreeview.hpp"
namespace nostalgia {
namespace studio {
namespace nostalgia::studio {
using namespace ox;
OxFSFile::OxFSFile(FileSystem *fs, QString path, OxFSFile *parentItem) {
OxFSFile::OxFSFile(PassThroughFS *fs, QString path, OxFSFile *parentItem) {
m_path = path;
m_parentItem = parentItem;
// find children
if (fs) {
QVector<DirectoryListing<QString>> ls;
if (fs->stat((const char*) m_path.toUtf8()).fileType == FileType_Directory) {
fs->ls(m_path.toUtf8(), &ls);
qSort(ls);
}
for (auto v : ls) {
if (v.name != "." && v.name != "..") {
auto ch = new OxFSFile(fs, m_path + "/" + v.name, this);
m_childItems.push_back(ch);
QVector<QString> ls;
auto stat = fs->stat(static_cast<const char*>(m_path.toUtf8()));
if (!stat.error) {
if (stat.value.fileType == FileType_Directory) {
fs->ls(m_path.toUtf8(), [&ls](const char *name, ox::InodeId_t inode) {
ls.push_back(name);
return OxError(0);
});
qSort(ls);
}
auto p = m_path;
// make sure ends with path separator
if (fs->stat(p.toUtf8().data()).value.fileType == FileType_Directory &&
p.size() && p.back() != QDir::separator()) {
p += QDir::separator();
}
for (auto name : ls) {
if (name != "." && name != "..") {
qDebug() << "name:" << m_path + name;
auto ch = new OxFSFile(fs, m_path + name, this);
m_childItems.push_back(ch);
}
}
}
}
@@ -101,7 +115,7 @@ QString OxFSFile::name() const {
// OxFSModel
OxFSModel::OxFSModel(FileSystem *fs, QObject *parent) {
OxFSModel::OxFSModel(PassThroughFS *fs, QObject *parent) {
m_rootItem = new OxFSFile(fs, "");
}
@@ -203,4 +217,3 @@ void OxFSModel::setupModelData(const QStringList &lines, OxFSFile *parent) {
}
}
}

View File

@@ -24,7 +24,7 @@ class OxFSFile {
QVector<OxFSFile*> m_childItems;
public:
OxFSFile(ox::FileSystem *fs, QString path, OxFSFile *parentItem = nullptr);
OxFSFile(ox::PassThroughFS *fs, QString path, OxFSFile *parentItem = nullptr);
~OxFSFile();
@@ -54,7 +54,7 @@ class OxFSModel: public QAbstractItemModel {
OxFSFile *m_rootItem = nullptr;
public:
explicit OxFSModel(ox::FileSystem *fs, QObject *parent = 0);
explicit OxFSModel(ox::PassThroughFS *fs, QObject *parent = 0);
~OxFSModel();

View File

@@ -11,14 +11,14 @@
#include "project.hpp"
namespace nostalgia {
namespace studio {
namespace nostalgia::studio {
using namespace ox;
QString Project::ROM_FILE = "/ROM.oxfs";
Project::Project(QString path) {
Project::Project(QString path): m_fs(path.toUtf8()) {
qDebug() << "Project:" << path;
m_path = path;
}
@@ -27,16 +27,6 @@ Project::~Project() {
void Project::create() {
QDir().mkpath(m_path);
auto buffSize = 1024;
auto buff = new uint8_t[buffSize];
FileSystem32::format(buff, buffSize, true);
m_fs = std::unique_ptr<ox::FileSystem>{createFileSystem(buff, buffSize, true)};
QFile file(m_path + ROM_FILE);
file.open(QIODevice::WriteOnly);
file.write((const char*) buff, buffSize);
file.close();
}
int Project::openRomFs() {
@@ -46,9 +36,8 @@ int Project::openRomFs() {
if (file.exists()) {
file.open(QIODevice::ReadOnly);
if (file.read((char*) buff.get(), buffSize) > 0) {
m_fs = std::unique_ptr<ox::FileSystem>{createFileSystem(buff.get(), buffSize, true)};
if (m_fs) {
buff.release();
m_fsBuff = std::move(buff);
if (m_fs.valid()) {
return 0;
} else {
return 1;
@@ -63,32 +52,31 @@ int Project::openRomFs() {
int Project::saveRomFs() const {
int err = 0;
QFile file(m_path + ROM_FILE);
err |= file.open(QIODevice::WriteOnly) == false;
err |= file.write((const char*) m_fs->buff(), m_fs->size()) == -1;
file.close();
//QFile file(m_path + ROM_FILE);
//err |= file.open(QIODevice::WriteOnly) == false;
//err |= file.write((const char*) m_fsBuff.get(), m_fs.size()) == -1;
//file.close();
return err;
}
FileSystem *Project::romFs() {
return m_fs.get();
PassThroughFS *Project::romFs() {
return &m_fs;
}
int Project::mkdir(QString path) const {
auto err = m_fs->mkdir(path.toUtf8().data(), true);
auto err = m_fs.mkdir(path.toUtf8().data(), true);
emit updated(path);
return err;
}
int Project::write(QString path, uint8_t *buff, size_t buffLen) const {
auto err = m_fs->write(path.toUtf8().data(), buff, buffLen);
auto err = m_fs.write(path.toUtf8().data(), buff, buffLen);
emit updated(path);
return err;
}
ox::FileStat Project::stat(QString path) const {
return m_fs->stat(path.toUtf8().data());
return m_fs.stat(path.toUtf8().data());
}
}
}

View File

@@ -25,7 +25,8 @@ class Project: public QObject {
static QString ROM_FILE;
QString m_path = "";
std::unique_ptr<ox::FileSystem> m_fs;
std::unique_ptr<uint8_t[]> m_fsBuff;
mutable ox::PassThroughFS m_fs;
public:
Project(QString path);
@@ -38,7 +39,7 @@ class Project: public QObject {
int saveRomFs() const;
ox::FileSystem *romFs();
ox::PassThroughFS *romFs();
int mkdir(QString path) const;

View File

@@ -336,8 +336,8 @@ void Wizard::setAccept(std::function<int(QWizard*)> acceptFunc) {
void Wizard::accept() {
auto page = dynamic_cast<WizardFormPage*>(currentPage());
if (page != nullptr and page->accept() == 0 and
m_acceptFunc != nullptr and m_acceptFunc(this) == 0) {
if ((page == nullptr || page->accept() == 0) &&
m_acceptFunc != nullptr && m_acceptFunc(this) == 0) {
QDialog::accept();
}
}

View File

@@ -25,7 +25,7 @@ namespace studio {
struct WizardMaker {
QString name;
std::function<QVector<QWizardPage*>()> make;
std::function<int(QWizard*)> onAccept;
std::function<int(QWizard*)> onAccept = [](QWizard*) { return 0; };
};
class WizardSelect: public QWizardPage {

View File

@@ -46,7 +46,7 @@ MainWindow::MainWindow(QString profilePath) {
auto screenSize = QApplication::desktop()->screenGeometry();
// set window to 75% of screen width, and center NostalgiaStudioProfile
auto sizePct = 0.75;
constexpr auto sizePct = 0.75;
resize(screenSize.width() * sizePct, screenSize.height() * sizePct);
move(-x(), -y());
move(screenSize.width() * (1 - sizePct) / 2, screenSize.height() * (1 - sizePct) / 2);
@@ -226,7 +226,6 @@ int MainWindow::writeState(QString path) {
int MainWindow::openProject(QString projectPath) {
auto err = closeProject();
auto project = new Project(projectPath);
err |= project->openRomFs();
if (err == 0) {
if (m_ctx.project) {
delete m_ctx.project;
@@ -238,6 +237,7 @@ int MainWindow::openProject(QString projectPath) {
connect(m_ctx.project, SIGNAL(updated(QString)), m_oxfsView, SLOT(updateFile(QString)));
m_importAction->setEnabled(true);
m_state.projectPath = projectPath;
qInfo() << "Open project:" << projectPath;
}
return err;
}
@@ -318,16 +318,20 @@ void MainWindow::showNewWizard() {
[this, ProjectName, ProjectPath](QWizard *wizard) {
auto projectName = wizard->field(ProjectName).toString();
auto projectPath = wizard->field(ProjectPath).toString();
qInfo() << "Project creation: final step";
if (QDir(projectPath).exists()) {
auto path = projectPath + "/" + projectName;
if (!QDir(path).exists()) {
Project(path).create();
openProject(path);
qInfo() << "Project creation successful:" << path;
return 0;
} else {
qInfo() << "Project file exists:" << path;
return 1;
}
} else {
qInfo() << "Project destination directory does not exist:" << projectPath;
return 2;
}
}