Browse Source

Z991239-6390 #comment 移除不需要的fileutil定义

80374374 2 months ago
parent
commit
4179cd207a
2 changed files with 0 additions and 297 deletions
  1. 0 238
      Framework/libtoolkit/fileutil.c
  2. 0 59
      Framework/libtoolkit/fileutil.h

+ 0 - 238
Framework/libtoolkit/fileutil.c

@@ -29,22 +29,12 @@ TOOLKIT_API BOOL ExistsDirA(LPCSTR lpDirPath)
 	DWORD dwRet = GetFileAttributesA(lpDirPath);
 	return (dwRet != INVALID_FILE_ATTRIBUTES) && (dwRet & FILE_ATTRIBUTE_DIRECTORY);
 }
-TOOLKIT_API BOOL ExistsDirW(LPCWSTR lpDirPath)
-{
-	DWORD dwRet = GetFileAttributesW(lpDirPath);
-	return (dwRet != INVALID_FILE_ATTRIBUTES) && (dwRet & FILE_ATTRIBUTE_DIRECTORY);
-}
 
 TOOLKIT_API BOOL ExistsFileA(LPCSTR lpFilePath)
 {
 	DWORD dwRet = GetFileAttributesA(lpFilePath);
 	return (dwRet != INVALID_FILE_ATTRIBUTES) && !(dwRet & FILE_ATTRIBUTE_DIRECTORY);
 }
-TOOLKIT_API BOOL ExistsFileW(LPCWSTR lpFilePath)
-{
-	DWORD dwRet = GetFileAttributesW(lpFilePath);
-	return (dwRet != INVALID_FILE_ATTRIBUTES) && !(dwRet & FILE_ATTRIBUTE_DIRECTORY);
-}
 
 TOOLKIT_API DWORD ReadFileSize(LPCSTR pszFile)
 {
@@ -134,71 +124,7 @@ TOOLKIT_API BOOL CreateDirA(LPCSTR lpDirPath, BOOL bRecursive)
 	return TRUE;
 }
 
-TOOLKIT_API BOOL CreateDirW(LPCWSTR lpDirPath, BOOL bRecursive)
-{
-	WCHAR* slashPos = NULL;
-	WCHAR* backSlashPos = NULL;
-	size_t len = wcslen(lpDirPath);
-	if (len <= 2 || len >= MAX_PATH-2) {
-		return FALSE;
-	} else {
-		if (!bRecursive) {
-			return CreateDirectoryW(lpDirPath, NULL) || (GetLastError() == ERROR_ALREADY_EXISTS);
-		} else {
-			WCHAR tmp[MAX_PATH], *p;
-			WCHAR* q = NULL;
-			q = p = &tmp[0];
-			wcsncpy(tmp, lpDirPath, MAX_PATH);
-			tmp[MAX_PATH-1] = 0;
-			if (tmp[len-1] != '\\' && tmp[len-1] != '/') {
-				tmp[len++] = SPLIT_SLASH;
-				tmp[len] = 0;
-			}
-#ifdef _WIN32
-			do {
-				slashPos = wcschr(p, SLASH);
-				backSlashPos = wcschr(p, BACK_SLASH);
-				if (slashPos != NULL && backSlashPos != NULL) {
-					p = slashPos < backSlashPos ? slashPos : backSlashPos;
-				}
-				else if (slashPos != NULL) {
-					p = slashPos;
-				}
-				else {
-					p = backSlashPos;
-				}
-				if (!p) {
-					break;
-				}
-				*p = 0;
-				if (!ExistsDirW(tmp)) {
-					if (!CreateDirectoryW(tmp, NULL) && GetLastError() != ERROR_ALREADY_EXISTS)
-						return FALSE;
-				}
-				*p = SPLIT_SLASH;
-				p++;
-			} while (1);
-#else
-			while ((p = wcschr(p, SPLIT_SLASH)) != NULL) {
-				if (p != q) {//linux compatibility. 
-					*p = 0;
-					if (!ExistsDirW(tmp)) {
-						if (!CreateDirectoryW(tmp, NULL) && GetLastError() != ERROR_ALREADY_EXISTS)
-							return FALSE;
-					}
-					*p = SPLIT_SLASH;
-				}
-				p++;
-				q = p;
-			}
-#endif
-		}
-	}
-	return TRUE;
-}
-
 TOOLKIT_API BOOL CreateDirRecursiveA(LPCSTR lpDirPath) { return CreateDirA(lpDirPath, TRUE); }
