static AudErrorCode MDReadAAFileSections( IAudibleInputStream *pFile, CAudibleAAInternal *pAudData ) 

{//-- Read sections. We do not read sections with ID more than MAX_SECTION_COUNT. 
//   We also do not read more than MAX_SECTION_COUNT sections
//  sectionCount = sectionCount < MAX_SECTION_COUNT < sectionCount
//--  Read number of entires in section table.
  unsigned long sectionCount; 
  if ( !ReadULong( pFile, &sectionCount ) )  { return AUD_FILE_READ_FAIL; }
//--  Read DUMMY, This way we skip 4 bytes. Use scope to get rid of extra local var.
  { unsigned long dummy;
    ReadULong( pFile, &dummy );
  }
  { unsigned short i;
    for ( i = 0; i < sectionCount; i++ )
    { unsigned long sectionID = 0;
      unsigned long sectionStarts = 0;
      unsigned long sectionLenghts   = 0;
      BOOL errSectionEntry = 
      ReadULong( pFile, &sectionID ) && ReadULong( pFile, &sectionStarts ) && ReadULong( pFile, &sectionLenghts );
      if ( !errSectionEntry )
      { return AUD_FILE_READ_FAIL;
      }
  //---- Put section ID if it fits into MAX_SECTION_COUNT
      if ( sectionID > 0 && sectionID <  MAX_SECTION_COUNT )
      { pAudData->audSections[sectionID].sectionID    = sectionID;
        pAudData->audSections[sectionID].sectionStart = sectionStarts;
        pAudData->audSections[sectionID].sectionLength   = sectionLenghts;
      }
    }
    return AUD_NO_ERROR; 
  }
}
static AudErrorCode MDReadAudibleSpecificHeader( IAudibleInputStream *pFile, CAudibleSpecificHeader *pSpecificHead, long sectionSize )

{ BOOL readRes =  
    ReadUShort( pFile, &pSpecificHead->hashTableVersion )                                                             &&
    AUD_NO_ERROR == pFile->pVTable->Read( pFile, pSpecificHead->szTitleID,        sizeof( pSpecificHead->szTitleID ), NULL        ) &&
    AUD_NO_ERROR == pFile->pVTable->Read( pFile, pSpecificHead->digitalSignature, sizeof( pSpecificHead->digitalSignature ), NULL ) &&
    ReadULong( pFile, &pSpecificHead->audioSizeBytes )                                                                &&
    ReadULong( pFile, &pSpecificHead->audioTimeSeconds )                                                              &&
    ReadULong( pFile, &pSpecificHead->hashBlockSize    )                                                              &&
    ReadULong( pFile, &pSpecificHead->unused );
//----------------  
  if ( !readRes )
  { return AUD_FILE_READ_FAIL;
  }
  return AUD_NO_ERROR;
}
コード例 #3
0
ファイル: ISmb.cpp プロジェクト: FEI17N/Lgi
	bool Read()
	{
		Conn->Read((char*) Protocol, sizeof(Protocol), 0);
		Command = ReadUShort();
		Status.Status = ReadULong();
		Flags = ReadUChar();
		Flags2 = ReadUShort();
		Conn->Read((char*) Pad, sizeof(Pad), 0);
		Tid = ReadUShort();
		Pid = ReadUShort();
		Uid = ReadUShort();
		Mid = ReadUShort();
		
		WordCount = ReadUChar();
		DeleteArray(ParameterWords);
		ParameterWords = new ushort[WordCount];
		if (ParameterWords)
		{
			Conn->Read((char*) ParameterWords, sizeof(ushort)*WordCount, 0);
		}

		ByteCount = ReadUChar();
		DeleteArray(Buffer);
		Buffer = new uchar[ByteCount];
		if (Buffer)
		{
			Conn->Read((char*) Buffer, sizeof(uchar)*ByteCount, 0);
		}

		return true;
	}
コード例 #4
0
ファイル: inifiles.cpp プロジェクト: gkathire/wxVCL
wxDateTime TIniFile::ReadULongDateTime(const wxString &Section,
  const wxString &Ident, wxDateTime Default)
{
	unsigned long WxTicks = ReadULong(Section, Ident, Default.GetTicks());
	wxDateTime Result((time_t)WxTicks);
	return Result;
}
static AudErrorCode MDValidateAAFileHeader( IAudibleInputStream *pFile) 

