def getOblivionModsPath(bash_ini_, game_info): ob_mods_path = get_path_from_ini(bash_ini_, u'sOblivionMods') if ob_mods_path: src = [u'[General]', u'sOblivionMods'] else: ob_mods_path = GPath(GPath(u'..').join(u'%s Mods' % game_info.fsName)) src = u'Relative Path' if not ob_mods_path.isabs(): ob_mods_path = dirs['app'].join(ob_mods_path) return ob_mods_path, src
def getPersonalPath(bash_ini_, my_docs_path): #--Determine User folders from Personal and Local Application Data directories # Attempt to pull from, in order: Command Line, Ini, win32com, Registry if my_docs_path: my_docs_path = GPath(my_docs_path) sErrorInfo = _(u"Folder path specified on command line (-p)") else: my_docs_path = get_path_from_ini(bash_ini_, 'sPersonalPath') if my_docs_path: sErrorInfo = _( u"Folder path specified in bash.ini (%s)") % u'sPersonalPath' else: my_docs_path, sErrorInfo = get_personal_path() # If path is relative, make absolute if not my_docs_path.isabs(): my_docs_path = dirs['app'].join(my_docs_path) # Error check if not my_docs_path.exists(): raise BoltError(u"Personal folder does not exist.\n" u"Personal folder: %s\nAdditional info:\n%s" % (my_docs_path.s, sErrorInfo)) return my_docs_path
def detectGames(workingDir=u''): """Detect which supported games are intalled. - First, read the windows registry, checking for the install keys for the games. - Next, check for a valid game at "workingDir" - Finally, also look one directory up from the cwd.""" #--First: Find all supported games via the registry import pkgutil import game as _game foundGames = {} allGames = {} # Detect the known games for importer,modname,ispkg in pkgutil.iter_modules(_game.__path__): # Equivalent of "from game import <modname>" try: module = __import__('game',globals(),locals(),[modname],-1) except: deprint(u'Error in game support file:', modname, traceback=True) continue submod = getattr(module,modname) if not hasattr(submod,'name') or not hasattr(submod,'exe'): continue allGames[submod.name.lower()] = submod #--Get this game's install path for hkey in (_winreg.HKEY_CURRENT_USER, _winreg.HKEY_LOCAL_MACHINE): for wow6432 in (u'',u'Wow6432Node\\'): for (subkey,entry) in submod.regInstallKeys: try: key = _winreg.OpenKey(hkey, u'Software\\%s%s' % (wow6432,subkey)) value = _winreg.QueryValueEx(key,entry) except: continue if value[1] != _winreg.REG_SZ: continue installPath = GPath(value[0]) if not installPath.exists(): continue exePath = installPath.join(submod.exe) if not exePath.exists(): continue foundGames[submod.name.lower()] = installPath del module # unload some modules del pkgutil del _game deprint(u'Detected the following supported games via Windows Registry:') for foundName in foundGames: deprint(u' %s:' % foundName, foundGames[foundName]) #--Second: Detect what game is installed on directory up from Mopy path = Path.getcwd() if path.cs[-4:] == u'mopy': path = GPath(path.s[:-5]) installPaths = [path] #--Third: Detect what game is installed at the specified "workingDir" if workingDir != u'': path = GPath(workingDir) if not path.isabs(): path = Path.getcwd().join(path) installPaths.insert(0,path) deprint(u'Detecting games via relative path and the -o argument:') name = None for path in installPaths: _name = path.tail.cs if _name in allGames: # We have a config for that game deprint(u' %s:' % _name, path) foundGames[_name] = path name = _name break else: # Folder name wasn't found, try looking by exe name for file in path.list(): for _name in allGames: if allGames[_name].exe == file: # Must be this game deprint(u' %s:' % _name, path) name = _name foundGames[name] = path break else: continue break else: continue break return foundGames,allGames,name
def _detectGames(cli_path=u'', bash_ini_=None): """Detect which supported games are installed. - If Bash supports no games raise. - For each game supported by Bash check for a supported game executable in the following dirs, in decreasing precedence: - the path provided by the -o cli argument if any - the sOblivionPath Bash Ini entry if present - one directory up from Mopy If a game exe is found update the path to this game and return immediately. Return (foundGames, name) - foundGames: a dict from supported games to their paths (the path will default to the windows registry path to the game, if present) - name: the game found in the first installDir or None if no game was found - a 'suggestion' for a game to use (if no game is specified/found via -g argument). """ #--Find all supported games and all games in the windows registry foundGames_ = _supportedGames() # sets _allGames if not set if not _allGames: # if allGames is empty something goes badly wrong raise BoltError(_(u'No game support modules found in Mopy/bash/game.')) # check in order of precedence the -o argument, the ini and our parent dir installPaths = collections.OrderedDict( ) #key->(path, found msg, error msg) #--First: path specified via the -o command line argument if cli_path != u'': test_path = GPath(cli_path) if not test_path.isabs(): test_path = Path.getcwd().join(test_path) installPaths['cmd'] = ( test_path, _(u'Set game mode to %(gamename)s specified via -o argument') + u': ', _(u'No known game in the path specified via -o argument: ' + u'%(path)s')) #--Second: check if sOblivionPath is specified in the ini ini_game_path = get_ini_option(bash_ini_, u'sOblivionPath') if ini_game_path and not ini_game_path == u'.': test_path = GPath(ini_game_path.strip()) if not test_path.isabs(): test_path = Path.getcwd().join(test_path) installPaths['ini'] = ( test_path, _(u'Set game mode to %(gamename)s based on sOblivionPath setting ' u'in bash.ini') + u': ', _(u'No known game in the path specified in sOblivionPath ini ' u'setting: %(path)s')) #--Third: Detect what game is installed one directory up from Mopy test_path = Path.getcwd() if test_path.cs[-4:] == u'mopy': test_path = GPath(test_path.s[:-5]) if not test_path.isabs(): test_path = Path.getcwd().join(test_path) installPaths['upMopy'] = ( test_path, _(u'Set game mode to %(gamename)s found in parent directory of' u' Mopy') + u': ', _(u'No known game in parent directory of Mopy: %(path)s')) #--Detect deprint( u'Detecting games via the -o argument, bash.ini and relative path:') # iterate installPaths in insert order ('cmd', 'ini', 'upMopy') for test_path, foundMsg, errorMsg in installPaths.itervalues(): for name, info in _allGames.items(): if test_path.join(*info.game_detect_file).exists(): # Must be this game deprint(foundMsg % {'gamename': name}, test_path) foundGames_[name] = test_path return foundGames_, name # no game exe in this install path - print error message deprint(errorMsg % {'path': test_path.s}) # no game found in installPaths - foundGames are the ones from the registry return foundGames_, None
def detectGames(workingDir=u''): """Detect which supported games are intalled. - First, read the windows registry, checking for the install keys for the games. - Next, check for a valid game at "workingDir" - Finally, also look one directory up from the cwd.""" #--First: Find all supported games via the registry import pkgutil import game as _game foundGames = {} allGames = {} # Detect the known games for importer, modname, ispkg in pkgutil.iter_modules(_game.__path__): # Equivalent of "from game import <modname>" try: module = __import__('game', globals(), locals(), [modname], -1) except: deprint(u'Error in game support file:', modname, traceback=True) continue submod = getattr(module, modname) if not hasattr(submod, 'name') or not hasattr(submod, 'exe'): continue allGames[submod.name.lower()] = submod #--Get this game's install path for hkey in (_winreg.HKEY_CURRENT_USER, _winreg.HKEY_LOCAL_MACHINE): for wow6432 in (u'', u'Wow6432Node\\'): for (subkey, entry) in submod.regInstallKeys: try: key = _winreg.OpenKey( hkey, u'Software\\%s%s' % (wow6432, subkey)) value = _winreg.QueryValueEx(key, entry) except: continue if value[1] != _winreg.REG_SZ: continue installPath = GPath(value[0]) if not installPath.exists(): continue exePath = installPath.join(submod.exe) if not exePath.exists(): continue foundGames[submod.name.lower()] = installPath del module # unload some modules del pkgutil del _game deprint(u'Detected the following supported games via Windows Registry:') for foundName in foundGames: deprint(u' %s:' % foundName, foundGames[foundName]) #--Second: Detect what game is installed on directory up from Mopy path = Path.getcwd() if path.cs[-4:] == u'mopy': path = GPath(path.s[:-5]) installPaths = [path] #--Third: Detect what game is installed at the specified "workingDir" if workingDir != u'': path = GPath(workingDir) if not path.isabs(): path = Path.getcwd().join(path) installPaths.insert(0, path) deprint(u'Detecting games via relative path and the -o argument:') name = None for path in installPaths: _name = path.tail.cs if _name in allGames: # We have a config for that game deprint(u' %s:' % _name, path) foundGames[_name] = path name = _name break else: # Folder name wasn't found, try looking by exe name for file in path.list(): for _name in allGames: if allGames[_name].exe == file: # Must be this game deprint(u' %s:' % _name, path) name = _name foundGames[name] = path break else: continue break else: continue break return foundGames, allGames, name
def _detectGames(cli_path=u'',bashIni=None): """Detect which supported games are installed. - If Bash supports no games raise. - For each game supported by Bash check for a supported game executable in the following dirs, in decreasing precedence: - the path provided by the -o cli argument if any - the sOblivionPath Bash Ini entry if present - one directory up from Mopy If a game exe is found update the path to this game and return immediately. Return (foundGames, name) - foundGames: a dict from supported games to their paths (the path will default to the windows registry path to the game, if present) - name: the game found in the first installDir or None if no game was found - a 'suggestion' for a game to use (if no game is specified/found via -g argument). """ #--Find all supported games and all games in the windows registry foundGames_ = _supportedGames() # sets _allGames if not set if not _allGames: # if allGames is empty something goes badly wrong raise BoltError(_(u'No game support modules found in Mopy/bash/game.')) # check in order of precedence the -o argument, the ini and our parent dir installPaths = collections.OrderedDict() #key->(path, found msg, error msg) #--First: path specified via the -o command line argument if cli_path != u'': path = GPath(cli_path) if not path.isabs(): path = Path.getcwd().join(path) installPaths['cmd'] = (path, _(u'Set game mode to %(gamename)s specified via -o argument') + u': ', _(u'No known game in the path specified via -o argument: ' + u'%(path)s')) #--Second: check if sOblivionPath is specified in the ini if bashIni and bashIni.has_option(u'General', u'sOblivionPath') \ and not bashIni.get(u'General', u'sOblivionPath') == u'.': path = GPath(bashIni.get(u'General', u'sOblivionPath').strip()) if not path.isabs(): path = Path.getcwd().join(path) installPaths['ini'] = (path, _(u'Set game mode to %(gamename)s based on sOblivionPath setting ' u'in bash.ini') + u': ', _(u'No known game in the path specified in sOblivionPath ini ' u'setting: %(path)s')) #--Third: Detect what game is installed one directory up from Mopy path = Path.getcwd() if path.cs[-4:] == u'mopy': path = GPath(path.s[:-5]) if not path.isabs(): path = Path.getcwd().join(path) installPaths['upMopy'] = (path, _(u'Set game mode to %(gamename)s found in parent directory of' u' Mopy') + u': ', _(u'No known game in parent directory of Mopy: %(path)s')) #--Detect deprint(u'Detecting games via the -o argument, bash.ini and relative path:') # iterate installPaths in insert order ('cmd', 'ini', 'upMopy') for path, foundMsg, errorMsg in installPaths.itervalues(): for name, module in _allGames.items(): if path.join(module.exe).exists(): # Must be this game deprint(foundMsg % {'gamename':name}, path) foundGames_[name] = path return foundGames_, name # no game exe in this install path - print error message deprint(errorMsg % {'path': path.s}) # no game found in installPaths - foundGames are the ones from the registry return foundGames_, None