home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / warphead.zip / H / PLFMFILE.H < prev    next >
C/C++ Source or Header  |  1997-02-28  |  17KB  |  429 lines

  1. //====START_GENERATED_PROLOG======================================
  2. //
  3. //
  4. //   COMPONENT_NAME: odutils
  5. //
  6. //   CLASSES:   PlatformFile
  7. //
  8. //   ORIGINS: 82,27
  9. //
  10. //
  11. //   (C) COPYRIGHT International Business Machines Corp. 1995,1996
  12. //   All Rights Reserved
  13. //   Licensed Materials - Property of IBM
  14. //   US Government Users Restricted Rights - Use, duplication or
  15. //   disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  16. //       
  17. //   IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  18. //   ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  19. //   PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  20. //   CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  21. //   USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  22. //   OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
  23. //   OR PERFORMANCE OF THIS SOFTWARE.
  24. //
  25. //====END_GENERATED_PROLOG========================================
  26. //
  27. // @(#) 1.25 com/src/utils/include/PlfmFile.h, odutils, od96os2, odos29646d 9/30/96 11:09:56 [ 11/15/96 15:29:01 ]
  28. /*
  29.     File:        PlatformFile.h
  30.  
  31.     Contains:    Template for PlatformFile header
  32.  
  33.     Owned by:    Vincent Lo
  34.  
  35.     Copyright:    ⌐ 1993 - 1995 by Apple Computer, Inc., all rights reserved.
  36.  
  37.     
  38.     In Progress:
  39.         
  40. */
  41.  
  42. #ifndef _PLFMFILE_
  43. #define _PLFMFILE_
  44.  
  45. #ifndef _ODTYPES_
  46. #include "ODTypes.h"
  47. #endif
  48. #if defined(_PLATFORM_WIN32_) || defined(_PLATFORM_OS2_) || defined(_PLATFORM_UNIX_)
  49. #ifndef _ODTYPESP_
  50. #include <ODTypesP.h>
  51. #endif
  52. #endif // defined(_PLATFORM_WIN32_) || defined(_PLATFORM_OS2_) || defined(_PLATFORM_UNIX_)
  53.  
  54. #ifndef _PLFMDEF_
  55. #include "PlfmDef.h"
  56. #endif
  57.  
  58. #ifndef _ODMEMORY_
  59. #include "ODMemory.h"
  60. #endif
  61.  
  62. #ifndef _ITEXT_
  63. #include "IText.h"        /* For ODScriptCode type */
  64. #endif
  65.  
  66. #if !defined(_PLATFORM_WIN32_) && !defined(_PLATFORM_OS2_) && !defined(_PLATFORM_UNIX_)
  67. #ifndef __FILES__
  68. #include <Files.h>
  69. #endif
  70. #endif // !defined(_PLATFORM_WIN32_) && !defined(_PLATFORM_OS2_) && !defined(_PLATFORM_UNIX_)
  71.  
  72. #if defined(_PLATFORM_WIN32_)
  73. #include <mapiwin.h>
  74. #include <wtypes.h>
  75. #include <winbase.h>
  76. #endif // defined(_PLATFORM_WIN32_)
  77.  
  78. #if defined(_PLATFORM_OS2_)
  79. #include <ODos2.h>
  80. #endif // defined(_PLATFORM_OS2_)
  81.  
  82. #if defined(_PLATFORM_UNIX_)
  83. #include <fcntl.h>
  84. #include <sys/mode.h>
  85. #include <sys/param.h>
  86. #endif // defined(_PLATFORM_UNIX_)
  87.  
  88. //==============================================================================
  89. // Theory of Operation
  90. //==============================================================================
  91.  
  92. //==============================================================================
  93. // Constants
  94. //==============================================================================
  95.  
  96. #if !defined(_PLATFORM_WIN32_) && !defined(_PLATFORM_OS2_) && !defined(_PLATFORM_UNIX_)
  97. const    ODSShort    kODNoFileRefNum         = 0;
  98. const    ODSShort    kODMaxFileNameSize        = 31;
  99. #else // defined(_PLATFORM_WIN32_) || defined(_PLATFORM_OS2_) || defined(_PLATFORM_UNIX_)
  100.  
  101. #if defined(_PLATFORM_WIN32_)
  102. typedef HANDLE    ODFileRefNum;
  103. const    ODFileRefNum kODNoFileRefNum = INVALID_HANDLE_VALUE;
  104. const    unsigned long    kODMaxFileNameSize = MAX_PATH;
  105. #endif // defined(_PLATFORM_WIN32_)
  106.  
  107. #if defined(_PLATFORM_OS2_)
  108. typedef HFILE     ODFileRefNum;
  109. const    ODFileRefNum kODNoFileRefNum = NULLHANDLE;
  110. const    unsigned long    kODMaxFileNameSize = CCHMAXPATH;
  111. #endif // defined(_PLATFORM_OS2_)
  112.  
  113. #if defined(_PLATFORM_UNIX_)
  114. typedef int     ODFileRefNum;
  115. const    ODFileRefNum kODNoFileRefNum = -1;
  116. const    unsigned long    kODMaxFileNameSize = MAXPATHLEN;
  117. #endif // defined(_PLATFORM_UNIX_)
  118.  
  119. #endif // !defined(_PLATFORM_WIN32_) && !defined(_PLATFORM_OS2_) && !defined(_PLATFORM_UNIX_)
  120.  
  121. //==============================================================================
  122. // Scalar Types
  123. //==============================================================================
  124.  
  125. typedef FSSpec        ODFileSpec;
  126. #if defined(_PLATFORM_WIN32_) || defined(_PLATFORM_OS2_) || defined(_PLATFORM_UNIX_)
  127. // Note: Keep in sync with ODTypesP.h
  128. #define kODFileRead  0x0001
  129. #define kODFileWrite 0x0002
  130. #define kODFileShareRead 0x0004
  131. #define kODFileShareWrite 0x0008
  132.  
  133. typedef unsigned long        ODFilePermission;
  134.  
  135. enum ODFilePosOptions {
  136.     kODSeekFromBeginning = fsFromStart,
  137.     kODSeekFromCurrent = fsFromMark,
  138.     kODSeekFromEnd = fsFromLEOF };
  139.  
  140. typedef unsigned long ODFileAttrFlags;
  141. #define kODFileAttrReadOnly  0x0001
  142.  
  143. #else // !defined(_PLATFORM_WIN32_) && !defined(_PLATFORM_OS2_) && !defined(_PLATFORM_UNIX_)
  144. typedef short        ODFileRefNum;
  145. typedef ODSByte        ODFilePermission;
  146.  
  147. typedef ODFileRefNum    *ODFileRefNumPtr;
  148. #endif // defined(_PLATFORM_WIN32_) || defined(_PLATFORM_OS2_) || defined(_PLATFORM_UNIX_)
  149.  
  150. #if !defined(_PLATFORM_WIN32_) && !defined(_PLATFORM_OS2_) && !defined(_PLATFORM_UNIX_)
  151. enum PFUniquifyAction { kSpecifyNewNameOnly, kRenameInPlace };
  152. #else // defined(_PLATFORM_WIN32_) || defined(_PLATFORM_OS2_) || defined(_PLATFORM_UNIX_)
  153. // No one uses kRenameInPlace on non-Mac Platforms.  Corresponding code removed.
  154. enum PFUniquifyAction { kSpecifyNewNameOnly };
  155. #endif // !defined(_PLATFORM_WIN32_) && !defined(_PLATFORM_OS2_) && !defined(_PLATFORM_UNIX_)
  156.  
  157. const    ODBoolean    kODTryCurrentName    = kODFalse;
  158. const    ODBoolean    kODForceNewName     = kODTrue;
  159.  
  160. const    ODSShort    kODNoResourceID = 0;
  161.  
  162. //==============================================================================
  163. // Classes defined in this interface
  164. //==============================================================================
  165.  
  166. class PlatformFile;
  167. #if !defined(_PLATFORM_WIN32_) && !defined(_PLATFORM_OS2_) && !defined(_PLATFORM_UNIX_)
  168. class CWithActiveResources;        // private class
  169. #endif // !defined(_PLATFORM_WIN32_) && !defined(_PLATFORM_OS2_) && !defined(_PLATFORM_UNIX_)
  170.  
  171.  
  172. //==============================================================================
  173. // PlatformFile
  174. //==============================================================================
  175.  
  176. class PlatformFile
  177. {    
  178. public:
  179.  
  180.     PlatformFile();
  181.    ~PlatformFile();
  182.  
  183. // Methods you can call when the file is not open:
  184.     // pointing the PlatformFile at a physical file    and setting default opening permissions
  185.     // Specify() can only be called once on the object. If it is being called more than once,
  186.     // the behavior is unpredictable. If you want to work with a different file,
  187.     // you need to delete the current object and create a new one. 
  188.     ODNVMethod    void        Specify(const ODFileSpec* fileSpec);
  189.     ODNVMethod    void        SpecifyFromFile(PlatformFile* file);
  190.     ODNVMethod    void        SetAsciiName(const char* name);
  191.     inline        void        SetPermission(ODFilePermission filePermission);
  192.     // create/open/delete the file
  193.     inline        void        SetFileRefNum( ODFileRefNum );
  194.     ODNVMethod    void        Create(ODOSType creator, ODOSType fileType, ODScriptCode scriptCode);
  195. #if defined(_PLATFORM_WIN32_) || defined(_PLATFORM_OS2_) || defined(_PLATFORM_UNIX_)
  196.     inline        ODFilePermission GetPermission();
  197.     ODNVMethod    void        UniquifyAndCreate(ODOSType creator, ODOSType fileType, ODScriptCode scriptCode,
  198.                                            short copyCount, ODBoolean forceNewName);
  199.     ODNVMethod    void        GetFileAttributes(ODFileAttrFlags *fAttr);
  200. #endif // defined(_PLATFORM_WIN32_) || defined(_PLATFORM_OS2_) || defined(_PLATFORM_UNIX_)
  201.     ODNVMethod    void        Open();
  202.     ODNVMethod    void        Delete();
  203.  
  204.     // These are optional and simply optimize multiple resource calls
  205. #if !defined(_PLATFORM_WIN32_) && !defined(_PLATFORM_OS2_) && !defined(_PLATFORM_UNIX_)
  206.     ODNVMethod    void        OpenResFile();
  207.     ODNVMethod    void        CloseResFile();
  208.     // create the resource fork (only to be used after Create).
  209.     ODNVMethod    void        CreateResFile();
  210. #endif // !defined(_PLATFORM_WIN32_) && !defined(_PLATFORM_OS2_) && !defined(_PLATFORM_UNIX_)
  211.  
  212. // Methods you can call anytime after calling Specify or SetAsciiName
  213.     ODNVMethod    ODBoolean    IsEqualTo(PlatformFile* file);
  214.     ODNVMethod    ODBoolean    IsLocked();
  215.     ODNVMethod    void        Lock();
  216.     ODNVMethod    void        Unlock();
  217. #if !defined(_PLATFORM_WIN32_) && !defined(_PLATFORM_OS2_) && !defined(_PLATFORM_UNIX_)
  218.     ODNVMethod    ODBoolean    IsStationery();
  219.     ODNVMethod    void        SetStationery(ODBoolean isStationery);
  220.     ODNVMethod    void        SetCustomIcon(ODBoolean hasCustomIcon);
  221.     ODNVMethod    ODBoolean    HasCustomIcon();
  222. #endif // !defined(_PLATFORM_WIN32_) && !defined(_PLATFORM_OS2_) && !defined(_PLATFORM_UNIX_)
  223.     ODNVMethod    ODBoolean    IsDirectory();
  224. #if !defined(_PLATFORM_WIN32_) && !defined(_PLATFORM_OS2_) && !defined(_PLATFORM_UNIX_)
  225.     ODNVMethod    void        SetCustomIconFamily(ODIconFamily icons);
  226.     ODNVMethod    ODIconFamily    GetCustomIconFamily();
  227. #endif // !defined(_PLATFORM_WIN32_) && !defined(_PLATFORM_OS2_) && !defined(_PLATFORM_UNIX_)
  228.     ODNVMethod    ODBoolean    Exists();
  229. #if !defined(_PLATFORM_WIN32_) && !defined(_PLATFORM_OS2_) && !defined(_PLATFORM_UNIX_)
  230.     ODNVMethod    ODUShort    GetFInfoFlags();
  231. #endif // !defined(_PLATFORM_WIN32_) && !defined(_PLATFORM_OS2_) && !defined(_PLATFORM_UNIX_)
  232.     
  233.  
  234. #if !defined(_PLATFORM_WIN32_) && !defined(_PLATFORM_OS2_) && !defined(_PLATFORM_UNIX_)
  235.     // Get & set the Desktop DB comment field
  236.     ODNVMethod    ODIText*    GetComments(ODIText* comments = kODNULL);
  237.     ODNVMethod    void        SetComments(ODIText* comments);
  238. #endif // !defined(_PLATFORM_WIN32_) && !defined(_PLATFORM_OS2_) && !defined(_PLATFORM_UNIX_)
  239.  
  240.  
  241.     ODNVMethod    void        FlushVolume();
  242.  
  243.     ODNVMethod    ODName*        GetName();
  244.     ODNVMethod    void        GetAsciiName(char* name,ODULong maxLength);
  245.     inline        ODULong        GetAsciiNameLength();
  246.     ODNVMethod    ODOSType    GetPlatformCreator();                    // Macintosh specific
  247.     ODNVMethod    ODOSType    GetPlatformType();                    // Macintosh specific
  248.     ODNVMethod    void        SetPlatformType(ODOSType fileType);    // Macintosh specific
  249. #if !defined(_PLATFORM_WIN32_) && !defined(_PLATFORM_OS2_) && !defined(_PLATFORM_UNIX_)
  250.     ODNVMethod    ODContainerType        GetContainerType();
  251.     ODNVMethod    void        SetContainerType(ODContainerType containerType);
  252.     ODNVMethod    ODPtr        ReadResourcePtr(ODPlatformType resType, ODSShort resID, ODULong* size); // Mac
  253.     ODNVMethod    void        WriteResourcePtr(ODPlatformType resType, ODSShort resID, 
  254.                                             const void *resPtr, ODULong size); // Mac
  255.     ODNVMethod    void        DeleteResource(ODPlatformType resType, ODSShort resID); // Mac
  256. #endif // !defined(_PLATFORM_WIN32_) && !defined(_PLATFORM_OS2_) && !defined(_PLATFORM_UNIX_)
  257.     inline        ODFileSpec&    GetFileSpec();
  258.     ODNVMethod    void        MoveRename( ODFileSpec* newSpec, ODBoolean isDuplicate ) ;
  259.     ODNVMethod    void        Move( ODSLong targetParID ) ;
  260.     ODNVMethod    void        UniquifyName( ODSShort uniquifyingStringID,
  261.                                             StringHandle uniquifyingString,
  262.                                             ODSShort uniquifyingNumberID,
  263.                                             StringHandle uniquifyingNumberString,
  264.                                             short copyCount,
  265.                                             PFUniquifyAction action,
  266.                                             ODBoolean forceNewName);
  267. #if !defined(_PLATFORM_WIN32_) && !defined(_PLATFORM_OS2_) && !defined(_PLATFORM_UNIX_)
  268.     ODNVMethod    void        MoveToTrash() ;
  269.     ODNVMethod    void        Rename( Str63 name ) ;
  270. #else // defined(_PLATFORM_WIN32_) || defined(_PLATFORM_OS2_) || defined(_PLATFORM_UNIX_)
  271.     ODNVMethod    void        Rename( ODFilePathname name ) ;
  272. #endif // !defined(_PLATFORM_WIN32_) && !defined(_PLATFORM_OS2_) && !defined(_PLATFORM_UNIX_)
  273.     ODNVMethod    ODTime        GetFileModDate();
  274.     ODNVMethod    void        SetFileModDate(ODTime date);
  275.     ODNVMethod    ODTime        GetFileCreationDate();
  276.     ODNVMethod    void        SetFileCreationDate(ODTime date);
  277.     ODNVMethod    ODULong     GetAllocationBlockSize();
  278. #if !defined(_PLATFORM_WIN32_) && !defined(_PLATFORM_OS2_) && !defined(_PLATFORM_UNIX_)
  279.     ODNVMethod    void        BumpFolderModDate();
  280.     
  281.     ODNVMethod    ODBoolean    IsInTrash( );
  282. #endif // !defined(_PLATFORM_WIN32_) && !defined(_PLATFORM_OS2_) && !defined(_PLATFORM_UNIX_)
  283.  
  284. // Methods you must call while the file is open    
  285.     ODNVMethod    void        Close();
  286.  
  287.     ODNVMethod    void        SetFilePos(ODSShort posMode, ODSLong posOff);
  288.     ODNVMethod    ODSLong        GetFilePos();
  289.  
  290.     ODNVMethod    void        Read(void* buffer, ODSLong* count);
  291.     ODNVMethod    void        Write(const void* buffer, ODSLong* count);
  292.  
  293.     ODNVMethod    ODSLong        GetEndOfFile();
  294.     ODNVMethod    void        SetEndOfFile(ODSLong length);
  295.  
  296.     inline        ODFileRefNum    GetFileRefNum();
  297.  
  298.     ODNVMethod    void        CopyFrom( PlatformFile* src );
  299.         
  300.  
  301. private:
  302. #if !defined(_PLATFORM_WIN32_) && !defined(_PLATFORM_OS2_) && !defined(_PLATFORM_UNIX_)
  303.     /* Constants to specify the file fork GetLocalPaths should match */
  304.     enum
  305.     {
  306.         kODDataFork        = 0,
  307.         kODResourceFork    = 1
  308.     };
  309.     typedef short ODForkType;
  310.     
  311.     ODNVMethod    void        GetFileID( );
  312.     ODNVMethod    void        UpdateSpecFromID( );
  313.     ODNVMethod    ODBoolean    ActivateResourceFile( ODBoolean &needToCloseResFile );
  314.     
  315.     ODNVMethod    ODFileRefNum GetFirstLocalPath( ODForkType fork );
  316.  
  317.  
  318. public:
  319.     ODNVMethod    ODError        GetLocalPaths(
  320.                               ODForkType fork,
  321.                               ODULong *refNumCount,
  322.                               ODFileRefNumPtr *refNums);
  323.  
  324. /*    Determine if local access paths to a file fork are open.
  325.     The GetLocalPaths function looks through the FCB list to see if
  326.     the fork of the file specified by spec and fork is open by the 
  327.     local File Manager (you should use PBGetCatInfo and check
  328.     ioFlAttrib if you need to see if *anyone* has the file fork open
  329.     *anywhere*). If the result is noErr, GetLocalPaths returns a
  330.     count and a pointer to an array of file refNums (if count is
  331.     not zero) of local access paths to the specified file fork.
  332.  
  333.     spec        input:    An FSSpec record specifying the file.
  334.     fork        input:    Specifies the file fork - either kDataFork
  335.                         or kResourceFork.
  336.     refNumCount    output:    The number of local access paths found.
  337.     refNums        output: If not NULL, a pointer to an array of
  338.                         file refNums - the number of which is
  339.                         specified by refNumCount.  The caller is
  340.                         responsible for disposing of this pointer.
  341. */
  342. #else // defined(_PLATFORM_WIN32_) || defined(_PLATFORM_OS2_) || defined(_PLATFORM_UNIX_)
  343.     ODNVMethod    void    ConcatenateSuffix(ODFilePathname filePathname, char *suffixString);
  344. #if defined(_PLATFORM_WIN32_)
  345.     ODNVMethod    DWORD    ConvertFromFileTime(LPFILETIME fileTime, ODTime *odTime);
  346.     ODNVMethod    DWORD ConvertToFileTime(ODTime odTime, LPFILETIME fileTime);
  347. #endif // defined(_PLATFORM_WIN32_)
  348. #if defined(_PLATFORM_OS2_)
  349.     ODNVMethod    unsigned long    ConvertFromFileTime(FDATE *fileDate, FTIME *fileTime,
  350.                                                    ODTime *odTime);
  351.     ODNVMethod    unsigned long    ConvertToFileTime(ODTime odTime,
  352.                                                  FDATE *fileDate, FTIME *fileTime);
  353. #endif // defined(_PLATFORM_OS2_)
  354. #endif // !defined(_PLATFORM_WIN32_) && !defined(_PLATFORM_OS2_) && !defined(_PLATFORM_UNIX_)
  355.  
  356. private:
  357.  
  358.     ODFileSpec            fFileSpec;
  359. #if !defined(_PLATFORM_WIN32_) && !defined(_PLATFORM_OS2_) && !defined(_PLATFORM_UNIX_)
  360.     ODSShort            fDataRefNum;
  361. #else // defined(_PLATFORM_WIN32_) || defined(_PLATFORM_OS2_) || defined(_PLATFORM_UNIX_)
  362.     ODFileRefNum    fDataRefNum;
  363.     ODFilePermission    fOpenPermission;  // Permissions actually used for file open.
  364.                                         // fPermission could theoretically be changed
  365.                                         // by user when file is already open.
  366. #endif // !defined(_PLATFORM_WIN32_) && !defined(_PLATFORM_OS2_) && !defined(_PLATFORM_UNIX_)
  367.     ODFilePermission    fPermission;
  368. #if !defined(_PLATFORM_WIN32_) && !defined(_PLATFORM_OS2_) && !defined(_PLATFORM_UNIX_)
  369.     ODContainerType        fContainerType;
  370. #endif // !defined(_PLATFORM_WIN32_) && !defined(_PLATFORM_OS2_) && !defined(_PLATFORM_UNIX_)
  371.     ODOSType            fCreator;
  372.     ODOSType            fFileType;
  373.     ODScriptCode        fScriptTag;
  374. #if !defined(_PLATFORM_WIN32_) && !defined(_PLATFORM_OS2_) && !defined(_PLATFORM_UNIX_)
  375.     ODULong                fFileID;
  376.     ODULong                fVolModDate;
  377.     ODULong                fTimeLastChecked;
  378.     ODFileRefNum        fResRefNum;
  379.     ODULong                fResOpenStack;
  380.     ODBoolean            fNeedToClose;
  381.     
  382.     friend class CWithActiveResources;
  383. #endif // !defined(_PLATFORM_WIN32_) && !defined(_PLATFORM_OS2_) && !defined(_PLATFORM_UNIX_)
  384.  
  385. };
  386.  
  387.  
  388. //------------------------------------------------------------------------------
  389. // Inline method bodies
  390. //------------------------------------------------------------------------------
  391.  
  392.  
  393. inline ODULong PlatformFile::GetAsciiNameLength()
  394. {
  395.     return fFileSpec.name[0];
  396. }
  397.  
  398. void PlatformFile::SetPermission(ODFilePermission permission)
  399. {
  400.     fPermission = permission;
  401. }
  402.  
  403. #if defined(_PLATFORM_WIN32_) || defined(_PLATFORM_OS2_) || defined(_PLATFORM_UNIX_)
  404.  
  405. ODFilePermission PlatformFile::GetPermission()
  406. {
  407.     return fPermission;
  408. }
  409. #endif // defined(_PLATFORM_WIN32_) || defined(_PLATFORM_OS2_) || defined(_PLATFORM_UNIX_)
  410.  
  411. inline ODFileSpec& PlatformFile::GetFileSpec()
  412. {
  413.     return fFileSpec;
  414. }
  415.  
  416. inline ODFileRefNum PlatformFile::GetFileRefNum()
  417. {
  418.     return fDataRefNum;
  419. }
  420.  
  421. inline void PlatformFile::SetFileRefNum( ODFileRefNum refNum )
  422. {
  423.     fDataRefNum = refNum;
  424. }
  425.  
  426.  
  427.  
  428. #endif // _PLFMFILE_
  429.