Cleanup memory management in Project
This commit is contained in:
parent
de89f86a26
commit
2b5c34279c
@ -23,19 +23,15 @@ Project::Project(QString path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Project::~Project() {
|
Project::~Project() {
|
||||||
if (m_fs) {
|
|
||||||
delete m_fs;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Project::create() {
|
void Project::create() {
|
||||||
qDebug() << "Project::create";
|
|
||||||
QDir().mkpath(m_path);
|
QDir().mkpath(m_path);
|
||||||
|
|
||||||
auto buffSize = 1024;
|
auto buffSize = 1024;
|
||||||
auto buff = new uint8_t[buffSize];
|
auto buff = new uint8_t[buffSize];
|
||||||
FileSystem32::format(buff, buffSize, true);
|
FileSystem32::format(buff, buffSize, true);
|
||||||
m_fs = createFileSystem(buff, buffSize, true);
|
m_fs = std::unique_ptr<ox::FileSystem>{createFileSystem(buff, buffSize, true)};
|
||||||
|
|
||||||
QFile file(m_path + ROM_FILE);
|
QFile file(m_path + ROM_FILE);
|
||||||
file.open(QIODevice::WriteOnly);
|
file.open(QIODevice::WriteOnly);
|
||||||
@ -46,23 +42,21 @@ void Project::create() {
|
|||||||
int Project::openRomFs() {
|
int Project::openRomFs() {
|
||||||
QFile file(m_path + ROM_FILE);
|
QFile file(m_path + ROM_FILE);
|
||||||
auto buffSize = file.size();
|
auto buffSize = file.size();
|
||||||
auto buff = new uint8_t[buffSize];
|
auto buff = std::make_unique<uint8_t[]>(buffSize);
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
file.open(QIODevice::ReadOnly);
|
file.open(QIODevice::ReadOnly);
|
||||||
if (file.read((char*) buff, buffSize) > 0) {
|
if (file.read((char*) buff.get(), buffSize) > 0) {
|
||||||
m_fs = createFileSystem(buff, buffSize, true);
|
m_fs = std::unique_ptr<ox::FileSystem>{createFileSystem(buff.get(), buffSize, true)};
|
||||||
if (m_fs) {
|
if (m_fs) {
|
||||||
|
buff.release();
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
delete []buff;
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
delete []buff;
|
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
delete []buff;
|
|
||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -77,7 +71,7 @@ int Project::saveRomFs() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
FileSystem *Project::romFs() {
|
FileSystem *Project::romFs() {
|
||||||
return m_fs;
|
return m_fs.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
int Project::mkdir(QString path) const {
|
int Project::mkdir(QString path) const {
|
||||||
|
@ -8,6 +8,8 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include <QSharedPointer>
|
#include <QSharedPointer>
|
||||||
|
|
||||||
#include <ox/fs/fs.hpp>
|
#include <ox/fs/fs.hpp>
|
||||||
@ -23,7 +25,7 @@ class Project: public QObject {
|
|||||||
static QString ROM_FILE;
|
static QString ROM_FILE;
|
||||||
|
|
||||||
QString m_path = "";
|
QString m_path = "";
|
||||||
ox::FileSystem *m_fs = nullptr;
|
std::unique_ptr<ox::FileSystem> m_fs;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Project(QString path);
|
Project(QString path);
|
||||||
@ -63,7 +65,7 @@ int Project::writeObj(QString path, T *obj) const {
|
|||||||
|
|
||||||
// write MetalClaw
|
// write MetalClaw
|
||||||
size_t mcSize = 0;
|
size_t mcSize = 0;
|
||||||
err |= ox::write((uint8_t*) buff.data(), buffLen, obj, &mcSize);
|
err |= ox::writeMC((uint8_t*) buff.data(), buffLen, obj, &mcSize);
|
||||||
if (err) {
|
if (err) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user