GenisysPro  for Minecraft PE/Windows 10 v1.1.x
Feature-rich server software for Minecraft PE and Windows 10 Edition
ZippedResourcePack Class Reference

Public Member Functions

 __construct (string $zipPath)
 
 getPackName ()
 
 getPackVersion ()
 
 getPackId ()
 
 getPackSize ()
 
 getSha256 (bool $cached=true)
 
 getPackChunk (int $start, int $length)
 
- Public Member Functions inherited from ResourcePack
 getSha256 ()
 

Static Public Member Functions

static verifyManifest (\stdClass $manifest)
 

Protected Attributes

 $path
 
 $manifest
 
 $sha256 = null
 
 $fileResource
 

Constructor & Destructor Documentation

◆ __construct()

__construct ( string  $zipPath)

ZippedResourcePack constructor.

Parameters
string$zipPath
75  {
76  $this->path = $zipPath;
77 
78  if(!file_exists($zipPath)){
79  throw new \InvalidArgumentException("无法打开材质包 $zipPath: 文件夹无法打开");
80  }
81 
82  $archive = new \ZipArchive();
83  if(($openResult = $archive->open($zipPath)) !== true){
84  throw new \InvalidStateException("打开 $zipPath $openResult");//Yeah, I don't speak, that...
85  }
86 
87  if(($manifestData = $archive->getFromName("manifest.json")) === false){
88  if(($manifestData = $archive->getFromName("pack_manifest.json")) === false){
89  throw new \InvalidStateException("无法加载材质包 $zipPath: 找不到主类");
90  }
91  }
92 
93  $archive->close();
94 
95  $manifest = json_decode($manifestData);
96  if(!self::verifyManifest($manifest)){
97  throw new \InvalidStateException("无法加载材质包 $zipPath: 主类错误或不完整");
98  }
99 
100  $this->manifest = $manifest;
101 
102  $this->fileResource = fopen($zipPath, "rb");
103  }

Member Function Documentation

◆ getPackChunk()

getPackChunk ( int  $start,
int  $length 
)
Parameters
int$start
int$length
Returns
string

Implements ResourcePack.

151  : string{
152  fseek($this->fileResource, $start);
153  if(feof($this->fileResource)){
154  throw new \RuntimeException("Requested a resource pack chunk with invalid start offset");
155  }
156  return fread($this->fileResource, $length);
157  }

◆ getPackId()

getPackId ( )
Returns
string

Implements ResourcePack.

122  : string{
123  return $this->manifest->header->uuid;
124  }

◆ getPackName()

getPackName ( )
Returns
string

Implements ResourcePack.

108  : string{
109  return $this->manifest->header->name;
110  }

◆ getPackSize()

getPackSize ( )
Returns
int

Implements ResourcePack.

129  : int{
130  return filesize($this->path);
131  }

◆ getPackVersion()

getPackVersion ( )
Returns
string

Implements ResourcePack.

115  : string{
116  return implode(".", $this->manifest->header->version);
117  }

◆ getSha256()

getSha256 ( bool  $cached = true)
Parameters
bool$cached
Returns
string
138  : string{
139  if($this->sha256 === null or !$cached){
140  $this->sha256 = hash_file("sha256", $this->path, true);
141  }
142  return $this->sha256;
143  }

◆ verifyManifest()

static verifyManifest ( \stdClass  $manifest)
static
Parameters
\stdClass$manifest
Returns
bool
46  {
47  if(!isset($manifest->format_version) or !isset($manifest->header) or !isset($manifest->modules)){
48  return false;
49  }
50  return
51  isset($manifest->header->description) and
52  isset($manifest->header->name) and
53  isset($manifest->header->uuid) and
54  isset($manifest->header->version) and
55  count($manifest->header->version) === 3;
56  }

Field Documentation

◆ $fileResource

$fileResource
protected

◆ $manifest

$manifest
protected

◆ $path

$path
protected

◆ $sha256

$sha256 = null
protected

The documentation for this class was generated from the following file: