home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / OS / FWFiles / Sources / FWFileSp.cpp < prev    next >
Encoding:
Text File  |  1995-11-08  |  23.1 KB  |  761 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:        FWFileSp.cpp
  4. //    Release Version:    $ 1.0d11 $
  5. //
  6. //    Copyright:    1995 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWOS.hpp"
  11.  
  12. #ifndef FWFILESP_H
  13. #include "FWFileSp.h"
  14. #endif
  15.  
  16. #ifndef FWFILESY_H
  17. #include "FWFileSy.h"
  18. #endif
  19.  
  20. #ifndef FWSTRTOO_H
  21. #include "FWStrToo.h"
  22. #endif
  23.  
  24. #ifndef FWEXCDEF_H
  25. #include "FWExcDef.h"
  26. #endif
  27.  
  28. #ifndef FWFILPAR_H
  29. #include "FWFilPar.h"
  30. #endif
  31.  
  32. #ifndef FWBNDSTR_H
  33. #include "FWBndStr.h"
  34. #endif
  35.  
  36. #if defined(FW_BUILD_MAC) && !defined(__ERRORS__)
  37. #include <Errors.h>
  38. #endif
  39.  
  40. #if defined(FW_BUILD_MAC) && !defined(__FINDER__)
  41. #include <Finder.h>
  42. #endif
  43.  
  44. #if defined(FW_BUILD_WIN) && !defined(__IO_H)
  45. #include <io.h>
  46. #endif
  47.  
  48. #if FW_LIB_EXPORT_PRAGMAS
  49. #pragma lib_export on
  50. #endif
  51.  
  52. //========================================================================================
  53. //  CLASS FW_CFileSpecification
  54. //========================================================================================
  55.  
  56. #pragma segment FWCFileSpecification
  57. //----------------------------------------------------------------------------------------
  58. //    FW_CFileSpecification::FW_CFileSpecification
  59. //
  60. //  Create a file specification from a directory and a file name.  
  61. //----------------------------------------------------------------------------------------
  62.  
  63. FW_CFileSpecification::FW_CFileSpecification(const FW_CDirectorySpecification& directory,
  64.                                              const FW_CString& fileName)
  65. {
  66. #ifdef FW_BUILD_WIN
  67.     directory.GetFullPath(fFileInfo);
  68.  
  69.     if (fileName.GetLength() > 0)
  70.         FW_CPrivFileSystemParser::AddDelimiter(fFileInfo);
  71.  
  72.     fFileInfo += fileName;
  73.  
  74.     // Verify that path exists.
  75.     FW_CDynamicString tempString;
  76.     if (!FW_CPrivFileSystemParser::WinGetPathName(fFileInfo, tempString))
  77.         FailOnError(FW_CFileSystem::kPathNotFound);
  78.  
  79.     if (!FW_CFileSystem::WinPathExists(tempString))
  80.         FailOnError(FW_CFileSystem::kPathNotFound);
  81. #endif
  82.  
  83. #ifdef FW_BUILD_MAC
  84.     FW_CFileSystem::FileError theError = FW_CFileSystem::kNoError;
  85.     Str255 macFileName;
  86.     FW_CString255 partialPathName;
  87.  
  88.     fFileType = FW_kDefaultFileType; 
  89.     fCreatorType = FW_kDefaultCreatorType;
  90.  
  91.     directory.MacGetFSSpec(fFileInfo);
  92.     partialPathName.ReplaceAll((FW_PascalChar*)&fFileInfo.name);
  93.     partialPathName.Prepend(&FW_kPathDelimiter, 1);
  94.  
  95.     FW_CPrivFileSystemParser::AddDelimiter(partialPathName);
  96.     partialPathName += fileName;
  97.     partialPathName.ExportPascal((FW_PascalChar*)&macFileName);
  98.  
  99.     theError = ::FSMakeFSSpec(fFileInfo.vRefNum, fFileInfo.parID, macFileName, &fFileInfo);
  100.     if ((theError != FW_CFileSystem::kNoError) && (theError != FW_CFileSystem::kNoFileFound))
  101.     {
  102.         FSSpec dirFSSpec;
  103.         directory.MacGetFSSpec(dirFSSpec);
  104.         
  105.         fFileInfo.vRefNum = dirFSSpec.vRefNum;
  106.         fFileInfo.parID = dirFSSpec.parID;
  107.         
  108.         FW_ASSERT(fileName.GetLength() < 64);
  109.         partialPathName.ExportPascal((FW_PascalChar*)&fFileInfo.name);
  110.         
  111.         ThrowError(theError);
  112.     }
  113.     
  114. #endif
  115.  
  116.     FW_END_CONSTRUCTOR
  117. }
  118.  
  119.  
  120. //----------------------------------------------------------------------------------------
  121. //    FW_CFileSpecification::FW_CFileSpecification
  122. //
  123. //    Initialize the specification with fileName.  If fileName is a partial pathname, then
  124. //    the current working directory is used.
  125. //----------------------------------------------------------------------------------------
  126.  
  127. FW_CFileSpecification::FW_CFileSpecification(const FW_CString& fileName)
  128. {
  129. #ifdef FW_BUILD_WIN
  130.     fFileInfo = fileName;
  131.     FW_CPrivFileSystemParser::WinExpandPartialPath(fFileInfo);
  132.  
  133.     // Verify that path exists.
  134.     FW_CDynamicString tempString;
  135.     if (!FW_CPrivFileSystemParser::WinGetPathName(fFileInfo, tempString))
  136.         FailOnError(FW_CFileSystem::kPathNotFound);
  137.  
  138.     if (!FW_CFileSystem::WinPathExists(tempString))
  139.         FailOnError(FW_CFileSystem::kPathNotFound);
  140. #endif
  141.  
  142. #ifdef FW_BUILD_MAC
  143.     FW_CFileSystem::FileError theError = FW_CFileSystem::kNoError;
  144.     Str255 macFileName;
  145.     
  146.     fFileType = FW_kDefaultFileType; 
  147.     fCreatorType = FW_kDefaultCreatorType;
  148.  
  149.     fileName.ExportPascal((FW_PascalChar*)&macFileName);
  150.  
  151.     theError = ::FSMakeFSSpec(0, 0, macFileName, &fFileInfo);
  152.     if ((theError != FW_CFileSystem::kNoError) && (theError != FW_CFileSystem::kNoFileFound))
  153.     {
  154.         fFileInfo.vRefNum = 0;
  155.         fFileInfo.parID = 0;
  156.         FW_ASSERT(fileName.GetLength() < 64);
  157.         fileName.ExportPascal((FW_PascalChar*)&fFileInfo.name);
  158.         ThrowError(theError);
  159.     }
  160. #endif
  161.  
  162.     FW_END_CONSTRUCTOR
  163. }
  164.  
  165.  
  166. //----------------------------------------------------------------------------------------
  167. //    FW_CFileSpecification::FW_CFileSpecification
  168. //
  169. //  Copy constructor
  170. //----------------------------------------------------------------------------------------
  171.  
  172. FW_CFileSpecification::FW_CFileSpecification(const FW_CFileSpecification& specification) :
  173.     fFileInfo(specification.fFileInfo)
  174. #ifdef FW_BUILD_MAC
  175.     , fFileType(specification.fFileType) 
  176.     , fCreatorType(specification.fCreatorType) 
  177. #endif
  178. {
  179.     FW_END_CONSTRUCTOR
  180. }
  181.  
  182.  
  183. //----------------------------------------------------------------------------------------
  184. //    FW_CFileSpecification::~FW_CFileSpecification
  185. //----------------------------------------------------------------------------------------
  186.  
  187. FW_CFileSpecification::~FW_CFileSpecification()
  188. {
  189.     FW_START_DESTRUCTOR
  190. }
  191.  
  192.  
  193. //----------------------------------------------------------------------------------------
  194. //    FW_CFileSpecification::GetName
  195. //
  196. //    Returns the name of the file.  This doesn't return the path information, just the
  197. //    file name.  
  198. //----------------------------------------------------------------------------------------
  199.  
  200. void FW_CFileSpecification::GetName(FW_CString& fileName) const
  201. {
  202. //    FW_CFileSystem::FileError theError = FW_CFileSystem::kNoError;
  203.  
  204. #ifdef FW_BUILD_WIN
  205.     FW_CDynamicString parsedName;
  206.  
  207.     if (FW_CPrivFileSystemParser::GetFileName(fFileInfo, parsedName))
  208.         fileName = parsedName;
  209.     else
  210.         FailOnError(FW_CFileSystem::kBadFileName);
  211. #endif
  212.  
  213. #ifdef FW_BUILD_MAC
  214.     fileName.ReplaceAll((FW_PascalChar*)&fFileInfo.name);
  215. #endif
  216.  
  217. }
  218.  
  219.  
  220. //----------------------------------------------------------------------------------------
  221. //    FW_CFileSpecification::GetParentDirectory
  222. //
  223. //  Returns the path information for this file as a directory specification.  This string
  224. //    will contain a trailing delimiter character.
  225. //----------------------------------------------------------------------------------------
  226.  
  227. FW_CDirectorySpecification FW_CFileSpecification::GetParentDirectory() const
  228. {
  229.     FW_CDirectorySpecification returnDirectory;
  230.  
  231. #ifdef FW_BUILD_WIN
  232.     FW_CDynamicString tempPathName;
  233.  
  234.     if (FW_CPrivFileSystemParser::WinGetPathName(fFileInfo, tempPathName))
  235.     {
  236.         // This is necessary because we can't set the whole path at once with operators.
  237.         FW_CDirectorySpecification tempDirectory(tempPathName);
  238.         returnDirectory = tempDirectory;
  239.     }
  240.     else
  241.     {
  242.         // Path should already have been verified.
  243.         FailOnError(FW_CFileSystem::kPathNotFound);
  244.     }
  245. #endif
  246.  
  247. #ifdef FW_BUILD_MAC    
  248.     FailOnError(FW_CPrivFileSystemParser::MacGenerateDirectory(fFileInfo.vRefNum, fFileInfo.parID, returnDirectory));
  249. #endif
  250.  
  251.     return returnDirectory;
  252. }
  253.  
  254.  
  255. //----------------------------------------------------------------------------------------
  256. //    FW_CFileSpecification::GetFullPath
  257. //
  258. //    Return the path and file name for this file.  The user should pass in a dynamic 
  259. //    string so as to guarantee that the path will fit.  The path should be a fully
  260. //    expanded pathname.
  261. //----------------------------------------------------------------------------------------
  262.  
  263. void FW_CFileSpecification::GetFullPath(FW_CString& fullPathName) const
  264. {
  265. #ifdef FW_BUILD_WIN
  266.     fullPathName = fFileInfo;
  267. #endif
  268.  
  269. #ifdef FW_BUILD_MAC
  270.     fullPathName.ReplaceAll((FW_PascalChar*)&fFileInfo.name);
  271.     FW_CFileSystem::FileError theError = FW_CFileSystem::kNoError;
  272.     
  273.     theError = FW_CPrivFileSystemParser::MacGenerateFullPathName(fFileInfo.vRefNum, fFileInfo.parID, fullPathName);
  274.     FailOnError(theError);
  275.     
  276. #endif
  277.  
  278. }
  279.  
  280.  
  281. //----------------------------------------------------------------------------------------
  282. //    FW_CFileSpecification::operator==
  283. //
  284. //  Equality operator.  Compares the location of each file.  If the location's match, then
  285. //    the file is a match.
  286. //  Note that the Windows side is case insensitive.  On the Mac, FSSMakeFSSpec should
  287. //    normalize file names so conversion should not be necessary.
  288. //----------------------------------------------------------------------------------------
  289.  
  290. FW_Boolean FW_CFileSpecification::operator==(const FW_CFileSpecification& theOtherFile) const
  291. {
  292. #ifdef FW_BUILD_WIN
  293.     FW_CDynamicString tempString1(fFileInfo);
  294.     FW_CDynamicString tempString2(theOtherFile.fFileInfo);
  295.     
  296.     tempString1.ToUpper();
  297.     tempString2.ToUpper();
  298.     return (tempString1 == tempString2);
  299. #endif
  300.  
  301. #ifdef FW_BUILD_MAC
  302.     if ((fFileInfo.vRefNum == theOtherFile.fFileInfo.vRefNum) && (fFileInfo.parID == theOtherFile.fFileInfo.parID))
  303.     {
  304.         FW_CDynamicString fileName1;
  305.         FW_CDynamicString fileName2;
  306.         
  307.         fileName1.ReplaceAll((FW_PascalChar*)&fFileInfo.name);
  308.         fileName2.ReplaceAll((FW_PascalChar*)&theOtherFile.fFileInfo.name);
  309.         
  310.         fileName1.ToUpper();
  311.         fileName2.ToUpper();
  312.         if (fileName1 == fileName2)
  313.             return (fFileType == theOtherFile.fFileType && fCreatorType == theOtherFile.fCreatorType);
  314.     }
  315.     
  316.     return (FALSE);
  317. #endif
  318.  
  319. }
  320.  
  321.  
  322. //----------------------------------------------------------------------------------------
  323. //    FW_CFileSpecification::operator=
  324. //
  325. //  Copies info over from pre-verified file specification.  Shouldn't need to do any 
  326. //    checks.
  327. //----------------------------------------------------------------------------------------
  328.  
  329. FW_CFileSpecification& FW_CFileSpecification::operator=(const FW_CFileSpecification& theOtherFile)
  330. {
  331.     fFileInfo = theOtherFile.fFileInfo;
  332. #ifdef FW_BUILD_MAC
  333.     fFileType = theOtherFile.fFileType;
  334.     fCreatorType = theOtherFile.fCreatorType;
  335. #endif
  336.     return (*this);
  337. }
  338.  
  339.  
  340. //----------------------------------------------------------------------------------------
  341. //    FW_CFileSpecification::operator=
  342. //
  343. //    Set the name of the file.  This only changes the name, it doesn't change the previous
  344. //    path.  Reverifies the path with the new fileName.
  345. //----------------------------------------------------------------------------------------
  346.  
  347. FW_CFileSpecification& FW_CFileSpecification::operator=(const FW_CString& fileName)
  348. {
  349. #ifdef FW_BUILD_WIN
  350.     FW_CDynamicString tempPathName;
  351.  
  352.     if (FW_CPrivFileSystemParser::WinGetPathName(fFileInfo, tempPathName))
  353.     {
  354.         FW_CPrivFileSystemParser::AddDelimiter(tempPathName);
  355.         fFileInfo = tempPathName;
  356.     }
  357.  
  358.     fFileInfo += fileName;
  359.     
  360.     // Verify that path exists.
  361.     FW_CDynamicString tempString;
  362.     if (!FW_CPrivFileSystemParser::WinGetPathName(fFileInfo, tempString))
  363.         FailOnError(FW_CFileSystem::kPathNotFound);
  364.  
  365.     if (!FW_CFileSystem::WinPathExists(tempString))
  366.         FailOnError(FW_CFileSystem::kPathNotFound);
  367. #endif
  368.  
  369. #ifdef FW_BUILD_MAC
  370.     FW_CFileSystem::FileError theError = FW_CFileSystem::kNoError;
  371.     short vRefNum = fFileInfo.vRefNum;
  372.     long dirID = fFileInfo.parID;
  373.     Str255 macFileName;
  374.     
  375.     fFileType = FW_kDefaultFileType; 
  376.     fCreatorType = FW_kDefaultCreatorType;
  377.  
  378.     fileName.ExportPascal((FW_PascalChar*)&macFileName);
  379.  
  380.     theError = ::FSMakeFSSpec(vRefNum, dirID, macFileName, &fFileInfo);
  381.     if ((theError != FW_CFileSystem::kNoError) && (theError != FW_CFileSystem::kNoFileFound))
  382.     {
  383.         fFileInfo.vRefNum = vRefNum;
  384.         fFileInfo.parID = dirID;
  385.         FW_ASSERT(fileName.GetLength() < 64);
  386.         fileName.ExportPascal((FW_PascalChar*)&fFileInfo.name);
  387.         ThrowError(theError);
  388.     }
  389. #endif
  390.  
  391.     return (*this);
  392. }
  393.  
  394.  
  395. #ifdef FW_BUILD_WIN
  396. //----------------------------------------------------------------------------------------
  397. //    FW_CFileSpecification::WinGetDrive
  398. //----------------------------------------------------------------------------------------
  399.  
  400. FW_Char FW_CFileSpecification::WinGetDrive() const
  401. {
  402.     FW_CharacterPosition colonPosition = -1;
  403.     FW_CDynamicString driveName;
  404.     FW_Char driveLetter = '\0';
  405.  
  406.     // If there's no drive information in the path, get the default drive information.
  407.     if (!FW_CPrivFileSystemParser::WinGetDrivePath(fFileInfo, driveName))
  408.         FailOnError(FW_CFileSystem::kBadFileName);
  409.  
  410.     if (!driveName.FindCharacter(FW_kDriveDelimiter, colonPosition))
  411.         FailOnError(FW_CFileSystem::kNoSuchVolume);
  412.  
  413.     if (colonPosition > 1)
  414.         FailOnError(FW_CFileSystem::kNoSuchVolume);
  415.         
  416.     driveName.ToLower();
  417.     
  418. #if defined(_MSC_VER) && (_MSC_VER <= 900)
  419.     driveLetter = driveName[(FW_CharacterPosition)(colonPosition - 1)];
  420. #else
  421.     driveLetter = driveName[colonPosition - 1];
  422. #endif
  423.  
  424.     if ((driveLetter < 'a') || (driveLetter > 'z'))
  425.         FailOnError(FW_CFileSystem::kBadFileName);
  426.  
  427.     return (driveLetter);
  428. }
  429. #endif
  430.  
  431.  
  432. #ifdef FW_BUILD_WIN
  433. //----------------------------------------------------------------------------------------
  434. //    FW_CFileSpecification::WinGetExtension
  435. //----------------------------------------------------------------------------------------
  436.  
  437. void FW_CFileSpecification::WinGetExtension(FW_CString& extension) const
  438. {
  439.     if (!FW_CPrivFileSystemParser::GetExtension(fFileInfo, extension))
  440.         extension = "";
  441. }
  442. #endif
  443.  
  444.  
  445. #ifdef FW_BUILD_WIN
  446. //----------------------------------------------------------------------------------------
  447. //    FW_CFileSpecification::WinSetExtension
  448. //----------------------------------------------------------------------------------------
  449.  
  450. void FW_CFileSpecification::WinSetExtension(const FW_CString& extension)
  451. {
  452.     FW_CDynamicString newFileInfo;
  453.  
  454.     FW_CPrivFileSystemParser::ChangeExtension(fFileInfo, extension, newFileInfo);
  455.     fFileInfo = newFileInfo;
  456. }
  457. #endif
  458.  
  459.  
  460. #ifdef FW_BUILD_MAC
  461. //----------------------------------------------------------------------------------------
  462. //    FW_CFileSpecification::FW_CFileSpecification
  463. //
  464. //    Macintosh FSSpec constructor.  
  465. //----------------------------------------------------------------------------------------
  466.  
  467. FW_CFileSpecification::FW_CFileSpecification(const FSSpec& specification) :
  468.     fFileInfo(specification),
  469.     fFileType(FW_kDefaultFileType),
  470.     fCreatorType(FW_kDefaultCreatorType)
  471. {
  472.     FW_END_CONSTRUCTOR
  473. }
  474. #endif
  475.  
  476.  
  477. #ifdef FW_BUILD_MAC
  478. //----------------------------------------------------------------------------------------
  479. //    FW_CFileSpecification::operator=
  480. //----------------------------------------------------------------------------------------
  481.  
  482. FW_CFileSpecification& FW_CFileSpecification::operator=(const FSSpec& macSpec)
  483. {
  484.     fFileInfo = macSpec;
  485.     fFileType = FW_kDefaultFileType; 
  486.     fCreatorType = FW_kDefaultCreatorType;
  487.     return (*this);
  488. }
  489. #endif
  490.  
  491.  
  492. #ifdef FW_BUILD_MAC
  493. //----------------------------------------------------------------------------------------
  494. //    FW_CFileSpecification::MacGetFSSpec
  495. //----------------------------------------------------------------------------------------
  496.  
  497. void FW_CFileSpecification::MacGetFSSpec(FSSpec& macSpec) const
  498. {
  499.     macSpec = fFileInfo;
  500. }
  501. #endif
  502.  
  503.  
  504. #ifdef FW_BUILD_MAC
  505. //----------------------------------------------------------------------------------------
  506. //    FW_CFileSpecification::MacSetTypeAndCreator
  507. //----------------------------------------------------------------------------------------
  508.  
  509. void FW_CFileSpecification::MacSetTypeAndCreator(OSType aFileType, OSType aCreatorType)
  510. {
  511.     fFileType = aFileType; 
  512.     fCreatorType = aCreatorType;
  513. }
  514. #endif
  515.  
  516.  
  517. #ifdef FW_BUILD_MAC
  518. //----------------------------------------------------------------------------------------
  519. //    FW_CFileSpecification::MacGetTypeAndCreator
  520. //----------------------------------------------------------------------------------------
  521.  
  522. void FW_CFileSpecification::MacGetTypeAndCreator(OSType &aFileType, OSType &aCreatorType) const
  523. {
  524.     aFileType = fFileType; 
  525.     aCreatorType = fCreatorType;
  526. }
  527. #endif
  528.  
  529.  
  530. //----------------------------------------------------------------------------------------
  531. //    FW_CFileSpecification::FailOnError
  532. //----------------------------------------------------------------------------------------
  533.  
  534. void FW_CFileSpecification::FailOnError(short theError) const
  535. {
  536.     // JEL: I don't know why kNoFileFound is not an error.
  537.     // Ideally, we should eliminate this method entirely, and just
  538.     // call FW_FailOnError directly, and only check for kNoFileFound
  539.     // where it is definitely not an error.
  540.     if (theError != FW_CFileSystem::kNoFileFound)
  541.         FW_FailOnError(theError);
  542. }
  543.  
  544.  
  545. //----------------------------------------------------------------------------------------
  546. //    FW_CFileSpecification::ThrowError
  547. //----------------------------------------------------------------------------------------
  548.  
  549. void FW_CFileSpecification::ThrowError(short theError) const
  550. {
  551.     FW_Failure(theError);
  552. }
  553.  
  554. //========================================================================================
  555. //  CLASS FW_CDirectorySpecification
  556. //========================================================================================
  557. #pragma segment FWCDirectorySpecification
  558.  
  559. //----------------------------------------------------------------------------------------
  560. //    FW_CDirectorySpecification::FW_CDirectorySpecification
  561. //
  562. //  Specifies the current working directory.
  563. //----------------------------------------------------------------------------------------
  564.  
  565. FW_CDirectorySpecification::FW_CDirectorySpecification() :
  566.     fFileSpec((FW_CString32)"")
  567. {
  568.     FW_END_CONSTRUCTOR
  569. }
  570.  
  571.  
  572. //----------------------------------------------------------------------------------------
  573. //    FW_CDirectorySpecification::FW_CDirectorySpecification
  574. //
  575. //  Copy constructor.
  576. //----------------------------------------------------------------------------------------
  577.  
  578. FW_CDirectorySpecification::FW_CDirectorySpecification(const FW_CDirectorySpecification& specification) :
  579.     fFileSpec(specification.fFileSpec)
  580. {
  581.     FW_END_CONSTRUCTOR
  582. }
  583.  
  584.  
  585. //----------------------------------------------------------------------------------------
  586. //    FW_CDirectorySpecification::FW_CDirectorySpecification
  587. //
  588. //  Specifies the path by string.  directoryName can be either a full or partial path
  589. //    name.  
  590. //----------------------------------------------------------------------------------------
  591.  
  592. FW_CDirectorySpecification::FW_CDirectorySpecification(const FW_CString& directoryName) :
  593.     fFileSpec(directoryName)
  594. {
  595.     FW_END_CONSTRUCTOR
  596. }
  597.  
  598.  
  599. //----------------------------------------------------------------------------------------
  600. //    FW_CDirectorySpecification::~FW_CDirectorySpecification
  601. //----------------------------------------------------------------------------------------
  602.  
  603. FW_CDirectorySpecification::~FW_CDirectorySpecification()
  604. {
  605.     FW_START_DESTRUCTOR
  606. }
  607.  
  608.  
  609. //----------------------------------------------------------------------------------------
  610. //    FW_CDirectorySpecification::GetDirectoryName
  611. //
  612. //  Return the name of this directory without any preceeding path information.  There is
  613. //    no path delimiter on the end of directoryName.
  614. //----------------------------------------------------------------------------------------
  615. void FW_CDirectorySpecification::GetName(FW_CString& directoryName) const
  616. {
  617.     fFileSpec.GetName(directoryName);
  618. }
  619.  
  620.  
  621. //----------------------------------------------------------------------------------------
  622. //    FW_CDirectorySpecification::GetParentDirectory
  623. //
  624. //  Fills in parentDirectory with information about the parent directory.
  625. //----------------------------------------------------------------------------------------
  626. FW_CDirectorySpecification FW_CDirectorySpecification::GetParentDirectory() const
  627. {
  628.     return fFileSpec.GetParentDirectory();
  629. }
  630.  
  631.  
  632. //----------------------------------------------------------------------------------------
  633. //    FW_CDirectorySpecification::GetFullPath
  634. //
  635. //  Fills in parentDirectory with information about the parent directory.
  636. //----------------------------------------------------------------------------------------
  637. void FW_CDirectorySpecification::GetFullPath(FW_CString& fullPath) const
  638. {
  639.     fFileSpec.GetFullPath(fullPath);
  640.     
  641.     FW_CPrivFileSystemParser::AddDelimiter(fullPath);
  642. }
  643.  
  644.  
  645. //----------------------------------------------------------------------------------------
  646. //    FW_CDirectorySpecification::operator==
  647. //----------------------------------------------------------------------------------------
  648. FW_Boolean FW_CDirectorySpecification::operator==(const FW_CDirectorySpecification& theOtherDir) const
  649. {
  650.     return (fFileSpec == theOtherDir.fFileSpec);
  651. }
  652.  
  653.  
  654. //----------------------------------------------------------------------------------------
  655. //    FW_CDirectorySpecification::operator=
  656. //----------------------------------------------------------------------------------------
  657. FW_CDirectorySpecification& FW_CDirectorySpecification::operator=(const FW_CDirectorySpecification& theOtherDir)
  658. {
  659.     fFileSpec = theOtherDir.fFileSpec;
  660.     return (*this);
  661. }
  662.  
  663.  
  664. //----------------------------------------------------------------------------------------
  665. //    FW_CDirectorySpecification::operator+=
  666. //
  667. //  Adds directoryName on to the end of this directory.
  668. //  In this case, the new name is assigned to the internal FileSpec, where it is interpeted
  669. //    as a partial path.
  670. //----------------------------------------------------------------------------------------
  671. FW_CDirectorySpecification& FW_CDirectorySpecification::operator+=(const FW_CString& directoryName)
  672. {
  673.     FW_CDynamicString tempName;
  674.     
  675.     fFileSpec.GetName(tempName);
  676.     
  677. #ifdef FW_BUILD_MAC
  678.     // Need to add a leading delimiter to indicate this is a partial path.
  679.     tempName.Prepend(&FW_kPathDelimiter, 1);
  680. #endif
  681.  
  682.     tempName += FW_kPathDelimiter;
  683.     tempName += directoryName;
  684.     
  685.     fFileSpec = tempName;
  686.     return (*this);
  687. }
  688.  
  689.  
  690. //----------------------------------------------------------------------------------------
  691. //    FW_CDirectorySpecification::operator=
  692. //
  693. //  Set the name of the directory to the value specified in directoryName.  directoryName
  694. //    should not contain any path delimiters.
  695. //----------------------------------------------------------------------------------------
  696. FW_CDirectorySpecification& FW_CDirectorySpecification::operator=(const FW_CString& directoryName)
  697. {
  698.     fFileSpec = directoryName;
  699.     return (*this);
  700. }
  701.  
  702.  
  703. #ifdef FW_BUILD_WIN
  704. //----------------------------------------------------------------------------------------
  705. //    FW_CDirectorySpecification::WinGetDrive
  706. //
  707. //  Get the drive letter that contains this directory.
  708. //----------------------------------------------------------------------------------------
  709. FW_Char FW_CDirectorySpecification::WinGetDrive() const
  710. {
  711.     return (fFileSpec.WinGetDrive());
  712. }
  713. #endif
  714.  
  715.  
  716. #ifdef FW_BUILD_MAC
  717. //----------------------------------------------------------------------------------------
  718. //    FW_CDirectorySpecification::FW_CDirectorySpecification
  719. //----------------------------------------------------------------------------------------
  720.  
  721. FW_CDirectorySpecification::FW_CDirectorySpecification(const FSSpec& specification) :
  722.     fFileSpec(specification)
  723. {
  724.     FW_END_CONSTRUCTOR
  725. }
  726. #endif
  727.  
  728.  
  729. #ifdef FW_BUILD_MAC
  730. //----------------------------------------------------------------------------------------
  731. //    FW_CDirectorySpecification::operator=
  732. //
  733. //  Copies the Macintosh FSSpec for this directory into specification.
  734. //----------------------------------------------------------------------------------------
  735.  
  736. FW_CDirectorySpecification& FW_CDirectorySpecification::operator=(const FSSpec& macSpec)
  737. {
  738.     fFileSpec = macSpec;
  739.     return (*this);
  740. }
  741. #endif
  742.  
  743.  
  744. #ifdef FW_BUILD_MAC
  745. //----------------------------------------------------------------------------------------
  746. //    FW_CDirectorySpecification::MacGetFSSpec
  747. //
  748. //  Copies the Macintosh FSSpec for this directory into specification.
  749. //----------------------------------------------------------------------------------------
  750.  
  751. void FW_CDirectorySpecification::MacGetFSSpec(FSSpec& macSpec) const
  752. {
  753.     fFileSpec.MacGetFSSpec(macSpec);
  754. }
  755. #endif
  756.  
  757.  
  758.  
  759.  
  760.  
  761.