1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace VoidBuilder; |
4
|
|
|
|
5
|
|
|
class File |
6
|
|
|
{ |
7
|
|
|
public $path; |
8
|
|
|
|
9
|
|
|
public function __construct (string $path) |
10
|
|
|
{ |
11
|
|
|
if (!is_file ($path)) |
12
|
|
|
throw new \Exception ('Wrong $path paeam'); |
13
|
|
|
|
14
|
|
|
$this->path = $path; |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
public function toXML (): string |
18
|
|
|
{ |
19
|
|
|
return '<File><Type>2</Type><Name>'. basename ($this->path) .'</Name><File>'. $this->path .'</File><ActiveX>False</ActiveX><ActiveXInstall>False</ActiveXInstall><Action>0</Action><OverwriteDateTime>False</OverwriteDateTime><OverwriteAttributes>False</OverwriteAttributes><PassCommandLine>False</PassCommandLine><HideFromDialogs>0</HideFromDialogs></File>'; |
20
|
|
|
} |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
class Folder |
24
|
|
|
{ |
25
|
|
|
public $path; |
26
|
|
|
public $files = []; |
27
|
|
|
|
28
|
|
|
public function __construct (string $path) |
29
|
|
|
{ |
30
|
|
|
if (!is_dir ($path)) |
31
|
|
|
throw new \Exception ('Wrong $path param'); |
32
|
|
|
|
33
|
|
|
$this->path = $path; |
34
|
|
|
|
35
|
|
|
foreach (array_slice (scandir ($path), 2) as $file) |
|
|
|
|
36
|
|
|
$this->files[] = is_dir ($file = $path .'/'. $file) ? |
37
|
|
|
new Folder ($file) : new File ($file); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function toXML (): string |
41
|
|
|
{ |
42
|
|
|
return '<File><Type>3</Type><Name>'. basename ($this->path) .'</Name><Action>0</Action><OverwriteDateTime>False</OverwriteDateTime><OverwriteAttributes>False</OverwriteAttributes><HideFromDialogs>0</HideFromDialogs><Files>'. implode ('', array_map (function ($item) |
43
|
|
|
{ |
44
|
|
|
return $item->toXML (); |
45
|
|
|
}, $this->files)) .'</Files></File>'; |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
class Joiner |
50
|
|
|
{ |
51
|
|
|
public $input; |
52
|
|
|
public $output; |
53
|
|
|
public $files = []; |
54
|
|
|
|
55
|
|
|
public function __construct (string $input, string $output) |
56
|
|
|
{ |
57
|
|
|
if (!is_file ($input)) |
58
|
|
|
throw new \Exception ('Wrong $input param'); |
59
|
|
|
|
60
|
|
|
$this->input = $input; |
61
|
|
|
$this->output = $output; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function add (string $path): Joiner |
65
|
|
|
{ |
66
|
|
|
$this->files[] = is_dir ($path) ? |
67
|
|
|
new Folder ($path) : new File ($path); |
68
|
|
|
|
69
|
|
|
return $this; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function getEVB (): string |
73
|
|
|
{ |
74
|
|
|
return str_replace ([ |
75
|
|
|
'%INPUT_FILE%', |
76
|
|
|
'%OUTPUT_FILE%', |
77
|
|
|
'%FILES%' |
78
|
|
|
], [ |
79
|
|
|
$this->input, |
80
|
|
|
$this->output, |
81
|
|
|
implode ('', array_map (function ($item) |
82
|
|
|
{ |
83
|
|
|
return $item->toXML (); |
84
|
|
|
}, $this->files)) |
85
|
|
|
], file_get_contents (dirname (__DIR__) .'/system/stub.evb')); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function join (): string |
89
|
|
|
{ |
90
|
|
|
file_put_contents (dirname (__DIR__) .'/system/temp.evb', $this->getEVB ()); |
91
|
|
|
$return = shell_exec ('"'. dirname (__DIR__) .'/system/enigmavbconsole.exe" "system/temp.evb"'); |
92
|
|
|
unlink (dirname (__DIR__) .'/system/temp.evb'); |
93
|
|
|
|
94
|
|
|
return $return; |
|
|
|
|
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|