git-svn-id: svn://db.shs.com.ru/pip@556 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
#include "pisysteminfo.h"
|
||||
#include "pidir.h"
|
||||
#include "piprocess.h"
|
||||
#include "piresourcesstorage.h"
|
||||
#ifdef WINDOWS
|
||||
# include <winsock2.h>
|
||||
extern FILETIME __pi_ftjan1970;
|
||||
@@ -278,6 +279,7 @@ PIInit::PIInit() {
|
||||
PIInit::~PIInit() {
|
||||
if (file_charset) delete file_charset;
|
||||
file_charset = 0;
|
||||
PIResourcesStorage::instance()->clear();
|
||||
#ifdef WINDOWS
|
||||
WSACleanup();
|
||||
//if (setTimerResolution) setTimerResolutionAddr(PRIVATE->prev_res, TRUE, &(PRIVATE->prev_res));
|
||||
|
||||
@@ -72,13 +72,11 @@ bool PIDir::operator ==(const PIDir & d) const {
|
||||
|
||||
bool PIDir::isAbsolute() const {
|
||||
if (path_.isEmpty()) return false;
|
||||
/*#ifdef WINDOWS
|
||||
if (path_.size_s() < 2) return false;
|
||||
return (path_.mid(1, 2).contains(":"));
|
||||
#else
|
||||
return (path_[0] == separator);
|
||||
#endif*/
|
||||
return (path_[0] == separator);
|
||||
if (path_[0] == separator) return true;
|
||||
#ifdef WINDOWS
|
||||
return (path_.mid(1, 1) == ":");
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -5,6 +5,6 @@
|
||||
#define PIP_VERSION_MAJOR 1
|
||||
#define PIP_VERSION_MINOR 1
|
||||
#define PIP_VERSION_REVISION 1
|
||||
#define PIP_VERSION_SUFFIX ""
|
||||
#define PIP_VERSION_SUFFIX "_alpha"
|
||||
|
||||
#endif // PIVERSION_H
|
||||
|
||||
50
src_main/resources/piresources.cpp
Normal file
50
src_main/resources/piresources.cpp
Normal file
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Resources subsystem
|
||||
Copyright (C) 2017 Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
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, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
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 for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "piresources.h"
|
||||
#include "piresourcesstorage.h"
|
||||
|
||||
|
||||
PIResources::PIResources() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
PIByteArray PIResources::get(const PIString & section, const PIString & name) {
|
||||
return PIResourcesStorage::instance()->get(section, name);
|
||||
}
|
||||
|
||||
|
||||
PIByteArray PIResources::get(const PIString & name) {
|
||||
return PIResourcesStorage::instance()->get(name);
|
||||
}
|
||||
|
||||
|
||||
void PIResources::dump() {
|
||||
PIMap<PIString, PIResourcesStorage::Section * > & sm(PIResourcesStorage::instance()->sections);
|
||||
PIMap<PIString, PIResourcesStorage::Section * >::iterator si;
|
||||
for (si = sm.begin(); si != sm.end(); ++si) {
|
||||
piCout << "Section [" << si.key() << "]";
|
||||
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";
|
||||
}
|
||||
}
|
||||
}
|
||||
42
src_main/resources/piresources.h
Normal file
42
src_main/resources/piresources.h
Normal file
@@ -0,0 +1,42 @@
|
||||
/*! \file piresources.h
|
||||
* \brief Resources subsystem
|
||||
*/
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Resources subsystem
|
||||
Copyright (C) 2017 Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
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, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
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 for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PIRESOURCES_H
|
||||
#define PIRESOURCES_H
|
||||
|
||||
#include "pistring.h"
|
||||
|
||||
class PIResources {
|
||||
public:
|
||||
|
||||
//! Encrypt given data "data", result size will be increased by \a sizeCrypt()
|
||||
static PIByteArray get(const PIString & section, const PIString & name);
|
||||
static PIByteArray get(const PIString & name);
|
||||
|
||||
static void dump();
|
||||
|
||||
private:
|
||||
PIResources();
|
||||
|
||||
};
|
||||
|
||||
#endif // PIRESOURCES_H
|
||||
156
src_main/resources/piresourcesstorage.cpp
Normal file
156
src_main/resources/piresourcesstorage.cpp
Normal file
@@ -0,0 +1,156 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Resources subsystem
|
||||
Copyright (C) 2017 Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
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, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
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 for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "piresourcesstorage.h"
|
||||
#include "pichunkstream.h"
|
||||
|
||||
|
||||
PIResourcesStorage::Section::Section() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
PIResourcesStorage::Section::~Section() {
|
||||
//piCout << "~Section";
|
||||
PIVector<PIByteArray * > bav = entries.values();
|
||||
piForeach (PIByteArray * i, bav) {
|
||||
if (i)
|
||||
delete i;
|
||||
}
|
||||
entries.clear();
|
||||
}
|
||||
|
||||
|
||||
void PIResourcesStorage::Section::add(const PIResourcesStorage::Section & s) {
|
||||
PIMap<PIString, PIByteArray * >::const_iterator i;
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
PIResourcesStorage::PIResourcesStorage() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
PIResourcesStorage::~PIResourcesStorage() {
|
||||
clear();
|
||||
}
|
||||
|
||||
|
||||
void PIResourcesStorage::registerSection(const PIString & section_name, const PIResourcesStorage::Section & data) {
|
||||
Section * s = sections.value(section_name, 0);
|
||||
if (!s) {
|
||||
s = new Section();
|
||||
sections[section_name] = s;
|
||||
}
|
||||
s->add(data);
|
||||
}
|
||||
|
||||
|
||||
void PIResourcesStorage::registerSection(const uchar * rc_data, const uchar * rc_desc, int rc_desc_size) {
|
||||
PIByteArray dba(rc_desc, rc_desc_size);
|
||||
PIVector<PIResourcesStorage::__RCEntry> el;
|
||||
dba >> el;
|
||||
PIMap<PIString, PIVector<PIResourcesStorage::__RCEntry> > ebs;
|
||||
piForeachC (PIResourcesStorage::__RCEntry & e, el) {
|
||||
ebs[e.section] << e;
|
||||
}
|
||||
PIMap<PIString, PIVector<PIResourcesStorage::__RCEntry> >::iterator it;
|
||||
for (it = ebs.begin(); it != ebs.end(); ++it) {
|
||||
PIResourcesStorage::Section s;
|
||||
PIVector<PIResourcesStorage::__RCEntry> & itv(it.value());
|
||||
piForeachC (PIResourcesStorage::__RCEntry & e, itv) {
|
||||
//piCout << "add" << e.name << PIString::readableSize(e.size);
|
||||
PIByteArray * eba = new PIByteArray(&(rc_data[e.offset]), e.size);
|
||||
s.entries[e.name] = eba;
|
||||
}
|
||||
registerSection(it.key(), s);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
PIResourcesStorage::Section * PIResourcesStorage::section(const PIString & section_name) const {
|
||||
return sections.value(section_name, 0);
|
||||
}
|
||||
|
||||
|
||||
PIByteArray PIResourcesStorage::get(const PIString & section_name, const PIString & entry_name) const {
|
||||
Section * s = sections.value(section_name, 0);
|
||||
if (!s) return PIByteArray();
|
||||
PIByteArray * ba = s->entries.value(entry_name, 0);
|
||||
if (!ba) return PIByteArray();
|
||||
return *ba;
|
||||
}
|
||||
|
||||
|
||||
PIByteArray PIResourcesStorage::get(const PIString & entry_name) const {
|
||||
PIMap<PIString, Section * >::const_iterator i;
|
||||
for (i = sections.begin(); i != sections.end(); ++i) {
|
||||
if (!i.value()) continue;
|
||||
PIByteArray * ba = i.value()->entries.value(entry_name, 0);
|
||||
if (!ba) continue;
|
||||
return *ba;
|
||||
}
|
||||
return PIByteArray();
|
||||
}
|
||||
|
||||
|
||||
void PIResourcesStorage::clear() {
|
||||
//piCout << "PIResourcesStorage clear";
|
||||
PIVector<Section * > sv = sections.values();
|
||||
piForeach (Section * i, sv)
|
||||
delete i;
|
||||
sections.clear();
|
||||
}
|
||||
|
||||
|
||||
PIResourcesStorage * PIResourcesStorage::instance() {
|
||||
static PIResourcesStorage * ret = new PIResourcesStorage();
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
b << cs.data();
|
||||
return b;
|
||||
}
|
||||
|
||||
|
||||
PIByteArray & operator >>(PIByteArray & b, PIResourcesStorage::__RCEntry & v) {
|
||||
PIByteArray ba; b >> ba;
|
||||
PIChunkStream cs(ba);
|
||||
while (!cs.atEnd()) {
|
||||
switch (cs.read()) {
|
||||
case 1: cs.get(v.section); break;
|
||||
case 2: cs.get(v.name); break;
|
||||
case 3: cs.get(v.file); break;
|
||||
case 4: cs.get(v.size); break;
|
||||
case 5: cs.get(v.offset); break;
|
||||
case 6: cs.get(v.flags); break;
|
||||
}
|
||||
}
|
||||
return b;
|
||||
}
|
||||
79
src_main/resources/piresourcesstorage.h
Normal file
79
src_main/resources/piresourcesstorage.h
Normal file
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Resources subsystem
|
||||
Copyright (C) 2017 Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
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, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
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 for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PIRESOURCES_P_H
|
||||
#define PIRESOURCES_P_H
|
||||
|
||||
#include "pistring.h"
|
||||
#include "pimap.h"
|
||||
|
||||
class PIResources;
|
||||
|
||||
class PIResourcesStorage {
|
||||
friend class PIResources;
|
||||
public:
|
||||
|
||||
static PIResourcesStorage * instance();
|
||||
|
||||
struct Section {
|
||||
Section();
|
||||
~Section();
|
||||
void add(const Section & s);
|
||||
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) {
|
||||
section = s;
|
||||
name = n;
|
||||
file = f;
|
||||
offset = o;
|
||||
size = si;
|
||||
flags = fl;
|
||||
}
|
||||
PIString section;
|
||||
PIString name;
|
||||
PIString file;
|
||||
llong offset;
|
||||
llong size;
|
||||
int flags;
|
||||
};
|
||||
|
||||
void registerSection(const PIString & section_name, const Section & data);
|
||||
void registerSection(const uchar * rc_data, const uchar * rc_desc, int rc_desc_size);
|
||||
Section * section(const PIString & section_name) const;
|
||||
PIByteArray get(const PIString & section_name, const PIString & entry_name) const;
|
||||
PIByteArray get(const PIString & entry_name) const;
|
||||
|
||||
void clear();
|
||||
|
||||
private:
|
||||
PIResourcesStorage();
|
||||
~PIResourcesStorage();
|
||||
|
||||
PIMap<PIString, Section * > sections;
|
||||
|
||||
};
|
||||
|
||||
|
||||
PIByteArray & operator <<(PIByteArray & b, const PIResourcesStorage::__RCEntry & v);
|
||||
PIByteArray & operator >>(PIByteArray & b, PIResourcesStorage::__RCEntry & v);
|
||||
|
||||
|
||||
#endif // PIRESOURCES_H
|
||||
Reference in New Issue
Block a user