Expand description
Icon identifier encoding.
Icons on the desktop are identified by a hex-encoded UTF-16 string
representing either the desktop-relative path (e.g. notes.txt) or —
for virtual items such as This PC — the display name. Each u16
becomes four lowercase hex characters ('A' → "0041").
The encoding matches
the legacy library’s escape_wchars function
exactly, so IDs stored by older versions of the Python extension keep
working.
§Why hex-encoded UTF-16?
- It round-trips any shell path or display name (including non-BMP characters, control codes, whitespace, or filesystem-invalid sequences) into an opaque ASCII token — safe for JSON, filenames, command-line arguments, MCP tool arguments, etc.
- The encoded string sorts stably and can be used as a dict/HashMap key without normalisation surprises.
- Decoding is trivial and lossless.
Functions§
- build_
icon_ id - Build an
IconIdthe same way the legacy extension did. - escape_
wchars - Encode a NUL-terminated UTF-16 buffer as lowercase hex.
- find_
desktop_ prefix_ len - Skip
C:\\Users\\User\\Desktop\\— return the index just past the fourth backslash within the firstMAX_PATHcode units, orNoneif fewer than four backslashes are found. Matches the C++findDesktopPathPrefixLengthhelper (returns-1there).