src/Common/File/File.h

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 
00082                 void FileCopy(const std::string& src, const std::string& dest, bool overwrite = true);
00083                 void FileCopy(const std::wstring& src, const std::wstring& dest, bool overwrite = true);
00084 
00093                 bool DirectoryExists(const std::string& path);
00094                 bool DirectoryExists(const std::wstring& path);
00095 
00104                 std::string DirectoryCreate(const std::string& path);
00105                 std::wstring DirectoryCreate(const std::wstring& path);
00106 
00107         enum DELETE_DIRECTORY_FLAGS
00108         {
00109             DELETE_DIRECTORY_FILES = 1, 
00110             DELETE_DIRECTORY_FOLDERS = 2, 
00111             DELETE_DIRECTORY_SUBDIRECTORIES = 4, 
00112             DELETE_DIRECTORY_EMPTY = DELETE_DIRECTORY_FOLDERS | DELETE_DIRECTORY_SUBDIRECTORIES, 
00113             DELETE_DIRECTORY_ALL = DELETE_DIRECTORY_FILES | DELETE_DIRECTORY_FOLDERS | DELETE_DIRECTORY_SUBDIRECTORIES 
00114         };
00115 
00128                 bool DirectoryDelete(const std::string& path, int flags = DELETE_DIRECTORY_ALL);
00129                 bool DirectoryDelete(const std::wstring& path, int flags = DELETE_DIRECTORY_ALL);
00130 
00135         long GetFileSize(const std::wstring& filename);
00136         long GetFileSize(const std::string& filename);
00137 
00138         enum FILESIZE_STRING_TYPE
00139         {
00140             FILESIZE_AUTO = 0, 
00141             FILESIZE_BYTES = 2, 
00142             FILESIZE_KBYTES = 3, 
00143             FILESIZE_MBYTES = 4, 
00144             FILESIZE_GBYTES = 5, 
00145         };
00146 
00147         const long BYTE = 1;
00148         const long KBYTE = BYTE * 1024;
00149         const long MBYTE = KBYTE * 1024;
00150         const long GBYTE = MBYTE * 1024;
00151 
00159         std::pair<std::string, std::string> SizeToStringPairA(long size, FILESIZE_STRING_TYPE type = FILESIZE_AUTO, int precision = 0);
00160         std::pair<std::wstring, std::wstring> SizeToStringPairW(long size, FILESIZE_STRING_TYPE type = FILESIZE_AUTO, int precision = 0);
00161 
00169         std::string SizeToStringA(long size, FILESIZE_STRING_TYPE type = FILESIZE_AUTO, int precision = 0);
00170         std::wstring SizeToStringW(long size, FILESIZE_STRING_TYPE type = FILESIZE_AUTO, int precision = 0);
00171 
00175         std::wstring DirectoryCombine(const std::wstring& dir, const std::wstring& file);
00176 
00177         enum GET_FILES_FLAGS
00178         {
00179             GET_FILES_FILES = 1, 
00180             GET_FILES_DIRECTORIES = 2, 
00181             GET_FILES_RECURSIVE = 4, 
00182             GET_FILES_ALL = GET_FILES_FILES | GET_FILES_DIRECTORIES | GET_FILES_RECURSIVE
00183         };
00184 
00191         std::list<std::wstring> GetFiles(const std::wstring& path, const std::wstring& wildcard = L"*.*", int flags = GET_FILES_FILES);
00192 
00199         std::list<std::wstring> GetFiles(const std::wstring& path_and_wildcard, int flags);
00200 
00207         std::list<std::wstring> GetDirectoryFiles(const std::wstring& path, const std::wstring& wildcard = L"*.*");
00208 
00214         void ReadToEnd(const std::wstring& filename, std::wstring& data);
00215 
00221         void ReadToEnd(const std::wstring& filename, std::string& data);
00222 
00228         void ReadToEnd(const std::wstring& filename, std::vector<char>& data);
00229 
00231                 static unsigned char utf8_bom[] = { 0xef, 0xbb, 0xbf };
00232 
00240                 bool ReadAndConvertToEnd(const std::wstring& filename, std::wstring& data);
00241 
00249         void FileWrite(
00250             const std::wstring& filename, 
00251             const std::vector<char>& data,
00252             DWORD dwShareMode = GENERIC_READ | GENERIC_WRITE,
00253             DWORD dwCreationDisposition = CREATE_ALWAYS,
00254             DWORD dwFlagsAndAttributes = FILE_ATTRIBUTE_NORMAL);
00255 
00262         void FileCreate(
00263             const std::wstring& filename, 
00264             DWORD dwShareMode = GENERIC_READ | GENERIC_WRITE,
00265             DWORD dwCreationDisposition = CREATE_ALWAYS,
00266             DWORD dwFlagsAndAttributes = FILE_ATTRIBUTE_NORMAL);
00267 
00273                 std::string GetParentDirectory(const std::string& path);
00274 
00275 
00281                 std::wstring GetParentDirectory(const std::wstring& path);
00282 
00289                 std::wstring GetSpecialFolderPath(int csidl, BOOL create = FALSE);
00290                 
00292                 bool IsAbsolutePath(const std::wstring& path);
00293         }
00294 }


© Application Security Inc. - All Rights Reserved http://msiext.codeplex.com