protected function addautoRun(string $filename, string $dir) : int
{
if (!empty($dir)) {
if ($dir[\strlen($dir) - 1] !== DIRECTORY_SEPARATOR) {
$dir .= DIRECTORY_SEPARATOR;
}
}
if (!\file_exists($filename)) {
echo $this->c['red'], 'File not found: ', $this->c[''], $filename, "\n";
return 0;
}
try {
$path = $this->getRealPath(\realpath($filename));
} catch (\Error $e) {
echo $this->c['red'], $e->getMessage(), $this->c[''], "\n";
return 0;
}
if (\array_key_exists($path, $this->session['autoRun'])) {
echo $this->c['yellow'], 'autoRun script already registered: ', $this->c[''], $path, "\n";
return 0;
}
// Recursive adding
if (\is_dir($path)) {
echo $this->c['red'], 'You cannot add a directory to an autoRun script: ', $this->c[''], $path, "\n";
return 0;
}
$this->session['autoRun'][$path] = ['type' => $this->getType($path), 'data' => Base64::encode(\file_get_contents($path))];
echo $this->c['green'], 'autoRun script registered: ', $this->c[''], $path, "\n";
return 1;
}