home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2009 June / maximum-cd-2009-06.iso / DiscContents / digsby_setup.exe / lib / util / checkoptions.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-02-26  |  7.8 KB  |  219 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  3.  
  4. from __future__ import with_statement
  5. from threads import Timer, threaded
  6. from primitives import traceguard
  7. import stdpaths
  8. import traceback
  9. from logging import getLogger
  10. log = getLogger('check_ffx_prefs')
  11. DIGSBY_SEARCH_URL = 'http://searchbox.digsby.com/search?q={searchTerms}&ie=utf-8&oe=utf-8&aq=t'
  12. CHECK_INTERVAL = 300
  13. SEARCH_LINES = [
  14.     'user_pref("browser.search.defaultenginename", "Google Powered Digsby Search");',
  15.     'user_pref("keyword.URL", "http://searchbox.digsby.com/search?sourceid=navclient&gfns=1&q=");']
  16. HOMEPAGE_LINES = [
  17.     'user_pref("browser.startup.homepage", "http://search.digsby.com");']
  18. DIGSBY_SEARCH_UUID_IE = '{3326ab56-742e-5603-906f-290517220122}'
  19. SEARCH_PLUGIN_TXT = '<?xml version="1.0" encoding="UTF-8"?>\n<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/"\n    xmlns:moz="http://www.mozilla.org/2006/browser/search/">\n    <ShortName>Google Powered Digsby Search</ShortName>\n    <Description>Google Powered Digsby Search</Description>\n    <InputEncoding>UTF-8</InputEncoding>\n    <moz:UpdateUrl>http://digsby.com/digsbysearch.xml</moz:UpdateUrl>\n    <moz:UpdateInterval>7</moz:UpdateInterval>\n    <Image width="16" height="16">data:image/x-icon;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAaRJREFUeNpiVIg5JRURw0A0YAHio943kYV%2B%2Ff33%2BdvvX7%2F%2FMjEx8nKycrGzwKXOiPKzICvdeezLhCV3jp15%2Bfv%2FX0YGhv8MDDxMX2qKTIw0RK10eYD6QYqATvoPBkt3f5K0W9Ew4fjTFz%2F%2Bw8Dm3W8UPeZxqFa%2BevsFyD0twgfVsOfkRxHrtfV9u5BVQ8Crd98%2FffkGYQM1QJ20%2FfSPv79eNxQGYfpSVJADmcvEAHbr7oOX2dj%2FERNKIA2%2F%2F%2Fz%2FxfCDhYVoDUDw5P6vf9%2B5iY0HVmZGQWm%2BN3fff%2Fn2k4eLHS739x%2FDiRs%2Ff%2F%2F5x8HO%2FOHzN3djfqgNjIwMgc6qzLx%2Fpy47j2zY%2Feff06tXhOUucgxeun33AUZGpHh4%2Bvo7t8EyIJqz%2FhpasD59%2B5dNrqdnznZIsEL9ICXCsWuBCwvTv%2FymS5PWPP32ExEALz%2F%2BB5r848cPCJcRaMP9xaYQzofPPzfuvrnj0Jst%2B5%2F8%2Bc4sLPeDkYlRgJc93VPE18NIXkYUmJYQSQMZ%2FP3379uPH7%2F%2F%2FEETBzqJ0WqLGvFpe2LCC4AAAwAyjg7ENzDDWAAAAABJRU5ErkJggg%3D%3D</Image>\n    <Url type="text/html" method="GET" template="http://searchbox.digsby.com/search?q={searchTerms}&ie=utf-8&oe=utf-8&aq=t" />\n    <Url type="application/x-suggestions+json" method="GET" template="http://suggestqueries.google.com/complete/search?output=firefox&client=firefox&hl={moz:locale}&q={searchTerms}" />\n    <moz:SearchForm>http://searchbox.digsby.com</moz:SearchForm>\n</OpenSearchDescription>'
  20. FFX_EXE = 'firefox.exe'
  21.  
  22. def start_checking():
  23.     log.info('starting checker')
  24.     Timer(0, do_check).start()
  25.  
  26.  
  27. def set_search_active():
  28.     
  29.     try:
  30.         AddGoogleSearchEngine_IE()
  31.     except Exception:
  32.         traceback.print_exc()
  33.  
  34.     
  35.     try:
  36.         
  37.         try:
  38.             f = _[2]
  39.             f.write(' ')
  40.         finally:
  41.             pass
  42.  
  43.     except Exception:
  44.         traceback.print_exc()
  45.         return False
  46.  
  47.     return True
  48.  
  49.  
  50. def set_homepage_active():
  51.     
  52.     try:
  53.         AddGoogleHomePage_IE()
  54.     except Exception:
  55.         traceback.print_exc()
  56.  
  57.     
  58.     try:
  59.         
  60.         try:
  61.             f = _[2]
  62.             f.write(' ')
  63.         finally:
  64.             pass
  65.  
  66.     except Exception:
  67.         traceback.print_exc()
  68.         return False
  69.  
  70.     return True
  71.  
  72.  
  73. def _get_search_filepath():
  74.     return stdpaths.userdata / 'dosearch'
  75.  
  76.  
  77. def _get_homepage_filepath():
  78.     return stdpaths.userdata / 'dohomepage'
  79.  
  80.  
  81. def do_check():
  82.     search = _get_search_filepath()
  83.     homepage = _get_homepage_filepath()
  84.     if search.exists():
  85.         pass
  86.     dosearch = search.isfile()
  87.     if homepage.exists():
  88.         pass
  89.     dohomepage = homepage.isfile()
  90.     log.info('dosearch: %s, dohomepage: %s', dosearch, dohomepage)
  91.     if dosearch or dohomepage:
  92.         if is_ffx_running():
  93.             log.info('ffx was running, checking again in %d seconds', CHECK_INTERVAL)
  94.             Timer(CHECK_INTERVAL, do_check).start()
  95.         else:
  96.             log.info('ffx not running, attempting to write prefs')
  97.             do_write(dosearch, dohomepage)
  98.     
  99.  
  100. do_check = threaded(do_check)
  101.  
  102. def do_write(search, homepage):
  103.     search_pth = _get_search_filepath()
  104.     homepage_pth = _get_homepage_filepath()
  105.     for pth in (stdpaths.userconfig / 'Mozilla' / 'Firefox' / 'Profiles').dirs():
  106.         searchplugins = pth / 'searchplugins'
  107.         if not searchplugins.exists():
  108.             traceguard.__enter__()
  109.             
  110.             try:
  111.                 searchplugins.makedirs()
  112.             finally:
  113.                 pass
  114.  
  115.         
  116.         if searchplugins.exists() and searchplugins.isdir():
  117.             
  118.             try:
  119.                 f = _[3]
  120.                 f.write(SEARCH_PLUGIN_TXT)
  121.             finally:
  122.                 pass
  123.  
  124.         
  125.         profileprefs = pth / 'prefs.js'
  126.         if profileprefs.exists() and profileprefs.isfile():
  127.             traceguard.__enter__()
  128.             
  129.             try:
  130.                 
  131.                 try:
  132.                     f = _[6]
  133.                     if homepage:
  134.                         log.info('writing homepage prefs')
  135.                         traceguard.__enter__()
  136.                         
  137.                         try:
  138.                             f.writelines(HOMEPAGE_LINES)
  139.                         finally:
  140.                             pass
  141.  
  142.                         traceguard.__enter__()
  143.                         
  144.                         try:
  145.                             homepage_pth.remove()
  146.                         finally:
  147.                             pass
  148.  
  149.                 finally:
  150.                     pass
  151.  
  152.             finally:
  153.                 pass
  154.  
  155.             continue
  156.         traceguard
  157.     
  158.  
  159. do_write = threaded(do_write)
  160.  
  161. def AddGoogleHomePage_IE():
  162.     import _winreg
  163.     traceguard.__enter__()
  164.     
  165.     try:
  166.         k = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER, 'Software\\Microsoft\\Internet Explorer\\Main\\', 0, _winreg.KEY_SET_VALUE)
  167.         _winreg.SetValueEx(k, 'Start Page', None, _winreg.REG_SZ, 'http://search.digsby.com')
  168.         k.Close()
  169.     finally:
  170.         pass
  171.  
  172.  
  173.  
  174. def AddGoogleSearchEngine_IE():
  175.     import _winreg
  176.     traceguard.__enter__()
  177.     
  178.     try:
  179.         k = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER, 'Software\\Microsoft\\Internet Explorer\\SearchScopes\\', 0, _winreg.KEY_ALL_ACCESS)
  180.         _winreg.SetValueEx(k, 'DefaultScope', None, _winreg.REG_SZ, DIGSBY_SEARCH_UUID_IE)
  181.         k2 = _winreg.CreateKey(k, DIGSBY_SEARCH_UUID_IE)
  182.         _winreg.SetValueEx(k2, 'DisplayName', None, _winreg.REG_SZ, 'Google Powered Digsby Search')
  183.         _winreg.SetValueEx(k2, 'URL', None, _winreg.REG_SZ, DIGSBY_SEARCH_URL)
  184.         k3 = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER, 'Software\\Microsoft\\Internet Explorer\\Main', 0, _winreg.KEY_ALL_ACCESS)
  185.         k4 = _winreg.CreateKey(k3, 'Main')
  186.         _winreg.SetValueEx(k4, 'Use Search Asst', None, _winreg.REG_SZ, 'no')
  187.         _winreg.SetValueEx(k4, 'Search Page', None, _winreg.REG_SZ, 'http://searchbox.digsby.com/')
  188.         _winreg.SetValueEx(k4, 'Search Bar', None, _winreg.REG_SZ, 'http://searchbox.digsby.com/ie')
  189.         k.Close()
  190.         k2.Close()
  191.         k3.Close()
  192.         k4.Close()
  193.     finally:
  194.         pass
  195.  
  196.     traceguard.__enter__()
  197.     
  198.     try:
  199.         l = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, 'SOFTWARE\\Microsoft\\Internet Explorer\\Main', 0, _winreg.KEY_ALL_ACCESS)
  200.         _winreg.SetValueEx(l, 'Search Page', None, _winreg.REG_SZ, 'http://searchbox.digsby.com/')
  201.         l2 = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, 'SOFTWARE\\Microsoft\\Internet Explorer\\Search', 0, _winreg.KEY_ALL_ACCESS)
  202.         _winreg.SetValueEx(l2, 'SearchAssistant', None, _winreg.REG_SZ, 'http://searchbox.digsby.com/ie')
  203.         l.Close()
  204.         l2.Close()
  205.     finally:
  206.         pass
  207.  
  208.  
  209.  
  210. def is_ffx_running():
  211.     process_list = process_list
  212.     import gui.native.win.process
  213.     return FFX_EXE in process_list()
  214.  
  215. __all__ = [
  216.     'start_checking',
  217.     'set_search_active',
  218.     'set_homepage_active']
  219.