{//--------- Position is already on zero. 
//--  Read file size 
  unsigned long fileSize;
  if ( !ReadULong( pFile, &fileSize ) )      { return AUD_FILE_READ_FAIL; };
//--  Read Magic number. 
  { unsigned long magicNumber;
    if ( !ReadULong( pFile, &magicNumber ) )   { return AUD_FILE_READ_FAIL; }
  //--   Compare magic number and file size with actual one.
    { unsigned long actualfileSize = pFile->pVTable->GetFileSize( pFile );
      if ( actualfileSize != fileSize )
      { return AUD_AA_FILE_TRUNCATED;
      }
      if ( magicNumber != 0x57907536 )
      { return AUD_NOT_AUDIBLE_FILE;
      }
      return AUD_NO_ERROR; 
    }
  }  
}
AudErrorCode MDReadAudibleIDList( IAudibleInputStream *pFile, CAudibleGroupOrPlayer_IDList *pIDList, long sectionSize )

{ int i;
  long temp;
//  BOOL readRes = ReadLong( pFile, &pIDList->idCount );
  BOOL readRes = ReadLong( pFile, &temp );
//---------------- Fail to read - return error. 
  if ( !readRes )
  { return AUD_FILE_READ_FAIL;
  }
  pIDList->idCount = temp;
//---------------- Size of section should be equal to 4 + pIDList->idCount * 4
  if ( sectionSize != 4 + pIDList->idCount * 4 )
  { return AUD_AA_FILE_BAD_FORMAT;
  }  
//--------- If count is less than fits to embedded array - then we leave it inside, otherwise dynamically allocate  
  if ( pIDList->idCount < sizeof( pIDList->idList ) / sizeof( pIDList->idList[0] ) )
  { pIDList->pIDsArray = pIDList->idList;
  }
  else
  { pIDList->pIDsArray = (unsigned long *)Audible_malloc( pIDList->idCount );
    if ( pIDList->pIDsArray == NULL )
    { return AUD_MEM_ALLOC_FAILED;
    }
  }
//---------- Now read values one by one
  for ( i = 0; i < pIDList->idCount; i++ )
  { 
    //if ( !ReadULong( pFile, &pIDList->pIDsArray[i] ) )
	if ( !ReadULong( pFile, (unsigned long *) &temp ) )
    { return AUD_FILE_READ_FAIL;
    }
	pIDList->pIDsArray[i] = temp;
  }
  return AUD_NO_ERROR;
}
static AudErrorCode MDReadAudibleTableOfContent( IAudibleInputStream *pFile, CAudibleAllChapters *pAudChapters, long sectionSize )

