From c35e883279632dda8743a3d1f9bbe5ac2748146f Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Tue, 13 Nov 2012 22:52:37 +0100 Subject: [PATCH] [DEV] add capacity on the File system node to get all file with subFolders --- etk/UString.cpp | 58 +++++++++++++++++++++++++------ etk/UString.h | 4 +-- etk/os/FSNode.cpp | 87 +++++++++++++++++++++++++++++++++++++++++++++-- etk/os/FSNode.h | 1 + 4 files changed, 136 insertions(+), 14 deletions(-) diff --git a/etk/UString.cpp b/etk/UString.cpp index fb3422b..80c2bc9 100644 --- a/etk/UString.cpp +++ b/etk/UString.cpp @@ -525,7 +525,7 @@ etk::Vector etk::UString::GetVector(void) } -bool etk::UString::StartWith(const etk::UString& data) +bool etk::UString::StartWith(const etk::UString& data, bool caseSensitive) const { if (data.Size() == 0) { return false; @@ -533,16 +533,34 @@ bool etk::UString::StartWith(const etk::UString& data) if (data.Size() > Size()) { return false; } - for (int32_t iii=0; iii= (uniChar_t)'A') { + in1 = in1 + (uniChar_t)'a' - (uniChar_t)'A'; + } + if (in2 <= 'Z' && in2 >= 'A') { + in2 = in2 + (uniChar_t)'a' - (uniChar_t)'A'; + } + if (in1 != in2) { + return false; + } + } } } return true; } -bool etk::UString::EndWith(const etk::UString& data) +bool etk::UString::EndWith(const etk::UString& data, bool caseSensitive) const { if (data.Size() == 0) { return false; @@ -550,11 +568,31 @@ bool etk::UString::EndWith(const etk::UString& data) if (data.Size() > Size()) { return false; } - for( int32_t iii=Size()-1, jjj=data.Size()-1; - iii>=0 && jjj>=0; - iii--, jjj--) { - if (data[jjj] != m_data[iii]) { - return false; + if (true == caseSensitive) { + for( int32_t iii=Size()-1, jjj=data.Size()-1; + iii>=0 && jjj>=0; + iii--, jjj--) { + if (data[jjj] != m_data[iii]) { + return false; + } + } + } else { + for( int32_t iii=Size()-1, jjj=data.Size()-1; + iii>=0 && jjj>=0; + iii--, jjj--) { + if (data[jjj] != m_data[iii]) { + uniChar_t in1 = data[jjj]; + uniChar_t in2 = m_data[iii]; + if (in1 <= (uniChar_t)'Z' && in1 >= (uniChar_t)'A') { + in1 = in1 + (uniChar_t)'a' - (uniChar_t)'A'; + } + if (in2 <= 'Z' && in2 >= 'A') { + in2 = in2 + (uniChar_t)'a' - (uniChar_t)'A'; + } + if (in1 != in2) { + return false; + } + } } } return true; diff --git a/etk/UString.h b/etk/UString.h index 22ff8e1..a838823 100644 --- a/etk/UString.h +++ b/etk/UString.h @@ -95,9 +95,9 @@ namespace etk * toolbox *****************************************************/ // Start With ... - bool StartWith(const etk::UString& data); + bool StartWith(const etk::UString& data, bool caseSensitive=true) const ; // End With ... - bool EndWith(const etk::UString& data); + bool EndWith(const etk::UString& data, bool caseSensitive=true) const ; // Find element int32_t FindForward(const char data, int32_t startPos=0) const; int32_t FindForward(const uniChar_t data, int32_t startPos=0) const; diff --git a/etk/os/FSNode.cpp b/etk/os/FSNode.cpp index 70745bf..5547ef7 100644 --- a/etk/os/FSNode.cpp +++ b/etk/os/FSNode.cpp @@ -585,8 +585,9 @@ void etk::FSNode::GenerateFileSystemPath(void) break; } m_systemFileName += m_userFileName; - } + + // now we get all the right if the file existed: void etk::FSNode::UpdateFileSystemProperty(void) { @@ -740,6 +741,27 @@ etk::UString etk::FSNode::GetNameFile(void) const etk::UString etk::FSNode::GetRelativeFolder(void) const { etk::UString tmppp = GetName(); + switch (m_typeNode) + { + case etk::FSN_UNKNOW: + case etk::FSN_FOLDER: + case etk::FSN_LINK: + if (tmppp.EndWith("/") == true) { + return tmppp; + } else { + etk::UString tmpVal = tmppp; + tmpVal += "/"; + return tmpVal; + } + break; + case etk::FSN_BLOCK: + case etk::FSN_CHARACTER: + case etk::FSN_FIFO: + case etk::FSN_FILE: + case etk::FSN_SOCKET: + default: + break; + } int32_t lastPos = tmppp.FindBack('/'); if (-1 != lastPos) { return tmppp.Extract(0, lastPos+1); @@ -986,6 +1008,67 @@ etk::FSNode etk::FSNode::FolderGetParent(void) return tmpp; } +void etk::FSNode::FolderGetRecursiveFiles(etk::Vector& output) +{ + #ifdef __TARGET_OS__Android + if( m_type == etk::FSN_TYPE_DATA + || m_type == etk::FSN_TYPE_THEME_DATA) { + etk::UString FolderName = GetNameFolder(); + for (int iii=0; iiid_name); + if( tmpName=="." + || tmpName==".." ) { + // do nothing ... + continue; + } + //TK_DEBUG(" find : " << ent->d_name << " ==> " << (GetRelativeFolder()+tmpName)); + tmpEmement = new etk::FSNode(GetRelativeFolder()+tmpName); + if (NULL != tmpEmement) { + if(tmpEmement->GetNodeType() == etk::FSN_FILE) { + etk::UString tmpVal = tmpEmement->GetName(); + output.PushBack(tmpVal); + } + if(tmpEmement->GetNodeType() == etk::FSN_FOLDER) { + tmpEmement->FolderGetRecursiveFiles(output); + } + delete(tmpEmement); + tmpEmement = NULL; + } else { + TK_ERROR("allocation error ... of ewol::FSNode"); + continue; + } + } + closedir(dir); + } else { + TK_ERROR("could not open directory : \"" << *this << "\""); + } + return; +} + /* File Specific : */ @@ -1019,7 +1102,7 @@ etk::UString etk::FSNode::FileGetExtention(void) uint64_t etk::FSNode::FileSize(void) { if (etk::FSN_FILE != m_typeNode) { - TK_ERROR("pppppppppppppppppppppp" << m_typeNode); + TK_ERROR("Request size of a non file node : " << m_typeNode); return 0; } #ifdef __TARGET_OS__Android diff --git a/etk/os/FSNode.h b/etk/os/FSNode.h index 4413288..e7e0de2 100644 --- a/etk/os/FSNode.h +++ b/etk/os/FSNode.h @@ -188,6 +188,7 @@ namespace etk bool temporaryFile=true); etk::FSNode FolderGetParent(void); // ordered by name ... + void FolderGetRecursiveFiles(etk::Vector& output); /* File Specific : */