[nostalgia/studio] Cleanup
This commit is contained in:
parent
2be31cca5c
commit
2f9accf5ba
@ -31,7 +31,7 @@ class Module {
|
||||
|
||||
virtual QVector<WizardMaker> importWizards(const Context *ctx);
|
||||
|
||||
virtual QVector<EditorMaker> editors(const class Context *ctx);
|
||||
virtual QVector<EditorMaker> editors(const class Context *ctx);
|
||||
|
||||
};
|
||||
|
||||
|
@ -13,20 +13,18 @@
|
||||
|
||||
namespace nostalgia::studio {
|
||||
|
||||
QString filePathToName(QString path, QString prefix, QString suffix) {
|
||||
QString filePathToName(const QString &path, const QString &prefix, const QString &suffix) {
|
||||
const auto begin = prefix.size();
|
||||
const auto end = path.size() - (suffix.size() + prefix.size());
|
||||
return path.mid(begin, end);
|
||||
}
|
||||
|
||||
|
||||
Project::Project(QString path): m_fs(std::make_unique<ox::PassThroughFS>(path.toUtf8())) {
|
||||
Project::Project(const QString &path): m_fs(std::make_unique<ox::PassThroughFS>(path.toUtf8())) {
|
||||
qDebug() << "Project:" << path;
|
||||
m_path = path;
|
||||
}
|
||||
|
||||
Project::~Project() = default;
|
||||
|
||||
void Project::create() {
|
||||
QDir().mkpath(m_path);
|
||||
}
|
||||
@ -35,32 +33,32 @@ ox::FileSystem *Project::romFs() {
|
||||
return m_fs.get();
|
||||
}
|
||||
|
||||
void Project::mkdir(QString path) const {
|
||||
void Project::mkdir(const QString &path) const {
|
||||
oxThrowError(m_fs->mkdir(path.toUtf8().data(), true));
|
||||
emit fileUpdated(path);
|
||||
}
|
||||
|
||||
ox::FileStat Project::stat(QString path) const {
|
||||
ox::FileStat Project::stat(const QString &path) const {
|
||||
oxRequireT(s, m_fs->stat(path.toUtf8().data()));
|
||||
return s;
|
||||
}
|
||||
|
||||
bool Project::exists(QString path) const {
|
||||
bool Project::exists(const QString &path) const {
|
||||
return m_fs->stat(path.toUtf8().data()).error == 0;
|
||||
}
|
||||
|
||||
void Project::writeBuff(QString path, uint8_t *buff, size_t buffLen) const {
|
||||
void Project::writeBuff(const QString &path, uint8_t *buff, size_t buffLen) const {
|
||||
oxThrowError(m_fs->write(path.toUtf8().data(), buff, buffLen));
|
||||
emit fileUpdated(path);
|
||||
}
|
||||
|
||||
ox::Buffer Project::loadBuff(QString path) const {
|
||||
ox::Buffer Project::loadBuff(const QString &path) const {
|
||||
const auto csPath = path.toUtf8();
|
||||
oxRequireMT(buff, m_fs->read(csPath.data()));
|
||||
return std::move(buff);
|
||||
}
|
||||
|
||||
void Project::lsProcDir(QStringList *paths, QString path) const {
|
||||
void Project::lsProcDir(QStringList *paths, const QString &path) const {
|
||||
oxRequireT(files, m_fs->ls(path.toUtf8()));
|
||||
for (const auto &name : files) {
|
||||
const auto fullPath = path + "/" + name.c_str();
|
||||
@ -78,10 +76,10 @@ void Project::lsProcDir(QStringList *paths, QString path) const {
|
||||
}
|
||||
}
|
||||
|
||||
QStringList Project::listFiles(QString path) const {
|
||||
QStringList Project::listFiles(const QString &path) const {
|
||||
QStringList paths;
|
||||
lsProcDir(&paths, path);
|
||||
return paths;
|
||||
return ox::move(paths);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -32,7 +32,8 @@ enum class ProjectEvent {
|
||||
FileUpdated,
|
||||
};
|
||||
|
||||
[[nodiscard]] QString filePathToName(QString path, QString prefix, QString suffix);
|
||||
[[nodiscard]]
|
||||
QString filePathToName(const QString &path, const QString &prefix, const QString &suffix);
|
||||
|
||||
class NOSTALGIASTUDIO_EXPORT Project: public QObject {
|
||||
Q_OBJECT
|
||||
@ -42,42 +43,40 @@ class NOSTALGIASTUDIO_EXPORT Project: public QObject {
|
||||
mutable std::unique_ptr<ox::FileSystem> m_fs;
|
||||
|
||||
public:
|
||||
explicit Project(QString path);
|
||||
explicit Project(const QString &path);
|
||||
|
||||
~Project() override;
|
||||
~Project() override = default;
|
||||
|
||||
void create();
|
||||
|
||||
ox::FileSystem *romFs();
|
||||
|
||||
void mkdir(QString path) const;
|
||||
void mkdir(const QString &path) const;
|
||||
|
||||
/**
|
||||
* Writes a MetalClaw object to the project at the given path.
|
||||
*/
|
||||
template<typename T>
|
||||
void writeObj(QString path, T *obj) const;
|
||||
void writeObj(const QString &path, T *obj) const;
|
||||
|
||||
template<typename T>
|
||||
std::unique_ptr<T> loadObj(QString path) const;
|
||||
std::unique_ptr<T> loadObj(const QString &path) const;
|
||||
|
||||
ox::FileStat stat(QString path) const;
|
||||
ox::FileStat stat(const QString &path) const;
|
||||
|
||||
bool exists(QString path) const;
|
||||
|
||||
void subscribe(ProjectEvent e, QObject *tgt, const char *slot) const;
|
||||
bool exists(const QString& path) const;
|
||||
|
||||
template<typename Functor>
|
||||
void subscribe(ProjectEvent e, QObject *tgt, Functor &&slot) const;
|
||||
|
||||
private:
|
||||
void writeBuff(QString path, uint8_t *buff, size_t buffLen) const;
|
||||
void writeBuff(const QString &path, uint8_t *buff, size_t buffLen) const;
|
||||
|
||||
ox::Buffer loadBuff(QString path) const;
|
||||
ox::Buffer loadBuff(const QString &path) const;
|
||||
|
||||
void lsProcDir(QStringList *paths, QString path) const;
|
||||
void lsProcDir(QStringList *paths, const QString &path) const;
|
||||
|
||||
QStringList listFiles(QString path = "") const;
|
||||
QStringList listFiles(const QString &path = "") const;
|
||||
|
||||
signals:
|
||||
void fileEvent(ProjectEvent, QString path) const;
|
||||
@ -92,7 +91,7 @@ class NOSTALGIASTUDIO_EXPORT Project: public QObject {
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
void Project::writeObj(QString path, T *obj) const {
|
||||
void Project::writeObj(const QString &path, T *obj) const {
|
||||
// write MetalClaw
|
||||
oxRequireMT(buff, ox::writeClaw(obj, ox::ClawFormat::Metal));
|
||||
// write to FS
|
||||
@ -112,7 +111,7 @@ void Project::writeObj(QString path, T *obj) const {
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
std::unique_ptr<T> Project::loadObj(QString path) const {
|
||||
std::unique_ptr<T> Project::loadObj(const QString &path) const {
|
||||
auto obj = std::make_unique<T>();
|
||||
auto buff = loadBuff(path);
|
||||
oxThrowError(ox::readClaw<T>(buff.data(), buff.size(), obj.get()));
|
||||
|
Loading…
Reference in New Issue
Block a user