57 $this->path = $zipPath;
59 if(!file_exists($zipPath)){
62 $size = filesize($zipPath);
70 $archive = new \ZipArchive();
71 if(($openResult = $archive->open($zipPath)) !==
true){
72 throw new ResourcePackException(
"Encountered ZipArchive error code $openResult while trying to open $zipPath");
75 if(($manifestData = $archive->getFromName(
"manifest.json")) ===
false){
78 for($i = 0; $i < $archive->numFiles; ++$i){
79 $name = Utils::assumeNotFalse($archive->getNameIndex($i),
"This index should be valid");
81 ($manifestPath ===
null || strlen($name) < strlen($manifestPath)) &&
82 preg_match(
'#.*/manifest.json$#', $name) === 1
84 $manifestPath = $name;
88 if($manifestIdx !==
null){
89 $manifestData = $archive->getFromIndex($manifestIdx);
90 assert($manifestData !==
false);
91 }elseif($archive->locateName(
"pack_manifest.json") !==
false){
102 $manifest = (
new CommentedJsonDecoder())->decode($manifestData);
103 }
catch(\RuntimeException $e){
106 if(!($manifest instanceof \stdClass)){
107 throw new ResourcePackException(
"manifest.json should contain a JSON object, not " . gettype($manifest));
110 $mapper = new \JsonMapper();
111 $mapper->bExceptionOnMissingData =
true;
112 $mapper->bStrictObjectTypeChecking =
true;
116 $manifest = $mapper->map($manifest,
new Manifest());
117 }
catch(\JsonMapper_Exception $e){
120 if(!Uuid::isValid($manifest->header->uuid)){
124 $this->manifest = $manifest;
126 $this->fileResource = fopen($zipPath,
"rb");
162 throw new \InvalidArgumentException(
"Pack length must be positive");
164 fseek($this->fileResource, $start);
165 if(feof($this->fileResource)){
166 throw new \InvalidArgumentException(
"Requested a resource pack chunk with invalid start offset");
168 return Utils::assumeNotFalse(fread($this->fileResource, $length),
"Already checked that we're not at EOF");