-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclean.php
More file actions
93 lines (74 loc) · 2.48 KB
/
clean.php
File metadata and controls
93 lines (74 loc) · 2.48 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
header('Content-Type: text/html; charset=utf-8');
set_time_limit(0);
$paths = array();
function dirToArray($dir)
{
global $paths;
$cdir = scandir($dir);
foreach ($cdir as $value) {
if (!in_array($value, array(".", ".."))) {
if (is_dir($dir . DIRECTORY_SEPARATOR . $value)) {
dirToArray($dir . DIRECTORY_SEPARATOR . $value);
} else {
$paths[] = $dir . DIRECTORY_SEPARATOR . $value;
}
}
}
}
dirToArray("src");
$tmp = "";
$deleteFile = array();
foreach ($paths as $path) {
$parts = explode('\\', $path);
$file = array_pop($parts);
$pathDir = implode('/', $parts);
if (strpos($file, ".") === false)
continue;
$ext = explode('.', $file)[1];
if ($ext !== "as")
continue;
$data = file_get_contents($path);
if (strpos($data, '[Embed(') === false)
continue;
$sourceName = "";
if (strpos($data, 'source="') !== false) {
$sourceName = explode('"', explode('source="', $data)[1])[0];
}
if ($sourceName == "")
continue;
$sourceExt = explode('.', $sourceName)[1];
if ($sourceExt != "ttf") {
continue;
}
$nameFile = explode('.', $file)[0];
$dirType = getTypeDir($sourceExt);
//if (!is_dir($pathDir.$dirType))
//mkdir($pathDir.$dirType);
$dataEdit = $data;
//$dataEdit = str_replace('source="'.$sourceName, 'source="'.str_replace('/', '', $dirType).'/'.$nameFile.'.'.$sourceExt, $dataEdit);
//$dataEdit = str_replace('source="'.$sourceName, 'source="'.$nameFile.'.'.$sourceExt, $dataEdit);
$packageName = explode("\n", explode("package ", $data)[1])[0];
$packageNameNew = str_replace(['/', 'src.'], '.', $pathDir);
$packageNameNew = ltrim($packageNameNew, ".");
//echo $packageNameNew."\n";
$dataEdit = str_replace('package '.$packageName, 'package '.$packageNameNew, $dataEdit);
//echo $dataEdit;
//exit();
file_put_contents($path, $dataEdit);
//copy($pathDir.'/'.$sourceName, $pathDir.$dirType.'/'.$nameFile.'.'.$sourceExt);
//if(!in_array($pathDir.'/'.$sourceName, $deleteFile))
//$deleteFile[] = $pathDir.'/'.$sourceName;
}
//foreach($deleteFile as $file) {
//unlink($file);
//}
//file_put_contents("tmp.txt", $tmp);
function getTypeDir($sourceExt) {
if ($sourceExt == 'png')
return "/images";
else if($sourceExt == 'mp3')
return "/sounds";
else if($sourceExt == 'bin')
return "/binaryData";
}