FileDir.h 5.0 KB

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