mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-21 00:07:30 +00:00
ResourcePackManager: extracted loadPackFromPath() private method from constructor body
This commit is contained in:
parent
c5d716dc9d
commit
50b70708fb
@ -93,41 +93,21 @@ class ResourcePackManager{
|
||||
}
|
||||
$pack = (string) $pack;
|
||||
try{
|
||||
$packPath = Path::join($this->path, $pack);
|
||||
if(!file_exists($packPath)){
|
||||
throw new ResourcePackException("File or directory not found");
|
||||
}
|
||||
if(is_dir($packPath)){
|
||||
throw new ResourcePackException("Directory resource packs are unsupported");
|
||||
}
|
||||
$newPack = $this->loadPackFromPath(Path::join($this->path, $pack));
|
||||
|
||||
$newPack = null;
|
||||
//Detect the type of resource pack.
|
||||
$info = new \SplFileInfo($packPath);
|
||||
switch($info->getExtension()){
|
||||
case "zip":
|
||||
case "mcpack":
|
||||
$newPack = new ZippedResourcePack($packPath);
|
||||
break;
|
||||
}
|
||||
$this->resourcePacks[] = $newPack;
|
||||
$index = strtolower($newPack->getPackId());
|
||||
$this->uuidList[$index] = $newPack;
|
||||
|
||||
if($newPack instanceof ResourcePack){
|
||||
$this->resourcePacks[] = $newPack;
|
||||
$index = strtolower($newPack->getPackId());
|
||||
$this->uuidList[$index] = $newPack;
|
||||
|
||||
$keyPath = Path::join($this->path, $pack . ".key");
|
||||
if(file_exists($keyPath)){
|
||||
try{
|
||||
$this->encryptionKeys[$index] = ErrorToExceptionHandler::trapAndRemoveFalse(
|
||||
fn() => file_get_contents($keyPath)
|
||||
);
|
||||
}catch(\ErrorException $e){
|
||||
throw new ResourcePackException("Could not read encryption key file: " . $e->getMessage(), 0, $e);
|
||||
}
|
||||
$keyPath = Path::join($this->path, $pack . ".key");
|
||||
if(file_exists($keyPath)){
|
||||
try{
|
||||
$this->encryptionKeys[$index] = ErrorToExceptionHandler::trapAndRemoveFalse(
|
||||
fn() => file_get_contents($keyPath)
|
||||
);
|
||||
}catch(\ErrorException $e){
|
||||
throw new ResourcePackException("Could not read encryption key file: " . $e->getMessage(), 0, $e);
|
||||
}
|
||||
}else{
|
||||
throw new ResourcePackException("Format not recognized");
|
||||
}
|
||||
}catch(ResourcePackException $e){
|
||||
$logger->critical("Could not load resource pack \"$pack\": " . $e->getMessage());
|
||||
@ -137,6 +117,25 @@ class ResourcePackManager{
|
||||
$logger->debug("Successfully loaded " . count($this->resourcePacks) . " resource packs");
|
||||
}
|
||||
|
||||
private function loadPackFromPath(string $packPath) : ResourcePack{
|
||||
if(!file_exists($packPath)){
|
||||
throw new ResourcePackException("File or directory not found");
|
||||
}
|
||||
if(is_dir($packPath)){
|
||||
throw new ResourcePackException("Directory resource packs are unsupported");
|
||||
}
|
||||
|
||||
//Detect the type of resource pack.
|
||||
$info = new \SplFileInfo($packPath);
|
||||
switch($info->getExtension()){
|
||||
case "zip":
|
||||
case "mcpack":
|
||||
return new ZippedResourcePack($packPath);
|
||||
}
|
||||
|
||||
throw new ResourcePackException("Format not recognized");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the directory which resource packs are loaded from.
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user