1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/other-licenses/7zstub/src/Windows/FileDir.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,189 @@ 1.4 +// Windows/FileDir.h 1.5 + 1.6 +#ifndef __WINDOWS_FILEDIR_H 1.7 +#define __WINDOWS_FILEDIR_H 1.8 + 1.9 +#include "../Common/String.h" 1.10 +#include "Defs.h" 1.11 + 1.12 +namespace NWindows { 1.13 +namespace NFile { 1.14 +namespace NDirectory { 1.15 + 1.16 +bool MyGetWindowsDirectory(CSysString &path); 1.17 +bool MyGetSystemDirectory(CSysString &path); 1.18 +#ifndef _UNICODE 1.19 +bool MyGetWindowsDirectory(UString &path); 1.20 +bool MyGetSystemDirectory(UString &path); 1.21 +#endif 1.22 + 1.23 +inline bool MySetFileAttributes(LPCTSTR fileName, DWORD fileAttributes) 1.24 + { return BOOLToBool(::SetFileAttributes(fileName, fileAttributes)); } 1.25 +#ifndef _UNICODE 1.26 +bool MySetFileAttributes(LPCWSTR fileName, DWORD fileAttributes); 1.27 +#endif 1.28 + 1.29 +inline bool MyMoveFile(LPCTSTR existFileName, LPCTSTR newFileName) 1.30 + { return BOOLToBool(::MoveFile(existFileName, newFileName)); } 1.31 +#ifndef _UNICODE 1.32 +bool MyMoveFile(LPCWSTR existFileName, LPCWSTR newFileName); 1.33 +#endif 1.34 + 1.35 +inline bool MyRemoveDirectory(LPCTSTR pathName) 1.36 + { return BOOLToBool(::RemoveDirectory(pathName)); } 1.37 +#ifndef _UNICODE 1.38 +bool MyRemoveDirectory(LPCWSTR pathName); 1.39 +#endif 1.40 + 1.41 +bool MyCreateDirectory(LPCTSTR pathName); 1.42 +bool CreateComplexDirectory(LPCTSTR pathName); 1.43 +#ifndef _UNICODE 1.44 +bool MyCreateDirectory(LPCWSTR pathName); 1.45 +bool CreateComplexDirectory(LPCWSTR pathName); 1.46 +#endif 1.47 + 1.48 +bool DeleteFileAlways(LPCTSTR name); 1.49 +#ifndef _UNICODE 1.50 +bool DeleteFileAlways(LPCWSTR name); 1.51 +#endif 1.52 + 1.53 +bool RemoveDirectoryWithSubItems(const CSysString &path); 1.54 +#ifndef _UNICODE 1.55 +bool RemoveDirectoryWithSubItems(const UString &path); 1.56 +#endif 1.57 + 1.58 +#ifndef _WIN32_WCE 1.59 +bool MyGetShortPathName(LPCTSTR longPath, CSysString &shortPath); 1.60 + 1.61 +bool MyGetFullPathName(LPCTSTR fileName, CSysString &resultPath, 1.62 + int &fileNamePartStartIndex); 1.63 +bool MyGetFullPathName(LPCTSTR fileName, CSysString &resultPath); 1.64 +bool GetOnlyName(LPCTSTR fileName, CSysString &resultName); 1.65 +bool GetOnlyDirPrefix(LPCTSTR fileName, CSysString &resultName); 1.66 +#ifndef _UNICODE 1.67 +bool MyGetFullPathName(LPCWSTR fileName, UString &resultPath, 1.68 + int &fileNamePartStartIndex); 1.69 +bool MyGetFullPathName(LPCWSTR fileName, UString &resultPath); 1.70 +bool GetOnlyName(LPCWSTR fileName, UString &resultName); 1.71 +bool GetOnlyDirPrefix(LPCWSTR fileName, UString &resultName); 1.72 +#endif 1.73 + 1.74 +inline bool MySetCurrentDirectory(LPCTSTR path) 1.75 + { return BOOLToBool(::SetCurrentDirectory(path)); } 1.76 +bool MyGetCurrentDirectory(CSysString &resultPath); 1.77 +#ifndef _UNICODE 1.78 +bool MySetCurrentDirectory(LPCWSTR path); 1.79 +bool MyGetCurrentDirectory(UString &resultPath); 1.80 +#endif 1.81 +#endif 1.82 + 1.83 +bool MySearchPath(LPCTSTR path, LPCTSTR fileName, LPCTSTR extension, 1.84 + CSysString &resultPath, UINT32 &filePart); 1.85 +#ifndef _UNICODE 1.86 +bool MySearchPath(LPCWSTR path, LPCWSTR fileName, LPCWSTR extension, 1.87 + UString &resultPath, UINT32 &filePart); 1.88 +#endif 1.89 + 1.90 +inline bool MySearchPath(LPCTSTR path, LPCTSTR fileName, LPCTSTR extension, 1.91 + CSysString &resultPath) 1.92 +{ 1.93 + UINT32 value; 1.94 + return MySearchPath(path, fileName, extension, resultPath, value); 1.95 +} 1.96 + 1.97 +#ifndef _UNICODE 1.98 +inline bool MySearchPath(LPCWSTR path, LPCWSTR fileName, LPCWSTR extension, 1.99 + UString &resultPath) 1.100 +{ 1.101 + UINT32 value; 1.102 + return MySearchPath(path, fileName, extension, resultPath, value); 1.103 +} 1.104 +#endif 1.105 + 1.106 +bool MyGetTempPath(CSysString &resultPath); 1.107 +#ifndef _UNICODE 1.108 +bool MyGetTempPath(UString &resultPath); 1.109 +#endif 1.110 + 1.111 +UINT MyGetTempFileName(LPCTSTR dirPath, LPCTSTR prefix, CSysString &resultPath); 1.112 +#ifndef _UNICODE 1.113 +UINT MyGetTempFileName(LPCWSTR dirPath, LPCWSTR prefix, UString &resultPath); 1.114 +#endif 1.115 + 1.116 +class CTempFile 1.117 +{ 1.118 + bool _mustBeDeleted; 1.119 + CSysString _fileName; 1.120 +public: 1.121 + CTempFile(): _mustBeDeleted(false) {} 1.122 + ~CTempFile() { Remove(); } 1.123 + void DisableDeleting() { _mustBeDeleted = false; } 1.124 + UINT Create(LPCTSTR dirPath, LPCTSTR prefix, CSysString &resultPath); 1.125 + bool Create(LPCTSTR prefix, CSysString &resultPath); 1.126 + bool Remove(); 1.127 +}; 1.128 + 1.129 +#ifdef _UNICODE 1.130 +typedef CTempFile CTempFileW; 1.131 +#else 1.132 +class CTempFileW 1.133 +{ 1.134 + bool _mustBeDeleted; 1.135 + UString _fileName; 1.136 +public: 1.137 + CTempFileW(): _mustBeDeleted(false) {} 1.138 + ~CTempFileW() { Remove(); } 1.139 + void DisableDeleting() { _mustBeDeleted = false; } 1.140 + UINT Create(LPCWSTR dirPath, LPCWSTR prefix, UString &resultPath); 1.141 + bool Create(LPCWSTR prefix, UString &resultPath); 1.142 + bool Remove(); 1.143 +}; 1.144 +#endif 1.145 + 1.146 +bool CreateTempDirectory(LPCTSTR prefixChars, CSysString &dirName); 1.147 + 1.148 +class CTempDirectory 1.149 +{ 1.150 + bool _mustBeDeleted; 1.151 + CSysString _tempDir; 1.152 +public: 1.153 + const CSysString &GetPath() const { return _tempDir; } 1.154 + CTempDirectory(): _mustBeDeleted(false) {} 1.155 + ~CTempDirectory() { Remove(); } 1.156 + bool Create(LPCTSTR prefix) ; 1.157 + bool Remove() 1.158 + { 1.159 + if (!_mustBeDeleted) 1.160 + return true; 1.161 + _mustBeDeleted = !RemoveDirectoryWithSubItems(_tempDir); 1.162 + return (!_mustBeDeleted); 1.163 + } 1.164 + void DisableDeleting() { _mustBeDeleted = false; } 1.165 +}; 1.166 + 1.167 +#ifdef _UNICODE 1.168 +typedef CTempDirectory CTempDirectoryW; 1.169 +#else 1.170 +class CTempDirectoryW 1.171 +{ 1.172 + bool _mustBeDeleted; 1.173 + UString _tempDir; 1.174 +public: 1.175 + const UString &GetPath() const { return _tempDir; } 1.176 + CTempDirectoryW(): _mustBeDeleted(false) {} 1.177 + ~CTempDirectoryW() { Remove(); } 1.178 + bool Create(LPCWSTR prefix) ; 1.179 + bool Remove() 1.180 + { 1.181 + if (!_mustBeDeleted) 1.182 + return true; 1.183 + _mustBeDeleted = !RemoveDirectoryWithSubItems(_tempDir); 1.184 + return (!_mustBeDeleted); 1.185 + } 1.186 + void DisableDeleting() { _mustBeDeleted = false; } 1.187 +}; 1.188 +#endif 1.189 + 1.190 +}}} 1.191 + 1.192 +#endif