#include <pathname.h>
Inheritance diagram for PathName:
Public Member Functions | |
PathName () | |
Default PathName class constructor. | |
PathName (const PathName &) | |
Copy Constructor for the PathName class. | |
PathName (const String_256 &) | |
Is to parse the path string passed in as a parameter. Also, it sets up the internal variables for location, filename and filetype. | |
const String_256 | GetPath (BOOL TrailingSlash=FALSE) const |
To reconstruct path name and return it. | |
const String_256 | GetLocation (BOOL KeepSep=TRUE) const |
To obtain the location from a pathname. | |
const String_256 | GetFileName (BOOL FullName=TRUE) const |
To Construct the FileName out of the FileName and FileType. | |
const String_256 | GetType () const |
Extracts the file type. | |
String_256 | GetWebAddress () const |
This function returns the path name in URL form. | |
const String_256 | GetTruncatedPath (UINT32 MaxSize=0) const |
Display fields which require a pathname to be shown in a fixed sized space will need the path name truncated if it is too long to fit into the space. This routine should do this in the standard Microsoft way. We use an OS/MFC routine, AbbreviateName, to do the work for for us. | |
const String_256 | GetTruncatedLocation (UINT32 MaxSize=0) const |
Display fields which require a location to be shown in a fixed sized space will need the location truncated if it is too long to fit into the space. This routine should do this in the standard Microsoft way. We use an OS/MFC routine, AbbreviateName, to do the work for for us. | |
BOOL | SetType (const String_256 &NewType) |
Changes the Pathnames type (extension). | |
BOOL | SetFileName (const String_256 &NewFileName) |
Allow alteration of the filename component of the path. | |
BOOL | SetFileNameAndType (const String_256 &NewFileName) |
Parses a string representing a filename type and sets up the class variables filetype and filename if the path is valid otherwise it leaves them sets them to null strings. Always sets the filename and filetype regardless of whether there is a file type present or not. SetFileName will not set the name if there is a type present. | |
BOOL | SetPathName (const String_256 &, BOOL SetErrors=TRUE) |
Parses a string representing a path and sets up the class variables filetype, filename and location if the path is valid otherwise it sets them to null strings. | |
virtual BOOL | IsValid (const String_256 &) const |
Parses a string representing a path and sets up the class variables filetype, filename and location if the path is valid. Cannot do the usual 8.3 checking of things like filenames as this is no longer valid given Chicargo and NT non-FAT filing systems. | |
virtual BOOL | IsValid () const |
Says whether the pathname currently in the class has been parsed correctly. This should only be used if the non-blank contructors have been called and more specifically the contructor which takes a pathname as a parameter has been used. This function then returns the result of the validation that happens in the constructor as of course constructors cannot return results! | |
PathName & | operator= (const PathName &) |
Assignment operator for pathnames. | |
Protected Member Functions | |
virtual BOOL | IsValidAndReturnInfo (const String_256 &ConstPath, String_256 &tempFilename, String_256 &tempLocation, String_256 &tempFiletype, String_256 &tempDrivename, BOOL SetErrors=TRUE) const |
Parses a string representing a path and returns the filetype, filename and location to the caller if the path is valid. Cannot do the usual 8.3 checking of things like filenames as this is no longer valid given Chicago and NT non-FAT filing systems. Routine called by IsValid to actually go and do the work involved with checking the pathname. Done this way so that internal calls do not have to parse the data again to get at the variables. | |
void | TruncateName (String_256 &FullName, String_256 *pShortName, INT32 MaxSize) const |
This function shortens a file name, replacing the middle sections of the name with ... if needed. eg if the input path is m:.art Resulting Filename MaxSize myfile.art 0-16 c:\....art 17-24 c:\....art 25-33 c:\....art 34-etc if the filename is longer than MaxSize then the filename will still be returned. In other words, it is possible for a string longer than MaxSize to be returned, so if this is important, check the length after you get your string back. | |
Protected Attributes | |
BOOL | PathNameValid |
String_256 | location |
String_256 | filename |
String_256 | filetype |
String_256 | drivename |
Definition at line 114 of file pathname.h.
|
Default PathName class constructor.
Definition at line 166 of file pathname.cpp. 00167 : PathNameValid(FALSE) 00168 { 00169 // Empty. 00170 }
|
|
Copy Constructor for the PathName class.
Definition at line 186 of file pathname.cpp. 00187 : PathNameValid(other.PathNameValid), 00188 location(other.location), 00189 filename(other.filename), 00190 filetype(other.filetype), 00191 drivename(other.drivename) 00192 { 00193 // Empty. 00194 }
|
|
Is to parse the path string passed in as a parameter. Also, it sets up the internal variables for location, filename and filetype.
Definition at line 212 of file pathname.cpp. 00213 { 00214 // Set up the protected variables at our disposal 00215 PathNameValid = FALSE; 00216 00217 // Check if supplied path is valid or not, if so then set up our internal variables 00218 // Use the internal form of the checking code which returns the values back to us, 00219 // blanked if a problem has happened. 00220 BOOL ok; 00221 String_256 tempFilename; //temporary string to hold the filename 00222 String_256 tempLocation; //temporary string to hold the location 00223 String_256 tempFiletype; //temporary string to hold the filetype 00224 String_256 tempDrivename; //temporary string to hold the drive name 00225 00226 // Use the internal form of the routine which returns us information which 00227 // we do not want and so just throw away 00228 ok = IsValidAndReturnInfo(path, tempFilename, tempLocation, tempFiletype, tempDrivename); 00229 00230 // We could return the result to the user but we are a constructor and so cannot. 00231 // but we will set up our variables to be the returned variables 00232 filename = tempFilename; 00233 location = tempLocation; 00234 filetype = tempFiletype; 00235 drivename = tempDrivename; 00236 PathNameValid = ok; 00237 }
|
|
To Construct the FileName out of the FileName and FileType.
Definition at line 605 of file pathname.cpp. 00606 { 00607 String_256 fname; 00608 fname.Empty(); 00609 00610 //Concatenation of FileName and FileType 00611 fname += filename; 00612 00613 // Changed by Neville 25/8/94 so that if no filetype is present then a full stop 00614 // is not added to the filename. 00615 // FullName parameter added 21/3/95 so that can just specify the filename itself, 00616 // without the extension. 00617 // Use IsWin32c() to test for Windows 95/Chicago 00618 if ( !filetype.IsEmpty() && FullName) 00619 { 00620 fname += String( wxT(FULLSTOP_SYM) ); 00621 fname += filetype; 00622 } 00623 00624 return fname; 00625 }
|
|
To obtain the location from a pathname.
Definition at line 567 of file pathname.cpp. 00568 { 00569 String_256 path; 00570 00571 path = location; 00572 if (!KeepSep) 00573 { 00574 // Get the last character and remove it if it is a backslash. 00575 INT32 Length = path.Length() - 1; 00576 TCHAR *pLocation = (TCHAR *) path; 00577 PORTNOTE("other","Removed UnicodeManager usage") 00578 if( pLocation[Length] == SEPARATOR ) 00579 #ifndef EXCLUDE_FROM_XARALX 00580 //&& !UnicodeManager::IsDBCSLeadByte(pLocation[Length-1])) 00581 #endif 00582 pLocation[Length] = 0; 00583 } 00584 00585 return path; 00586 }
|
|
To reconstruct path name and return it.
Definition at line 255 of file pathname.cpp. 00256 { 00257 String_256 path; 00258 path.Empty(); 00259 00260 // Concatenation of Location, FileName and FileType 00261 path += location; 00262 path += filename; 00263 00264 // Changed by Neville 25/8/94 so that if no filetype is present then a full stop 00265 // is not added to the filename. 00266 if ( !filetype.IsEmpty() ) 00267 { 00268 path += String( wxT(FULLSTOP_SYM) ); 00269 path += filetype; 00270 } 00271 00272 // Though it might not make much sense for filenames, it's invaluable for directory paths in the 00273 // library gallery system... 00274 if(TrailingSlash) 00275 { 00276 // Add a trailing slash if it hasn't got one (usually, roots have 'em, but sub-dirs don't) 00277 INT32 ByteLength = path.Length(); 00278 PORTNOTE("other","Removed UnicodeManager usage") 00279 if( path[ByteLength-1]!=SEPARATOR ) 00280 #ifndef EXCLUDE_FROM_XARALX 00281 //|| ((path[ByteLength-1]==SEPARATOR) && UnicodeManager::IsDBCSLeadByte(path[ByteLength-2]))) 00282 #endif 00283 path += SEPARATOR; 00284 } 00285 00286 return path; 00287 }
|
|
Display fields which require a location to be shown in a fixed sized space will need the location truncated if it is too long to fit into the space. This routine should do this in the standard Microsoft way. We use an OS/MFC routine, AbbreviateName, to do the work for for us.
Definition at line 542 of file pathname.cpp. 00543 { 00544 // Use the normal routine to get the pathname 00545 static String_256 path; 00546 path = GetLocation(FALSE); 00547 00548 // Shorten the filename down a bit. 00549 String_256 ShortPath; 00550 TruncateName(path, &ShortPath, (INT32)MaxSize); 00551 return ShortPath; 00552 }
|
|
Display fields which require a pathname to be shown in a fixed sized space will need the path name truncated if it is too long to fit into the space. This routine should do this in the standard Microsoft way. We use an OS/MFC routine, AbbreviateName, to do the work for for us.
Definition at line 367 of file pathname.cpp. 00368 { 00369 // Use the normal routine to get the pathname 00370 String_256 path; 00371 path = GetPath(); 00372 00373 // Shorten the filename down a bit. 00374 String_256 ShortPath; 00375 ShortPath.Empty(); 00376 TruncateName(path, &ShortPath, (INT32)MaxSize); 00377 return ShortPath; 00378 }
|
|
Extracts the file type.
Definition at line 641 of file pathname.cpp. 00642 { 00643 return filetype; 00644 }
|
|
This function returns the path name in URL form.
The way we do this is: a. Convert all backslashes to forward slashes b. Add "file:///" to the start to the string Remarkably, this works both with UNC pathnames and ordinary ones. So: \earth/test.htm becomes file://///earth/progtemp/imagemaps/test.htm d:.htm becomes file:///d:/imagemaps/test.htm bugfix #10747 (Marc 20/9/04) - some browsers (notably Opera) choked on the | character when used to replace the colon in a path, so this behaviour was removed. Also, the host was not correctly specified, so it is now specified as the local machine with "file:///". Notes: it was not possible to rewrite a UNC as "file://<host>/<path>" because this fails in Mozilla & Netscape. So we are left with the "file://///<host>/<path>" solution which unfortunately does not work in Opera but at least works in IE,Netscape & Mozilla!
Definition at line 329 of file pathname.cpp. 00330 { 00331 //First let's get this path as a string 00332 String_256 strPath=GetPath(FALSE); 00333 00334 //Convert all the backslashes to forward slashes 00335 strPath.SwapChar('\\', '/'); 00336 00337 //Add "file:///" to the start of the sting 00338 String_256 strToReturn( wxT("file:///") ); 00339 00340 strToReturn+=strPath; 00341 00342 //And return 00343 return strToReturn; 00344 00345 }
|
|
Says whether the pathname currently in the class has been parsed correctly. This should only be used if the non-blank contructors have been called and more specifically the contructor which takes a pathname as a parameter has been used. This function then returns the result of the validation that happens in the constructor as of course constructors cannot return results!
Reimplemented in DirPath, and FilePath. Definition at line 871 of file pathname.cpp. 00872 { 00873 // Just return the result that we have found earlier to the caller 00874 // If the wrong constructor has been called then should be automatically FALSE. 00875 return PathNameValid; 00876 }
|
|
Parses a string representing a path and sets up the class variables filetype, filename and location if the path is valid. Cannot do the usual 8.3 checking of things like filenames as this is no longer valid given Chicargo and NT non-FAT filing systems.
Reimplemented in DirPath, and FilePath. Definition at line 833 of file pathname.cpp. 00834 { 00835 BOOL ok; 00836 String_256 tempFilename; //temporary string to hold the filename 00837 String_256 tempLocation; //temporary string to hold the location 00838 String_256 tempFiletype; //temporary string to hold the filetype 00839 String_256 tempDrivename; //temporary string to hold the drive name 00840 00841 // Use the internal form of the routine which returns us information which 00842 // we do not want and so just throw away 00843 ok = IsValidAndReturnInfo(path, tempFilename, tempLocation, tempFiletype, tempDrivename); 00844 00845 // Set up our class variable which holds this validation information 00846 //PathNameValid = ok; // don't be so stupid 00847 00848 // return result to the user 00849 return ok; 00850 }
|
|
Parses a string representing a path and returns the filetype, filename and location to the caller if the path is valid. Cannot do the usual 8.3 checking of things like filenames as this is no longer valid given Chicago and NT non-FAT filing systems. Routine called by IsValid to actually go and do the work involved with checking the pathname. Done this way so that internal calls do not have to parse the data again to get at the variables.
Reimplemented in DirPath, and FilePath. Definition at line 910 of file pathname.cpp. 00916 { 00917 // First ensure the strings passed in are blanked 00918 tempFilename.Empty(); 00919 tempLocation.Empty(); 00920 tempFiletype.Empty(); 00921 tempDrivename.Empty(); 00922 00923 // Get a non const version, as this function tends to party a bit too much 00924 String_256 path = ConstPath; 00925 00926 // Then check for an empty path being passed to us 00927 // and also that a device name is not being specified 00928 if ( !path.IsEmpty() && !IsDeviceName(path)) 00929 { 00930 BOOL ok = TRUE; // General flag for returning results 00931 BOOL driveFound = FALSE; // Flag for valid drive found 00932 BOOL fnameFound = FALSE; // Flag for valid filename found 00933 BOOL BadCharacter = FALSE; // Flag for bad character found 00934 00935 String_256 temp; // temporary string buffer 00936 String_256 tempDrive; // temporary string to hold drive 00937 00938 const TCHAR *fn; // File Name Pointer 00939 00940 fn = path; 00941 temp.Empty(); 00942 00943 // First check if there is a valid drive name or net drive name present 00944 // If the first character of the path is an alpha then assume drive and check if valid 00945 // and so of the form D:/ 00946 // Otherwise, check for a UNC (Universal naming convention) form of drive of the form 00947 // \\Deepthought 00948 if (*fn == SEPARATOR) 00949 driveFound = getNetDrive(&fn, temp, &BadCharacter); //Parse as UNC or network drive 00950 else 00951 driveFound = getDrive(&fn, temp); // Parse the Drive 00952 00953 // If parsed that ok then add the drive to our location store 00954 // otherwise reset back to the entire path string and look for a relative style path 00955 if (driveFound) 00956 { 00957 tempLocation = temp; // Add drive to location string 00958 tempDrivename = temp; // Note drive name found for future use 00959 } 00960 else 00961 fn = path; // Start again at first character 00962 00963 // If no drive or net drive (UNC) present then this may be a relative path so do not 00964 // assume that everything fails because of this. 00965 // Now move along the path to see if we have a correct filename with possible multiple 00966 // directories being specified before it. 00967 while (ok && !fnameFound) 00968 { 00969 temp.Empty(); // Clear temporary 00970 // The size of the file/directory name is really max string size - current size 00971 // of the location string i.e. the space remaining in our fixed length strings. 00972 UINT32 MaxSize = temp.MaxLength() - tempLocation.Length(); 00973 ok = getIdentifier(&fn, temp, MaxSize, &BadCharacter); //Get the Identifier 00974 if (ok) 00975 { 00976 if (*fn == SEPARATOR) // If it is a directory location\path 00977 { 00978 tempLocation += temp; // add to file location\path temp buffer 00979 fn++; // and move to after separator 00980 } 00981 else // If it is a filename 00982 { 00983 tempFilename = temp; // add to file name temp buffer 00984 fnameFound = TRUE; // and flag found to terminate search 00985 } 00986 } 00987 } 00988 00989 // If everything went well then we should now have a filename with an optional 00990 // drive/net drive and optional directory list. Now check for a file extension 00991 // on the end of the filename. 00992 // fn is pointing at the end of the found filename if everything ok 00993 00994 if (ok) // If ok so far 00995 { 00996 // Note current position i.e. end of supplied path 00997 // We will scan from the end backwards to locate the extension. 00998 // const TCHAR* CurrentPos = fn; 00999 const TCHAR* StartOfPath = path; 01000 01001 if (*fn == END_OF_PATH || *fn == END_OF_STRING) 01002 { 01003 fn = camStrdec(path, fn); // move to last valid character 01004 // Get File Extension 01005 // If we don't find a vlaid extension then do not complain as this should 01006 // not be a problem. 01007 BOOL ExtOk = getExtension(&fn, temp, MAXEXT, StartOfPath); 01008 01009 if (ExtOk) 01010 { 01011 // We parsed it ok, so make a note of it. 01012 tempFiletype = temp; // FileType = File Extension 01013 // tempFileName should already be = leafname found 01014 // tempLocation should already be = directory path found 01015 // And remove it from the filename 01016 UINT32 LenFilename = tempFilename.Length(); 01017 UINT32 LenExtensionName = tempFiletype.Length(); 01018 // Strip the extension name plus the full stop from the filename. 01019 if (LenFilename > LenExtensionName) 01020 { 01021 temp.Empty(); 01022 tempFilename.Left(&temp, (LenFilename - LenExtensionName - 1)); 01023 tempFilename = temp; 01024 } 01025 } 01026 else 01027 { 01028 // We have not found what we consider to be a valid extension so say 01029 // we have a blank filetype. 01030 tempFiletype.Empty(); // FileType = File Extension 01031 // The filename is the valid leafname that has been found, possibly 01032 // including a dodgy extension name that we did not like at all. 01033 } 01034 } 01035 else 01036 { 01037 tempFiletype.Empty(); // FileType = File Extension = none 01038 } 01039 } 01040 01041 // Ok is the flag that says whether we have found a valid filename or not so return 01042 // this to the caller. 01043 // Now we also have a flag BadCharacter. If set we have found what we consider to be 01044 // an illegal/reserved character in the filename and so should return false but may 01045 // have parsed the filename ok so that this can be shown to the user. 01046 // if (BadCharacter) 01047 // { 01048 // // If set errors has been specified then set up the required error 01049 // if (SetErrors) 01050 // Error::SetError(_R(IDE_PATH_ERROR), 0); // Set up the correct error 01051 // return FALSE; 01052 // } 01053 // else 01054 // return ok; // Return ok flag 01055 01056 // Always return the result, if we reach this point. Ignore bad characters as these 01057 // are ok under NT. 01058 if (!ok) 01059 { 01060 if (SetErrors) 01061 { 01062 Error::SetError(_R(IDE_PATH_ERROR), 0); 01063 } 01064 } 01065 return ok; 01066 } 01067 else 01068 { 01069 tempFiletype.Empty(); //Return blank fileType 01070 tempFilename.Empty(); //Return blank fileName 01071 tempLocation.Empty(); //Return blank location 01072 01073 // If set errors has been specified then set up the required error 01074 if (SetErrors) 01075 Error::SetError(_R(IDE_PATH_ERROR), 0); // Set up the correct error 01076 return FALSE; // Null path passed to us 01077 } 01078 01079 // If we reach here then things must have gone terribly wrong so return False 01080 return FALSE; 01081 }
|
|
Assignment operator for pathnames.
Definition at line 1098 of file pathname.cpp. 01099 { 01100 filename = newPath.filename; 01101 location = newPath.location; 01102 filetype = newPath.filetype; 01103 drivename = newPath.drivename; 01104 01105 PathNameValid = newPath.PathNameValid; 01106 01107 return *this; 01108 }
|
|
Allow alteration of the filename component of the path.
Definition at line 684 of file pathname.cpp. 00685 { 00686 const TCHAR* fn = NewFileName; 00687 String_256 newfilename; 00688 BOOL BadCharacter = FALSE; 00689 BOOL ok = FALSE; 00690 ok = getIdentifier(&fn, newfilename, NewFileName.Length(), &BadCharacter); 00691 if (!ok || BadCharacter || newfilename.Length() != NewFileName.Length()) 00692 { 00693 // don't allow any bad characters & ensure given NewFileName is the whole thing 00694 return FALSE; 00695 } 00696 00697 String_32 temp; 00698 ok = getExtension(&fn, temp, MAXEXT, fn); 00699 if (ok) 00700 { 00701 // an extnesion was found - don't allow it 00702 return FALSE; 00703 } 00704 00705 // set the filename to the new one 00706 filename = newfilename; 00707 00708 return TRUE; 00709 }
|
|
Parses a string representing a filename type and sets up the class variables filetype and filename if the path is valid otherwise it leaves them sets them to null strings. Always sets the filename and filetype regardless of whether there is a file type present or not. SetFileName will not set the name if there is a type present.
Definition at line 730 of file pathname.cpp. 00731 { 00732 // Check if supplied path is valid or not, if so then set up our internal variables 00733 // Use the internal form of the checking code which returns the values back to us, 00734 // blanked and with an error flag set if a problem has happened. 00735 BOOL ok; 00736 String_256 tempFilename; //temporary string to hold the filename 00737 String_256 tempLocation; //temporary string to hold the location 00738 String_256 tempFiletype; //temporary string to hold the filetype 00739 String_256 tempDrivename; //temporary string to hold the drive name 00740 00741 // Use the internal form of the routine which returns us information which 00742 // we do not want and so just throw away 00743 ok = IsValidAndReturnInfo(NewFileName, tempFilename, tempLocation, tempFiletype, tempDrivename); 00744 00745 // Set up our class variables to be the returned variables 00746 // Only set the ones that we are interested in though. 00747 filename = tempFilename; 00748 filetype = tempFiletype; 00749 00750 // Set up our class variable which holds this validation information 00751 PathNameValid = ok; 00752 00753 // return the result of the parsing of the pathname to the caller. 00754 return ok; 00755 }
|
|
Parses a string representing a path and sets up the class variables filetype, filename and location if the path is valid otherwise it sets them to null strings.
Definition at line 777 of file pathname.cpp. 00778 { 00779 // Check if supplied path is valid or not, if so then set up our internal variables 00780 // Use the internal form of the checking code which returns the values back to us, 00781 // blanked and with an error flag set if a problem has happened. 00782 BOOL ok; 00783 String_256 tempFilename; //temporary string to hold the filename 00784 String_256 tempLocation; //temporary string to hold the location 00785 String_256 tempFiletype; //temporary string to hold the filetype 00786 String_256 tempDrivename; //temporary string to hold the drive name 00787 00788 // Use the internal form of the routine which returns us information which 00789 // we do not want and so just throw away 00790 ok = IsValidAndReturnInfo(path, tempFilename, tempLocation, tempFiletype, tempDrivename, 00791 SetErrors); 00792 00793 // Set up our class variables to be the returned variables 00794 filename = tempFilename; 00795 location = tempLocation; 00796 filetype = tempFiletype; 00797 drivename = tempDrivename; 00798 00799 // Set up our class variable which holds this validation information 00800 PathNameValid = ok; 00801 00802 // return the result of the parsing of the pathname to the caller. 00803 return ok; 00804 }
|
|
Changes the Pathnames type (extension).
Definition at line 660 of file pathname.cpp. 00661 { 00662 // set the filetype to the new one 00663 filetype = NewType; 00664 00665 // all worked 00666 return TRUE; 00667 }
|
|
This function shortens a file name, replacing the middle sections of the name with ... if needed. eg if the input path is m:.art Resulting Filename MaxSize myfile.art 0-16 c:\....art 17-24 c:\....art 25-33 c:\....art 34-etc if the filename is longer than MaxSize then the filename will still be returned. In other words, it is possible for a string longer than MaxSize to be returned, so if this is important, check the length after you get your string back.
Definition at line 410 of file pathname.cpp. 00411 { 00412 // If maxsize is zero, then give back the whole path name 00413 if (MaxSize==0) 00414 { 00415 *pShortName = FullName; 00416 return; 00417 } 00418 00419 // Find out how long the full path is 00420 INT32 FullLength = FullName.Length(); 00421 00422 // if we can fit it into MaxSize, then return it 00423 if (FullLength<=MaxSize) 00424 { 00425 *pShortName = FullName; 00426 return; 00427 } 00428 00429 // OK, we will need to compress it, so look for the actual filename part of the path 00430 // the filename goes from the end of the string to the last \ in the string 00431 const TCHAR* pFullName = (const TCHAR*)FullName; 00432 const TCHAR* pLastSlash = camStrrchr(pFullName, SEPARATOR); 00433 00434 // if we fell off the end of the string, we only had a filename, so return it 00435 if (pLastSlash == NULL) 00436 { 00437 *pShortName = FullName; 00438 return; 00439 } 00440 00441 // Find out the length of the filename 00442 INT32 FileNameLen = FullLength - (pLastSlash - pFullName); 00443 INT32 FileNameStart = pLastSlash - pFullName; 00444 00445 // Now, starting from the front of the string, we have to try and add 00446 // in more and more of the path, until it will fit no more. 00447 // We will skip the first 2 chars as they will be either c: or \\. 00448 const TCHAR* pCurrent = pFullName; 00449 pCurrent = camStrinc(pCurrent); 00450 pCurrent = camStrinc(pCurrent); // Now pointing at the third character 00451 00452 // see if this is a UNC filename 00453 if (*pCurrent != SEPARATOR) 00454 { 00455 // yes, it's UNC, so walk though the server name 00456 do 00457 { 00458 pCurrent = camStrinc(pCurrent); 00459 } while (*pCurrent != SEPARATOR); 00460 } 00461 00462 // Up to here is the volume name really 00463 INT32 VolumeNameLen = pCurrent-pFullName; 00464 00465 // and we need at least the first directory 00466 do 00467 { 00468 pCurrent = camStrinc(pCurrent); 00469 } while (*pCurrent != SEPARATOR); 00470 00471 // See if what we have will fit 00472 INT32 CurrentLength = pCurrent - pFullName; 00473 if ((CurrentLength+FileNameLen+4)>MaxSize) 00474 { 00475 // maybe we could have just volume name\...\filename 00476 if ((VolumeNameLen+4+FileNameLen)>MaxSize) 00477 { 00478 // Nope, it won't fit, so just return the filename 00479 *pShortName = String_256(pFullName+FileNameStart+1); 00480 return; 00481 } 00482 else 00483 { 00484 // Yep, we can fit it in... 00485 // Build the resulting short path 00486 FullName.Left(pShortName, VolumeNameLen); 00487 *pShortName+=TEXT(SEPARATOR_SYM) TEXT("..."); 00488 *pShortName+=pFullName+FileNameStart; 00489 return; 00490 } 00491 } 00492 00493 // Since we can fit the first directory, keep it as part of the volume name 00494 VolumeNameLen = pCurrent-pFullName; 00495 00496 // put i back to the start of the filename and start working backwards 00497 pCurrent = pFullName + FileNameStart; 00498 INT32 DirectoryStart = FileNameStart; 00499 while ((VolumeNameLen+4+(FullLength-(pCurrent-pFullName))) < MaxSize) 00500 { 00501 DirectoryStart = pCurrent-pFullName; 00502 do 00503 { 00504 pCurrent = camStrdec(pFullName, pCurrent); 00505 } while ((*pCurrent!=SEPARATOR) && ((pCurrent-pFullName)>VolumeNameLen)); 00506 } 00507 00508 // We got all the way back to the start of the volume name 00509 if (DirectoryStart==VolumeNameLen) 00510 { 00511 *pShortName = FullName; 00512 return; 00513 } 00514 00515 // Build the resulting short path 00516 FullName.Left(pShortName, VolumeNameLen); 00517 *pShortName+=TEXT(SEPARATOR_SYM) TEXT("..."); 00518 *pShortName+=pFullName+DirectoryStart; 00519 }
|
|
Definition at line 121 of file pathname.h. |
|
Definition at line 119 of file pathname.h. |
|
Definition at line 120 of file pathname.h. |
|
Definition at line 118 of file pathname.h. |
|
Definition at line 117 of file pathname.h. |