Skip to content

Commit

Permalink
Scripts: Always read patch files as utf-8, fix invalid escape sequences
Browse files Browse the repository at this point in the history
  • Loading branch information
CookiePLMonster committed Dec 29, 2024
1 parent 1962559 commit 59b50aa
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions .github/scripts/validate_patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ def log_error(file_path, line_number, message, line, shouldCleanLine = False):
print(f'Error in {file_path} (line {line_number}): {message}\n\t"{line}"')

def is_file_valid(file_path):
with open(file_path, 'r') as file:
with open(file_path, 'r', encoding='utf-8') as file:
for line_number, line in enumerate(file, 1):
cleaned_line = clean_line(line)
if cleaned_line == "":
continue
elif cleaned_line.startswith("["):
if not cleaned_line.endswith("]"):
print(f'Error in {file_path} group format (line {line_number}): Unclosed brackets for group.\n\T"{line}"')
print(f'Error in {file_path} group format (line {line_number}): Unclosed brackets for group.\n\t"{line}"')
return False
continue
elif re.match(r'^(\s*(gametitle|comment|gsaspectratio|gsinterlacemode|author|description)\s*=)', line, re.IGNORECASE):
Expand All @@ -41,7 +41,7 @@ def is_file_valid(file_path):
if not re.match(r'^patch=(0|1|2),(EE|IOP),[0-9A-Fa-f]{1,8},(byte|short|word|double|extended|beshort|beword|bedouble|bytes),[0-9A-Fa-f]{1,8}', line):
log_error(file_path, line_number, "Invalid patch format.", line, True)
return False
if re.match(",\d{8}(\n|\s*(//.*)*)+(?!.)", line):
if re.match(r",\d{8}(\n|\s*(//.*)*)+(?!.)", line):
log_error(file_path, line_number, "Invalid comment syntax at end of patch line.", line, False)
return False
elif cleaned_line.startswith("dpatch"):
Expand Down Expand Up @@ -71,7 +71,7 @@ def is_file_valid(file_path):

def main():
error_found = False
print('Started validating patches files')
print('Started validating patch files')

files = glob.glob(patches_glob_path)
file_count = len(files)
Expand Down

0 comments on commit 59b50aa

Please sign in to comment.