diff --git a/CMakeLists.txt b/CMakeLists.txt index 08deeeb2..048966c7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,11 +28,12 @@ macro(gather_src DIR CPP H H_P) list(APPEND ${H_P} ${PHS}) endmacro() -set(PIP_SRC_MAIN "src_main") -set(PIP_SRC_CRYPT "src_crypt") +set(PIP_SRC_MAIN "src_main") +set(PIP_SRC_CRYPT "src_crypt") set(PIP_SRC_COMPRESS "src_compress") -set(PIP_SRC_USB "src_usb") -set(PIP_SRC_FFTW "src_fftw") +set(PIP_SRC_USB "src_usb") +set(PIP_SRC_FFTW "src_fftw") +#set(PIP_SRC_RESOURCES "src_resources") set(PIP_LIBS_TARGETS pip) set(LIBS_MAIN) set(LIBS_STATUS) @@ -85,7 +86,7 @@ endif() # Sources # Main lib -set(PIP_FOLDERS "." "core" "containers" "thread" "system" "io" "console" "math" "code" "geo") +set(PIP_FOLDERS "." "core" "containers" "thread" "system" "io" "console" "math" "code" "geo" "resources") include_directories("${PIP_SRC_MAIN}") foreach(F ${PIP_FOLDERS}) include_directories("${PIP_SRC_MAIN}/${F}") @@ -104,6 +105,9 @@ gather_src("${PIP_SRC_USB}" CPP_LIB_USB HDRS PHDRS) # FFTW lib gather_src("${PIP_SRC_FFTW}" CPP_LIB_FFTW HDRS PHDRS) +# Resources lib +#gather_src("${PIP_SRC_RESOURCES}" CPP_LIB_RESOURCES HDRS PHDRS) + # Check Bessel functions set(CMAKE_REQUIRED_INCLUDES math.h) @@ -357,8 +361,14 @@ else() endif() +# Add resource system +#add_library(pip_resources SHARED ${CPP_LIB_RESOURCES}) +#target_link_libraries(pip_resources pip ) +#list(APPEND PIP_LIBS_TARGETS pip_resources) + + # Test program -add_executable(pip_test "main.cpp") +add_executable(pip_test "main.cpp" "1.cpp") target_link_libraries(pip_test pip pip_compress) @@ -407,6 +417,7 @@ add_subdirectory("${PIP_SRC_MAIN}/auxiliary/piterminal") add_subdirectory("utils/system_test") add_subdirectory("utils/remote_console") add_subdirectory("utils/code_model_generator") +add_subdirectory("utils/resources_compiler") add_subdirectory("utils/udp_file_transfer") if(sodium_FOUND) add_subdirectory("utils/system_daemon") diff --git a/FindPIP.cmake b/FindPIP.cmake index 00ee988d..b1b5fb5c 100644 --- a/FindPIP.cmake +++ b/FindPIP.cmake @@ -5,8 +5,10 @@ if(WIN32) find_library(PIP_USB_LIBRARY pip_usb ${MINGW_LIB}) find_library(PIP_CRYPT_LIBRARY pip_crypt ${MINGW_LIB}) find_library(PIP_FFTW_LIBRARY pip_fftw ${MINGW_LIB}) + find_library(PIP_COMPRESS_LIBRARY pip_compress ${MINGW_LIB}) set(PIP_INCLUDES ${MINGW_INCLUDE}/pip) set(PIP_CMG ${MINGW_BIN}/pip_cmg.exe) + set(PIP_RC ${MINGW_BIN}/pip_rc.exe) else() set(_DIR_ "/usr") if(APPLE) @@ -16,6 +18,7 @@ else() find_library(PIP_USB_LIBRARY pip_usb ${_DIR_}/lib/) find_library(PIP_CRYPT_LIBRARY pip_crypt ${_DIR_}/lib/) find_library(PIP_FFTW_LIBRARY pip_fftw ${_DIR_}/lib/) + find_library(PIP_COMPRESS_LIBRARY pip_compress ${_DIR_}/lib/) if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") find_library(DL_LIBRARY dl) list(APPEND PIP_LIBRARY ${DL_LIBRARY}) @@ -27,6 +30,7 @@ else() endif() set(PIP_INCLUDES ${_DIR_}/include/pip) set(PIP_CMG ${_DIR_}/bin/pip_cmg) + set(PIP_RC ${_DIR_}/bin/pip_rc) endif() if(NOT PIP_VERSION) diff --git a/PIPMacros.cmake b/PIPMacros.cmake index ba1f1728..93d10333 100644 --- a/PIPMacros.cmake +++ b/PIPMacros.cmake @@ -53,3 +53,40 @@ macro(pip_code_model RESULT) VERBATIM) endmacro() +macro(pip_resources RESULT INPUT) + #message(STATUS "src = ${CCM_SRC}") + #message(STATUS "result = ${RESULT}") + #message(STATUS "options = \"${CCM_OPTS}\"") + get_filename_component(RC_OUT "${INPUT}" NAME_WE) + set(RC_FILE "pirc_${RC_OUT}.cpp") + set(RC_OUT ${CMAKE_CURRENT_BINARY_DIR}/${RC_FILE}) + set(${RESULT} ${${RESULT}} ${RC_OUT}) + set(CCM_FILES) + #if (ABS) + if(IS_ABSOLUTE "${INPUT}") + set(RC_FILES "${INPUT}") + else() + set(RC_FILES "${CMAKE_CURRENT_SOURCE_DIR}/${INPUT}") + endif() + #else() + # foreach(csrc ${CCM_SRC}) + # list(APPEND CCM_FILES "${CMAKE_CURRENT_SOURCE_DIR}/${csrc}") + # endforeach() + #endif() + #message(STATUS "CCM = ${RESULT}") + if(NOT DEFINED PIP_DLL_DIR) + set(PIP_DLL_DIR ${CMAKE_CURRENT_BINARY_DIR}) + endif() + #message("PIP_RC: ${PIP_RC}") + #message("RC_OUT: ${RC_OUT}") + #message("RC_FILES: ${RC_FILES}") + #message("PIP_DLL_DIR: ${PIP_DLL_DIR}") + add_custom_command(OUTPUT ${RC_OUT} + COMMAND ${PIP_RC} + ARGS -i ${RC_FILES} -o ${RC_OUT} + DEPENDS ${RC_FILES} + WORKING_DIRECTORY ${PIP_DLL_DIR} + COMMENT "Generating ${RC_FILE}" + VERBATIM) +endmacro() + diff --git a/main.cpp b/main.cpp index 1d1072cd..0d006b7f 100644 --- a/main.cpp +++ b/main.cpp @@ -11,7 +11,7 @@ int main(int argc, char *argv[]) { ba = piDecompress(ba); piCout << "decompress" << ba.toHex(); piCout << PIString::fromUTF8(ba); - ba = PIByteArray(16); + ba = PIByteArray(160); piCout << ba.toHex() << ba.size(); piCout << piCompress(ba).toHex() << piCompress(ba).size(); /*PIString s = PIString::fromUTF8("hello, привет"); diff --git a/src_main/core/piinit.cpp b/src_main/core/piinit.cpp index c0e01e51..727cc539 100644 --- a/src_main/core/piinit.cpp +++ b/src_main/core/piinit.cpp @@ -25,6 +25,7 @@ #include "pisysteminfo.h" #include "pidir.h" #include "piprocess.h" +#include "piresourcesstorage.h" #ifdef WINDOWS # include 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)); diff --git a/src_main/io/pidir.cpp b/src_main/io/pidir.cpp index de8ef845..d39ff0df 100755 --- a/src_main/io/pidir.cpp +++ b/src_main/io/pidir.cpp @@ -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; } diff --git a/src_main/piversion.h b/src_main/piversion.h index 814ca432..5c9913af 100644 --- a/src_main/piversion.h +++ b/src_main/piversion.h @@ -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 diff --git a/src_main/resources/piresources.cpp b/src_main/resources/piresources.cpp new file mode 100644 index 00000000..cd799893 --- /dev/null +++ b/src_main/resources/piresources.cpp @@ -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 . +*/ + +#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 & sm(PIResourcesStorage::instance()->sections); + PIMap::iterator si; + for (si = sm.begin(); si != sm.end(); ++si) { + piCout << "Section [" << si.key() << "]"; + if (!si.value()) continue; + PIMap::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"; + } + } +} diff --git a/src_main/resources/piresources.h b/src_main/resources/piresources.h new file mode 100644 index 00000000..cec0c258 --- /dev/null +++ b/src_main/resources/piresources.h @@ -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 . +*/ + +#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 diff --git a/src_main/resources/piresourcesstorage.cpp b/src_main/resources/piresourcesstorage.cpp new file mode 100644 index 00000000..569b3516 --- /dev/null +++ b/src_main/resources/piresourcesstorage.cpp @@ -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 . +*/ + +#include "piresourcesstorage.h" +#include "pichunkstream.h" + + +PIResourcesStorage::Section::Section() { + +} + + +PIResourcesStorage::Section::~Section() { + //piCout << "~Section"; + PIVector bav = entries.values(); + piForeach (PIByteArray * i, bav) { + if (i) + delete i; + } + entries.clear(); +} + + +void PIResourcesStorage::Section::add(const PIResourcesStorage::Section & s) { + PIMap::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 el; + dba >> el; + PIMap > ebs; + piForeachC (PIResourcesStorage::__RCEntry & e, el) { + ebs[e.section] << e; + } + PIMap >::iterator it; + for (it = ebs.begin(); it != ebs.end(); ++it) { + PIResourcesStorage::Section s; + PIVector & 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::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
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; +} diff --git a/src_main/resources/piresourcesstorage.h b/src_main/resources/piresourcesstorage.h new file mode 100644 index 00000000..172dda71 --- /dev/null +++ b/src_main/resources/piresourcesstorage.h @@ -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 . +*/ + +#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 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 sections; + +}; + + +PIByteArray & operator <<(PIByteArray & b, const PIResourcesStorage::__RCEntry & v); +PIByteArray & operator >>(PIByteArray & b, PIResourcesStorage::__RCEntry & v); + + +#endif // PIRESOURCES_H