Repository navigation
Read vdd_settings.xml saved in a Windows code page - #221
Merged
Merged
Conversation
A settings file saved in the system's ANSI code page, as Notepad does, was not UTF-8 or UTF-16, so the host kept the driver's old modes and skipped the graphics card pin. The driver reads the file with XmlLite, which takes UTF-8 and UTF-16 but no double-byte code page: declared, it reads nothing; undeclared or declared UTF-8, it stops at the first non-ASCII byte. The host now decodes such a file in the code page its declaration names, or in the system's ANSI code page, and writes it back as UTF-8 with a matching declaration, which the driver reads to the end. The original is kept as vdd_settings.xml.bak-<date> first. Bytes that are no character in that code page leave the file alone, as before.
A settings file read from a code page is now written back as UTF-8 even when its graphics card stays, so the driver reads all of it. UTF-8 with stray bytes is no longer read in the system's code page when it starts with a byte order mark, or, in a single-byte code page, when it still holds UTF-8 beyond ASCII; its UTF-8 text would be garbled. A second conversion the same day keeps its original as vdd_settings.xml.bak-<date>-<n>. Each conversion is logged once. Tests cover the system code page through apply_pin and write_with_pin.
The mixed UTF-8 cases are refused only in a single-byte system code page, so the file-level cases now run only there and both byte orders are tested in code page 1252 directly. The backup test passes its date instead of reading the clock.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Some hosts logged
Could not write vdd_settings.xml … stream did not contain valid UTF-8andLeft vdd_settings.xml as it is; the driver chooses the graphics card. In those cases the settings file had been saved in the system's ANSI code page, which Notepad's "ANSI" option and some older tools use. #207 reads UTF-8 and UTF-16 but still refused this file, so the second screen kept stale modes, and on hybrid laptops the host skipped the card pin.What the driver reads
Virtual Display Driver 25.5.2 opens
vdd_settings.xmlwithSHCreateStreamOnFileW, then callsCreateXmlReaderandSetInput. It sets no MultiLanguage property or encoding hint. It reads until XmlLite reports an error and keeps whatever it read before that. I tested a native probe that makes the same calls on Windows 11:windows-1252,ISO-8859-1).euc-kr,ks_c_5601-1987,windows-949,cp949,uhc,gb2312,gbk,GB18030,windows-936,cp936), the reader fails on the declaration and reads nothing. This happens even when the rest of the file is ASCII.encoding='utf-8'is kept as Notepad keeps it, the reader stops at the first non-ASCII byte.Writing such a file back in its code page would keep the driver stopping at that byte. So the host writes it back as UTF-8 with an
encoding="utf-8"declaration, which the reader takes to the end, and keeps the original beside it.Change
MultiByteToWideCharin that code page. A file with no declaration, or one declared UTF-8 whose bytes are not UTF-8, is decoded in the system ANSI code page (CP_ACP). The declaration is renamed toutf-8, as Keep Second screen working when the startup Disable hangs, after a lock, and with UTF-16 settings #207 does for UTF-16.vdd_settings.xml.bak-<YYYYMMDD>. If today's backup already holds different bytes, the copy goes to-2,-3and so on; a backup with the same bytes is reused. Each conversion logsWrote vdd_settings.xml as UTF-8; the original is kept beside itonce, with the backup's file name.MB_ERR_INVALID_CHARS), unknown encodings, and single-byte declarations, which the driver already reads, are left alone with one warning as before. The error now reads "the settings file is in no encoding this host reads".windowsalready enablesWin32_Globalization.Tests
host/tests/fixtures/vdd_settings-25.5.2-cp949.xmland-cp936.xml: the vendor file with a non-ASCII comment holding a folder path and a non-ASCII card name, saved in that code page with theutf-8declaration kept. They were made with Python's codecs, independent of the conversion under test.a_code_page_settings_file_is_read_in_the_systems_code_page(Windows), the undeclared-legacy case: files declared UTF-8 and files with no declaration decode to the expected text in code page 949 or 936. The non-ASCII card reads back, and pinning a card changes only the card.a_code_page_settings_file_is_written_back_as_utf8_with_a_backup(Windows), the declared case, with four names per code page:apply_pinwrites UTF-8 equal to the expected text, with only the card and the declaration changed.write_with_pinkeeps the non-ASCII card another app named in the rewritten file.a_settings_file_in_another_encoding_is_left_alone: its undeclared ANSI case is now read on Windows, which is this change; that case still runs off Windows. On Windows it is replaced by an unknown declared encoding and a cut double-byte character. Both stay byte for byte with no backup, also withowned = true.a_file_in_the_systems_code_page_is_written_back_as_utf8(Windows, system code page 1252): the driver's file saved as ANSI, with theutf-8declaration kept and a card name outside ASCII, goes through the realCP_ACPpath.apply_pinconverts the file whether the card is kept, unchanged or named.write_with_pinrewrites the whole file and keeps the card.Radeon®, and the backup equals the original bytes.Kept,Unchangedandpin_gpu_inwith the same card: each still converts the file, with one backup.utf8_with_a_stray_byte_is_not_read_in_a_single_byte_code_page(Windows), plus new left-alone cases on every platform: a byte order mark followed by a stray byte, and UTF-8 before or after a stray byte. Each stays byte for byte with no backup.each_original_of_a_day_is_backed_up_once: backup numbering and reuse.encoding_names_are_windows_code_pages: the name table and the backup date.On the base, the file-level test fails:
apply_pinreturns an error for the code page fixture.Checks:
cargo test -p eternal-host --lib, 1091 passed, andcargo clippy -p eternal-host --all-targets -- -D warnings.cargo test -p eternal-host --lib, 1093 passed, including the four Windows-only tests, and the same clippy check.