aboutsummaryrefslogtreecommitdiff
path: root/CPP/Windows/FileDir.h
diff options
context:
space:
mode:
Diffstat (limited to 'CPP/Windows/FileDir.h')
-rw-r--r--CPP/Windows/FileDir.h125
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
10namespace NWindows {
11namespace NFile {
12namespace NDir {
13
14bool GetWindowsDir(FString &path);
15bool GetSystemDir(FString &path);
16
17bool SetDirTime(CFSTR path, const FILETIME *cTime, const FILETIME *aTime, const FILETIME *mTime);
18
19
20#ifdef _WIN32
21
22bool 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
33bool SetFileAttrib_PosixHighDetect(CFSTR path, DWORD attrib);
34
35
36bool MyMoveFile(CFSTR existFileName, CFSTR newFileName);
37
38#ifndef UNDER_CE
39bool MyCreateHardLink(CFSTR newFileName, CFSTR existFileName);
40#endif
41
42bool RemoveDir(CFSTR path);
43bool 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
50bool CreateComplexDir(CFSTR path);
51
52bool DeleteFileAlways(CFSTR name);
53bool RemoveDirWithSubItems(const FString &path);
54
55bool MyGetFullPathName(CFSTR path, FString &resFullPath);
56bool GetFullPathAndSplit(CFSTR path, FString &resDirPrefix, FString &resFileName);
57bool GetOnlyDirPrefix(CFSTR path, FString &resDirPrefix);
58
59#ifndef UNDER_CE
60
61bool SetCurrentDir(CFSTR path);
62bool GetCurrentDir(FString &resultPath);
63
64#endif
65
66bool MyGetTempPath(FString &resultPath);
67
68class CTempFile MY_UNCOPYABLE
69{
70 bool _mustBeDeleted;
71 FString _path;
72 void DisableDeleting() { _mustBeDeleted = false; }
73public:
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
85class CTempDir MY_UNCOPYABLE
86{
87 bool _mustBeDeleted;
88 FString _path;
89public:
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)
101class CCurrentDirRestorer MY_UNCOPYABLE
102{
103 FString _path;
104public:
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