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