Logo Search packages:      
Sourcecode: xchm version File versions

bool CHMFile::LoadContextIDs (  ) 

Attempts to build an index of context-ID/page pairs from the file.

Returns:
true if it's possible to buld the tree, false otherwise.

Definition at line 205 of file chmfile.cpp.

Referenced by LoadCHM().

{
      chmUnitInfo ivb_ui, strs_ui;

      _cidMap.clear();

      // make sure what we need is there. 
      // #IVB has list of context ID's and #STRINGS offsets to file names.
      if( chm_resolve_object(_chmFile, "/#IVB", &ivb_ui ) != 
                        CHM_RESOLVE_SUCCESS ||
            chm_resolve_object(_chmFile, "/#STRINGS", &strs_ui) != 
                        CHM_RESOLVE_SUCCESS )
            return false; // failed to find internal files
      
      UCharPtr ivb_buf(new unsigned char[ivb_ui.length]);
      u_int64_t ivb_len = 0;

      if((ivb_len = chm_retrieve_object(_chmFile, &ivb_ui, 
                                ivb_buf.get(), 0, 
                                ivb_ui.length)) == 0 )
            return false; // failed to retrieve data

      // always odd (DWORD + 2(n)*DWORD, so make even
      ivb_len = ivb_len/sizeof(u_int32_t) - 1; 
      
      if( ivb_len % 2 != 0 )
            return false; // we retrieved unexpected data from the file.

      u_int32_t *ivbs = new u_int32_t[ivb_len];
      int j = 4; // offset to exclude first DWORD
      
      // convert our DWORDs to numbers
      for( unsigned int i = 0; i < ivb_len; i++ )
      {
            ivbs[i] = UINT32ARRAY(ivb_buf.get() + j);
            j+=4; // step to the next DWORD
      }

      UCharPtr strs_buf(new unsigned char[strs_ui.length]);
      u_int64_t strs_len = 0;

      if( (strs_len = chm_retrieve_object(_chmFile, &strs_ui, 
                                  strs_buf.get(), 
                                  0, strs_ui.length)) == 0 ) {
            delete[] ivbs;
            return false; // failed to retrieve data
      }

      for( unsigned int i = 0; i < ivb_len; i+=2 )
      {     // context-IDs as KEY, fileName from #STRINGS as VALUE
            _cidMap[ivbs[i]] = CURRENT_CHAR_STRING(
                  strs_buf.get() + ivbs[i+1]);
      }

      delete[] ivbs;
      
      // everything went well!
      return true;
}


Generated by  Doxygen 1.6.0   Back to index