1 // Windows/FileDir.h
2
3 #ifndef ZIP7_INC_WINDOWS_FILE_DIR_H
4 #define ZIP7_INC_WINDOWS_FILE_DIR_H
5
6 #include "../Common/MyString.h"
7
8 #include "FileIO.h"
9
10 namespace NWindows {
11 namespace NFile {
12 namespace NDir {
13
14 bool GetWindowsDir(FString &path);
15 bool GetSystemDir(FString &path);
16
17 /*
18 WIN32 API : SetFileTime() doesn't allow to set zero timestamps in file
19 but linux : allows unix time = 0 in filesystem
20 */
21
22 bool SetDirTime(CFSTR path, const CFiTime *cTime, const CFiTime *aTime, const CFiTime *mTime);
23
24
25 #ifdef _WIN32
26
27 bool SetFileAttrib(CFSTR path, DWORD attrib);
28
29 /*
30 Some programs store posix attributes in high 16 bits of windows attributes field.
31 Also some programs use additional flag markers: 0x8000 or 0x4000.
32 SetFileAttrib_PosixHighDetect() tries to detect posix field, and it extracts only attribute
33 bits that are related to current system only.
34 */
35 #else
36
37 int my_chown(CFSTR path, uid_t owner, gid_t group);
38
39 #endif
40
41 bool SetFileAttrib_PosixHighDetect(CFSTR path, DWORD attrib);
42
43
44 #ifndef _WIN32
45 #define PROGRESS_CONTINUE 0
46 #define PROGRESS_CANCEL 1
47 // #define PROGRESS_STOP 2
48 // #define PROGRESS_QUIET 3
49 #endif
50 Z7_PURE_INTERFACES_BEGIN
DECLARE_INTERFACE(ICopyFileProgress)51 DECLARE_INTERFACE(ICopyFileProgress)
52 {
53 // in: total, current: include all/processed alt streams.
54 // it returns PROGRESS_CONTINUE or PROGRESS_CANCEL.
55 virtual DWORD CopyFileProgress(UInt64 total, UInt64 current) = 0;
56 };
57 Z7_PURE_INTERFACES_END
58
59 bool MyMoveFile(CFSTR existFileName, CFSTR newFileName);
60 // (progress == NULL) is allowed
61 bool MyMoveFile_with_Progress(CFSTR oldFile, CFSTR newFile,
62 ICopyFileProgress *progress);
63
64
65 #ifndef UNDER_CE
66 bool MyCreateHardLink(CFSTR newFileName, CFSTR existFileName);
67 #endif
68
69 bool RemoveDir(CFSTR path);
70 bool CreateDir(CFSTR path);
71
72 /* CreateComplexDir returns true, if directory can contain files after the call (two cases):
73 1) the directory already exists (network shares and drive paths are supported)
74 2) the directory was created
75 path can be WITH or WITHOUT trailing path separator. */
76
77 bool CreateComplexDir(CFSTR path);
78
79 bool DeleteFileAlways(CFSTR name);
80 bool RemoveDirWithSubItems(const FString &path);
81
82 bool MyGetFullPathName(CFSTR path, FString &resFullPath);
83 bool GetFullPathAndSplit(CFSTR path, FString &resDirPrefix, FString &resFileName);
84 bool GetOnlyDirPrefix(CFSTR path, FString &resDirPrefix);
85
86 #ifndef UNDER_CE
87
88 bool SetCurrentDir(CFSTR path);
89 bool GetCurrentDir(FString &resultPath);
90
91 #endif
92
93 bool MyGetTempPath(FString &resultPath);
94
95 bool CreateTempFile2(CFSTR prefix, bool addRandom, AString &postfix, NIO::COutFile *outFile);
96
97 class CTempFile MY_UNCOPYABLE
98 {
99 bool _mustBeDeleted;
100 FString _path;
DisableDeleting()101 void DisableDeleting() { _mustBeDeleted = false; }
102 public:
CTempFile()103 CTempFile(): _mustBeDeleted(false) {}
~CTempFile()104 ~CTempFile() { Remove(); }
GetPath()105 const FString &GetPath() const { return _path; }
106 bool Create(CFSTR pathPrefix, NIO::COutFile *outFile); // pathPrefix is not folder prefix
107 bool CreateRandomInTempFolder(CFSTR namePrefix, NIO::COutFile *outFile);
108 bool Remove();
109 // bool MoveTo(CFSTR name, bool deleteDestBefore);
110 bool MoveTo(CFSTR name, bool deleteDestBefore,
111 ICopyFileProgress *progress);
112 };
113
114
115 #ifdef _WIN32
116 class CTempDir MY_UNCOPYABLE
117 {
118 bool _mustBeDeleted;
119 FString _path;
120 public:
CTempDir()121 CTempDir(): _mustBeDeleted(false) {}
~CTempDir()122 ~CTempDir() { Remove(); }
GetPath()123 const FString &GetPath() const { return _path; }
DisableDeleting()124 void DisableDeleting() { _mustBeDeleted = false; }
125 bool Create(CFSTR namePrefix) ;
126 bool Remove();
127 };
128 #endif
129
130
131 #if !defined(UNDER_CE)
132 class CCurrentDirRestorer MY_UNCOPYABLE
133 {
134 FString _path;
135 public:
136 bool NeedRestore;
137
CCurrentDirRestorer()138 CCurrentDirRestorer(): NeedRestore(true)
139 {
140 GetCurrentDir(_path);
141 }
~CCurrentDirRestorer()142 ~CCurrentDirRestorer()
143 {
144 if (!NeedRestore)
145 return;
146 FString s;
147 if (GetCurrentDir(s))
148 if (s != _path)
149 SetCurrentDir(_path);
150 }
151 };
152 #endif
153
154 }}}
155
156 #endif
157