NickHugi / PyKotor

A Python library that can read and modify most file formats used by the game Knights of the Old Republic and its sequel.
GNU Lesser General Public License v3.0
11 stars 3 forks source link

Fixed holopatcher error reading info.rtf files not utf-8 encoded #30

Closed chrisvigil closed 9 months ago

chrisvigil commented 10 months ago

When HoloPatcher attempts to load a info.rtf for a mod with an encoding other then UTF-8 it will fail.

Added autodetection of encoding which will fall back on UTF-8

Confirmed working with mod New_Lightsaber_Blade_Model_TSL 1.0.0 that has info.rtf files with latin1 encoding.

th3w1zard1 commented 10 months ago

I haven't had any issues with that mod.

take a quick look at utility.encoding.py, the method decode_bytes_with_fallbacks already autodetects then falls back to compatible encodings when one isn't found, with the ultimate fallback always being utf-8. There are also many tests in pykotor/src/tests/test_encoding.py.

not to say I'm skeptical of your pr at all, i'm just saying it's more likely it is perhaps your operating system, python version, or hardware? Can you open an issue that'll successfully reproduce this problem on the latest v1.43 holopatcher?

If not I'll take a look at this later in the week. Thanks for reporting this problem.

chrisvigil commented 9 months ago

Jupp I get the issue with the latest 1.4.3 release without my patch and my patch solves the issue for me.

decode_bytes_with_fallbacks doesn't appear to be used when reading rtf files.

It's quite likely a Linux only issue if you haven't see it before.

OS: Arch Linux Python Version: 3.11.6

2024-01-08-162151_hyprshot

th3w1zard1 commented 9 months ago

Yes that's exactly it: I was able to reproduce on Linux, but not Windows. Thanks for reporting this.

th3w1zard1 commented 9 months ago

Ah, you're correct, it was using default encoding (utf-8) without any detection whatsoever.

Cheers mate.