00001 /* 00002 * pdirect.h 00003 * 00004 * File system directory class. 00005 * 00006 * Portable Windows Library 00007 * 00008 * Copyright (c) 1993-1998 Equivalence Pty. Ltd. 00009 * 00010 * The contents of this file are subject to the Mozilla Public License 00011 * Version 1.0 (the "License"); you may not use this file except in 00012 * compliance with the License. You may obtain a copy of the License at 00013 * http://www.mozilla.org/MPL/ 00014 * 00015 * Software distributed under the License is distributed on an "AS IS" 00016 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 00017 * the License for the specific language governing rights and limitations 00018 * under the License. 00019 * 00020 * The Original Code is Portable Windows Library. 00021 * 00022 * The Initial Developer of the Original Code is Equivalence Pty. Ltd. 00023 * 00024 * Portions are Copyright (C) 1993 Free Software Foundation, Inc. 00025 * All Rights Reserved. 00026 * 00027 * Contributor(s): ______________________________________. 00028 * 00029 * $Log: pdirect.h,v $ 00030 * Revision 1.42 2004/09/17 03:51:15 csoutheren 00031 * More fixes for PDirectory problem 00032 * 00033 * Revision 1.42 2004/09/15 05:11:39 csoutheren 00034 * Fixed problem with PDirectory destructor not calling Close() 00035 * Thanks to Paul Long 00036 * 00037 * Revision 1.41 2003/09/17 05:41:58 csoutheren 00038 * Removed recursive includes 00039 * 00040 * Revision 1.40 2003/09/17 01:18:02 csoutheren 00041 * Removed recursive include file system and removed all references 00042 * to deprecated coooperative threading support 00043 * 00044 * Revision 1.39 2003/06/06 15:04:17 dsandras 00045 * 00046 * Fixed compilation warning with gcc 3.3 by removing the PINLINE 00047 * 00048 * Revision 1.38 2002/11/20 00:13:43 robertj 00049 * Fixed some documentation 00050 * 00051 * Revision 1.37 2002/11/19 12:07:02 robertj 00052 * Added function to get root directory. 00053 * 00054 * Revision 1.36 2002/11/19 10:34:59 robertj 00055 * Added function to extract a path as an array of directories components. 00056 * 00057 * Revision 1.35 2002/09/16 01:08:59 robertj 00058 * Added #define so can select if #pragma interface/implementation is used on 00059 * platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan. 00060 * 00061 * Revision 1.34 2001/05/22 12:49:32 robertj 00062 * Did some seriously wierd rewrite of platform headers to eliminate the 00063 * stupid GNU compiler warning about braces not matching. 00064 * 00065 * Revision 1.33 2001/02/13 06:55:21 robertj 00066 * Fixed problem with operator= in PDirectory class, part of larger change previously made. 00067 * 00068 * Revision 1.32 2000/06/26 11:17:19 robertj 00069 * Nucleus++ port (incomplete). 00070 * 00071 * Revision 1.31 2000/04/03 18:41:27 robertj 00072 * Fixed BeOS compatibility problem with openlog() function. 00073 * 00074 * Revision 1.30 1999/03/09 02:59:50 robertj 00075 * Changed comments to doc++ compatible documentation. 00076 * 00077 * Revision 1.29 1999/02/16 08:11:09 robertj 00078 * MSVC 6.0 compatibility changes. 00079 * 00080 * Revision 1.28 1998/09/23 06:21:06 robertj 00081 * Added open source copyright license. 00082 * 00083 * Revision 1.27 1998/03/05 12:44:34 robertj 00084 * Added cluster size. 00085 * 00086 * Revision 1.26 1997/03/31 11:34:00 robertj 00087 * Fixed default permissions for directories , different from that for files. 00088 * 00089 * Revision 1.25 1997/01/12 04:22:21 robertj 00090 * Added function to get disk size and free space. 00091 * 00092 * Revision 1.24 1995/12/23 03:45:31 robertj 00093 * Added constructor for C string literals. 00094 * 00095 * Revision 1.23 1995/11/09 12:17:23 robertj 00096 * Added platform independent base type access classes. 00097 * 00098 * Revision 1.22 1995/10/14 15:02:22 robertj 00099 * Added function to get parent directory. 00100 * 00101 * Revision 1.21 1995/06/17 11:12:52 robertj 00102 * Documentation update. 00103 * 00104 * Revision 1.20 1995/03/14 12:42:00 robertj 00105 * Updated documentation to use HTML codes. 00106 * 00107 * Revision 1.19 1995/03/12 04:42:48 robertj 00108 * Updated documentation. 00109 * Changed return type of functions to the correct case string. 00110 * 00111 * Revision 1.18 1995/02/22 10:50:33 robertj 00112 * Changes required for compiling release (optimised) version. 00113 * 00114 * Revision 1.17 1995/01/06 10:42:25 robertj 00115 * Moved identifiers into different scope. 00116 * Changed file size to 64 bit integer. 00117 * Documentation 00118 * 00119 * Revision 1.16 1994/10/24 00:07:03 robertj 00120 * Changed PFilePath and PDirectory so descends from either PString or 00121 * PCaselessString depending on the platform. 00122 * 00123 * Revision 1.15 1994/10/23 04:49:25 robertj 00124 * Chnaged PDirectory to descend of PString. 00125 * Added PDirectory Exists() function. 00126 * 00127 * Revision 1.14 1994/08/23 11:32:52 robertj 00128 * Oops 00129 * 00130 * Revision 1.13 1994/08/22 00:46:48 robertj 00131 * Added pragma fro GNU C++ compiler. 00132 * 00133 * Revision 1.12 1994/06/25 11:55:15 robertj 00134 * Unix version synchronisation. 00135 * 00136 * Revision 1.11 1994/04/20 12:17:44 robertj 00137 * Split name into PFilePath 00138 * 00139 * Revision 1.10 1994/04/11 14:16:27 robertj 00140 * Added function for determining if character is a valid directory separator. 00141 * 00142 * Revision 1.9 1994/04/01 14:14:57 robertj 00143 * Put platform independent file permissions and type codes back. 00144 * 00145 * Revision 1.7 1994/01/13 03:17:55 robertj 00146 * Added functions to get the name of the volume the directory is contained in 00147 * and a function to determine if the directory is a root directory of the 00148 * volume (ie is does not have a parent directory). 00149 * 00150 * Revision 1.6 1994/01/03 04:42:23 robertj 00151 * Mass changes to common container classes and interactors etc etc etc. 00152 * 00153 * Revision 1.5 1993/12/31 06:45:38 robertj 00154 * Made inlines optional for debugging purposes. 00155 * 00156 * Revision 1.4 1993/08/21 01:50:33 robertj 00157 * Made Clone() function optional, default will assert if called. 00158 * 00159 * Revision 1.3 1993/07/14 12:49:16 robertj 00160 * Fixed RCS keywords. 00161 * 00162 */ 00163 00164 00165 #ifndef _PDIRECTORY 00166 #define _PDIRECTORY 00167 00168 #ifdef P_USE_PRAGMA 00169 #pragma interface 00170 #endif 00171 00172 #ifdef Fifo 00173 #undef Fifo 00174 #endif 00175 00176 #ifdef _WIN32 00177 #define PDIR_SEPARATOR '\\' 00178 const PINDEX P_MAX_PATH = _MAX_PATH; 00179 typedef PCaselessString PFilePathString; 00180 #else 00181 #define PDIR_SEPARATOR '/' 00182 #define P_MAX_PATH (_POSIX_PATH_MAX) 00183 typedef PString PFilePathString; 00184 #endif 00185 00187 // File System 00188 00193 class PFileInfo : public PObject 00194 { 00195 PCLASSINFO(PFileInfo, PObject); 00196 00197 public: 00202 enum FileTypes { 00204 RegularFile = 1, 00206 SymbolicLink = 2, 00208 SubDirectory = 4, 00210 CharDevice = 8, 00212 BlockDevice = 16, 00214 Fifo = 32, 00216 SocketDevice = 64, 00218 UnknownFileType = 256, 00220 AllFiles = 0x1ff 00221 }; 00222 00224 FileTypes type; 00225 00229 PTime created; 00230 00232 PTime modified; 00233 00237 PTime accessed; 00238 00242 PUInt64 size; 00243 00245 enum Permissions { 00247 WorldExecute = 1, 00249 WorldWrite = 2, 00251 WorldRead = 4, 00253 GroupExecute = 8, 00255 GroupWrite = 16, 00257 GroupRead = 32, 00259 UserExecute = 64, 00261 UserWrite = 128, 00263 UserRead = 256, 00265 AllPermissions = 0x1ff, 00267 DefaultPerms = UserRead|UserWrite|GroupRead|WorldRead, 00269 DefaultDirPerms = DefaultPerms|UserExecute|GroupExecute|WorldExecute 00270 00271 }; 00272 00278 int permissions; 00279 00284 BOOL hidden; 00285 }; 00286 00287 00312 class PDirectory : public PFilePathString 00313 { 00314 PCONTAINERINFO(PDirectory, PFilePathString); 00315 00316 public: 00319 00320 PDirectory(); 00321 00326 PDirectory( 00327 const char * cpathname 00328 ); 00329 00334 PDirectory( 00335 const PString & pathname 00336 ); 00337 00340 PDirectory & operator=( 00341 const PString & pathname 00342 ); 00343 00346 PDirectory & operator=( 00347 const char * cpathname 00348 ); 00350 00360 PDirectory GetParent() const; 00361 00372 PFilePathString GetVolume() const; 00373 00379 BOOL IsRoot() const; 00380 00386 PDirectory GetRoot() const; 00387 00392 PStringArray GetPath() const; 00393 00400 PINLINE static BOOL IsSeparator( 00401 char ch 00402 ); 00403 00414 BOOL GetVolumeSpace( 00415 PInt64 & total, 00416 PInt64 & free, 00417 DWORD & clusterSize 00418 ) const; 00420 00428 BOOL Exists() const; 00429 00435 static BOOL Exists( 00436 const PString & path 00437 ); 00438 00444 BOOL Change() const; 00445 00451 static BOOL Change( 00452 const PString & path 00453 ); 00454 00460 BOOL Create( 00461 int perm = PFileInfo::DefaultDirPerms // Permission on new directory. 00462 ) const; 00468 static BOOL Create( 00469 const PString & p, 00470 int perm = PFileInfo::DefaultDirPerms 00471 ); 00472 00478 BOOL Remove(); 00479 00485 static BOOL Remove( 00486 const PString & path 00487 ); 00489 00507 virtual BOOL Open( 00508 int scanMask = PFileInfo::AllFiles 00509 ); 00510 00525 virtual BOOL Restart( 00526 int scanMask = PFileInfo::AllFiles 00527 ); 00528 00540 BOOL Next(); 00541 00543 virtual void Close(); 00544 00559 virtual PFilePathString GetEntryName() const; 00560 00570 virtual BOOL IsSubDir() const; 00571 00577 virtual BOOL GetInfo( 00578 PFileInfo & info 00579 ) const; 00581 00582 00583 protected: 00584 // New functions for class 00585 void Construct(); 00586 void Destruct() 00587 { Close(); PFilePathString::Destruct(); } 00588 00589 // Member variables 00591 int scanMask; 00592 00593 // Include platform dependent part of class 00594 #ifdef _WIN32 00595 #include "msos/ptlib/pdirect.h" 00596 #else 00597 #include "unix/ptlib/pdirect.h" 00598 #endif 00599 00600 }; 00601 00602 #endif 00603 00604 // End Of File ///////////////////////////////////////////////////////////////