Skip to main content

Module ids

Module ids 

Source
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 IconId the 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 first MAX_PATH code units, or None if fewer than four backslashes are found. Matches the C++ findDesktopPathPrefixLength helper (returns -1 there).