home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2008 February / PCWFEB08.iso / Software / Freeware / Miro 1.0 / Miro_Installer.exe / xulrunner / python / migrateappname.py < prev    next >
Encoding:
Python Source  |  2007-11-12  |  3.7 KB  |  89 lines

  1. # Miro - an RSS based video player application
  2. # Copyright (C) 2005-2007 Participatory Culture Foundation
  3. #
  4. # This program is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; either version 2 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the Free Software
  16. # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  17.  
  18. import util
  19. import platformcfg
  20. import os
  21. import os.path
  22. import resources
  23. import config
  24. import prefs
  25. import _winreg
  26. from xpcom import components
  27.  
  28. def migrateSupport(oldAppName, newAppName):
  29.     global migratedSupport
  30.     migratedSupport = False
  31.     # This gets called before config is set up, so we have to cheat
  32.     templateVars = util.readSimpleConfigFile(resources.path('app.config'))
  33.     appDataDir = platformcfg._appDataDirectory
  34.     oldSupportDir = os.path.join(appDataDir, templateVars['publisher'], oldAppName, 'Support')
  35.     newSupportDir = os.path.join(appDataDir, templateVars['publisher'], newAppName, 'Support')
  36.  
  37.     # Migrate support
  38.     if os.path.exists(oldSupportDir):
  39.         if not os.path.exists(os.path.join(newSupportDir,"preferences.bin")):
  40.             try:
  41.                 for name in os.listdir(oldSupportDir):
  42.                     os.rename(os.path.join(oldSupportDir,name),
  43.                               os.path.join(newSupportDir,name))
  44.                 migratedSupport = True
  45.             except:
  46.                 pass
  47.  
  48.     if migratedSupport:
  49.         runSubkey = "Software\\Microsoft\\Windows\\CurrentVersion\\Run"
  50.         try:
  51.             folder = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER, runSubkey)
  52.         except WindowsError, e:
  53.             if e.errno == 2: # registry key doesn't exist
  54.                 folder = _winreg.CreateKey(_winreg.HKEY_CURRENT_USER, runSubkey)
  55.             else:
  56.                 raise
  57.  
  58.         count = 0
  59.         while True:
  60.             try:
  61.                 (name, val, type) = _winreg.EnumValue(folder,count)
  62.             except:
  63.                 return True
  64.             count += 1
  65.             if (name == oldAppName):
  66.                 filename = os.path.join(resources.resourceRoot(),"..",("%s.exe" % templateVars['shortAppName']))
  67.                 filename = os.path.normpath(filename)
  68.                 writable_folder = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER,
  69.                                            runSubkey, 0,_winreg.KEY_SET_VALUE)
  70.                 _winreg.SetValueEx(writable_folder, newAppName, 0,_winreg.REG_SZ, filename)
  71.                 _winreg.DeleteValue(writable_folder, oldAppName)
  72.                 return True
  73.         return True
  74.     else:
  75.         return False
  76.     
  77. def migrateVideos(oldAppName, newAppName):
  78.     global migratedSupport
  79.     # we have to wait to import this
  80.     pybridgeCID = "@participatoryculture.org/dtv/pybridge;1"
  81.     pybridge = components.classes[pybridgeCID]. \
  82.                  getService(components.interfaces.pcfIDTVPyBridge)
  83.     if migratedSupport:
  84.         oldDefault = os.path.join(platformcfg._baseMoviesDirectory, oldAppName)
  85.         newDefault = os.path.join(platformcfg._baseMoviesDirectory, newAppName)
  86.         videoDir = config.get(prefs.MOVIES_DIRECTORY)
  87.         if videoDir == newDefault:
  88.             pybridge.changeMoviesDirectory(newDefault, True)
  89.