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 bool CreateComplexDir(CFSTR path);
28 bool DeleteFileAlways(CFSTR name);
29 bool RemoveDirWithSubItems(const FString &path);
30 
31 bool MyGetFullPathName(CFSTR path, FString &resFullPath);
32 bool GetFullPathAndSplit(CFSTR path, FString &resDirPrefix, FString &resFileName);
33 bool GetOnlyDirPrefix(CFSTR path, FString &resDirPrefix);
34 
35 #ifndef UNDER_CE
36 
37 bool SetCurrentDir(CFSTR path);
38 bool GetCurrentDir(FString &resultPath);
39 
40 #endif
41 
42 bool MyGetTempPath(FString &resultPath);
43 
44 class CTempFile
45 {
46   bool _mustBeDeleted;
47   FString _path;
DisableDeleting()48   void DisableDeleting() { _mustBeDeleted = false; }
49 public:
CTempFile()50   CTempFile(): _mustBeDeleted(false) {}
~CTempFile()51   ~CTempFile() { Remove(); }
GetPath()52   const FString &GetPath() const { return _path; }
53   bool Create(CFSTR pathPrefix, NIO::COutFile *outFile); // pathPrefix is not folder prefix
54   bool CreateRandomInTempFolder(CFSTR namePrefix, NIO::COutFile *outFile);
55   bool Remove();
56   bool MoveTo(CFSTR name, bool deleteDestBefore);
57 };
58 
59 class CTempDir
60 {
61   bool _mustBeDeleted;
62   FString _path;
63 public:
CTempDir()64   CTempDir(): _mustBeDeleted(false) {}
~CTempDir()65   ~CTempDir() { Remove();  }
GetPath()66   const FString &GetPath() const { return _path; }
DisableDeleting()67   void DisableDeleting() { _mustBeDeleted = false; }
68   bool Create(CFSTR namePrefix) ;
69   bool Remove();
70 };
71 
72 #if !defined(UNDER_CE)
73 class CCurrentDirRestorer
74 {
75   FString _path;
76 public:
77   bool NeedRestore;
78 
CCurrentDirRestorer()79   CCurrentDirRestorer(): NeedRestore(true)
80   {
81     GetCurrentDir(_path);
82   }
~CCurrentDirRestorer()83   ~CCurrentDirRestorer()
84   {
85     if (!NeedRestore)
86       return;
87     FString s;
88     if (GetCurrentDir(s))
89       if (s != _path)
90         SetCurrentDir(_path);
91   }
92 };
93 #endif
94 
95 }}}
96 
97 #endif
98