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); 18bool SetFileAttrib(CFSTR path, DWORD attrib); 19bool MyMoveFile(CFSTR existFileName, CFSTR newFileName); 20 21#ifndef UNDER_CE 22bool MyCreateHardLink(CFSTR newFileName, CFSTR existFileName); 23#endif 24 25bool RemoveDir(CFSTR path); 26bool CreateDir(CFSTR path); 27bool CreateComplexDir(CFSTR path); 28bool DeleteFileAlways(CFSTR name); 29bool RemoveDirWithSubItems(const FString &path); 30 31bool MyGetFullPathName(CFSTR path, FString &resFullPath); 32bool GetFullPathAndSplit(CFSTR path, FString &resDirPrefix, FString &resFileName); 33bool GetOnlyDirPrefix(CFSTR path, FString &resDirPrefix); 34 35#ifndef UNDER_CE 36 37bool SetCurrentDir(CFSTR path); 38bool GetCurrentDir(FString &resultPath); 39 40#endif 41 42bool MyGetTempPath(FString &resultPath); 43 44class CTempFile 45{ 46 bool _mustBeDeleted; 47 FString _path; 48 void DisableDeleting() { _mustBeDeleted = false; } 49public: 50 CTempFile(): _mustBeDeleted(false) {} 51 ~CTempFile() { Remove(); } 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 59class CTempDir 60{ 61 bool _mustBeDeleted; 62 FString _path; 63public: 64 CTempDir(): _mustBeDeleted(false) {} 65 ~CTempDir() { Remove(); } 66 const FString &GetPath() const { return _path; } 67 void DisableDeleting() { _mustBeDeleted = false; } 68 bool Create(CFSTR namePrefix) ; 69 bool Remove(); 70}; 71 72#if !defined(UNDER_CE) 73class CCurrentDirRestorer 74{ 75 FString _path; 76public: 77 bool NeedRestore; 78 79 CCurrentDirRestorer(): NeedRestore(true) 80 { 81 GetCurrentDir(_path); 82 } 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