コード例 #1
0
def init_dirs_mopy_and_cd(is_standalone):
    # ensure we are in the correct directory so relative paths will work
    # properly
    if is_standalone:
        pathToProg = os.path.dirname(unicode(sys.executable, Path.sys_fs_enc))
    else:
        pathToProg = os.path.dirname(unicode(sys.argv[0], Path.sys_fs_enc))
    if pathToProg:
        os.chdir(pathToProg)
    dirs['mopy'] = Path.getcwd()
    dirs['bash'] = dirs['mopy'].join(u'bash')
    dirs['compiled'] = dirs['bash'].join(u'compiled')
    dirs['l10n'] = dirs['bash'].join(u'l10n')
    dirs['db'] = dirs['bash'].join(u'db')
    dirs['templates'] = dirs['mopy'].join(u'templates')
    dirs['images'] = dirs['bash'].join(u'images')
    global mopy_dirs_initialized
    mopy_dirs_initialized = True
コード例 #2
0
ファイル: bush.py プロジェクト: LHBDev/wrye-bash
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
コード例 #3
0
ファイル: bush.py プロジェクト: Skarfoze/wrye-bash
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
コード例 #4
0
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
コード例 #5
0
ファイル: bush.py プロジェクト: LORDofDOOM/wrye-bash
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