Fixed a bug in QST header parsing.

Headers were parsed incorrectly if the basename of the file chunk was less than 5 characters.
This commit is contained in:
jtuu 2019-10-17 23:36:25 +03:00
parent 48f525a3bd
commit 2caa4eea2b
2 changed files with 17 additions and 1 deletions

View File

@ -5,6 +5,7 @@ import { Cursor } from "../../cursor/Cursor";
import { ResizableBufferCursor } from "../../cursor/ResizableBufferCursor";
import { WritableCursor } from "../../cursor/WritableCursor";
import { ResizableBuffer } from "../../ResizableBuffer";
import { basename } from "../../../util";
const logger = Logger.get("core/data_formats/parsing/quest/qst");
@ -128,7 +129,7 @@ function parse_headers(cursor: Cursor): QstHeader[] {
if (
prev_quest_id != undefined &&
prev_file_name != undefined &&
(quest_id !== prev_quest_id || file_name.slice(0, 5) !== prev_file_name.slice(0, 5))
(quest_id !== prev_quest_id || basename(file_name) !== basename(prev_file_name))
) {
cursor.seek(-88);
break;

View File

@ -26,3 +26,18 @@ export function array_buffers_equal(a: ArrayBuffer, b: ArrayBuffer): boolean {
return true;
}
/**
* Returns the given filename without the file extension.
*/
export function basename(filename: string): string {
const dot_idx = filename.lastIndexOf(".");
// < 0 means filenames doesn't contain any "."
// also skip index 0 because that would mean the basename is empty
if (dot_idx > 1) {
return filename.slice(0, dot_idx);
}
return filename;
}