summaryrefslogtreecommitdiff
path: root/lyt/directorypackage.cpp
diff options
context:
space:
mode:
authorTreeki <treeki@gmail.com>2012-08-03 05:16:52 +0200
committerTreeki <treeki@gmail.com>2012-08-03 05:16:52 +0200
commit7a183cfa367db01413c001306741d06e1826d077 (patch)
treee50e2e222ddf924e4d868e79ed87a0ced85d01e1 /lyt/directorypackage.cpp
parentebcc95da4c26369511caa90d89c5ed06e1e4853a (diff)
downloadLayoutStudio-7a183cfa367db01413c001306741d06e1826d077.tar.gz
LayoutStudio-7a183cfa367db01413c001306741d06e1826d077.zip
might as well push all this. a massive amount of changes
Diffstat (limited to '')
-rw-r--r--lyt/directorypackage.cpp99
1 files changed, 32 insertions, 67 deletions
diff --git a/lyt/directorypackage.cpp b/lyt/directorypackage.cpp
index dd8c39d..803cb80 100644
--- a/lyt/directorypackage.cpp
+++ b/lyt/directorypackage.cpp
@@ -19,29 +19,30 @@
#include <QtCore/QDir>
-LYTDirectoryPackage::LYTDirectoryPackage(QString path) : LYTPackageBase() {
+LYTDirectoryPackage::LYTDirectoryPackage(QString path, QObject *parent) : LYTPackageBase(parent) {
+ qWarning("LYTDirectoryPackage is currently unmaintained, you probably shouldn't use it");
+
QDir fix_path(path);
this->m_path = fix_path.absolutePath();
}
-QStringList LYTDirectoryPackage::listSubDirIfExists(QString dirName) const {
+QStringList LYTDirectoryPackage::list(ItemType type) const {
QDir search(m_path);
- if (search.cd(dirName)) {
+ if (search.cd(defaultPathForItemType(type))) {
return search.entryList();
}
return QStringList();
}
-
-QByteArray LYTDirectoryPackage::getFileFromSubDirIfExists(QString dirName, QString fileName) const {
+QByteArray LYTDirectoryPackage::get(ItemType type, const QString &name) const {
QDir search(m_path);
- if (search.cd(dirName)) {
- QFile file(search.absoluteFilePath(fileName));
+ if (search.cd(defaultPathForItemType(type))) {
+ QFile file(search.absoluteFilePath(name));
if (file.open(QFile::ReadOnly)) {
return file.readAll();
@@ -51,76 +52,40 @@ QByteArray LYTDirectoryPackage::getFileFromSubDirIfExists(QString dirName, QStri
return QByteArray();
}
-
-bool LYTDirectoryPackage::writeFileToSubDir(QString dirName, QString fileName, QByteArray data) {
+bool LYTDirectoryPackage::write(ItemType type, const QString &name, const QByteArray &data) {
QDir search(m_path);
+ QString dirName = defaultPathForItemType(type);
- if (search.cd(dirName)) {
- QFile file(search.absoluteFilePath(fileName));
-
- if (file.open(QFile::WriteOnly)) {
- if (file.write(data) != -1) {
- return true;
- }
- }
- }
-
- return false;
-}
+ if (!search.cd(dirName)) {
+ if (!search.mkdir(dirName))
+ return false;
+ if (!search.cd(dirName))
+ return false;
+ }
+ QFile file(search.absoluteFilePath(name));
+ if (file.open(QFile::WriteOnly)) {
+ if (file.write(data) != -1) {
+ return true;
+ }
+ }
-
-QStringList LYTDirectoryPackage::listAnims() const {
- return this->listSubDirIfExists("anim");
-}
-
-QStringList LYTDirectoryPackage::listLayouts() const {
- return this->listSubDirIfExists("blyt");
-}
-
-QStringList LYTDirectoryPackage::listTextures() const {
- return this->listSubDirIfExists("timg");
+ return false;
}
-QStringList LYTDirectoryPackage::listFonts() const {
- return this->listSubDirIfExists("font");
-}
-
-
-
-QByteArray LYTDirectoryPackage::getAnim(QString name) const {
- return this->getFileFromSubDirIfExists("anim", name);
-}
-
-QByteArray LYTDirectoryPackage::getLayout(QString name) const {
- return this->getFileFromSubDirIfExists("blyt", name);
-}
-
-QByteArray LYTDirectoryPackage::getTexture(QString name) const {
- return this->getFileFromSubDirIfExists("timg", name);
-}
-
-QByteArray LYTDirectoryPackage::getFont(QString name) const {
- return this->getFileFromSubDirIfExists("font", name);
-}
-
-
+bool LYTDirectoryPackage::remove(ItemType type, const QString &name) {
+ QDir search(m_path);
-bool LYTDirectoryPackage::writeAnim(QString name, QByteArray data) {
- return this->writeFileToSubDir("anim", name, data);
-}
+ if (search.cd(defaultPathForItemType(type))) {
+ QFile file(search.absoluteFilePath(name));
-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);
-}
+ if (file.open(QFile::WriteOnly)) {
+ return file.remove();
+ }
+ }
-bool LYTDirectoryPackage::writeFont(QString name, QByteArray data) {
- return this->writeFileToSubDir("font", name, data);
+ return false;
}