-TOOLKIT_API BOOL CreateDirRecursiveW(LPCWSTR lpDirPath) { return CreateDirW(lpDirPath, TRUE); }
 
 TOOLKIT_API BOOL CreateParentDirA(LPCSTR lpPath, BOOL bRecursive)
 {
@@ -216,22 +142,6 @@ TOOLKIT_API BOOL CreateParentDirA(LPCSTR lpPath, BOOL bRecursive)
 	return CreateDirA(pdir, bRecursive);
 }
 
-TOOLKIT_API BOOL CreateParentDirW(LPCWSTR lpPath, BOOL bRecursive)
-{
-	WCHAR pdir[MAX_PATH];
-	const WCHAR *p;
-	p = wcsrchr(lpPath, '\\');
-	if (!p) {
-		p = wcsrchr(lpPath, '/');
-	}
-	if (!p) {
-		return FALSE;
-	}
-	wcsncpy(pdir, lpPath, p-lpPath);
-	pdir[p-lpPath] = 0;
-	return CreateDirW(pdir, bRecursive);
-}
-
 TOOLKIT_API BOOL ClearDirRecursiveA(LPCSTR lpDirPath)
 {
 	array_header_t *arr;
@@ -262,36 +172,6 @@ TOOLKIT_API BOOL ClearDirRecursiveA(LPCSTR lpDirPath)
 	return bRet;
 }
 
-TOOLKIT_API BOOL ClearDirRecursiveW(LPCWSTR lpDirPath)
-{
-	array_header_t *arr;
-	BOOL bRet = TRUE;
-
-	TOOLKIT_ASSERT(lpDirPath);
-
-	arr = fileutil_get_sub_files_w(lpDirPath);
-	if (arr) {
-		int i;
-		for (i = 0; i < arr->nelts; ++i) {
-			wchar_t *tmp = ARRAY_IDX(arr, i, wchar_t*);
-			bRet &= DeleteFileW(tmp);
-		}
-		toolkit_array_free2(arr);
-	}
-
-	arr = fileutil_get_sub_dirs_w(lpDirPath);
-	if (arr) {
-		int i;
-		for (i = 0; i < arr->nelts; ++i) {
-			wchar_t *tmp = ARRAY_IDX(arr, i, wchar_t*);
-			bRet &= ClearDirRecursiveW(tmp);
-		}
-		toolkit_array_free2(arr);
-	}
-
-	return bRet;
-}
-
 TOOLKIT_API BOOL RemoveFileA(LPCSTR pszFile)
 {
 	if(ExistsFileA(pszFile))
@@ -435,61 +315,6 @@ TOOLKIT_API BOOL RemoveDirRecursiveA(LPCSTR lpDirPath)
 
 }
 
