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