git-svn-id: svn://db.shs.com.ru/pip@558 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5

This commit is contained in:
2017-11-21 10:37:00 +00:00
parent fde7d7bc80
commit 11f5ebb23d
7 changed files with 140 additions and 26 deletions

View File

@@ -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;