git-svn-id: svn://db.shs.com.ru/pip@558 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -120,6 +120,7 @@ PIString PIFile::FileInfo::dir() const {
|
||||
if (path.isEmpty()) return PIString();
|
||||
PIString ret = path.mid(0, path.findLast(PIDir::separator));
|
||||
if (ret.isEmpty()) ret = PIDir::separator;
|
||||
if (!PIDir(ret).isExists()) return (PIStringAscii(".") + PIDir::separator);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,9 @@ void PIResources::dump() {
|
||||
if (!si.value()) continue;
|
||||
PIMap<PIString, PIByteArray * >::iterator fi;
|
||||
for (fi = si.value()->entries.begin(); fi != si.value()->entries.end(); ++fi) {
|
||||
piCout << " " << fi.key() << ":" << (fi.value() ? fi.value()->size_s() : 0) << "b";
|
||||
PIString s = fi.key() + ": ";
|
||||
s << (fi.value() ? fi.value()->size_s() : 0) << " b";
|
||||
piCout << " " << s;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
#include "piresourcesstorage.h"
|
||||
#include "pichunkstream.h"
|
||||
#include "piset.h"
|
||||
|
||||
|
||||
PIResourcesStorage::Section::Section() {
|
||||
@@ -28,12 +29,6 @@ PIResourcesStorage::Section::Section() {
|
||||
|
||||
PIResourcesStorage::Section::~Section() {
|
||||
//piCout << "~Section";
|
||||
PIVector<PIByteArray * > bav = entries.values();
|
||||
piForeach (PIByteArray * i, bav) {
|
||||
if (i)
|
||||
delete i;
|
||||
}
|
||||
entries.clear();
|
||||
}
|
||||
|
||||
|
||||
@@ -42,11 +37,25 @@ void PIResourcesStorage::Section::add(const PIResourcesStorage::Section & s) {
|
||||
for (i = s.entries.begin(); i != s.entries.end(); ++i) {
|
||||
if (!i.value()) continue;
|
||||
if (entries.value(i.key(), 0)) continue;
|
||||
entries[i.key()] = new PIByteArray(i.value()->data(), i.value()->size());
|
||||
entries[i.key()] = i.value();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void PIResourcesStorage::Section::purge() {
|
||||
PIVector<PIByteArray * > bav = entries.values();
|
||||
PISet<PIByteArray * > bas;
|
||||
piForeach (PIByteArray * i, bav) {
|
||||
if (i)
|
||||
bas << i;
|
||||
}
|
||||
bav = bas.toVector();
|
||||
piForeach (PIByteArray * i, bav)
|
||||
delete i;
|
||||
entries.clear();
|
||||
}
|
||||
|
||||
|
||||
PIResourcesStorage::PIResourcesStorage() {
|
||||
|
||||
}
|
||||
@@ -80,9 +89,11 @@ void PIResourcesStorage::registerSection(const uchar * rc_data, const uchar * rc
|
||||
PIResourcesStorage::Section s;
|
||||
PIVector<PIResourcesStorage::__RCEntry> & itv(it.value());
|
||||
piForeachC (PIResourcesStorage::__RCEntry & e, itv) {
|
||||
//piCout << "add" << e.name << PIString::readableSize(e.size);
|
||||
//piCout << "add" << e.name << e.alias << PIString::readableSize(e.size);
|
||||
PIByteArray * eba = new PIByteArray(&(rc_data[e.offset]), e.size);
|
||||
s.entries[e.name] = eba;
|
||||
if (!e.alias.isEmpty() && e.alias != e.name)
|
||||
s.entries[e.alias] = eba;
|
||||
}
|
||||
registerSection(it.key(), s);
|
||||
}
|
||||
@@ -118,8 +129,10 @@ PIByteArray PIResourcesStorage::get(const PIString & entry_name) const {
|
||||
void PIResourcesStorage::clear() {
|
||||
//piCout << "PIResourcesStorage clear";
|
||||
PIVector<Section * > sv = sections.values();
|
||||
piForeach (Section * i, sv)
|
||||
delete i;
|
||||
piForeach (Section * i, sv) {
|
||||
if (i)
|
||||
i->purge();
|
||||
}
|
||||
sections.clear();
|
||||
}
|
||||
|
||||
@@ -133,7 +146,8 @@ PIResourcesStorage * PIResourcesStorage::instance() {
|
||||
PIByteArray & operator <<(PIByteArray & b, const PIResourcesStorage::__RCEntry & v) {
|
||||
PIChunkStream cs;
|
||||
cs << cs.chunk(1, v.section) << cs.chunk(2, v.name) << cs.chunk(3, v.file)
|
||||
<< cs.chunk(4, v.size) << cs.chunk(5, v.offset) << cs.chunk(6, v.flags);
|
||||
<< cs.chunk(4, v.size) << cs.chunk(5, v.offset) << cs.chunk(6, v.flags)
|
||||
<< cs.chunk(7, v.alias);
|
||||
b << cs.data();
|
||||
return b;
|
||||
}
|
||||
@@ -150,6 +164,7 @@ PIByteArray & operator >>(PIByteArray & b, PIResourcesStorage::__RCEntry & v) {
|
||||
case 4: cs.get(v.size); break;
|
||||
case 5: cs.get(v.offset); break;
|
||||
case 6: cs.get(v.flags); break;
|
||||
case 7: cs.get(v.alias); break;
|
||||
}
|
||||
}
|
||||
return b;
|
||||
|
||||
@@ -35,13 +35,16 @@ public:
|
||||
Section();
|
||||
~Section();
|
||||
void add(const Section & s);
|
||||
void purge();
|
||||
PIMap<PIString, PIByteArray * > entries;
|
||||
};
|
||||
|
||||
struct __RCEntry {
|
||||
__RCEntry(const PIString & s = PIString(), const PIString & n = PIString(), const PIString & f = PIString(), llong o = 0, llong si = 0, int fl = 0) {
|
||||
__RCEntry(const PIString & s = PIString(), const PIString & n = PIString(), const PIString & a = PIString(),
|
||||
const PIString & f = PIString(), llong o = 0, llong si = 0, int fl = 0) {
|
||||
section = s;
|
||||
name = n;
|
||||
alias = a;
|
||||
file = f;
|
||||
offset = o;
|
||||
size = si;
|
||||
@@ -49,6 +52,7 @@ public:
|
||||
}
|
||||
PIString section;
|
||||
PIString name;
|
||||
PIString alias;
|
||||
PIString file;
|
||||
llong offset;
|
||||
llong size;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#include "generator.h"
|
||||
#include "piresourcesstorage.h"
|
||||
|
||||
typedef PIPair<PIString, PIString> SSPair;
|
||||
|
||||
bool generate(PIFile & file, const PIVector<ParserSection> & files) {
|
||||
if (!file.isOpened()) return false;
|
||||
@@ -12,10 +11,11 @@ bool generate(PIFile & file, const PIVector<ParserSection> & files) {
|
||||
PIString descname = "_pirc_" + fcname + "_desc_";
|
||||
PIVector<PIResourcesStorage::__RCEntry> fv;
|
||||
piForeachC (ParserSection & s, files) {
|
||||
piForeachC (SSPair & p, s.files) {
|
||||
piForeachC (ParserEntry & p, s.files) {
|
||||
PIFile f;
|
||||
if (!f.open(p.second, PIIODevice::ReadOnly)) continue;
|
||||
fv << PIResourcesStorage::__RCEntry(s.name, p.first, p.second);
|
||||
if (!f.open(p.path, PIIODevice::ReadOnly)) continue;
|
||||
//piCout << "gen" << p.name << p.alias << p.path;
|
||||
fv << PIResourcesStorage::__RCEntry(s.name, p.name, p.alias, p.path);
|
||||
}
|
||||
}
|
||||
if (fv.isEmpty()) return false;
|
||||
|
||||
@@ -7,9 +7,26 @@ PIVector<ParserSection> parse(const PIString & path) {
|
||||
PIFile f;
|
||||
if (!f.open(path, PIIODevice::ReadOnly))
|
||||
return ret;
|
||||
PIString ext = f.fileInfo().extension();
|
||||
PIString ext = f.fileInfo().extension().toLowerCase();
|
||||
//PIString fc = PIString::fromUTF8(f.readAll());
|
||||
if (ext == "conf") return parseConf(f, PIDir(f.fileInfo().dir()).absolutePath() + "/");
|
||||
PIString dir = PIDir(f.fileInfo().dir()).absolutePath() + "/";
|
||||
//piCout << dir;
|
||||
if (ext == "conf") return parseConf(f, dir);
|
||||
if (ext == "qrc") return parseQRC(f, dir);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
ParserEntry makeEntry(PIString filename, const PIString & dir) {
|
||||
ParserEntry ret;
|
||||
//ret.alias = PIFile::fileInfo(filename).name();
|
||||
ret.path = filename;
|
||||
if (!PIDir(PIFile::fileInfo(filename).dir()).isAbsolute()) {
|
||||
//piCout << "rel, add dir";
|
||||
ret.path.insert(0, dir);
|
||||
}
|
||||
//piCout << line << path;
|
||||
ret.name = filename;
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -27,13 +44,76 @@ PIVector<ParserSection> parseConf(PIFile & file, const PIString & dir) {
|
||||
ps.files.clear();
|
||||
continue;
|
||||
}
|
||||
PIString path = line;
|
||||
if (!PIDir(PIFile::fileInfo(line).dir()).isAbsolute()) {
|
||||
//piCout << "rel, add dir";
|
||||
path.insert(0, dir);
|
||||
PIString alias;
|
||||
int i = line.findLast("=");
|
||||
if (i > 0) {
|
||||
alias = line.takeMid(i + 1).trim();
|
||||
line.cutRight(1).trim();
|
||||
}
|
||||
//piCout << line;
|
||||
ps.files << PIPair<PIString, PIString>(line, path);
|
||||
ParserEntry e = makeEntry(line, dir);
|
||||
if (!alias.isEmpty())
|
||||
e.alias = alias;
|
||||
ps.files << e;
|
||||
}
|
||||
if (!ps.files.isEmpty()) ret << ps;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
PIVector<ParserSection> parseQRC(PIFile & file, const PIString & dir) {
|
||||
PIVector<ParserSection> ret;
|
||||
if (!file.isOpened()) return ret;
|
||||
ParserSection ps;
|
||||
bool is_files = false;
|
||||
while (!file.isEnd()) {
|
||||
PIString line = file.readLine().trim();
|
||||
if (line.isEmpty()) continue;
|
||||
if (line.startsWith("<qresource")) {
|
||||
if (!ps.files.isEmpty()) ret << ps;
|
||||
ps.name.clear();
|
||||
ps.files.clear();
|
||||
line.cutLeft(10);
|
||||
if (line.endsWith(">")) line.cutRight(1);
|
||||
line.trim();
|
||||
if (line.endsWith("/")) {
|
||||
is_files = false;
|
||||
continue;
|
||||
}
|
||||
is_files = true;
|
||||
if (line.startsWith("prefix")) {
|
||||
int i = line.find("=");
|
||||
if (i > 0) {
|
||||
line.cutLeft(i + 1).trim();
|
||||
if (line.startsWith("\"")) line.cutLeft(1);
|
||||
if (line.endsWith("\"")) line.cutRight(1);
|
||||
ps.name = line;
|
||||
}
|
||||
}
|
||||
//piCout << "section \"" << ps.name << "\"";
|
||||
continue;
|
||||
}
|
||||
if (line == "</qresource>") {
|
||||
is_files = false;
|
||||
continue;
|
||||
}
|
||||
if (!is_files) continue;
|
||||
if (!line.startsWith("<file")) continue;
|
||||
PIString alias = line.takeRange('<', '>', '\0');
|
||||
alias.cutLeft(4).trim();
|
||||
if (alias.startsWith("alias")) {
|
||||
int i = alias.find("=");
|
||||
if (i > 0) {
|
||||
alias.cutLeft(i + 1).trim();
|
||||
if (alias.startsWith("\"")) alias.cutLeft(1);
|
||||
if (alias.endsWith("\"")) alias.cutRight(1);
|
||||
}
|
||||
}
|
||||
if (line.endsWith("</file>")) line.cutRight(7).trim();
|
||||
ParserEntry e = makeEntry(line, dir);
|
||||
if (!alias.isEmpty())
|
||||
e.alias = alias;
|
||||
ps.files << e;
|
||||
//piCout << "file =" << line << "alias =" << alias;
|
||||
}
|
||||
if (!ps.files.isEmpty()) ret << ps;
|
||||
return ret;
|
||||
|
||||
@@ -4,12 +4,24 @@
|
||||
#include "pidir.h"
|
||||
#include "pifile.h"
|
||||
|
||||
struct ParserEntry {
|
||||
ParserEntry(const PIString & n = PIString(), const PIString & a = PIString(), const PIString & p = PIString()) {
|
||||
name = n;
|
||||
alias = a;
|
||||
path = p;
|
||||
}
|
||||
PIString name;
|
||||
PIString alias;
|
||||
PIString path;
|
||||
};
|
||||
|
||||
struct ParserSection {
|
||||
PIString name;
|
||||
PIVector<PIPair<PIString, PIString> > files; // name, path
|
||||
PIVector<ParserEntry> files;
|
||||
};
|
||||
|
||||
PIVector<ParserSection> parse(const PIString & path);
|
||||
PIVector<ParserSection> parseConf(PIFile & file, const PIString & dir);
|
||||
PIVector<ParserSection> parseQRC(PIFile & file, const PIString & dir);
|
||||
|
||||
#endif // PIRC_PARSER_H
|
||||
|
||||
Reference in New Issue
Block a user