-
Notifications
You must be signed in to change notification settings - Fork 151
/
FileHelper.h
206 lines (168 loc) · 5.63 KB
/
FileHelper.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#pragma once
#include <Windows.h>
#include <atlstr.h>
#include "km.h"
#include <map>
/////////////////////////////////////////////////////////////////////////////
//
// 提供文件基础操作
//
/////////////////////////////////////////////////////////////////////////////
//UTF16文件头
const BYTE BomUTF16[] = { 0xff,0xfe };
//UTF8文件头
const BYTE BomUTF8[] = { 0xEF ,0xBB ,0xBF };
#define YY_range_base_for_find_file_start(szFindPath, _FindFileData) \
{ \
WIN32_FIND_DATAW ___range_base_for_find_file_data; \
WIN32_FIND_DATAW& _FindFileData = ___range_base_for_find_file_data; \
CHFileFind hFileFind = FindFirstFileW(szFindPath, &_FindFileData); \
if(hFileFind.IsInvalid() == false) \
{ \
do
#define YY_range_base_for_find_file_end() \
while (FindNextFileW(hFileFind, &___range_base_for_find_file_data)); \
} \
}
#define YY_range_base_for_find_file_end_with_errorcode(errorcode) \
while (FindNextFileW(hFileFind, &___range_base_for_find_file_data) ? true : (errorcode = GetLastErrorFromBoolFalse(),false)); \
} \
else \
{ \
errorcode = GetLastErrorFromBoolFalse(); \
} \
}
//判断问是否是.以及..
_Check_return_
bool __fastcall IsDots(
_In_z_ LPCWSTR FileName,
_In_ DWORD cbFileName
);
_Check_return_
bool __fastcall IsDots(
_In_z_ LPCWSTR FileName
);
_Check_return_
bool __fastcall IsDots(
_In_z_ LPCSTR FileName
);
#define _IsDots IsDots
_Check_return_ _Success_(return == 0)
NTSTATUS __fastcall GetFileId(
_In_z_ LPCWSTR FilePath,
_Out_opt_ FILE_STANDARD_INFORMATION* pFileStandardInfo,
_Out_opt_ FILE_INTERNAL_INFORMATION* pFileInternalInfo = NULL
);
_Check_return_ _Success_(return == 0)
NTSTATUS __fastcall NtGetFileId(
_In_ POBJECT_ATTRIBUTES ObjectAttributes,
_Out_opt_ FILE_STANDARD_INFORMATION* pFileStandardInfo,
_Out_opt_ FILE_INTERNAL_INFORMATION* pFileInternalInfo
);
/*无视权限删除文件或者文件夹
DeleteRootPath指示是否删除根目录,当Path为文件时此产生无效*/
_Check_return_ _Success_(return == 0)
NTSTATUS DeleteDirectory(
_In_z_ LPCWSTR Path,
_In_ BOOL DeleteRootPath = TRUE
);
_Check_return_
LSTATUS UpdateFile(
_In_ CString lpExistingFileName,
_In_ CString lpNewFileName
);
_Check_return_ _Success_(return == 0)
NTSTATUS CopyDirectory(
_In_z_ LPCWSTR ExistingDirectoryPath,
_In_z_ LPCWSTR NewDirectoryInfoPath
);
//DWORD MoveFileEx2(LPCTSTR lpExistingFileName, LPCWSTR lpNewFileName, DWORD dwFlags = MOVEFILE_REPLACE_EXISTING);
//无视权限删除文件或者(空)文件夹
_Check_return_ _Success_(return == 0)
NTSTATUS DeleteFile2(
_In_z_ LPCWSTR FilePath
);
_Check_return_ _Success_(return == 0)
NTSTATUS NtDeleteFile2(
_In_ POBJECT_ATTRIBUTES ObjectAttributes
);
_Check_return_ _Success_(return != 0xFFFFFFFF)
DWORD GetFileAttributes2(
_In_z_ LPCTSTR FilePath
);
_Check_return_ _Success_(return == 0)
NTSTATUS NtSetFileAttributes(
_In_ POBJECT_ATTRIBUTES ObjectAttributes,
_In_ DWORD FileAttributes
);
_Check_return_ _Success_(return == 0)
NTSTATUS SetFileAttributes2(
_In_z_ LPCTSTR FilePath,
_In_ DWORD FileAttributes
);
UINT64 GetFileAllocationSize(
_In_z_ LPCWSTR FilePath
);
UINT64 GetDirectorySize(
_In_z_ LPCWSTR FilePath
);
//可以NTFS压缩一个文件/文件夹
_Check_return_
LSTATUS CompressFile(
_In_z_ LPCWSTR FilePath
);
ULONG64 GetDriverFreeSize(
_In_z_ LPCWSTR Latter
);
ULONG64 GetDriverUseSize(
_In_z_ LPCWSTR Latter
);
_Check_return_
BOOL CheckUpdateFile(
_In_ CString Src,
_In_ CString Des,
_Out_ std::map<UINT64, DWORD>& FileMap,
_Out_opt_ UINT64* pSize
);
_Check_return_
LSTATUS GetFileVersion(
_In_ HMODULE hFileMoudle,
_Out_writes_bytes_(8) UINT16 Version[4],
_In_ WORD wLanguage = MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL)
);
_Check_return_
LSTATUS GetFileVersion(
_In_z_ LPCWSTR FilePath,
_Out_writes_bytes_(8) UINT16 Version[4],
_In_ WORD wLanguage = MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL)
);
UINT64 GetDirectoryAllocationSize(
_In_z_ LPCWSTR FilePath,
_Out_ std::map<UINT64, DWORD>& FileMap
);
_Check_return_ _Success_(return == S_OK)
LSTATUS CrateDirectorHandLink(
_In_ CString To,
_In_ CString From
);
//Error Code https://msdn.microsoft.com/en-us/library/windows/desktop/bb762164(v=vs.85).aspx
_Check_return_ _Success_(return == 0)
int MoveDirectory(
_In_ CString ExistingDirectoryPath,
_In_ CString NewDirectoryInfoPath
);
enum FilePathType
{
PathIsUnkow = -1,
PathNotExist,
PathIsFile,
PathIsDir,
};
_Check_return_
FilePathType GetFileType(
_In_z_ LPCWSTR FilePath
);
_Check_return_
FilePathType GetFileType(
_In_z_ LPCSTR FilePath
);