diff --git a/inc/hgl/filesystem/FileSystem.h b/inc/hgl/filesystem/FileSystem.h index 9d5cc35..7a72092 100644 --- a/inc/hgl/filesystem/FileSystem.h +++ b/inc/hgl/filesystem/FileSystem.h @@ -46,6 +46,20 @@ namespace hgl bool GetCurrentProgramPath(OSString &); ///<取得当前程序所在路径 bool GetLocalAppdataPath(OSString &); ///<取得当前用户应用程序数据存放路径 + bool GetOSLibararyPath(OSString &); ///<取得操作系统共用动态库路径 + + + /** + * @param filename 要查找的文件名称 + * @param user_data 用户自定义数据 + * @param exist 文件是否存在 + * @return 是否继续查找 + */ + typedef bool (*OnFindedFileFUNC)(const OSString &filename,void *user_data,bool exist); + + const uint FindFileOnPaths(const OSString &filename,const OSStringList &paths,void *user_data,OnFindedFileFUNC ff); ///<在多个目录内查找一个文件 + const uint FindFileOnPaths(const OSStringList &filenames,const OSStringList &paths,void *user_data,OnFindedFileFUNC ff); ///<在多个目录内查找一个文件,这个文件可能有多个文件名 + /** * 文件名长度限制 * diff --git a/inc/hgl/filesystem/Filename.h b/inc/hgl/filesystem/Filename.h index acc365f..4d065ad 100644 --- a/inc/hgl/filesystem/Filename.h +++ b/inc/hgl/filesystem/Filename.h @@ -79,7 +79,7 @@ namespace hgl * 根据离散的每一级目录名称和最终名称合成完整文件名 */ template - inline const String ComboFilename(const StringList> &sl,const T spear_char=(T)HGL_DIRECTORY_SEPARATOR_RAWCHAR) + inline const String ComboFilename(const StringList &sl,const T spear_char=(T)HGL_DIRECTORY_SEPARATOR_RAWCHAR) { T **str_list=AutoDeleteArray(sl.GetCount()); int *str_len=AutoDeleteArray(sl.GetCount()); diff --git a/src/FileSystem/FileSystem.cpp b/src/FileSystem/FileSystem.cpp index 257656c..db2f693 100644 --- a/src/FileSystem/FileSystem.cpp +++ b/src/FileSystem/FileSystem.cpp @@ -379,5 +379,72 @@ namespace hgl return(true); } + + /** + * 在多个目录内查找一个文件 + * @param filename 要查找的文件名称 + * @param paths 要查找的目录 + * @param user_data 用户自定义数据 + * @param ff 查找响应事件函数 + */ + const uint FindFileOnPaths(const OSString &filename,const OSStringList &paths,void *user_data,OnFindedFileFUNC ff) + { + if(filename.IsEmpty()||paths.GetCount()<=0)return(0); + if(ff==nullptr)return 0; + + uint count=0; + bool exist; + OSString full_filename; + + for(const OSString *pn:paths) + { + full_filename=MergeFilename(*pn,filename); + + exist=FileExist(full_filename); + + if(exist) + ++count; + + if(!ff(full_filename,user_data,exist)) + return(count); + } + + return count; + } + + /** + * 在多个目录内查找一个文件,这个文件可能有多个文件名 + * @param filenames 要查找的文件名称 + * @param paths 要查找的目录 + * @param user_data 用户自定义数据 + * @param ff 查找响应事件函数 + */ + const uint FindFileOnPaths(const OSStringList &filenames,const OSStringList &paths,void *user_data,OnFindedFileFUNC ff) + { + if(filenames.GetCount()<=0||paths.GetCount()<=0)return(0); + if(ff==nullptr)return 0; + + uint count=0; + bool exist; + OSString full_filename; + + for(const OSString *pn:paths) + { + for(const OSString *fn:filenames) + { + full_filename=MergeFilename(*pn,*fn); + + exist=FileExist(full_filename); + + if(exist) + ++count; + + if(!ff(full_filename,user_data,exist)) + return(count); + } + } + + return count; + } }//namespace filesystem }//namespace hgl