diff options
author | Igor Pavlov <87184205+ip7z@users.noreply.github.com> | 2021-12-27 00:00:00 +0000 |
---|---|---|
committer | Igor Pavlov <87184205+ip7z@users.noreply.github.com> | 2022-03-18 15:35:13 +0500 |
commit | f19f813537c7aea1c20749c914e756b54a9c3cf5 (patch) | |
tree | 816ba62ca7c0fa19f2eb46d9e9d6f7dd7c3a744d /CPP/Windows/FileDir.h | |
parent | 98e06a519b63b81986abe76d28887f6984a7732b (diff) | |
download | 7zip-21.07.tar.gz 7zip-21.07.tar.bz2 7zip-21.07.zip |
'21.07'21.07
Diffstat (limited to 'CPP/Windows/FileDir.h')
-rw-r--r-- | CPP/Windows/FileDir.h | 125 |
1 files changed, 125 insertions, 0 deletions
diff --git a/CPP/Windows/FileDir.h b/CPP/Windows/FileDir.h new file mode 100644 index 0000000..6d6ddea --- /dev/null +++ b/CPP/Windows/FileDir.h | |||
@@ -0,0 +1,125 @@ | |||
1 | // Windows/FileDir.h | ||
2 | |||
3 | #ifndef __WINDOWS_FILE_DIR_H | ||
4 | #define __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 | bool SetDirTime(CFSTR path, const FILETIME *cTime, const FILETIME *aTime, const FILETIME *mTime); | ||
18 | |||
19 | |||
20 | #ifdef _WIN32 | ||
21 | |||
22 | bool SetFileAttrib(CFSTR path, DWORD attrib); | ||
23 | |||
24 | /* | ||
25 | Some programs store posix attributes in high 16 bits of windows attributes field. | ||
26 | Also some programs use additional flag markers: 0x8000 or 0x4000. | ||
27 | SetFileAttrib_PosixHighDetect() tries to detect posix field, and it extracts only attribute | ||
28 | bits that are related to current system only. | ||
29 | */ | ||
30 | |||
31 | #endif | ||
32 | |||
33 | bool SetFileAttrib_PosixHighDetect(CFSTR path, DWORD attrib); | ||
34 | |||
35 | |||
36 | bool MyMoveFile(CFSTR existFileName, CFSTR newFileName); | ||
37 | |||
38 | #ifndef UNDER_CE | ||
39 | bool MyCreateHardLink(CFSTR newFileName, CFSTR existFileName); | ||
40 | #endif | ||
41 | |||
42 | bool RemoveDir(CFSTR path); | ||
43 | bool CreateDir(CFSTR path); | ||
44 | |||
45 | /* CreateComplexDir returns true, if directory can contain files after the call (two cases): | ||
46 | 1) the directory already exists (network shares and drive paths are supported) | ||
47 | 2) the directory was created | ||
48 | path can be WITH or WITHOUT trailing path separator. */ | ||
49 | |||
50 | bool CreateComplexDir(CFSTR path); | ||
51 | |||
52 | bool DeleteFileAlways(CFSTR name); | ||
53 | bool RemoveDirWithSubItems(const FString &path); | ||
54 | |||
55 | bool MyGetFullPathName(CFSTR path, FString &resFullPath); | ||
56 | bool GetFullPathAndSplit(CFSTR path, FString &resDirPrefix, FString &resFileName); | ||
57 | bool GetOnlyDirPrefix(CFSTR path, FString &resDirPrefix); | ||
58 | |||
59 | #ifndef UNDER_CE | ||
60 | |||
61 | bool SetCurrentDir(CFSTR path); | ||
62 | bool GetCurrentDir(FString &resultPath); | ||
63 | |||
64 | #endif | ||
65 | |||
66 | bool MyGetTempPath(FString &resultPath); | ||
67 | |||
68 | class CTempFile MY_UNCOPYABLE | ||
69 | { | ||
70 | bool _mustBeDeleted; | ||
71 | FString _path; | ||
72 | void DisableDeleting() { _mustBeDeleted = false; } | ||
73 | public: | ||
74 | CTempFile(): _mustBeDeleted(false) {} | ||
75 | ~CTempFile() { Remove(); } | ||
76 | const FString &GetPath() const { return _path; } | ||
77 | bool Create(CFSTR pathPrefix, NIO::COutFile *outFile); // pathPrefix is not folder prefix | ||
78 | bool CreateRandomInTempFolder(CFSTR namePrefix, NIO::COutFile *outFile); | ||
79 | bool Remove(); | ||
80 | bool MoveTo(CFSTR name, bool deleteDestBefore); | ||
81 | }; | ||
82 | |||
83 | |||
84 | #ifdef _WIN32 | ||
85 | class CTempDir MY_UNCOPYABLE | ||
86 | { | ||
87 | bool _mustBeDeleted; | ||
88 | FString _path; | ||
89 | public: | ||
90 | CTempDir(): _mustBeDeleted(false) {} | ||
91 | ~CTempDir() { Remove(); } | ||
92 | const FString &GetPath() const { return _path; } | ||
93 | void DisableDeleting() { _mustBeDeleted = false; } | ||
94 | bool Create(CFSTR namePrefix) ; | ||
95 | bool Remove(); | ||
96 | }; | ||
97 | #endif | ||
98 | |||
99 | |||
100 | #if !defined(UNDER_CE) | ||
101 | class CCurrentDirRestorer MY_UNCOPYABLE | ||
102 | { | ||
103 | FString _path; | ||
104 | public: | ||
105 | bool NeedRestore; | ||
106 | |||
107 | CCurrentDirRestorer(): NeedRestore(true) | ||
108 | { | ||
109 | GetCurrentDir(_path); | ||
110 | } | ||
111 | ~CCurrentDirRestorer() | ||
112 | { | ||
113 | if (!NeedRestore) | ||
114 | return; | ||
115 | FString s; | ||
116 | if (GetCurrentDir(s)) | ||
117 | if (s != _path) | ||
118 | SetCurrentDir(_path); | ||
119 | } | ||
120 | }; | ||
121 | #endif | ||
122 | |||
123 | }}} | ||
124 | |||
125 | #endif | ||