|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* rmarchiv.tk |
|
5
|
|
|
* (c) 2016-2017 by Marcel 'ryg' Hering |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace App\Console\Commands; |
|
9
|
|
|
|
|
10
|
|
|
use App\Models\GamesFile; |
|
11
|
|
|
use App\Models\PlayerIndexjson; |
|
12
|
|
|
use Illuminate\Console\Command; |
|
13
|
|
|
|
|
14
|
|
|
class PlayerCreateInfo extends Command |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* The name and signature of the console command. |
|
18
|
|
|
* |
|
19
|
|
|
* @var string |
|
20
|
|
|
*/ |
|
21
|
|
|
protected $signature = 'player:createinfo'; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* The console command description. |
|
25
|
|
|
* |
|
26
|
|
|
* @var string |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $description = 'creates index.json data for easyrpg'; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Create a new command instance. |
|
32
|
|
|
* |
|
33
|
|
|
* @return void |
|
|
|
|
|
|
34
|
|
|
*/ |
|
35
|
|
|
public function __construct() |
|
36
|
|
|
{ |
|
37
|
|
|
parent::__construct(); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Execute the console command. |
|
42
|
|
|
* |
|
43
|
|
|
* @return mixed |
|
44
|
|
|
*/ |
|
45
|
|
|
public function handle() |
|
46
|
|
|
{ |
|
47
|
|
|
$this->info('Lade Gamefiles ohne index.json'); |
|
48
|
|
|
|
|
49
|
|
|
$gamefiles = GamesFile::with('game')->get(); |
|
50
|
|
|
|
|
51
|
|
|
$counter = 0; |
|
|
|
|
|
|
52
|
|
|
$toindexed = []; |
|
53
|
|
|
|
|
54
|
|
|
foreach ($gamefiles as $gamefile) { |
|
55
|
|
|
if ($gamefile->game) { |
|
56
|
|
|
$makerid = $gamefile->game->maker_id; |
|
57
|
|
|
//echo $makerid.' - '.$gamefile->id.PHP_EOL; |
|
|
|
|
|
|
58
|
|
|
if ($makerid == 2 or |
|
|
|
|
|
|
59
|
|
|
$makerid == 3 or |
|
|
|
|
|
|
60
|
|
|
$makerid == 6 or |
|
|
|
|
|
|
61
|
|
|
$makerid == 9 or |
|
|
|
|
|
|
62
|
|
|
$makerid == 11) { |
|
63
|
|
|
// RPG2k/2k3/MV |
|
64
|
|
|
if ($gamefile->playerIndex()->count() == 0) { |
|
65
|
|
|
$toindexed[] = $gamefile; |
|
66
|
|
|
$this->info('ADD '.$gamefile->game->title); |
|
67
|
|
|
$counter += 1; |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
$this->info('Es wurden '.$counter.' Gamefiles gefunden.'); |
|
74
|
|
|
|
|
75
|
|
|
$bar = $this->output->createProgressBar(count($toindexed)); |
|
76
|
|
|
$bar->setFormat(" \033[44;37m %title:-37s% \033[0m\n %current%/%max% %bar% %percent:3s%%\n %remaining:-10s% %memory:37s%"); |
|
77
|
|
|
$bar->setBarCharacter($done = "\033[32m●\033[0m"); |
|
|
|
|
|
|
78
|
|
|
$bar->setEmptyBarCharacter($empty = "\033[31m●\033[0m"); |
|
|
|
|
|
|
79
|
|
|
$bar->setProgressCharacter($progress = "\033[32m➤ \033[0m"); |
|
80
|
|
|
$bar->setMessage('Starte indizierung der Gamefiles', 'title'); |
|
81
|
|
|
$bar->start(); |
|
82
|
|
|
|
|
83
|
|
|
$i = 0; |
|
|
|
|
|
|
84
|
|
|
foreach ($toindexed as $toindex) { |
|
85
|
|
|
$bar->setMessage('Entpacken von: '.$toindex->game_id.'/'.$toindex->id, 'title'); |
|
86
|
|
|
\Log::info('Entpacken von '.$toindex->game_id.'/'.$toindex->id); |
|
87
|
|
|
$path = storage_path('app/public/'.$toindex->filename); |
|
88
|
|
|
if ($toindex->extension == 'zip') { |
|
89
|
|
|
$zip = new \ZipArchive(); |
|
90
|
|
|
$zip->open($path); |
|
91
|
|
|
$makerid = $toindex->game->maker_id; |
|
92
|
|
|
if ($makerid == 6) { |
|
93
|
|
|
// RPG Maker MV |
|
94
|
|
|
// Nur Pfad zum "www/" Ordner noetig |
|
95
|
|
|
for ($i = 0; $i < $zip->numFiles; $i++) { |
|
96
|
|
|
$filename = $zip->getNameIndex($i); |
|
97
|
|
|
$this->info('Saved XXX basepath: '.$filename); |
|
98
|
|
|
if (ends_with($filename, 'www/')) { |
|
99
|
|
|
$pl = new PlayerIndexjson(); |
|
|
|
|
|
|
100
|
|
|
$pl->gamefile_id = $toindex->id; |
|
101
|
|
|
$pl->key = 'www'; |
|
|
|
|
|
|
102
|
|
|
$pl->value = $filename; |
|
|
|
|
|
|
103
|
|
|
$pl->filename = $filename; |
|
|
|
|
|
|
104
|
|
|
$pl->save(); |
|
105
|
|
|
|
|
106
|
|
|
\Log::info('Saved basepath: '.$filename); |
|
107
|
|
|
break; |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
} else { |
|
111
|
|
|
// RPG Maker 2k/2k3 |
|
112
|
|
|
for ($i = 0; $i < $zip->numFiles; $i++) { |
|
113
|
|
|
$filename = $zip->getNameIndex($i); |
|
114
|
|
|
|
|
115
|
|
|
if (! ends_with($filename, '/') and ! starts_with($filename, '_MACOSX')) { |
|
|
|
|
|
|
116
|
|
|
$imp = $this->search_for_base_path($filename); |
|
117
|
|
|
|
|
118
|
|
|
if (! $imp == '') { |
|
119
|
|
|
$pl = new PlayerIndexjson(); |
|
|
|
|
|
|
120
|
|
|
$pl->gamefile_id = $toindex->id; |
|
121
|
|
View Code Duplication |
if (! ends_with(strtolower($imp), ['.exe', '.lmu', '.ldb', 'ini', '.dll', 'lmt', 'lsd'])) { |
|
|
|
|
|
|
122
|
|
|
$pl->key = preg_replace('/(\.\w+$)/', '', strtolower($imp)); |
|
123
|
|
|
} else { |
|
124
|
|
|
$pl->key = strtolower($imp); |
|
125
|
|
|
} |
|
126
|
|
|
$pl->value = $imp; |
|
|
|
|
|
|
127
|
|
|
$pl->filename = 'www'; |
|
128
|
|
|
$pl->save(); |
|
129
|
|
|
|
|
130
|
|
|
\Log::info('Saved basepath: '.$filename); |
|
131
|
|
|
} else { |
|
132
|
|
|
\Log::info('Empty basepath: '.$filename); |
|
133
|
|
|
} |
|
134
|
|
|
} |
|
135
|
|
|
} |
|
136
|
|
|
} |
|
137
|
|
|
@$zip->close(); |
|
|
|
|
|
|
138
|
|
|
} else { |
|
139
|
|
|
continue; |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
//return; |
|
143
|
|
|
$bar->advance(); |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
$bar->finish(); |
|
147
|
|
|
|
|
148
|
|
|
$this->info('Fertig.'); |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
View Code Duplication |
public function search_for_base_path($filepath) |
|
|
|
|
|
|
152
|
|
|
{ |
|
153
|
|
|
$dirarray = [ |
|
154
|
|
|
'backdrop', |
|
155
|
|
|
'battle', |
|
156
|
|
|
'battle2', |
|
157
|
|
|
'battlecharset', |
|
158
|
|
|
'battleweapon', |
|
159
|
|
|
'charset', |
|
160
|
|
|
'chipset', |
|
161
|
|
|
'faceset', |
|
162
|
|
|
'frame', |
|
163
|
|
|
'gameover', |
|
164
|
|
|
'monster', |
|
165
|
|
|
'panorama', |
|
166
|
|
|
'picture', |
|
167
|
|
|
'system', |
|
168
|
|
|
'system2', |
|
169
|
|
|
'title', |
|
170
|
|
|
'music', |
|
171
|
|
|
'sound', |
|
172
|
|
|
]; |
|
173
|
|
|
|
|
174
|
|
|
$rootarray = [ |
|
175
|
|
|
'harmony.dll', |
|
176
|
|
|
'rpg_rt.exe', |
|
177
|
|
|
'rpg_rt.ini', |
|
178
|
|
|
'rpg_rt.ldb', |
|
179
|
|
|
'rpg_rt.lmt', |
|
180
|
|
|
'rpg_rt.dat', |
|
181
|
|
|
]; |
|
182
|
|
|
|
|
183
|
|
|
$mapparray = []; |
|
184
|
|
|
for ($i = 0; $i < 2000; $i++) { |
|
185
|
|
|
$mapparray[] = 'map'.sprintf('%04d', $i).'.lmu'; |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
$filearray = array_merge($rootarray, $mapparray); |
|
189
|
|
|
|
|
190
|
|
|
$searcharray = array_merge($dirarray, $filearray); |
|
191
|
|
|
|
|
192
|
|
|
if (starts_with(strtolower($filepath), $searcharray)) { |
|
193
|
|
|
$imp = str_replace('/', '\\/', $filepath); |
|
194
|
|
|
} else { |
|
195
|
|
|
if (str_contains(strtolower($filepath), $searcharray)) { |
|
196
|
|
|
$exp = explode('/', $filepath); |
|
197
|
|
|
$res = array_shift($exp); |
|
|
|
|
|
|
198
|
|
|
$imp = implode('/', $exp); |
|
199
|
|
|
$imp = $this->search_for_base_path($imp); |
|
200
|
|
|
} else { |
|
201
|
|
|
$imp = ''; |
|
202
|
|
|
} |
|
203
|
|
|
} |
|
204
|
|
|
|
|
205
|
|
|
if ($imp != '') { |
|
206
|
|
|
if (array_search(strtolower($imp), $filearray)) { |
|
207
|
|
|
$imp = '.\\/'.$imp; |
|
208
|
|
|
} |
|
209
|
|
|
} |
|
210
|
|
|
|
|
211
|
|
|
return $imp; |
|
212
|
|
|
} |
|
213
|
|
|
} |
|
214
|
|
|
|
Adding a
@returnannotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.