home *** CD-ROM | disk | FTP | other *** search
/ Media Share 13 / mediashare_13.zip / mediashare_13 / ZIPPED / PROGRAM / WTJ9403.ZIP / WILDASS / SOURCE / GRPFILE.CPP < prev    next >
C/C++ Source or Header  |  1993-08-13  |  2KB  |  131 lines

  1. #include <afxwin.h>
  2. #include <afxext.h> 
  3. #include <ctl3d.h>
  4.  
  5. #include "grpfile.h"
  6.    
  7. ProgramMgrGroup::ProgramMgrGroup( const char * pszSrc )      
  8. {
  9.    CFile aFile( pszSrc, CFile::modeRead );
  10.    
  11.    // read the header
  12.    GROUPHEADER gh;
  13.    aFile.Read( &gh, sizeof(GROUPHEADER) );
  14.  
  15.    // read the name
  16.    aFile.Seek( gh.pName, CFile::begin );
  17.  
  18.    while ( TRUE )
  19.    {
  20.       char aChar;  
  21.       aFile.Read( &aChar, sizeof(char) );
  22.       
  23.       if ( aChar != '\0' )
  24.          m_strName += aChar;
  25.       else
  26.          break;
  27.    }     
  28.    
  29.    // ok. now lets read the items
  30.    
  31.    // allocate memory to holf the offsetes to the
  32.    // itemdata entries
  33.    WORD * pOffset = new WORD[gh.cItems];
  34.    
  35.    // read the offsets
  36.    aFile.Seek( sizeof(GROUPHEADER), CFile::begin );
  37.    aFile.Read( pOffset, gh.cItems*sizeof(WORD) );
  38.  
  39.    // iterate the items.
  40.    // take care of invalid items; these don`t hva
  41.    // an offset, but instead windows puts an 
  42.    // 0 in the array of offsets      
  43.    
  44.    for( WORD iItems = 0; iItems<gh.cItems; iItems++ )
  45.    {  
  46.       if ( ! pOffset[iItems] )
  47.          continue;
  48.       else         
  49.       {
  50.          ProgramMgrItem * pItem = new ProgramMgrItem( aFile, pOffset[iItems] );
  51.          AddTail( pItem );
  52.       }
  53.    }   
  54.    
  55.    // free the tmp buffer
  56.    delete [] pOffset;
  57. }     
  58.  
  59. ProgramMgrGroup::~ProgramMgrGroup()
  60. {
  61.    for ( POSITION pos=GetHeadPosition(); pos!=NULL; )
  62.    {
  63.       delete GetNext( pos );
  64.    }
  65. }
  66.  
  67. const char *
  68. ProgramMgrGroup::Name() const
  69. {
  70.    return m_strName;
  71. }
  72.  
  73. // items
  74. ProgramMgrItem::ProgramMgrItem( CFile& rFile, WORD cbOffset )
  75. {  
  76.    rFile.Seek( cbOffset, CFile::begin );
  77.    
  78.    ITEMDATA id;
  79.    rFile.Read( &id, sizeof(ITEMDATA) );
  80.    rFile.Seek( id.pName, CFile::begin );
  81.    // read the items name
  82.    while ( TRUE )
  83.    {  
  84.       char aChar;
  85.       rFile.Read( &aChar, sizeof(char) );
  86.       
  87.       if ( aChar != '\0' )
  88.          m_strName += aChar;
  89.       else
  90.          break;
  91.    }  
  92.    
  93.    // read the items command
  94.    rFile.Seek( id.pCommand, CFile::begin );
  95.    while ( TRUE )
  96.    {  
  97.       char aChar;
  98.       rFile.Read( &aChar, sizeof(char) );
  99.       
  100.       if ( aChar != '\0' )
  101.          m_strPath += aChar;
  102.       else
  103.          break;
  104.    }  
  105. }
  106.  
  107. const char *
  108. ProgramMgrItem::Name() const
  109. {  
  110.    return m_strName;
  111. }
  112.       
  113. const char *
  114. ProgramMgrItem::Path() const
  115. {
  116.    return m_strPath;
  117. }
  118.               
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.