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 / Include / FWFileSy.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-11-08  |  9.7 KB  |  375 lines  |  [TEXT/MPS ]

  1. #if !defined(FWFILESY_H) && !defined(__ODFRC__)
  2. #define FWFILESY_H
  3. //========================================================================================
  4. //
  5. //    File:        FWFileSy.h
  6. //    Release Version:    $ 1.0d11 $
  7. //
  8. //    Copyright:    1995 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #ifndef FWFILESP_H
  13. #include "FWFileSp.h"
  14. #endif
  15.  
  16. #ifndef FWPRIEXC_H
  17. #include "FWPriExc.h"
  18. #endif
  19.  
  20. #if defined(FW_BUILD_MAC) && !defined(__FILES__)
  21. #include "Files.h"
  22. #endif
  23.  
  24. #if defined(FW_BUILD_MAC) && !defined(__ERRORS__)
  25. #include "Errors.h"
  26. #endif
  27.  
  28. #ifdef FW_BUILD_WIN16
  29. // WINVER 0x30a
  30. #include <windows.h>
  31. #endif
  32.  
  33. #ifdef FW_BUILD_WIN32
  34. #include <winerror.h>
  35. #include <winbase.h>
  36. #endif
  37.  
  38. #if FW_LIB_EXPORT_PRAGMAS
  39. #pragma lib_export on
  40. #endif
  41.  
  42. //========================================================================================
  43. //  Platform Error constants
  44. //========================================================================================
  45.  
  46. const FW_PlatformError FW_xCantDeleteWorkingDirectory = -30010;    // !!!JEL need offical value
  47. const FW_PlatformError FW_xInvalidDirectory = -30011;    // !!!JEL need offical value
  48.  
  49. //========================================================================================
  50. //  Forward declarations
  51. //========================================================================================
  52. class FW_CFileSpecification;
  53. class FW_CDirectorySpecification;
  54.  
  55. //========================================================================================
  56. //  Forward declarations
  57. //========================================================================================
  58.  
  59. #ifdef FW_BUILD_WIN16
  60. typedef HFILE FW_FileAccessHandle;
  61. #endif
  62.  
  63. #ifdef FW_BUILD_WIN32
  64. typedef HANDLE FW_FileAccessHandle;
  65. #endif
  66.  
  67. #ifdef FW_BUILD_MAC
  68. typedef short FW_FileAccessHandle;
  69. const OSType FW_kDefaultFileType = 'TEXT';
  70. const OSType FW_kDefaultCreatorType = 'ttxt';
  71. #endif
  72.  
  73. const FW_FileAccessHandle FW_kInvalidAccessHandle = (FW_FileAccessHandle)(-1);
  74. const long FW_kInvalidSeek = -1;
  75.  
  76.  
  77. //========================================================================================
  78. //    FW_CAccessPermission
  79. //
  80. //    Static class which defines some FWCommon file operations.  Should be nested inside of
  81. //    FW_PFile, but CFront was having troubles.
  82. //========================================================================================
  83.  
  84. class FW_CLASS_ATTR FW_CAccessPermission
  85. {
  86. public:
  87. #ifdef FW_BUILD_MAC
  88.     enum Access
  89.     {
  90.         kRead = fsRdPerm,
  91.         kWrite = fsWrPerm,
  92.         kReadWrite = fsRdWrPerm
  93.     };
  94.  
  95.     // Mac defines these constants as bit positions.
  96.     enum Deny
  97.     {
  98.         kDenyNone = 0x00,
  99.         kDenyRead = 0x10,
  100.         kDenyWrite = 0x20,
  101.         kDenyReadWrite = 0x30
  102.     };
  103. #endif
  104. #ifdef FW_BUILD_WIN16
  105.     enum Access
  106.     {
  107.         kRead = OF_READ,
  108.         kWrite = OF_WRITE,
  109.         kReadWrite = OF_READWRITE
  110.     };
  111.  
  112.  
  113.     enum Deny
  114.     {
  115.         kDenyNone = OF_SHARE_DENY_NONE,
  116.         kDenyRead = OF_SHARE_DENY_READ,
  117.         kDenyWrite = OF_SHARE_DENY_WRITE,
  118.         kDenyReadWrite = OF_SHARE_EXCLUSIVE
  119.     };
  120. #endif
  121.  
  122.  
  123. #ifdef FW_BUILD_WIN32
  124.     enum Access
  125.     {
  126.         kRead = GENERIC_READ,
  127.         kWrite = GENERIC_WRITE,
  128.         kReadWrite = GENERIC_READ | GENERIC_WRITE
  129.     };
  130.  
  131.  
  132.     enum Deny
  133.     {
  134.         kDenyNone = FILE_SHARE_READ | FILE_SHARE_WRITE,
  135.         kDenyRead = FILE_SHARE_WRITE,
  136.         kDenyWrite = FILE_SHARE_READ,
  137.         kDenyReadWrite = 0
  138.     };
  139. #endif
  140.  
  141.     FW_CAccessPermission(Access access = kReadWrite,
  142.                      Deny deny = kDenyReadWrite);
  143.         // Main constructor, sets up the specified access priveleges.  Default privelege
  144.         //   is exclusive read/write access.
  145.         
  146.     FW_CAccessPermission(const FW_CAccessPermission& permission);
  147.         // Copy constructor
  148.         
  149.     ~FW_CAccessPermission();
  150.     
  151.     
  152.     void GetPermission(Access& access,
  153.                         Deny& deny) const;
  154.         // Returns the priveleges this class specifies.
  155.         
  156.         
  157.     //===========================================================
  158.     // Operators
  159.     //===========================================================
  160.     
  161.     FW_CAccessPermission& operator=(const FW_CAccessPermission& permission);
  162.         // Assignment operator.
  163.         
  164.     FW_Boolean operator==(const FW_CAccessPermission& permission) const;
  165.         // Equality operator.
  166.         
  167.     FW_Boolean operator!=(const FW_CAccessPermission& permission) const;
  168.         // Inequality operator.
  169.  
  170. private:
  171.     Access fAccess;
  172.     Deny fDeny;
  173. };
  174.  
  175.  
  176. //========================================================================================
  177. //    FW_PFile
  178. //
  179. //    Static class which defines some FWCommon file operations.
  180. //========================================================================================
  181.  
  182. class FW_CLASS_ATTR FW_CFileSystem
  183. {
  184. public:    
  185.     typedef short FileError;
  186.  
  187.     static void CreateFile(const FW_CFileSpecification& fileSpec, FW_Boolean overWriteExisting = FALSE);
  188.         // Creates the file specified by fileSpec.  If the file already exists and 
  189.         //   overWriteExisting is TRUE, then the file will be truncated to zero-length.
  190.         //   Otherwise, the file will be left alone.
  191.  
  192.     static void DeleteFile(const FW_CFileSpecification& fileSpec);
  193.         // Deletes the file specified by fileSpec.  WARNING: This action cannot be undone.
  194.  
  195.     static void CreateDirectory(const FW_CDirectorySpecification& directory);
  196.         // Creates the directory specified by directory.  If the directory already
  197.         //   exists, then nothing is done.  
  198.         
  199.     static void DeleteDirectory(const FW_CDirectorySpecification& directory);
  200.         // Deletes the directory specified by directory.  This routine will only 
  201.         //   delete an empty directory.  The user must make sure that there are no
  202.         //   files left in the directory.  The directory must also not be the current
  203.         //   working directory for it to be deleted.  Use SetCurrentDirectory to set
  204.         //   another directory if this is the case.
  205.         
  206.     static void GetCurrentDirectory(FW_CDirectorySpecification& directory);
  207.         // Sets directory to point to the current default directory.
  208.  
  209.     static void SetCurrentDirectory(const FW_CDirectorySpecification& directory);
  210.         // Set the current working directory.
  211.     
  212.     static FW_Boolean IsValidDirectory(const FW_CDirectorySpecification& directory);
  213.         // Returns TRUE if the specified directory exists.
  214.     
  215.     static FW_Boolean IsValidDrive(const FW_CString& driveName);
  216.         // Returns TRUE if the specified drive exists.
  217.  
  218.     static FW_Boolean IsValidFile(const FW_CFileSpecification& theFile);
  219.         // Tests the existence of a file.
  220.     
  221. private:
  222. #ifdef FW_BUILD_WIN16
  223.     static FW_CFileSystem::FileError PrivWinPrimitiveSetCurrentDir(const FW_Char* dirName, 
  224.                                                                   short driveNumber);
  225.     static FW_CFileSystem::FileError PrivWinPrimitiveDeleteDir(const FW_Char* dirName);
  226.     static FW_CFileSystem::FileError PrivWinPrimitiveCreateDir(const FW_Char* dirName);
  227. #endif
  228.  
  229.     FW_CFileSystem() {}
  230.         // This is a package class.
  231.     
  232. public:
  233. #ifdef FW_BUILD_WIN
  234.     static FW_Boolean WinPathExists(const FW_CString& pathName);
  235.         // Tests the existence of a particular path and/or filename.  Paths should NOT
  236.         //   be terminated with a path delimiter.
  237. #endif
  238.  
  239.  
  240. #ifdef FW_BUILD_WIN16
  241.     enum MoveMethods
  242.     {
  243.         kFromStart = 0,
  244.         kFromCurrent = 1,
  245.         kFromEnd = 2
  246.     };
  247. #endif
  248.  
  249. #ifdef FW_BUILD_WIN32
  250.     enum MoveMethods
  251.     {
  252.         kFromStart = FILE_BEGIN,
  253.         kFromCurrent = FILE_CURRENT,
  254.         kFromEnd = FILE_END
  255.     };
  256. #endif
  257.  
  258.  
  259. #ifdef FW_BUILD_WIN16
  260.     enum FW_ErrorCodes
  261.     {
  262.         kNoError = 0, 
  263.         kBadFileName = 123,
  264.         kDirectoryBusy = 16,
  265.         kDirectoryFull = 82,
  266.         kDiskFull = 39,
  267.         kEndOfFileReached = 38,
  268.         kFileExists = 80,
  269.         kFileLocked = 33,
  270.         kNoFileFound = 2, 
  271.         kFileNotOpen = 1006, 
  272.         kGeneralIOError = 31,
  273.         kInvalidAccess = 12,
  274.         kInvalidFileReference = 6,
  275.         kNoSuchVolume = 15, 
  276.         kParameterError = 87,
  277.         kPathNotFound = 3, 
  278.         kPermissionError = 5,
  279.         kReadFault = 30,
  280.         kSeekError = 25,
  281.         kSharingViolation = 32,
  282.         kTooManyOpenFiles = 4,
  283.         kWriteFault = 29,
  284.         kWriteProtect = 19
  285.     };
  286. #endif
  287.  
  288. #ifdef FW_BUILD_WIN32
  289.     enum FW_ErrorCodes
  290.     {
  291.         kNoError = NO_ERROR, 
  292.         kBadFileName = ERROR_INVALID_NAME,
  293.         kDirectoryBusy = ERROR_CURRENT_DIRECTORY,
  294.         kDirectoryFull = ERROR_CANNOT_MAKE,
  295.         kDiskFull = ERROR_HANDLE_DISK_FULL,
  296.         kEndOfFileReached = ERROR_HANDLE_EOF,
  297.         kFileExists = ERROR_FILE_EXISTS,
  298.         kFileLocked = ERROR_LOCK_VIOLATION,
  299.         kNoFileFound = ERROR_FILE_NOT_FOUND, 
  300.         kFileNotOpen = ERROR_FILE_INVALID, 
  301.         kGeneralIOError = ERROR_GEN_FAILURE,
  302.         kInvalidAccess = ERROR_INVALID_ACCESS,
  303.         kInvalidFileReference = ERROR_INVALID_HANDLE,
  304.         kNoSuchVolume = ERROR_INVALID_DRIVE, 
  305.         kParameterError = ERROR_INVALID_PARAMETER,
  306.         kPathNotFound = ERROR_PATH_NOT_FOUND, 
  307.         kPermissionError = ERROR_ACCESS_DENIED,
  308.         kReadFault = ERROR_READ_FAULT,
  309.         kSeekError = ERROR_SEEK,
  310.         kSharingViolation = ERROR_SHARING_VIOLATION,
  311.         kTooManyOpenFiles = ERROR_TOO_MANY_OPEN_FILES,
  312.         kWriteFault = ERROR_WRITE_FAULT,
  313.         kWriteProtect = ERROR_WRITE_PROTECT
  314.     };
  315.     
  316.     
  317. #endif
  318.     
  319.  
  320. public:
  321. #ifdef FW_BUILD_MAC
  322.     enum MoveMethods
  323.     {
  324.         kFromStart = fsFromStart,
  325.         kFromCurrent = fsFromMark,
  326.         kFromEnd = fsFromLEOF
  327.     };
  328.  
  329.     enum FW_ErrorCodes
  330.     {
  331.         kNoError = noErr, 
  332.         kAFPAccessDenied = afpAccessDenied,
  333.         kAFPDenyConflict = afpDenyConflict,
  334.         kAFPObjectTypeErr = afpObjectTypeErr,
  335.         kBadFileName = bdNamErr,
  336.         kDirectoryBusy = fBsyErr,
  337.         kDirectoryFull = dirFulErr,
  338.         kDiskFull = dskFulErr,
  339.         kEndOfFileReached = eofErr,
  340.         kFileBusy = fBsyErr,
  341.         kFileExists = dupFNErr,
  342.         kFileLocked = fLckdErr,
  343.         kNoFileFound = fnfErr, 
  344.         kFileNotOpen = fnOpnErr,
  345.         kGeneralIOError = ioErr,
  346.         kGetFPosError = gfpErr,
  347.         kInvalidAccess = wrPermErr,
  348.         kInvalidFileReference = rfNumErr,
  349.         kNoSuchVolume = nsvErr, 
  350.         kNotAnHFSVolume = wrgVolTypErr,
  351.         kParameterError = paramErr,
  352.         kPathNotFound = dirNFErr, 
  353.         kPermissionError = permErr,
  354.         kRenameError = fsRnErr,
  355.         kSeekError = posErr,
  356.         kSharingViolation = opWrErr,
  357.         kTooManyOpenFiles = tmfoErr,
  358.         kVolumeLocked = vLckdErr,
  359.         kWriteProtect = wPrErr
  360.     };
  361.  
  362.     static FW_Boolean MacIsVolumeShared(short volumeRefNum);
  363.         // Returns TRUE if the volume specified by volumeRefNum 
  364. #endif
  365.  
  366. };
  367.  
  368. #if FW_LIB_EXPORT_PRAGMAS
  369. #pragma lib_export off
  370. #endif
  371.  
  372. #endif
  373.  
  374.  
  375.