2019-08-19 19:19:58 +08:00
|
|
|
|
#ifndef HGL_FILE_SYSTEM_INCLUDE
|
|
|
|
|
#define HGL_FILE_SYSTEM_INCLUDE
|
|
|
|
|
|
2021-01-21 11:52:37 +08:00
|
|
|
|
#include<hgl/filesystem/Filename.h>
|
2019-08-19 19:19:58 +08:00
|
|
|
|
namespace hgl
|
|
|
|
|
{
|
|
|
|
|
namespace io
|
|
|
|
|
{
|
|
|
|
|
class InputStream;
|
|
|
|
|
}//namespace io
|
|
|
|
|
|
|
|
|
|
namespace filesystem
|
|
|
|
|
{
|
|
|
|
|
bool FileCopy(const OSString &,const OSString &); ///<文件复制
|
|
|
|
|
bool FileDelete(const OSString &); ///<文件删除
|
|
|
|
|
bool FileMove(const OSString &,const OSString &); ///<文件移动
|
|
|
|
|
bool FileRename(const OSString &,const OSString &); ///<文件改名
|
|
|
|
|
bool FileExist(const OSString &); ///<文件确认是否存在
|
2020-05-06 17:13:16 +08:00
|
|
|
|
bool FileComp(const OSString &,const OSString &,const size_t buf_size=HGL_SIZE_1MB); ///<文件比较
|
2019-08-19 19:19:58 +08:00
|
|
|
|
|
|
|
|
|
bool FileCanRead(const OSString &); ///<检测文件是否可读
|
|
|
|
|
bool FileCanWrite(const OSString &); ///<检测文件是否可写
|
|
|
|
|
bool FileCanExec(const OSString &); ///<检测文件是否可执行
|
|
|
|
|
|
2022-03-17 23:16:44 +08:00
|
|
|
|
uint64 FileLastWriteTime(const OSString &); ///<获取文件最后写入时间
|
|
|
|
|
|
2020-06-05 11:00:58 +08:00
|
|
|
|
void *LoadFileToMemory(const OSString &,int64 &,bool append_zero=false); ///<加载一个文件到内存
|
2020-04-08 18:08:18 +08:00
|
|
|
|
int64 LoadFileToMemory(const OSString &,void **,bool append_zero=false); ///<加载一个文件到内存
|
2019-08-19 19:19:58 +08:00
|
|
|
|
int64 SaveMemoryToFile(const OSString &,const void *,const int64 &); ///<保存一块内存成文件
|
|
|
|
|
int64 SaveMemoryToFile(const OSString &,void **,const int64 *,const int &); ///<保存多块内存成一个文件
|
|
|
|
|
|
|
|
|
|
void *LoadFileToMemory(const OSString &,int64,void *buf,int64); ///<加载一个文件的一部分到内存
|
|
|
|
|
bool SaveMemoryToFile(const OSString &,int64,const void *,int64); ///<保存一块内存到一个文件
|
|
|
|
|
|
|
|
|
|
bool IsDirectory(const os_char *);
|
2024-03-09 20:47:19 +08:00
|
|
|
|
inline bool IsDirectory(const OSString &str){return IsDirectory(str.c_str());} ///<判断这个名称是否是目录
|
2019-08-19 19:19:58 +08:00
|
|
|
|
|
|
|
|
|
#if HGL_OS != HGL_OS_Windows
|
|
|
|
|
bool IsLink(const os_char *); ///<判断这个名称是否是链接
|
|
|
|
|
#endif//
|
|
|
|
|
|
|
|
|
|
bool MakePath(const OSString &); ///<创建一个路径
|
|
|
|
|
bool DeletePath(const OSString &); ///<删除一个路径
|
|
|
|
|
void DeleteTree(const OSString &); ///<删除一个路径(包含所有文件)
|
|
|
|
|
|
|
|
|
|
bool GetCurrentPath(OSString &); ///<取得当前路径
|
|
|
|
|
bool GetCurrentProgram(OSString &); ///<取得当前程序全路径名称
|
|
|
|
|
bool GetCurrentProgramPath(OSString &); ///<取得当前程序所在路径
|
2020-10-09 18:24:40 +08:00
|
|
|
|
bool GetLocalAppdataPath(OSString &); ///<取得当前用户应用程序数据存放路径
|
2019-08-19 19:19:58 +08:00
|
|
|
|
|
2022-03-31 18:13:36 +08:00
|
|
|
|
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); ///<在多个目录内查找一个文件,这个文件可能有多个文件名
|
|
|
|
|
|
2021-09-07 13:07:47 +08:00
|
|
|
|
/**
|
|
|
|
|
* 文件名长度限制
|
|
|
|
|
*
|
|
|
|
|
* OS | FILENAME | FILENAME+PATHNAME |
|
|
|
|
|
* ------------------+----------+-------------------+
|
|
|
|
|
* Windows 256 260
|
|
|
|
|
* Windows 10(>1607) 32767 32767 // max length must get from lpMaximumComponentLength of GetVolumeInformation
|
|
|
|
|
* // https://docs.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=powershell
|
|
|
|
|
*
|
|
|
|
|
* MacOS/Solaris/AIX 255 1024
|
|
|
|
|
* Linux 255 1024/4096
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
//使用int64而不是__int64是因为不是所有编译器都支持__int64的写法,必须使用DataType.h中引入的定义
|
2019-08-19 19:19:58 +08:00
|
|
|
|
|
|
|
|
|
/**
|
2020-11-09 15:14:28 +08:00
|
|
|
|
* 文件信息数据结构
|
|
|
|
|
*/
|
2019-08-19 19:19:58 +08:00
|
|
|
|
struct FileInfo ///文件信息
|
|
|
|
|
{
|
|
|
|
|
os_char name[HGL_MAX_PATH]; ///<文件名(不包含路径)
|
|
|
|
|
os_char fullname[HGL_MAX_PATH]; ///<完整名称(包含路径)
|
|
|
|
|
|
|
|
|
|
uint64 size; ///<文件长度
|
|
|
|
|
|
|
|
|
|
union
|
|
|
|
|
{
|
|
|
|
|
uint32 attrib; ///<文件属性
|
|
|
|
|
|
|
|
|
|
struct
|
|
|
|
|
{
|
|
|
|
|
bool is_file:1; ///<是文件
|
|
|
|
|
bool is_directory:1; ///<是目录
|
|
|
|
|
|
|
|
|
|
bool is_hiddle:1; ///<是否隐藏文件
|
|
|
|
|
|
|
|
|
|
#if HGL_OS != HGL_OS_Windows
|
|
|
|
|
bool is_link:1; ///<是否是链接
|
|
|
|
|
#endif//HGL_OS != HGL_OS_Windows
|
|
|
|
|
|
|
|
|
|
bool can_read:1; ///<可以读
|
|
|
|
|
bool can_write:1; ///<可以写
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
uint64 mtime; ///<最后修改日期(这个值在win/unix下不通用)
|
|
|
|
|
};//struct FileInfo
|
|
|
|
|
|
|
|
|
|
bool GetFileInfo(const os_char *filename,struct FileInfo &); ///<取得文件信息
|
|
|
|
|
|
|
|
|
|
int GetFileInfoList(List<FileInfo> &, const OSString &folder_name, bool proc_folder, bool proc_file, bool sub_folder);
|
|
|
|
|
}//namespace filesystem
|
|
|
|
|
}//namespace hgl
|
|
|
|
|
#endif//HGL_FILE_SYSTEM_INCLUDE
|