Extends the DirtList class

This commit is contained in:
Maschell 2017-10-31 20:43:35 +01:00
parent 0315280370
commit 9d32fea60d
4 changed files with 33 additions and 14 deletions

View File

@ -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();

View File

@ -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<DirEntry> FileInfo;
};

View File

@ -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

5
source/utils/utils.s Normal file
View File

@ -0,0 +1,5 @@
.globl getApplicationEndAddr
getApplicationEndAddr:
lis r3, __CODE_END@h
ori r3, r3, __CODE_END@l
blr