• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 bool SetFileAttrib(CFSTR path, DWORD attrib);
21 
22 /*
23   Some programs store posix attributes in high 16 bits of windows attributes field.
24   Also some programs use additional flag markers: 0x8000 or 0x4000.
25   SetFileAttrib_PosixHighDetect() tries to detect posix field, and it extracts only attribute
26   bits that are related to current system only.
27 */
28 
29 bool SetFileAttrib_PosixHighDetect(CFSTR path, DWORD attrib);
30 
31 
32 bool MyMoveFile(CFSTR existFileName, CFSTR newFileName);
33 
34 #ifndef UNDER_CE
35 bool MyCreateHardLink(CFSTR newFileName, CFSTR existFileName);
36 #endif
37 
38 bool RemoveDir(CFSTR path);
39 bool CreateDir(CFSTR path);
40 
41 /* CreateComplexDir returns true, if directory can contain files after the call (two cases):
42     1) the directory already exists (network shares and drive paths are supported)
43     2) the directory was created
44   path can be WITH or WITHOUT trailing path separator. */
45 
46 bool CreateComplexDir(CFSTR path);
47 
48 bool DeleteFileAlways(CFSTR name);
49 bool RemoveDirWithSubItems(const FString &path);
50 
51 bool MyGetFullPathName(CFSTR path, FString &resFullPath);
52 bool GetFullPathAndSplit(CFSTR path, FString &resDirPrefix, FString &resFileName);
53 bool GetOnlyDirPrefix(CFSTR path, FString &resDirPrefix);
54 
55 #ifndef UNDER_CE
56 
57 bool SetCurrentDir(CFSTR path);
58 bool GetCurrentDir(FString &resultPath);
59 
60 #endif
61 
62 bool MyGetTempPath(FString &resultPath);
63 
64 class CTempFile
65 {
66   bool _mustBeDeleted;
67   FString _path;
DisableDeleting()68   void DisableDeleting() { _mustBeDeleted = false; }
69 public:
CTempFile()70   CTempFile(): _mustBeDeleted(false) {}
~CTempFile()71   ~CTempFile() { Remove(); }
GetPath()72   const FString &GetPath() const { return _path; }
73   bool Create(CFSTR pathPrefix, NIO::COutFile *outFile); // pathPrefix is not folder prefix
74   bool CreateRandomInTempFolder(CFSTR namePrefix, NIO::COutFile *outFile);
75   bool Remove();
76   bool MoveTo(CFSTR name, bool deleteDestBefore);
77 };
78 
79 class CTempDir
80 {
81   bool _mustBeDeleted;
82   FString _path;
83 public:
CTempDir()84   CTempDir(): _mustBeDeleted(false) {}
~CTempDir()85   ~CTempDir() { Remove();  }
GetPath()86   const FString &GetPath() const { return _path; }
DisableDeleting()87   void DisableDeleting() { _mustBeDeleted = false; }
88   bool Create(CFSTR namePrefix) ;
89   bool Remove();
90 };
91 
92 #if !defined(UNDER_CE)
93 class CCurrentDirRestorer
94 {
95   FString _path;
96 public:
97   bool NeedRestore;
98 
CCurrentDirRestorer()99   CCurrentDirRestorer(): NeedRestore(true)
100   {
101     GetCurrentDir(_path);
102   }
~CCurrentDirRestorer()103   ~CCurrentDirRestorer()
104   {
105     if (!NeedRestore)
106       return;
107     FString s;
108     if (GetCurrentDir(s))
109       if (s != _path)
110         SetCurrentDir(_path);
111   }
112 };
113 #endif
114 
115 }}}
116 
117 #endif
118