view src/win32/7zip/7z/CPP/Windows/FileDir.h @ 5:8fe0c57e53d2

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