Go to the documentation of this file.00001 #pragma once
00002
00003 namespace AppSecInc
00004 {
00006 namespace File
00007 {
00012 std::string GetTemporaryFileNameA();
00013 std::wstring GetTemporaryFileNameW();
00014
00019 std::string GetTemporaryDirectoryA();
00020 std::wstring GetTemporaryDirectoryW();
00021
00026 std::string GetModuleFileNameA(HINSTANCE h = NULL);
00027 std::wstring GetModuleFileNameW(HINSTANCE h = NULL);
00028
00033 std::string GetModuleDirectoryA();
00034 std::wstring GetModuleDirectoryW();
00035
00041 std::string GetFileDirectoryA(const std::string& path);
00042 std::wstring GetFileDirectoryW(const std::wstring& path);
00043
00049 std::string GetFileNameA(const std::string& path);
00050 std::wstring GetFileNameW(const std::wstring& path);
00051
00056 std::string GetCurrentDirectoryA();
00057 std::wstring GetCurrentDirectoryW();
00058
00067 bool FileExists(const std::string& filename);
00068 bool FileExists(const std::wstring& filename);
00069
00074 void FileDelete(const std::string& filename);
00075 void FileDelete(const std::wstring& filename);
00076
00085 bool DirectoryExists(const std::string& path);
00086 bool DirectoryExists(const std::wstring& path);
00087
00096 std::string DirectoryCreate(const std::string& path);
00097 std::wstring DirectoryCreate(const std::wstring& path);
00098
00099 enum DELETE_DIRECTORY_FLAGS
00100 {
00101 DELETE_DIRECTORY_FILES = 1,
00102 DELETE_DIRECTORY_FOLDERS = 2,
00103 DELETE_DIRECTORY_SUBDIRECTORIES = 4,
00104 DELETE_DIRECTORY_EMPTY = DELETE_DIRECTORY_FOLDERS | DELETE_DIRECTORY_SUBDIRECTORIES,
00105 DELETE_DIRECTORY_ALL = DELETE_DIRECTORY_FILES | DELETE_DIRECTORY_FOLDERS | DELETE_DIRECTORY_SUBDIRECTORIES
00106 };
00107
00120 bool DirectoryDelete(const std::string& path, int flags = DELETE_DIRECTORY_ALL);
00121 bool DirectoryDelete(const std::wstring& path, int flags = DELETE_DIRECTORY_ALL);
00122
00127 long GetFileSize(const std::wstring& filename);
00128 long GetFileSize(const std::string& filename);
00129
00130 enum FILESIZE_STRING_TYPE
00131 {
00132 FILESIZE_AUTO = 0,
00133 FILESIZE_BYTES = 2,
00134 FILESIZE_KBYTES = 3,
00135 FILESIZE_MBYTES = 4,
00136 FILESIZE_GBYTES = 5,
00137 };
00138
00139 const long BYTE = 1;
00140 const long KBYTE = BYTE * 1024;
00141 const long MBYTE = KBYTE * 1024;
00142 const long GBYTE = MBYTE * 1024;
00143
00151 std::pair<std::string, std::string> SizeToStringPairA(long size, FILESIZE_STRING_TYPE type = FILESIZE_AUTO, int precision = 0);
00152 std::pair<std::wstring, std::wstring> SizeToStringPairW(long size, FILESIZE_STRING_TYPE type = FILESIZE_AUTO, int precision = 0);
00153
00161 std::string SizeToStringA(long size, FILESIZE_STRING_TYPE type = FILESIZE_AUTO, int precision = 0);
00162 std::wstring SizeToStringW(long size, FILESIZE_STRING_TYPE type = FILESIZE_AUTO, int precision = 0);
00163
00167 std::wstring DirectoryCombine(const std::wstring& dir, const std::wstring& file);
00168
00169 enum GET_FILES_FLAGS
00170 {
00171 GET_FILES_FILES = 1,
00172 GET_FILES_DIRECTORIES = 2,
00173 GET_FILES_RECURSIVE = 4,
00174 GET_FILES_ALL = GET_FILES_FILES | GET_FILES_DIRECTORIES | GET_FILES_RECURSIVE
00175 };
00176
00183 std::list<std::wstring> GetFiles(const std::wstring& path, const std::wstring& wildcard = L"*.*", int flags = GET_FILES_FILES);
00184
00191 std::list<std::wstring> GetFiles(const std::wstring& path_and_wildcard, int flags);
00192
00199 std::list<std::wstring> GetDirectoryFiles(const std::wstring& path, const std::wstring& wildcard = L"*.*");
00200
00206 void ReadToEnd(const std::wstring& filename, std::wstring& data);
00207
00213 void ReadToEnd(const std::wstring& filename, std::string& data);
00214
00220 void ReadToEnd(const std::wstring& filename, std::vector<char>& data);
00221
00223 static unsigned char utf8_bom[] = { 0xef, 0xbb, 0xbf };
00224
00232 bool ReadAndConvertToEnd(const std::wstring& filename, std::wstring& data);
00233
00241 void FileWrite(
00242 const std::wstring& filename,
00243 const std::vector<char>& data,
00244 DWORD dwShareMode = GENERIC_READ | GENERIC_WRITE,
00245 DWORD dwCreationDisposition = CREATE_ALWAYS,
00246 DWORD dwFlagsAndAttributes = FILE_ATTRIBUTE_NORMAL);
00247
00254 void FileCreate(
00255 const std::wstring& filename,
00256 DWORD dwShareMode = GENERIC_READ | GENERIC_WRITE,
00257 DWORD dwCreationDisposition = CREATE_ALWAYS,
00258 DWORD dwFlagsAndAttributes = FILE_ATTRIBUTE_NORMAL);
00259
00265 std::string GetParentDirectory(const std::string& path);
00266
00267
00273 std::wstring GetParentDirectory(const std::wstring& path);
00274
00281 std::wstring GetSpecialFolderPath(int csidl, BOOL create = FALSE);
00282
00284 bool IsAbsolutePath(const std::wstring& path);
00285 }
00286 }