From af0e24d9bf26db51ae6c2615aed93a5c1105de6f Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Tue, 15 Jan 2019 22:33:13 -0600 Subject: [PATCH] [nostalgia] Switch Studio to PassThroughFS --- .vscode/c_cpp_properties.json | 3 +- CMakeLists.txt | 1 + Dockerfile | 12 +++--- Makefile | 8 ++-- scripts/run-make | 2 +- scripts/setup-build.ps1 | 10 ++++- src/nostalgia/common/fileaddr.hpp | 21 ++++++++++ src/nostalgia/core/context.hpp | 6 +-- src/nostalgia/core/gba/mem.cpp | 14 +++---- .../core/studio/import_tilesheet_wizard.cpp | 36 +++++++++------- .../core/studio/import_tilesheet_wizard.hpp | 6 +-- src/nostalgia/core/types.hpp | 6 +-- src/nostalgia/player/CMakeLists.txt | 2 + src/nostalgia/player/main.cpp | 2 +- src/nostalgia/studio/CMakeLists.txt | 1 + src/nostalgia/studio/lib/CMakeLists.txt | 3 ++ src/nostalgia/studio/lib/oxfstreeview.cpp | 41 ++++++++++++------- src/nostalgia/studio/lib/oxfstreeview.hpp | 4 +- src/nostalgia/studio/lib/project.cpp | 40 +++++++----------- src/nostalgia/studio/lib/project.hpp | 5 ++- src/nostalgia/studio/lib/wizard.cpp | 4 +- src/nostalgia/studio/lib/wizard.hpp | 2 +- src/nostalgia/studio/mainwindow.cpp | 8 +++- src/nostalgia/tools/CMakeLists.txt | 2 + src/nostalgia/tools/pack.cpp | 23 +++++++---- src/nostalgia/world/world.cpp | 4 +- 26 files changed, 159 insertions(+), 107 deletions(-) create mode 100644 src/nostalgia/common/fileaddr.hpp diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 0103b360..131ed53e 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -30,7 +30,8 @@ ], "compilerPath": "/usr/bin/clang", "cStandard": "c11", - "cppStandard": "c++17" + "cppStandard": "c++17", + "compileCommands": "${workspaceFolder}/build/linux-x86_64-debug/compile_commands.json" }, { "name": "Linux", diff --git a/CMakeLists.txt b/CMakeLists.txt index 7b2b9325..aee44168 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,6 +45,7 @@ if(NOT MSVC) if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") # forces colored output when using ninja set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-color") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++") endif() endif() diff --git a/Dockerfile b/Dockerfile index f9c82993..33b38a07 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM fedora:28 +FROM fedora:29 RUN dnf update -y @@ -33,11 +33,11 @@ RUN dnf install -y ninja-build ############################################################################### # Install devkitARM -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 -WORKDIR /opt -RUN tar xf /tmp/devkitArm.tar.bz2 -ENV DEVKITARM /opt/devkitARM +#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 +#WORKDIR /opt +#RUN tar xf /tmp/devkitArm.tar.bz2 +#ENV DEVKITARM /opt/devkitARM ############################################################################### # Setup sudoers diff --git a/Makefile b/Makefile index 7b152ba4..1da5c550 100644 --- a/Makefile +++ b/Makefile @@ -31,15 +31,15 @@ test: ${ENV_RUN} ./scripts/run-make build test run: install - ./dist/current/bin/nostalgia -debug + ${ENV_RUN} ./dist/current/bin/nostalgia -debug 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 mgba-qt nostalgia.gba gdb: make - gdb ./build/current/src/wombat/wombat + ${ENV_RUN} gdb ./build/current/src/wombat/wombat 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: docker build . -t ${DEVENV_IMAGE} diff --git a/scripts/run-make b/scripts/run-make index 8c59fa1c..28dfe61c 100755 --- a/scripts/run-make +++ b/scripts/run-make @@ -4,5 +4,5 @@ set -e for f in $(find $1 -maxdepth 1 -mindepth 1 -type d) do - cmake --build "$f" --target $2 -- -j + cmake --build "$f" --target $2 done diff --git a/scripts/setup-build.ps1 b/scripts/setup-build.ps1 index ce7ec4e9..8978414a 100755 --- a/scripts/setup-build.ps1 +++ b/scripts/setup-build.ps1 @@ -6,21 +6,28 @@ Param( ) $project=(Get-Location).Path +$buildTool="" if (${target} -eq "windows") { $toolchain="-DCMAKE_TOOLCHAIN_FILE=cmake/Modules/Mingw.cmake" + $buildTool="-GNinja" } elseif (${target} -eq "gba") { $toolchain="-DCMAKE_TOOLCHAIN_FILE=cmake/Modules/GBA.cmake" $nostalgiaBuildType="-DNOSTALGIA_BUILD_TYPE=GBA" $oxUseStdLib="-DOX_USE_STDLIB=OFF" +} else { + $buildTool="-GNinja" } 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") { $buildTypeArgs="-DCMAKE_BUILD_TYPE=Debug" + $sanitizerArgs="" } elseif (${buildType} -eq "release") { $buildTypeArgs="-DCMAKE_BUILD_TYPE=Release" + $sanitizerArgs="" } if (${env:NOSTALGIA_QT_PATH} -ne "") { @@ -40,6 +47,7 @@ cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ` $nostalgiaBuildType ` $oxUseStdLib ` $buildTypeArgs ` + $sanitizerArgs ` $qtPath ` $toolchain ` $project diff --git a/src/nostalgia/common/fileaddr.hpp b/src/nostalgia/common/fileaddr.hpp new file mode 100644 index 00000000..a6379c15 --- /dev/null +++ b/src/nostalgia/common/fileaddr.hpp @@ -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; +}; + +} diff --git a/src/nostalgia/core/context.hpp b/src/nostalgia/core/context.hpp index e1718e61..95672ea5 100644 --- a/src/nostalgia/core/context.hpp +++ b/src/nostalgia/core/context.hpp @@ -8,14 +8,12 @@ #include -namespace nostalgia { -namespace core { +namespace nostalgia::core { // User Input Output struct Context { - ox::FileSystem32 *rom = nullptr; + ox::FileSystem *rom = nullptr; }; } -} diff --git a/src/nostalgia/core/gba/mem.cpp b/src/nostalgia/core/gba/mem.cpp index 1fa41880..6229fdd6 100644 --- a/src/nostalgia/core/gba/mem.cpp +++ b/src/nostalgia/core/gba/mem.cpp @@ -9,11 +9,12 @@ #include "addresses.hpp" #include "panic.hpp" -namespace nostalgia { -namespace core { +#include + +namespace nostalgia::core { struct HeapSegment { - size_t size; + std::size_t size; uint8_t inUse; HeapSegment *next; @@ -32,12 +33,11 @@ void initHeap() { _heapIdx->inUse = false; } -} } using namespace nostalgia::core; -void *malloc(size_t allocSize) { +void *malloc(std::size_t allocSize) { // add space for heap segment header data const auto fullSize = allocSize + sizeof(HeapSegment); 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); } -void *operator new[](size_t allocSize) { +void *operator new[](std::size_t allocSize) { return malloc(allocSize); } diff --git a/src/nostalgia/core/studio/import_tilesheet_wizard.cpp b/src/nostalgia/core/studio/import_tilesheet_wizard.cpp index d1072b0c..72b72a33 100644 --- a/src/nostalgia/core/studio/import_tilesheet_wizard.cpp +++ b/src/nostalgia/core/studio/import_tilesheet_wizard.cpp @@ -6,6 +6,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include #include #include "import_tilesheet_wizard.hpp" @@ -13,15 +14,15 @@ namespace nostalgia { namespace core { -const QString ImportTilesheetWizardPage::TILESHEET_DIR = "/TileSheets/"; -const QString ImportTilesheetWizardPage::TILESHEET_NAME = "projectName"; -const QString ImportTilesheetWizardPage::IMPORT_PATH = "projectPath"; +const QString ImportTilesheetWizardPage::TileSheetDir = "/TileSheets/"; +const QString ImportTilesheetWizardPage::TileSheetName = "projectName"; +const QString ImportTilesheetWizardPage::ImportPath = "projectPath"; const QString ImportTilesheetWizardPage::BPP = "bpp"; ImportTilesheetWizardPage::ImportTilesheetWizardPage(const studio::Context *ctx) { m_ctx = ctx; - addLineEdit(tr("&Tile Sheet Name:"), TILESHEET_NAME + "*", "", [this](QString) { - auto importPath = field(IMPORT_PATH).toString(); + addLineEdit(tr("&Tile Sheet Name:"), TileSheetName + "*", "", [this](QString) { + auto importPath = field(ImportPath).toString(); if (QFile(importPath).exists()) { return 0; } else { @@ -31,31 +32,38 @@ ImportTilesheetWizardPage::ImportTilesheetWizardPage(const studio::Context *ctx) } ); auto fileTypes = "(*.png);;(*.bmp);;(*.jpg);;(*.jpeg)"; - addPathBrowse(tr("Tile Sheet &Path:"), IMPORT_PATH + "*", "", + addPathBrowse(tr("Tile Sheet &Path:"), ImportPath + "*", "", QFileDialog::ExistingFile, fileTypes); addComboBox(tr("Bits Per Pixe&l:"), BPP, {"4", "8"}); } int ImportTilesheetWizardPage::accept() { - auto tilesheetName = field(TILESHEET_NAME).toString(); - auto importPath = field(IMPORT_PATH).toString(); + auto tilesheetName = field(TileSheetName).toString(); + auto importPath = field(ImportPath).toString(); QFile importFile(importPath); if (importFile.exists()) { - return importImage(importFile, field(TILESHEET_NAME).toString()); + return importImage(importFile, field(TileSheetName).toString()); } else { return 1; } } int ImportTilesheetWizardPage::importImage(QFile &srcFile, QString tilesheetName) { - auto buffSize = srcFile.size(); - uint8_t buff[buffSize]; if (srcFile.exists()) { srcFile.open(QIODevice::ReadOnly); - if (srcFile.read((char*) buff, buffSize) > 0) { + auto buff = srcFile.readAll(); + QImage srcImg; + if (srcImg.loadFromData(buff)) { int err = 0; - m_ctx->project->mkdir(TILESHEET_DIR); - err |= m_ctx->project->write(TILESHEET_DIR + tilesheetName, buff, buffSize); + // ensure image is PNG + 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(out.data()), out.size()); err |= m_ctx->project->saveRomFs(); return err; } else { diff --git a/src/nostalgia/core/studio/import_tilesheet_wizard.hpp b/src/nostalgia/core/studio/import_tilesheet_wizard.hpp index 0fb6b742..152367be 100644 --- a/src/nostalgia/core/studio/import_tilesheet_wizard.hpp +++ b/src/nostalgia/core/studio/import_tilesheet_wizard.hpp @@ -15,9 +15,9 @@ namespace core { class ImportTilesheetWizardPage: public studio::WizardFormPage { private: - static const QString TILESHEET_DIR; - static const QString TILESHEET_NAME; - static const QString IMPORT_PATH; + static const QString TileSheetDir; + static const QString TileSheetName; + static const QString ImportPath; static const QString BPP; const studio::Context *m_ctx = nullptr; diff --git a/src/nostalgia/core/types.hpp b/src/nostalgia/core/types.hpp index 78e607d0..6406f5de 100644 --- a/src/nostalgia/core/types.hpp +++ b/src/nostalgia/core/types.hpp @@ -8,12 +8,10 @@ #pragma once -#include +#include -namespace nostalgia { -namespace core { +namespace nostalgia::core { typedef ox::FileStore32::InodeId_t InodeId_t; } -} diff --git a/src/nostalgia/player/CMakeLists.txt b/src/nostalgia/player/CMakeLists.txt index 1ee6c55b..51eb8339 100644 --- a/src/nostalgia/player/CMakeLists.txt +++ b/src/nostalgia/player/CMakeLists.txt @@ -22,6 +22,8 @@ target_link_libraries( NostalgiaCore OxFS OxStd + OxTrace + OxMetalClaw ) add_custom_target("nostalgia.bin") diff --git a/src/nostalgia/player/main.cpp b/src/nostalgia/player/main.cpp index be86cb2a..52ba0176 100644 --- a/src/nostalgia/player/main.cpp +++ b/src/nostalgia/player/main.cpp @@ -13,7 +13,7 @@ using namespace nostalgia::core; using namespace nostalgia::world; int main() { - ox::FileSystem32 fs(loadRom(), false); + ox::FileSystem32 fs(ox::FileStore32(loadRom(), 33554432)); // 32 MB Context ctx; init(&ctx); ctx.rom = &fs; diff --git a/src/nostalgia/studio/CMakeLists.txt b/src/nostalgia/studio/CMakeLists.txt index 9c74080f..c95f948b 100644 --- a/src/nostalgia/studio/CMakeLists.txt +++ b/src/nostalgia/studio/CMakeLists.txt @@ -12,6 +12,7 @@ add_executable( target_link_libraries( nostalgia-studio + c++fs Qt5::Core Qt5::Widgets OxClArgs diff --git a/src/nostalgia/studio/lib/CMakeLists.txt b/src/nostalgia/studio/lib/CMakeLists.txt index 9e96ef65..0b36f044 100644 --- a/src/nostalgia/studio/lib/CMakeLists.txt +++ b/src/nostalgia/studio/lib/CMakeLists.txt @@ -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 ) diff --git a/src/nostalgia/studio/lib/oxfstreeview.cpp b/src/nostalgia/studio/lib/oxfstreeview.cpp index 027ceb00..164d9493 100644 --- a/src/nostalgia/studio/lib/oxfstreeview.cpp +++ b/src/nostalgia/studio/lib/oxfstreeview.cpp @@ -6,30 +6,44 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include +#include #include #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> 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 ls; + auto stat = fs->stat(static_cast(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) { } } -} diff --git a/src/nostalgia/studio/lib/oxfstreeview.hpp b/src/nostalgia/studio/lib/oxfstreeview.hpp index ee423cce..fd55e54e 100644 --- a/src/nostalgia/studio/lib/oxfstreeview.hpp +++ b/src/nostalgia/studio/lib/oxfstreeview.hpp @@ -24,7 +24,7 @@ class OxFSFile { QVector 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(); diff --git a/src/nostalgia/studio/lib/project.cpp b/src/nostalgia/studio/lib/project.cpp index f94b1c87..686819b7 100644 --- a/src/nostalgia/studio/lib/project.cpp +++ b/src/nostalgia/studio/lib/project.cpp @@ -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{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{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()); } } -} diff --git a/src/nostalgia/studio/lib/project.hpp b/src/nostalgia/studio/lib/project.hpp index 7f8def3d..1a526af0 100644 --- a/src/nostalgia/studio/lib/project.hpp +++ b/src/nostalgia/studio/lib/project.hpp @@ -25,7 +25,8 @@ class Project: public QObject { static QString ROM_FILE; QString m_path = ""; - std::unique_ptr m_fs; + std::unique_ptr 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; diff --git a/src/nostalgia/studio/lib/wizard.cpp b/src/nostalgia/studio/lib/wizard.cpp index 55f32a7c..c008de3b 100644 --- a/src/nostalgia/studio/lib/wizard.cpp +++ b/src/nostalgia/studio/lib/wizard.cpp @@ -336,8 +336,8 @@ void Wizard::setAccept(std::function acceptFunc) { void Wizard::accept() { auto page = dynamic_cast(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(); } } diff --git a/src/nostalgia/studio/lib/wizard.hpp b/src/nostalgia/studio/lib/wizard.hpp index ebf739a9..b7b73a3b 100644 --- a/src/nostalgia/studio/lib/wizard.hpp +++ b/src/nostalgia/studio/lib/wizard.hpp @@ -25,7 +25,7 @@ namespace studio { struct WizardMaker { QString name; std::function()> make; - std::function onAccept; + std::function onAccept = [](QWizard*) { return 0; }; }; class WizardSelect: public QWizardPage { diff --git a/src/nostalgia/studio/mainwindow.cpp b/src/nostalgia/studio/mainwindow.cpp index f2b8292b..034f8271 100644 --- a/src/nostalgia/studio/mainwindow.cpp +++ b/src/nostalgia/studio/mainwindow.cpp @@ -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; } } diff --git a/src/nostalgia/tools/CMakeLists.txt b/src/nostalgia/tools/CMakeLists.txt index 0014df93..506602ab 100644 --- a/src/nostalgia/tools/CMakeLists.txt +++ b/src/nostalgia/tools/CMakeLists.txt @@ -13,6 +13,8 @@ target_link_libraries( OxClArgs OxFS OxStd + OxTrace + OxMetalClaw NostalgiaCommon NostalgiaCore ) diff --git a/src/nostalgia/tools/pack.cpp b/src/nostalgia/tools/pack.cpp index 8f53a393..0c904af3 100644 --- a/src/nostalgia/tools/pack.cpp +++ b/src/nostalgia/tools/pack.cpp @@ -118,21 +118,28 @@ int run(ClArgs args) { size_t fsBuffSize; auto fsBuff = loadFileBuff(argFsPath, &fsBuffSize); if (fsBuff && !err) { - auto fs = createFileSystem(fsBuff, fsBuffSize); + auto fs = FileSystem32(FileStore32(fsBuff, fsBuffSize)); - if (fs) { - fs = expandCopyCleanup(fs, fs->size() + fs->spaceNeeded(imgDataBuffSize)); - fsBuff = fs->buff(); // update fsBuff pointer in case there is a new buff - err |= fs->write(argInode, imgDataBuff, imgDataBuffSize); + if (fs.valid()) { + const auto sizeNeeded = fs.size() + fs.spaceNeeded(imgDataBuffSize); + if (sizeNeeded > fsBuffSize) { + 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 (argCompact) { - fs->resize(); + FileStore32(fsBuff, fsBuffSize).compact(); } auto fsFile = fopen(argFsPath.toUtf8(), "wb"); if (fsFile) { - err = fwrite(fsBuff, fs->size(), 1, fsFile) != 1; + err = fwrite(fsBuff, fs.size(), 1, fsFile) != 1; err |= fclose(fsFile); if (err) { cerr << "Could not write to file system file.\n"; @@ -143,8 +150,6 @@ int run(ClArgs args) { } else { err = 3; } - - delete fs; } else { err = 4; } diff --git a/src/nostalgia/world/world.cpp b/src/nostalgia/world/world.cpp index 95baecda..17dbb4e7 100644 --- a/src/nostalgia/world/world.cpp +++ b/src/nostalgia/world/world.cpp @@ -8,8 +8,7 @@ #include "world.hpp" -namespace nostalgia { -namespace world { +namespace nostalgia::world { using namespace common; using namespace core; @@ -49,4 +48,3 @@ void Zone::setTile(int x, int y, Tile *td) { } } -}