-TOOLKIT_API BOOL RemoveDirRecursiveW(LPCWSTR lpDirPath)
-{
-	array_header_t *arr;
-	BOOL bRet = TRUE;
-
-	TOOLKIT_ASSERT(lpDirPath);
-
-	arr = fileutil_get_sub_files_w(lpDirPath);
-	if (arr) {
-		int i;
-		for (i = 0; i < arr->nelts; ++i) {
-			wchar_t *tmp = ARRAY_IDX(arr, i, wchar_t*);
-			bRet &= DeleteFileW(tmp);
-		}
-		toolkit_array_free2(arr);
-	}
-
-	arr = fileutil_get_sub_dirs_w(lpDirPath);
-	if (arr) {
-		int i;
-		for (i = 0; i < arr->nelts; ++i) {
-			wchar_t *tmp = ARRAY_IDX(arr, i, wchar_t*);
-			bRet &= RemoveDirRecursiveW(tmp);
-		}
-		toolkit_array_free2(arr);
-	}
-
-	if (bRet) {
-		bRet = RemoveDirectoryW(lpDirPath);
-	}
-
-	return bRet;
-}
-
-TOOLKIT_API HANDLE ExtCreateFileW(LPCWSTR lpFileName,
-	DWORD dwDesiredAccess,
-	DWORD dwShareMode,
-	LPSECURITY_ATTRIBUTES lpSecurityAttributes,
-	DWORD dwCreationDisposition,
-	DWORD dwFlagsAndAttributes,
-	HANDLE hTemplateFile)
-{
-	if (!lpFileName)
-		return INVALID_HANDLE_VALUE;
-	if (lpFileName[0] != '\\')
-		CreateParentDirW(lpFileName, TRUE);
-	return CreateFileW(lpFileName,
-		dwDesiredAccess,
-		dwShareMode,
-		lpSecurityAttributes,
-		dwCreationDisposition,
-		dwFlagsAndAttributes,
-		hTemplateFile);
-}
-
 TOOLKIT_API HANDLE ExtCreateFileA(LPCSTR lpFileName,
 	DWORD dwDesiredAccess,
 	DWORD dwShareMode,
@@ -636,49 +461,6 @@ static array_header_t *fileutil_get_sub_a(const char *path, int isfile, int limi
 	return arr;
 }
 
-static array_header_t *fileutil_get_sub_w(const wchar_t *path, int isfile, int limitation)
-{
-	array_header_t *arr = NULL;
-    WCHAR tmp[MAX_PATH];
-    int npath;
-
-    if (!path)
-        return NULL;
-    npath = wcslen(path);
-    if (npath < 2)
-        return NULL;
-
-    wcscpy(tmp, path);
-    if (tmp[npath - 1] != '\\' && tmp[npath - 1] != '/') {
-        tmp[npath++] = SPLIT_SLASH;
-        tmp[npath] = 0;
-    }
-    tmp[npath++] = '*';
-    tmp[npath] = 0;
-
-    arr = array_make(3, sizeof(wchar_t*));
-    {
-        WIN32_FIND_DATAW fd;
-        HANDLE hFind = FindFirstFileW(tmp, &fd);
-        if (hFind != INVALID_HANDLE_VALUE) {
-            tmp[--npath] = 0;
-            do {
-                int isdir = !!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY);
-                if (isfile ^ isdir) {
-                    wchar_t* v = malloc(sizeof(wchar_t) * (npath + wcslen(fd.cFileName) + 1));
-                    wcscpy(v, tmp);
-                    wcscat(v, fd.cFileName);
-                    ARRAY_PUSH(arr, wchar_t*) = v;
-                }
-            } while (FindNextFileW(hFind, &fd) && arr->nelts < limitation);
-            FindClose(hFind);
-        }
-    }
-
-	return arr;
-
-}
-
 TOOLKIT_API array_header_t *fileutil_get_sub_files_a(const char *path)
 {
 	return fileutil_get_sub_a(path, 1, INT_MAX);
@@ -689,16 +471,6 @@ TOOLKIT_API array_header_t *fileutil_get_sub_dirs_a(const char *path)
 	return fileutil_get_sub_a(path, 0, INT_MAX);
 }
 
