fileutil.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. * category: [tool for file]
  3. * apply status: framework
  4. * edit status:
  5. * build status:
  6. * description:
  7. */
  8. #ifndef __FILEUTIL_H__
  9. #define __FILEUTIL_H__
  10. #pragma once
  11. #include "config.h"
  12. #include "path.h"
  13. #ifdef __cplusplus
  14. extern "C" {
  15. #endif
  16. TOOLKIT_API BOOL ExistsDirA(LPCSTR lpDirPath);
  17. TOOLKIT_API BOOL ExistsDirW(LPCWSTR lpDirPath);
  18. #if defined(UNICODE) || defined(_UNICODE)
  19. #define ExistsDir ExistsDirW
  20. #else
  21. #define ExistsDir ExistsDirA
  22. #endif
  23. TOOLKIT_API BOOL ExistsFileA(LPCSTR lpFilePath);
  24. TOOLKIT_API BOOL ExistsFileW(LPCWSTR lpFilePath);
  25. #if defined(UNICODE) || defined(_UNICODE)
  26. #define ExistsFile ExistsFileW
  27. #else
  28. #define ExistsFile ExistsFileA
  29. #endif
  30. TOOLKIT_API BOOL RemoveFileA(LPCSTR pszFile);
  31. TOOLKIT_API BOOL RemoveFileReadOnlyAttributeA(LPCSTR pszFile);
  32. TOOLKIT_API BOOL CopyDirA(LPCSTR pszSourceDir, LPCSTR pszDestDir);
  33. TOOLKIT_API BOOL CreateDirA(LPCSTR lpDirPath, BOOL bRecursive);
  34. TOOLKIT_API BOOL CreateDirW(LPCWSTR lpDirPath, BOOL bRecursive);
  35. #if defined(UNICODE) || defined(_UNICODE)
  36. #define CreateDir CreateDirW
  37. #else
  38. #define CreateDir CreateDirA
  39. #endif
  40. TOOLKIT_API BOOL CreateDirRecursiveA(LPCSTR lpDirPath);
  41. TOOLKIT_API BOOL CreateDirRecursiveW(LPCWSTR lpDirPath);
  42. #if defined(UNICODE) || defined(_UNICODE)
  43. #define CreateDirRecursive CreateDirRecursiveW
  44. #else
  45. #define CreateDirRecursive CreateDirRecursiveA
  46. #endif
  47. TOOLKIT_API BOOL ClearDirRecursiveA(LPCSTR lpDirPath);
  48. TOOLKIT_API BOOL ClearDirRecursiveW(LPCWSTR lpDirPath);
  49. #if defined(UNICODE) || defined(_UNICODE)
  50. #define ClearDirRecursive ClearDirRecursiveW
  51. #else
  52. #define ClearDirRecursive ClearDirRecursiveA
  53. #endif
  54. TOOLKIT_API BOOL RemoveDirRecursiveA(LPCSTR lpDirPath);
  55. TOOLKIT_API BOOL RemoveDirRecursiveW(LPCWSTR lpDirPath);
  56. #if defined(UNICODE) || defined(_UNICODE)
  57. #define RemoveDirRecursive RemoveDirRecursiveW
  58. #else
  59. #define RemoveDirRecursive RemoveDirRecursiveA
  60. #endif
  61. TOOLKIT_API BOOL CreateParentDirA(LPCSTR lpPath, BOOL bRecursive);
  62. TOOLKIT_API BOOL CreateParentDirW(LPCWSTR lpPath, BOOL bRecursive);
  63. #if defined(UNICODE) || defined(_UNICODE)
  64. #define CreateParentDir CreateParentDirW
  65. #else
  66. #define CreateParentDir CreateParentDirA
  67. #endif
  68. TOOLKIT_API HANDLE ExtCreateFileA(LPCSTR lpFileName,
  69. DWORD dwDesiredAccess,
  70. DWORD dwShareMode,
  71. LPSECURITY_ATTRIBUTES lpSecurityAttributes,
  72. DWORD dwCreationDisposition,
  73. DWORD dwFlagsAndAttributes,
  74. HANDLE hTemplateFile);
  75. TOOLKIT_API HANDLE ExtCreateFileW(LPCWSTR lpFileName,
  76. DWORD dwDesiredAccess,
  77. DWORD dwShareMode,
  78. LPSECURITY_ATTRIBUTES lpSecurityAttributes,
  79. DWORD dwCreationDisposition,
  80. DWORD dwFlagsAndAttributes,
  81. HANDLE hTemplateFile);
  82. #if defined(UNICODE) || defined(_UNICODE)
  83. #define ExtCreateFile ExtCreateFileW
  84. #else
  85. #define ExtCreateFile ExtCreateFileA
  86. #endif
  87. typedef struct array_header_t array_header_t;
  88. TOOLKIT_API array_header_t *fileutil_get_sub_files_a(const char *path);
  89. TOOLKIT_API array_header_t *fileutil_get_sub_dirs_a(const char *path);
  90. TOOLKIT_API array_header_t *fileutil_get_sub_files_w(const wchar_t *path);
  91. TOOLKIT_API array_header_t *fileutil_get_sub_dirs_w(const wchar_t *path);
  92. TOOLKIT_API array_header_t *fileutil_get_sub_files2_a(const char *path, int limitation);
  93. TOOLKIT_API array_header_t *fileutil_get_sub_dirs2_a(const char *path, int limitation);
  94. TOOLKIT_API array_header_t *fileutil_get_sub_files2_w(const wchar_t *path, int limitation);
  95. TOOLKIT_API array_header_t *fileutil_get_sub_dirs2_w(const wchar_t *path, int limitation);
  96. #if defined(UNICODE) || defined(_UNICODE)
  97. #define fileutil_get_sub_files fileutil_get_sub_files_w
  98. #define fileutil_get_sub_dirs fileutil_get_sub_dirs_w
  99. #else
  100. #define fileutil_get_sub_files fileutil_get_sub_files_a
  101. #define fileutil_get_sub_dirs fileutil_get_sub_dirs_a
  102. #endif
  103. /** suc:0, failed: -1*/
  104. TOOLKIT_API int fileutil_copy_file(const char* dest_file_path, const char* src_file_path);
  105. TOOLKIT_API void fileutil_delete_file(const char* filename);
  106. TOOLKIT_API FILE *fileutil_transaction_fopen(const char *filename, const char *mode);
  107. TOOLKIT_API int fileutil_transaction_fclose(const char *filename, FILE *fp);
  108. #ifndef _WIN32
  109. TOOLKIT_API void _splitpath(const char* path, char* drive, char* dir, char* fname, char* ext);
  110. #endif //NOT _WIN32
  111. #ifdef __cplusplus
  112. } // extern "C" {
  113. #endif
  114. #endif //__FILEUTIL_H__