From c8dc0b010030a0b04f8f3134df972bb9ad6d89df Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Tue, 12 Nov 2013 21:58:13 +0100 Subject: [PATCH] [DEV] change idea std::u32string to std::string --- etk/Color.cpp | 24 +- etk/Color.h | 2 +- etk/Hash.h | 34 +- etk/MessageFifo.h | 2 +- etk/UChar.cpp | 16 +- etk/UChar.h | 11 +- etk/UString.cpp | 131 ++++++- etk/UString.h | 9 + etk/archive/Archive.cpp | 14 +- etk/archive/Archive.h | 44 ++- etk/archive/Zip.cpp | 10 +- etk/archive/Zip.h | 2 +- etk/math/Vector2D.cpp | 151 +++++++- etk/math/Vector2D.h | 134 +++---- etk/os/FSNode.cpp | 767 +++++++++++++++++++++------------------- etk/os/FSNode.h | 69 +++- etk/os/FSNodeRight.cpp | 54 ++- etk/os/FSNodeRight.h | 3 +- 18 files changed, 939 insertions(+), 538 deletions(-) diff --git a/etk/Color.cpp b/etk/Color.cpp index b64f53f..48fe474 100644 --- a/etk/Color.cpp +++ b/etk/Color.cpp @@ -84,7 +84,7 @@ namespace etk { return Color(*this).get(); } - template<> Color::Color(std::u32string _input) : + template<> Color::Color(std::string _input) : m_r(255), m_g(255), m_b(255), @@ -97,8 +97,7 @@ namespace etk { //std::ostringstream oss; //oss << to_u8string(_input); //oss >> std::hex >> val; - std::string plop = to_u8string(_input); - val = stoul(plop); + val = std::stoul(_input); if(_input.size() == 3) { m_r = (val & 0x00000F00) >> 8; m_r = (m_r | m_r << 4); @@ -139,20 +138,18 @@ namespace etk { && _input[1] == 'g' && _input[2] == 'b' && _input[3] == '(' ) { - /* - int32_t _red=0, _green=0, _blue=0, _alpha=0; float fred=0, fgreen=0, fblue=0, falpha=0; - if (sscanf(inputData + 4, "%u,%u,%u,%u", &_red, &_green, &_blue, &_alpha) == 4) { + if (sscanf(_input.c_str() + 4, "%u,%u,%u,%u", &_red, &_green, &_blue, &_alpha) == 4) { m_r = etk_min(0xFF, _red); m_g = etk_min(0xFF, _green); m_b = etk_min(0xFF, _blue); m_a = etk_min(0xFF, _alpha); - } else if (sscanf(inputData + 4, "%u,%u,%u", &_red, &_green, &_blue) == 3) { + } else if (sscanf(_input.c_str() + 4, "%u,%u,%u", &_red, &_green, &_blue) == 3) { m_r = etk_min(0xFF, _red); m_g = etk_min(0xFF, _green); m_b = etk_min(0xFF, _blue); - } else if (sscanf(inputData + 4, "%f%%,%f%%,%f%%,%f%%", &fred, &fgreen, &fblue, &falpha) == 4) { + } else if (sscanf(_input.c_str() + 4, "%f%%,%f%%,%f%%,%f%%", &fred, &fgreen, &fblue, &falpha) == 4) { fred = etk_avg(0.0, fred, 1.0); fgreen = etk_avg(0.0, fgreen, 1.0); fblue = etk_avg(0.0, fblue, 1.0); @@ -161,7 +158,7 @@ namespace etk { m_g = (uint8_t)(fgreen * 255.); m_b = (uint8_t)(fblue * 255.); m_a = (uint8_t)(falpha * 255.); - } else if (sscanf(inputData + 4, "%f%%,%f%%,%f%%", &fred, &fgreen, &fblue) == 3) { + } else if (sscanf(_input.c_str() + 4, "%f%%,%f%%,%f%%", &fred, &fgreen, &fblue) == 3) { fred = etk_avg(0.0, fred, 1.0); fgreen= etk_avg(0.0, fgreen, 1.0); fblue = etk_avg(0.0, fblue, 1.0); @@ -169,15 +166,13 @@ namespace etk { m_g = (uint8_t)(fgreen * 255.); m_b = (uint8_t)(fblue * 255.); } else { - TK_ERROR(" pb in parsing the color : \"" << inputData << "\" ==> unknown methode ..."); + TK_ERROR(" pb in parsing the color : \"" << _input << "\" ==> unknown methode ..."); } - */ } else { bool findIt = false; - std::string tmputf8string = to_u8string(_input); // direct named color ... for (esize_t iii=0; iii " << *this); } - template<> Color::Color(std::u32string _input) - { + template<> Color::Color(std::string _input) { etk::Color tmpColor(_input); *this = tmpColor; } diff --git a/etk/Color.h b/etk/Color.h index e5b961c..feff2a1 100644 --- a/etk/Color.h +++ b/etk/Color.h @@ -34,7 +34,7 @@ namespace etk { }; Color(const etk::Color& _obj) { set(_obj.r(), _obj.g(), _obj.b(), _obj.a()); }; Color(const etk::Color& _obj) { set(_obj.r(), _obj.g(), _obj.b(), _obj.a()); }; - Color(std::u32string _input); + Color(std::string _input); ~Color(void) { }; Color& operator=(const etk::Color& _input) { diff --git a/etk/Hash.h b/etk/Hash.h index a4ae4f1..db5c38f 100644 --- a/etk/Hash.h +++ b/etk/Hash.h @@ -21,9 +21,9 @@ namespace etk { template class HashData { public: - std::u32string m_key; //!< name of the current hash + std::string m_key; //!< name of the current hash MY_TYPE m_value; //!< data of the current Hash - HashData(const std::u32string& _key, const MY_TYPE& _val) : + HashData(const std::string& _key, const MY_TYPE& _val) : m_key(_key), m_value(_val) { // nothing to do ... @@ -45,7 +45,7 @@ namespace etk { * @brief Remove all entry in the Hash table */ void clear(void) { - for (int32_t iii=0; iiim_key << "' with '" << _key << "'" ); if (m_data[iii]->m_key == _key) { @@ -75,7 +75,7 @@ namespace etk { * @param[in] _key Name of the hash requested * @return true if the element exist */ - bool exist(const std::u32string& _name) const { + bool exist(const std::string& _name) const { int64_t elementId = getId(_name); //TK_INFO(" Exist ? '" << _name << "' id=" << elementId ); if (elementId<0) { @@ -90,7 +90,7 @@ namespace etk { * @param[in] _key Name of the hash requested * @return Reference on the Element */ - MY_TYPE& get(const std::u32string& _key) const { + MY_TYPE& get(const std::string& _key) const { static MY_TYPE g_error; int64_t elementId = getId(_key); if (elementId<0) { @@ -104,14 +104,14 @@ namespace etk { * @param[in] _key Name of the hash requested * @return An reference on the copy of selected element */ - MY_TYPE& operator[] (const std::u32string& _key) { + MY_TYPE& operator[] (const std::string& _key) { return get(_key); } - const MY_TYPE& operator[] (const std::u32string& _key) const { + const MY_TYPE& operator[] (const std::string& _key) const { return get(_key); } - void add(const std::u32string& _key, const MY_TYPE& _value) { + void add(const std::string& _key, const MY_TYPE& _value) { int64_t elementId = getId(_key); if (elementId <0) { HashData* tmp = new HashData(_key, _value); @@ -124,10 +124,10 @@ namespace etk { } m_data[elementId]->m_value = _value; } - void set(const std::u32string& _key, const MY_TYPE& _value) { + void set(const std::string& _key, const MY_TYPE& _value) { add(_key, _value); } - void remove(const std::u32string& _key) { + void remove(const std::string& _key) { int64_t elementId = getId(_key); if (elementId <0) { //nothing to do ==> not existed @@ -144,13 +144,13 @@ namespace etk { esize_t size(void) const { return m_data.size(); } - MY_TYPE& operator[] (esize_t _pos) { + MY_TYPE& operator[] (size_t _pos) { return getValue(_pos); } - const MY_TYPE& operator[] (esize_t _pos) const { + const MY_TYPE& operator[] (size_t _pos) const { return getValue(_pos); } - const std::u32string& getKey(esize_t _pos) const { + const std::string& getKey(size_t _pos) const { // NOTE :Do not change log level, this generate error only in debug mode #if DEBUG_LEVEL > 2 if(_pos>m_data.size()){ @@ -159,7 +159,7 @@ namespace etk { #endif return m_data[_pos]->m_key; } - const MY_TYPE& getValue(esize_t _pos) const { + const MY_TYPE& getValue(size_t _pos) const { // NOTE :Do not change log level, this generate error only in debug mode #if DEBUG_LEVEL > 2 if(_pos>m_data.size()){ @@ -168,7 +168,7 @@ namespace etk { #endif return m_data[_pos]->m_value; } - MY_TYPE& getValue(esize_t _pos) { + MY_TYPE& getValue(size_t _pos) { // NOTE :Do not change log level, this generate error only in debug mode #if DEBUG_LEVEL > 2 if(_pos>m_data.size()){ diff --git a/etk/MessageFifo.h b/etk/MessageFifo.h index e299dfa..9b3109b 100644 --- a/etk/MessageFifo.h +++ b/etk/MessageFifo.h @@ -45,7 +45,7 @@ namespace etk // copy element : _data = m_data[0]; // remove element : - m_data.erase(0); + m_data.erase(m_data.begin()); // remove lock m_mutex.unLock(); return true; diff --git a/etk/UChar.cpp b/etk/UChar.cpp index 41f2f32..74087c7 100644 --- a/etk/UChar.cpp +++ b/etk/UChar.cpp @@ -15,6 +15,14 @@ #include #include +const char32_t etk::UChar::Null('\0'); +const char32_t etk::UChar::Return('\n'); +const char32_t etk::UChar::CarrierReturn('\r'); +const char32_t etk::UChar::Tabulation('\t'); +const char32_t etk::UChar::Suppress((const char)127); +const char32_t etk::UChar::Delete((const char)8); +const char32_t etk::UChar::Space(' '); +const char32_t etk::UChar::Escape((const char)27); bool etk::isWhiteChar(char32_t _val) { if( _val == ' ' @@ -210,14 +218,6 @@ char32_t etk::setUtf8(const char* _input) { } #if 0 -const char32_t char32_t::Null('\0'); -const char32_t char32_t::Return('\n'); -const char32_t char32_t::CarrierReturn('\r'); -const char32_t char32_t::Tabulation('\t'); -const char32_t char32_t::Suppress((const char)127); -const char32_t char32_t::Delete((const char)8); -const char32_t char32_t::Space(' '); -const char32_t char32_t::Escape((const char)27); diff --git a/etk/UChar.h b/etk/UChar.h index 28143e3..8a6c651 100644 --- a/etk/UChar.h +++ b/etk/UChar.h @@ -38,7 +38,16 @@ namespace etk { REGEXP_OPCODE_NO_CHAR,/* \@ */ REGEXP_OPCODE_ERROR, // not used }; - + namespace UChar { + extern const char32_t Null; //!< '\0' + extern const char32_t Return; //!< '\n' + extern const char32_t CarrierReturn; //!< '\r' CR + extern const char32_t Tabulation; //!< '\t' TAB + extern const char32_t Suppress; //!< BS (SUPPRESS) + extern const char32_t Delete; //!< DEL + extern const char32_t Space; //!< ' ' SPACE + extern const char32_t Escape; //!< ESC Escape + }; #if 0 class UChar : public char32_t{ public: // classic unicar code : diff --git a/etk/UString.cpp b/etk/UString.cpp index f34f03a..569f02e 100644 --- a/etk/UString.cpp +++ b/etk/UString.cpp @@ -13,6 +13,23 @@ #undef __class__ #define __class__ "std::u32string" +etk::CCout& etk::operator <<(etk::CCout& _os, const std::string& _obj) { + _os << _obj.c_str(); + return _os; +} + +etk::CCout& etk::operator <<(etk::CCout& _os, const std::vector& _obj) { + _os << "{"; + for (int32_t iii=0; iii< _obj.size(); iii++) { + if (iii>0) { + _os << " ~ "; + } + _os << _obj[iii]; + } + _os << "}"; + return _os; +} + etk::CCout& etk::operator <<(etk::CCout& _os, const std::u32string& _obj) { _os << to_u8string(_obj).c_str(); return _os; @@ -204,6 +221,13 @@ bool compare_no_case(const std::string& _obj, const std::string& _val) { return true; } +std::string to_lower(const std::string& _obj) { + std::string out; + for(size_t iii=0 ; iii<_obj.size() ; iii++) { + out.push_back(tolower(_obj[iii])); + } + return out; +} std::u32string to_lower(const std::u32string& _obj) { std::u32string out; for(size_t iii=0 ; iii<_obj.size() ; iii++) { @@ -212,6 +236,14 @@ std::u32string to_lower(const std::u32string& _obj) { return out; } +std::string to_upper(const std::string& _obj) { + std::string out; + for(size_t iii=0 ; iii<_obj.size() ; iii++) { + out.push_back(toupper(_obj[iii])); + } + return out; +} + std::u32string to_upper(const std::u32string& _obj) { std::u32string out; for(size_t iii=0 ; iii<_obj.size() ; iii++) { @@ -220,6 +252,33 @@ std::u32string to_upper(const std::u32string& _obj) { return out; } +bool end_with(const std::string& _obj, const std::string& _val, bool _caseSensitive) { + if (_val.size() == 0) { + return false; + } + if (_val.size() > _obj.size()) { + return false; + } + if (true == _caseSensitive) { + for( int64_t iii=_val.size()-1, jjj=_obj.size()-1; + iii>=0 && jjj>=0; + iii--, jjj--) { + if (_obj[jjj] != _val[iii]) { + return false; + } + } + return true; + } + for( int64_t iii=_val.size()-1, jjj=_obj.size()-1; + iii>=0 && jjj>=0; + iii--, jjj--) { + if (tolower(_val[iii]) != tolower(_obj[jjj])) { + return false; + } + } + return true; +} + bool end_with(const std::u32string& _obj, const std::u32string& _val, bool _caseSensitive) { if (_val.size() == 0) { return false; @@ -247,6 +306,33 @@ bool end_with(const std::u32string& _obj, const std::u32string& _val, bool _case return true; } +bool start_with(const std::string& _obj, const std::string& _val, bool _caseSensitive) { + if (_val.size() == 0) { + return false; + } + if (_val.size() > _obj.size()) { + return false; + } + if (true == _caseSensitive) { + for( size_t iii = 0; + iii < _obj.size(); + iii++) { + if (_obj[iii] != _val[iii]) { + return false; + } + } + return true; + } + for( size_t iii = 0; + iii < _obj.size(); + iii++) { + if (tolower(_val[iii]) != tolower(_obj[iii])) { + return false; + } + } + return true; +} + bool start_with(const std::u32string& _obj, const std::u32string& _val, bool _caseSensitive) { if (_val.size() == 0) { return false; @@ -298,9 +384,38 @@ std::string replace(const std::string& _obj, char _val, char _replace) { return copy; } +std::string extract_line(const std::string& _obj, int32_t _pos) { + // search back : '\n' + size_t startPos = _obj.rfind('\n', _pos); + if (startPos == _pos) { + startPos = 0; + } else { + startPos++; + } + // search forward : '\n' + size_t stopPos = _pos; + if (_obj[_pos] != '\n') { + stopPos = _obj.find('\n', _pos); + if (stopPos == _pos) { + stopPos = _obj.size(); + } + } + if (startPos < 0) { + startPos = 0; + } else if (startPos >= _obj.size() ) { + return ""; + } + if (stopPos < 0) { + return ""; + } else if (stopPos >= _obj.size() ) { + stopPos = _obj.size(); + } + return std::string(_obj, startPos, stopPos); +} + std::u32string extract_line(const std::u32string& _obj, int32_t _pos) { // search back : '\n' - esize_t startPos = _obj.rfind('\n', _pos); + size_t startPos = _obj.rfind('\n', _pos); if (startPos == _pos) { startPos = 0; } else { @@ -327,6 +442,20 @@ std::u32string extract_line(const std::u32string& _obj, int32_t _pos) { return std::u32string(_obj, startPos, stopPos); } +std::vector string_split(const std::string& _input, char _val) { + std::vector list; + size_t lastStartPos=0; + for(size_t iii=0; iii<_input.size(); iii++) { + if (_input[iii]==_val) { + list.push_back(std::string(_input, lastStartPos, iii)); + lastStartPos = iii+1; + } + } + if (lastStartPos<_input.size()) { + list.push_back(std::string(_input, lastStartPos)); + } + return list; +} #if 0 diff --git a/etk/UString.h b/etk/UString.h index ce3e4ee..adf34b7 100644 --- a/etk/UString.h +++ b/etk/UString.h @@ -264,6 +264,8 @@ namespace etk { }; #endif + etk::CCout& operator <<(etk::CCout& _os, const std::string& _obj); + etk::CCout& operator <<(etk::CCout& _os, const std::vector& _obj); etk::CCout& operator <<(etk::CCout& _os, const std::u32string& _obj); etk::CCout& operator <<(etk::CCout& _os, const std::vector& _obj); }; @@ -310,7 +312,12 @@ bool stobool(const std::string& _str); std::u32string to_lower(const std::u32string& _obj); std::u32string to_upper(const std::u32string& _obj); +std::string to_lower(const std::string& _obj); +std::string to_upper(const std::string& _obj); + +bool end_with(const std::string& _obj, const std::string& _val, bool _caseSensitive = false); bool end_with(const std::u32string& _obj, const std::u32string& _val, bool _caseSensitive = false); +bool start_with(const std::string& _obj, const std::string& _val, bool _caseSensitive = false); bool start_with(const std::u32string& _obj, const std::u32string& _val, bool _caseSensitive = false); bool compare_no_case(const std::u32string& _obj, const std::u32string& _val); @@ -321,8 +328,10 @@ std::string replace(const std::string& _obj, char _val, char _replace); int32_t strlen(const char32_t * _data); +std::string extract_line(const std::string& _obj, int32_t _pos); std::u32string extract_line(const std::u32string& _obj, int32_t _pos); +std::vector string_split(const std::string& _input, char _val); #endif diff --git a/etk/archive/Archive.cpp b/etk/archive/Archive.cpp index d9204b8..1db0ce8 100644 --- a/etk/archive/Archive.cpp +++ b/etk/archive/Archive.cpp @@ -10,7 +10,7 @@ #include #include -const etk::Archive::Content& etk::Archive::getContent(const std::u32string& _key) const { +const etk::Archive::Content& etk::Archive::getContent(const std::string& _key) const { static const etk::Archive::Content g_error; if (m_content.exist(_key)==false) { TK_ERROR("File does not exist : " << _key); @@ -28,12 +28,12 @@ void etk::Archive::display(void) } } -etk::Archive* etk::Archive::load(const std::u32string& _fileName) { +etk::Archive* etk::Archive::load(const std::string& _fileName) { etk::Archive* output=NULL; - std::u32string tmpName = to_lower(_fileName); + std::string tmpName = to_lower(_fileName); // select the corect Loader : - if( true == end_with(tmpName, U".zip") - || true == end_with(tmpName, U".apk") ) { + if( true == end_with(tmpName, ".zip") + || true == end_with(tmpName, ".apk") ) { output = new etk::archive::Zip(_fileName); if (NULL==output) { TK_ERROR("An error occured when load archive : " << _fileName); @@ -45,7 +45,7 @@ etk::Archive* etk::Archive::load(const std::u32string& _fileName) { } -void etk::Archive::open(const std::u32string& _key) { +void etk::Archive::open(const std::string& _key) { if (m_content.exist(_key)==false) { TK_ERROR("Try open an unexistant file : '" << _key << "'"); return; @@ -57,7 +57,7 @@ void etk::Archive::open(const std::u32string& _key) { m_content[_key].increaseRef(); } -void etk::Archive::close(const std::u32string& _key) { +void etk::Archive::close(const std::string& _key) { if (m_content.exist(_key)==false) { TK_ERROR("Try close an unexistant file : '" << _key << "'"); return; diff --git a/etk/archive/Archive.h b/etk/archive/Archive.h index 52824c3..8b02dba 100644 --- a/etk/archive/Archive.h +++ b/etk/archive/Archive.h @@ -13,13 +13,10 @@ #include #include -namespace etk -{ - class Archive - { +namespace etk { + class Archive { public: - class Content - { + class Content { private: int32_t m_link; //!< number of element open on this file public: @@ -39,16 +36,21 @@ namespace etk std::vector& getDataVector(void) { return m_data; }; }; public: - Archive(const std::u32string& _fileName) : m_fileName(_fileName) { }; + Archive(const std::string& _fileName) : + m_fileName(_fileName) { + + }; virtual ~Archive(void) { }; protected: - std::u32string m_fileName; //!< File name when it came from an file + std::string m_fileName; //!< File name when it came from an file public: /** * @brief Get the current file name. * @return the requested file name. */ - const std::u32string& getFileName(void) { return m_fileName; }; + const std::string& getFileName(void) { + return m_fileName; + }; protected: etk::Hash m_content; public: @@ -56,41 +58,49 @@ namespace etk * @brief Get the number of elements * @return nb files in the archive */ - esize_t size(void) const { return m_content.size(); }; + esize_t size(void) const { + return m_content.size(); + }; /** * @brief Get the File name of the ID * @param[in] _id id of the element (must be < Size()) * @return FileName of the requested id */ - const std::u32string& getName(esize_t _id) const { return m_content.getKey(_id); }; + const std::string& getName(esize_t _id) const { + return m_content.getKey(_id); + }; /** * @brief Get the File name of the ID * @param[in] _id id of the element (must be < Size()) * @return the archive content */ - const Content& getContent(esize_t _id) const { return m_content.getValue(_id); }; + const Content& getContent(esize_t _id) const { + return m_content.getValue(_id); + }; /** * @brief Get the File name of the ID * @param[in] _key name of the file * @return FileName of the requested id */ - const Content& getContent(const std::u32string& _key) const; + const Content& getContent(const std::string& _key) const; /** * @brief Check if a file exist * @param[in] _key Name of the file * @return true if the file is present */ - bool exist(const std::u32string& _key) const { return m_content.exist(_key); }; + bool exist(const std::string& _key) const { + return m_content.exist(_key); + }; /** * @brief Load the specific file in the memory * @param[in] _key Name of the file */ - void open(const std::u32string& _key); + void open(const std::string& _key); /** * @brief Un-Load the specific file from the memory * @param[in] _key Name of the file */ - void close(const std::u32string& _key); + void close(const std::string& _key); /** * @brief Display all Element in the archive */ @@ -107,7 +117,7 @@ namespace etk * @param[in] _fileName File name of the specific archive. * @return A pointer an the specified archive, the user might delete it. */ - static Archive* load(const std::u32string& _fileName); + static Archive* load(const std::string& _fileName); /** * @brief Create an Achive with a specific name. diff --git a/etk/archive/Zip.cpp b/etk/archive/Zip.cpp index 663d9b9..fb08479 100644 --- a/etk/archive/Zip.cpp +++ b/etk/archive/Zip.cpp @@ -10,12 +10,12 @@ #include #include -etk::archive::Zip::Zip(const std::u32string& _fileName) : +etk::archive::Zip::Zip(const std::string& _fileName) : etk::Archive(_fileName), m_ctx(NULL) { /* Open the zip file */ - m_ctx = unzOpen(to_u8string(m_fileName).c_str()); + m_ctx = unzOpen(m_fileName.c_str()); if(!m_ctx) { TK_ERROR("Unable to open the zip file '" << m_fileName << "'"); return; @@ -38,7 +38,7 @@ etk::archive::Zip::Zip(const std::u32string& _fileName) : if(tmpFileName[strlen(tmpFileName) - 1] == '/' ) { // find directory ... } else { - m_content.add(to_u32string(tmpFileName), etk::Archive::Content(tmpFileInfo.uncompressed_size)); + m_content.add(tmpFileName, etk::Archive::Content(tmpFileInfo.uncompressed_size)); } /* Go the the next entry listed in the zip file. */ if((iii+1) < m_info.number_entry) { @@ -60,7 +60,7 @@ etk::archive::Zip::~Zip(void) void etk::archive::Zip::loadFile(int32_t _id) { - std::u32string fileNameRequested = m_content.getKey(_id); + std::string fileNameRequested = m_content.getKey(_id); TK_VERBOSE("Real load file : " << _id << " = '" << fileNameRequested << "'"); unzGoToFirstFile(m_ctx); @@ -74,7 +74,7 @@ void etk::archive::Zip::loadFile(int32_t _id) TK_ERROR("Could not read file info from the zip file '" << m_fileName << "'"); return; } - if (fileNameRequested == to_u32string(tmpFileName) ) { + if (fileNameRequested == tmpFileName ) { // Entry is a file, so extract it. if(unzOpenCurrentFile(m_ctx) != UNZ_OK) { TK_ERROR("Could not open file '" << fileNameRequested << "' into the zip file '" << m_fileName << "'"); diff --git a/etk/archive/Zip.h b/etk/archive/Zip.h index 00c3d1d..164d975 100644 --- a/etk/archive/Zip.h +++ b/etk/archive/Zip.h @@ -21,7 +21,7 @@ namespace etk { unzFile m_ctx; //!< mini zip context unz_global_info m_info; //!< global information of the Zip public: - Zip(const std::u32string& _fileName); + Zip(const std::string& _fileName); virtual ~Zip(void); protected: // herited functions : virtual void loadFile(int32_t _id); diff --git a/etk/math/Vector2D.cpp b/etk/math/Vector2D.cpp index 52042d1..0ac7cae 100644 --- a/etk/math/Vector2D.cpp +++ b/etk/math/Vector2D.cpp @@ -50,16 +50,49 @@ etk::CCout& etk::operator <<(etk::CCout& _os, const etk::Vector2D& _obj) namespace etk { + template<> Vector2D::operator std::string(void) const { + std::string str; + str = "("; + str += std::to_string(x()); + str += ","; + str += std::to_string(y()); + str += ")"; + return str; + } template<> Vector2D::operator std::u32string(void) const { std::u32string str; str = U"("; - str += x(); + str += to_u32string(x()); str += U","; - str += y(); + str += to_u32string(y()); str += U")"; return str; } + template<> Vector2D::Vector2D(const std::string& _str) { + m_floats[0] = false; + m_floats[1] = false; + // copy to permit to modify it : + std::string tmpStr = _str; + if (_str[0] == '(') { + tmpStr.erase(tmpStr.begin()); + } + if (*tmpStr.end() == ')') { + tmpStr.erase(tmpStr.end()); + } + size_t posComa = tmpStr.find(','); + if (posComa == 0) { + // no coma ... + // in every case, we parse the first element : + m_floats[0] = stobool(tmpStr); + m_floats[1] = m_floats[0]; + } else { + m_floats[0] = stobool(std::string(tmpStr, 0, posComa)); + tmpStr.erase(0, posComa+1); + m_floats[1] = stobool(tmpStr); + } + TK_VERBOSE("Parse : \"" << _str << "\" ==> " << *this); + } template<> Vector2D::Vector2D(const std::u32string& _str) { m_floats[0] = false; m_floats[1] = false; @@ -85,16 +118,50 @@ namespace etk { TK_VERBOSE("Parse : \"" << _str << "\" ==> " << *this); } + template<> Vector2D::operator std::string(void) const { + std::string str; + str = "("; + str += std::to_string(x()); + str += ","; + str += std::to_string(y()); + str += ")"; + return str; + } template<> Vector2D::operator std::u32string(void) const { std::u32string str; str = U"("; - str += x(); + str += to_u32string(x()); str += U","; - str += y(); + str += to_u32string(y()); str += U")"; return str; } + template<> Vector2D::Vector2D(const std::string& _str) { + m_floats[0] = 0; + m_floats[1] = 0; + // copy to permit to modify it : + std::string tmpStr = _str; + if (_str[0] == '(') { + tmpStr.erase(tmpStr.begin()); + } + if (*tmpStr.end() == ')') { + tmpStr.erase(tmpStr.end()); + } + + size_t posComa = tmpStr.find(','); + if (posComa == 0) { + // no coma ... + // in every case, we parse the first element : + m_floats[0] = stoi(tmpStr); + m_floats[1] = m_floats[0]; + } else { + m_floats[0] = stoi(std::string(tmpStr, 0, posComa)); + tmpStr.erase(0,posComa+1); + m_floats[1] = stoi(tmpStr); + } + TK_VERBOSE("Parse : \"" << _str << "\" ==> " << *this); + } template<> Vector2D::Vector2D(const std::u32string& _str) { m_floats[0] = 0; m_floats[1] = 0; @@ -121,16 +188,51 @@ namespace etk { TK_VERBOSE("Parse : \"" << _str << "\" ==> " << *this); } + template<> Vector2D::operator std::string(void) const { + std::string str; + str = "("; + str += std::to_string(x()); + str += ","; + str += std::to_string(y()); + str += ")"; + return str; + } + template<> Vector2D::operator std::u32string(void) const { std::u32string str; str = U"("; - str += x(); + str += to_u32string(x()); str += U","; - str += y(); + str += to_u32string(y()); str += U")"; return str; } + template<> Vector2D::Vector2D(const std::string& _str) + { + m_floats[0] = 0; + m_floats[1] = 0; + // copy to permit to modify it : + std::string tmpStr = _str; + if (_str[0] == '(') { + tmpStr.erase(tmpStr.begin()); + } + if (*tmpStr.end() == ')') { + tmpStr.erase(tmpStr.end()); + } + size_t posComa = tmpStr.find(','); + if (posComa == 0) { + // no coma ... + // in every case, we parse the first element : + m_floats[0] = stoi(tmpStr); + m_floats[1] = m_floats[0]; + } else { + m_floats[0] = stoi(std::string(tmpStr, 0, posComa)); + tmpStr.erase(0,posComa+1); + m_floats[1] = stoi(tmpStr); + } + TK_VERBOSE("Parse : \"" << _str << "\" ==> " << *this); + } template<> Vector2D::Vector2D(const std::u32string& _str) { m_floats[0] = 0; @@ -157,16 +259,49 @@ namespace etk { TK_VERBOSE("Parse : \"" << _str << "\" ==> " << *this); } + template<> Vector2D::operator std::string(void) const { + std::string str; + str = "("; + str += std::to_string(x()); + str += ","; + str += std::to_string(y()); + str += ")"; + return str; + } template<> Vector2D::operator std::u32string(void) const { std::u32string str; str = U"("; - str += x(); + str += to_u32string(x()); str += U","; - str += y(); + str += to_u32string(y()); str += U")"; return str; } + template<> Vector2D::Vector2D(const std::string& _str) { + m_floats[0] = 0; + m_floats[1] = 0; + // copy to permit to modify it : + std::string tmpStr = _str; + if (_str[0] == '(') { + tmpStr.erase(tmpStr.begin()); + } + if (*tmpStr.end() == ')') { + tmpStr.erase(tmpStr.end()); + } + size_t posComa = tmpStr.find(','); + if (posComa == 0) { + // no coma ... + // in every case, we parse the first element : + m_floats[0] = stof(tmpStr); + m_floats[1] = m_floats[0]; + } else { + m_floats[0] = stof(std::string(tmpStr, 0, posComa)); + tmpStr.erase(0,posComa+1); + m_floats[1] = stof(tmpStr); + } + TK_VERBOSE("Parse : \"" << _str << "\" ==> " << *this); + } template<> Vector2D::Vector2D(const std::u32string& _str) { m_floats[0] = 0; m_floats[1] = 0; diff --git a/etk/math/Vector2D.h b/etk/math/Vector2D.h index ba5c1c0..a52f13e 100644 --- a/etk/math/Vector2D.h +++ b/etk/math/Vector2D.h @@ -25,8 +25,7 @@ namespace etk /***************************************************** * Constructor *****************************************************/ - Vector2D(void) - { + Vector2D(void) { #ifdef DEBUG // in debug mode we set supid value to prevent forget of the inits ... m_floats[0] = (T)34673363; @@ -34,14 +33,14 @@ namespace etk #endif }; - Vector2D(T _x, T _y) - { + Vector2D(T _x, T _y) { m_floats[0] = _x; m_floats[1] = _y; }; Vector2D(const Vector2D& obj) { m_floats[0] = (T)obj.x(); m_floats[1] = (T)obj.y(); }; Vector2D(const Vector2D& obj) { m_floats[0] = (T)obj.x(); m_floats[1] = (T)obj.y(); }; Vector2D(const Vector2D& obj) { m_floats[0] = (T)obj.x(); m_floats[1] = (T)obj.y(); }; + Vector2D(const std::string& str); Vector2D(const std::u32string& str); ~Vector2D(void) { }; /***************************************************** @@ -173,14 +172,12 @@ namespace etk /***************************************************** * ++ operator *****************************************************/ - Vector2D& operator++() // prefix - { + Vector2D& operator++() { ++m_floats[0]; ++m_floats[1]; return *this; } - Vector2D operator++(int unused) // postfix - { + Vector2D operator++(int unused) { Vector2D result = *this; ++(*this); return result; @@ -188,184 +185,161 @@ namespace etk /***************************************************** * -- operator *****************************************************/ - Vector2D& operator--() // prefix - { + Vector2D& operator--() { --m_floats[0]; --m_floats[1]; return *this; } - - Vector2D operator--(int unused) // postfix - { + Vector2D operator--(int unused) { Vector2D result = *this; --(*this); return result; } - /** * @brief Return the dot product * @param v The other vector in the dot product */ - btScalar dot(const Vector2D& v) const - { + btScalar dot(const Vector2D& v) const { return m_floats[0] * v.m_floats[0] + m_floats[1] * v.m_floats[1]; } - /** * @brief Return the length of the vector squared */ - btScalar length2(void) const - { + btScalar length2(void) const { return dot(*this); } - /** * @brief Return the length of the vector */ - btScalar length(void) const - { + btScalar length(void) const { return btSqrt(length2()); } - /** * @brief Return the distance squared between the ends of this and another vector * This is symantically treating the vector like a point */ - btScalar distance2(const btVector3& v) const - { + btScalar distance2(const btVector3& v) const { return (v - *this).length2(); } - /** * @brief Return the distance between the ends of this and another vector * This is symantically treating the vector like a point */ - btScalar distance(const btVector3& v) const - { + btScalar distance(const btVector3& v) const { return (v - *this).length(); } - /** * @brief Normalize this vector * x^2 + y^2 + z^2 = 1 */ - Vector3D& normalize(void) - { + Vector3D& normalize(void) { return *this /= length(); } - /** * @brief Return a normalized version of this vector */ - Vector2D normalized(void) const - { + Vector2D normalized(void) const { return *this / length(); } - /** * @brief Return a vector will the absolute values of each element */ - Vector2D absolute(void) const - { + Vector2D absolute(void) const { return Vector2D( abs(m_floats[0]), abs(m_floats[1])); } - /** * @brief Return the axis with the smallest value * Note return values are 0,1,2 for x, y, or z */ - int32_t minAxis(void) const - { + int32_t minAxis(void) const { return m_floats[0] < m_floats[1] ? 0 : 1; } - /** * @brief Return the axis with the largest value * Note return values are 0,1,2 for x, y, or z */ - int32_t maxAxis(void) const - { + int32_t maxAxis(void) const { return m_floats[0] < m_floats[1] ? 1 : 0; } - - int32_t furthestAxis(void) const - { + int32_t furthestAxis(void) const { return absolute().minAxis(); } - - int32_t closestAxis(void) const - { + int32_t closestAxis(void) const { return absolute().maxAxis(); } - /** * @brief Return the x value */ - const T& getX() const { return m_floats[0]; } + const T& getX() const { + return m_floats[0]; + } /** * @brief Return the y value */ - const T& getY() const { return m_floats[1]; } + const T& getY() const { + return m_floats[1]; + } /** * @brief Set the x value */ - void setX(T _x) { m_floats[0] = _x;}; + void setX(T _x) { + m_floats[0] = _x; + }; /** * @brief Set the y value */ - void setY(T _y) { m_floats[1] = _y;}; + void setY(T _y) { + m_floats[1] = _y; + }; /** * @brief Return the x value */ - const T& x() const { return m_floats[0]; } + const T& x() const { + return m_floats[0]; + } /** * @brief Return the y value */ - const T& y() const { return m_floats[1]; } - - operator T *() { return &m_floats[0]; } - operator const T *() const { return &m_floats[0]; } - + const T& y() const { + return m_floats[1]; + } + operator T *() { + return &m_floats[0]; + } + operator const T *() const { + return &m_floats[0]; + } /** * @brief Set each element to the max of the current values and the values of another btVector3 * @param other The other btVector3 to compare with */ - void setMax(const Vector2D& other) - { + void setMax(const Vector2D& other) { btSetMax(m_floats[0], other.m_floats[0]); btSetMax(m_floats[1], other.m_floats[1]); } - /** * @brief Set each element to the min of the current values and the values of another btVector3 * @param other The other btVector3 to compare with */ - void setMin(const Vector2D& other) - { + void setMin(const Vector2D& other) { btSetMin(m_floats[0], other.m_floats[0]); btSetMin(m_floats[1], other.m_floats[1]); } - - void setValue(const T& _x, const T& _y) - { + void setValue(const T& _x, const T& _y) { m_floats[0]=_x; m_floats[1]=_y; } - - void setZero(void) - { + void setZero(void) { setValue(0,0); } - - bool isZero(void) const - { + bool isZero(void) const { return m_floats[0] == 0 && m_floats[1] == 0; } //!< string cast : + operator std::string(void) const; operator std::u32string(void) const; - //std::u32string UString(void) const { return *this; }; }; /** * @brief Debug operator To display the curent element in a Human redeable information @@ -384,14 +358,12 @@ typedef etk::Vector2D ivec2; typedef etk::Vector2D uivec2; typedef etk::Vector2D bvec2; -inline vec2 vec2ClipInt32(const vec2& val) -{ - return vec2((int32_t)val.x(), (int32_t)val.y()); +inline vec2 vec2ClipInt32(const vec2& _val) { + return vec2((int32_t)_val.x(), (int32_t)_val.y()); } -inline vec2 vec2ClipInt64(const vec2& val) -{ - return vec2((int64_t)val.x(), (int64_t)val.y()); +inline vec2 vec2ClipInt64(const vec2& _val) { + return vec2((int64_t)_val.x(), (int64_t)_val.y()); } #endif diff --git a/etk/os/FSNode.cpp b/etk/os/FSNode.cpp index 3d362e5..7c9038f 100644 --- a/etk/os/FSNode.cpp +++ b/etk/os/FSNode.cpp @@ -36,14 +36,13 @@ extern "C" { -static std::u32string simplifyPathAbstractPath(std::u32string _input) +static std::string simplifyPathAbstractPath(std::string _input) { int32_t findStartPos = _input.find('/') + 1; int32_t findPos = _input.find('/', findStartPos); //TK_DEBUG("Siplify : \"" << input << "\""); int32_t preventBadCode = 0; - while (findPos!=-1) - { + while (findPos!=0) { //TK_DEBUG(" string=\"" << input << "\""); //TK_DEBUG(" '/' @" << findPos); if (_input.size() set to zip file apk access -static std::u32string s_fileAPK = U""; -static std::u32string baseApplName = U"ewolNoName"; -static std::u32string baseRunPath = U"/"; +static std::string s_fileAPK = ""; +static std::string baseApplName = "ewolNoName"; +static std::string baseRunPath = "/"; #if defined(__TARGET_OS__Android) - static std::u32string baseFolderHome = U"/sdcard/"; // home folder - static std::u32string baseFolderData = U"assets/"; // program Data - static std::u32string baseFolderDataUser = U"/sdcard/.tmp/userData/"; // Data specific user (local modification) - static std::u32string baseFolderCache = U"/sdcard/.tmp/cache/"; // Temporary data (can be removed the next time) + static std::string baseFolderHome = "/sdcard/"; // home folder + static std::string baseFolderData = "assets/"; // program Data + static std::string baseFolderDataUser = "/sdcard/.tmp/userData/"; // Data specific user (local modification) + static std::string baseFolderCache = "/sdcard/.tmp/cache/"; // Temporary data (can be removed the next time) #elif defined(__TARGET_OS__Windows) - static std::u32string baseFolderHome = U"c:/test"; // home folder - static std::u32string baseFolderData = U"c:/test/share/"; // program Data - static std::u32string baseFolderDataUser = U"c:/test/userData/"; // Data specific user (local modification) - static std::u32string baseFolderCache = U"c:/Windows/Temp/ewol/"; // Temporary data (can be removed the next time) + static std::string baseFolderHome = "c:/test"; // home folder + static std::string baseFolderData = "c:/test/share/"; // program Data + static std::string baseFolderDataUser = "c:/test/userData/"; // Data specific user (local modification) + static std::string baseFolderCache = "c:/Windows/Temp/ewol/"; // Temporary data (can be removed the next time) #else - static std::u32string baseFolderHome = U"~"; // home folder - static std::u32string baseFolderData = U"share/"; // program Data - static std::u32string baseFolderDataUser = U"~/.tmp/userData/"; // Data specific user (local modification) - static std::u32string baseFolderCache = U"~/.tmp/cache/"; // Temporary data (can be removed the next time) + static std::string baseFolderHome = "~"; // home folder + static std::string baseFolderData = "share/"; // program Data + static std::string baseFolderDataUser = "~/.tmp/userData/"; // Data specific user (local modification) + static std::string baseFolderCache = "~/.tmp/cache/"; // Temporary data (can be removed the next time) #endif @@ -140,7 +139,7 @@ static std::u32string baseRunPath = U"/"; void etk::setBaseFolderData(const char* _folder) { #ifdef __TARGET_OS__Android - baseFolderData = U"assets/"; + baseFolderData = "assets/"; s_fileAPK = _folder; loadAPK(s_fileAPK); #else @@ -166,28 +165,26 @@ void etk::setBaseFolderCache(const char* _folder) #endif } -std::u32string l_argZero = U""; -void etk::setArgZero(const std::u32string& _val) -{ +std::string l_argZero = ""; +void etk::setArgZero(const std::string& _val) { l_argZero = _val; } - /* - On Unixes with /proc really straight and realiable way is to: - readlink("/proc/self/exe", buf, bufsize) (Linux) - readlink("/proc/curproc/file", buf, bufsize) (FreeBSD) - readlink("/proc/self/path/a.out", buf, bufsize) (Solaris) - On Unixes without /proc (i.e. if above fails): - If argv[0] starts with "/" (absolute path) this is the path. - Otherwise if argv[0] contains "/" (relative path) append it to cwd (assuming it hasn't been changed yet). - Otherwise search directories in $PATH for executable argv[0]. - Afterwards it may be reasonable to check whether the executable isn't actually a symlink. If it is resolve it relative to the symlink directory. - This step is not necessary in /proc method (at least for Linux). There the proc symlink points directly to executable. - Note that it is up to the calling process to set argv[0] correctly. It is right most of the times however there are occasions when the calling process cannot be trusted (ex. setuid executable). - On Windows: use GetModuleFileName(NULL, buf, bufsize) - */ -std::u32string getApplicationPath(void) -{ - std::u32string binaryName = U"no-name"; +/* + On Unixes with /proc really straight and realiable way is to: + readlink("/proc/self/exe", buf, bufsize) (Linux) + readlink("/proc/curproc/file", buf, bufsize) (FreeBSD) + readlink("/proc/self/path/a.out", buf, bufsize) (Solaris) + On Unixes without /proc (i.e. if above fails): + If argv[0] starts with "/" (absolute path) this is the path. + Otherwise if argv[0] contains "/" (relative path) append it to cwd (assuming it hasn't been changed yet). + Otherwise search directories in $PATH for executable argv[0]. + Afterwards it may be reasonable to check whether the executable isn't actually a symlink. If it is resolve it relative to the symlink directory. + This step is not necessary in /proc method (at least for Linux). There the proc symlink points directly to executable. + Note that it is up to the calling process to set argv[0] correctly. It is right most of the times however there are occasions when the calling process cannot be trusted (ex. setuid executable). + On Windows: use GetModuleFileName(NULL, buf, bufsize) +*/ +std::string getApplicationPath(void) { + std::string binaryName = "no-name"; char binaryCompleatePath[FILENAME_MAX]; memset(binaryCompleatePath, 0, FILENAME_MAX); #ifdef __TARGET_OS__Windows @@ -202,21 +199,21 @@ std::u32string getApplicationPath(void) // Generic Linux system readlink("/proc/self/exe", binaryCompleatePath, FILENAME_MAX); if(strlen(binaryCompleatePath) != 0) { - binaryName = to_u32string(binaryCompleatePath); + binaryName = binaryCompleatePath; return binaryName; } // generic FreeBSD system memset(binaryCompleatePath, 0, FILENAME_MAX); readlink("/proc/curproc/file", binaryCompleatePath, FILENAME_MAX); if(strlen(binaryCompleatePath) != 0) { - binaryName = to_u32string(binaryCompleatePath); + binaryName = binaryCompleatePath; return binaryName; } // generic Solaris system memset(binaryCompleatePath, 0, FILENAME_MAX); readlink("/proc/self/path/a.out", binaryCompleatePath, FILENAME_MAX); if(strlen(binaryCompleatePath) != 0) { - binaryName = to_u32string(binaryCompleatePath); + binaryName = binaryCompleatePath; return binaryName; } // now we are in a really bad case ... @@ -232,14 +229,14 @@ std::u32string getApplicationPath(void) TK_VERBOSE("Parse arg0 = '" << l_argZero << "' try add PWD"); char * basicPathPWD = getenv("PWD"); if (NULL != basicPathPWD) { - std::u32string testCompleatePath = to_u32string(basicPathPWD); - testCompleatePath += U"/"; + std::string testCompleatePath = basicPathPWD; + testCompleatePath += "/"; testCompleatePath += l_argZero; // check if the element existed : TK_VERBOSE("test path: '" << testCompleatePath << "'"); memset(binaryCompleatePath, 0, FILENAME_MAX); struct stat statProperty; - if (-1 != stat(to_u8string(testCompleatePath).c_str(), &statProperty)) { + if (-1 != stat(testCompleatePath.c_str(), &statProperty)) { //Normal case when the file does not exist ... ==> the it was in unknow mode ... binaryName = testCompleatePath; TK_VERBOSE("find real name = '" << binaryName << "'"); @@ -255,60 +252,62 @@ std::u32string getApplicationPath(void) TK_INFO("Binary name : " << binaryName); return binaryName; } +std::u32string getUApplicationPath(void) { + return to_u32string(getApplicationPath()); +} -void etk::initDefaultFolder(const char* _applName) -{ - baseApplName = to_u32string(_applName); +void etk::initDefaultFolder(const char* _applName) { + baseApplName = _applName; char cCurrentPath[FILENAME_MAX]; char * basicPath = getenv("HOME"); if (NULL == basicPath) { TK_ERROR("ERROR while trying to get the path of the home folder"); #if defined(__TARGET_OS__Windows) - baseFolderHome = U"c:/"; + baseFolderHome = "c:/"; #elif defined(__TARGET_OS__Android) - baseFolderHome = U"/sdcard"; + baseFolderHome = "/sdcard"; #else - baseFolderHome = U"~"; + baseFolderHome = "~"; #endif } else { - baseFolderHome = to_u32string(basicPath); + baseFolderHome = basicPath; } if (!getcwd(cCurrentPath, FILENAME_MAX)) { - baseRunPath = U"."; + baseRunPath = "."; } else { cCurrentPath[FILENAME_MAX - 1] = '\0'; if (cCurrentPath[0] == '/') { - baseRunPath = to_u32string(cCurrentPath+1); + baseRunPath = cCurrentPath+1; } else { - baseRunPath = to_u32string(cCurrentPath); + baseRunPath = cCurrentPath; } } TK_DBG_MODE("Find Basic running PATH : \"" << baseRunPath << "\""); #ifndef __TARGET_OS__Android - std::u32string binaryPath = getApplicationPath(); + std::string binaryPath = getApplicationPath(); binaryPath = replace(binaryPath, '\\', '/'); int32_t pos = binaryPath.rfind('/'); - std::u32string binaryName(binaryPath, pos); + std::string binaryName(binaryPath, pos); binaryPath.erase(binaryName.begin() + pos, binaryName.end()); TK_INFO("Bianry name : '" << binaryPath << "' && '" << binaryName << "'" ); #ifdef __TARGET_OS__Windows - baseFolderData = binaryPath; - baseFolderData += U"/data/"; + baseFolderData = binaryPath; + baseFolderData += "/data/"; baseFolderDataUser = binaryPath; - baseFolderDataUser += U"/user/"; + baseFolderDataUser += "/user/"; baseFolderCache = binaryPath; - baseFolderCache += U"/tmp/"; + baseFolderCache += "/tmp/"; #else // if element is installed : - baseFolderData = U"/usr/share"; + baseFolderData = "/usr/share"; baseFolderData += binaryName; - baseFolderData += U"/"; + baseFolderData += "/"; - std::u32string theoricInstalledName = U"/usr/bin"; + std::string theoricInstalledName = "/usr/bin"; theoricInstalledName += binaryName; TK_VERBOSE(" position : '" << binaryPath << "' installed position : '" << theoricInstalledName << "'"); if (binaryPath != theoricInstalledName) { @@ -316,22 +315,22 @@ void etk::initDefaultFolder(const char* _applName) // remove bin/applName baseFolderData = binaryPath; #ifdef __TARGET_OS__MacOs - baseFolderData += U"/../../Resources/"; + baseFolderData += "/../../Resources/"; #else - baseFolderData += U"/../../share"; + baseFolderData += "/../../share"; baseFolderData += binaryName; - baseFolderData += U"/"; + baseFolderData += "/"; #endif baseFolderData = simplifyPathAbstractPath(baseFolderData); } baseFolderDataUser = baseFolderHome; - baseFolderDataUser += U"/.local/share/"; + baseFolderDataUser += "/.local/share/"; baseFolderDataUser += binaryName; - baseFolderDataUser += U"/"; + baseFolderDataUser += "/"; - baseFolderCache = U"/tmp/"; + baseFolderCache = "/tmp/"; baseFolderCache += binaryName; - baseFolderCache += U"/"; + baseFolderCache += "/"; #endif #endif TK_INFO("baseFolderHome : '" << baseFolderHome << "'"); @@ -340,15 +339,19 @@ void etk::initDefaultFolder(const char* _applName) TK_INFO("baseFolderCache : '" << baseFolderCache << "'"); } -std::u32string etk::getUserHomeFolder(void) -{ +std::string etk::getUserHomeFolder(void) { return baseFolderHome; } +std::u32string etk::getUUserHomeFolder(void) { + return to_u32string(baseFolderHome); +} -std::u32string etk::getUserRunFolder(void) -{ +std::string etk::getUserRunFolder(void) { return baseRunPath; } +std::u32string etk::getUUserRunFolder(void) { + return to_u32string(baseRunPath); +} #ifdef __TARGET_OS__Android @@ -373,8 +376,7 @@ bool etk::FSNode::loadDataZip(void) -static int32_t FSNODE_LOCAL_mkdir(const char* _path, mode_t _mode) -{ +static int32_t FSNODE_LOCAL_mkdir(const char* _path, mode_t _mode) { struct stat st; int32_t status = 0; if (stat(_path, &st) != 0) { @@ -395,8 +397,7 @@ static int32_t FSNODE_LOCAL_mkdir(const char* _path, mode_t _mode) return(status); } -static int32_t FSNODE_LOCAL_mkPath(const char* _path, mode_t _mode) -{ +static int32_t FSNODE_LOCAL_mkPath(const char* _path, mode_t _mode) { char *pp; char *sp; int status; @@ -429,8 +430,24 @@ static int32_t FSNODE_LOCAL_mkPath(const char* _path, mode_t _mode) #undef __class__ #define __class__ "FSNode" +etk::FSNode::FSNode(const std::string& _nodeName) : + m_userFileName(""), + m_type(etk::FSN_TYPE_UNKNOW), + m_typeNode(etk::FSN_UNKNOW), + m_PointerFile(NULL), + m_timeCreate(0), + m_timeModify(0), + m_timeAccess(0) +#ifdef __TARGET_OS__Android + , m_zipContent(NULL), + m_zipReadingOffset(-1) +#endif +{ + privateSetName(_nodeName); +} + etk::FSNode::FSNode(const std::u32string& _nodeName) : - m_userFileName(U""), + m_userFileName(""), m_type(etk::FSN_TYPE_UNKNOW), m_typeNode(etk::FSN_UNKNOW), m_PointerFile(NULL), @@ -478,8 +495,7 @@ void etk::FSNode::sortElementList(std::vector& _list) { } } -void etk::FSNode::privateSetName(const std::u32string& _newName) -{ +void etk::FSNode::privateSetName(const std::string& _newName) { if( NULL != m_PointerFile #ifdef __TARGET_OS__Android || NULL != m_zipContent @@ -496,15 +512,15 @@ void etk::FSNode::privateSetName(const std::u32string& _newName) m_zipReadingOffset = 0; #endif // Reset ALL DATA : - m_userFileName = U""; + m_userFileName = ""; m_type = etk::FSN_TYPE_UNKNOW; TK_DBG_MODE("1 : Set Name : \"" << _newName << "\""); // generate destination name in case of the input error - std::u32string destFilename; + std::string destFilename; if (_newName.size() == 0) { // if no name ==> go to the root Folder - destFilename = U"ROOT:"; + destFilename = "ROOT:"; } else { destFilename = _newName; } @@ -537,54 +553,54 @@ void etk::FSNode::privateSetName(const std::u32string& _newName) destFilename.erase(0, 1); #endif m_type = etk::FSN_TYPE_DIRECT; - } else if( true == start_with(destFilename, U"ROOT:") - || true == start_with(destFilename, U"root:") ) { + } else if( true == start_with(destFilename, "ROOT:") + || true == start_with(destFilename, "root:") ) { TK_DBG_MODE(" ==> detect root 2 "); destFilename.erase(0, 5); m_type = etk::FSN_TYPE_DIRECT; - if(true == start_with(destFilename, U"~")) { + if(true == start_with(destFilename, "~")) { destFilename.erase(0, 1); m_type = etk::FSN_TYPE_HOME; } - } else if( true == start_with(destFilename, U"DIRECT:") - || true == start_with(destFilename, U"direct:") ) { + } else if( true == start_with(destFilename, "DIRECT:") + || true == start_with(destFilename, "direct:") ) { TK_DBG_MODE(" ==> detect direct"); destFilename.erase(0, 7); m_type = etk::FSN_TYPE_DIRECT; - if(true == start_with(destFilename, U"~")) { + if(true == start_with(destFilename, "~")) { destFilename.erase(0, 1); m_type = etk::FSN_TYPE_HOME; } - } else if( true == start_with(destFilename, U"DATA:") - || true == start_with(destFilename, U"data:") ) { + } else if( true == start_with(destFilename, "DATA:") + || true == start_with(destFilename, "data:") ) { TK_DBG_MODE(" ==> detect data"); destFilename.erase(0, 5); m_type = etk::FSN_TYPE_DATA; - } else if( true == start_with(destFilename, U"USERDATA:") - || true == start_with(destFilename, U"userdata:") ) { + } else if( true == start_with(destFilename, "USERDATA:") + || true == start_with(destFilename, "userdata:") ) { TK_DBG_MODE(" ==> detect User-data"); destFilename.erase(0, 9); m_type = etk::FSN_TYPE_USER_DATA; - } else if( true == start_with(destFilename, U"CACHE:") - || true == start_with(destFilename, U"cache:") ) { + } else if( true == start_with(destFilename, "CACHE:") + || true == start_with(destFilename, "cache:") ) { TK_DBG_MODE(" ==> detect Cach"); destFilename.erase(0, 6); m_type = etk::FSN_TYPE_CACHE; - } else if( true == start_with(destFilename, U"THEME:") - || true == start_with(destFilename, U"theme:") ) { + } else if( true == start_with(destFilename, "THEME:") + || true == start_with(destFilename, "theme:") ) { TK_DBG_MODE(" ==> detect theme"); destFilename.erase(0, 6); m_type = etk::FSN_TYPE_THEME; - } else if(true == start_with(destFilename, U"~")) { + } else if(true == start_with(destFilename, "~")) { TK_DBG_MODE(" ==> detect home 2"); destFilename.erase(0, 1); m_type = etk::FSN_TYPE_HOME; - } else if( true == start_with(destFilename, U"HOME:") - || true == start_with(destFilename, U"home:") ) { + } else if( true == start_with(destFilename, "HOME:") + || true == start_with(destFilename, "home:") ) { TK_DBG_MODE(" ==> detect home 3"); destFilename.erase(0, 5); m_type = etk::FSN_TYPE_HOME; - if(true == start_with(destFilename, U"~")) { + if(true == start_with(destFilename, "~")) { destFilename.erase(0, 1); } } /*else if(true == destFilename.StartWith(baseRunPath)) { @@ -597,7 +613,7 @@ void etk::FSNode::privateSetName(const std::u32string& _newName) m_type = etk::FSN_TYPE_RELATIF; // we force to have the correct name : (can generate many problem otherwise ... - std::u32string tmpName = etk::getUserRunFolder() + U"/" + destFilename; + std::string tmpName = etk::getUserRunFolder() + "/" + destFilename; destFilename = tmpName; m_type = etk::FSN_TYPE_DIRECT; @@ -618,9 +634,11 @@ void etk::FSNode::privateSetName(const std::u32string& _newName) updateFileSystemProperty(); TK_DBG_MODE("6 : type : [" << m_typeNode << "] right :" << m_rights); } +void etk::FSNode::privateSetName(const std::u32string& _newName) { + privateSetName(to_u8string(_newName)); +} - -bool directCheckFile(std::u32string _tmpFileNameDirect, bool _checkInAPKIfNeeded = false) { +bool directCheckFile(std::string _tmpFileNameDirect, bool _checkInAPKIfNeeded = false) { #ifdef __TARGET_OS__Android if (true == _checkInAPKIfNeeded) { if( NULL != s_APKArchive @@ -632,12 +650,14 @@ bool directCheckFile(std::u32string _tmpFileNameDirect, bool _checkInAPKIfNeeded #endif // tmpStat Buffer : struct stat statProperty; - if (-1 == stat(to_u8string(_tmpFileNameDirect).c_str(), &statProperty)) { + if (-1 == stat(_tmpFileNameDirect.c_str(), &statProperty)) { return false; } return true; } - +bool directCheckFile(std::u32string _tmpFileNameDirect, bool _checkInAPKIfNeeded = false) { + return directCheckFile(to_u8string(_tmpFileNameDirect)); +} // Now we generate the real FS path: void etk::FSNode::generateFileSystemPath(void) { switch (m_type) { @@ -646,10 +666,9 @@ void etk::FSNode::generateFileSystemPath(void) { m_systemFileName = baseFolderHome; break; case etk::FSN_TYPE_DIRECT: - m_systemFileName = U"/"; + m_systemFileName = "/"; break; - case etk::FSN_TYPE_RELATIF: - { + case etk::FSN_TYPE_RELATIF: { // Get the command came from the running of the program : char cCurrentPath[FILENAME_MAX]; if (!getcwd(cCurrentPath, FILENAME_MAX)) { @@ -658,10 +677,10 @@ void etk::FSNode::generateFileSystemPath(void) { cCurrentPath[1] = '\0'; } cCurrentPath[FILENAME_MAX - 1] = '\0'; - m_systemFileName = to_u32string(cCurrentPath); - m_systemFileName += U"/"; - } + m_systemFileName = cCurrentPath; + m_systemFileName += "/"; break; + } case etk::FSN_TYPE_HOME: m_systemFileName = baseFolderHome; break; @@ -678,43 +697,43 @@ void etk::FSNode::generateFileSystemPath(void) { case etk::FSN_TYPE_THEME_DATA: { //std::u32string myCompleateName=baseFolderData + "/theme/"; - std::u32string themeName(U""); - std::u32string basicName(m_userFileName); + std::string themeName(""); + std::string basicName(m_userFileName); size_t firstPos = m_userFileName.find(':'); if (0 != firstPos) { // we find a theme name : We extracted it : - themeName = std::u32string(m_userFileName, 0, firstPos); - basicName = std::u32string(m_userFileName, firstPos+1); + themeName = std::string(m_userFileName, 0, firstPos); + basicName = std::string(m_userFileName, firstPos+1); } TK_DBG_MODE(" THEME party : \"" << themeName << "\" => \"" << basicName << "\""); themeName = etk::theme::getName(themeName); TK_DBG_MODE(" ==> theme Folder \"" << themeName << "\""); // search the corect folder : - if (themeName == U"") { + if (themeName == "") { TK_WARNING("no theme name detected : set it to \"default\""); - } else if (themeName != U"default") { + } else if (themeName != "default") { // Selected theme : // check in the user data : - m_systemFileName = baseFolderDataUser + U"theme/" + themeName + U"/" + basicName; + m_systemFileName = baseFolderDataUser + "theme/" + themeName + "/" + basicName; if (directCheckFile(m_systemFileName) == true) { return; } // check in the Appl data : - m_systemFileName = baseFolderData + U"theme/" + themeName + U"/" + basicName; + m_systemFileName = baseFolderData + "theme/" + themeName + "/" + basicName; if (directCheckFile(m_systemFileName, true) == true) { m_type = etk::FSN_TYPE_THEME_DATA; return; } } - themeName = U"default"; + themeName = "default"; // default theme : // check in the user data : - m_systemFileName = baseFolderDataUser + U"theme/" + themeName + U"/" + basicName; + m_systemFileName = baseFolderDataUser + "theme/" + themeName + "/" + basicName; if (true==directCheckFile(m_systemFileName)) { return; } // check in the Appl data : In every case we return this one ... - m_systemFileName = baseFolderData + U"theme/" + themeName + U"/" + basicName; + m_systemFileName = baseFolderData + "theme/" + themeName + "/" + basicName; if (true==directCheckFile(m_systemFileName, true)) { m_type = etk::FSN_TYPE_THEME_DATA; return; @@ -729,8 +748,7 @@ void etk::FSNode::generateFileSystemPath(void) { // now we get all the right if the file existed: -void etk::FSNode::updateFileSystemProperty(void) -{ +void etk::FSNode::updateFileSystemProperty(void) { // clean general properties : m_rights.clear(); m_timeCreate = 0; @@ -747,7 +765,7 @@ void etk::FSNode::updateFileSystemProperty(void) // ---------------------------------------- // = Check if it was a folder : = // ---------------------------------------- - std::u32string folderName = U"/"; + std::string folderName = "/"; if (true == m_systemFileName.endWith(folderName)) { folderName = m_systemFileName; } else { @@ -768,7 +786,7 @@ void etk::FSNode::updateFileSystemProperty(void) #endif // tmpStat Buffer : struct stat statProperty; - if (-1 == stat(to_u8string(m_systemFileName).c_str(), &statProperty)) { + if (-1 == stat(m_systemFileName.c_str(), &statProperty)) { //Normal case when the file does not exist ... ==> the it was in unknow mode ... return; } @@ -798,76 +816,87 @@ void etk::FSNode::updateFileSystemProperty(void) return; } -bool etk::FSNode::setRight(etk::FSNodeRight _newRight) -{ +bool etk::FSNode::setRight(etk::FSNodeRight _newRight) { // TODO : ... TK_ERROR("Can not set the new rights ..."); return false; } -void etk::FSNode::setName(const std::u32string& _newName) -{ +void etk::FSNode::setName(const std::string& _newName) { + privateSetName(_newName); +} +void etk::FSNode::setName(const std::u32string& _newName) { privateSetName(_newName); } -std::u32string etk::FSNode::getNameFolder(void) const { +std::string etk::FSNode::getNameFolder(void) const { size_t lastPos = m_systemFileName.rfind('/'); if (0 != lastPos) { - return std::u32string(m_systemFileName, 0, lastPos); + return std::string(m_systemFileName, 0, lastPos); } - return U""; + return ""; +} +std::u32string etk::FSNode::getUNameFolder(void) const { + return to_u32string(getNameFolder()); } -std::u32string etk::FSNode::getFileSystemName(void) const { +std::string etk::FSNode::getFileSystemName(void) const { return m_systemFileName; } +std::u32string etk::FSNode::getUFileSystemName(void) const { + return to_u32string(getFileSystemName()); +} -std::u32string etk::FSNode::getName(void) const { - std::u32string output; - switch (m_type) - { +std::string etk::FSNode::getName(void) const { + std::string output; + switch (m_type) { default: case etk::FSN_TYPE_UNKNOW: - output = U"HOME:"; + output = "HOME:"; break; case etk::FSN_TYPE_DIRECT: - output = U"/"; + output = "/"; break; case etk::FSN_TYPE_RELATIF: - output = U""; + output = ""; break; case etk::FSN_TYPE_HOME: - output = U"~"; + output = "~"; break; case etk::FSN_TYPE_DATA: - output = U"DATA:"; + output = "DATA:"; break; case etk::FSN_TYPE_USER_DATA: - output = U"USERDATA:"; + output = "USERDATA:"; break; case etk::FSN_TYPE_CACHE: - output = U"CACHE:"; + output = "CACHE:"; break; case etk::FSN_TYPE_THEME: case etk::FSN_TYPE_THEME_DATA: - output = U"THEME:"; + output = "THEME:"; break; } output += m_userFileName; return output; } - - -std::u32string etk::FSNode::getNameFile(void) const { - size_t lastPos = m_systemFileName.rfind('/'); - if (0 != lastPos) { - return std::u32string(m_systemFileName, lastPos+1); - } - return U""; +std::u32string etk::FSNode::getUName(void) const { + return to_u32string(getName()); } -std::u32string etk::FSNode::getRelativeFolder(void) const { - std::u32string tmppp = getName(); +std::string etk::FSNode::getNameFile(void) const { + size_t lastPos = m_systemFileName.rfind('/'); + if (0 != lastPos) { + return std::string(m_systemFileName, lastPos+1); + } + return ""; +} +std::u32string etk::FSNode::getUNameFile(void) const { + return to_u32string(getNameFile()); +} + +std::string etk::FSNode::getRelativeFolder(void) const { + std::string tmppp = getName(); TK_DBG_MODE("get REF folder : " << tmppp ); switch (m_typeNode) { @@ -878,8 +907,8 @@ std::u32string etk::FSNode::getRelativeFolder(void) const { TK_DBG_MODE(" ==> : " << tmppp ); return tmppp; } else { - std::u32string tmpVal = tmppp; - tmpVal += U"/"; + std::string tmpVal = tmppp; + tmpVal += "/"; TK_DBG_MODE(" ==> : " << tmppp ); return tmpVal; } @@ -895,15 +924,18 @@ std::u32string etk::FSNode::getRelativeFolder(void) const { size_t lastPos = tmppp.rfind('/'); if (0 != lastPos) { TK_DBG_MODE(" ==> : " << tmppp.extract(0, lastPos+1) ); - return std::u32string(tmppp, 0, lastPos+1); + return std::string(tmppp, 0, lastPos+1); } lastPos = tmppp.rfind(':'); if (0 != lastPos) { TK_DBG_MODE(" ==> : " << tmppp.extract(0, lastPos+1) ); - return std::u32string(tmppp, 0, lastPos+1); + return std::string(tmppp, 0, lastPos+1); } TK_DBG_MODE(" ==> : \"\"" ); - return U""; + return ""; +} +std::u32string etk::FSNode::getURelativeFolder(void) const { + return to_u32string(getRelativeFolder()); } @@ -919,31 +951,34 @@ bool etk::FSNode::touch(void) { return ret; } -bool etk::FSNode::move(const std::u32string& _path) { +bool etk::FSNode::move(const std::string& _path) { etk::FSNode tmpDst(_path); if (tmpDst.exist()==true) { tmpDst.remove(); } TK_DEBUG("Move : \"" << getFileSystemName() << "\" ==> \"" << tmpDst.getFileSystemName() << "\""); - int32_t res = rename(to_u8string(getFileSystemName()).c_str(), to_u8string(tmpDst.getFileSystemName()).c_str()); + int32_t res = rename(getFileSystemName().c_str(), tmpDst.getFileSystemName().c_str()); if (res!=0) { return false; } else { return true; } } +bool etk::FSNode::move(const std::u32string& _path) { + return move(to_u8string(_path)); +} bool etk::FSNode::remove(void) { if (getNodeType()==etk::FSN_FOLDER) { // remove the folder - if( 0!=rmdir(to_u8string(m_systemFileName).c_str()) ) { + if( 0!=rmdir(m_systemFileName.c_str()) ) { if (ENOTEMPTY == errno) { TK_ERROR("The Directory is not empty..."); } return false; } } else { - if( 0!=unlink(to_u8string(m_systemFileName).c_str()) ) { + if( 0!=unlink(m_systemFileName.c_str()) ) { return false; } } @@ -952,104 +987,102 @@ bool etk::FSNode::remove(void) { return true; } -uint64_t etk::FSNode::timeCreated(void) const -{ +uint64_t etk::FSNode::timeCreated(void) const { return m_timeCreate; } -std::u32string etk::FSNode::timeCreatedString(void) const -{ +std::string etk::FSNode::timeCreatedString(void) const { time_t tmpVal = (int32_t)m_timeCreate; - std::u32string tmpTime = to_u32string(ctime(&tmpVal)); + std::string tmpTime = ctime(&tmpVal); if (tmpTime[tmpTime.size()-1] == '\n') { tmpTime.erase(tmpTime.end()); } return tmpTime; } +std::u32string etk::FSNode::timeUCreatedString(void) const { + return to_u32string(timeCreatedString()); +} -uint64_t etk::FSNode::timeModified(void) const -{ +uint64_t etk::FSNode::timeModified(void) const { return m_timeModify; } -std::u32string etk::FSNode::timeModifiedString(void) const -{ +std::string etk::FSNode::timeModifiedString(void) const { time_t tmpVal = (int32_t)m_timeModify; - std::u32string tmpTime = to_u32string(ctime(&tmpVal)); + std::string tmpTime = ctime(&tmpVal); if (tmpTime[tmpTime.size()-1] == '\n') { tmpTime.erase(tmpTime.end()); } return tmpTime; } +std::u32string etk::FSNode::timeUModifiedString(void) const { + return to_u32string(timeModifiedString()); +} -uint64_t etk::FSNode::timeAccessed(void) const -{ +uint64_t etk::FSNode::timeAccessed(void) const { return m_timeAccess; } -std::u32string etk::FSNode::timeAccessedString(void) const -{ +std::string etk::FSNode::timeAccessedString(void) const { time_t tmpVal = (int32_t)m_timeAccess; - std::u32string tmpTime = to_u32string(ctime(&tmpVal)); + std::string tmpTime = ctime(&tmpVal); if (tmpTime[tmpTime.size()-1] == '\n') { tmpTime.erase(tmpTime.end()); } return tmpTime; } - +std::u32string etk::FSNode::timeUAccessedString(void) const { + return to_u32string(timeAccessedString()); +} /* Operator : */ -const etk::FSNode& etk::FSNode::operator= (const etk::FSNode &_obj ) -{ - if( this != &_obj ) // avoid copy to itself - { - if( NULL != m_PointerFile - #ifdef __TARGET_OS__Android - || NULL != m_zipContent - #endif - ) { - TK_ERROR("Missing close the file : " << *this); - fileClose(); - m_PointerFile = NULL; - } - #ifdef __TARGET_OS__Android - m_zipContent = NULL; - m_zipReadingOffset = 0; - #endif - std::u32string tmppp = _obj.getName(); - privateSetName(tmppp); +const etk::FSNode& etk::FSNode::operator= (const etk::FSNode &_obj ) { + // avoid copy to itself + if( this == &_obj ) { + return *this; } + if( NULL != m_PointerFile + #ifdef __TARGET_OS__Android + || NULL != m_zipContent + #endif + ) { + TK_ERROR("Missing close the file : " << *this); + fileClose(); + m_PointerFile = NULL; + } + #ifdef __TARGET_OS__Android + m_zipContent = NULL; + m_zipReadingOffset = 0; + #endif + std::string tmppp = _obj.getName(); + privateSetName(tmppp); return *this; } -bool etk::FSNode::operator== (const etk::FSNode& _obj ) const -{ - if( this != &_obj ) { - if( _obj.m_userFileName == m_userFileName - && _obj.m_systemFileName == m_systemFileName - && _obj.m_type == m_type ) { - return true; - } else { - return false; - } +bool etk::FSNode::operator== (const etk::FSNode& _obj ) const { + if( this == &_obj ) { return true; } + if( _obj.m_userFileName == m_userFileName + && _obj.m_systemFileName == m_systemFileName + && _obj.m_type == m_type ) { + return true; + } else { + return false; + } return true; } -bool etk::FSNode::operator!= (const etk::FSNode& _obj ) const -{ +bool etk::FSNode::operator!= (const etk::FSNode& _obj ) const { return !(*this == _obj); } -etk::CCout& etk::operator <<(etk::CCout &_os, const etk::FSNode &_obj) -{ +etk::CCout& etk::operator <<(etk::CCout &_os, const etk::FSNode &_obj) { _os << "[" << _obj.m_type << "]->\"" << _obj.m_userFileName << "\""; return _os; } -etk::CCout& etk::operator <<(etk::CCout &_os, const enum etk::FSNType &_obj) -{ +etk::CCout& etk::operator <<(etk::CCout &_os, const enum etk::FSNType &_obj) { switch (_obj) { case etk::FSN_TYPE_UNKNOW: @@ -1086,10 +1119,8 @@ etk::CCout& etk::operator <<(etk::CCout &_os, const enum etk::FSNType &_obj) return _os; } -etk::CCout& etk::operator <<(etk::CCout &_os, const enum etk::typeNode &_obj) -{ - switch (_obj) - { +etk::CCout& etk::operator <<(etk::CCout &_os, const enum etk::typeNode &_obj) { + switch (_obj) { case etk::FSN_UNKNOW: _os << "FSN_UNKNOW"; break; @@ -1124,18 +1155,17 @@ etk::CCout& etk::operator <<(etk::CCout &_os, const enum etk::typeNode &_obj) /* Folder specific : */ -int64_t etk::FSNode::folderCount(void) -{ +int64_t etk::FSNode::folderCount(void) { int64_t counter=0; DIR *dir = NULL; struct dirent *ent = NULL; - dir = opendir(to_u8string(m_systemFileName).c_str()); + dir = opendir(m_systemFileName.c_str()); if (dir != NULL) { // for each element in the drectory... while ((ent = readdir(dir)) != NULL) { - std::u32string tmpName(to_u32string(ent->d_name)); - if( tmpName == U"." - || tmpName == U".." ) { + std::string tmpName(ent->d_name); + if( tmpName == "." + || tmpName == ".." ) { // do nothing ... continue; } @@ -1148,8 +1178,8 @@ int64_t etk::FSNode::folderCount(void) } return counter; } -std::vector etk::FSNode::folderGetSubList(bool _showHidenFile, bool _getFolderAndOther, bool _getFile, bool _temporaryFile) -{ + +std::vector etk::FSNode::folderGetSubList(bool _showHidenFile, bool _getFolderAndOther, bool _getFile, bool _temporaryFile) { std::vector tmpp; if (m_typeNode != etk::FSN_FOLDER ) { return tmpp; @@ -1159,18 +1189,18 @@ std::vector etk::FSNode::folderGetSubList(bool _showHidenFile, bo etk::FSNode * tmpEmement; DIR *dir = NULL; struct dirent *ent = NULL; - dir = opendir(to_u8string(m_systemFileName).c_str()); + dir = opendir(m_systemFileName.c_str()); if (dir != NULL) { // for each element in the drectory... while ((ent = readdir(dir)) != NULL) { - std::u32string tmpName(to_u32string(ent->d_name)); + std::string tmpName(ent->d_name); TK_VERBOSE(" search in folder\"" << tmpName << "\""); - if( tmpName == U"." - || tmpName == U".." ) { + if( tmpName == "." + || tmpName == ".." ) { // do nothing ... continue; } - if( false == start_with(tmpName, U".") + if( false == start_with(tmpName, ".") || true == _showHidenFile) { tmpEmement = new etk::FSNode(getRelativeFolder()+tmpName); if (NULL == tmpEmement) { @@ -1202,30 +1232,29 @@ std::vector etk::FSNode::folderGetSubList(bool _showHidenFile, bo return tmpp; } -etk::FSNode etk::FSNode::folderGetParent(void) -{ + +etk::FSNode etk::FSNode::folderGetParent(void) { etk::FSNode tmpp; return tmpp; } -void etk::FSNode::folderGetRecursiveFiles(std::vector& _output, bool _recursiveEnable) -{ +void etk::FSNode::folderGetRecursiveFiles(std::vector& _output, bool _recursiveEnable) { #ifdef __TARGET_OS__Android if( m_type == etk::FSN_TYPE_DATA || m_type == etk::FSN_TYPE_THEME_DATA) { - std::u32string assetsName = U"assets/"; - std::u32string FolderName = getNameFolder(); + std::string assetsName = "assets/"; + std::string FolderName = getNameFolder(); if (s_APKArchive==NULL) { return; } for (int iii=0; iiisize(); iii++) { - std::u32string filename = s_APKArchive->getName(iii); + std::string filename = s_APKArchive->getName(iii); if (filename.startWith(FolderName) == true) { - std::u32string tmpString; + std::string tmpString; if(m_type == etk::FSN_TYPE_DATA) { - tmpString = U"DATA:"; + tmpString = "DATA:"; } else { - tmpString = U"THEME:"; + tmpString = "THEME:"; } if (true == filename.startWith(assetsName)) { filename.remove(0,assetsName.size()); @@ -1241,14 +1270,14 @@ void etk::FSNode::folderGetRecursiveFiles(std::vector& _output, etk::FSNode * tmpEmement; DIR *dir = NULL; struct dirent *ent = NULL; - dir = opendir(to_u8string(m_systemFileName).c_str()); + dir = opendir(m_systemFileName.c_str()); //TK_DEBUG(" ** open Folder : " << m_systemFileName ); if (dir != NULL) { // for each element in the drectory... while ((ent = readdir(dir)) != NULL) { - std::u32string tmpName(to_u32string(ent->d_name)); - if( tmpName == U"." - || tmpName == U".." ) { + std::string tmpName(ent->d_name); + if( tmpName == "." + || tmpName == ".." ) { // do nothing ... continue; } @@ -1256,7 +1285,7 @@ void etk::FSNode::folderGetRecursiveFiles(std::vector& _output, tmpEmement = new etk::FSNode(getRelativeFolder()+tmpName); if (NULL != tmpEmement) { if(tmpEmement->getNodeType() == etk::FSN_FILE) { - std::u32string tmpVal = tmpEmement->getName(); + std::string tmpVal = tmpEmement->getName(); _output.push_back(tmpVal); } if(tmpEmement->getNodeType() == etk::FSN_FOLDER) { @@ -1277,36 +1306,42 @@ void etk::FSNode::folderGetRecursiveFiles(std::vector& _output, } return; } +void etk::FSNode::folderGetRecursiveFiles(std::vector& _output, bool _recursiveEnable) { + _output.clear(); + std::vector tmpVal; + folderGetRecursiveFiles(tmpVal, _recursiveEnable); + for (size_t iii=0; iii hiden file - && m_userFileName.size() != lastPos ) // Remove file ended with . - { + && m_userFileName.size() != lastPos ) { // Remove file ended with . return true; } else { return false; } } -std::u32string etk::FSNode::fileGetExtention(void) -{ +std::string etk::FSNode::fileGetExtention(void) { size_t lastPos = m_userFileName.rfind('.'); if( 0 != lastPos // Find a . at the fist position .jdlskjdfklj ==> hiden file - && m_userFileName.size() != lastPos ) // Remove file ended with . - { + && m_userFileName.size() != lastPos ) { // Remove file ended with . // Get the FileName - return std::u32string(m_userFileName, lastPos+1); + return std::string(m_userFileName, lastPos+1); } - return U""; + return ""; +} +std::u32string etk::FSNode::fileUGetExtention(void) { + return to_u32string(fileGetExtention()); } -uint64_t etk::FSNode::fileSize(void) -{ +uint64_t etk::FSNode::fileSize(void) { if (etk::FSN_FILE != m_typeNode) { TK_ERROR("Request size of a non file node : " << m_typeNode); return 0; @@ -1323,7 +1358,7 @@ uint64_t etk::FSNode::fileSize(void) // Note : this is a proper methode to get the file size for Big files ... otherwithe the size is limited at 2^31 bytes // tmpStat Buffer : struct stat statProperty; - if (-1 == stat(to_u8string(m_systemFileName).c_str(), &statProperty)) { + if (-1 == stat(m_systemFileName.c_str(), &statProperty)) { //Normal case when the file does not exist ... ==> the it was in unknow mode ... TK_ERROR("mlkmlkmlkmlkmlkmlk"); return 0; @@ -1336,8 +1371,7 @@ uint64_t etk::FSNode::fileSize(void) } -bool etk::FSNode::fileOpenRead(void) -{ +bool etk::FSNode::fileOpenRead(void) { #ifdef __TARGET_OS__Android if( etk::FSN_TYPE_DATA == m_type || etk::FSN_TYPE_THEME_DATA == m_type) { @@ -1353,15 +1387,14 @@ bool etk::FSNode::fileOpenRead(void) return true; } TK_VERBOSE(" Read file : " << m_systemFileName); - m_PointerFile=fopen(to_u8string(m_systemFileName).c_str(),"rb"); + m_PointerFile=fopen(m_systemFileName.c_str(),"rb"); if(NULL == m_PointerFile) { TK_ERROR("Can not find the file " << *this ); return false; } return true; } -bool etk::FSNode::fileOpenWrite(void) -{ +bool etk::FSNode::fileOpenWrite(void) { #ifdef __TARGET_OS__Android if( etk::FSN_TYPE_DATA == m_type || etk::FSN_TYPE_THEME_DATA == m_type) { @@ -1372,17 +1405,17 @@ bool etk::FSNode::fileOpenWrite(void) TK_CRITICAL("File Already open : " << *this); return true; } - FSNODE_LOCAL_mkPath(to_u8string(getNameFolder()).c_str() , 0777); + FSNODE_LOCAL_mkPath(getNameFolder().c_str() , 0777); TK_VERBOSE(" write file : " << m_systemFileName); - m_PointerFile=fopen(to_u8string(m_systemFileName).c_str(),"wb"); + m_PointerFile=fopen(m_systemFileName.c_str(),"wb"); if(NULL == m_PointerFile) { TK_ERROR("Can not find the file " << *this); return false; } return true; } -bool etk::FSNode::fileOpenAppend(void) -{ + +bool etk::FSNode::fileOpenAppend(void) { #ifdef __TARGET_OS__Android if( etk::FSN_TYPE_DATA == m_type || etk::FSN_TYPE_THEME_DATA == m_type) { @@ -1393,23 +1426,23 @@ bool etk::FSNode::fileOpenAppend(void) TK_CRITICAL("File Already open : " << *this); return true; } - FSNODE_LOCAL_mkPath(to_u8string(getNameFolder()).c_str() , 0777); + FSNODE_LOCAL_mkPath(getNameFolder().c_str() , 0777); TK_VERBOSE(" append file : " << m_systemFileName); - m_PointerFile=fopen(to_u8string(m_systemFileName).c_str(),"ab"); + m_PointerFile=fopen(m_systemFileName.c_str(),"ab"); if(NULL == m_PointerFile) { TK_ERROR("Can not find the file " << *this); return false; } return true; } -bool etk::FSNode::fileClose(void) -{ + +bool etk::FSNode::fileClose(void) { #ifdef __TARGET_OS__Android if( etk::FSN_TYPE_DATA == m_type || etk::FSN_TYPE_THEME_DATA == m_type) { - if (NULL == m_zipContent) { + if (m_zipContent == NULL) { TK_CRITICAL("File Already closed : " << *this); return false; } @@ -1419,7 +1452,7 @@ bool etk::FSNode::fileClose(void) return true; } #endif - if (NULL == m_PointerFile) { + if (m_PointerFile == NULL) { TK_CRITICAL("File Already closed : " << *this); return false; } @@ -1427,26 +1460,25 @@ bool etk::FSNode::fileClose(void) m_PointerFile = NULL; return true; } -char* etk::FSNode::fileGets(char * _elementLine, int64_t _maxData) -{ + +char* etk::FSNode::fileGets(char* _elementLine, int64_t _maxData) { memset(_elementLine, 0, _maxData); #ifdef __TARGET_OS__Android char * element = _elementLine; int64_t outSize = 0; - if( etk::FSN_TYPE_DATA == m_type - || etk::FSN_TYPE_THEME_DATA == m_type) {//char * tmpData = internalDataFiles[iii].data + m_readingOffset; - if (NULL == m_zipContent) { + if( m_type == etk::FSN_TYPE_DATA + || m_type == etk::FSN_TYPE_THEME_DATA) {//char * tmpData = internalDataFiles[iii].data + m_readingOffset; + if (m_zipContent == NULL) { element[0] = '\0'; return NULL; } - if (m_zipReadingOffset>=m_zipContent->size()) { + if (m_zipReadingOffset >= m_zipContent->size()) { element[0] = '\0'; return NULL; } while (((char*)m_zipContent->data())[m_zipReadingOffset] != '\0') { if( ((char*)m_zipContent->data())[m_zipReadingOffset] == '\n' - || ((char*)m_zipContent->data())[m_zipReadingOffset] == '\r') - { + || ((char*)m_zipContent->data())[m_zipReadingOffset] == '\r') { *element = ((char*)m_zipContent->data())[m_zipReadingOffset]; element++; m_zipReadingOffset++; @@ -1478,9 +1510,7 @@ char* etk::FSNode::fileGets(char * _elementLine, int64_t _maxData) return fgets(_elementLine, _maxData, m_PointerFile); } - -char etk::FSNode::fileGet(void) -{ +char etk::FSNode::fileGet(void) { char data='\0'; if (fileRead(&data, 1, 1)!=1) { return '\0'; @@ -1488,14 +1518,11 @@ char etk::FSNode::fileGet(void) return data; } - - -int64_t etk::FSNode::fileRead(void* _data, int64_t _blockSize, int64_t _nbBlock) -{ +int64_t etk::FSNode::fileRead(void* _data, int64_t _blockSize, int64_t _nbBlock) { #ifdef __TARGET_OS__Android - if( etk::FSN_TYPE_DATA == m_type - || etk::FSN_TYPE_THEME_DATA == m_type) { - if (NULL == m_zipContent) { + if( m_type == etk::FSN_TYPE_DATA + || m_type == etk::FSN_TYPE_THEME_DATA) { + if (m_zipContent == NULL) { ((char*)_data)[0] = '\0'; return 0; } @@ -1511,11 +1538,11 @@ int64_t etk::FSNode::fileRead(void* _data, int64_t _blockSize, int64_t _nbBlock) #endif return fread(_data, _blockSize, _nbBlock, m_PointerFile); } -int64_t etk::FSNode::fileWrite(void * _data, int64_t _blockSize, int64_t _nbBlock) -{ + +int64_t etk::FSNode::fileWrite(void * _data, int64_t _blockSize, int64_t _nbBlock) { #ifdef __TARGET_OS__Android - if( etk::FSN_TYPE_DATA == m_type - || etk::FSN_TYPE_THEME_DATA == m_type) { + if( m_type == etk::FSN_TYPE_DATA + || m_type == etk::FSN_TYPE_THEME_DATA) { TK_CRITICAL("Can not write on data inside APK : " << *this); return 0; } @@ -1525,8 +1552,8 @@ int64_t etk::FSNode::fileWrite(void * _data, int64_t _blockSize, int64_t _nbBloc bool etk::FSNode::fileSeek(long int _offset, enum etk::seekNode _origin) { #ifdef __TARGET_OS__Android - if( etk::FSN_TYPE_DATA == m_type - || etk::FSN_TYPE_THEME_DATA == m_type) { + if( m_type == etk::FSN_TYPE_DATA + || m_type == etk::FSN_TYPE_THEME_DATA) { if (NULL == m_zipContent) { return false; } @@ -1572,36 +1599,31 @@ bool etk::FSNode::fileSeek(long int _offset, enum etk::seekNode _origin) } } -void etk::FSNode::fileFlush(void) -{ +void etk::FSNode::fileFlush(void) { #ifdef __TARGET_OS__Android - if( etk::FSN_TYPE_DATA == m_type - || etk::FSN_TYPE_THEME_DATA == m_type) { + if( m_type == etk::FSN_TYPE_DATA + || m_type == etk::FSN_TYPE_THEME_DATA) { return; } #endif - if (NULL != m_PointerFile) { + if (m_PointerFile != NULL) { fflush(m_PointerFile); } } - - // TODO : Add an INIT to reset all allocated parameter : -class tmpThemeElement -{ +class tmpThemeElement { public: - std::u32string refName; - std::u32string folderName; + std::string refName; + std::string folderName; }; static std::vector g_listTheme; // set the Folder of a subset of a theme ... -void etk::theme::setName(std::u32string _refName, std::u32string _folderName) -{ +void etk::theme::setName(const std::string& _refName, const std::string& _folderName) { for(int32_t iii=0; iiirefName==_refName) { @@ -1621,9 +1643,12 @@ void etk::theme::setName(std::u32string _refName, std::u32string _folderName) tmpp->folderName = _folderName; g_listTheme.push_back(tmpp); } +void etk::theme::setName(const std::u32string& _refName, const std::u32string& _folderName) { + setName(to_u8string(_refName), to_u8string(_folderName)); +} // get the folder from a Reference theme -std::u32string etk::theme::getName(std::u32string _refName) { +std::string etk::theme::getName(const std::string& _refName) { for(int32_t iii=0; iiirefName==_refName) { @@ -1634,9 +1659,17 @@ std::u32string etk::theme::getName(std::u32string _refName) { // We did not find the theme return _refName; } +std::u32string etk::theme::getName(const std::u32string& _refName) { + return to_u32string(getName(to_u8string(_refName))); +} // get the list of all the theme folder availlable in the user Home/appl -std::vector etk::theme::list(void) { +std::vector etk::theme::list(void) { + std::vector tmpp; + return tmpp; + // TODO : +} +std::vector etk::theme::listU(void) { std::vector tmpp; return tmpp; // TODO : @@ -1648,38 +1681,45 @@ std::vector etk::theme::list(void) { * Simple direct wrapper on the FileSystem node access : * * -------------------------------------------------------------------------- */ -bool etk::FSNodeRemove(const std::u32string& _path) -{ +bool etk::FSNodeRemove(const std::string& _path) { etk::FSNode tmpNode(_path); if (false==tmpNode.exist()) { return false; } return tmpNode.remove(); } +bool etk::FSNodeRemove(const std::u32string& _path) { + return FSNodeRemove(to_u8string(_path)); +} -int64_t etk::FSNodeGetCount(const std::u32string& _path) -{ +int64_t etk::FSNodeGetCount(const std::string& _path) { etk::FSNode tmpNode(_path); if (false==tmpNode.exist()) { return -1; } return tmpNode.folderCount(); } +int64_t etk::FSNodeGetCount(const std::u32string& _path) { + return FSNodeGetCount(to_u8string(_path)); +} -bool etk::FSNodeCreate(const std::u32string& _path, etk::FSNodeRight _right, enum etk::typeNode _type) -{ +bool etk::FSNodeCreate(const std::string& _path, etk::FSNodeRight _right, enum etk::typeNode _type) { // TODO : return false; } +bool etk::FSNodeCreate(const std::u32string& _path, etk::FSNodeRight _right, enum etk::typeNode _type) { + return FSNodeCreate(to_u8string(_path), _right, _type); +} -bool etk::FSNodeExist(const std::u32string& _path) -{ +bool etk::FSNodeExist(const std::string& _path) { etk::FSNode tmpNode(_path); return tmpNode.exist(); } +bool etk::FSNodeExist(const std::u32string& _path) { + return FSNodeExist(to_u8string(_path)); +} -bool etk::FSNodeMove(const std::u32string& _path1, const std::u32string& _path2) -{ +bool etk::FSNodeMove(const std::string& _path1, const std::string& _path2) { etk::FSNode tmpNode(_path1); if (false==tmpNode.exist()) { TK_DEBUG("try to move un existant file \"" << _path1 << "\""); @@ -1690,45 +1730,59 @@ bool etk::FSNodeMove(const std::u32string& _path1, const std::u32string& _path2) //move the node return tmpNode.move(_path2); } +bool etk::FSNodeMove(const std::u32string& _path1, const std::u32string& _path2) { + return FSNodeMove(to_u8string(_path1), to_u8string(_path2)); +} -etk::FSNodeRight etk::FSNodeGetRight(const std::u32string& _path) -{ +etk::FSNodeRight etk::FSNodeGetRight(const std::string& _path) { etk::FSNode tmpNode(_path); return tmpNode.getRight(); } +etk::FSNodeRight etk::FSNodeGetRight(const std::u32string& _path) { + return FSNodeGetRight(to_u8string(_path)); +} -enum etk::typeNode etk::FSNodeGetType(const std::u32string& _path) -{ +enum etk::typeNode etk::FSNodeGetType(const std::string& _path) { etk::FSNode tmpNode(_path); return tmpNode.getNodeType(); } +enum etk::typeNode etk::FSNodeGetType(const std::u32string& _path) { + return FSNodeGetType(to_u8string(_path)); +} -uint64_t etk::FSNodeGetTimeCreated(const std::u32string& _path) -{ +uint64_t etk::FSNodeGetTimeCreated(const std::string& _path) { etk::FSNode tmpNode(_path); return tmpNode.timeCreated(); } +uint64_t etk::FSNodeGetTimeCreated(const std::u32string& _path) { + return FSNodeGetTimeCreated(to_u8string(_path)); +} -uint64_t etk::FSNodeGetTimeModified(const std::u32string& _path) -{ +uint64_t etk::FSNodeGetTimeModified(const std::string& _path) { etk::FSNode tmpNode(_path); return tmpNode.timeModified(); } +uint64_t etk::FSNodeGetTimeModified(const std::u32string& _path) { + return FSNodeGetTimeModified(to_u8string(_path)); +} -uint64_t etk::FSNodeGetTimeAccessed(const std::u32string& _path) -{ +uint64_t etk::FSNodeGetTimeAccessed(const std::string& _path) { etk::FSNode tmpNode(_path); return tmpNode.timeAccessed(); } +uint64_t etk::FSNodeGetTimeAccessed(const std::u32string& _path) { + return FSNodeGetTimeAccessed(to_u8string(_path)); +} -bool etk::FSNodeTouch(const std::u32string& _path) -{ +bool etk::FSNodeTouch(const std::string& _path) { etk::FSNode tmpNode(_path); return tmpNode.touch(); } +bool etk::FSNodeTouch(const std::u32string& _path) { + return FSNodeTouch(to_u8string(_path)); +} -bool etk::FSNodeEcho(const std::u32string& _path, const std::u32string& _dataTowrite) -{ +bool etk::FSNodeEcho(const std::string& _path, const std::string& _dataTowrite) { etk::FSNode tmpNode(_path); if (false==tmpNode.exist()) { return false; @@ -1740,16 +1794,17 @@ bool etk::FSNodeEcho(const std::u32string& _path, const std::u32string& _dataTow return false; } // convert in UTF8 : - std::string tmpChar = to_u8string(_dataTowrite); - if (tmpChar.size() != tmpNode.fileWrite((char*)tmpChar.c_str(), 1, tmpChar.size())) { + if (_dataTowrite.size() != tmpNode.fileWrite((char*)_dataTowrite.c_str(), 1, _dataTowrite.size())) { tmpNode.fileClose(); return false; } return tmpNode.fileClose(); } +bool etk::FSNodeEcho(const std::u32string& _path, const std::u32string& _dataTowrite) { + return FSNodeEcho(to_u8string(_path), to_u8string(_dataTowrite)); +} -bool etk::FSNodeEchoAdd(const std::u32string& _path, const std::u32string& _dataTowrite) -{ +bool etk::FSNodeEchoAdd(const std::string& _path, const std::string& _dataTowrite) { etk::FSNode tmpNode(_path); if (false==tmpNode.exist()) { return false; @@ -1761,24 +1816,28 @@ bool etk::FSNodeEchoAdd(const std::u32string& _path, const std::u32string& _data return false; } // convert in UTF8 : - std::string tmpChar = to_u8string(_dataTowrite); - if (tmpChar.size() != tmpNode.fileWrite((char*)tmpChar.c_str(), 1, tmpChar.size())) { + if (_dataTowrite.size() != tmpNode.fileWrite((char*)_dataTowrite.c_str(), 1, _dataTowrite.size())) { tmpNode.fileClose(); return false; } return tmpNode.fileClose(); } +bool etk::FSNodeEchoAdd(const std::u32string& _path, const std::u32string& _dataTowrite) { + return FSNodeEchoAdd(to_u8string(_path), to_u8string(_dataTowrite)); +} -void etk::FSNodeHistory(const std::u32string& _path, int32_t _historyCount) -{ +void etk::FSNodeHistory(const std::string& _path, int32_t _historyCount) { // step 1 : Move the file to prevent writing error //Get the first oldest save : for (int32_t iii=_historyCount-1; iii>0 ; iii--) { - if (true==etk::FSNodeExist(_path + U"-" + to_u32string(iii)) ) { - etk::FSNodeMove(_path + U"-" + to_u32string(iii), _path + U"-" + to_u32string(iii+1)); + if (true==etk::FSNodeExist(_path + "-" + std::to_string(iii)) ) { + etk::FSNodeMove(_path + "-" + std::to_string(iii), _path + "-" + std::to_string(iii+1)); } } if (true==etk::FSNodeExist(_path) ) { - etk::FSNodeMove(_path, _path + U"-1"); + etk::FSNodeMove(_path, _path + "-1"); } } +void etk::FSNodeHistory(const std::u32string& _path, int32_t _historyCount) { + return FSNodeHistory(to_u8string(_path), _historyCount); +} diff --git a/etk/os/FSNode.h b/etk/os/FSNode.h index b572ad7..6a07f93 100644 --- a/etk/os/FSNode.h +++ b/etk/os/FSNode.h @@ -22,7 +22,7 @@ namespace etk { - void setArgZero(const std::u32string& _val); + void setArgZero(const std::string& _val); /** * List of Type that a node can have (this wrap some type that not exist on Windows) */ @@ -123,8 +123,8 @@ namespace etk class FSNode { private: - std::u32string m_userFileName; //!< the name requested by the User - std::u32string m_systemFileName; //!< the compleate filename for the system + std::string m_userFileName; //!< the name requested by the User + std::string m_systemFileName; //!< the compleate filename for the system enum FSNType m_type; //!< the Type of data requested by the User enum typeNode m_typeNode; //!< type of the current file/Folder/Link etk::FSNodeRight m_rights; //!< IO right of the current file @@ -140,7 +140,8 @@ namespace etk * @brief Constructor * @param[in] _path Path of the curent file /folder ... */ - FSNode(const std::u32string& _path = U"~"); + FSNode(const std::string& _path = "~"); + FSNode(const std::u32string& _path); /** * @brief Destructor * @note you will have some warning if you did not close your files @@ -159,6 +160,7 @@ namespace etk * @brief Common set name of the Node (if the user decide to change the node selection * @param[in] _newName Name of the Node */ + void privateSetName(const std::string& _newName); void privateSetName(const std::u32string& _newName); private: #ifdef __TARGET_OS__Android @@ -207,35 +209,41 @@ namespace etk * @return true : action done * @return false : action not done */ + void setName(const std::string& _newName); void setName(const std::u32string& _newName); /** * @brief Get the Generate FileSystem name * @return the requested filename */ - std::u32string getFileSystemName(void) const; + std::string getFileSystemName(void) const; + std::u32string getUFileSystemName(void) const; /** * @brief Get the current folder of the Node. (file system name) * @return the common name define (like /xxxxx/xxxxx/ or c:/xxxxx/xxxxx/) * @note Auto remove of ../../../ and // */ - std::u32string getNameFolder(void) const; + std::string getNameFolder(void) const; + std::u32string getUNameFolder(void) const; /** * @brief Get the current compleate node name (file system name) * @return All the user name definition (like /xxxxx/xxxxx/myFile.kkk or c:/xxxxx/xxxxx/myFile.kkk) * @note Auto remove of ../../../ and // */ - std::u32string getName(void) const; + std::string getName(void) const; + std::u32string getUName(void) const; /** * @brief Get the file or current folder name (if it was a folder) * @return the name of the node (like myFile.kkk) */ - std::u32string getNameFile(void) const; + std::string getNameFile(void) const; + std::u32string getUNameFile(void) const; /** * @brief Get the current folder of the Node. * @return the common name define (like DATA:xxxxx/xxxxx/) * @note Auto remove of ../../../ and // */ - std::u32string getRelativeFolder(void) const; + std::string getRelativeFolder(void) const; + std::u32string getURelativeFolder(void) const; /** * @brief update the Time of the file with the current time * @return true : action done @@ -248,6 +256,7 @@ namespace etk * @return true : action done * @return false : action not done */ + bool move(const std::string& _path); bool move(const std::u32string& _path); /** * @brief Get the node type (DATA/DIRECT...) @@ -271,7 +280,8 @@ namespace etk * @brief Get the creating time of the File * @return The time requested (in string) */ - std::u32string timeCreatedString(void) const; + std::string timeCreatedString(void) const; + std::u32string timeUCreatedString(void) const; /** * @brief Get the modifying time of the File * @return The time requested @@ -281,7 +291,8 @@ namespace etk * @brief Get the modifying time of the File * @return The time requested (in string) */ - std::u32string timeModifiedString(void) const; + std::string timeModifiedString(void) const; + std::u32string timeUModifiedString(void) const; /** * @brief Get the Accessed time of the File * @return The time requested @@ -291,7 +302,8 @@ namespace etk * @brief Get the Accessed time of the File * @return The time requested (in string) */ - std::u32string timeAccessedString(void) const; + std::string timeAccessedString(void) const; + std::u32string timeUAccessedString(void) const; /** * @brief copy the other FSnode ==> for vector * @param[in] _obj input node @@ -346,6 +358,7 @@ namespace etk * @param[out] _output List of all the File names (You must clear it before set it in) * @param[in] _recursiveEnable Activate the recursive mode (enable by default) */ + void folderGetRecursiveFiles(std::vector& _output, bool _recursiveEnable=true); void folderGetRecursiveFiles(std::vector& _output, bool _recursiveEnable=true); /** * @brief Check if the file have an extention ( ***.ccc) @@ -357,7 +370,8 @@ namespace etk * @brief Get the extention of the Node * @return the requested extention */ - std::u32string fileGetExtention(void); + std::string fileGetExtention(void); + std::u32string fileUGetExtention(void); /** * @brief Get the File size * @return the requested size @@ -463,12 +477,14 @@ namespace etk * @brief Get the home folder of the user * @return the home folder : like : "/home/machin/" */ - std::u32string getUserHomeFolder(void); + std::string getUserHomeFolder(void); + std::u32string getUUserHomeFolder(void); /** * @brief Get the folder of the Program is running * @return the basic folder name (ex : run ./appl in the pwd=/home/machin/sousFolder ==> this return the pwd folder) */ - std::u32string getUserRunFolder(void); + std::string getUserRunFolder(void); + std::u32string getUUserRunFolder(void); namespace theme { // TODO : Add an INIT ... @@ -477,18 +493,21 @@ namespace etk * @param[in] _refName Theme cathegorie ex : "GUI" "SHADER" "DEFAULT" * @param[in] _folderName The associated folder of the Theme (like "myTheme/folder/folder2/") */ - void setName(std::u32string _refName, std::u32string _folderName); + void setName(const std::string& _refName, const std::string& _folderName); + void setName(const std::u32string& _refName, const std::u32string& _folderName); /** * @brief get the folder from a Reference theme * @param[in] _refName Theme cathegorie ex : "GUI" "SHADER" "DEFAULT" * @return the path of the theme */ - std::u32string getName(std::u32string _refName); + std::string getName(const std::string& _refName); + std::u32string getName(const std::u32string& _refName); /** * @brief Get the list of all the theme folder availlable in the user Home/appl * @return The list of elements */ - std::vector list(void); + std::vector list(void); + std::vector listU(void); }; /** @@ -497,6 +516,7 @@ namespace etk * @return true : Action done corectly * @return false : An error occured */ + bool FSNodeRemove(const std::string& _path); bool FSNodeRemove(const std::u32string& _path); /** * @brief Simple access for : count the number of element in a path (if it is not a path ==> return -1) @@ -504,6 +524,7 @@ namespace etk * @return number of File inside * @return -1 : An error occured */ + int64_t FSNodeGetCount(const std::string& _path); int64_t FSNodeGetCount(const std::u32string& _path); /** * @brief Simple access for : Create a file or a folder depending of the request @@ -513,6 +534,7 @@ namespace etk * @return true : Action done corectly * @return false : An error occured */ + bool FSNodeCreate(const std::string& _path, etk::FSNodeRight _right, enum etk::typeNode _type=etk::FSN_FOLDER); bool FSNodeCreate(const std::u32string& _path, etk::FSNodeRight _right, enum etk::typeNode _type=etk::FSN_FOLDER); /** * @brief Simple access for : chexk the exestance of an element @@ -520,6 +542,7 @@ namespace etk * @return true : Action done corectly * @return false : An error occured */ + bool FSNodeExist(const std::string& _path); bool FSNodeExist(const std::u32string& _path); /** * @brief Simple access for : chexk the exestance of an element @@ -528,6 +551,7 @@ namespace etk * @return true : Action done corectly * @return false : An error occured */ + bool FSNodeMove(const std::string& _path1, const std::string& _path2); bool FSNodeMove(const std::u32string& _path1, const std::u32string& _path2); /** * @brief Simple access for : Get right of the current Node @@ -535,6 +559,7 @@ namespace etk * @return true : Action done corectly * @return false : An error occured */ + etk::FSNodeRight FSNodeGetRight(const std::string& _path); etk::FSNodeRight FSNodeGetRight(const std::u32string& _path); /** * @brief Simple access for : Get type of the current node @@ -542,6 +567,7 @@ namespace etk * @return true : Action done corectly * @return false : An error occured */ + enum etk::typeNode FSNodeGetType(const std::string& _path); enum etk::typeNode FSNodeGetType(const std::u32string& _path); /** * @brief Simple access for : Getting creation time of the current node @@ -549,6 +575,7 @@ namespace etk * @return true : Action done corectly * @return false : An error occured */ + uint64_t FSNodeGetTimeCreated(const std::string& _path); uint64_t FSNodeGetTimeCreated(const std::u32string& _path); /** * @brief Simple access for : Getting Modification time of the current node @@ -556,6 +583,7 @@ namespace etk * @return true : Action done corectly * @return false : An error occured */ + uint64_t FSNodeGetTimeModified(const std::string& _path); uint64_t FSNodeGetTimeModified(const std::u32string& _path); /** * @brief Simple access for : Getting Accessing time of the current node @@ -563,6 +591,7 @@ namespace etk * @return true : Action done corectly * @return false : An error occured */ + uint64_t FSNodeGetTimeAccessed(const std::string& _path); uint64_t FSNodeGetTimeAccessed(const std::u32string& _path); /** * @brief Simple access for : Update Modification time with the current time of the node (>) @@ -570,6 +599,7 @@ namespace etk * @return true : Action done corectly * @return false : An error occured */ + bool FSNodeTouch(const std::string& _path); bool FSNodeTouch(const std::u32string& _path); /** * @brief Simple access for : Basic write on the node (like console echo) @@ -578,6 +608,7 @@ namespace etk * @return true : Action done corectly * @return false : An error occured */ + bool FSNodeEcho(const std::string& _path, const std::string& _dataTowrite); bool FSNodeEcho(const std::u32string& _path, const std::u32string& _dataTowrite); /** * @brief Simple access for : Basic write on the node (like console echo) in adding mode (>>) @@ -586,12 +617,14 @@ namespace etk * @return true : Action done corectly * @return false : An error occured */ + bool FSNodeEchoAdd(const std::string& _path, const std::string& _dataTowrite); bool FSNodeEchoAdd(const std::u32string& _path, const std::u32string& _dataTowrite); /** * @brief move file to generate an history of the current file * @param[in] _path Folder/File/Pipe path of the node * @param[in] _historyCount number of saved file in the history (-xxx) */ + void FSNodeHistory(const std::string& _path, int32_t _historyCount); void FSNodeHistory(const std::u32string& _path, int32_t _historyCount); }; diff --git a/etk/os/FSNodeRight.cpp b/etk/os/FSNodeRight.cpp index ef9b950..0f8f810 100644 --- a/etk/os/FSNodeRight.cpp +++ b/etk/os/FSNodeRight.cpp @@ -176,8 +176,8 @@ void etk::FSNodeRight::setOtherRunable(bool _newStatus) m_rights |= RIGHT_OTHER_EXECUTE; } } -std::u32string etk::FSNodeRight::getRight(void) const -{ + +std::u32string etk::FSNodeRight::getURight(void) const { std::u32string tmp; if (isUserReadable() == true) { tmp += U"r"; @@ -227,6 +227,56 @@ std::u32string etk::FSNodeRight::getRight(void) const return tmp; } +std::string etk::FSNodeRight::getRight(void) const { + std::string tmp; + if (isUserReadable() == true) { + tmp += "r"; + } else { + tmp += "-"; + } + if (isUserWritable() == true) { + tmp += "w"; + } else { + tmp += "-"; + } + if (isUserRunable() == true) { + tmp += "x"; + } else { + tmp += "-"; + } + if (isGroupReadable() == true) { + tmp += "r"; + } else { + tmp += "-"; + } + if (isGroupWritable() == true) { + tmp += "w"; + } else { + tmp += "-"; + } + if (isGroupRunable() == true) { + tmp += "x"; + } else { + tmp += "-"; + } + if (isOtherReadable() == true) { + tmp += "r"; + } else { + tmp += "-"; + } + if (isOtherWritable() == true) { + tmp += "w"; + } else { + tmp += "-"; + } + if (isOtherRunable() == true) { + tmp += "x"; + } else { + tmp += "-"; + } + return tmp; +} + etk::CCout& etk::operator <<(etk::CCout &_os, const etk::FSNodeRight &_obj) { diff --git a/etk/os/FSNodeRight.h b/etk/os/FSNodeRight.h index 26bfcb5..b1dbb5b 100644 --- a/etk/os/FSNodeRight.h +++ b/etk/os/FSNodeRight.h @@ -49,7 +49,8 @@ namespace etk void setOtherWritable(bool _newStatus); void setOtherRunable(bool _newStatus); - std::u32string getRight(void) const; + std::u32string getURight(void) const; + std::string getRight(void) const; }; etk::CCout& operator <<(etk::CCout &_os, const etk::FSNodeRight &_obj); };