[nostalgia] Switch Studio to PassThroughFS

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

View File

@ -30,7 +30,8 @@
], ],
"compilerPath": "/usr/bin/clang", "compilerPath": "/usr/bin/clang",
"cStandard": "c11", "cStandard": "c11",
"cppStandard": "c++17" "cppStandard": "c++17",
"compileCommands": "${workspaceFolder}/build/linux-x86_64-debug/compile_commands.json"
}, },
{ {
"name": "Linux", "name": "Linux",

View File

@ -45,6 +45,7 @@ if(NOT MSVC)
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
# forces colored output when using ninja # forces colored output when using ninja
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-color") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-color")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
endif() endif()
endif() endif()

View File

@ -1,4 +1,4 @@
FROM fedora:28 FROM fedora:29
RUN dnf update -y RUN dnf update -y
@ -33,11 +33,11 @@ RUN dnf install -y ninja-build
############################################################################### ###############################################################################
# Install devkitARM # Install devkitARM
RUN dnf install -y lbzip2 #RUN dnf install -y lbzip2
RUN curl -o /tmp/devkitArm.tar.bz2 -SL https://phoenixnap.dl.sourceforge.net/project/devkitpro/devkitARM/devkitARM_r47/devkitARM_r47-x86_64-linux.tar.bz2 #RUN curl -o /tmp/devkitArm.tar.bz2 -SL https://phoenixnap.dl.sourceforge.net/project/devkitpro/devkitARM/devkitARM_r47/devkitARM_r47-x86_64-linux.tar.bz2
WORKDIR /opt #WORKDIR /opt
RUN tar xf /tmp/devkitArm.tar.bz2 #RUN tar xf /tmp/devkitArm.tar.bz2
ENV DEVKITARM /opt/devkitARM #ENV DEVKITARM /opt/devkitARM
############################################################################### ###############################################################################
# Setup sudoers # Setup sudoers

View File

@ -31,15 +31,15 @@ test:
${ENV_RUN} ./scripts/run-make build test ${ENV_RUN} ./scripts/run-make build test
run: install run: install
./dist/current/bin/nostalgia -debug ${ENV_RUN} ./dist/current/bin/nostalgia -debug
run-studio: install run-studio: install
./dist/current/bin/nostalgia-studio -profile dist/current/share/nostalgia-studio.json ${ENV_RUN} ./dist/current/bin/nostalgia-studio -profile dist/current/share/nostalgia-studio.json
gba-run: gba-pkg gba-run: gba-pkg
mgba-qt nostalgia.gba mgba-qt nostalgia.gba
gdb: make gdb: make
gdb ./build/current/src/wombat/wombat ${ENV_RUN} gdb ./build/current/src/wombat/wombat
gdb-studio: install gdb-studio: install
gdb --args ./dist/current/bin/nostalgia-studio -profile dist/current/share/nostalgia-studio.json ${ENV_RUN} gdb --args ./dist/current/bin/nostalgia-studio -profile dist/current/share/nostalgia-studio.json
devenv-image: devenv-image:
docker build . -t ${DEVENV_IMAGE} docker build . -t ${DEVENV_IMAGE}

View File

@ -4,5 +4,5 @@ set -e
for f in $(find $1 -maxdepth 1 -mindepth 1 -type d) for f in $(find $1 -maxdepth 1 -mindepth 1 -type d)
do do
cmake --build "$f" --target $2 -- -j cmake --build "$f" --target $2
done done

View File

@ -6,21 +6,28 @@ Param(
) )
$project=(Get-Location).Path $project=(Get-Location).Path
$buildTool=""
if (${target} -eq "windows") { if (${target} -eq "windows") {
$toolchain="-DCMAKE_TOOLCHAIN_FILE=cmake/Modules/Mingw.cmake" $toolchain="-DCMAKE_TOOLCHAIN_FILE=cmake/Modules/Mingw.cmake"
$buildTool="-GNinja"
} elseif (${target} -eq "gba") { } elseif (${target} -eq "gba") {
$toolchain="-DCMAKE_TOOLCHAIN_FILE=cmake/Modules/GBA.cmake" $toolchain="-DCMAKE_TOOLCHAIN_FILE=cmake/Modules/GBA.cmake"
$nostalgiaBuildType="-DNOSTALGIA_BUILD_TYPE=GBA" $nostalgiaBuildType="-DNOSTALGIA_BUILD_TYPE=GBA"
$oxUseStdLib="-DOX_USE_STDLIB=OFF" $oxUseStdLib="-DOX_USE_STDLIB=OFF"
} else {
$buildTool="-GNinja"
} }
if (${buildType} -eq "asan") { if (${buildType} -eq "asan") {
$buildTypeArgs="-DUSE_ASAN=ON -DCMAKE_BUILD_TYPE=Debug" $buildTypeArgs="-DCMAKE_BUILD_TYPE=Debug"
$sanitizerArgs="-DUSE_ASAN=ON"
} elseif (${buildType} -eq "debug") { } elseif (${buildType} -eq "debug") {
$buildTypeArgs="-DCMAKE_BUILD_TYPE=Debug" $buildTypeArgs="-DCMAKE_BUILD_TYPE=Debug"
$sanitizerArgs=""
} elseif (${buildType} -eq "release") { } elseif (${buildType} -eq "release") {
$buildTypeArgs="-DCMAKE_BUILD_TYPE=Release" $buildTypeArgs="-DCMAKE_BUILD_TYPE=Release"
$sanitizerArgs=""
} }
if (${env:NOSTALGIA_QT_PATH} -ne "") { if (${env:NOSTALGIA_QT_PATH} -ne "") {
@ -40,6 +47,7 @@ cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON `
$nostalgiaBuildType ` $nostalgiaBuildType `
$oxUseStdLib ` $oxUseStdLib `
$buildTypeArgs ` $buildTypeArgs `
$sanitizerArgs `
$qtPath ` $qtPath `
$toolchain ` $toolchain `
$project $project

View File

@ -0,0 +1,21 @@
/*
* Copyright 2016 - 2018 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
namespace nostalgia::common {
class FileAddr {
private:
union {
ox::BString<255> path;
uint64_t inode;
} m_data;
};
}

View File

@ -8,14 +8,12 @@
#include <ox/fs/fs.hpp> #include <ox/fs/fs.hpp>
namespace nostalgia { namespace nostalgia::core {
namespace core {
// User Input Output // User Input Output
struct Context { struct Context {
ox::FileSystem32 *rom = nullptr; ox::FileSystem *rom = nullptr;
}; };
} }
}

View File

@ -9,11 +9,12 @@
#include "addresses.hpp" #include "addresses.hpp"
#include "panic.hpp" #include "panic.hpp"
namespace nostalgia { #include <ox/std/std.hpp>
namespace core {
namespace nostalgia::core {
struct HeapSegment { struct HeapSegment {
size_t size; std::size_t size;
uint8_t inUse; uint8_t inUse;
HeapSegment *next; HeapSegment *next;
@ -32,12 +33,11 @@ void initHeap() {
_heapIdx->inUse = false; _heapIdx->inUse = false;
} }
}
} }
using namespace nostalgia::core; using namespace nostalgia::core;
void *malloc(size_t allocSize) { void *malloc(std::size_t allocSize) {
// add space for heap segment header data // add space for heap segment header data
const auto fullSize = allocSize + sizeof(HeapSegment); const auto fullSize = allocSize + sizeof(HeapSegment);
auto seg = _heapIdx; auto seg = _heapIdx;
@ -117,11 +117,11 @@ void free(void *ptrIn) {
} }
} }
void *operator new(size_t allocSize) { void *operator new(std::size_t allocSize) {
return malloc(allocSize); return malloc(allocSize);
} }
void *operator new[](size_t allocSize) { void *operator new[](std::size_t allocSize) {
return malloc(allocSize); return malloc(allocSize);
} }

View File

@ -6,6 +6,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/ */
#include <QBuffer>
#include <QFile> #include <QFile>
#include "import_tilesheet_wizard.hpp" #include "import_tilesheet_wizard.hpp"
@ -13,15 +14,15 @@
namespace nostalgia { namespace nostalgia {
namespace core { namespace core {
const QString ImportTilesheetWizardPage::TILESHEET_DIR = "/TileSheets/"; const QString ImportTilesheetWizardPage::TileSheetDir = "/TileSheets/";
const QString ImportTilesheetWizardPage::TILESHEET_NAME = "projectName"; const QString ImportTilesheetWizardPage::TileSheetName = "projectName";
const QString ImportTilesheetWizardPage::IMPORT_PATH = "projectPath"; const QString ImportTilesheetWizardPage::ImportPath = "projectPath";
const QString ImportTilesheetWizardPage::BPP = "bpp"; const QString ImportTilesheetWizardPage::BPP = "bpp";
ImportTilesheetWizardPage::ImportTilesheetWizardPage(const studio::Context *ctx) { ImportTilesheetWizardPage::ImportTilesheetWizardPage(const studio::Context *ctx) {
m_ctx = ctx; m_ctx = ctx;
addLineEdit(tr("&Tile Sheet Name:"), TILESHEET_NAME + "*", "", [this](QString) { addLineEdit(tr("&Tile Sheet Name:"), TileSheetName + "*", "", [this](QString) {
auto importPath = field(IMPORT_PATH).toString(); auto importPath = field(ImportPath).toString();
if (QFile(importPath).exists()) { if (QFile(importPath).exists()) {
return 0; return 0;
} else { } else {
@ -31,31 +32,38 @@ ImportTilesheetWizardPage::ImportTilesheetWizardPage(const studio::Context *ctx)
} }
); );
auto fileTypes = "(*.png);;(*.bmp);;(*.jpg);;(*.jpeg)"; auto fileTypes = "(*.png);;(*.bmp);;(*.jpg);;(*.jpeg)";
addPathBrowse(tr("Tile Sheet &Path:"), IMPORT_PATH + "*", "", addPathBrowse(tr("Tile Sheet &Path:"), ImportPath + "*", "",
QFileDialog::ExistingFile, fileTypes); QFileDialog::ExistingFile, fileTypes);
addComboBox(tr("Bits Per Pixe&l:"), BPP, {"4", "8"}); addComboBox(tr("Bits Per Pixe&l:"), BPP, {"4", "8"});
} }
int ImportTilesheetWizardPage::accept() { int ImportTilesheetWizardPage::accept() {
auto tilesheetName = field(TILESHEET_NAME).toString(); auto tilesheetName = field(TileSheetName).toString();
auto importPath = field(IMPORT_PATH).toString(); auto importPath = field(ImportPath).toString();
QFile importFile(importPath); QFile importFile(importPath);
if (importFile.exists()) { if (importFile.exists()) {
return importImage(importFile, field(TILESHEET_NAME).toString()); return importImage(importFile, field(TileSheetName).toString());
} else { } else {
return 1; return 1;
} }
} }
int ImportTilesheetWizardPage::importImage(QFile &srcFile, QString tilesheetName) { int ImportTilesheetWizardPage::importImage(QFile &srcFile, QString tilesheetName) {
auto buffSize = srcFile.size();
uint8_t buff[buffSize];
if (srcFile.exists()) { if (srcFile.exists()) {
srcFile.open(QIODevice::ReadOnly); srcFile.open(QIODevice::ReadOnly);
if (srcFile.read((char*) buff, buffSize) > 0) { auto buff = srcFile.readAll();
QImage srcImg;
if (srcImg.loadFromData(buff)) {
int err = 0; int err = 0;
m_ctx->project->mkdir(TILESHEET_DIR); // ensure image is PNG
err |= m_ctx->project->write(TILESHEET_DIR + tilesheetName, buff, buffSize); QByteArray out;
QBuffer outBuffer(&out);
outBuffer.open(QIODevice::WriteOnly);
srcImg.save(&outBuffer, "PNG");
// make sure tile sheet directory exists
m_ctx->project->mkdir(TileSheetDir);
// write image
err |= m_ctx->project->write(TileSheetDir + tilesheetName + ".png", reinterpret_cast<uint8_t*>(out.data()), out.size());
err |= m_ctx->project->saveRomFs(); err |= m_ctx->project->saveRomFs();
return err; return err;
} else { } else {

View File

@ -15,9 +15,9 @@ namespace core {
class ImportTilesheetWizardPage: public studio::WizardFormPage { class ImportTilesheetWizardPage: public studio::WizardFormPage {
private: private:
static const QString TILESHEET_DIR; static const QString TileSheetDir;
static const QString TILESHEET_NAME; static const QString TileSheetName;
static const QString IMPORT_PATH; static const QString ImportPath;
static const QString BPP; static const QString BPP;
const studio::Context *m_ctx = nullptr; const studio::Context *m_ctx = nullptr;

View File

@ -8,12 +8,10 @@
#pragma once #pragma once
#include <ox/fs/filestore.hpp> #include <ox/fs/fs.hpp>
namespace nostalgia { namespace nostalgia::core {
namespace core {
typedef ox::FileStore32::InodeId_t InodeId_t; typedef ox::FileStore32::InodeId_t InodeId_t;
} }
}

View File

@ -22,6 +22,8 @@ target_link_libraries(
NostalgiaCore NostalgiaCore
OxFS OxFS
OxStd OxStd
OxTrace
OxMetalClaw
) )
add_custom_target("nostalgia.bin") add_custom_target("nostalgia.bin")

View File

@ -13,7 +13,7 @@ using namespace nostalgia::core;
using namespace nostalgia::world; using namespace nostalgia::world;
int main() { int main() {
ox::FileSystem32 fs(loadRom(), false); ox::FileSystem32 fs(ox::FileStore32(loadRom(), 33554432)); // 32 MB
Context ctx; Context ctx;
init(&ctx); init(&ctx);
ctx.rom = &fs; ctx.rom = &fs;

View File

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

View File

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

View File

@ -6,30 +6,44 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/ */
#include <QDebug>
#include <QDir>
#include <QVector> #include <QVector>
#include "oxfstreeview.hpp" #include "oxfstreeview.hpp"
namespace nostalgia { namespace nostalgia::studio {
namespace studio {
using namespace ox; using namespace ox;
OxFSFile::OxFSFile(FileSystem *fs, QString path, OxFSFile *parentItem) { OxFSFile::OxFSFile(PassThroughFS *fs, QString path, OxFSFile *parentItem) {
m_path = path; m_path = path;
m_parentItem = parentItem; m_parentItem = parentItem;
// find children // find children
if (fs) { if (fs) {
QVector<DirectoryListing<QString>> ls; QVector<QString> ls;
if (fs->stat((const char*) m_path.toUtf8()).fileType == FileType_Directory) { auto stat = fs->stat(static_cast<const char*>(m_path.toUtf8()));
fs->ls(m_path.toUtf8(), &ls); if (!stat.error) {
qSort(ls); if (stat.value.fileType == FileType_Directory) {
} fs->ls(m_path.toUtf8(), [&ls](const char *name, ox::InodeId_t inode) {
for (auto v : ls) { ls.push_back(name);
if (v.name != "." && v.name != "..") { return OxError(0);
auto ch = new OxFSFile(fs, m_path + "/" + v.name, this); });
m_childItems.push_back(ch); 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::OxFSModel(FileSystem *fs, QObject *parent) { OxFSModel::OxFSModel(PassThroughFS *fs, QObject *parent) {
m_rootItem = new OxFSFile(fs, ""); 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; QVector<OxFSFile*> m_childItems;
public: public:
OxFSFile(ox::FileSystem *fs, QString path, OxFSFile *parentItem = nullptr); OxFSFile(ox::PassThroughFS *fs, QString path, OxFSFile *parentItem = nullptr);
~OxFSFile(); ~OxFSFile();
@ -54,7 +54,7 @@ class OxFSModel: public QAbstractItemModel {
OxFSFile *m_rootItem = nullptr; OxFSFile *m_rootItem = nullptr;
public: public:
explicit OxFSModel(ox::FileSystem *fs, QObject *parent = 0); explicit OxFSModel(ox::PassThroughFS *fs, QObject *parent = 0);
~OxFSModel(); ~OxFSModel();

View File

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

View File

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

View File

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

View File

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

View File

@ -13,6 +13,8 @@ target_link_libraries(
OxClArgs OxClArgs
OxFS OxFS
OxStd OxStd
OxTrace
OxMetalClaw
NostalgiaCommon NostalgiaCommon
NostalgiaCore NostalgiaCore
) )

View File

@ -118,21 +118,28 @@ int run(ClArgs args) {
size_t fsBuffSize; size_t fsBuffSize;
auto fsBuff = loadFileBuff(argFsPath, &fsBuffSize); auto fsBuff = loadFileBuff(argFsPath, &fsBuffSize);
if (fsBuff && !err) { if (fsBuff && !err) {
auto fs = createFileSystem(fsBuff, fsBuffSize); auto fs = FileSystem32(FileStore32(fsBuff, fsBuffSize));
if (fs) { if (fs.valid()) {
fs = expandCopyCleanup(fs, fs->size() + fs->spaceNeeded(imgDataBuffSize)); const auto sizeNeeded = fs.size() + fs.spaceNeeded(imgDataBuffSize);
fsBuff = fs->buff(); // update fsBuff pointer in case there is a new buff if (sizeNeeded > fsBuffSize) {
err |= fs->write(argInode, imgDataBuff, imgDataBuffSize); auto newBuff = new uint8_t[sizeNeeded];
memcpy(newBuff, fsBuff, fsBuffSize);
delete[] fsBuff;
fsBuff = newBuff;
fsBuffSize = sizeNeeded;
}
fsBuff = fs.buff(); // update fsBuff pointer in case there is a new buff
err |= fs.write(argInode, imgDataBuff, imgDataBuffSize);
if (!err) { if (!err) {
if (argCompact) { if (argCompact) {
fs->resize(); FileStore32(fsBuff, fsBuffSize).compact();
} }
auto fsFile = fopen(argFsPath.toUtf8(), "wb"); auto fsFile = fopen(argFsPath.toUtf8(), "wb");
if (fsFile) { if (fsFile) {
err = fwrite(fsBuff, fs->size(), 1, fsFile) != 1; err = fwrite(fsBuff, fs.size(), 1, fsFile) != 1;
err |= fclose(fsFile); err |= fclose(fsFile);
if (err) { if (err) {
cerr << "Could not write to file system file.\n"; cerr << "Could not write to file system file.\n";
@ -143,8 +150,6 @@ int run(ClArgs args) {
} else { } else {
err = 3; err = 3;
} }
delete fs;
} else { } else {
err = 4; err = 4;
} }

View File

@ -8,8 +8,7 @@
#include "world.hpp" #include "world.hpp"
namespace nostalgia { namespace nostalgia::world {
namespace world {
using namespace common; using namespace common;
using namespace core; using namespace core;
@ -49,4 +48,3 @@ void Zone::setTile(int x, int y, Tile *td) {
} }
} }
}