Skip to content

Commit

Permalink
v1.5.3
Browse files Browse the repository at this point in the history
  • Loading branch information
AbyssMorgan committed May 13, 2023
1 parent 8e92d48 commit 9cc2ba2
Show file tree
Hide file tree
Showing 10 changed files with 633 additions and 316 deletions.
1 change: 1 addition & 0 deletions _get_package.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ SET PATH=%PATH%;%CD%\bin\main;%CD%\bin\php;%CD%\bin\imagick
"%CD%\bin\php\php.exe" "%CD%\includes\main.php" --put-version
FOR /F "tokens=*" %%s IN ('TYPE "%CD%\version"') DO SET _VERSION=%%s
"%CD%\bin\main\7z.exe" a -mx9 -t7z "%CD%\AVE-PHP_v%_VERSION%.7z" "bin" "includes" "commands" "AVE-PHP.cmd" "README.md" "LICENSE"
"%CD%\bin\main\7z.exe" a -mx9 -t7z "%CD%\AVE-PHP_v%_VERSION%_UPDATE.7z" "includes" "commands" "AVE-PHP.cmd" "README.md" "LICENSE"
PAUSE
294 changes: 12 additions & 282 deletions includes/AVE.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
declare(strict_types=1);

use App\Services\IniFile;
use App\Services\Logs;
use App\Services\CommandLine;
use App\Services\AveCore;

use App\Tools\NamesGenerator;
use App\Tools\FileFunctions;
Expand All @@ -14,30 +13,15 @@
use App\Tools\CheckFileIntegrity;
use App\Tools\MySQLTools;

