Some BINKP optimisation, implemented crypt, implemented receiving compressed transfers
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace App\Classes\File;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Contracts\Filesystem\FileNotFoundException;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use League\Flysystem\UnreadableFileEncountered;
|
||||
@@ -23,6 +22,10 @@ class Item
|
||||
// For deep debugging
|
||||
protected bool $DEBUG = FALSE;
|
||||
|
||||
/** @var int max size of file to use compression */
|
||||
// @todo MAX_COMPSIZE hasnt been implemented in RECEIVE OR SEND
|
||||
protected const MAX_COMPSIZE = 0x1fff;
|
||||
|
||||
protected const IS_PKT = (1<<1);
|
||||
protected const IS_ARC = (1<<2);
|
||||
protected const IS_FILE = (1<<3);
|
||||
@@ -30,29 +33,33 @@ class Item
|
||||
protected const IS_REQ = (1<<5);
|
||||
protected const IS_TIC = (1<<6);
|
||||
|
||||
protected const I_RECV = (1<<6);
|
||||
protected const I_SEND = (1<<7);
|
||||
protected const I_RECV = (1<<0);
|
||||
protected const I_SEND = (1<<1);
|
||||
|
||||
protected string $file_name = '';
|
||||
protected int $file_size = 0;
|
||||
protected int $file_mtime = 0;
|
||||
protected int $file_type = 0;
|
||||
protected int $action = 0;
|
||||
/** Current read/write pointer */
|
||||
protected int $file_pos = 0;
|
||||
/** File descriptor */
|
||||
protected mixed $f = NULL;
|
||||
protected int $type;
|
||||
protected int $action;
|
||||
protected File $filemodel;
|
||||
|
||||
public bool $sent = FALSE;
|
||||
public bool $received = FALSE;
|
||||
public bool $incomplete = FALSE;
|
||||
/** Time we started sending/receiving */
|
||||
protected int $start;
|
||||
|
||||
/**
|
||||
* @throws FileNotFoundException
|
||||
* @throws UnreadableFileEncountered
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function __construct($file,int $action)
|
||||
{
|
||||
$this->action |= $action;
|
||||
|
||||
switch ($action) {
|
||||
case self::I_SEND:
|
||||
if ($file instanceof File) {
|
||||
@@ -63,7 +70,7 @@ class Item
|
||||
|
||||
} else {
|
||||
if (! is_string($file))
|
||||
throw new Exception('Invalid object creation - file should be a string');
|
||||
throw new \Exception('Invalid object creation - file should be a string');
|
||||
|
||||
if (! file_exists($file))
|
||||
throw new FileNotFoundException('Item doesnt exist: '.$file);
|
||||
@@ -83,7 +90,7 @@ class Item
|
||||
$keys = ['name','mtime','size'];
|
||||
|
||||
if (! is_array($file) || array_diff(array_keys($file),$keys))
|
||||
throw new Exception('Invalid object creation - file is not a valid array :'.serialize(array_diff(array_keys($file),$keys)));
|
||||
throw new \Exception('Invalid object creation - file is not a valid array :'.serialize(array_diff(array_keys($file),$keys)));
|
||||
|
||||
$this->file_name = $file['name'];
|
||||
$this->file_size = $file['size'];
|
||||
@@ -92,14 +99,15 @@ class Item
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new Exception('Unknown action: '.$action);
|
||||
throw new \Exception('Unknown action: '.$action);
|
||||
}
|
||||
|
||||
$this->file_type |= $this->whatType();
|
||||
$this->action = $action;
|
||||
$this->type = $this->whatType();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function __get($key)
|
||||
{
|
||||
@@ -107,10 +115,10 @@ class Item
|
||||
case 'mtime':
|
||||
case 'name':
|
||||
case 'size':
|
||||
if ($this->action & self::I_RECV)
|
||||
if ($this->action & self::I_RECV|self::I_SEND)
|
||||
return $this->{'file_'.$key};
|
||||
|
||||
throw new Exception('Invalid request for key: '.$key);
|
||||
throw new \Exception('Invalid request for key: '.$key);
|
||||
|
||||
case 'recvas':
|
||||
return $this->file_name;
|
||||
@@ -119,13 +127,13 @@ class Item
|
||||
return $this->file_name ? basename($this->file_name) : $this->filemodel->name;
|
||||
|
||||
default:
|
||||
throw new Exception('Unknown key: '.$key);
|
||||
throw new \Exception('Unknown key: '.$key);
|
||||
}
|
||||
}
|
||||
|
||||
protected function isType(int $type): bool
|
||||
{
|
||||
return $this->file_type & $type;
|
||||
return $this->type & $type;
|
||||
}
|
||||
|
||||
private function whatType(): int
|
||||
|
Reference in New Issue
Block a user