home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Sample Code / AOCE Sample Code / PowerTalk Access Modules / Sample SMSAM / SampleSMSAM Source / VirtualFile / VirtualDataForkOnlyFile.cp < prev    next >
Encoding:
Text File  |  1995-07-28  |  6.4 KB  |  268 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        VirtualDataForkOnlyFile.cp
  3.  
  4.     Copyright:    © 1991-1994 by Apple Computer, Inc.
  5.                 All rights reserved.
  6.  
  7.     Part of the AOCE Sample SMSAM Package.  Consult the license
  8.     which came with this software for your specific legal rights.
  9.  
  10. */
  11.  
  12.  
  13.  
  14. #ifndef __BLJSTANDARDINCLUDES__
  15. #include "BLJStandardIncludes.h"
  16. #endif
  17.  
  18. #ifndef __VIRTUALMACFILE__
  19. #include "VirtualMacFile.h"
  20. #endif
  21.  
  22. #ifndef __ERRORS__
  23. #include <Errors.h>
  24. #endif
  25.  
  26. #ifndef __VIRTUALRAMORDISKFILE__
  27. #include "VirtualRamOrDiskFile.h"
  28. #endif
  29.  
  30. #ifndef __VIRTUALDATAFORKONLYFILE__
  31. #include "VirtualDataForkOnlyFile.h"
  32. #endif
  33.  
  34. #ifndef __VIRTUALFILE__
  35. #include "VirtualFile.h"
  36. #endif
  37.  
  38. #ifndef __UTILITIES__
  39. #include "Utilities.h"
  40. #endif
  41.  
  42. #ifndef    __DEBUGGINGGEAR__
  43. #include "DebuggingGear.h"
  44. #endif
  45.  
  46. #pragma segment TVirtualDataForkOnlyFile
  47.  
  48. /***********************************|****************************************/
  49.  
  50. TVirtualDataForkOnlyFile::TVirtualDataForkOnlyFile(const Str31 fileName, OSType creator, OSType type):
  51.     TVirtualMacFile (),
  52.     fDataFile ( new TVirtualRamOrDiskFile () ),
  53.     fCreationDate ( NowDateTime () ),
  54.     fModificationDate ( NowDateTime() ),
  55.     fOpenCount ( 0 )
  56. {
  57.     fSpec.vRefNum = -1;
  58.     fSpec.parID = 2;
  59.     SetFileName(fileName);
  60.  
  61.     fFinderInfo.fdType = type;
  62.     fFinderInfo.fdCreator = creator;
  63.     fFinderInfo.fdFlags = 0;
  64.     fFinderInfo.fdLocation.h = fFinderInfo.fdLocation.v = 0;
  65.     fFinderInfo.fdFldr = 0;
  66.  
  67.     fDataFile->RegisterReference();
  68. }
  69.  
  70. /***********************************|****************************************/
  71.  
  72. TVirtualDataForkOnlyFile::TVirtualDataForkOnlyFile(const Str31 fileName, TVirtualFile* dataFile, OSType creator, OSType type ):
  73.     TVirtualMacFile (),
  74.     fDataFile ( dataFile ),
  75.     fCreationDate ( NowDateTime () ),
  76.     fModificationDate ( NowDateTime() ),
  77.     fOpenCount ( 0 )
  78. {
  79.     fSpec.vRefNum = -1;
  80.     fSpec.parID = 2;
  81.     SetFileName(fileName);
  82.  
  83.     fFinderInfo.fdType = type;
  84.     fFinderInfo.fdCreator = creator;
  85.     fFinderInfo.fdFlags = 0;
  86.     fFinderInfo.fdLocation.h = fFinderInfo.fdLocation.v = 0;
  87.     fFinderInfo.fdFldr = 0;
  88.     
  89.     fDataFile->RegisterReference();
  90. }
  91.  
  92. /***********************************|****************************************/
  93.  
  94. TVirtualDataForkOnlyFile::~TVirtualDataForkOnlyFile()
  95. {
  96.     fDataFile->UnregisterReference();
  97. }
  98.  
  99. /***********************************|****************************************/
  100.  
  101. OSErr TVirtualDataForkOnlyFile::Open ()
  102. {
  103.     fOpenCount++;
  104.     if (fOpenCount == 1) {
  105.         fDataFile->SetPosition(fsFromStart, 0);
  106.     }
  107.     return noErr;
  108. }
  109.  
  110. /***********************************|****************************************/
  111.  
  112. OSErr TVirtualDataForkOnlyFile::Close ()
  113. {
  114.     if (fOpenCount <= 1) {
  115.         fOpenCount = 0;
  116.     }
  117.     return noErr;
  118. }
  119.  
  120. /***********************************|****************************************/
  121.  
  122. OSErr TVirtualDataForkOnlyFile::ReadData (void* buffer,long& count,TVirtualMacFile::ForkType whichFork)
  123. {    OSErr err;
  124.     if (whichFork == kData)
  125.         err = fDataFile->ReadData (buffer,count);
  126.     else
  127.         err = (count > 0) ? eofErr : noErr;
  128.     return err;
  129. }
  130.  
  131. /***********************************|****************************************/
  132.  
  133. OSErr TVirtualDataForkOnlyFile::WriteData (const void* buffer, long& count, TVirtualMacFile::ForkType whichFork)
  134. {    OSErr err;
  135.     if (whichFork == kData)
  136.         err = fDataFile->WriteData (buffer,count);
  137.     else
  138.         err = (count > 0) ? posErr : noErr;
  139.     return err;
  140. }
  141.  
  142. /***********************************|****************************************/
  143.  
  144. OSErr TVirtualDataForkOnlyFile::SetEnd (long logEof, TVirtualMacFile::ForkType whichFork)
  145. {    OSErr err;
  146.     if (whichFork == kData)
  147.         err = fDataFile->SetEnd ( logEof );
  148.     else
  149.         err = (logEof != 0) ? posErr : noErr;
  150.     return err;
  151. }
  152.  
  153. /***********************************|****************************************/
  154.  
  155. OSErr TVirtualDataForkOnlyFile::GetEnd (long& logEof, TVirtualMacFile::ForkType whichFork) const
  156. {    OSErr err;
  157.     if (whichFork == kData)
  158.         err = fDataFile->GetEnd ( logEof );
  159.     else {
  160.         logEof = 0;
  161.         err = noErr;
  162.     }
  163.     return err;
  164. }
  165.  
  166. /***********************************|****************************************/
  167.  
  168. OSErr TVirtualDataForkOnlyFile::SetPosition (short posMode, long posOff, TVirtualMacFile::ForkType whichFork)
  169. {
  170.     OSErr err;
  171.     if (whichFork == kData)
  172.         err = fDataFile->SetPosition (posMode,posOff);
  173.     else {
  174.         err = posErr;
  175.         if (posMode == fsFromStart)
  176.             err = (posOff == 0) ? noErr : posErr;
  177.         else if (posMode == fsFromMark)
  178.             err = (posOff == 0) ? noErr : posErr;
  179.         else if (posMode == fsFromLEOF)
  180.             err = (posOff == 0) ? noErr : posErr;
  181.     }
  182.     return err;
  183. }
  184.  
  185. /***********************************|****************************************/
  186.  
  187. OSErr TVirtualDataForkOnlyFile::GetPosition (long& filePos, TVirtualMacFile::ForkType whichFork) const
  188. {
  189.     OSErr err;
  190.     if (whichFork == kData)
  191.         err = fDataFile->GetPosition ( filePos );
  192.     else {
  193.         filePos = 0;
  194.         err = noErr;
  195.     }
  196.     return err;
  197. }
  198.  
  199. /***********************************|****************************************/
  200.  
  201. OSErr TVirtualDataForkOnlyFile::SetFinderInfo (const FInfo& finderInfo)
  202. {
  203.     fFinderInfo = finderInfo;
  204.     return noErr;
  205. }
  206.  
  207. /***********************************|****************************************/
  208.  
  209. OSErr TVirtualDataForkOnlyFile::GetFinderInfo (FInfo& finderInfo) const
  210. {
  211.     finderInfo = fFinderInfo;
  212.     return noErr;
  213. }
  214.  
  215. /***********************************|****************************************/
  216.  
  217. OSErr TVirtualDataForkOnlyFile::GetDate (unsigned long& dateTime,TVirtualMacFile::WhichDateType whichDate) const
  218. {
  219.     if (whichDate == kCreationDate)
  220.         dateTime =  fCreationDate;
  221.     else
  222.         dateTime = fModificationDate;
  223.     return noErr;
  224. }
  225.  
  226. /***********************************|****************************************/
  227.  
  228. OSErr TVirtualDataForkOnlyFile::SetDate (unsigned long dateTime,TVirtualMacFile::WhichDateType whichDate)
  229. {
  230.     if  (whichDate == kCreationDate)
  231.         fCreationDate = dateTime;
  232.     else fModificationDate = dateTime;
  233.  
  234.     return noErr;
  235. }
  236.  
  237. /***********************************|****************************************/
  238.  
  239. void TVirtualDataForkOnlyFile::SetUserRef(long ref)
  240. {
  241.     fDataFile->SetUserRef(ref);
  242. }
  243.  
  244. /***********************************|****************************************/
  245.  
  246. long TVirtualDataForkOnlyFile::GetUserRef() const
  247. {
  248.     return fDataFile->GetUserRef();
  249. }
  250.  
  251. /***********************************|****************************************/
  252.  
  253. OSErr TVirtualDataForkOnlyFile::SetSpec ( const FSSpec& spec )
  254. {
  255.     fSpec = spec;
  256.     return noErr;
  257. }
  258.  
  259. /***********************************|****************************************/
  260.  
  261. OSErr TVirtualDataForkOnlyFile::GetSpec ( FSSpec& spec ) const
  262. {
  263.     spec = fSpec;
  264.     return noErr;
  265. }
  266.  
  267. /***********************************|****************************************/
  268.