-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProtocol.php
More file actions
79 lines (67 loc) · 2.3 KB
/
Protocol.php
File metadata and controls
79 lines (67 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
require_once dirname(__FILE__) . '/vendor/autoload.php';
include 'ProtocolCodeGenerator/Util/DocstringUtils.php';
include 'ProtocolCodeGenerator/Util/NameUtils.php';
include 'ProtocolCodeGenerator/Util/XMLUtils.php';
include 'ProtocolCodeGenerator/Util/NumberUtils.php';
use ProtocolCodeGenerator\Generate\ProtocolCodeGenerator;
class Protocol {
private $excludeFiles = [
'Net/Packet.php',
'SerializationError.php'
];
public function clean() {
$generated = $this->generatedDir();
if (file_exists($generated)) {
echo "Removing: $generated\n";
$this->removeDirectory($generated);
}
}
public function generate() {
$code_generator = new ProtocolCodeGenerator($this->eoProtocolDir());
$code_generator->generate($this->generatedDir());
}
private function generatedDir() {
return dirname(__FILE__) . '/Eolib/Protocol';
}
private function eoProtocolDir() {
return dirname(__FILE__) . '/eo-protocol/xml';
}
private function removeDirectory($path, $subPath = '') {
$files = array_diff(scandir($path), array('.','..'));
foreach ($files as $file) {
$fullPath = "$path/$file";
$relativePath = $subPath . $file;
if (in_array($relativePath, $this->excludeFiles)) {
echo "Excluding from deletion: $relativePath\n";
continue;
}
if (is_dir($fullPath)) {
$this->removeDirectory($fullPath, $relativePath . '/');
} else {
echo "Deleting file: $fullPath\n";
unlink($fullPath);
}
}
if (!empty($subPath) && in_array(rtrim($subPath, '/'), $this->excludeFiles)) {
echo "Excluding directory from deletion: $path\n";
return;
}
echo "Removing directory: $path\n";
return rmdir($path);
}
}
if ($argc > 1) {
$protocol = new Protocol();
switch ($argv[1]) {
case "clean":
$protocol->clean();
break;
case "generate":
$protocol->clean();
$protocol->generate();
break;
default:
echo "Unknown command. Valid commands are 'generate' and 'clean'.\n";
}
}