summaryrefslogtreecommitdiff
path: root/lyt/archivepackage.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/archivepackage.cpp
parentebcc95da4c26369511caa90d89c5ed06e1e4853a (diff)
downloadLayoutStudio-7a183cfa367db01413c001306741d06e1826d077.tar.gz
LayoutStudio-7a183cfa367db01413c001306741d06e1826d077.zip
might as well push all this. a massive amount of changes
Diffstat (limited to 'lyt/archivepackage.cpp')
-rw-r--r--lyt/archivepackage.cpp129
1 files changed, 79 insertions, 50 deletions
diff --git a/lyt/archivepackage.cpp b/lyt/archivepackage.cpp
index eaabbf2..acb92d2 100644
--- a/lyt/archivepackage.cpp
+++ b/lyt/archivepackage.cpp
@@ -19,11 +19,11 @@
#include <QtCore/QFile>
-LYTArchivePackage::LYTArchivePackage() : LYTPackageBase() {
+LYTArchivePackage::LYTArchivePackage(QObject *parent) : LYTPackageBase(parent) {
m_archive = new WiiArchiveU8;
}
-LYTArchivePackage::LYTArchivePackage(QString filename) : LYTPackageBase() {
+LYTArchivePackage::LYTArchivePackage(QString filename, QObject *parent) : LYTPackageBase(parent) {
m_filename = filename;
QFile file(filename);
@@ -47,11 +47,14 @@ WiiArchiveU8 *LYTArchivePackage::archive() const {
QString LYTArchivePackage::filename() const {
return m_filename;
}
+void LYTArchivePackage::setFilename(QString path) {
+ m_filename = path;
+}
-QStringList LYTArchivePackage::listSubDirIfExists(QString dirName) const {
- WiiFSObject *obj = this->m_archive->root.resolvePath(dirName);
+QStringList LYTArchivePackage::list(ItemType type) const {
+ WiiFSObject *obj = this->m_archive->root.resolvePath(defaultPathForItemType(type, true));
if (obj && obj->isDirectory()) {
QStringList output;
@@ -66,9 +69,9 @@ QStringList LYTArchivePackage::listSubDirIfExists(QString dirName) const {
return QStringList();
}
-
-QByteArray LYTArchivePackage::getFileFromSubDirIfExists(QString dirName, QString fileName) const {
- WiiFSObject *obj = this->m_archive->root.resolvePath(QString("%1/%2").arg(dirName, fileName));
+QByteArray LYTArchivePackage::get(ItemType type, const QString &name) const {
+ QString dirName = defaultPathForItemType(type, true);
+ WiiFSObject *obj = this->m_archive->root.resolvePath(QString("%1/%2").arg(dirName, name));
if (obj && obj->isFile()) {
return ((WiiFile*)obj)->data;
@@ -77,71 +80,97 @@ QByteArray LYTArchivePackage::getFileFromSubDirIfExists(QString dirName, QString
return QByteArray();
}
+bool LYTArchivePackage::write(ItemType type, const QString &name, const QByteArray &data) {
+ if (name.isEmpty())
+ return false;
-bool LYTArchivePackage::writeFileToSubDir(QString dirName, QString fileName, QByteArray data) {
- WiiFSObject *obj = this->m_archive->root.resolvePath(QString("%1/%2").arg(dirName, fileName));
+ WiiFSObject *rootDir = this->m_archive->root.findByName("arc", false);
+ if (!rootDir) {
+ rootDir = new WiiDirectory;
+ rootDir->name = "arc";
+ m_archive->root.addChild(rootDir);
+ }
+ if (!rootDir->isDirectory())
+ return false;
- if (obj && obj->isFile()) {
- ((WiiFile*)obj)->data = data;
- return true;
- }
+ QString dirName = defaultPathForItemType(type, false);
+ WiiFSObject *dir = ((WiiDirectory*)rootDir)->findByName(dirName, false);
- return false;
-}
+ if (!dir) {
+ dir = new WiiDirectory;
+ dir->name = dirName;
+ ((WiiDirectory*)rootDir)->addChild(dir);
+ }
+ if (!dir->isDirectory())
+ return false;
+ WiiFSObject *obj = ((WiiDirectory*)dir)->findByName(name, false);
+ if (obj && obj->isFile()) {
+ emit aboutToModifyFile(type, name);
+ ((WiiFile*)obj)->data = data;
-QStringList LYTArchivePackage::listAnims() const {
- return this->listSubDirIfExists("arc/anim");
-}
+ emit fileWasModified(type, name);
-QStringList LYTArchivePackage::listLayouts() const {
- return this->listSubDirIfExists("arc/blyt");
-}
+ return true;
-QStringList LYTArchivePackage::listTextures() const {
- return this->listSubDirIfExists("arc/timg");
-}
+ } else if (!obj) {
+ emit aboutToAddFile(type, name);
-QStringList LYTArchivePackage::listFonts() const {
- return this->listSubDirIfExists("arc/font");
-}
+ WiiFile *newFile = new WiiFile;
+ newFile->name = name;
+ newFile->data = data;
+ ((WiiDirectory*)dir)->addChild(newFile);
+ emit fileWasAdded(type, name);
+ return true;
+ }
-QByteArray LYTArchivePackage::getAnim(QString name) const {
- return this->getFileFromSubDirIfExists("arc/anim", name);
+ return false;
}
-QByteArray LYTArchivePackage::getLayout(QString name) const {
- return this->getFileFromSubDirIfExists("arc/blyt", name);
-}
+bool LYTArchivePackage::remove(ItemType type, const QString &name) {
+ WiiFSObject *obj = this->m_archive->root.resolvePath(defaultPathForItemType(type, true));
-QByteArray LYTArchivePackage::getTexture(QString name) const {
- return this->getFileFromSubDirIfExists("arc/timg", name);
-}
+ if (obj && obj->isDirectory()) {
+ WiiDirectory *dir = (WiiDirectory*)obj;
+
+ WiiFSObject *what = dir->findByName(name, false);
+ if (what && what->isFile()) {
+ emit aboutToRemoveFile(type, name);
+ dir->removeChild(what);
+ emit fileWasRemoved(type, name);
+ return true;
+ }
+ }
-QByteArray LYTArchivePackage::getFont(QString name) const {
- return this->getFileFromSubDirIfExists("arc/font", name);
+ return false;
}
+bool LYTArchivePackage::rename(ItemType type, const QString &from, const QString &to) {
+ if (to.isEmpty())
+ return false;
+ WiiFSObject *obj = this->m_archive->root.resolvePath(defaultPathForItemType(type, true));
-bool LYTArchivePackage::writeAnim(QString name, QByteArray data) {
- return this->writeFileToSubDir("arc/anim", name, data);
-}
-
-bool LYTArchivePackage::writeLayout(QString name, QByteArray data) {
- return this->writeFileToSubDir("arc/blyt", name, data);
-}
-
-bool LYTArchivePackage::writeTexture(QString name, QByteArray data) {
- return this->writeFileToSubDir("arc/timg", name, data);
-}
+ if (obj && obj->isDirectory()) {
+ WiiDirectory *dir = (WiiDirectory*)obj;
+
+ WiiFSObject *what = dir->findByName(from, false);
+ if (what && what->isFile()) {
+ WiiFSObject *conflict = dir->findByName(to, false);
+ if (!conflict) {
+ emit aboutToRenameFile(type, from, to);
+ what->name = to;
+ emit fileWasRenamed(type, from, to);
+ return true;
+ }
+ }
+ }
-bool LYTArchivePackage::writeFont(QString name, QByteArray data) {
- return this->writeFileToSubDir("arc/font", name, data);
+ return false;
}