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 9namespace NWindows { 10namespace NFile { 11namespace NDirectory { 12 13#ifdef WIN_LONG_PATH 14bool GetLongPaths(LPCWSTR s1, LPCWSTR s2, UString &d1, UString &d2); 15#endif 16 17bool MyGetWindowsDirectory(CSysString &path); 18bool MyGetSystemDirectory(CSysString &path); 19#ifndef _UNICODE 20bool MyGetWindowsDirectory(UString &path); 21bool MyGetSystemDirectory(UString &path); 22#endif 23 24bool SetDirTime(LPCWSTR fileName, const FILETIME *cTime, const FILETIME *aTime, const FILETIME *mTime); 25 26bool MySetFileAttributes(LPCTSTR fileName, DWORD fileAttributes); 27bool MyMoveFile(LPCTSTR existFileName, LPCTSTR newFileName); 28bool MyRemoveDirectory(LPCTSTR pathName); 29bool MyCreateDirectory(LPCTSTR pathName); 30bool CreateComplexDirectory(LPCTSTR pathName); 31bool DeleteFileAlways(LPCTSTR name); 32bool RemoveDirectoryWithSubItems(const CSysString &path); 33 34#ifndef _UNICODE 35bool MySetFileAttributes(LPCWSTR fileName, DWORD fileAttributes); 36bool MyMoveFile(LPCWSTR existFileName, LPCWSTR newFileName); 37bool MyRemoveDirectory(LPCWSTR pathName); 38bool MyCreateDirectory(LPCWSTR pathName); 39bool CreateComplexDirectory(LPCWSTR pathName); 40bool DeleteFileAlways(LPCWSTR name); 41bool RemoveDirectoryWithSubItems(const UString &path); 42#endif 43 44bool GetOnlyDirPrefix(LPCTSTR fileName, CSysString &resultName); 45bool GetOnlyName(LPCTSTR fileName, CSysString &resultName); 46#ifdef UNDER_CE 47bool MyGetFullPathName(LPCWSTR fileName, UString &resultPath); 48bool MyGetFullPathName(LPCWSTR fileName, UString &resultPath, int &fileNamePartStartIndex); 49#else 50bool MyGetShortPathName(LPCTSTR longPath, CSysString &shortPath); 51 52bool MyGetFullPathName(LPCTSTR fileName, CSysString &resultPath, int &fileNamePartStartIndex); 53bool MyGetFullPathName(LPCTSTR fileName, CSysString &resultPath); 54#ifndef _UNICODE 55bool MyGetFullPathName(LPCWSTR fileName, UString &resultPath, 56 int &fileNamePartStartIndex); 57bool MyGetFullPathName(LPCWSTR fileName, UString &resultPath); 58bool GetOnlyName(LPCWSTR fileName, UString &resultName); 59bool GetOnlyDirPrefix(LPCWSTR fileName, UString &resultName); 60#endif 61 62inline bool MySetCurrentDirectory(LPCTSTR path) 63 { return BOOLToBool(::SetCurrentDirectory(path)); } 64bool MyGetCurrentDirectory(CSysString &resultPath); 65#ifndef _UNICODE 66bool MySetCurrentDirectory(LPCWSTR path); 67bool MyGetCurrentDirectory(UString &resultPath); 68#endif 69 70bool MySearchPath(LPCTSTR path, LPCTSTR fileName, LPCTSTR extension, CSysString &resultPath, UINT32 &filePart); 71#ifndef _UNICODE 72bool MySearchPath(LPCWSTR path, LPCWSTR fileName, LPCWSTR extension, UString &resultPath, UINT32 &filePart); 73#endif 74 75inline 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 82inline 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 91bool MyGetTempPath(CSysString &resultPath); 92#ifndef _UNICODE 93bool MyGetTempPath(UString &resultPath); 94#endif 95 96UINT MyGetTempFileName(LPCTSTR dirPath, LPCTSTR prefix, CSysString &resultPath); 97#ifndef _UNICODE 98UINT MyGetTempFileName(LPCWSTR dirPath, LPCWSTR prefix, UString &resultPath); 99#endif 100 101class CTempFile 102{ 103 bool _mustBeDeleted; 104 CSysString _fileName; 105public: 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 115typedef CTempFile CTempFileW; 116#else 117class CTempFileW 118{ 119 bool _mustBeDeleted; 120 UString _fileName; 121public: 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 131bool CreateTempDirectory(LPCTSTR prefixChars, CSysString &dirName); 132 133class CTempDirectory 134{ 135 bool _mustBeDeleted; 136 CSysString _tempDir; 137public: 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 153typedef CTempDirectory CTempDirectoryW; 154#else 155class CTempDirectoryW 156{ 157 bool _mustBeDeleted; 158 UString _tempDir; 159public: 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