1 // Windows/FileDir.h 2 3 #ifndef __WINDOWS_FILEDIR_H 4 #define __WINDOWS_FILEDIR_H 5 6 #include "../Common/MyString.h" 7 #include "Defs.h" 8 9 namespace NWindows { 10 namespace NFile { 11 namespace NDirectory { 12 13 #ifdef WIN_LONG_PATH 14 bool GetLongPaths(LPCWSTR s1, LPCWSTR s2, UString &d1, UString &d2); 15 #endif 16 17 bool MyGetWindowsDirectory(CSysString &path); 18 bool MyGetSystemDirectory(CSysString &path); 19 #ifndef _UNICODE 20 bool MyGetWindowsDirectory(UString &path); 21 bool MyGetSystemDirectory(UString &path); 22 #endif 23 24 bool SetDirTime(LPCWSTR fileName, const FILETIME *cTime, const FILETIME *aTime, const FILETIME *mTime); 25 26 bool MySetFileAttributes(LPCTSTR fileName, DWORD fileAttributes); 27 bool MyMoveFile(LPCTSTR existFileName, LPCTSTR newFileName); 28 bool MyRemoveDirectory(LPCTSTR pathName); 29 bool MyCreateDirectory(LPCTSTR pathName); 30 bool CreateComplexDirectory(LPCTSTR pathName); 31 bool DeleteFileAlways(LPCTSTR name); 32 bool RemoveDirectoryWithSubItems(const CSysString &path); 33 34 #ifndef _UNICODE 35 bool MySetFileAttributes(LPCWSTR fileName, DWORD fileAttributes); 36 bool MyMoveFile(LPCWSTR existFileName, LPCWSTR newFileName); 37 bool MyRemoveDirectory(LPCWSTR pathName); 38 bool MyCreateDirectory(LPCWSTR pathName); 39 bool CreateComplexDirectory(LPCWSTR pathName); 40 bool DeleteFileAlways(LPCWSTR name); 41 bool RemoveDirectoryWithSubItems(const UString &path); 42 #endif 43 44 bool GetOnlyDirPrefix(LPCTSTR fileName, CSysString &resultName); 45 bool GetOnlyName(LPCTSTR fileName, CSysString &resultName); 46 #ifdef UNDER_CE 47 bool MyGetFullPathName(LPCWSTR fileName, UString &resultPath); 48 bool MyGetFullPathName(LPCWSTR fileName, UString &resultPath, int &fileNamePartStartIndex); 49 #else 50 bool MyGetShortPathName(LPCTSTR longPath, CSysString &shortPath); 51 52 bool MyGetFullPathName(LPCTSTR fileName, CSysString &resultPath, int &fileNamePartStartIndex); 53 bool MyGetFullPathName(LPCTSTR fileName, CSysString &resultPath); 54 #ifndef _UNICODE 55 bool MyGetFullPathName(LPCWSTR fileName, UString &resultPath, 56 int &fileNamePartStartIndex); 57 bool MyGetFullPathName(LPCWSTR fileName, UString &resultPath); 58 bool GetOnlyName(LPCWSTR fileName, UString &resultName); 59 bool GetOnlyDirPrefix(LPCWSTR fileName, UString &resultName); 60 #endif 61 62 inline bool MySetCurrentDirectory(LPCTSTR path) 63 { return BOOLToBool(::SetCurrentDirectory(path)); } 64 bool MyGetCurrentDirectory(CSysString &resultPath); 65 #ifndef _UNICODE 66 bool MySetCurrentDirectory(LPCWSTR path); 67 bool MyGetCurrentDirectory(UString &resultPath); 68 #endif 69 70 bool MySearchPath(LPCTSTR path, LPCTSTR fileName, LPCTSTR extension, CSysString &resultPath, UINT32 &filePart); 71 #ifndef _UNICODE 72 bool MySearchPath(LPCWSTR path, LPCWSTR fileName, LPCWSTR extension, UString &resultPath, UINT32 &filePart); 73 #endif 74 75 inline bool MySearchPath(LPCTSTR path, LPCTSTR fileName, LPCTSTR extension, CSysString &resultPath) 76 { 77 UINT32 value; 78 return MySearchPath(path, fileName, extension, resultPath, value); 79 } 80 81 #ifndef _UNICODE 82 inline bool MySearchPath(LPCWSTR path, LPCWSTR fileName, LPCWSTR extension, UString &resultPath) 83 { 84 UINT32 value; 85 return MySearchPath(path, fileName, extension, resultPath, value); 86 } 87 #endif 88 89 #endif 90 91 bool MyGetTempPath(CSysString &resultPath); 92 #ifndef _UNICODE 93 bool MyGetTempPath(UString &resultPath); 94 #endif 95 96 UINT MyGetTempFileName(LPCTSTR dirPath, LPCTSTR prefix, CSysString &resultPath); 97 #ifndef _UNICODE 98 UINT MyGetTempFileName(LPCWSTR dirPath, LPCWSTR prefix, UString &resultPath); 99 #endif 100 101 class CTempFile 102 { 103 bool _mustBeDeleted; 104 CSysString _fileName; 105 public: 106 CTempFile(): _mustBeDeleted(false) {} 107 ~CTempFile() { Remove(); } 108 void DisableDeleting() { _mustBeDeleted = false; } 109 UINT Create(LPCTSTR dirPath, LPCTSTR prefix, CSysString &resultPath); 110 bool Create(LPCTSTR prefix, CSysString &resultPath); 111 bool Remove(); 112 }; 113 114 #ifdef _UNICODE 115 typedef CTempFile CTempFileW; 116 #else 117 class CTempFileW 118 { 119 bool _mustBeDeleted; 120 UString _fileName; 121 public: 122 CTempFileW(): _mustBeDeleted(false) {} 123 ~CTempFileW() { Remove(); } 124 void DisableDeleting() { _mustBeDeleted = false; } 125 UINT Create(LPCWSTR dirPath, LPCWSTR prefix, UString &resultPath); 126 bool Create(LPCWSTR prefix, UString &resultPath); 127 bool Remove(); 128 }; 129 #endif 130 131 bool CreateTempDirectory(LPCTSTR prefixChars, CSysString &dirName); 132 133 class CTempDirectory 134 { 135 bool _mustBeDeleted; 136 CSysString _tempDir; 137 public: 138 const CSysString &GetPath() const { return _tempDir; } 139 CTempDirectory(): _mustBeDeleted(false) {} 140 ~CTempDirectory() { Remove(); } 141 bool Create(LPCTSTR prefix) ; 142 bool Remove() 143 { 144 if (!_mustBeDeleted) 145 return true; 146 _mustBeDeleted = !RemoveDirectoryWithSubItems(_tempDir); 147 return (!_mustBeDeleted); 148 } 149 void DisableDeleting() { _mustBeDeleted = false; } 150 }; 151 152 #ifdef _UNICODE 153 typedef CTempDirectory CTempDirectoryW; 154 #else 155 class CTempDirectoryW 156 { 157 bool _mustBeDeleted; 158 UString _tempDir; 159 public: 160 const UString &GetPath() const { return _tempDir; } 161 CTempDirectoryW(): _mustBeDeleted(false) {} 162 ~CTempDirectoryW() { Remove(); } 163 bool Create(LPCWSTR prefix) ; 164 bool Remove() 165 { 166 if (!_mustBeDeleted) 167 return true; 168 _mustBeDeleted = !RemoveDirectoryWithSubItems(_tempDir); 169 return (!_mustBeDeleted); 170 } 171 void DisableDeleting() { _mustBeDeleted = false; } 172 }; 173 #endif 174 175 }}} 176 177 #endif 178