other-licenses/7zstub/src/Windows/FileDir.h

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

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

mercurial