diff --git a/Sources/libetk/etk/os/FSNode.cpp b/Sources/libetk/etk/os/FSNode.cpp index cbcdeac9..bb883200 100644 --- a/Sources/libetk/etk/os/FSNode.cpp +++ b/Sources/libetk/etk/os/FSNode.cpp @@ -33,6 +33,7 @@ extern "C" { // file browsing ... #include + #include } #ifdef __TARGET_OS__Android @@ -231,8 +232,10 @@ etk::FSNode::FSNode(void) : m_userFileName(""), m_type(etk::FSN_TYPE_UNKNOW), m_typeNode(etk::FSN_UNKNOW), - m_rights(0), - m_PointerFile(NULL) + m_PointerFile(NULL), + m_timeCreate(0), + m_timeModify(0), + m_timeAccess(0) #ifdef __TARGET_OS__Android , m_idZipFile(-1), m_zipData(NULL), @@ -248,8 +251,10 @@ etk::FSNode::FSNode(etk::UString nodeName) : m_userFileName(""), m_type(etk::FSN_TYPE_UNKNOW), m_typeNode(etk::FSN_UNKNOW), - m_rights(0), - m_PointerFile(NULL) + m_PointerFile(NULL), + m_timeCreate(0), + m_timeModify(0), + m_timeAccess(0) #ifdef __TARGET_OS__Android , m_idZipFile(-1), m_zipData(NULL), @@ -273,10 +278,99 @@ etk::FSNode::~FSNode(void) } } +static etk::UString SimplifyPathAbstractPath(etk::UString input) +{ + int32_t findStartPos = input.FindForward('/') + 1; + int32_t findPos = input.FindForward('/', findStartPos); + //TK_DEBUG("Siplify : \"" << input << "\""); + int32_t preventBadCode = 0; + while (findPos!=-1) + { + //TK_DEBUG(" string=\"" << input << "\""); + //TK_DEBUG(" '/' @" << findPos); + if (input.Size()5000) { + TK_CRITICAL("ERROR when getting the small path ... this is loop prevention..."); + break; + } + } + /* + #ifndef __TARGET_OS__Windows + // for the target that supported the Realpath system : + char buf[MAX_FILE_NAME]; + memset(buf, 0, MAX_FILE_NAME); + char * ok = realpath(input.c_str(), buf); + if (!ok) { + TK_ERROR("Error to get the real path"); + input = "/"; + } else { + input = buf; + } + #endif + */ + //TK_DEBUG(" ==> \"" << input << "\""); + return input; +} + + +static void SortElementList(etk::Vector &list) +{ + // TODO : ... + /* + etk::Vector tmpList = list; + list.Clear(); + for(int32_t iii=0; iiim_name > list[jjj]->m_name) { + findPos = jjj+1; + } + } + } + //EWOL_DEBUG("position="<\"" << m_userFileName << "\""); + TK_DBG_MODE("3 : parse done : [" << m_type << "]->\"" << m_userFileName << "\""); - // Now we reduce the path with all un-needed - // TODO : set it back again ... - //m_userFileName = etk::tool::SimplifyPath(m_userFileName); - TK_DBG_MODE("4 : Path simplification : [" << m_type << "]->\"" << m_userFileName << "\""); + // Now we reduce the path with all un-needed ../ and other thinks ... + // TODO : Do it whith link and the other sub thinks ... + m_userFileName = SimplifyPathAbstractPath(m_userFileName); + TK_DBG_MODE("4 : Path simplification : [" << m_type << "]->\"" << m_userFileName << "\""); - // TODO : Get rights - // TODO : Check if it is a file or a folder ... + // Now we generate the real FS path: + GenerateFileSystemPath(); + TK_DBG_MODE("5 : file System Real name : \"" << m_systemFileName << "\""); + + // now we get all the right if the file existed: + UpdateFileSystemProperty(); + TK_DBG_MODE("6 : type : [" << m_typeNode << "] right :" << m_rights); } -bool etk::FSNode::DirectExistFile(etk::UString tmpFileNameDirect, bool checkInAPKIfNeeded) + +bool DirectCheckFile(etk::UString tmpFileNameDirect, bool checkInAPKIfNeeded=false) { #ifdef __TARGET_OS__Android if (true == checkInAPKIfNeeded) { + for (int iii=0; iii \"" << basicName << "\""); + // search the corect folder : + if (themeName == "") { + TK_WARNING("no theme name detected : set it to \"default\""); + } else { + // Selected theme : + // check in the user data : + m_systemFileName = baseFolderDataUser + "theme/" + themeName + "/" + basicName; + if (true==DirectCheckFile(m_systemFileName)) { + return; + } + // check in the Appl data : + m_systemFileName = baseFolderData + "theme/" + themeName + "/" + basicName; + if (true==DirectCheckFile(m_systemFileName, true)) { + m_type = etk::FSN_TYPE_THEME_DATA; + return; + } + } + themeName = "default"; + // default theme : + // check in the user data : + 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 + "theme/" + themeName + "/" + basicName; + m_type = etk::FSN_TYPE_THEME_DATA; + return; + } + break; + } + m_systemFileName += m_userFileName; + +} +// now we get all the right if the file existed: +void etk::FSNode::UpdateFileSystemProperty(void) +{ + // clean general properties : + m_rights.Clear(); + m_timeCreate = 0; + m_timeModify = 0; + m_timeAccess = 0; + m_idOwner = 0; + m_idGroup = 0; + // File type is not knowns ... + m_typeNode=FSN_UNKNOW; + + #ifdef __TARGET_OS__Android + if( m_type == etk::FSN_TYPE_DATA + || m_type == etk::FSN_TYPE_THEME_DATA) { for (int iii=0; iii= s_APKnbFiles)) { TK_ERROR("File Does not existed ... in APK : \"" << tmpFilename << "\""); - return false; + return; } + // note : Zip does not support other think than file ... + // TODO : Suport folder parsing ... + m_typeNode=FSN_FILE; + m_rights.IsUserReadable(true); + // TODO : Set the time of the file (time program compilation) + // TODO : Set the USER ID in the group and the user Id ... TK_DBG_MODE("File existed ... in APK : \"" << tmpFilename << "\" ==> id=" << m_idZipFile); - return true; + return; } #endif - FILE *myFile=myFile=fopen(tmpFileNameDirect.c_str(),"rb"); - if(NULL == myFile) { - TK_DBG_MODE("check existance of : " << tmpFileNameDirect); - return false; + // tmpStat Buffer : + struct stat statProperty; + if (-1 == stat(m_systemFileName.c_str(), &statProperty)) { + //Normal case when the file does not exist ... ==> the it was in unknow mode ... + return; } - fclose(myFile); - DIR *pDir = opendir (tmpFileNameDirect.c_str()); - if (pDir != NULL) { - (void) closedir(pDir); - m_typeNode = etk::FSN_FILE; - return true; + switch (statProperty.st_mode & S_IFMT) { + case S_IFBLK: m_typeNode=etk::FSN_BLOCK; break; + case S_IFCHR: m_typeNode=etk::FSN_CHARACTER; break; + case S_IFDIR: m_typeNode=etk::FSN_FOLDER; break; + case S_IFIFO: m_typeNode=etk::FSN_FIFO; break; + case S_IFLNK: m_typeNode=etk::FSN_LINK; break; + case S_IFREG: m_typeNode=etk::FSN_FILE; break; + case S_IFSOCK: m_typeNode=etk::FSN_SOCKET; break; + default: m_typeNode=etk::FSN_UNKNOW; break; } - m_typeNode = etk::FSN_FOLDER; - return false; -} - -etk::UString etk::FSNode::GetFileSystemName(void) const -{ - etk::UString output; - switch (m_type) - { - default: - case etk::FSN_TYPE_UNKNOW: - output = baseFolderHome; - break; - case etk::FSN_TYPE_DIRECT: - output = "/"; - break; - case etk::FSN_TYPE_RELATIF: - { - // Get the command came from the running of the program : - char cCurrentPath[FILENAME_MAX]; - if (!getcwd(cCurrentPath, FILENAME_MAX)) { - TK_WARNING("Can not get the curent path"); - output = "/"; - } - cCurrentPath[FILENAME_MAX - 1] = '\0'; - output = cCurrentPath; - output += "/"; - } - break; - case etk::FSN_TYPE_HOME: - output = baseFolderHome; - break; - case etk::FSN_TYPE_DATA: - output = baseFolderData; - break; - case etk::FSN_TYPE_USER_DATA: - output = baseFolderDataUser; - break; - case etk::FSN_TYPE_CACHE: - output = baseFolderCache; - break; - case etk::FSN_TYPE_THEME: - case etk::FSN_TYPE_THEME__USER_THEME: - case etk::FSN_TYPE_THEME__USER_DEFAULT: - case etk::FSN_TYPE_THEME__APPL_THEME: - case etk::FSN_TYPE_THEME__APPL_DEFAULT: - { - //etk::UString myCompleateName=baseFolderData + "/theme/"; - etk::UString themeName(""); - etk::UString basicName(m_userFileName); - int32_t firstPos = m_userFileName.FindForward(':'); - if (-1 != firstPos) { - // we find a theme name : We extracted it : - themeName = m_userFileName.Extract(0, firstPos); - basicName = m_userFileName.Extract(firstPos+1); - } - TK_DBG_MODE(" THEME party : \"" << themeName << "\" => \"" << basicName << "\""); - switch (m_type) - { - default: - case etk::FSN_TYPE_THEME: - TK_ERROR("request compleate name without call the Exist function, that search the good folder ==> default appl theme"); - case etk::FSN_TYPE_THEME__APPL_DEFAULT: - themeName = "default"; - return baseFolderData + "theme/" + themeName + "/" + basicName; - case etk::FSN_TYPE_THEME__APPL_THEME: - return baseFolderData + "theme/" + themeName + "/" + basicName; - case etk::FSN_TYPE_THEME__USER_THEME: - return baseFolderDataUser + "theme/" + themeName + "/" + basicName; - case etk::FSN_TYPE_THEME__USER_DEFAULT: - themeName = "default"; - return baseFolderDataUser + "theme/" + themeName + "/" + basicName; - } - } - break; - } - output += m_userFileName; - return output; -} - - -etk::UString etk::FSNode::GetFileSystemNameTheme(void) -{ - //etk::UString myCompleateName=baseFolderData + "/theme/"; - etk::UString themeName(""); - etk::UString basicName(m_userFileName); - int32_t firstPos = m_userFileName.FindForward(':'); - if (-1 != firstPos) { - // we find a theme name : We extracted it : - themeName = m_userFileName.Extract(0, firstPos); - basicName = m_userFileName.Extract(firstPos+1); - } - TK_DBG_MODE(" THEME party : \"" << themeName << "\" => \"" << basicName << "\""); - - if (themeName == "") { - TK_WARNING("no theme name detected : set it to \"default\""); - } else { - // Selected theme : - // check in the user data : - etk::UString tmpCompleateName = baseFolderDataUser + "theme/" + themeName + "/" + basicName; - if (true==DirectExistFile(tmpCompleateName)) { - m_type = FSN_TYPE_THEME__USER_THEME; - return tmpCompleateName; - } - // check in the Appl data : - tmpCompleateName = baseFolderData + "theme/" + themeName + "/" + basicName; - if (true==DirectExistFile(tmpCompleateName, etk::FSN_TYPE_DATA)) { - m_type = FSN_TYPE_THEME__APPL_THEME; - return tmpCompleateName; - } - } - themeName = "default"; - // default theme : - // check in the user data : - etk::UString tmpCompleateName = baseFolderDataUser + "theme/" + themeName + "/" + basicName; - if (true==DirectExistFile(tmpCompleateName)) { - m_type = FSN_TYPE_THEME__USER_DEFAULT; - return tmpCompleateName; - } - // check in the Appl data : In every case we return this one ... - tmpCompleateName = baseFolderData + "theme/" + themeName + "/" + basicName; - m_type = FSN_TYPE_THEME__APPL_DEFAULT; - return tmpCompleateName; + // Right + m_rights = statProperty.st_mode; + m_idOwner = (int32_t) statProperty.st_uid; + m_idGroup = (int32_t) statProperty.st_gid; + m_timeCreate = statProperty.st_ctime; + m_timeModify = statProperty.st_mtime; + m_timeAccess = statProperty.st_atime; + return; } /* All Right of the file */ -bool etk::FSNode::Exist(void) +bool etk::FSNode::SetRight(etk::FSNodeRight newRight) { - etk::UString myCompleateName; - switch(m_type) - { - case etk::FSN_TYPE_THEME: - case etk::FSN_TYPE_THEME__USER_THEME: - case etk::FSN_TYPE_THEME__USER_DEFAULT: - case etk::FSN_TYPE_THEME__APPL_THEME: - case etk::FSN_TYPE_THEME__APPL_DEFAULT: - myCompleateName = GetFileSystemNameTheme(); - break; - default: - myCompleateName = GetFileSystemName(); - break; - } - bool tmpFlag = false; - if( etk::FSN_TYPE_DATA == m_type - || etk::FSN_TYPE_THEME__APPL_THEME == m_type - || etk::FSN_TYPE_THEME__APPL_DEFAULT == m_type) { - tmpFlag = true; - } - return DirectExistFile(myCompleateName, tmpFlag); -} - -bool etk::FSNode::IsFile(void) -{ - return (m_typeNode == etk::FSN_FILE); -} - -bool etk::FSNode::IsFolder(void) -{ - return (m_typeNode == etk::FSN_FOLDER); -} - -bool etk::FSNode::IsLink(void) -{ - return (m_typeNode == etk::FSN_LINK); -} - -// User -bool etk::FSNode::IsUserReadable(void) -{ - return ((m_rights&etk::RIGHT_USER_READ)!=0)?true:false; -} - -bool etk::FSNode::IsUserWritable(void) -{ - return ((m_rights&etk::RIGHT_USER_WRITE)!=0)?true:false; -} - -bool etk::FSNode::IsUserRunable(void) -{ - return ((m_rights&etk::RIGHT_USER_EXECUTE)!=0)?true:false; -} - -void etk::FSNode::SetUserReadable(bool newStatus) -{ - // reset the flag : - m_rights &= (0xFFFFFFFF - etk::RIGHT_USER_READ); - if (true == newStatus) { - m_rights |= etk::RIGHT_USER_READ; - } -} - -void etk::FSNode::SetUserWritable(bool newStatus) -{ - // reset the flag : - m_rights &= (0xFFFFFFFF - etk::RIGHT_USER_WRITE); - if (true == newStatus) { - m_rights |= etk::RIGHT_USER_WRITE; - } -} - -void etk::FSNode::SetUserRunable(bool newStatus) -{ - // reset the flag : - m_rights &= (0xFFFFFFFF - etk::RIGHT_USER_EXECUTE); - if (true == newStatus) { - m_rights |= etk::RIGHT_USER_EXECUTE; - } -} - -// group -bool etk::FSNode::IsGroupReadable(void) -{ - return ((m_rights&etk::RIGHT_GROUP_READ)!=0)?true:false; -} - -bool etk::FSNode::IsGroupWritable(void) -{ - return ((m_rights&etk::RIGHT_GROUP_WRITE)!=0)?true:false; -} - -bool etk::FSNode::IsGroupRunable(void) -{ - return ((m_rights&etk::RIGHT_GROUP_EXECUTE)!=0)?true:false; -} - -void etk::FSNode::SetGroupReadable(bool newStatus) -{ - // reset the flag : - m_rights &= (0xFFFFFFFF - etk::RIGHT_GROUP_READ); - if (true == newStatus) { - m_rights |= etk::RIGHT_GROUP_READ; - } -} - -void etk::FSNode::SetGroupWritable(bool newStatus) -{ - // reset the flag : - m_rights &= (0xFFFFFFFF - etk::RIGHT_GROUP_WRITE); - if (true == newStatus) { - m_rights |= etk::RIGHT_GROUP_WRITE; - } -} - -void etk::FSNode::SetGroupRunable(bool newStatus) -{ - // reset the flag : - m_rights &= (0xFFFFFFFF - etk::RIGHT_GROUP_EXECUTE); - if (true == newStatus) { - m_rights |= etk::RIGHT_GROUP_EXECUTE; - } -} - -// other -bool etk::FSNode::IsOtherReadable(void) -{ - return ((m_rights&etk::RIGHT_OTHER_READ)!=0)?true:false; -} - -bool etk::FSNode::IsOtherWritable(void) -{ - return ((m_rights&etk::RIGHT_OTHER_WRITE)!=0)?true:false; -} - -bool etk::FSNode::IsOtherRunable(void) -{ - return ((m_rights&etk::RIGHT_OTHER_EXECUTE)!=0)?true:false; -} - -void etk::FSNode::SetOtherReadable(bool newStatus) -{ - // reset the flag : - m_rights &= (0xFFFFFFFF - etk::RIGHT_OTHER_READ); - if (true == newStatus) { - m_rights |= etk::RIGHT_OTHER_READ; - } -} - -void etk::FSNode::SetOtherWritable(bool newStatus) -{ - // reset the flag : - m_rights &= (0xFFFFFFFF - etk::RIGHT_OTHER_WRITE); - if (true == newStatus) { - m_rights |= etk::RIGHT_OTHER_WRITE; - } -} - -void etk::FSNode::SetOtherRunable(bool newStatus) -{ - // reset the flag : - m_rights &= (0xFFFFFFFF - etk::RIGHT_OTHER_EXECUTE); - if (true == newStatus) { - m_rights |= etk::RIGHT_OTHER_EXECUTE; - } + // TODO : ... + TK_ERROR("Can not set the new rights ..."); + return false; } @@ -730,11 +686,9 @@ void etk::FSNode::SetName(etk::UString newName) etk::UString etk::FSNode::GetNameFolder(void) const { - etk::UString myCompleateName=GetFileSystemName(); - - int32_t lastPos = myCompleateName.FindBack('/'); + int32_t lastPos = m_systemFileName.FindBack('/'); if (-1 != lastPos) { - return myCompleateName.Extract(0, lastPos); + return m_systemFileName.Extract(0, lastPos); } return ""; } @@ -768,10 +722,7 @@ etk::UString etk::FSNode::GetName(void) const output = "CACHE"; break; case etk::FSN_TYPE_THEME: - case etk::FSN_TYPE_THEME__USER_THEME: - case etk::FSN_TYPE_THEME__USER_DEFAULT: - case etk::FSN_TYPE_THEME__APPL_THEME: - case etk::FSN_TYPE_THEME__APPL_DEFAULT: + case etk::FSN_TYPE_THEME_DATA: output = "THEME:"; break; } @@ -782,26 +733,23 @@ etk::UString etk::FSNode::GetName(void) const etk::UString etk::FSNode::GetNameFile(void) const { - etk::UString myCompleateName=GetFileSystemName(); - - int32_t lastPos = myCompleateName.FindBack('/'); + int32_t lastPos = m_systemFileName.FindBack('/'); if (-1 != lastPos) { - return myCompleateName.Extract(lastPos+1); + return m_systemFileName.Extract(lastPos+1); } return ""; } etk::UString etk::FSNode::GetRelativeFolder(void) const { - etk::UString myCompleateName=GetName(); - - int32_t lastPos = myCompleateName.FindBack('/'); + etk::UString tmppp = GetName(); + int32_t lastPos = tmppp.FindBack('/'); if (-1 != lastPos) { - return myCompleateName.Extract(0, lastPos+1); + return tmppp.Extract(0, lastPos+1); } - lastPos = myCompleateName.FindBack(':'); + lastPos = tmppp.FindBack(':'); if (-1 != lastPos) { - return myCompleateName.Extract(0, lastPos+1); + return tmppp.Extract(0, lastPos+1); } return ""; } @@ -815,13 +763,37 @@ bool etk::FSNode::Remove(void) { return false; } -uint64_t etk::FSNode::TimeCreated(void) +uint64_t etk::FSNode::TimeCreated(void) const { - return 0; + return m_timeCreate; } -uint64_t etk::FSNode::TimeModified(void) + +etk::UString etk::FSNode::TimeCreatedString(void) const { - return 0; + time_t tmpVal = (int32_t)m_timeCreate; + return ctime(&tmpVal); +} + +uint64_t etk::FSNode::TimeModified(void) const +{ + return m_timeModify; +} + +etk::UString etk::FSNode::TimeModifiedString(void) const +{ + time_t tmpVal = (int32_t)m_timeModify; + return ctime(&tmpVal); +} + +uint64_t etk::FSNode::TimeAccessed(void) const +{ + return m_timeAccess; +} + +etk::UString etk::FSNode::TimeAccessedString(void) const +{ + time_t tmpVal = (int32_t)m_timeAccess; + return ctime(&tmpVal); } /* @@ -831,9 +803,6 @@ const etk::FSNode& etk::FSNode::operator= (const etk::FSNode &obj ) { if( this != &obj ) // avoid copy to itself { - m_userFileName = obj.m_userFileName; - m_type = obj.m_type; - m_rights = obj.m_rights; if( NULL != m_PointerFile #ifdef __TARGET_OS__Android || NULL != m_zipData @@ -849,6 +818,8 @@ const etk::FSNode& etk::FSNode::operator= (const etk::FSNode &obj ) m_zipDataSize = 0; m_zipReadingOffset = 0; #endif + etk::UString tmppp = obj.GetName(); + PrivateSetName(tmppp); } return *this; } @@ -856,6 +827,7 @@ 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 { @@ -905,17 +877,8 @@ etk::CCout& etk::operator <<(etk::CCout &os, const etk::FSNType_te &obj) case etk::FSN_TYPE_THEME: os << "FSN_TYPE_THEME"; break; - case etk::FSN_TYPE_THEME__USER_THEME: - os << "FSN_TYPE_THEME(USER_THEME)"; - break; - case etk::FSN_TYPE_THEME__USER_DEFAULT: - os << "FSN_TYPE_THEME(USER_DEFAULT)"; - break; - case etk::FSN_TYPE_THEME__APPL_THEME: - os << "FSN_TYPE_THEME(APPL_THEME)"; - break; - case etk::FSN_TYPE_THEME__APPL_DEFAULT: - os << "FSN_TYPE_THEME(APPL_DEFAULT)"; + case etk::FSN_TYPE_THEME_DATA: + os << "FSN_TYPE_THEME(DATA)"; break; default: os << "FSN_TYPE_????"; @@ -924,6 +887,41 @@ etk::CCout& etk::operator <<(etk::CCout &os, const etk::FSNType_te &obj) return os; } +etk::CCout& etk::operator <<(etk::CCout &os, const etk::typeNode_te &obj) +{ + switch (obj) + { + case etk::FSN_UNKNOW: + os << "FSN_UNKNOW"; + break; + case etk::FSN_BLOCK: + os << "FSN_BLOCK"; + break; + case etk::FSN_CHARACTER: + os << "FSN_CHARACTER"; + break; + case etk::FSN_FOLDER: + os << "FSN_FOLDER"; + break; + case etk::FSN_FIFO: + os << "FSN_FIFO"; + break; + case etk::FSN_LINK: + os << "FSN_LINK"; + break; + case etk::FSN_FILE: + os << "FSN_FILE"; + break; + case etk::FSN_SOCKET: + os << "FSN_SOCKET"; + break; + default: + os << "FSN_????"; + break; + } + return os; +} + /* Folder specific : */ @@ -931,9 +929,58 @@ int32_t etk::FSNode::FolderCount(void) { return 0; } -etk::Vector etk::FSNode::FolderGetSubList(void) +etk::Vector etk::FSNode::FolderGetSubList(bool showHidenFile, bool getFolderAndOther, bool getFile, bool temporaryFile) { - etk::Vector tmpp; + etk::Vector tmpp; + if (m_typeNode != etk::FSN_FOLDER ) { + return tmpp; + } + + // regenerate the next list : + etk::FSNode * tmpEmement; + DIR *dir = NULL; + struct dirent *ent = NULL; + dir = opendir(m_systemFileName.c_str()); + if (dir != NULL) { + // for each element in the drectory... + while ((ent = readdir(dir)) != NULL) { + etk::UString tmpName(ent->d_name); + TK_DEBUG(" search in folder\"" << tmpName << "\""); + if( tmpName=="." + || tmpName==".." ) { + // do nothing ... + continue; + } + if( false == tmpName.StartWith(".") + || true == showHidenFile) { + tmpEmement = new etk::FSNode(GetRelativeFolder()+tmpName); + if (NULL == tmpEmement) { + TK_ERROR("allocation error ... of ewol::FSNode"); + continue; + } + if(tmpEmement->GetNodeType() == etk::FSN_FILE) { + if (true == getFile) { + tmpp.PushBack(tmpEmement); + } else { + delete(tmpEmement); + tmpEmement = NULL; + } + } else if (getFolderAndOther) { + tmpp.PushBack(tmpEmement); + } else { + delete(tmpEmement); + tmpEmement = NULL; + } + } + } + closedir(dir); + } else { + TK_ERROR("could not open directory : \"" << *this << "\""); + } + + // reorder the files + SortElementList(tmpp); + return tmpp; } etk::FSNode etk::FSNode::FolderGetParent(void) @@ -971,38 +1018,43 @@ etk::UString etk::FSNode::FileGetExtention(void) } return tmpExt; } -int32_t etk::FSNode::FileSize(void) + +uint64_t etk::FSNode::FileSize(void) { + if (etk::FSN_FILE != m_typeNode) { + TK_ERROR("pppppppppppppppppppppp" << m_typeNode); + return 0; + } #ifdef __TARGET_OS__Android if( etk::FSN_TYPE_DATA == m_type - || etk::FSN_TYPE_THEME__APPL_THEME == m_type - || etk::FSN_TYPE_THEME__APPL_DEFAULT == m_type) { + || etk::FSN_TYPE_THEME_DATA == m_type) { if (true == LoadDataZip()) { return m_zipDataSize; } return 0; } #endif - FILE *myFile=NULL; - etk::UString myCompleateName = GetFileSystemName(); - myFile=fopen(myCompleateName.c_str(),"rb"); - if(NULL == myFile) { - //EWOL_ERROR("Can not find the file " << *this); - return -1; + // 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(m_systemFileName.c_str(), &statProperty)) { + //Normal case when the file does not exist ... ==> the it was in unknow mode ... + TK_ERROR("mlkmlkmlkmlkmlkmlk"); + return 0; } - int32_t size = 0; - fseek(myFile, 0, SEEK_END); - size = ftell(myFile); - fseek(myFile, 0, SEEK_SET); - fclose(myFile); - return size; + TK_INFO(" file size : " << (int64_t)statProperty.st_size << " bytes"); + if ((uint64_t)statProperty.st_size<=0) { + return 0; + } + return (uint64_t)statProperty.st_size; } + + bool etk::FSNode::FileOpenRead(void) { #ifdef __TARGET_OS__Android if( etk::FSN_TYPE_DATA == m_type - || etk::FSN_TYPE_THEME__APPL_THEME == m_type - || etk::FSN_TYPE_THEME__APPL_DEFAULT == m_type) { + || etk::FSN_TYPE_THEME_DATA == m_type) { return LoadDataZip(); } #endif @@ -1010,8 +1062,7 @@ bool etk::FSNode::FileOpenRead(void) TK_CRITICAL("File Already open : " << *this); return true; } - etk::UString myCompleateName = GetFileSystemName(); - m_PointerFile=fopen(myCompleateName.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; @@ -1022,8 +1073,7 @@ bool etk::FSNode::FileOpenWrite(void) { #ifdef __TARGET_OS__Android if( etk::FSN_TYPE_DATA == m_type - || etk::FSN_TYPE_THEME__APPL_THEME == m_type - || etk::FSN_TYPE_THEME__APPL_DEFAULT == m_type) { + || etk::FSN_TYPE_THEME_DATA == m_type) { return false; } #endif @@ -1031,8 +1081,7 @@ bool etk::FSNode::FileOpenWrite(void) TK_CRITICAL("File Already open : " << *this); return true; } - etk::UString myCompleateName = GetFileSystemName(); - m_PointerFile=fopen(myCompleateName.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; @@ -1043,8 +1092,7 @@ bool etk::FSNode::FileClose(void) { #ifdef __TARGET_OS__Android if( etk::FSN_TYPE_DATA == m_type - || etk::FSN_TYPE_THEME__APPL_THEME == m_type - || etk::FSN_TYPE_THEME__APPL_DEFAULT == m_type) { + || etk::FSN_TYPE_THEME_DATA == m_type) { if (NULL == m_zipData) { TK_CRITICAL("File Already closed : " << *this); return false; @@ -1071,8 +1119,7 @@ char* etk::FSNode::FileGets(char * elementLine, int32_t maxData) char * element = elementLine; int32_t outSize = 0; if( etk::FSN_TYPE_DATA == m_type - || etk::FSN_TYPE_THEME__APPL_THEME == m_type - || etk::FSN_TYPE_THEME__APPL_DEFAULT == m_type) {//char * tmpData = internalDataFiles[iii].data + m_readingOffset; + || etk::FSN_TYPE_THEME_DATA == m_type) {//char * tmpData = internalDataFiles[iii].data + m_readingOffset; if (NULL == m_zipData) { element[0] = '\0'; return NULL; @@ -1119,8 +1166,7 @@ int32_t etk::FSNode::FileRead(void * data, int32_t blockSize, int32_t nbBlock) { #ifdef __TARGET_OS__Android if( etk::FSN_TYPE_DATA == m_type - || etk::FSN_TYPE_THEME__APPL_THEME == m_type - || etk::FSN_TYPE_THEME__APPL_DEFAULT == m_type) { + || etk::FSN_TYPE_THEME_DATA == m_type) { if (NULL == m_zipData) { ((char*)data)[0] = '\0'; return 0; @@ -1141,8 +1187,7 @@ int32_t etk::FSNode::FileWrite(void * data, int32_t blockSize, int32_t nbBlock) { #ifdef __TARGET_OS__Android if( etk::FSN_TYPE_DATA == m_type - || etk::FSN_TYPE_THEME__APPL_THEME == m_type - || etk::FSN_TYPE_THEME__APPL_DEFAULT == m_type) { + || etk::FSN_TYPE_THEME_DATA == m_type) { TK_CRITICAL("Can not write on data inside APK : " << *this); return 0; } @@ -1153,8 +1198,7 @@ bool etk::FSNode::FileSeek(long int offset, int origin) { #ifdef __TARGET_OS__Android if( etk::FSN_TYPE_DATA == m_type - || etk::FSN_TYPE_THEME__APPL_THEME == m_type - || etk::FSN_TYPE_THEME__APPL_DEFAULT == m_type) { + || etk::FSN_TYPE_THEME_DATA == m_type) { if (NULL == m_zipData) { return false; } diff --git a/Sources/libetk/etk/os/FSNode.h b/Sources/libetk/etk/os/FSNode.h index 280ee61b..1c2e0d30 100644 --- a/Sources/libetk/etk/os/FSNode.h +++ b/Sources/libetk/etk/os/FSNode.h @@ -26,6 +26,7 @@ #define __ETK_FILE_SYSTEM_NODE_H__ #include +#include #define MAX_FILE_NAME (10240) @@ -33,27 +34,20 @@ namespace etk { - // Right Flags : - enum { - RIGHT_OTHER_EXECUTE = 1 << 0, - RIGHT_OTHER_WRITE = 1 << 1, - RIGHT_OTHER_READ = 1 << 2, - RIGHT_GROUP_EXECUTE = 1 << 3, - RIGHT_GROUP_WRITE = 1 << 4, - RIGHT_GROUP_READ = 1 << 5, - RIGHT_USER_EXECUTE = 1 << 6, - RIGHT_USER_WRITE = 1 << 7, - RIGHT_USER_READ = 1 << 8, - }; typedef enum { FSN_UNKNOW, + FSN_BLOCK, + FSN_CHARACTER, FSN_FOLDER, - FSN_FILE, + FSN_FIFO, FSN_LINK, + FSN_FILE, + FSN_SOCKET, } typeNode_te; - + etk::CCout& operator <<(etk::CCout &os, const etk::typeNode_te &obj); + typedef enum { FSN_TYPE_UNKNOW, // user might done abstraction ==> acces of the sdcard when possible ... @@ -93,10 +87,7 @@ namespace etk // - try on FSN_TYPE_DATA/theme/default/xxx // - try on FSN_TYPE_EWOL_DATA/theme/default/xxx ==> later when the lib will be accessible in packages FSN_TYPE_THEME, - FSN_TYPE_THEME__USER_THEME, - FSN_TYPE_THEME__USER_DEFAULT, - FSN_TYPE_THEME__APPL_THEME, - FSN_TYPE_THEME__APPL_DEFAULT, + FSN_TYPE_THEME_DATA } FSNType_te; etk::CCout& operator <<(etk::CCout &os, const etk::FSNType_te &obj); @@ -133,17 +124,28 @@ namespace etk { private: etk::UString m_userFileName; //!< the name requested by the User + etk::UString m_systemFileName; //!< the compleate filename for the system FSNType_te m_type; //!< the Type of data requested by the User typeNode_te m_typeNode; //!< type of the current file/Folder/Link - //etk::UString m_realFileSystemName; //!< the real FS name - uint32_t m_rights; //!< IO right of the current file + etk::FSNodeRight m_rights; //!< IO right of the current file // specific when file Access : FILE * m_PointerFile; + uint64_t m_timeCreate; + uint64_t m_timeModify; + uint64_t m_timeAccess; + uint32_t m_idOwner; + uint32_t m_idGroup; private: etk::UString GetFileSystemName(void) const; etk::UString GetFileSystemNameTheme(void); void PrivateSetName(etk::UString& newName); bool DirectExistFile(etk::UString tmpFileNameDirect, bool checkInAPKIfNeeded = false); + + // Now we generate the real FS path: + void GenerateFileSystemPath(void); + // now we get all the right if the file existed: + void UpdateFileSystemProperty(void); + private: #ifdef __TARGET_OS__Android bool LoadDataZip(void); @@ -160,32 +162,10 @@ namespace etk /* All Right of the file */ - bool Exist(void); - bool IsFile(void); - bool IsFolder(void); - bool IsLink(void); - // User - bool IsUserReadable(void); - bool IsUserWritable(void); - bool IsUserRunable(void); - void SetUserReadable(bool newStatus); - void SetUserWritable(bool newStatus); - void SetUserRunable(bool newStatus); - // group - bool IsGroupReadable(void); - bool IsGroupWritable(void); - bool IsGroupRunable(void); - void SetGroupReadable(bool newStatus); - void SetGroupWritable(bool newStatus); - void SetGroupRunable(bool newStatus); - // other - bool IsOtherReadable(void); - bool IsOtherWritable(void); - bool IsOtherRunable(void); - void SetOtherReadable(bool newStatus); - void SetOtherWritable(bool newStatus); - void SetOtherRunable(bool newStatus); - + bool Exist(void) { return (m_typeNode!=etk::FSN_UNKNOW); }; + typeNode_te GetNodeType(void) { return m_typeNode; }; + etk::FSNodeRight GetRight(void) { return m_rights; }; + bool SetRight(etk::FSNodeRight newRight); /* Common API : @@ -198,8 +178,13 @@ namespace etk bool Touch(void); FSNType_te GetTypeAccess(void) { return m_type; }; bool Remove(void); - uint64_t TimeCreated(void); - uint64_t TimeModified(void); + // File time properties + uint64_t TimeCreated(void) const; + etk::UString TimeCreatedString(void) const; + uint64_t TimeModified(void) const; + etk::UString TimeModifiedString(void) const; + uint64_t TimeAccessed(void) const; + etk::UString TimeAccessedString(void) const; /* Operator : @@ -212,16 +197,19 @@ namespace etk /* Folder specific : */ - int32_t FolderCount(void); - etk::Vector FolderGetSubList(void); - etk::FSNode FolderGetParent(void); // ordered by name ... + int32_t FolderCount(void); + etk::Vector FolderGetSubList(bool showHidenFile=true, + bool getFolderAndOther=true, + bool getFile=true, + bool temporaryFile=true); + etk::FSNode FolderGetParent(void); // ordered by name ... /* File Specific : */ bool FileHasExtention(void); etk::UString FileGetExtention(void); - int32_t FileSize(void); + uint64_t FileSize(void); bool FileOpenRead(void); bool FileOpenWrite(void); bool FileClose(void); diff --git a/Sources/libetk/etk/os/FSNodeRight.cpp b/Sources/libetk/etk/os/FSNodeRight.cpp new file mode 100644 index 00000000..8f8078a8 --- /dev/null +++ b/Sources/libetk/etk/os/FSNodeRight.cpp @@ -0,0 +1,252 @@ +/** + ******************************************************************************* + * @file etk/os/FSNodeRight.cpp + * @brief Ewol Tool Kit : File System node access abstraction (Sources) + * @author Edouard DUPIN + * @date 2/11/2012 + * @par Project + * Ewol TK + * + * @par Copyright + * Copyright 2011 Edouard DUPIN, all right reserved + * + * This software is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY. + * + * Licence summary : + * You can modify and redistribute the sources code and binaries. + * You can send me the bug-fix + * + * Term of the licence in in the file licence.txt. + * + ******************************************************************************* + */ + + +#include +#include +#include + +// Right Flags : +enum { + RIGHT_OTHER_EXECUTE = 1 << 0, + RIGHT_OTHER_WRITE = 1 << 1, + RIGHT_OTHER_READ = 1 << 2, + RIGHT_GROUP_EXECUTE = 1 << 3, + RIGHT_GROUP_WRITE = 1 << 4, + RIGHT_GROUP_READ = 1 << 5, + RIGHT_USER_EXECUTE = 1 << 6, + RIGHT_USER_WRITE = 1 << 7, + RIGHT_USER_READ = 1 << 8, +}; + +etk::FSNodeRight::FSNodeRight(void) : + m_rights(0) +{ + +} +etk::FSNodeRight::FSNodeRight(int16_t newRight) : + m_rights(newRight&0x01FF) +{ + +} +// copy operator : +const etk::FSNodeRight& etk::FSNodeRight::operator= (const etk::FSNodeRight &obj ) +{ + m_rights = obj.m_rights; + return *this; +} + +// set right : +const etk::FSNodeRight& etk::FSNodeRight::operator= (const int32_t newVal ) +{ + m_rights = newVal&0x01FF; + return *this; +} + +// User +bool etk::FSNodeRight::IsUserReadable(void) const +{ + return ((m_rights&RIGHT_USER_READ)!=0)?true:false; +} + +bool etk::FSNodeRight::IsUserWritable(void) const +{ + return ((m_rights&RIGHT_USER_WRITE)!=0)?true:false; +} + +bool etk::FSNodeRight::IsUserRunable(void) const +{ + return ((m_rights&RIGHT_USER_EXECUTE)!=0)?true:false; +} + +void etk::FSNodeRight::SetUserReadable(bool newStatus) +{ + // reset the flag : + m_rights &= (0xFFFFFFFF - RIGHT_USER_READ); + if (true == newStatus) { + m_rights |= RIGHT_USER_READ; + } +} + +void etk::FSNodeRight::SetUserWritable(bool newStatus) +{ + // reset the flag : + m_rights &= (0xFFFFFFFF - RIGHT_USER_WRITE); + if (true == newStatus) { + m_rights |= RIGHT_USER_WRITE; + } +} + +void etk::FSNodeRight::SetUserRunable(bool newStatus) +{ + // reset the flag : + m_rights &= (0xFFFFFFFF - RIGHT_USER_EXECUTE); + if (true == newStatus) { + m_rights |= RIGHT_USER_EXECUTE; + } +} + +// group +bool etk::FSNodeRight::IsGroupReadable(void) const +{ + return ((m_rights&RIGHT_GROUP_READ)!=0)?true:false; +} + +bool etk::FSNodeRight::IsGroupWritable(void) const +{ + return ((m_rights&RIGHT_GROUP_WRITE)!=0)?true:false; +} + +bool etk::FSNodeRight::IsGroupRunable(void) const +{ + return ((m_rights&RIGHT_GROUP_EXECUTE)!=0)?true:false; +} + +void etk::FSNodeRight::SetGroupReadable(bool newStatus) +{ + // reset the flag : + m_rights &= (0xFFFFFFFF - RIGHT_GROUP_READ); + if (true == newStatus) { + m_rights |= RIGHT_GROUP_READ; + } +} + +void etk::FSNodeRight::SetGroupWritable(bool newStatus) +{ + // reset the flag : + m_rights &= (0xFFFFFFFF - RIGHT_GROUP_WRITE); + if (true == newStatus) { + m_rights |= RIGHT_GROUP_WRITE; + } +} + +void etk::FSNodeRight::SetGroupRunable(bool newStatus) +{ + // reset the flag : + m_rights &= (0xFFFFFFFF - RIGHT_GROUP_EXECUTE); + if (true == newStatus) { + m_rights |= RIGHT_GROUP_EXECUTE; + } +} + +// other +bool etk::FSNodeRight::IsOtherReadable(void) const +{ + return ((m_rights&RIGHT_OTHER_READ)!=0)?true:false; +} + +bool etk::FSNodeRight::IsOtherWritable(void) const +{ + return ((m_rights&RIGHT_OTHER_WRITE)!=0)?true:false; +} + +bool etk::FSNodeRight::IsOtherRunable(void) const +{ + return ((m_rights&RIGHT_OTHER_EXECUTE)!=0)?true:false; +} + +void etk::FSNodeRight::SetOtherReadable(bool newStatus) +{ + // reset the flag : + m_rights &= (0xFFFFFFFF - RIGHT_OTHER_READ); + if (true == newStatus) { + m_rights |= RIGHT_OTHER_READ; + } +} + +void etk::FSNodeRight::SetOtherWritable(bool newStatus) +{ + // reset the flag : + m_rights &= (0xFFFFFFFF - RIGHT_OTHER_WRITE); + if (true == newStatus) { + m_rights |= RIGHT_OTHER_WRITE; + } +} + +void etk::FSNodeRight::SetOtherRunable(bool newStatus) +{ + // reset the flag : + m_rights &= (0xFFFFFFFF - RIGHT_OTHER_EXECUTE); + if (true == newStatus) { + m_rights |= RIGHT_OTHER_EXECUTE; + } +} +etk::UString etk::FSNodeRight::GetRight(void) const +{ + etk::UString tmp; + if (true==IsUserReadable()) { + tmp += "r"; + } else { + tmp += "-"; + } + if (true==IsUserWritable()) { + tmp += "w"; + } else { + tmp += "-"; + } + if (true==IsUserRunable()) { + tmp += "x"; + } else { + tmp += "-"; + } + if (true==IsGroupReadable()) { + tmp += "r"; + } else { + tmp += "-"; + } + if (true==IsGroupWritable()) { + tmp += "w"; + } else { + tmp += "-"; + } + if (true==IsGroupRunable()) { + tmp += "x"; + } else { + tmp += "-"; + } + if (true==IsOtherReadable()) { + tmp += "r"; + } else { + tmp += "-"; + } + if (true==IsOtherWritable()) { + tmp += "w"; + } else { + tmp += "-"; + } + if (true==IsOtherRunable()) { + tmp += "x"; + } else { + tmp += "-"; + } + return tmp; +} + + +etk::CCout& etk::operator <<(etk::CCout &os, const etk::FSNodeRight &obj) +{ + os << obj.GetRight(); + return os; +}; + diff --git a/Sources/libetk/etk/os/FSNodeRight.h b/Sources/libetk/etk/os/FSNodeRight.h new file mode 100644 index 00000000..0573f82e --- /dev/null +++ b/Sources/libetk/etk/os/FSNodeRight.h @@ -0,0 +1,74 @@ +/** + ******************************************************************************* + * @file etk/os/FSNodeRight.h + * @brief Ewol Tool Kit : File System node access abstraction (header) + * @author Edouard DUPIN + * @date 2/11/2012 + * @par Project + * Ewol TK + * + * @par Copyright + * Copyright 2011 Edouard DUPIN, all right reserved + * + * This software is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY. + * + * Licence summary : + * You can modify and redistribute the sources code and binaries. + * You can send me the bug-fix + * + * Term of the licence in in the file licence.txt. + * + ******************************************************************************* + */ + +#ifndef __ETK_FILE_SYSTEM_NODE_RIGHT_H__ +#define __ETK_FILE_SYSTEM_NODE_RIGHT_H__ + +#include + +namespace etk +{ + class FSNodeRight + { + private: + uint16_t m_rights; + public: + FSNodeRight(void); + FSNodeRight(int16_t newRight); + ~FSNodeRight(void) { }; + // copy operator : + const etk::FSNodeRight& operator= (const etk::FSNodeRight &obj ); + // set right : + const etk::FSNodeRight& operator= (const int32_t newVal ); + + void Clear(void) { m_rights = 0; }; + // User + bool IsUserReadable(void) const; + bool IsUserWritable(void) const; + bool IsUserRunable(void) const; + void SetUserReadable(bool newStatus); + void SetUserWritable(bool newStatus); + void SetUserRunable(bool newStatus); + // group + bool IsGroupReadable(void) const; + bool IsGroupWritable(void) const; + bool IsGroupRunable(void) const; + void SetGroupReadable(bool newStatus); + void SetGroupWritable(bool newStatus); + void SetGroupRunable(bool newStatus); + // other + bool IsOtherReadable(void) const; + bool IsOtherWritable(void) const; + bool IsOtherRunable(void) const; + void SetOtherReadable(bool newStatus); + void SetOtherWritable(bool newStatus); + void SetOtherRunable(bool newStatus); + + etk::UString GetRight(void) const; + }; + etk::CCout& operator <<(etk::CCout &os, const etk::FSNodeRight &obj); +}; + +#endif + diff --git a/Sources/libetk/file.mk b/Sources/libetk/file.mk index c6d5b481..580e0fb9 100644 --- a/Sources/libetk/file.mk +++ b/Sources/libetk/file.mk @@ -18,6 +18,7 @@ FILE_LIST+= \ FILE_LIST+= \ etk/os/FSNode.cpp \ + etk/os/FSNodeRight.cpp \ etk/os/Memory.cpp \ diff --git a/Sources/libewol/ewol/ResourceManager.cpp b/Sources/libewol/ewol/ResourceManager.cpp index 502cc7a7..c79d865a 100644 --- a/Sources/libewol/ewol/ResourceManager.cpp +++ b/Sources/libewol/ewol/ResourceManager.cpp @@ -334,7 +334,7 @@ bool ewol::resource::Keep(etk::UString& filename, ewol::TextureFile*& object, et TmpFilename += "x"; TmpFilename += size2.y; - EWOL_INFO("KEEP : TectureFile : file : \"" << TmpFilename << "\" basic size=" << size); + EWOL_INFO("KEEP : TextureFile : file : \"" << TmpFilename << "\" basic size=" << size); object = static_cast(LocalKeep(TmpFilename)); if (NULL != object) { return true; diff --git a/Sources/libewol/ewol/openGL/Program.cpp b/Sources/libewol/ewol/openGL/Program.cpp index 2fdeee46..22a9a9eb 100644 --- a/Sources/libewol/ewol/openGL/Program.cpp +++ b/Sources/libewol/ewol/openGL/Program.cpp @@ -125,10 +125,11 @@ int32_t ewol::Program::GetAttribute(etk::UString tmpElement) tmp.m_name = tmpElement; tmp.m_isAttribute = true; tmp.m_elementId = glGetAttribLocation(m_program, tmp.m_name.c_str()); + tmp.m_isLinked = true; if (tmp.m_elementId<0) { checkGlError("glGetAttribLocation", __LINE__); - EWOL_INFO("glGetAttribLocation(\"" << tmp.m_name << "\") = " << tmp.m_elementId); - return -1; + EWOL_WARNING("glGetAttribLocation(\"" << tmp.m_name << "\") = " << tmp.m_elementId); + tmp.m_isLinked = false; } m_elementList.PushBack(tmp); return m_elementList.Size()-1; @@ -148,10 +149,11 @@ int32_t ewol::Program::GetUniform(etk::UString tmpElement) tmp.m_name = tmpElement; tmp.m_isAttribute = false; tmp.m_elementId = glGetUniformLocation(m_program, tmp.m_name.c_str()); + tmp.m_isLinked = true; if (tmp.m_elementId<0) { checkGlError("glGetUniformLocation", __LINE__); - EWOL_ERROR("glGetUniformLocation(\"" << tmp.m_name << "\") = " << tmp.m_elementId); - return -1; + EWOL_WARNING("glGetUniformLocation(\"" << tmp.m_name << "\") = " << tmp.m_elementId); + tmp.m_isLinked = false; } m_elementList.PushBack(tmp); return m_elementList.Size()-1; @@ -197,15 +199,19 @@ void ewol::Program::UpdateContext(void) for(int32_t iii=0; iiim_elementList.Size()) { return; } + if (false == m_elementList[idElem].m_isLinked) { + return; + } #if 0 glEnable(GL_TEXTURE_2D); checkGlError("glEnable", __LINE__); diff --git a/Sources/libewol/ewol/openGL/Program.h b/Sources/libewol/ewol/openGL/Program.h index 878efc10..1a42bedf 100644 --- a/Sources/libewol/ewol/openGL/Program.h +++ b/Sources/libewol/ewol/openGL/Program.h @@ -39,6 +39,7 @@ etk::UString m_name; GLint m_elementId; bool m_isAttribute; + bool m_isLinked; }; class Program : public ewol::Resource diff --git a/Sources/libewol/ewol/openGL/Shader.cpp b/Sources/libewol/ewol/openGL/Shader.cpp index 85d477f2..7fa79af7 100644 --- a/Sources/libewol/ewol/openGL/Shader.cpp +++ b/Sources/libewol/ewol/openGL/Shader.cpp @@ -42,19 +42,12 @@ ewol::Shader::Shader(etk::UString& filename): EWOL_DEBUG("OGL : load SHADER \"" << filename << "\""); // load data from file "all the time ..." - etk::FSNode file(m_name); - if (false == file.Exist()) { - EWOL_ERROR("File does not Exist : \"" << file << "\""); - return; - } - - etk::UString fileExtention = file.FileGetExtention(); - if (fileExtention == "frag") { + if (true == m_name.EndWith(".frag") ) { m_type = GL_FRAGMENT_SHADER; - } else if (fileExtention == "vert") { + } else if (true == m_name.EndWith(".vert") ) { m_type = GL_VERTEX_SHADER; } else { - EWOL_ERROR("File does not have extention \".vert\" for Vertex Shader or \".frag\" for Fragment Shader. but : \"" << fileExtention << "\""); + EWOL_ERROR("File does not have extention \".vert\" for Vertex Shader or \".frag\" for Fragment Shader. but : \"" << m_name << "\""); return; } Reload(); @@ -143,7 +136,7 @@ void ewol::Shader::Reload(void) return; } - int32_t fileSize = file.FileSize(); + int64_t fileSize = file.FileSize(); if (0==fileSize) { EWOL_ERROR("This file is empty : " << file); return; diff --git a/Sources/libewol/ewol/texture/TextureBMP.cpp b/Sources/libewol/ewol/texture/TextureBMP.cpp index 30bcb51a..459d2376 100644 --- a/Sources/libewol/ewol/texture/TextureBMP.cpp +++ b/Sources/libewol/ewol/texture/TextureBMP.cpp @@ -64,7 +64,7 @@ typedef enum { #undef __class__ #define __class__ "texture::TextureBMP" -void ewol::imageBMP::GenerateImage(etk::FSNode & fileName, draw::Image & ouputImage) +bool ewol::imageBMP::GenerateImage(etk::UString & inputFile, draw::Image & ouputImage) { modeBitmap_te m_dataMode = BITS_16_R5G6B5; int32_t m_width = 0; @@ -72,41 +72,46 @@ void ewol::imageBMP::GenerateImage(etk::FSNode & fileName, draw::Image & ouputIm bitmapFileHeader_ts m_FileHeader; bitmapInfoHeader_ts m_InfoHeader; + etk::FSNode fileName(inputFile); // Get the fileSize ... /*if (fileName.Size() < (int32_t)(sizeof(bitmapFileHeader_ts) + sizeof(bitmapInfoHeader_ts) ) ) { EWOL_ERROR("not enought data in the file named=\"" << fileName << "\""); return; }*/ + if (false==fileName.Exist()) { + EWOL_ERROR("File does not existed=\"" << fileName << "\""); + return false; + } if(false == fileName.FileOpenRead() ) { EWOL_ERROR("Can not find the file name=\"" << fileName << "\""); - return; + return false; } // get the data : if (fileName.FileRead(&m_FileHeader,sizeof(bitmapFileHeader_ts),1) != 1) { EWOL_ERROR("error loading file header"); fileName.FileClose(); - return; + return false; } if (fileName.FileRead(&m_InfoHeader,sizeof(bitmapInfoHeader_ts),1) != 1) { EWOL_ERROR("error loading file header"); fileName.FileClose(); - return; + return false; } if(false == fileName.FileSeek(m_FileHeader.bfOffBits, SEEK_SET)) { EWOL_ERROR("error with the 'bfOffBits' in the file named=\"" << fileName << "\""); fileName.FileClose(); - return; + return false; } // Check the header error : if (m_FileHeader.bfType != 0x4D42) { EWOL_ERROR("the file=\"" << fileName << "\" is not a bitmap file ..."); fileName.FileClose(); - return; + return false; } if (m_FileHeader.bfReserved != 0x00000000) { EWOL_ERROR("the bfReserved feald is not at 0 ==> not supported format ..."); fileName.FileClose(); - return; + return false; } if( m_InfoHeader.biBitCount == 16 && m_InfoHeader.biCompression == 0) @@ -131,7 +136,7 @@ void ewol::imageBMP::GenerateImage(etk::FSNode & fileName, draw::Image & ouputIm } else { EWOL_ERROR("the biBitCount & biCompression fealds are unknow ==> not supported format ..."); fileName.FileClose();; - return; + return false; } m_width = m_InfoHeader.biWidth; m_height = m_InfoHeader.biHeight; @@ -234,6 +239,7 @@ void ewol::imageBMP::GenerateImage(etk::FSNode & fileName, draw::Image & ouputIm delete(m_data); m_data=NULL; } + return true; } /* void ewol::texture::TextureBMP::Display(void) diff --git a/Sources/libewol/ewol/texture/TextureBMP.h b/Sources/libewol/ewol/texture/TextureBMP.h index 8c3b1f47..cf37a370 100644 --- a/Sources/libewol/ewol/texture/TextureBMP.h +++ b/Sources/libewol/ewol/texture/TextureBMP.h @@ -34,7 +34,7 @@ namespace ewol { namespace imageBMP { - void GenerateImage(etk::FSNode & fileName, draw::Image & ouputImage); + bool GenerateImage(etk::UString & inputFile, draw::Image & ouputImage); }; }; diff --git a/Sources/libewol/ewol/texture/TextureFile.cpp b/Sources/libewol/ewol/texture/TextureFile.cpp index 5ebe35f8..64dbbd9e 100644 --- a/Sources/libewol/ewol/texture/TextureFile.cpp +++ b/Sources/libewol/ewol/texture/TextureFile.cpp @@ -36,34 +36,30 @@ ewol::TextureFile::TextureFile(etk::UString genName, etk::UString tmpfileName, etk::Vector2D size) : Texture(genName) { - // load data - etk::FSNode fileName(etk::UString("DATA:") + tmpfileName); - if (false == fileName.Exist()) { - EWOL_ERROR("File does not Exist ... " << fileName << " from : " << tmpfileName); - } else { - // get the upper paw2 ot the size requested... - if (size.x>0 && size.y>0) { - SetImageSize(size); - } - - etk::UString fileExtention = fileName.FileGetExtention(); - if (fileExtention == "bmp") { - // generate the texture - ewol::imageBMP::GenerateImage(fileName, m_data); - } else if (fileExtention == "svg") { - svg::Parser m_element(fileName); - if (false == m_element.IsLoadOk()) { - EWOL_ERROR("Error To load SVG file " << fileName ); - } else { - // generate the texture - m_element.GenerateAnImage(size, m_data); - } - } else if (fileExtention == "png") { - EWOL_ERROR("Extention not supported now, but soon " << fileName ); - } else { - EWOL_ERROR("Extention not managed " << fileName << " Sopported extention : .bmp / .svg / .png"); - } - Flush(); + etk::UString tmpName = etk::UString("DATA:") + tmpfileName; + // get the upper paw2 ot the size requested... + if (size.x>0 && size.y>0) { + SetImageSize(size); } + // load data + if (true == tmpName.EndWith(".bmp") ) { + // generate the texture + if (false == ewol::imageBMP::GenerateImage(tmpName, m_data)) { + EWOL_ERROR("Error To load BMP file " << tmpName ); + } + } else if (true == tmpName.EndWith(".svg") ) { + svg::Parser m_element(tmpName); + if (false == m_element.IsLoadOk()) { + EWOL_ERROR("Error To load SVG file " << tmpName ); + } else { + // generate the texture + m_element.GenerateAnImage(size, m_data); + } + } else if (true == tmpName.EndWith(".png") ) { + EWOL_ERROR("Extention not supported now, but soon " << tmpName ); + } else { + EWOL_ERROR("Extention not managed " << tmpName << " Sopported extention : .bmp / .svg / .png"); + } + Flush(); } diff --git a/Sources/libewol/ewol/texture/TextureSVG.cpp b/Sources/libewol/ewol/texture/TextureSVG.cpp index 2ed0e356..122f2d8a 100644 --- a/Sources/libewol/ewol/texture/TextureSVG.cpp +++ b/Sources/libewol/ewol/texture/TextureSVG.cpp @@ -32,7 +32,8 @@ #define __class__ "texture::TextureSVG" -ewol::texture::TextureSVG::TextureSVG(etk::FSNode & fileName, int32_t width, int32_t height) : m_elementParsed(fileName) +ewol::texture::TextureSVG::TextureSVG(etk::UString & fileName, int32_t width, int32_t height) : + m_elementParsed(fileName) { m_loadOK = false; if (false == m_elementParsed.IsLoadOk()) { diff --git a/Sources/libewol/ewol/texture/TextureSVG.h b/Sources/libewol/ewol/texture/TextureSVG.h index 034608a3..5723cf15 100644 --- a/Sources/libewol/ewol/texture/TextureSVG.h +++ b/Sources/libewol/ewol/texture/TextureSVG.h @@ -42,7 +42,7 @@ namespace ewol uint8_t * m_data; bool m_loadOK; public: - TextureSVG(etk::FSNode & fileName, int32_t width, int32_t height); + TextureSVG(etk::UString & fileName, int32_t width, int32_t height); ~TextureSVG(void); bool LoadOK(void); int32_t Width(void); diff --git a/Sources/libewol/ewol/widget/Entry.cpp b/Sources/libewol/ewol/widget/Entry.cpp index 7a4f629e..845eec1b 100644 --- a/Sources/libewol/ewol/widget/Entry.cpp +++ b/Sources/libewol/ewol/widget/Entry.cpp @@ -210,21 +210,11 @@ void ewol::Entry::OnDraw(DrawProperty& displayProp) // position : m_GLprogram->SendAttribute(m_GLPosition, 2/*x,y*/, &m_coord[0]); // all entry parameters : - if (0<=m_GLsizeBorder) { - m_GLprogram->Uniform1f(m_GLsizeBorder, m_borderSize); - } - if (0<=m_GLsizePadding) { - m_GLprogram->Uniform1f(m_GLsizePadding, m_paddingSize); - } - if (0<=m_GLsize) { - m_GLprogram->Uniform2fv(m_GLsize, 1, &m_size.x); - } - if (0<=m_GLposText) { - m_GLprogram->Uniform4fv(m_GLposText, 1, m_pos); - } - if (0<=m_GLstate) { - m_GLprogram->Uniform1i(m_GLstate, 0); - } + m_GLprogram->Uniform1f(m_GLsizeBorder, m_borderSize); + m_GLprogram->Uniform1f(m_GLsizePadding, m_paddingSize); + m_GLprogram->Uniform2fv(m_GLsize, 1, &m_size.x); + m_GLprogram->Uniform4fv(m_GLposText, 1, m_pos); + m_GLprogram->Uniform1i(m_GLstate, 0); // Request the draw of the elements : glDrawArrays(GL_TRIANGLES, 0, m_coord.Size()); m_GLprogram->UnUse(); diff --git a/Sources/libewol/ewol/widget/ListFileSystem.cpp b/Sources/libewol/ewol/widget/ListFileSystem.cpp index d6c05c42..9ae3dd26 100644 --- a/Sources/libewol/ewol/widget/ListFileSystem.cpp +++ b/Sources/libewol/ewol/widget/ListFileSystem.cpp @@ -25,13 +25,6 @@ #include #include -#include - -// TODO : Remove the link with this at this level of abstraction ... -extern "C" { - // file browsing ... - #include -} #undef __class__ #define __class__ "ListFileSystem" @@ -41,26 +34,6 @@ extern const char * const ewolEventFSFileValidate = "ewol-event-file-system-fi extern const char * const ewolEventFSFolderSelect = "ewol-event-file-system-folder-select"; extern const char * const ewolEventFSFolderValidate = "ewol-event-file-system-folder-validate"; -static void SortElementList(etk::Vector &list) -{ - etk::Vector tmpList = list; - list.Clear(); - for(int32_t iii=0; iiim_name > list[jjj]->m_name) { - findPos = jjj+1; - } - } - } - //EWOL_DEBUG("position="<d_name, '.') == NULL) { - localType = DIRECTORY_TYPE_FOLDER; - } else { - localType = DIRECTORY_TYPE_FILE; - } - #else - switch(ent->d_type) - { - case DT_DIR: - localType = DIRECTORY_TYPE_FOLDER; - break; - case DT_REG: - localType = DIRECTORY_TYPE_FILE; - break; - } - #endif - if( true==m_showFile - && DIRECTORY_TYPE_FILE==localType) { - if (ent->d_name != NULL) { - etk::UString tmpString(ent->d_name); - if( false==tmpString.StartWith(".") - || true ==m_showHidden) { - tmpEmement = new ewol::elementFS(tmpString, ewol::EFS_FILE); - if (NULL != tmpEmement) { - m_list.PushBack(tmpEmement); - } - tmpEmement = NULL; - } - } - } - if( true==m_showFolder - && DIRECTORY_TYPE_FOLDER==localType) { - if (ent->d_name != NULL) { - etk::UString tmpString(ent->d_name); - //EWOL_DEBUG(" find Folder : \"" << tmpString << "\"(" << tmpString.Size() << ") ?= \"" << ent->d_name << "\"(" << strlen(ent->d_name) ); - if (tmpString != "." && tmpString != "..") { - if( false==tmpString.StartWith(".") - || true ==m_showHidden) { - tmpEmement = new ewol::elementFS(tmpString, ewol::EFS_FOLDER); - if (NULL != tmpEmement) { - m_list.PushBack(tmpEmement); - } - tmpEmement = NULL; - } - } - } - } - } - closedir(dir); - } else { - EWOL_ERROR("could not open directory : \"" << m_folder << "\""); - } - - // reorder the files - SortElementList(m_list); + etk::FSNode tmpFolder(m_folder); + // Get the new list : + m_list = tmpFolder.FolderGetSubList(m_showHidden, m_showFolder, m_showFile, m_showTemporaryFile); // request a redraw ... MarkToRedraw(); } @@ -253,7 +136,7 @@ etk::UString ewol::ListFileSystem::GetSelect(void) etk::UString tmpVal = ""; if (m_selectedLine >= 0) { if (m_list[m_selectedLine] != NULL) { - tmpVal = m_list[m_selectedLine]->m_name; + tmpVal = m_list[m_selectedLine]->GetNameFile(); } } return tmpVal; @@ -266,7 +149,7 @@ void ewol::ListFileSystem::SetSelect( etk::UString data) { // search the coresponding file : for (int32_t iii=0; iiim_name == data) { + if (m_list[iii]->GetNameFile() == data) { // we find the line : m_selectedLine = iii; break; @@ -288,7 +171,7 @@ uint32_t ewol::ListFileSystem::GetNuberOfRaw(void) { }; bool ewol::ListFileSystem::GetElement(int32_t colomn, int32_t raw, etk::UString &myTextToWrite, draw::Color &fg, draw::Color &bg) { if (raw >= 0 && raw < m_list.Size() && NULL != m_list[raw]) { - myTextToWrite = m_list[raw]->m_name; + myTextToWrite = m_list[raw]->GetNameFile(); } else { myTextToWrite = "ERROR"; } @@ -321,13 +204,13 @@ bool ewol::ListFileSystem::OnItemEvent(int32_t IdInput, ewol::eventInputType_te && m_selectedLine < m_list.Size() && NULL != m_list[m_selectedLine] ) { // generate event extern : - switch(m_list[m_selectedLine]->m_type) + switch(m_list[m_selectedLine]->GetNodeType()) { - case ewol::EFS_FILE : - GenerateEventId(ewolEventFSFileSelect, m_list[m_selectedLine]->m_name); + case etk::FSN_FILE : + GenerateEventId(ewolEventFSFileSelect, m_list[m_selectedLine]->GetNameFile()); break; - case ewol::EFS_FOLDER : - GenerateEventId(ewolEventFSFolderSelect, m_list[m_selectedLine]->m_name); + case etk::FSN_FOLDER : + GenerateEventId(ewolEventFSFolderSelect, m_list[m_selectedLine]->GetNameFile()); break; default: EWOL_ERROR("Can not generate event on an unknow type"); @@ -338,13 +221,13 @@ bool ewol::ListFileSystem::OnItemEvent(int32_t IdInput, ewol::eventInputType_te if( m_selectedLine >=0 && m_selectedLine < m_list.Size() && NULL != m_list[m_selectedLine] ) { - switch(m_list[m_selectedLine]->m_type) + switch(m_list[m_selectedLine]->GetNodeType()) { - case ewol::EFS_FILE : - GenerateEventId(ewolEventFSFileValidate, m_list[m_selectedLine]->m_name); + case etk::FSN_FILE : + GenerateEventId(ewolEventFSFileValidate, m_list[m_selectedLine]->GetNameFile()); break; - case ewol::EFS_FOLDER : - GenerateEventId(ewolEventFSFolderValidate, m_list[m_selectedLine]->m_name); + case etk::FSN_FOLDER : + GenerateEventId(ewolEventFSFolderValidate, m_list[m_selectedLine]->GetNameFile()); break; default: EWOL_ERROR("Can not generate event on an unknow type"); diff --git a/Sources/libewol/ewol/widget/ListFileSystem.h b/Sources/libewol/ewol/widget/ListFileSystem.h index c3c9fb47..673bcea7 100644 --- a/Sources/libewol/ewol/widget/ListFileSystem.h +++ b/Sources/libewol/ewol/widget/ListFileSystem.h @@ -26,6 +26,7 @@ #define __EWOL_LIST_FILE_H__ #include +#include extern const char * const ewolEventFSFileSelect; extern const char * const ewolEventFSFileValidate; @@ -33,35 +34,16 @@ extern const char * const ewolEventFSFolderSelect; extern const char * const ewolEventFSFolderValidate; namespace ewol { - typedef enum { - EFS_FOLDER, - EFS_FILE, - EFS_LINK, - } elementFS_te; - - class elementFS - { - public : - etk::UString m_name; - elementFS_te m_type; - int32_t m_rights; - elementFS(etk::UString name, elementFS_te type) : - m_name(name), - m_type(type), - m_rights(0) - { }; - ~elementFS(void) {}; - }; class ListFileSystem : public ewol::List { private: - etk::Vector m_list; - etk::UString m_folder; - int32_t m_selectedLine; - bool m_showFile; - bool m_showTemporaryFile; - bool m_showFolder; - bool m_showHidden; + etk::Vector m_list; + etk::UString m_folder; + int32_t m_selectedLine; + bool m_showFile; + bool m_showTemporaryFile; + bool m_showFolder; + bool m_showHidden; public: ListFileSystem(void); ~ListFileSystem(void); diff --git a/Sources/libparsersvg b/Sources/libparsersvg index 4ee34e68..edfe4d2a 160000 --- a/Sources/libparsersvg +++ b/Sources/libparsersvg @@ -1 +1 @@ -Subproject commit 4ee34e68155bfdc528d4371ed939b9de75aaf3c2 +Subproject commit edfe4d2aa6e50b496ff3c10203984e5b090c516d