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