• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 bool MyMoveFile(CFSTR existFileName, CFSTR newFileName);
45 
46 #ifndef UNDER_CE
47 bool MyCreateHardLink(CFSTR newFileName, CFSTR existFileName);
48 #endif
49 
50 bool RemoveDir(CFSTR path);
51 bool CreateDir(CFSTR path);
52 
53 /* CreateComplexDir returns true, if directory can contain files after the call (two cases):
54     1) the directory already exists (network shares and drive paths are supported)
55     2) the directory was created
56   path can be WITH or WITHOUT trailing path separator. */
57 
58 bool CreateComplexDir(CFSTR path);
59 
60 bool DeleteFileAlways(CFSTR name);
61 bool RemoveDirWithSubItems(const FString &path);
62 
63 bool MyGetFullPathName(CFSTR path, FString &resFullPath);
64 bool GetFullPathAndSplit(CFSTR path, FString &resDirPrefix, FString &resFileName);
65 bool GetOnlyDirPrefix(CFSTR path, FString &resDirPrefix);
66 
67 #ifndef UNDER_CE
68 
69 bool SetCurrentDir(CFSTR path);
70 bool GetCurrentDir(FString &resultPath);
71 
72 #endif
73 
74 bool MyGetTempPath(FString &resultPath);
75 
76 bool CreateTempFile2(CFSTR prefix, bool addRandom, AString &postfix, NIO::COutFile *outFile);
77 
78 class CTempFile  MY_UNCOPYABLE
79 {
80   bool _mustBeDeleted;
81   FString _path;
DisableDeleting()82   void DisableDeleting() { _mustBeDeleted = false; }
83 public:
CTempFile()84   CTempFile(): _mustBeDeleted(false) {}
~CTempFile()85   ~CTempFile() { Remove(); }
GetPath()86   const FString &GetPath() const { return _path; }
87   bool Create(CFSTR pathPrefix, NIO::COutFile *outFile); // pathPrefix is not folder prefix
88   bool CreateRandomInTempFolder(CFSTR namePrefix, NIO::COutFile *outFile);
89   bool Remove();
90   bool MoveTo(CFSTR name, bool deleteDestBefore);
91 };
92 
93 
94 #ifdef _WIN32
95 class CTempDir  MY_UNCOPYABLE
96 {
97   bool _mustBeDeleted;
98   FString _path;
99 public:
CTempDir()100   CTempDir(): _mustBeDeleted(false) {}
~CTempDir()101   ~CTempDir() { Remove();  }
GetPath()102   const FString &GetPath() const { return _path; }
DisableDeleting()103   void DisableDeleting() { _mustBeDeleted = false; }
104   bool Create(CFSTR namePrefix) ;
105   bool Remove();
106 };
107 #endif
108 
109 
110 #if !defined(UNDER_CE)
111 class CCurrentDirRestorer  MY_UNCOPYABLE
112 {
113   FString _path;
114 public:
115   bool NeedRestore;
116 
CCurrentDirRestorer()117   CCurrentDirRestorer(): NeedRestore(true)
118   {
119     GetCurrentDir(_path);
120   }
~CCurrentDirRestorer()121   ~CCurrentDirRestorer()
122   {
123     if (!NeedRestore)
124       return;
125     FString s;
126     if (GetCurrentDir(s))
127       if (s != _path)
128         SetCurrentDir(_path);
129   }
130 };
131 #endif
132 
133 }}}
134 
135 #endif
136