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 / VVFileMacFile.cp < prev    next >
Encoding:
Text File  |  1995-07-28  |  5.6 KB  |  230 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        VVFileMacFile.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 __VVFILEMACFILE__
  23. #include "VVFileMacFile.h"
  24. #endif
  25.  
  26. #ifndef __VIRTUALFILE__
  27. #include "VirtualFile.h"
  28. #endif
  29.  
  30. #ifndef __VIRTUALRAMORDISKFILE__
  31. #include "VirtualRamOrDiskFile.h"
  32. #endif
  33.  
  34. #ifndef __UTILITIES__
  35. #include "Utilities.h"
  36. #endif
  37.  
  38. #ifndef    __DEBUGGINGGEAR__
  39. #include "DebuggingGear.h"
  40. #endif
  41.  
  42. #pragma segment TVVFileMacFile
  43.  
  44. /***********************************|****************************************/
  45.  
  46. TVVFileMacFile::TVVFileMacFile(const Str31 fileName):
  47.     TVirtualMacFile (),
  48.     fDataFile ( new TVirtualRamOrDiskFile () ),
  49.     fResourceFile ( new TVirtualRamOrDiskFile () ),
  50.     fCreationDate ( NowDateTime () ),
  51.     fRemoveRefs ( false ),
  52.     fOpenCount ( 0 )
  53. {
  54.     fSpec.vRefNum = -1;
  55.     fSpec.parID = 2;
  56.     SetFileName(fileName);
  57.     fFinderInfo.fdType = 'TEXT';
  58.     fFinderInfo.fdCreator = 'MPST';
  59. }
  60.  
  61. /***********************************|****************************************/
  62.  
  63. TVVFileMacFile::TVVFileMacFile(TVirtualFile* dfFile,TVirtualFile* rfFile,const Str31 fileName):
  64.     TVirtualMacFile (),
  65.     fDataFile ( dfFile ),
  66.     fResourceFile ( rfFile ),
  67.     fCreationDate ( NowDateTime () ),
  68.     fRemoveRefs ( true )
  69. {
  70.     fSpec.vRefNum = -1;
  71.     fSpec.parID = 2;
  72.     SetFileName(fileName);
  73.     fFinderInfo.fdType = 'TEXT';
  74.     fFinderInfo.fdCreator = 'MPST';
  75.     dfFile->RegisterReference();
  76.     rfFile->RegisterReference();
  77. }
  78.  
  79. //--------------------------------------------------------------------------------
  80.  
  81. TVVFileMacFile::~TVVFileMacFile()
  82. {
  83.     if ( fRemoveRefs )
  84.     {
  85.         fDataFile->UnregisterReference();
  86.         fResourceFile->UnregisterReference();
  87.     }
  88.     else
  89.     {
  90.         delete fDataFile;
  91.         delete fResourceFile;
  92.     }
  93. }
  94.  
  95. //--------------------------------------------------------------------------------
  96.  
  97. OSErr TVVFileMacFile::Open ()
  98. {
  99.     fOpenCount++;
  100.     if (fOpenCount == 1) {
  101.         fDataFile->SetPosition(fsFromStart, 0);
  102.         fResourceFile->SetPosition(fsFromStart, 0);
  103.     }
  104.     return noErr;
  105. }
  106.  
  107. //--------------------------------------------------------------------------------
  108.  
  109. OSErr TVVFileMacFile::Close ()
  110. {
  111.     if (fOpenCount <= 1) {
  112.         fOpenCount = 0;
  113.     }
  114.     return noErr;
  115. }
  116.  
  117. //--------------------------------------------------------------------------------
  118.  
  119. OSErr TVVFileMacFile::ReadData (void* buffer,long& count,TVirtualMacFile::ForkType whichFork)
  120. {
  121.     TVirtualFile* file = (whichFork == kData) ? fDataFile : fResourceFile;
  122.     return file->ReadData (buffer,count);
  123. }
  124.  
  125. //--------------------------------------------------------------------------------
  126.  
  127. OSErr TVVFileMacFile::WriteData (const void* buffer, long& count, TVirtualMacFile::ForkType whichFork)
  128. {
  129.     TVirtualFile* file = (whichFork == kData) ? fDataFile : fResourceFile;
  130.     return file->WriteData (buffer,count);
  131. }
  132.  
  133. //--------------------------------------------------------------------------------
  134.  
  135. OSErr TVVFileMacFile::SetEnd (long logEof, TVirtualMacFile::ForkType whichFork)
  136. {
  137.     TVirtualFile* file = (whichFork == kData) ? fDataFile : fResourceFile;
  138.     return file->SetEnd (logEof);
  139. }
  140.  
  141. //--------------------------------------------------------------------------------
  142.  
  143. OSErr TVVFileMacFile::GetEnd (long& logEof, TVirtualMacFile::ForkType whichFork) const
  144. {
  145.     TVirtualFile* file = (whichFork == kData) ? fDataFile : fResourceFile;
  146.     return file->GetEnd (logEof);
  147. }
  148.  
  149. //--------------------------------------------------------------------------------
  150.  
  151. OSErr TVVFileMacFile::SetPosition (short posMode, long posOff, TVirtualMacFile::ForkType whichFork)
  152. {
  153.     TVirtualFile* file = (whichFork == kData) ? fDataFile : fResourceFile;
  154.     return file->SetPosition (posMode,posOff);
  155. }
  156.  
  157. //--------------------------------------------------------------------------------
  158.  
  159. OSErr TVVFileMacFile::GetPosition (long& filePos,TVirtualMacFile::ForkType whichFork) const
  160. {
  161.     TVirtualFile* file = (whichFork == kData) ? fDataFile : fResourceFile;
  162.     return  file->GetPosition (filePos);
  163. }
  164.  
  165. //--------------------------------------------------------------------------------
  166.  
  167. OSErr TVVFileMacFile::SetFinderInfo (const FInfo& finderInfo)
  168. {
  169.     fFinderInfo = finderInfo;
  170.     return noErr;
  171. }
  172.  
  173. //--------------------------------------------------------------------------------
  174.  
  175. OSErr TVVFileMacFile::GetFinderInfo (FInfo& finderInfo) const
  176. {
  177.     finderInfo = fFinderInfo;
  178.     return noErr;
  179. }
  180.  
  181. //--------------------------------------------------------------------------------
  182.  
  183. OSErr TVVFileMacFile::GetDate (unsigned long& dateTime,TVirtualMacFile::WhichDateType) const
  184. {
  185.     dateTime =  fCreationDate;
  186.     return noErr;
  187. }
  188.  
  189. //--------------------------------------------------------------------------------
  190.  
  191. OSErr TVVFileMacFile::SetDate (unsigned long dateTime,TVirtualMacFile::WhichDateType whichDate)
  192. {
  193.     if  (whichDate == kCreationDate)
  194.         fCreationDate = dateTime;
  195.  
  196.     return noErr;
  197. }
  198.  
  199. //--------------------------------------------------------------------------------
  200.  
  201. void TVVFileMacFile::SetUserRef(long ref)
  202. {
  203.     fDataFile->SetUserRef(ref);
  204. }
  205.  
  206. //--------------------------------------------------------------------------------
  207.  
  208. long TVVFileMacFile::GetUserRef() const
  209. {
  210.     return fDataFile->GetUserRef();
  211. }
  212.  
  213. //--------------------------------------------------------------------------------
  214.  
  215. OSErr TVVFileMacFile::SetSpec ( const FSSpec& spec )
  216. {
  217.     fSpec = spec;
  218.     return noErr;
  219. }
  220.  
  221. //--------------------------------------------------------------------------------
  222.  
  223. OSErr TVVFileMacFile::GetSpec ( FSSpec& spec ) const
  224. {
  225.     spec = fSpec;
  226.     return noErr;
  227. }
  228.  
  229. /***********************************|****************************************/
  230.