filepath.h

Go to the documentation of this file.
00001 /****
00002  * \file mi32/filepath.h
00003  * \brief Class FILEPATH - Handle filenames (directories and files) on supported platforms
00004  *
00005  * Definitions:
00006  *              
00007  * Name - The string after the last directory separator (SepMark).
00008  * Extn - The string after the 'Name' separated by the last extension separator (ExtnMark)
00009  * Path - The string representing the entire directory path up to 'Name'.
00010  *
00011  * Implementation notes:
00012  *
00013  * This class is not thread safe.  Most of the time the instance is specific to a 
00014  *    thread therefore the resource sharing issues are not involved.  If this class is
00015  *    a shared resource, it is up to the user of the class to guard it using the 
00016  *    appropriate locking method.
00017  *
00018  * \if NODOC
00019  * $Id: filepath.h_v 1.53 2004/10/15 16:07:36 dwilliss Exp $
00020  *
00021  * $Log: filepath.h_v $
00022  * Revision 1.53  2004/10/15 16:07:36  dwilliss
00023  * Added new PATHTYPE for logs
00024  *
00025  * Revision 1.52  2003/10/03 20:46:58  dwilliss
00026  * Changed static member from an MISTRING to a poitner to MISTRING.
00027  *
00028  * Revision 1.51  2003/09/15 13:49:56  fileserver!dwilliss
00029  * Doxygen
00030  *
00031  * Revision 1.50  2003/07/09 17:20:34  scowan
00032  * Removed mac 9 stuff and methods that are not used.
00033  *
00034  * Revision 1.49  2003/07/03 20:35:41  scowan
00035  * Removed mac native code.
00036  *
00037  * Revision 1.48  2003/06/18 19:31:35  scowan
00038  * Added convert name static method.
00039  *
00040  * Revision 1.47  2003/05/19 15:43:30  mju
00041  * Add pathtype_InstallationFolder.
00042  * Remove deprecated pathtype value.
00043  *
00044  * Revision 1.46  2003/05/16 17:50:54  mju
00045  * Add PATHTYPE_Settings values.
00046  *
00047  * Revision 1.45  2003/05/15 14:30:21  mju
00048  * Rename PATHTYPE_Documents enums.
00049  *
00050  * Revision 1.44  2003/02/25 22:48:57  mju
00051  * Make PATHTYPE names consistent and more complete and eliminate obsolete ones.
00052  *
00053  * Revision 1.43  2003/02/17 21:05:00  scowan
00054  * Added new path types.
00055  *
00056  * Revision 1.42  2003/02/13 23:22:52  scowan
00057  * Added static method.
00058  *
00059  * Revision 1.41  2002/11/20 16:39:40  mju
00060  * Add PATHTYPE_MicroImages.
00061  *
00062  * Revision 1.40  2002/09/09 16:05:28  mju
00063  * nc.
00064  *
00065  * Revision 1.39  2002/09/04 21:46:37  dwilliss
00066  * Just a see also on GetOSPath()
00067  *
00068  * Revision 1.38  2002/08/27 13:55:59  scowan
00069  * Allow set mac file type for osx.
00070  *
00071  * Revision 1.37  2002/08/21 15:52:38  scowan
00072  * Minor changes.
00073  *
00074  * Revision 1.36  2002/07/03 22:10:01  dwilliss
00075  * Work around stupid Mac problem with struct tm sometimes being std::tm
00076  *
00077  * Revision 1.35  2002/06/28 17:03:29  dwilliss
00078  * Damn Mac!  Can't get it to stop doing a "using std::tm"
00079  *
00080  * Revision 1.32  2002/06/17 14:24:50  mju
00081  * Remove 'struct' from use of 'tm' as not needed to hopefully fix MacOS9.
00082  *
00083  * Revision 1.30  2002/06/07 15:30:16  scowan
00084  * Added method to get encoded char poath.
00085  *
00086  * Revision 1.28  2002/03/27 17:04:38  mju
00087  * Add operator<< to put filepath 'display string' into MISTRING.
00088  *
00089  * Revision 1.27  2002/03/18 16:32:43  scowan
00090  * Added assign method.
00091  *
00092  * Revision 1.26  2002/01/16 18:13:39  scowan
00093  * Do stupid thing for MAC.
00094  *
00095  * Revision 1.25  2002/01/14 17:50:00  scowan
00096  * Limit use of set module filename to UNIX only.
00097  *
00098  * Revision 1.24  2002/01/14 16:29:45  scowan
00099  * Added strip to folder.
00100  *
00101  * Revision 1.23  2001/12/06 17:43:04  scowan
00102  * Added generate temp file method.
00103  *
00104  * Revision 1.22  2001/08/03 21:05:14  mju
00105  * Add GetQuotedPath implementing old GetOSPath() behavior.
00106  *
00107  * Revision 1.21  2001/05/03 19:43:28  scowan
00108  * Added Haschildren method().
00109  *
00110  * Revision 1.20  2001/03/14 15:23:48  scowan
00111  * Added set osd path for windows.
00112  *
00113  * Revision 1.18  2000/09/21 19:33:44  scowan
00114  * Added is same extn methods.
00115  *
00116  * Revision 1.16  2000/08/09 16:48:40  scowan
00117  * Updated relative path code.
00118  *
00119  * Revision 1.15  2000/08/08 13:39:10  mju
00120  * Don't have Genitor document "removed" and unimplemented methods.
00121  *
00122  * Revision 1.14  2000/07/19 16:13:10  scowan
00123  * Make cosnt versions of Get Relative Path and comment out old versions.
00124  *
00125  * Revision 1.13  2000/07/11 17:34:41  mju
00126  * Need to undef CLASSLIBEXPORT at end.
00127  *
00128  * Revision 1.12  2000/07/06 17:53:40  mju
00129  * Add IsFile and IsFolder methods.
00130  *
00131  * Revision 1.11  2000/06/13 14:20:48  mju
00132  * Use inclusion guards.
00133  *
00134  * \endif
00135 ****/
00136 
00137 #ifndef  INC_MI32_FILEPATH_H
00138 #define  INC_MI32_FILEPATH_H
00139 
00140 #ifndef  INC_MI32_STDDEFNS_H
00141 #include <mi32/stddefns.h>
00142 #endif
00143 
00144 #ifndef  INC_MI32_UCSTRING_H
00145 #include <mi32/ucstring.h>
00146 #endif
00147 
00148 #ifndef  INC_MI32_MISTRING_H
00149 #include <mi32/mistring.h>
00150 #endif
00151 
00152 #ifndef  INC_TIME_H
00153 #include <time.h>
00154 #define  INC_TIME_H
00155 #endif
00156 
00157 #ifdef MISYSTEMDLL
00158    #define CLASSLIBEXPORT MI_DLLCLASSEXPORT
00159 #else
00160    #define CLASSLIBEXPORT MI_DLLCLASSIMPORT
00161 #endif
00162 
00163 #ifndef GENERATING_DOXYGEN_OUTPUT
00164 class FILE_RAW;         // Forward declaration
00165 #endif // GENERATING_DOXYGEN_OUTPUT
00166 
00167 //! System file and directory services class.
00168 class CLASSLIBEXPORT FILEPATH {     
00169    public:
00170 
00171       typedef ERRVALUE (*StatusCallback)(INT64 FileSize, INT64 BytesLeft, void *udata);
00172 
00173       //! Possible file permissions to set or check for.
00174       enum PERMISSION {                   
00175          PERMISSION_Invalid = 0,
00176          PERMISSION_Exists = 1,
00177          PERMISSION_Read = 2,
00178          PERMISSION_Write = 3,
00179          PERMISSION_ReadWrite = 4,
00180          PERMISSION_Execute = 5
00181          };
00182 
00183       //! File system types as can be determined.
00184       enum FILESYSTYPE {                  
00185          FILESYSTYPE_Unknown,
00186          FILESYSTYPE_NoRootDir,           //!< Win32
00187          FILESYSTYPE_Removable,           //!< Zip, Jaz, ...
00188          FILESYSTYPE_Fixed,
00189          FILESYSTYPE_Network,
00190          FILESYSTYPE_CDROM,               //!< Read only file systems
00191          FILESYSTYPE_RamDisk,
00192          FILESYSTYPE_Tape,
00193          FILESYSTYPE_URL
00194          };
00195 
00196       //! Common file path types.
00197       enum PATHTYPE {
00198          PATHTYPE_Current = 0,                     //!< Current system path, usually same as installation folder
00199          PATHTYPE_Home = 1,                        //!< Users home directory if it exists
00200          PATHTYPE_ExecutableFile = 2,              //!< Path to the executable file
00201          PATHTYPE_Desktop = 3,
00202          PATHTYPE_Font = 4,
00203          #if defined(WIN32)
00204             PATHTYPE_Windows = 5,                  //!< Windows install path location
00205             PATHTYPE_WindowsSystem = 6,            //!< Windows system path location
00206          #endif
00207          PATHTYPE_InstallationFolder = 7,          //!< Folder where product is "installed"
00208          PATHTYPE_ExecutableFolder = 8,            //!< Folder containing current process executable
00209          PATHTYPE_Documents_AllUsers = 9,          //!< All-users "Documents" folder
00210          PATHTYPE_MicroImages_Shared = 10,         //!< Shared "MicroImages" folder
00211          PATHTYPE_Documents_CurrentUser = 11,      //!< Current-user "Documents" folder
00212          PATHTYPE_MicroImages_User = 12,           //!< Current-user "MicroImages" folder
00213          PATHTYPE_Settings_CurInst_CurUser = 13,   //!< Settings for current 'installation', current user
00214          PATHTYPE_Settings_CurInst_AllUsers = 14,  //!< Settings for current 'installation', all users
00215          PATHTYPE_Settings_AllInst_CurUser = 15,   //!< Settings for all 'installations', current user
00216          PATHTYPE_Settings_AllInst_AllUsers = 16,  //!< Settings for all 'installations', all users
00217          PATHTYPE_MicroImages_Logs = 17,           //!< Place to put log files (same as MicroImages_User except on Macs where it's (HOME)/Logs/MicroImages
00218          };
00219 
00220       //! Type of children to select in GetChildren calls.
00221       enum CHILDTYPE {                    
00222          CHILDTYPE_Directory = 1,
00223          CHILDTYPE_File
00224          };
00225 
00226       //! Convert component OS filename passed in to a displayable filename.
00227       //! Only has an effect on MAC_OSX where the colon ':' is transposed to a slash '/' when displaying       
00228       static MISTRING ConvertNameToDisplay (
00229          const MISTRING& name
00230          );
00231 
00232       //! Determine list of drives / volumes for this OS.
00233       static int GetDriveList (           
00234          MISTRINGLIST& DriveList
00235          );
00236 
00237       //! Get an environment variable as a path (or paths) and convert using the correct OS encoding
00238       static bool GetEnvPath (            
00239          const char *name,
00240          MISTRING& EnvPathStr
00241          );
00242          
00243    #if 0
00244       #ifndef GENERATING_DOXYGEN_OUTPUT
00245       //! Get maximum amount of characters allowed for an operating system's path segment.
00246       //! @return The operating system's limit for a path segment / filename.
00247       static UINT32 GetNameSizeLimit (    
00248          );
00249 
00250       //! Get maximum amount of characters allowed for an operating system's full path.
00251       //!
00252       //! @return The operating system's limit for a full path.
00253       static UINT32 GetPathSizeLimit (    
00254          );
00255       #endif //!< GENERATING_DOXYGEN_OUTPUT
00256    #endif
00257 
00258       //! Is the string given specify a relative path.
00259       //! A string is considered a relative path if:
00260       //!   1.  The string is empty or the string == "."
00261       //!   2.  The string starts with a relative path indicator specific for the platform
00262       //!      On all but the MAC, the string can start with either the same directory relative path
00263       //!      or the parent directory relative path.  The MAC does not have a current directory 
00264       //!      relative path.
00265       //!
00266       //!   Example:
00267       //!      if (FILEPATH::IsRelativePath(RelStr)) {
00268       //!         FilePath = BasePath;    // Assign base path to dest
00269       //!         FilePath += RelStr;        // Concatinate relative path onto dest
00270       //!         }
00271       //!      else {
00272       //!         FilePath = RelStr;         // Full path, assign to dest
00273       //!         }
00274       //!
00275       //! @return 'true' if path is a relative path, false if not
00276       static bool IsRelativePath (
00277          const UNICODE *path              //!< String to determine if a relative path
00278          );
00279 
00280       #if !defined(WIN32)
00281       //! Set application executable name so that PATHTYPE_Executable for SetSystemPath() can work.
00282       //! For UNIX systems only!
00283       static void SetModuleFileName (
00284          const char *name,                //!< Name of executable (argv[0] for most systems)
00285          CHAR_ENCODING encoding           //!< String encoding (CHAR_ENCODING_ASCII for most systems)
00286          );
00287       #endif
00288 
00289       //! Default constructor, empty path.
00290       FILEPATH (                       
00291          );
00292 
00293       //! Copy constructor.
00294       FILEPATH (                       
00295          const FILEPATH& p
00296          );
00297 
00298       //! Concatenation constructor, 'dir' must be a directory.
00299       FILEPATH (                       
00300          const FILEPATH& dir,
00301          const MISTRING& name
00302          );
00303 
00304       //! Concatenation constructor, 'dir' must be a directory.
00305       FILEPATH (                       
00306          const FILEPATH& dir,
00307          const UNICODE *name
00308          );
00309 
00310       //! Concatenation constructor, 'dir' must be a directory.
00311       FILEPATH (                       
00312          const FILEPATH& dir,
00313          const char *name,
00314          CHAR_ENCODING encoding = CHAR_ENCODING_ASCII
00315          );
00316 
00317       //! Constructor, inialize with a system path.
00318       explicit FILEPATH (                 
00319          PATHTYPE type
00320          );
00321 
00322       //! Constructor, initialize with MISTRING.
00323       explicit FILEPATH (                 
00324          const MISTRING& p
00325          );
00326 
00327       //! Constructor, initialize with UNICODE*, for compatibility.
00328       FILEPATH (                       
00329          const UNICODE *p
00330          );
00331 
00332       //! Constructor, initialize with C string, for efficiency.
00333       explicit FILEPATH (                 
00334          const char *p,
00335          CHAR_ENCODING encoding = CHAR_ENCODING_ASCII
00336          );
00337 
00338       //! Initialize a FILEPATH with an entry from an INI file.
00339       FILEPATH (                          
00340          void *IniHandle,                 //!< Handle to INI file to read from, 0 for default file "tntproc.ini"
00341          const char *group,               //!< INI group to read path from
00342          const char *field                //!< INI field to read path from
00343          );
00344 
00345       //! Destructor.
00346       ~FILEPATH (                         
00347          );
00348 
00349       //! Assignment operator.
00350       FILEPATH& operator= (               
00351          const FILEPATH& q
00352          );
00353 
00354       //! Assignment from MISTRING.
00355       FILEPATH& operator= (               
00356          const MISTRING& q
00357          );
00358 
00359       //! Assignment from UNICODE*.
00360       FILEPATH& operator= (               
00361          const UNICODE* q
00362          );
00363 
00364       //! Concatenate from MISTRING, adding separator.
00365       FILEPATH& operator+= (              
00366          const MISTRING& q
00367          );
00368 
00369       //! Concatenate from UNICODE*, adding separator.
00370       FILEPATH& operator+= (              
00371          const UNICODE* q
00372          );
00373 
00374       //! Concatenate from C string, for efficiency.
00375       FILEPATH& operator+= (              
00376          const char *q                    //!< ASCII encoded string
00377          );
00378 
00379       //! Append a string to FILEPATH, adding separator.
00380       FILEPATH& Append (                  
00381          const char *q,                   //!< String to append with
00382          CHAR_ENCODING encoding           //!< Encoding of the string
00383          );
00384 
00385       //! Assign a character string representation of a path to FILEPATH using the character encoding.
00386       //! @return Reference to 'this'
00387       FILEPATH& Assign (
00388          const char *p,
00389          CHAR_ENCODING encoding = CHAR_ENCODING_ASCII
00390          );
00391          
00392       //! Check access permissions on the file / directory. 
00393       //! @return 0 if access permitted, < 0 if error or EFileNotFound
00394       ERRVALUE CheckAccess (
00395          const PERMISSION perm = PERMISSION_Read      //!< Access permission to check for
00396          ) const;
00397 
00398       //! Clear the path representation.  
00399       void Clear (                     
00400          );
00401 
00402       //! Check if path contains "subpath" given.
00403       bool Contains (                     
00404          const FILEPATH& SubPath          //!< Subpath to check against
00405          ) const;
00406 
00407       //! Copy contents from SourcePath.
00408       ERRVALUE CopyFileFrom (             
00409          const FILEPATH& SourcePath,      //!< Source file to ccopy from
00410          StatusCallback StatusCB = 0,     //!< Callback to report file copy status
00411          void *udata = 0                  //!< Callback data passed to status callback
00412          ) const;
00413 
00414       //! Check if file exists.
00415       bool Exists (                    
00416          ) const;
00417 
00418       //! Generate a temp file given a basepath and a basename for the temp file
00419       //! Called by FILEFIND::MakeTempFile()
00420       ERRVALUE GenerateTempFile (
00421          const FILEPATH& BasePath,
00422          const MISTRING& Basename
00423          );
00424          
00425       //! Generate Operating system specific path with the proper encoding for character based IO calls.
00426       //! Use this method to call functions that take a path ONLY if nothing else can be done and it is 
00427       //! a third party library.  It is not known if the third party library can handle the multiple 
00428       //! encodings if they manipulate the path.
00429       //! @return Encoded OS filepath, Caller MUST free.
00430       char* GenerateEncodedOSPath (
00431          ) const;
00432 
00433       //! Returns the amount of free space on the volume that the path represents.
00434       INT64 GetAvailableSpace (           
00435          ) const;
00436 
00437       //! Obtain a list of child directories or files that exist under this path.
00438       //! @return Number of children found.
00439       int GetChildren (
00440          MISTRINGLIST& ChildList,         //!< List of child names found after search
00441          CHILDTYPE ChildType              //!< Type of children to search for CHILDTYPE_Directory or CHILDTYPE_File.
00442          ) const;
00443       
00444       //! Obtain a list of child directories or files that exist under this path using a pattern to select which children to find.
00445       //! @return Number of children found.
00446       int GetChildren (
00447          MISTRINGLIST& ChildList,         //!< List of child names found after search
00448          const MISTRING& pattern,         //!< Pattern to match
00449          CHILDTYPE ChildType              //!< Type of children to search for CHILDTYPE_Directory or CHILDTYPE_File.
00450          ) const;
00451 
00452       //! Separate path into individual components, returns number of components.
00453       int GetComponents (
00454          MISTRINGLIST& CompList           //!< List of components RETURNED
00455          ) const;
00456 
00457       //! Get the display string representation for the path.
00458       //!
00459       //! Used to get a string that is to be displayed to the end user.
00460       MISTRING GetDisplay (
00461          ) const;
00462 
00463       //! Get the encoded string representation for the path.
00464       //!
00465       //! Used to get a string that is to be saved to a database / file for later retrieval.
00466       //! The encoding is used in the case of file transfer to different system types, 
00467       //! Eg UNIX -> WIN32 or MAC -> WIN32 or any other combination.
00468       MISTRING GetEncoded (
00469          ) const;
00470 
00471       //! Get the file name extension, without the extension marker.  
00472       //!
00473       //! The extension is considered to be the string after the last extension marker.
00474       //! Eg. in "test.rvc.txt", 'txt' would be the extension returned.
00475       MISTRING GetExtension (
00476          ) const;
00477 
00478       //! Get type of system drive the path represents.
00479       //! @return Type of system drive the path represents.
00480       FILESYSTYPE GetFileSysType (     
00481          ) const;
00482 
00483    #if defined(MAC_OSX)
00484       //! Obtain the Macintosh Creator and type fields based on the file extension.
00485       ERRVALUE GetMacFileType (       
00486          char *creator, 
00487          char *type
00488          ) const;
00489    #endif
00490       
00491       //! Get the Mio...() encoded string representation for the path.
00492       //! Used in legacy code where the function requires a const UNICODE* string.
00493       MISTRING GetMioPath (
00494          ) const;
00495 
00496       //! Get the last component name (file or folder) with extension (if exists).
00497       //! @return Last component name
00498       MISTRING GetName (                  
00499          ) const;
00500 
00501       //! Get the file name only, no extension, unless directory.
00502       //! A directory is not considered to have an extension, therefore if this path
00503       //! represents a directory, the name with extension is returned.
00504       MISTRING GetNameOnly (
00505          ) const;
00506 
00507       //! Get the OS string representation for the path.
00508       //! Used to generate valid path string for use in OS-specific file I/O functions.
00509       //! Does not insert quotes around components containing spaces.
00510       //! Note, you probably really want GenerateEncodedOSPath() which will
00511       //! convert the filename to the character encoding of the file system
00512       //! @see GetQuotedPath, GenerateEncodedOSPath
00513       MISTRING GetOSPath (
00514          ) const;
00515 
00516       //! Get the path representation only.
00517       FILEPATH GetPathOnly (              
00518          ) const;
00519 
00520       //! Get access permissions on the file / directory.
00521       PERMISSION GetPermission (         
00522          ) const;
00523 
00524       //! Get path with quotes inserted around components containing spaces.
00525       //! Used to generate a valid string to use command lines.
00526       //! @see GetOSPath
00527       MISTRING GetQuotedPath (
00528          ) const;
00529 
00530       //! Generate an encoded relative path from a source path.
00531       //! The string returned will be one of three types:
00532       //!   1. A string == ".", the current path and the source path are equal
00533       //!   2. An encoded string from GetEncoded() method, the two paths are completely unrelated
00534       //!   3. An encoded string with the relative path.
00535       //!
00536       //! See also IsRelativePath().   
00537       //!
00538       //! @return Relative path string
00539       MISTRING GetRelativePath (          
00540          const FILEPATH& BasePath      //!< Base path which the instance is compared to and the relative path is generated against
00541          ) const;
00542 
00543       //! Generate an encoded relative path from a system default path.
00544       //!
00545       //! @return Relative path string, see other GetRelativePath() for complete docs
00546       MISTRING GetRelativePath (
00547          const PATHTYPE ft = PATHTYPE_Current
00548          ) const;
00549 
00550       //! Return size of the file.
00551       INT64 GetSize (                     
00552          ) const;
00553 
00554       //! Return maximum size of a file on the drive represented.
00555       INT64 GetSystemMaxSize (            
00556          ) const;
00557 
00558       //! Get the creation time for the file.
00559       ERRVALUE GetTimeCreated (           
00560          time_t *rettime                  //!< UTC time
00561          ) const;
00562 
00563       //! Get the modification time for the file.
00564       ERRVALUE GetTimeModified (          
00565          time_t *rettime                  //!< UTC time
00566          ) const;
00567 
00568       //! Does the path have children of a specific type?
00569       //! @return "True' if children of the correct type found
00570       bool HasChildren (
00571          CHILDTYPE ChildType              //!< Type of children to search for CHILDTYPE_Directory or CHILDTYPE_File.
00572          ) const;
00573       
00574       //! Does the Name part of the path have an extension?
00575       bool HasExtension (                 
00576          ) const;
00577 
00578       //! Initialize a FILEPATH with an entry from an INI file.
00579       //! @return 'true' if the entry exists.
00580       bool IniRead (                   
00581          void *IniHandle,                 //!< Handle to INI file to read from, 0 for default file "tntproc.ini"
00582          const char *group,               //!< INI group to read path from
00583          const char *field                //!< INI field to read path from
00584          );
00585 
00586       //! Write encoded filepath to .ini file.
00587       void IniWrite (                     
00588          void *IniHandle,                 //!< Handle to INI file to write to, 0 for default file "tntproc.ini"
00589          const char *group,               //!< INI group to write encoded path to
00590          const char *field                //!< INI field to write encoded path to
00591          ) const;
00592 
00593       //! Is the path a child path of 'BasePath'
00594       bool IsChildPath (
00595          const FILEPATH& BasePath
00596          ) const;
00597       
00598       //! Is FILEPATH empty?
00599       bool IsEmpty (                   
00600          ) const;
00601 
00602       //! Are the paths equal?
00603       //!
00604       //! Case insensitive check for WIN32, MAC.
00605       bool IsEqual (                     
00606          const FILEPATH& TestPath
00607          ) const;
00608 
00609       //! Is FILEPATH an existing file?
00610       bool IsFile (
00611          ) const;
00612 
00613       //! Is FILEPATH an existing folder (directory)?
00614       bool IsFolder (
00615          ) const;
00616 
00617       //! Is "this" less than testpath?
00618       //!
00619       //! Case insensitive check for WIN32, MAC.
00620       bool IsLessThan (                  
00621          const FILEPATH& TestPath
00622          ) const;
00623 
00624       //! Is the file referenced a directory?
00625       //!
00626       //! A non-existant path is a directory.
00627       bool IsPathOnly (                  
00628          ) const;
00629 
00630       //! Is the path / file readable?
00631       bool IsReadable (                
00632          ) const;
00633 
00634       //! Is the path a root path?
00635       bool IsRootOnly (                
00636          ) const;
00637 
00638       //! Does the filepath have the same extension as that passed in
00639       //! This method is used to speed up extension checking without creating one or two MISTRINGs
00640       //! This method uses no-case comparisons
00641       //! @return True if extensions match or if path has no extension and '0' or "" is passed for 'extn'
00642       bool IsSameExtn (
00643          const char *extn        //!< Do not prepend extension marker '.'
00644          ) const;
00645 
00646       //! Does the filepath have the same extension as that passed in
00647       //! This method is used to speed up extension checking without creating one or two MISTRINGs
00648       //! This method uses no-case comparisons
00649       //! @return True if extensions match or if path has no extension and '0' or "" is passed for 'extn'
00650       bool IsSameExtn (
00651          const MISTRING& extn       //!< Do not prepend extension marker '.'
00652          ) const;
00653 
00654       // Note: back slashes in the comment below are doubled up for Doxygen
00655       //! Is the path a UNC host path only? (\\\\Machine).
00656       bool IsUNCHostOnly (             
00657          ) const;
00658 
00659       // Note: back slashes in the comment below are doubled up for Doxygen
00660       //! Is the path a UNC root path? (\\\\Machine\\share).
00661       bool IsUNCRoot (                 
00662          ) const;
00663 
00664       //! Is the path / file writable?
00665       //!
00666       //! (Writable is correct spelling).
00667       bool IsWritable (                   
00668          ) const;
00669 
00670       //! Creates a path, returns 0 if path was created or existed, < 0 if error. 
00671       //!
00672       //! If true, will create all non-existant directories listed in its path.
00673       ERRVALUE Make (                     
00674          bool MakeTree = false              
00675          ) const;
00676 
00677       //! Remove a file from the system, does not remove directories.
00678       ERRVALUE Remove (                
00679          ) const;
00680 
00681       //! Rename an existing file with a new name, FILEPATH changed after sucessful operation.
00682       ERRVALUE Rename (                
00683          const MISTRING& newname          //!< Name to change to
00684          );                                  
00685 
00686       //! Rename an existing file with a new name extracted from 'newname', FILEPATH not changed.
00687       ERRVALUE Rename (
00688          const FILEPATH& newname          //!< Name to change to, path is ignored
00689          ) const;
00690 
00691       //! Replace root of the path with a new root.
00692       FILEPATH& ReplaceRoot (             
00693          const FILEPATH& SourcePath       //!< Path that contains new root path
00694          );
00695 
00696       //! Search for file by changing path case incrementally.
00697       //! @return "true" if found and FILEPATH will be modified.
00698       bool SearchCase (
00699          );
00700 
00701       //! Search path for file using reference path iteratively.
00702       //! @return "true" if found and FILEPATH will be modified.
00703       bool SearchIterative (
00704          const FILEPATH& RefPath
00705          );
00706 
00707       //! Set extension of the path.
00708       FILEPATH& SetExtension (            
00709          const MISTRING& extn
00710          );
00711 
00712       //! Set extension of the path.
00713       FILEPATH& SetExtension (            
00714          const char* extn,
00715          CHAR_ENCODING encoding = CHAR_ENCODING_ASCII
00716          );
00717          
00718    #if defined(MAC_OSX)
00719       //! Set Macintosh file type based on creator and type fields.
00720       ERRVALUE SetMacFileType (        
00721          const char *creator, 
00722          const char *type
00723          ) const;
00724    #endif
00725 
00726       //! Replace FILEPATH name.
00727       FILEPATH& SetName (                 
00728          const MISTRING& name
00729          );
00730 
00731       //! Replace FILEPATH name, overloaded for efficiency.
00732       FILEPATH& SetName (                
00733          const char* name,
00734          CHAR_ENCODING encoding = CHAR_ENCODING_ASCII
00735          );
00736 
00737    #if defined(WIN32)
00738       //! Set the path from the OS string representation
00739       //!
00740       //! Used to set the path from a OS specific function
00741       void SetOSPath (
00742          const char* path
00743          );
00744 
00745       //! Set the path from the OS string representation
00746       //!
00747       //! Used to set the path from a OS specific function
00748       void SetOSPath (
00749          const UNICODE* path
00750          );
00751    #endif
00752 
00753       //! Set access permissions on the file / directory.
00754       ERRVALUE SetPermission (
00755          PERMISSION perm                  //!< Permission to set file / directory to
00756          ) const;
00757 
00758       //! Sets FILEPATH to a system path.
00759       void SetSystemPath (
00760          PATHTYPE pt                      //!< System path to set FILEPATH to
00761          );
00762 
00763       //! Change creation time for a file, if possible.
00764       ERRVALUE SetTimeCreated (
00765          const tm*const timeval     //!< UTC based time value
00766          ) const;
00767 
00768       //! Change creation time for a file, if possible.
00769       ERRVALUE SetTimeCreated (
00770          time_t value                     //!< UTC based time value
00771          ) const;
00772 
00773       //! Change modification time for a file, if possible.
00774       ERRVALUE SetTimeModified (
00775          const tm*const timeval     //!< UTC based time value
00776          ) const;
00777 
00778       //! Change modification time for a file, if possible.
00779       ERRVALUE SetTimeModified (
00780          time_t value                     //!< UTC based time value
00781          ) const;
00782 
00783       //! Strips the extension, if it exists, off of Name.
00784       FILEPATH& StripExtension (
00785          );
00786 
00787       //! Strips the last component off of the path.
00788       FILEPATH& StripLastComponent (
00789          );
00790 
00791       //! Strips off components until the remaining path exists.
00792       FILEPATH& StripToExisting (
00793          );
00794 
00795       //! Strips off components until the remaining folder path exists.
00796       FILEPATH& StripToFolder (
00797          );
00798 
00799       //! Strips everything off except the root path.
00800       FILEPATH& StripToRoot (
00801          );
00802 
00803    private:
00804       #ifndef GENERATING_DOXYGEN_OUTPUT
00805 
00806       void AppendPath (const MISTRING& name);      //! Appends name to the end of the FILEPATH
00807       ERRVALUE GenerateErrorCode (ERRVALUE DftErrCode) const;        //!< Generate a MicroImages error code based on system error code
00808       char *GenerateOSPath () const;      //!< Generate Operating system specific path
00809       int GetExtnPosn () const;           //!< Returns the position of the extn marker
00810       int GetRootEndPosn () const;        //!< Return position of end of the root path
00811       void GetWindowsFolderPath (int folder);
00812       void JoinRelativePath (const MISTRING& str);             //! Join relative path to stored path
00813       ERRVALUE MakePath () const;         //!< Creates a path using the end path name
00814 
00815       MISTRING *m_path;                   //!< Allocated pointer to the string that holds the path
00816 
00817       static const UNICODE s_ExtnMark;    //!< System extension marker (.)
00818       static const UNICODE s_SepMark;     //!< System path separator marker (\\, /, :)
00819       static const UNICODE s_RelMark;     //!< System path relative marker (., :, .)
00820       static const char *s_BackTagStr;    //!< System directory backup string (..\\, ../, :)
00821       static const char *s_SameDirStr;    //!< System directory same directory string (.\\, ./, Invalid for the MAC)
00822       static const char *s_EncodeStr;     //!< Encode system marker
00823       static MISTRING *s_argv0;           //!< Internal module path stored for SetSystemPath()
00824       
00825       friend class FILE_RAW;              //!< To give FILE_RAW access to GenerateOSPath()
00826 
00827       CHECKSIZE(sizeof(void*));
00828       #endif // GENERATING_DOXYGEN_OUTPUT
00829    };
00830 
00831 DEFINE_ENUM_OPERATORS(FILEPATH::PERMISSION)
00832 
00833 #if defined(WIN32)
00834 #if !defined(MISYSTEMDLL) && !defined(NODLLLINKAGE)
00835 #pragma warning(disable:4231)          /* the extern before template is a non-standard extension */
00836 
00837 extern template class CLASSLIBEXPORT MILIST<FILEPATH>;      //! Template instantiation
00838 
00839 #pragma warning(default:4231)          /* restore previous warning */
00840 #endif      // _DLL
00841 #endif      // WIN32
00842 
00843 typedef MILIST<FILEPATH>   FILEPATHLIST;     //!< Easier to type
00844 
00845 /*
00846 * Overloaded operators for this class, inlined to prevent multiple copies
00847 */
00848 
00849 //! Compare two FILEPATHS for equality.
00850 inline bool operator== (               
00851    const FILEPATH& p,
00852    const FILEPATH& q
00853    ) { return (p.IsEqual(q)); }
00854 
00855 //! Compare two FILEPATHS for inequality.
00856 inline bool operator!= (               
00857    const FILEPATH& p,
00858    const FILEPATH& q
00859    ) { return (!p.IsEqual(q)); }
00860 
00861 //! Compare two FILEPATHS for less than.
00862 inline bool operator< (                
00863    const FILEPATH& p,
00864    const FILEPATH& q
00865    ) { return (p.IsLessThan(q)); }
00866 
00867 //! Compare two FILEPATHS for greater than.
00868 inline bool operator> (                
00869    const FILEPATH& p,
00870    const FILEPATH& q
00871    ) { return (!p.IsLessThan(q) && !p.IsEqual(q)); }
00872 
00873 //! Compare two FILEPATHS for less than or equality.
00874 inline bool operator<= (               
00875    const FILEPATH& p,
00876    const FILEPATH& q
00877    ) { return (p.IsLessThan(q) || p.IsEqual(q)); }
00878 
00879 //! Compare two FILEPATHS for greater than or equality.
00880 inline bool operator>= (               
00881    const FILEPATH& p,
00882    const FILEPATH& q
00883    ) { return (!p.IsLessThan(q)); }
00884 
00885 //! Append a name to a path.
00886 inline FILEPATH operator+ (            
00887    const FILEPATH& q,
00888    const MISTRING& p
00889    ) {
00890    FILEPATH temp(q);
00891    return (temp += p);
00892    }
00893 
00894 inline MISTRING& operator<< (
00895    MISTRING& lhs,
00896    const FILEPATH& rhs
00897    ) { return (lhs.operator<<(rhs.GetDisplay())); }
00898 
00899 #undef   CLASSLIBEXPORT
00900 
00901 #endif

Generated on Tue Dec 14 13:18:21 2004 for TNTsdk by  doxygen 1.3.8-20040913