Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix hmt encoding #34

Merged
merged 5 commits into from
Apr 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

This project also inherits changes from [Binilla](https://github.com/Sigmmma/binilla).

## [1.9.2]
### Changed
- Fix encoding problems with hmt files that aren't utf-16-le encoded.

## [1.9.1]
### Changed
- Fix missing license in distributions.
Expand Down
6 changes: 3 additions & 3 deletions mozzarilla/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
# ##############
# metadata #
# ##############
__author__ = "Devin Bobadilla, Michelle van der Graaf"
__author__ = "Sigmmma"
# YYYY.MM.DD
__date__ = "2020.03.07"
__version__ = (1, 9, 1)
__date__ = "2020.04.28"
__version__ = (1, 9, 2)
__website__ = "https://github.com/Sigmmma/mozzarilla"
14 changes: 12 additions & 2 deletions mozzarilla/windows/tools/compile_hud_message_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#

import os
import charset_normalizer

from pathlib import Path
from traceback import format_exc
Expand Down Expand Up @@ -44,8 +45,17 @@ def hud_message_text_from_hmt(app, fp=None):

print("Creating hud_message_text from this hmt file:")
print(" %s" % fp)
with fp.open("r", encoding="utf-16-le") as f:
hmt_string_data = f.read()

with fp.open("rb") as f:
contents = f.read()
guess = charset_normalizer.detect(contents)
# utf-16 is our fallback as that is the proper encoding for
# these files and has the biggest detection failure rate.
hmt_string_data = contents.decode(guess['encoding'] or "utf-16")
# Reading files this way doesn't remove carriage returns.
# We have to wipe them out like this.
hmt_string_data = hmt_string_data.replace("\r", "")

except Exception:
print(format_exc())
print(" Could not load hmt file.")
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ supyr_struct
binilla
reclaimer
arbytmap
charset_normalizer
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@
},
platforms=["POSIX", "Windows"],
keywords=["binilla", "binary", "data structure"],
install_requires=['reclaimer', 'binilla', 'arbytmap', 'supyr_struct'],
requires=['reclaimer', 'arbytmap', 'binilla'],
install_requires=['reclaimer', 'binilla', 'arbytmap', 'supyr_struct', "charset_normalizer"],
requires=['reclaimer', 'arbytmap', 'binilla', "charset_normalizer"],
provides=['mozzarilla'],
python_requires=">=3.5",
classifiers=[
Expand Down