ADTF
builds/digitalwerk/solutions/adtf_content/adtf_base/adtf_core/src/libraries/a_utils/include/a_utils/core/filesystem.h
Go to the documentation of this file.
1 
7 #ifndef _FILESYSTEM_CLASS_HEADER_
8 #define _FILESYSTEM_CLASS_HEADER_
9 
10 namespace A_UTILS_NS
11 {
12 
18 class DOEXPORT cFileAttributes
19 {
20  public:
34 
36  typedef enum
37  {
38  #ifdef WIN32
39  // map to Win32 definitions
40  ATTRIBUTE_READONLY = 0x00000001,
41  ATTRIBUTE_FOLDER = 0x00000010,
42  ATTRIBUTE_HIDDEN = 0x00000002,
43  ATTRIBUTE_SYSTEM = 0x00000004,
44  ATTRIBUTE_ARCHIVE = 0x00000020,
45  ATTRIBUTE_COMPRESSED = 0x00000800,
46  ATTRIBUTE_ENCRYPTED = 0x00004000,
47  ATTRIBUTE_OFFLINE = 0x00001000,
48  #else
49  ATTRIBUTE_READONLY = 1,
50  ATTRIBUTE_FOLDER = 2,
51  ATTRIBUTE_HIDDEN = 4,
52  ATTRIBUTE_SYSTEM = 8,
53  ATTRIBUTE_ARCHIVE = 16,
54  ATTRIBUTE_COMPRESSED = 32,
55  ATTRIBUTE_ENCRYPTED = 64,
56  ATTRIBUTE_OFFLINE = 128,
57  #endif
58  ATTRIBUTE_SYMLINK = 256,
59  ATTRIBUTE_PIPE = 512,
60  ATTRIBUTE_BLOCKDEVICE = 1024,
61  ATTRIBUTE_CHARDEVICE = 2048,
62  ATTRIBUTE_INVALID = 0xFFFFFFFF
63  } FileAttributeFlag;
64 
70  {
71  Init();
72  }
73 
79  cFileAttributes(tUInt32 nAttributes)
80  {
81  Set(nAttributes);
82  }
83 
94  tBool Set(tUInt32 nAttributes)
95  {
96  if (nAttributes != ATTRIBUTE_INVALID)
97  {
98  bValid = true;
99  bReadOnly = ((nAttributes & ATTRIBUTE_READONLY) != 0);
100  bFolder = ((nAttributes & ATTRIBUTE_FOLDER) != 0);
101  bHidden = ((nAttributes & ATTRIBUTE_HIDDEN) != 0);
102  bSystem = ((nAttributes & ATTRIBUTE_SYSTEM) != 0);
103  bArchive = ((nAttributes & ATTRIBUTE_ARCHIVE) != 0);
104  bCompressed = ((nAttributes & ATTRIBUTE_COMPRESSED) != 0);
105  bEncrypted = ((nAttributes & ATTRIBUTE_ENCRYPTED) != 0);
106  bOffline = ((nAttributes & ATTRIBUTE_OFFLINE) != 0);
107  bSymLink = ((nAttributes & ATTRIBUTE_SYMLINK) != 0);
108  bPipe = ((nAttributes & ATTRIBUTE_PIPE) != 0);
109  bBlockDevice = ((nAttributes & ATTRIBUTE_BLOCKDEVICE) != 0);
110  bCharDevice = ((nAttributes & ATTRIBUTE_CHARDEVICE) != 0);
111 
112  return true;
113  }
114  else
115  {
116  Init();
117 
118  return false;
119  }
120  }
121 
132  tUInt32 GetAttributes(tUInt32& nAttributes) const
133  {
134  if (bValid)
135  {
136  nAttributes = 0;
137 
138  if (bReadOnly)
139  nAttributes |= ATTRIBUTE_READONLY;
140  if (bFolder)
141  nAttributes |= ATTRIBUTE_FOLDER;
142  if (bHidden)
143  nAttributes |= ATTRIBUTE_HIDDEN;
144  if (bSystem)
145  nAttributes |= ATTRIBUTE_SYSTEM;
146  if (bArchive)
147  nAttributes |= ATTRIBUTE_ARCHIVE;
148  if (bCompressed)
149  nAttributes |= ATTRIBUTE_COMPRESSED;
150  if (bEncrypted)
151  nAttributes |= ATTRIBUTE_ENCRYPTED;
152  if (bOffline)
153  nAttributes |= ATTRIBUTE_OFFLINE;
154  if (bSymLink)
155  nAttributes |= ATTRIBUTE_SYMLINK;
156  if (bPipe)
157  nAttributes |= ATTRIBUTE_PIPE;
158  if (bBlockDevice)
159  nAttributes |= ATTRIBUTE_BLOCKDEVICE;
160  if (bCharDevice)
161  nAttributes |= ATTRIBUTE_CHARDEVICE;
162 
163  return nAttributes;
164  }
165  else
166  {
167  return (tUInt32)ATTRIBUTE_INVALID;
168  }
169  }
170 
171  private:
172  void Init()
173  {
174  bValid = false;
175  bReadOnly = false;
176  bFolder = false;
177  bHidden = false;
178  bSystem = false;
179  bArchive = false;
180  bCompressed = false;
181  bEncrypted = false;
182  bOffline = false;
183  bSymLink = false;
184  bPipe = false;
185  bBlockDevice = false;
186  bCharDevice = false;
187  }
188 };
189 
195 class DOEXPORT cFileSystem
196 {
197  public:
198  enum
199  {
200  ED_DEFAULT = 0x0,
201  ED_FILES = 0x1,
202  ED_DIRECTORIES = 0x2
203  };
204 
209  typedef enum
210  {
211  PERM_USR_RD = 0x0400,
212  PERM_USR_WR = 0x0200,
213  PERM_USR_EX = 0x0100,
214 
215  PERM_GRP_RD = 0x0040,
216  PERM_GRP_WR = 0x0020,
217  PERM_GRP_EX = 0x0010,
218 
219  PERM_OTH_RD = 0x0004,
220  PERM_OTH_WR = 0x0002,
221  PERM_OTH_EX = 0x0001,
222 
223  PERM_SUID = 0x4000,
224  PERM_SGID = 0x2000,
225  PERM_SVTX = 0x1000
226  } FilePermissionFlag;
227 
228 
229  protected:
233 
234  public:
235 
247  static tUInt32 GetFileAttrib(const cFilename& strFilename);
248 
265  static tResult ReadTextFile(const cFilename& strFilename,
266  cString& strString,
267  const tUInt32& ui32OpenMode=cFile::OM_Read |
270 
283  static tResult WriteTextFile(const cFilename& strFilename, const cString& strString);
284 
296  static tBool Exists(const cFilename& strFilename);
297 
310  static tResult ExistsLongPathAware(const cFilename& strFilename);
311 
325  static tFileSize GetFileSize(const cFilename& strFilename);
326 
336  static tBool IsFile(const cFilename& strFilename);
337 
347  static tBool IsDirectory(const cFilename& strFilename);
348 
369  static tResult CreatePath(const cFilename& strDirName, tBool bRecursive = false);
370 
380  static tBool IsReadOnly(const cFilename& strFilename);
381 
394  static tResult SetReadOnly(const cFilename& strFilename, tBool bReadOnly = true);
395 
409  static tResult DelFile(const cFilename& strFilename);
410 
425  static tResult DelDirectory(const cFilename& strDirectory);
426 
437 
450  static tResult SetCurDirectory(const cFilename& strDirName);
451 
460 #ifdef WIN32
467  static cFilename GetWinDirectory();
468 
476  static tBool LongPathsEnabled();
477 #endif
486 
492 
536  static tResult FileCopy(const cString &strFrom,const cString &strTo);
537 
553  static tResult FolderCopy(const cFilename &strFrom,const cFilename &strTo);
554 
568  static tResult Move(const cFilename &strFrom,const cFilename &strTo);
569 
585  static tUInt32 GetFilePermissions(const cFilename& strFilename);
586 
605  static tResult SetFilePermissions(const cFilename& strFilename, tUInt32 nPermissionMask);
623  static tInt GetSectorSize(const cFilename& strFilename);
634  static tVoid* AllocPageAlignedMemory(tInt nSize, tInt nPageSize=0);
647 
663  static tResult EnumDirectory(const cFilename& strDir,
664  cStringList& lstFiles,
665  tUInt32 ui32Flags=0);
680  static tResult GetFreeDiskSpace(const tChar* strFolder, tUInt64 *pui64FreeBytes);
681 
712  static tResult FindFiles(const cString & strPattern, cStringList & lstFiles);
713 
726  static tResult FindFolders(const cString& strPattern, cStringList& lstFolders);
727 
741 
755 
769 
775 
788  static tResult RenameFilename(cFilename oldFileName, cFilename newFileName);
789 };
790 
791 } // namespace A_UTILS_NS
792 
793 #endif // _FILE_CLASS_HEADER_
char tChar
The tChar defines the type for platform character set (platform and compiler dependent type).
tInt64 tFileSize
type definition for a file or stream size value (platform and compiler independent type).
void tVoid
The tVoid is always the definition for the void (non-type).
int tInt
type definition for signed integer value (platform and compiler dependent type).
bool tBool
The tBool defines the type for the Values tTrue and tFalse (platform and compiler dependent).
uint32_t tUInt32
type definition for unsigned integer values (32bit) (platform and compiler independent type).
uint64_t tUInt64
type definition for unsigned integer values (64bit) (platform and compiler independent type).
@ OM_Read
Open existing file.
Definition: file.h:36
@ OM_SharedRead
Allows shared read access, use in addition to flags above.
Definition: file.h:52
@ OM_SequentialAccess
Optimized for sequential access, use in addition to flags above.
Definition: file.h:60
static cFilename GetSysDirectory()
Returns the system directory (e.g.
static tBool IsDirectory(const cFilename &strFilename)
This function checks if the specified filename points to a directory.
static tResult ReadTextFile(const cFilename &strFilename, cString &strString, const tUInt32 &ui32OpenMode=cFile::OM_Read|cFile::OM_SharedRead|cFile::OM_SequentialAccess)
This function reads a complete text file into a cString object.
static tResult WriteTextFile(const cFilename &strFilename, const cString &strString)
This function creates a text file from an existing cString object.
static tInt GetSectorSize(const cFilename &strFilename)
Get the sector size of the filesystem that a specified file resides on.
static tResult SetFilePermissions(const cFilename &strFilename, tUInt32 nPermissionMask)
Sets the permission set of a file.
static tResult DelFile(const cFilename &strFilename)
Deletes a File.
static tResult CreatePath(const cFilename &strDirName, tBool bRecursive=false)
This function creates a directory.
static tResult GetTimeCreation(const cFilename filename, A_UTILS_NS::cDateTime &dt)
This function returns the creation time of the file.
static tBool IsFile(const cFilename &strFilename)
This function checks if the specified filename points to a file.
static tResult FindFolders(const cString &strPattern, cStringList &lstFolders)
Searches for folders matching a specific pattern.
static tResult FileCopy(const cString &strFrom, const cString &strTo)
Copies a file to another location.
static tResult GetFreeDiskSpace(const tChar *strFolder, tUInt64 *pui64FreeBytes)
Returns the free diskspace on the media that the given path resides on.
static tInt GetLastErrorCode()
Gets the error code of the last failure.
static tBool Exists(const cFilename &strFilename)
This function checks if a file or directory exists.
static tVoid * AllocPageAlignedMemory(tInt nSize, tInt nPageSize=0)
Allocates memory that is page aligned.
static tResult FolderCopy(const cFilename &strFrom, const cFilename &strTo)
Copies a folder recursively to another location.
static tResult SetReadOnly(const cFilename &strFilename, tBool bReadOnly=true)
This function sets or removes the read-only flag for a file.
static tUInt32 GetFilePermissions(const cFilename &strFilename)
Returns the permission set of a file.
static tResult FindFiles(const cString &strPattern, cStringList &lstFiles)
Search for files matching a specific pattern.
static cFilename GetAppDirectory()
Returns the directory where the executable resides.
static tInt GetDefaultSectorSize()
Get the default sector size.
static tFileSize GetFileSize(const cFilename &strFilename)
This function gets the size of a file in bytes.
static tResult GetTimeAccess(const cFilename filename, A_UTILS_NS::cDateTime &dt)
This function returns the last access time of the file.
static tResult Move(const cFilename &strFrom, const cFilename &strTo)
Moves a folder or file.
static tResult RenameFilename(cFilename oldFileName, cFilename newFileName)
The rename function shall change the name of a file.
static cFilename GetOwnModuleDirectory()
For instance a DLL or shared library file is loaded within another application.
static cFilename GetCurDirectory()
Returns the current working directory.
static tResult GetTimeChange(const cFilename filename, A_UTILS_NS::cDateTime &dt)
This function returns the last change (write) time of the file.
static cFilename GetTempDirectory()
Returns the temp directory.
static tResult FreePageAlignedMemory(tVoid *pMemory)
Free memory that has been allocated using AllocPageAlignedMemory.
static tBool IsReadOnly(const cFilename &strFilename)
This function checks if a file is read-only.
static tResult EnumDirectory(const cFilename &strDir, cStringList &lstFiles, tUInt32 ui32Flags=0)
Lists all entries in a directory.
static tResult SetCurDirectory(const cFilename &strDirName)
Changes the current working directory.
static cFilename GetUserApplicationDirectory(const cString &strApplication=cString::Empty)
Returns the application data directory of the current user.
static cFilename GetOwnModuleFileName()
The filename of the module (DLL, so, executable) calling this method.
static tUInt32 GetFileAttrib(const cFilename &strFilename)
Get the file attributes of a specified file.
static tResult ExistsLongPathAware(const cFilename &strFilename)
This function checks if a file or directory exists.
static tResult DelDirectory(const cFilename &strDirectory)
Deletes a Directory.
File name class.
Definition: filename.h:59
static const _myType Empty
Internally used empty string.
Definition: string.h:54
ADTF A_UTIL Namespace - Within adtf this is used as adtf::util or adtf_util.
Definition: d_ptr.h:11