Skip to content

Commit 8825c77

Browse files
InfernioSharlikran
authored andcommitted
Be less cautious in Path.version
Drops a way too broad except clause there. The only reasonable exception I could see coming from get_file_version is a ValueError from the new string code, so I added an except there to make sure. If this does end up breaking something, it points to a way deeper issue that actually needs investigating, not silencing. Fix crash on startup due to xSE version check Turns out that there was a reason for the insanely broad except clause in Path.version. StatusBar_Button.obseVersion did not check if the xSE file actually exists before checking its version - which obviously errors. Obviously, the correct solution here is not to silence that erorr, but to make obseVersion check if the file actually exists before calling strippedVersion on it. Add support for reading versions of .lnk files This fixes a crash when any of those are added to the 'Apps' folder and also shows their versions when the 'app version' status bar feature is enabled - so we even came out of this with a new feature! Also added some minor try-except clauses around the win32 api calls there now that I understand what actually causes them.
1 parent 97894a3 commit 8825c77

3 files changed

Lines changed: 22 additions & 13 deletions

File tree

Mopy/bash/basher/app_buttons.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,13 @@ def DoPopupMenu(self,event):
103103
@property
104104
def obseVersion(self):
105105
if bass.inisettings['SteamInstall']:
106-
se_exe = bush.game.se.steam_exe
106+
se_exe = bass.dirs['app'].join(bush.game.se.steam_exe)
107107
else:
108-
se_exe = bush.game.se.exe
109-
version = bass.dirs['app'].join(se_exe).strippedVersion
110-
return u'.'.join([u'%s'%x for x in version])
108+
se_exe = bass.dirs['app'].join(bush.game.se.exe)
109+
if se_exe.isfile():
110+
return u'.'.join([u'%s' % x for x in se_exe.strippedVersion])
111+
else:
112+
return u''
111113

112114
#------------------------------------------------------------------------------
113115
# App Links -------------------------------------------------------------------

Mopy/bash/bolt.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -797,13 +797,7 @@ def stat(self):
797797
def version(self):
798798
"""File version (exe/dll) embedded in the file properties."""
799799
from env import get_file_version
800-
try:
801-
version = get_file_version(self._s)
802-
if version is None:
803-
version = (0,0,0,0)
804-
except: # TODO: pywintypes.error?
805-
version = (0,0,0,0)
806-
return version
800+
return get_file_version(self._s)
807801

808802
@property
809803
def strippedVersion(self):

Mopy/bash/env.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,11 @@ def get_file_version(filename):
339339
:param filename: The file from which the version should be read.
340340
:return A 4-int tuple, for example (1, 9, 32, 0).
341341
"""
342+
# If it's a symbolic link (i.e. a user-added app), resolve it first
343+
if win32client and filename.endswith(u'.lnk'):
344+
sh = win32client.Dispatch(u'WScript.Shell')
345+
shortcut = sh.CreateShortCut(filename)
346+
filename = shortcut.TargetPath
342347
if win32api is None:
343348
# TODO(inf) The linux method needs support for string fields
344349
return _linux_get_file_version_info(filename)
@@ -381,7 +386,11 @@ def _query_string_field_version(file_name, version_prefix):
381386
# We need to ask for language and copepage first, before we can
382387
# query the actual version.
383388
l_query = u'\\VarFileInfo\\Translation'
384-
lang, codepage = win32api.GetFileVersionInfo(file_name, l_query)[0]
389+
try:
390+
lang, codepage = win32api.GetFileVersionInfo(file_name, l_query)[0]
391+
except win32api.error:
392+
# File does not have a string field section
393+
return (0, 0, 0, 0)
385394
ver_query = u'\\StringFileInfo\\%04X%04X\\%s' % (lang, codepage,
386395
version_prefix)
387396
full_ver = win32api.GetFileVersionInfo(file_name, ver_query)
@@ -403,7 +412,11 @@ def _query_fixed_field_version(file_name, version_prefix):
403412
ProductVersion.
404413
:return: A 4-tuple of integers containing the version of the file.
405414
"""
406-
info = win32api.GetFileVersionInfo(file_name, u'\\')
415+
try:
416+
info = win32api.GetFileVersionInfo(file_name, u'\\')
417+
except win32api.error:
418+
# File does not have a fixed field section
419+
return (0, 0, 0, 0)
407420
ms = info[u'%sMS' % version_prefix]
408421
ls = info[u'%sLS' % version_prefix]
409422
return win32api.HIWORD(ms), win32api.LOWORD(ms), win32api.HIWORD(ls), \

0 commit comments

Comments
 (0)