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