rlm@1: // Windows/FileDir.h rlm@1: rlm@1: #ifndef __WINDOWS_FILEDIR_H rlm@1: #define __WINDOWS_FILEDIR_H rlm@1: rlm@1: #include "../Common/MyString.h" rlm@1: #include "Defs.h" rlm@1: rlm@1: namespace NWindows { rlm@1: namespace NFile { rlm@1: namespace NDirectory { rlm@1: rlm@1: #ifdef WIN_LONG_PATH rlm@1: bool GetLongPaths(LPCWSTR s1, LPCWSTR s2, UString &d1, UString &d2); rlm@1: #endif rlm@1: rlm@1: bool MyGetWindowsDirectory(CSysString &path); rlm@1: bool MyGetSystemDirectory(CSysString &path); rlm@1: #ifndef _UNICODE rlm@1: bool MyGetWindowsDirectory(UString &path); rlm@1: bool MyGetSystemDirectory(UString &path); rlm@1: #endif rlm@1: rlm@1: bool SetDirTime(LPCWSTR fileName, const FILETIME *cTime, const FILETIME *aTime, const FILETIME *mTime); rlm@1: rlm@1: bool MySetFileAttributes(LPCTSTR fileName, DWORD fileAttributes); rlm@1: bool MyMoveFile(LPCTSTR existFileName, LPCTSTR newFileName); rlm@1: bool MyRemoveDirectory(LPCTSTR pathName); rlm@1: bool MyCreateDirectory(LPCTSTR pathName); rlm@1: bool CreateComplexDirectory(LPCTSTR pathName); rlm@1: bool DeleteFileAlways(LPCTSTR name); rlm@1: bool RemoveDirectoryWithSubItems(const CSysString &path); rlm@1: rlm@1: #ifndef _UNICODE rlm@1: bool MySetFileAttributes(LPCWSTR fileName, DWORD fileAttributes); rlm@1: bool MyMoveFile(LPCWSTR existFileName, LPCWSTR newFileName); rlm@1: bool MyRemoveDirectory(LPCWSTR pathName); rlm@1: bool MyCreateDirectory(LPCWSTR pathName); rlm@1: bool CreateComplexDirectory(LPCWSTR pathName); rlm@1: bool DeleteFileAlways(LPCWSTR name); rlm@1: bool RemoveDirectoryWithSubItems(const UString &path); rlm@1: #endif rlm@1: rlm@1: #ifndef _WIN32_WCE rlm@1: bool MyGetShortPathName(LPCTSTR longPath, CSysString &shortPath); rlm@1: rlm@1: bool MyGetFullPathName(LPCTSTR fileName, CSysString &resultPath, rlm@1: int &fileNamePartStartIndex); rlm@1: bool MyGetFullPathName(LPCTSTR fileName, CSysString &resultPath); rlm@1: bool GetOnlyName(LPCTSTR fileName, CSysString &resultName); rlm@1: bool GetOnlyDirPrefix(LPCTSTR fileName, CSysString &resultName); rlm@1: #ifndef _UNICODE rlm@1: bool MyGetFullPathName(LPCWSTR fileName, UString &resultPath, rlm@1: int &fileNamePartStartIndex); rlm@1: bool MyGetFullPathName(LPCWSTR fileName, UString &resultPath); rlm@1: bool GetOnlyName(LPCWSTR fileName, UString &resultName); rlm@1: bool GetOnlyDirPrefix(LPCWSTR fileName, UString &resultName); rlm@1: #endif rlm@1: rlm@1: inline bool MySetCurrentDirectory(LPCTSTR path) rlm@1: { return BOOLToBool(::SetCurrentDirectory(path)); } rlm@1: bool MyGetCurrentDirectory(CSysString &resultPath); rlm@1: #ifndef _UNICODE rlm@1: bool MySetCurrentDirectory(LPCWSTR path); rlm@1: bool MyGetCurrentDirectory(UString &resultPath); rlm@1: #endif rlm@1: #endif rlm@1: rlm@1: bool MySearchPath(LPCTSTR path, LPCTSTR fileName, LPCTSTR extension, rlm@1: CSysString &resultPath, UINT32 &filePart); rlm@1: #ifndef _UNICODE rlm@1: bool MySearchPath(LPCWSTR path, LPCWSTR fileName, LPCWSTR extension, rlm@1: UString &resultPath, UINT32 &filePart); rlm@1: #endif rlm@1: rlm@1: inline bool MySearchPath(LPCTSTR path, LPCTSTR fileName, LPCTSTR extension, rlm@1: CSysString &resultPath) rlm@1: { rlm@1: UINT32 value; rlm@1: return MySearchPath(path, fileName, extension, resultPath, value); rlm@1: } rlm@1: rlm@1: #ifndef _UNICODE rlm@1: inline bool MySearchPath(LPCWSTR path, LPCWSTR fileName, LPCWSTR extension, rlm@1: UString &resultPath) rlm@1: { rlm@1: UINT32 value; rlm@1: return MySearchPath(path, fileName, extension, resultPath, value); rlm@1: } rlm@1: #endif rlm@1: rlm@1: bool MyGetTempPath(CSysString &resultPath); rlm@1: #ifndef _UNICODE rlm@1: bool MyGetTempPath(UString &resultPath); rlm@1: #endif rlm@1: rlm@1: UINT MyGetTempFileName(LPCTSTR dirPath, LPCTSTR prefix, CSysString &resultPath); rlm@1: #ifndef _UNICODE rlm@1: UINT MyGetTempFileName(LPCWSTR dirPath, LPCWSTR prefix, UString &resultPath); rlm@1: #endif rlm@1: rlm@1: class CTempFile rlm@1: { rlm@1: bool _mustBeDeleted; rlm@1: CSysString _fileName; rlm@1: public: rlm@1: CTempFile(): _mustBeDeleted(false) {} rlm@1: ~CTempFile() { Remove(); } rlm@1: void DisableDeleting() { _mustBeDeleted = false; } rlm@1: UINT Create(LPCTSTR dirPath, LPCTSTR prefix, CSysString &resultPath); rlm@1: bool Create(LPCTSTR prefix, CSysString &resultPath); rlm@1: bool Remove(); rlm@1: }; rlm@1: rlm@1: #ifdef _UNICODE rlm@1: typedef CTempFile CTempFileW; rlm@1: #else rlm@1: class CTempFileW rlm@1: { rlm@1: bool _mustBeDeleted; rlm@1: UString _fileName; rlm@1: public: rlm@1: CTempFileW(): _mustBeDeleted(false) {} rlm@1: ~CTempFileW() { Remove(); } rlm@1: void DisableDeleting() { _mustBeDeleted = false; } rlm@1: UINT Create(LPCWSTR dirPath, LPCWSTR prefix, UString &resultPath); rlm@1: bool Create(LPCWSTR prefix, UString &resultPath); rlm@1: bool Remove(); rlm@1: }; rlm@1: #endif rlm@1: rlm@1: bool CreateTempDirectory(LPCTSTR prefixChars, CSysString &dirName); rlm@1: rlm@1: class CTempDirectory rlm@1: { rlm@1: bool _mustBeDeleted; rlm@1: CSysString _tempDir; rlm@1: public: rlm@1: const CSysString &GetPath() const { return _tempDir; } rlm@1: CTempDirectory(): _mustBeDeleted(false) {} rlm@1: ~CTempDirectory() { Remove(); } rlm@1: bool Create(LPCTSTR prefix) ; rlm@1: bool Remove() rlm@1: { rlm@1: if (!_mustBeDeleted) rlm@1: return true; rlm@1: _mustBeDeleted = !RemoveDirectoryWithSubItems(_tempDir); rlm@1: return (!_mustBeDeleted); rlm@1: } rlm@1: void DisableDeleting() { _mustBeDeleted = false; } rlm@1: }; rlm@1: rlm@1: #ifdef _UNICODE rlm@1: typedef CTempDirectory CTempDirectoryW; rlm@1: #else rlm@1: class CTempDirectoryW rlm@1: { rlm@1: bool _mustBeDeleted; rlm@1: UString _tempDir; rlm@1: public: rlm@1: const UString &GetPath() const { return _tempDir; } rlm@1: CTempDirectoryW(): _mustBeDeleted(false) {} rlm@1: ~CTempDirectoryW() { Remove(); } rlm@1: bool Create(LPCWSTR prefix) ; rlm@1: bool Remove() rlm@1: { rlm@1: if (!_mustBeDeleted) rlm@1: return true; rlm@1: _mustBeDeleted = !RemoveDirectoryWithSubItems(_tempDir); rlm@1: return (!_mustBeDeleted); rlm@1: } rlm@1: void DisableDeleting() { _mustBeDeleted = false; } rlm@1: }; rlm@1: #endif rlm@1: rlm@1: }}} rlm@1: rlm@1: #endif