diff options
author | Treeki <treeki@gmail.com> | 2010-10-07 15:56:13 +0200 |
---|---|---|
committer | Treeki <treeki@gmail.com> | 2010-10-07 15:56:13 +0200 |
commit | 5f6dad55d75cbe146ff7fefc899a02ccd39078ba (patch) | |
tree | 0822df14cc6d2c0329810c9ae7b4a4a638fe82b1 /lyt/directorypackage.cpp | |
download | LayoutStudio-5f6dad55d75cbe146ff7fefc899a02ccd39078ba.tar.gz LayoutStudio-5f6dad55d75cbe146ff7fefc899a02ccd39078ba.zip |
initial commit -- everything compiles except for material.cpp. the material system still needs quite a bit of work; this will come in due time
Diffstat (limited to 'lyt/directorypackage.cpp')
-rw-r--r-- | lyt/directorypackage.cpp | 119 |
1 files changed, 119 insertions, 0 deletions
diff --git a/lyt/directorypackage.cpp b/lyt/directorypackage.cpp new file mode 100644 index 0000000..93e3ad8 --- /dev/null +++ b/lyt/directorypackage.cpp @@ -0,0 +1,119 @@ +#include "directorypackage.h" + +#include <QDir> + +LYTDirectoryPackage::LYTDirectoryPackage(QString path) : LYTPackageBase() { + QDir fix_path(path); + this->m_path = fix_path.absolutePath(); +} + + + +QStringList LYTDirectoryPackage::listSubDirIfExists(QString dirName) { + QDir search(m_path); + + if (search.cd(dirName)) { + return search.entryList(); + } + + return QStringList(); +} + + +QByteArray LYTDirectoryPackage::getFileFromSubDirIfExists(QString dirName, QString fileName) { + QDir search(m_path); + + if (search.cd(dirName)) { + QFile file(search.absoluteFilePath(fileName)); + + if (file.open(QFile::ReadOnly)) { + return file.readAll(); + } + } + + return QByteArray(); +} + + +bool LYTDirectoryPackage::writeFileToSubDir(QString dirName, QString fileName, QByteArray data) { + QDir search(m_path); + + if (search.cd(dirName)) { + QFile file(search.absoluteFilePath(fileName)); + + if (file.open(QFile::WriteOnly)) { + if (file.write(data) != -1) { + return true; + } + } + } + + return false; +} + + + + +QStringList LYTDirectoryPackage::listAnims() { + return this->listSubDirIfExists("anim"); +} + +QStringList LYTDirectoryPackage::listLayouts() { + return this->listSubDirIfExists("blyt"); +} + +QStringList LYTDirectoryPackage::listTextures() { + return this->listSubDirIfExists("timg"); +} + +QStringList LYTDirectoryPackage::listFonts() { + return this->listSubDirIfExists("font"); +} + + + +QByteArray LYTDirectoryPackage::getAnim(QString name) { + return this->getFileFromSubDirIfExists("anim", name); +} + +QByteArray LYTDirectoryPackage::getLayout(QString name) { + return this->getFileFromSubDirIfExists("blyt", name); +} + +QByteArray LYTDirectoryPackage::getTexture(QString name) { + return this->getFileFromSubDirIfExists("timg", name); +} + +QByteArray LYTDirectoryPackage::getFont(QString name) { + return this->getFileFromSubDirIfExists("font", name); +} + + + +bool LYTDirectoryPackage::writeAnim(QString name, QByteArray data) { + return this->writeFileToSubDir("anim", name, data); +} + +bool LYTDirectoryPackage::writeLayout(QString name, QByteArray data) { + return this->writeFileToSubDir("blyt", name, data); +} + +bool LYTDirectoryPackage::writeTexture(QString name, QByteArray data) { + return this->writeFileToSubDir("timg", name, data); +} + +bool LYTDirectoryPackage::writeFont(QString name, QByteArray data) { + return this->writeFileToSubDir("font", name, data); +} + + + +bool LYTDirectoryPackage::savePackage() { + // No-op since this is a directory + return true; +} + + +QString LYTDirectoryPackage::description() { + return m_path; +} |