class AVE extends CommandLine {
class AVE extends AveCore {

public IniFile $config;
public IniFile $mkvmerge;

public Logs $log_event;
public Logs $log_error;
public Logs $log_data;

public string $path;
public string $app_data;
public bool $abort = false;
public bool $open_log = false;

public string $app_name = "AVE";
public string $version = "1.5.2";

private ?string $command;
private array $arguments;
private string $logo;
private string $tool_name;
private string $subtool_name;
private array $folders_state = [];
private $tool;
public string $version = "1.5.3";

private array $folders_to_scan = [
'bin',
Expand All @@ -46,13 +30,7 @@ class AVE extends CommandLine {
];

public function __construct(array $arguments){
parent::__construct();
date_default_timezone_set(IntlTimeZone::createDefault()->getID());
$this->path = $this->get_file_path(__DIR__."/..");
unset($arguments[0]);
$this->command = $arguments[1] ?? null;
if(isset($arguments[1])) unset($arguments[1]);
$this->arguments = array_values($arguments);
parent::__construct($arguments);
$this->logo = "\r\n AVE-PHP Toolkit v$this->version by Abyss Morgan\r\n";
$changed = false;

Expand Down Expand Up @@ -148,11 +126,6 @@ public function __construct(array $arguments){
}
}

public function get_version_number(string $version) : int {
$ver = explode(".", $version);
return 10000 * intval($ver[0]) + 100*intval($ver[1]) + intval($ver[2]);
}

public function check_for_updates(string &$version) : bool {
$ch = curl_init("https://raw.githubusercontent.com/AbyssMorgan/AVE-PHP/master/version");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
Expand Down Expand Up @@ -202,15 +175,6 @@ public function tool_update(bool $response = false) : void {
}
}

public function clear() : void {
$this->cls();
if($this->config->get('AVE_SHOW_LOGO')){
echo "$this->logo\r\n";
} else {
echo "\r\n";
}
}

public function execute() : void {
switch(strtolower($this->command ?? '')){
case '--make-backup': {
Expand All @@ -235,7 +199,7 @@ public function execute() : void {
while(!$this->abort){
$this->abort = $this->select_tool();
}
$this->exit(10, $this->open_log);
$this->exit(10, false);
break;
}
default: {
Expand All @@ -245,31 +209,6 @@ public function execute() : void {
}
}

public function set_tool(string $name) : void {
$this->tool_name = $name;
$this->subtool_name = '';
$this->title("$this->app_name v$this->version > $this->tool_name");
$this->write_log("Set Tool: $this->tool_name");
}

public function set_subtool(string $name) : void {
$this->subtool_name = $name;
$this->title("$this->app_name v$this->version > $this->tool_name > $this->subtool_name");
$this->write_log("Set Tool: $this->tool_name > $this->subtool_name");
}

public function set_progress(int $progress, int $errors) : void {
$title = "$this->app_name v$this->version > $this->tool_name";
if(!empty($this->subtool_name)) $title .= " > $this->subtool_name";
$this->title("$title > Files: $progress Errors: $errors");
}

public function set_progress_ex(string $label, int $progress, int $total) : void {
$title = "$this->app_name v$this->version > $this->tool_name";
if(!empty($this->subtool_name)) $title .= " > $this->subtool_name";
$this->title("$title > $label: $progress / $total");
}

public function select_tool() : bool {
$this->write_log("Select Tool");
$this->clear();
Expand All @@ -285,7 +224,9 @@ public function select_tool() : bool {
' 4 - Media Tools',
' 5 - Check File Integrity',
' 6 - MySQL Tools',
' ',
' C - Open config folder',
' H - Show documentation',
' U - Check for updates',
]);

Expand Down Expand Up @@ -324,12 +265,16 @@ public function select_tool() : bool {
$this->open_file($this->app_data, "");
break;
}
case 'H': {
$this->clear();
$this->open_url("https://github.com/AbyssMorgan/AVE-PHP/wiki");
break;
}
case 'U': {
$this->clear();
$this->title("$this->app_name v$this->version > CheckForUpdates");
$this->tool_update(true);
return true;
break;
}
}
if(!$this->abort && !is_null($this->tool)){
Expand All @@ -338,221 +283,6 @@ public function select_tool() : bool {
return false;
}

public function select_action() : bool {
do {
$this->clear();
$this->title("$this->app_name v$this->version > $this->tool_name");
$this->tool->help();
echo " Action: ";
$line = $this->get_input();
if($line == '#') return false;
$response = $this->tool->action($line);
}
while(!$response);
return true;
}

public function setup_folders(array $folders) : void {
$this->folders_state = [];
foreach($folders as $folder){
$this->folders_state[$folder] = file_exists($folder) ? '' : '[NOT EXISTS]';
$this->write_log("Scan: $folder");
}
$this->print_folders_state();
}

public function set_folder_done(string $folder) : void {
$this->folders_state[$folder] = '[DONE]';
$this->print_folders_state();
}

public function print_folders_state() : void {
$this->clear();
foreach($this->folders_state as $folder_name => $state){
echo " Scan: \"$folder_name\" $state\r\n";
}
}

public function rmdir(string $path, bool $log = true) : bool {
if(!file_exists($path) || !is_dir($path)) return false;
if(rmdir($path)){
if($log) $this->write_log("DELETE \"$path\"");
return true;
} else {
if($log) $this->write_error("FAILED DELETE \"$path\"");
return false;
}
}

public function unlink(string $path, bool $log = true) : bool {
if(!file_exists($path) || is_dir($path)) return false;
if(unlink($path)){
if($log) $this->write_log("DELETE \"$path\"");
return true;
} else {
if($log) $this->write_error("FAILED DELETE \"$path\"");
return false;
}
}

public function mkdir(string $path, bool $log = true) : bool {
if(file_exists($path) && is_dir($path)) return true;
if(mkdir($path, 0777, true)){
if($log) $this->write_log("MKDIR \"$path\"");
return true;
} else {
if($log) $this->write_error("FAILED MKDIR \"$path\"");
return false;
}
}

public function rename(string $from, string $to, bool $log = true) : bool {
if($from == $to) return true;
if(file_exists($to) && pathinfo($from, PATHINFO_DIRNAME) != pathinfo($to, PATHINFO_DIRNAME)){
if($log) $this->write_error("FAILED RENAME \"$from\" \"$to\" FILE EXIST");
return false;
}
if(rename($from, $to)){
if($log) $this->write_log("RENAME \"$from\" \"$to\"");
return true;
} else {
if($log) $this->write_error("FAILED RENAME \"$from\" \"$to\"");
return false;
}
}

public function copy(string $from, string $to, bool $log = true) : bool {
if($from == $to) return true;
if(file_exists($to) && pathinfo($from, PATHINFO_DIRNAME) != pathinfo($to, PATHINFO_DIRNAME)){
if($log) $this->write_error("FAILED COPY \"$from\" \"$to\" FILE EXIST");
return false;
}
if(copy($from, $to)){
if($log) $this->write_log("COPY \"$from\" \"$to\"");
return true;
} else {
if($log) $this->write_error("FAILED COPY \"$from\" \"$to\"");
return false;
}
}

public function print_help(array $help) : void {
echo implode("\r\n", $help)."\r\n\r\n";
}

public function progress(int|float $count, int|float $total) : void {
if($total > 0){
$percent = sprintf("%.02f", ($count / $total) * 100.0);
echo " Progress: $percent % \r";
}
}

public function getHashFromIDX(string $path, array &$keys, bool $progress) : int {
if(!file_exists($path)) return 0;
$cnt = 0;
$size = filesize($path);
$fp = @fopen($path, "r");
if($fp){
while(($line = fgets($fp)) !== false){
$line = trim($line);
$keys[pathinfo($line, PATHINFO_FILENAME)] = $line;
$cnt++;
if($progress) $this->progress(ftell($fp), $size);
}
fclose($fp);
}
return $cnt;
}

public function formatBytes(int $bytes, int $precision = 2) : string {
if($bytes <= 0) return '0.00 B';
$i = floor(log($bytes)/log(1024));
$sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
return sprintf('%.'.$precision.'f', $bytes/pow(1024, $i)).' '.$sizes[$i];
}

public function getFiles(string $path, array|null $extensions = null, array|null $except = null) : array {
$data = [];
$files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path, FilesystemIterator::KEY_AS_PATHNAME | FilesystemIterator::CURRENT_AS_FILEINFO | FilesystemIterator::SKIP_DOTS));
foreach($files as $file){
if($file->isDir() || $file->isLink()) continue;
if(!is_null($extensions) && !in_array(strtolower($file->getExtension()), $extensions)) continue;
if(!is_null($except) && in_array(strtolower($file->getExtension()), $except)) continue;
$fp = $file->getRealPath();
if(!$fp) continue;
array_push($data, $fp);
}
return $data;
}

public function getFolders(string $path) : array {
$data = [];
$files = new DirectoryIterator($path);
array_push($data, $path);
foreach($files as $file){
if($file->isDir() && !$file->isDot()){
$data = array_merge($data, $this->getFolders($file->getRealPath()));
}
}
return $data;
}

public function write_log(string|array $data) : void {
if($this->config->get('AVE_LOG_EVENT')){
$this->log_event->write($data);
}
}

public function write_error(string|array $data) : void {
if($this->config->get('AVE_LOG_ERROR')){
$this->log_error->write($data);
}
}

public function write_data(string|array $data) : void {
$this->log_data->write($data);
}

public function exit(int $seconds = 10, bool $open_log = false) : void {
$this->write_log("Exit");
$this->open_logs($open_log, false);
$this->timeout($seconds);
}

public function init_logs(){
$timestamp = date("Y-m-d His");
$this->log_event = new Logs($this->get_file_path($this->config->get('AVE_LOG_FOLDER')."/$timestamp-Event.txt"), true, true);
$this->log_error = new Logs($this->get_file_path($this->config->get('AVE_LOG_FOLDER')."/$timestamp-Error.txt"), true, true);
$this->log_data = new Logs($this->get_file_path($this->config->get('AVE_DATA_FOLDER')."/$timestamp.txt"), false, true);
}

public function open_logs(bool $open_event = false, bool $init = true) : void {
$this->log_event->close();
$this->log_error->close();
$this->log_data->close();
if($this->config->get('AVE_OPEN_LOG_EVENT') && $open_event && file_exists($this->log_event->getPath())){
$this->open_file($this->log_event->getPath());
}
if(file_exists($this->log_data->getPath())){
$this->open_file($this->log_data->getPath());
}
if(file_exists($this->log_error->getPath())){
$this->open_file($this->log_error->getPath());
}
if($init) $this->init_logs();
}

private function timeout(int $seconds) : void {
$this->title("$this->app_name v$this->version > Exit $seconds seconds");
if($seconds > 0){
sleep(1);
$seconds--;
$this->timeout($seconds);
} else {
exit(0);
}
}

}

?>
1 change: 1 addition & 0 deletions includes/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
require_once("$includes_path/services/Logs.php");
require_once("$includes_path/services/IniFile.php");
require_once("$includes_path/services/CommandLine.php");
require_once("$includes_path/services/AveCore.php");
require_once("$includes_path/services/GuardPattern.php");
require_once("$includes_path/services/GuardDriver.php");
require_once("$includes_path/services/FaceDetector.php");
Expand Down
Loading

0 comments on commit 9cc2ba2

Please sign in to comment.