-TOOLKIT_API array_header_t *fileutil_get_sub_files_w(const wchar_t *path)
-{
-	return fileutil_get_sub_w(path, 1, INT_MAX);
-}
-
-TOOLKIT_API array_header_t *fileutil_get_sub_dirs_w(const wchar_t *path)
-{
-	return fileutil_get_sub_w(path, 0, INT_MAX);
-}
-
 TOOLKIT_API array_header_t *fileutil_get_sub_files2_a(const char *path, int limitation)
 {
 	return fileutil_get_sub_a(path, 1, limitation);
@@ -709,16 +481,6 @@ TOOLKIT_API array_header_t *fileutil_get_sub_dirs2_a(const char *path, int limit
 	return fileutil_get_sub_a(path, 0, limitation);
 }
 
-TOOLKIT_API array_header_t *fileutil_get_sub_files2_w(const wchar_t *path, int limitation)
-{
-	return fileutil_get_sub_w(path, 1, limitation);
-}
-
-TOOLKIT_API array_header_t *fileutil_get_sub_dirs2_w(const wchar_t *path, int limitation)
-{
-	return fileutil_get_sub_w(path, 0, limitation);
-}
-
 TOOLKIT_API FILE *fileutil_transaction_fopen(const char *filename, const char *mode)
 {
 	DWORD dwAttr;

+ 0 - 59
Framework/libtoolkit/fileutil.h

@@ -20,22 +20,10 @@ extern "C" {
 #endif
 
 TOOLKIT_API BOOL ExistsDirA(LPCSTR lpDirPath);
-TOOLKIT_API BOOL ExistsDirW(LPCWSTR lpDirPath);
-
-#if defined(UNICODE) || defined(_UNICODE)
-#define ExistsDir ExistsDirW
-#else 
 #define ExistsDir ExistsDirA
-#endif
 
 TOOLKIT_API BOOL ExistsFileA(LPCSTR lpFilePath);
-TOOLKIT_API BOOL ExistsFileW(LPCWSTR lpFilePath);
-
-#if defined(UNICODE) || defined(_UNICODE)
-#define ExistsFile ExistsFileW
-#else 
 #define ExistsFile ExistsFileA
-#endif
 
 TOOLKIT_API DWORD ReadFileSize(LPCSTR pszFile);
 
@@ -45,44 +33,19 @@ TOOLKIT_API BOOL RemoveFileReadOnlyAttributeA(LPCSTR pszFile);
 TOOLKIT_API BOOL CopyDirA(LPCSTR pszSourceDir, LPCSTR pszDestDir);
 
 TOOLKIT_API BOOL CreateDirA(LPCSTR lpDirPath, BOOL bRecursive);
-TOOLKIT_API BOOL CreateDirW(LPCWSTR lpDirPath, BOOL bRecursive);
-#if defined(UNICODE) || defined(_UNICODE)
-#define CreateDir CreateDirW
-#else 
 #define CreateDir CreateDirA
-#endif
 
 TOOLKIT_API BOOL CreateDirRecursiveA(LPCSTR lpDirPath);
-TOOLKIT_API BOOL CreateDirRecursiveW(LPCWSTR lpDirPath);
-#if defined(UNICODE) || defined(_UNICODE)
-#define CreateDirRecursive CreateDirRecursiveW
-#else 
 #define CreateDirRecursive CreateDirRecursiveA
-#endif
 
 TOOLKIT_API BOOL ClearDirRecursiveA(LPCSTR lpDirPath);
-TOOLKIT_API BOOL ClearDirRecursiveW(LPCWSTR lpDirPath);
-#if defined(UNICODE) || defined(_UNICODE)
-#define ClearDirRecursive ClearDirRecursiveW
-#else 
 #define ClearDirRecursive ClearDirRecursiveA
-#endif
 
 TOOLKIT_API BOOL RemoveDirRecursiveA(LPCSTR lpDirPath);
-TOOLKIT_API BOOL RemoveDirRecursiveW(LPCWSTR lpDirPath);
-#if defined(UNICODE) || defined(_UNICODE)
-#define RemoveDirRecursive RemoveDirRecursiveW
-#else 
 #define RemoveDirRecursive RemoveDirRecursiveA
-#endif
 
 TOOLKIT_API BOOL CreateParentDirA(LPCSTR lpPath, BOOL bRecursive);
-TOOLKIT_API BOOL CreateParentDirW(LPCWSTR lpPath, BOOL bRecursive);
-#if defined(UNICODE) || defined(_UNICODE)
-#define CreateParentDir CreateParentDirW
-#else 
 #define CreateParentDir CreateParentDirA
-#endif
 
 TOOLKIT_API HANDLE ExtCreateFileA(LPCSTR lpFileName,
 	DWORD dwDesiredAccess,
@@ -92,37 +55,15 @@ TOOLKIT_API HANDLE ExtCreateFileA(LPCSTR lpFileName,
 	DWORD dwFlagsAndAttributes,
 	HANDLE hTemplateFile);
 
-TOOLKIT_API HANDLE ExtCreateFileW(LPCWSTR lpFileName,
-	DWORD dwDesiredAccess,
-	DWORD dwShareMode,
-	LPSECURITY_ATTRIBUTES lpSecurityAttributes,
-	DWORD dwCreationDisposition,
-	DWORD dwFlagsAndAttributes,
-	HANDLE hTemplateFile);
-
-#if defined(UNICODE) || defined(_UNICODE)
-#define ExtCreateFile ExtCreateFileW
-#else 
 #define ExtCreateFile ExtCreateFileA
-#endif
 
 typedef struct array_header_t array_header_t;
 TOOLKIT_API array_header_t *fileutil_get_sub_files_a(const char *path);
 TOOLKIT_API array_header_t *fileutil_get_sub_dirs_a(const char *path);
-TOOLKIT_API array_header_t *fileutil_get_sub_files_w(const wchar_t *path);
-TOOLKIT_API array_header_t *fileutil_get_sub_dirs_w(const wchar_t *path);
 TOOLKIT_API array_header_t *fileutil_get_sub_files2_a(const char *path, int limitation);
 TOOLKIT_API array_header_t *fileutil_get_sub_dirs2_a(const char *path, int limitation);
-TOOLKIT_API array_header_t *fileutil_get_sub_files2_w(const wchar_t *path, int limitation);
-TOOLKIT_API array_header_t *fileutil_get_sub_dirs2_w(const wchar_t *path, int limitation);
-
-#if defined(UNICODE) || defined(_UNICODE)
-#define fileutil_get_sub_files fileutil_get_sub_files_w
-#define fileutil_get_sub_dirs fileutil_get_sub_dirs_w
-#else 
 #define fileutil_get_sub_files fileutil_get_sub_files_a
 #define fileutil_get_sub_dirs fileutil_get_sub_dirs_a
-#endif
 
 /** suc:0, failed: -1*/
 TOOLKIT_API int fileutil_copy_file(const char* dest_file_path, const char* src_file_path);