pysteam icon indicating copy to clipboard operation
pysteam copied to clipboard

Allow non-ASCII characters in shortcut AppName.

Open Ryochan7 opened this issue 9 years ago • 3 comments
trafficstars

This change was mainly to work around problems with a custom shortcut for Star Wars: Dark Forces purchased from GOG. The name has a Registerted Sign (U+00AE) in it which would make the name fail to convert to ascii and cause the script to stop. The change seems to work fine for my other non-Steam app shortcuts as well.

Ryochan7 avatar Jan 12 '16 18:01 Ryochan7

Sweet, thanks for doing this! Could you explain more about why you changed the lines you did? I'm not super familiar with character encodings, but I see changes to the shortcut generator but not the shortcut parser. It may just be early in the morning, but what was causing the error before and why do these lines fix it?

scottrice avatar Jan 13 '16 16:01 scottrice

python reads the shortcuts.vdf file fine and the name is encoded as a byte string. The problem was occurring while attempting to convert that byte string to unicode in ShortcutGenerator.generate_keyvalue_pair and also for the conversion when writing the new shortcuts.vdf file in shortcuts.write_shortcuts. Here is the output of the main error:

=========== User: 10238787 ===========
[ERROR] An exception occurred while running Ice
Traceback (most recent call last):
  File "/usr/share/games/ice/runners/ice_engine.py", line 153, in run
    self.main(dry_run=dry_run)
  File "/usr/share/games/ice/runners/ice_engine.py", line 133, in main
    self.run_for_user(user_context, dry_run=dry_run)
  File "/usr/share/games/ice/runners/ice_engine.py", line 145, in run_for_user
    self._create_backup(user, dry_run=dry_run)
  File "/usr/share/games/ice/runners/ice_engine.py", line 167, in _create_backup
    shortcuts.write_shortcuts(backup_path, shortcuts.get_shortcuts(user))
  File "/usr/lib/python2.7/dist-packages/pysteam/shortcuts.py", line 30, in write_shortcuts
    vdf_contents = ShortcutGenerator().to_string(shortcuts)
  File "/usr/lib/python2.7/dist-packages/pysteam/_shortcut_generator.py", line 20, in to_string
    string = x00 + 'shortcuts' + x00 + self.generate_array_string(shortcuts) + x08 + x08 + x0a
  File "/usr/lib/python2.7/dist-packages/pysteam/_shortcut_generator.py", line 29, in generate_array_string
    string += x00 + str(i) + x00 + self.generate_shortcut_string(shortcut)
  File "/usr/lib/python2.7/dist-packages/pysteam/_shortcut_generator.py", line 34, in generate_shortcut_string
    string += self.generate_keyvalue_pair("AppName",shortcut.name)
  File "/usr/lib/python2.7/dist-packages/pysteam/_shortcut_generator.py", line 52, in generate_keyvalue_pair
    return x01 + key + x00 + value + (x00 if more else x08)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 9: ordinal not in range(128)

Ryochan7 avatar Jan 13 '16 17:01 Ryochan7

@Ryochan7 @scottrice , this is very similar to in an old commit for Ice (b1b1f08), when the structure of Ice was a bit different.

mdeguzis avatar Jan 30 '16 01:01 mdeguzis