• 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 bool SetFileAttrib(CFSTR path, DWORD attrib);
19 bool MyMoveFile(CFSTR existFileName, CFSTR newFileName);
20 
21 #ifndef UNDER_CE
22 bool MyCreateHardLink(CFSTR newFileName, CFSTR existFileName);
23 #endif
24 
25 bool RemoveDir(CFSTR path);
26 bool CreateDir(CFSTR path);
27 
28 /* CreateComplexDir returns true, if directory can contain files after the call (two cases):
29     1) the directory already exists (network shares and drive paths are supported)
30     2) the directory was created
31   path can be WITH or WITHOUT trailing path separator. */
32 
33 bool CreateComplexDir(CFSTR path);
34 
35 bool DeleteFileAlways(CFSTR name);
36 bool RemoveDirWithSubItems(const FString &path);
37 
38 bool MyGetFullPathName(CFSTR path, FString &resFullPath);
39 bool GetFullPathAndSplit(CFSTR path, FString &resDirPrefix, FString &resFileName);
40 bool GetOnlyDirPrefix(CFSTR path, FString &resDirPrefix);
41 
42 #ifndef UNDER_CE
43 
44 bool SetCurrentDir(CFSTR path);
45 bool GetCurrentDir(FString &resultPath);
46 
47 #endif
48 
49 bool MyGetTempPath(FString &resultPath);
50 
51 class CTempFile
52 {
53   bool _mustBeDeleted;
54   FString _path;
DisableDeleting()55   void DisableDeleting() { _mustBeDeleted = false; }
56 public:
CTempFile()57   CTempFile(): _mustBeDeleted(false) {}
~CTempFile()58   ~CTempFile() { Remove(); }
GetPath()59   const FString &GetPath() const { return _path; }
60   bool Create(CFSTR pathPrefix, NIO::COutFile *outFile); // pathPrefix is not folder prefix
61   bool CreateRandomInTempFolder(CFSTR namePrefix, NIO::COutFile *outFile);
62   bool Remove();
63   bool MoveTo(CFSTR name, bool deleteDestBefore);
64 };
65 
66 class CTempDir
67 {
68   bool _mustBeDeleted;
69   FString _path;
70 public:
CTempDir()71   CTempDir(): _mustBeDeleted(false) {}
~CTempDir()72   ~CTempDir() { Remove();  }
GetPath()73   const FString &GetPath() const { return _path; }
DisableDeleting()74   void DisableDeleting() { _mustBeDeleted = false; }
75   bool Create(CFSTR namePrefix) ;
76   bool Remove();
77 };
78 
79 #if !defined(UNDER_CE)
80 class CCurrentDirRestorer
81 {
82   FString _path;
83 public:
84   bool NeedRestore;
85 
CCurrentDirRestorer()86   CCurrentDirRestorer(): NeedRestore(true)
87   {
88     GetCurrentDir(_path);
89   }
~CCurrentDirRestorer()90   ~CCurrentDirRestorer()
91   {
92     if (!NeedRestore)
93       return;
94     FString s;
95     if (GetCurrentDir(s))
96       if (s != _path)
97         SetCurrentDir(_path);
98   }
99 };
100 #endif
101 
102 }}}
103 
104 #endif
105