blob: 803cb806d415da6b15e99e5784051644e584f2cb (
plain)
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
|
/*******************************************************************************
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, 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::list(ItemType type) const {
QDir search(m_path);
if (search.cd(defaultPathForItemType(type))) {
return search.entryList();
}
return QStringList();
}
QByteArray LYTDirectoryPackage::get(ItemType type, const QString &name) const {
QDir search(m_path);
if (search.cd(defaultPathForItemType(type))) {
QFile file(search.absoluteFilePath(name));
if (file.open(QFile::ReadOnly)) {
return file.readAll();
}
}
return QByteArray();
}
bool LYTDirectoryPackage::write(ItemType type, const QString &name, const QByteArray &data) {
QDir search(m_path);
QString dirName = defaultPathForItemType(type);
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;
}
}
return false;
}
bool LYTDirectoryPackage::remove(ItemType type, const QString &name) {
QDir search(m_path);
if (search.cd(defaultPathForItemType(type))) {
QFile file(search.absoluteFilePath(name));
if (file.open(QFile::WriteOnly)) {
return file.remove();
}
}
return false;
}
bool LYTDirectoryPackage::savePackage() {
// No-op since this is a directory
return true;
}
QString LYTDirectoryPackage::description() const {
return m_path;
}
|