1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
/*******************************************************************************
This file is part of LayoutStudio (http://github.com/Treeki/LayoutStudio)
Copyright (c) 2010 Treeki (treeki@gmail.com)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, version 2.0.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License 2.0 for more details.
You should have received a copy of the GNU General Public License 2.0
along with this program. If not, see <http://www.gnu.org/licenses/>.
*******************************************************************************/
#include "directorypackage.h"
#include <QtCore/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;
}
|