home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 October / maximum-cd-2011-10.iso / DiscContents / digsby_setup.exe / lib / plugins / digsby_updater / winhelpers.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2011-06-22  |  3.7 KB  |  105 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.     app = wx.GetApp()
  62.     if app.IsMainLoopRunning() and app.DigsbyCleanupAndQuit():
  63.         force_restart_timer.start()
  64.     
  65.  
  66.  
  67. def _launch_updater(tempdir):
  68.     ShellExecute = windll.shell32.ShellExecuteW
  69.     POST_UPDATE_EXE = 'Digsby Updater.exe'
  70.     UPDATE_EXE = 'Digsby PreUpdater.exe'
  71.     tempdir = path.path(tempdir)
  72.     exc = get_exe_name()
  73.     for EXE in (POST_UPDATE_EXE, UPDATE_EXE):
  74.         if sys.DEV:
  75.             updater = path.path('ext') / 'msw' / EXE
  76.         else:
  77.             updater = path.path(sys.executable.decode(locale.getpreferredencoding())).parent / 'lib' / EXE
  78.         if not updater.isfile():
  79.             raise AssertionError('could not find %s' % updater)
  80.         updater.isfile()
  81.         updater.copy2(tempdir.parent)
  82.         updater = tempdir.parent / updater.name
  83.         if not updater.isfile():
  84.             raise AssertionError('could not copy %s to %s' % updater.name, tempdir.parent)
  85.         updater.isfile()
  86.         log.info('updater path is %r', updater)
  87.     
  88.     hwnd = get_top_level_hwnd()
  89.     log.info('top level window HWND is %s', hwnd)
  90.     SW_SHOWNORMAL = 1
  91.     SE_ERR_ACCESSDENIED = 5
  92.     params = u'supersecret "%s" "%s"' % (tempdir.parent, exc)
  93.     log.info('%s %s', updater, params)
  94.     res = ShellExecute(hwnd, None, updater, params, None, SW_SHOWNORMAL)
  95.     if res > 32:
  96.         log.info('ShellExecute successful: %s', res)
  97.         return None
  98.     if res == SE_ERR_ACCESSDENIED:
  99.         log.info('access denied')
  100.     else:
  101.         log.info('ShellExecute error: %s', res)
  102.     import updater
  103.     updater._delete_updater_files()
  104.  
  105.