Skip to content

Commit 20b8d91

Browse files
committed
Fixed certain files not being parsed due to in-line toc directives
1 parent 207a2ad commit 20b8d91

File tree

1 file changed

+23
-26
lines changed

1 file changed

+23
-26
lines changed

src/TocFileParser.php

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ public function listFiles(string $tocFilePath): array
7474

7575
$dir = dirname($tocFilePath);
7676
$files = [];
77+
$pattern = '/\[(?<name>[^ \]]+) (?<value>[^\]]+)\]/';
7778
foreach ($fileLines as $line) {
7879
$line = strtr(
7980
$line,
@@ -83,33 +84,29 @@ public function listFiles(string $tocFilePath): array
8384
'\\' => '/',
8485
],
8586
);
86-
$gameTypeFilter = '[AllowLoadGameType';
87-
if (str_contains($line, $gameTypeFilter)) {
88-
$offset = strpos($line, $gameTypeFilter);
89-
$filterSubString = substr(
90-
$line,
91-
$offset + strlen($gameTypeFilter),
92-
strpos($line, ']', $offset) - $offset - strlen($gameTypeFilter),
93-
);
94-
if (!$this->allowLoadGameType($filterSubString)) {
95-
continue; // skip this file
96-
}
97-
$line = str_replace(
98-
substr($line, $offset, strpos($line, ']', $offset)),
99-
'',
100-
$line,
101-
);
102-
}
103-
if (str_contains($line, '[AllowLoad ')) {
104-
if (str_contains($line, '[AllowLoad Glue]')) {
105-
continue; // skip this file
87+
if (preg_match_all($pattern, $line, $matches, PREG_SET_ORDER)) {
88+
foreach ($matches as $match) {
89+
$name = $match['name'];
90+
$value = $match['value'];
91+
switch ($name) {
92+
case 'AllowLoadGameType':
93+
if (!$this->allowLoadGameType($value)) {
94+
continue 2; // skip this file
95+
}
96+
break;
97+
case 'AllowLoad':
98+
if (strtolower($value) === 'glue') {
99+
continue 2; // skip this file
100+
}
101+
break;
102+
case 'AllowLoadEnvironment':
103+
case 'LoadIntoEnvironment':
104+
break; // ignore for now
105+
default:
106+
throw new RuntimeException("Unrecognized in-line directive ($name) in TOC line: $line");
107+
}
108+
$line = str_replace($match[0], '', $line);
106109
}
107-
$offset = strpos($line, '[AllowLoad ');
108-
$line = str_replace(
109-
substr($line, $offset, strpos($line, ']', $offset)),
110-
'',
111-
$line,
112-
);
113110
}
114111

115112
$line = trim($line);

0 commit comments

Comments
 (0)