diff --git a/source/fs/DirList.cpp b/source/fs/DirList.cpp index 932d9fe..97557a7 100644 --- a/source/fs/DirList.cpp +++ b/source/fs/DirList.cpp @@ -39,11 +39,12 @@ DirList::DirList() { Flags = 0; Filter = 0; + Depth = 0; } -DirList::DirList(const std::string & path, const char *filter, u32 flags) +DirList::DirList(const std::string & path, const char *filter, u32 flags, u32 maxDepth) { - this->LoadPath(path, filter, flags); + this->LoadPath(path, filter, flags, maxDepth); this->SortList(); } @@ -52,12 +53,13 @@ DirList::~DirList() ClearList(); } -bool DirList::LoadPath(const std::string & folder, const char *filter, u32 flags) +bool DirList::LoadPath(const std::string & folder, const char *filter, u32 flags, u32 maxDepth) { if(folder.empty()) return false; Flags = flags; Filter = filter; + Depth = maxDepth; std::string folderpath(folder); u32 length = folderpath.size(); @@ -69,6 +71,11 @@ bool DirList::LoadPath(const std::string & folder, const char *filter, u32 flags if(length > 0 && folderpath[length-1] == '/') folderpath.erase(length-1); + //! add root slash if missing + if(folderpath.find('/') == std::string::npos){ + folderpath += '/'; + } + return InternalLoadPath(folderpath); } @@ -94,15 +101,19 @@ bool DirList::InternalLoadPath(std::string &folderpath) if(strcmp(filename,".") == 0 || strcmp(filename,"..") == 0) continue; - if(Flags & CheckSubfolders) + if((Flags & CheckSubfolders) && (Depth > 0)) { - s32 length = folderpath.size(); - if(length > 2 && folderpath[length-1] != '/') - folderpath += '/'; - folderpath += filename; - InternalLoadPath(folderpath); - folderpath.erase(length); - } + s32 length = folderpath.size(); + if(length > 2 && folderpath[length-1] != '/'){ + folderpath += '/'; + } + folderpath += filename; + + Depth--; + InternalLoadPath(folderpath); + folderpath.erase(length); + Depth++; + } if(!(Flags & Dirs)) continue; @@ -158,7 +169,7 @@ void DirList::ClearList() if(FileInfo[i].FilePath){ free(FileInfo[i].FilePath); FileInfo[i].FilePath = NULL; - } + } } FileInfo.clear(); diff --git a/source/fs/DirList.h b/source/fs/DirList.h index 331abc9..effa80a 100644 --- a/source/fs/DirList.h +++ b/source/fs/DirList.h @@ -45,11 +45,11 @@ public: //!\param path Path from where to load the filelist of all files //!\param filter A fileext that needs to be filtered //!\param flags search/filter flags from the enum - DirList(const std::string & path, const char *filter = NULL, u32 flags = Files | Dirs); + DirList(const std::string & path, const char *filter = NULL, u32 flags = Files | Dirs, u32 maxDepth = 0xffffffff); //!Destructor virtual ~DirList(); //! Load all the files from a directory - bool LoadPath(const std::string & path, const char *filter = NULL, u32 flags = Files | Dirs); + bool LoadPath(const std::string & path, const char *filter = NULL, u32 flags = Files | Dirs, u32 maxDepth = 0xffffffff); //! Get a filename of the list //!\param list index const char * GetFilename(s32 index) const; @@ -88,6 +88,7 @@ protected: inline bool valid(u32 pos) const { return (pos < FileInfo.size()); }; u32 Flags; + u32 Depth; const char *Filter; std::vector FileInfo; }; diff --git a/source/utils/utils.h b/source/utils/utils.h index 2b33e34..95bf98d 100644 --- a/source/utils/utils.h +++ b/source/utils/utils.h @@ -39,6 +39,8 @@ extern "C" { #define le32(i) ((((u32)le16((i) & 0xFFFF)) << 16) | ((u32)le16(((i) & 0xFFFF0000) >> 16))) #define le64(i) ((((u64)le32((i) & 0xFFFFFFFFLL)) << 32) | ((u64)le32(((i) & 0xFFFFFFFF00000000LL) >> 32))) +unsigned int getApplicationEndAddr(void); + #ifdef __cplusplus } #endif diff --git a/source/utils/utils.s b/source/utils/utils.s new file mode 100644 index 0000000..b210f76 --- /dev/null +++ b/source/utils/utils.s @@ -0,0 +1,5 @@ + .globl getApplicationEndAddr +getApplicationEndAddr: + lis r3, __CODE_END@h + ori r3, r3, __CODE_END@l + blr