mirror of
https://github.com/Maschell/libutils.git
synced 2024-11-05 20:55:08 +01:00
Extends the DirtList class
This commit is contained in:
parent
0315280370
commit
9d32fea60d
@ -39,11 +39,12 @@ DirList::DirList()
|
|||||||
{
|
{
|
||||||
Flags = 0;
|
Flags = 0;
|
||||||
Filter = 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();
|
this->SortList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,12 +53,13 @@ DirList::~DirList()
|
|||||||
ClearList();
|
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;
|
if(folder.empty()) return false;
|
||||||
|
|
||||||
Flags = flags;
|
Flags = flags;
|
||||||
Filter = filter;
|
Filter = filter;
|
||||||
|
Depth = maxDepth;
|
||||||
|
|
||||||
std::string folderpath(folder);
|
std::string folderpath(folder);
|
||||||
u32 length = folderpath.size();
|
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] == '/')
|
if(length > 0 && folderpath[length-1] == '/')
|
||||||
folderpath.erase(length-1);
|
folderpath.erase(length-1);
|
||||||
|
|
||||||
|
//! add root slash if missing
|
||||||
|
if(folderpath.find('/') == std::string::npos){
|
||||||
|
folderpath += '/';
|
||||||
|
}
|
||||||
|
|
||||||
return InternalLoadPath(folderpath);
|
return InternalLoadPath(folderpath);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,14 +101,18 @@ bool DirList::InternalLoadPath(std::string &folderpath)
|
|||||||
if(strcmp(filename,".") == 0 || strcmp(filename,"..") == 0)
|
if(strcmp(filename,".") == 0 || strcmp(filename,"..") == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if(Flags & CheckSubfolders)
|
if((Flags & CheckSubfolders) && (Depth > 0))
|
||||||
{
|
{
|
||||||
s32 length = folderpath.size();
|
s32 length = folderpath.size();
|
||||||
if(length > 2 && folderpath[length-1] != '/')
|
if(length > 2 && folderpath[length-1] != '/'){
|
||||||
folderpath += '/';
|
folderpath += '/';
|
||||||
|
}
|
||||||
folderpath += filename;
|
folderpath += filename;
|
||||||
|
|
||||||
|
Depth--;
|
||||||
InternalLoadPath(folderpath);
|
InternalLoadPath(folderpath);
|
||||||
folderpath.erase(length);
|
folderpath.erase(length);
|
||||||
|
Depth++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!(Flags & Dirs))
|
if(!(Flags & Dirs))
|
||||||
|
@ -45,11 +45,11 @@ public:
|
|||||||
//!\param path Path from where to load the filelist of all files
|
//!\param path Path from where to load the filelist of all files
|
||||||
//!\param filter A fileext that needs to be filtered
|
//!\param filter A fileext that needs to be filtered
|
||||||
//!\param flags search/filter flags from the enum
|
//!\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
|
//!Destructor
|
||||||
virtual ~DirList();
|
virtual ~DirList();
|
||||||
//! Load all the files from a directory
|
//! 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
|
//! Get a filename of the list
|
||||||
//!\param list index
|
//!\param list index
|
||||||
const char * GetFilename(s32 index) const;
|
const char * GetFilename(s32 index) const;
|
||||||
@ -88,6 +88,7 @@ protected:
|
|||||||
inline bool valid(u32 pos) const { return (pos < FileInfo.size()); };
|
inline bool valid(u32 pos) const { return (pos < FileInfo.size()); };
|
||||||
|
|
||||||
u32 Flags;
|
u32 Flags;
|
||||||
|
u32 Depth;
|
||||||
const char *Filter;
|
const char *Filter;
|
||||||
std::vector<DirEntry> FileInfo;
|
std::vector<DirEntry> FileInfo;
|
||||||
};
|
};
|
||||||
|
@ -39,6 +39,8 @@ extern "C" {
|
|||||||
#define le32(i) ((((u32)le16((i) & 0xFFFF)) << 16) | ((u32)le16(((i) & 0xFFFF0000) >> 16)))
|
#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)))
|
#define le64(i) ((((u64)le32((i) & 0xFFFFFFFFLL)) << 32) | ((u64)le32(((i) & 0xFFFFFFFF00000000LL) >> 32)))
|
||||||
|
|
||||||
|
unsigned int getApplicationEndAddr(void);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
5
source/utils/utils.s
Normal file
5
source/utils/utils.s
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
.globl getApplicationEndAddr
|
||||||
|
getApplicationEndAddr:
|
||||||
|
lis r3, __CODE_END@h
|
||||||
|
ori r3, r3, __CODE_END@l
|
||||||
|
blr
|
Loading…
Reference in New Issue
Block a user