{
  int	i;

  //---- AA file consist of multiple sections, each section - multiple blocks.
  BOOL readRes = ReadULong( pFile, &pAudChapters->audioChapetsCount ); // Read count of audio chapters.
  if ( !readRes )
  { return AUD_FILE_READ_FAIL;
  }

  //---- Check for valid chapter count
  if ( pAudChapters->audioChapetsCount > AUDIO_CHAPTERS_MAX_COUNT )
  { return AUD_AA_FILE_BAD_FORMAT;
  } 

  //----------- Now allocate memory for audio chapters.
  pAudChapters->pAudioChap = (CAudibleOneAudioChapter *)Audible_malloc( pAudChapters->audioChapetsCount * sizeof( CAudibleOneAudioChapter ) );
  if ( pAudChapters->pAudioChap == NULL )
  { return AUD_MEM_ALLOC_FAILED;
  }

  //----------- Good, now iterate through all sections.
  for ( i = 0; i < pAudChapters->audioChapetsCount; i++ )
  { char unUsed[8];
    long entriesCount;
	CAudibleOneAudioChapter *p = &pAudChapters->pAudioChap[i];
    readRes = 
      ReadLong( pFile,  &p->blockCount )                                &&
      AUD_NO_ERROR == pFile->pVTable->Read( pFile, unUsed, sizeof( unUsed ), NULL )  &&
      ReadLong( pFile, &p->audioSize  )                                &&
      ReadLong( pFile,  &p->audioTimeSec )                              &&
      ReadUShort(pFile, &p->codecID )                                   &&
      ReadLong( pFile,  &entriesCount );
    if ( !readRes )
    { return AUD_FILE_READ_FAIL;
    }
	//---- For metadata, just assume one block
    p->pAudioBlockInfo = (CAudibleBlockInfo *)Audible_malloc( sizeof( CAudibleBlockInfo ) );	//p->audBlockInfo;
	if ( p->pAudioBlockInfo == NULL )
	  return AUD_MEM_ALLOC_FAILED;
    //--------------------- Now we skip time stamp table, as we know the bitrate. 
    { unsigned long curPos = pFile->pVTable->GetCurrentPos( pFile );
      curPos += entriesCount * 8;
      if ( AUD_NO_ERROR != pFile->pVTable->SetCurrentPos( pFile, curPos ) )
      { return AUD_FILE_SEEK_FAIL;
      }
    }   
  }

/*
  //---- Read one chapter to get the codecID. First skip some data we don't need right now...
  pAudChapters->pAudioChap = &tempChapter;
  if ( pFile->pVTable->Read( pFile, unUsed, 4*5, NULL ) != AUD_NO_ERROR )
    return AUD_FILE_READ_FAIL;
*/
/*
  pAudChapters->pAudioChap = &tempChapter;
  for ( i = 0; i < 5; i++ )
    if ( !ReadULong( pFile, &dummy ) )
    { return AUD_FILE_READ_FAIL;
    }
*/
/*
  //---- Read codec ID
  if ( !ReadUShort( pFile, &pAudChapters->pAudioChap[0].codecID ) )
  { return AUD_FILE_READ_FAIL;
  }
*/
/*
//----------- Now allocate memory for audio chapters.
//  pAudChapters->audioChapetsCount = minimum( AUDIO_CHAPTERS_MAX_COUNT, pAudChapters->audioChapetsCount );
  pAudChapters->pAudioChap = (CAudibleOneAudioChapter *)Audible_malloc( pAudChapters->audioChapetsCount * sizeof( CAudibleOneAudioChapter ) );
  if ( pAudChapters->pAudioChap == NULL )
  { return AUD_MEM_ALLOC_FAILED;
  }
//----------- Good, now iterates through all sections.
  { unsigned long i = 0;
    for ( i = 0; i < pAudChapters->audioChapetsCount; i++ )
    { short unUsed[4];
      long entriesCount = 0;
      readRes = 
        ReadLong( pFile,  &pAudChapters->pAudioChap[i].blockCount )                                &&
        AUD_NO_ERROR == pFile->pVTable->Read( pFile, unUsed, 2 * sizeof( unUsed ) / sizeof( unUsed[0] ), NULL )  &&
        ReadLong( pFile, &pAudChapters->pAudioChap[i].audioSize  )                                &&
        ReadLong( pFile,  &pAudChapters->pAudioChap[i].audioTimeSec )                              &&
        ReadUShort(pFile, &pAudChapters->pAudioChap[i].codecID )                                   &&
        ReadLong( pFile,  &entriesCount );
      if ( !readRes )
      { return AUD_FILE_READ_FAIL;
      }
  //---------------------  If count of blocks more than 4, we allocate memory dynamically
      if ( pAudChapters->pAudioChap[i].blockCount <= MAX_DEFAULD_AUDIOBLOCK_COUNT )
      { pAudChapters->pAudioChap[i].pAudioBlockInfo = pAudChapters->pAudioChap[i].audBlockInfo;
      }
      else
      { pAudChapters->pAudioChap[i].pAudioBlockInfo = 
          ( CAudibleBlockInfo *)Audible_malloc( pAudChapters->pAudioChap[i].blockCount * sizeof( CAudibleBlockInfo ) );
      }      
  //--------------------- Now we skip time stamp table, as we know the bitrate. 
  //    { unsigned long curPos = pFile->pVTable->GetCurrentPos( pFile );
  //      curPos += entriesCount * 8;
  //      if ( AUD_NO_ERROR != pFile->pVTable->SetCurrentPos( pFile, curPos ) )
  //      { return AUD_FILE_SEEK_FAIL;
  //      }
  //    }   
    }
    return AUD_NO_ERROR;
  }
*/

  return AUD_NO_ERROR;
}