added GetOSLibararyPath and FindFileOnPaths functions.
This commit is contained in:
parent
a4d1ed0c3c
commit
08d2fa2a1f
@ -46,6 +46,20 @@ namespace hgl
|
|||||||
bool GetCurrentProgramPath(OSString &); ///<取得当前程序所在路径
|
bool GetCurrentProgramPath(OSString &); ///<取得当前程序所在路径
|
||||||
bool GetLocalAppdataPath(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); ///<在多个目录内查找一个文件,这个文件可能有多个文件名
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 文件名长度限制
|
* 文件名长度限制
|
||||||
*
|
*
|
||||||
|
@ -79,7 +79,7 @@ namespace hgl
|
|||||||
* 根据离散的每一级目录名称和最终名称合成完整文件名
|
* 根据离散的每一级目录名称和最终名称合成完整文件名
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
inline const String<T> ComboFilename(const StringList<String<T>> &sl,const T spear_char=(T)HGL_DIRECTORY_SEPARATOR_RAWCHAR)
|
inline const String<T> ComboFilename(const StringList<T> &sl,const T spear_char=(T)HGL_DIRECTORY_SEPARATOR_RAWCHAR)
|
||||||
{
|
{
|
||||||
T **str_list=AutoDeleteArray<T *>(sl.GetCount());
|
T **str_list=AutoDeleteArray<T *>(sl.GetCount());
|
||||||
int *str_len=AutoDeleteArray<int>(sl.GetCount());
|
int *str_len=AutoDeleteArray<int>(sl.GetCount());
|
||||||
|
@ -379,5 +379,72 @@ namespace hgl
|
|||||||
|
|
||||||
return(true);
|
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 filesystem
|
||||||
}//namespace hgl
|
}//namespace hgl
|
||||||
|
Loading…
x
Reference in New Issue
Block a user