Beispiel #1
0
 /**
  * Retrieve the list of the data sections contained in this CHM.
  *
  * @throws Exception Throws an Exception in case of errors.
  */
 protected function retrieveSectionList()
 {
     $nameList = $this->getEntryByPath('::DataSpace/NameList');
     if ($nameList === null) {
         throw new Exception("Missing required entry: '::DataSpace/NameList'");
     }
     if ($nameList->getContentSectionIndex() !== 0) {
         throw new Exception("The content of the entry '{$nameList->getPath()}' should be in section 0, but it's in section {$nameList->getContentSection()}");
     }
     $nameListReader = new StringReader($nameList->getContents());
     /* Length */
     $nameListReader->readUInt16();
     $numSections = $nameListReader->readUInt16();
     if ($numSections === 0) {
         throw new Exception('No content section defined.');
     }
     for ($i = 0; $i < $numSections; ++$i) {
         $nameLength = $nameListReader->readUInt16();
         $utf16name = $nameListReader->readString($nameLength * 2);
         $nameListReader->readUInt16();
         $name = iconv('UTF-16LE', 'UTF-8', $utf16name);
         switch ($name) {
             case 'Uncompressed':
                 break;
             case 'MSCompressed':
                 if ($i === 0) {
                     throw new Exception('First data section should be Uncompressed');
                 } else {
                     $this->sections[$i] = new Section\MSCompressedSection($this);
                 }
                 break;
             default:
                 throw new Exception("Unknown data section: {$name}");
         }
     }
 }