home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 February / maximum-cd-2011-02.iso / DiscContents / digsby_setup85.exe / lib / plugins / digsby_updater / winhelpers.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-11-24  |  3.5 KB  |  101 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.6)
  3.  
  4. import os
  5. import sys
  6. import shutil
  7. import locale
  8. import wx
  9. import util
  10. import stdpaths
  11. import path
  12. from ctypes import windll
  13. import logging
  14. log = logging.getLogger('AutoUpdate')
  15.  
  16. def platform_cleanup():
  17.     return _remove_virtual_store()
  18.  
  19.  
  20. def get_exe_name():
  21.     return util.program_dir().relpathto(path.path(sys._real_exe.decode(locale.getpreferredencoding())))
  22.  
  23.  
  24. def _remove_virtual_store():
  25.     if not os.name == 'nt':
  26.         return []
  27.     import gui.native.win.winutil as winutil
  28.     if not winutil.is_vista():
  29.         return []
  30.     to_remove = []
  31.     for virtual_store in (stdpaths.userlocaldata / 'VirtualStore' / 'Program Files' / 'Digsby', stdpaths.userlocaldata / 'VirtualStore' / 'Program Files (x86)' / 'Digsby'):
  32.         util.traceguard.__enter__()
  33.         
  34.         try:
  35.             if virtual_store.isdir():
  36.                 to_remove.extend(virtual_store.walkfiles())
  37.         finally:
  38.             pass
  39.  
  40.     
  41.     return to_remove
  42.  
  43.  
  44. def get_top_level_hwnd():
  45.     splash = wx.FindWindowByName('Digsby Login Window')
  46.     if splash is None:
  47.         topwins = wx.GetTopLevelWindows()
  48.         if isinstance(topwins, list) and topwins:
  49.             topwins = topwins[0]
  50.         
  51.         splash = None if topwins else None
  52.     
  53.     if splash is not None:
  54.         return splash.Handle
  55.  
  56.  
  57. def restart_and_update(tempdir):
  58.     import atexit
  59.     atexit.register(_launch_updater, tempdir)
  60.     force_restart_timer = util.Timer(7, _launch_updater, tempdir)
  61.     if wx.GetApp().DigsbyCleanupAndQuit():
  62.         force_restart_timer.start()
  63.     
  64.  
  65.  
  66. def _launch_updater(tempdir):
  67.     ShellExecute = windll.shell32.ShellExecuteW
  68.     POST_UPDATE_EXE = 'Digsby Updater.exe'
  69.     UPDATE_EXE = 'Digsby PreUpdater.exe'
  70.     tempdir = path.path(tempdir)
  71.     exc = get_exe_name()
  72.     for EXE in (POST_UPDATE_EXE, UPDATE_EXE):
  73.         if sys.DEV:
  74.             updater = path.path('ext') / 'msw' / EXE
  75.         else:
  76.             updater = path.path(sys.executable.decode(locale.getpreferredencoding())).parent / 'lib' / EXE
  77.         if not updater.isfile():
  78.             raise AssertionError('could not find %s' % updater)
  79.         updater.isfile()
  80.         updater.copy2(tempdir.parent)
  81.         updater = tempdir.parent / updater.name
  82.         if not updater.isfile():
  83.             raise AssertionError('could not copy %s to %s' % updater.name, tempdir.parent)
  84.         updater.isfile()
  85.         log.info('updater path is %r', updater)
  86.     
  87.     hwnd = get_top_level_hwnd()
  88.     log.info('top level window HWND is %s', hwnd)
  89.     SW_SHOWNORMAL = 1
  90.     SE_ERR_ACCESSDENIED = 5
  91.     params = u'supersecret "%s" "%s"' % (tempdir.parent, exc)
  92.     log.info('%s %s', updater, params)
  93.     res = ShellExecute(hwnd, None, updater, params, None, SW_SHOWNORMAL)
  94.     if res > 32:
  95.         log.info('ShellExecute successful: %s', res)
  96.     elif res == SE_ERR_ACCESSDENIED:
  97.         log.info('access denied')
  98.     else:
  99.         log.info('ShellExecute error: %s', res)
  100.  
  101.