Ejemplo n.º 1
0
def init_app_links(apps_dir, badIcons, iconList):
    init_params = []
    for path, (target, icon,
               description) in _get_app_links(apps_dir).iteritems():
        if target.lower().find(
                ur'installer\{') != -1:  # msi shortcuts: dc0c8de
            target = path
        else:
            target = GPath(target)
        if not target.exists(): continue
        # Target exists - extract path, icon and description
        # First try a custom icon #TODO(ut) docs - also comments methods here!
        fileName = u'%s%%i.png' % path.sbody
        customIcons = [apps_dir.join(fileName % x) for x in (16, 24, 32)]
        if customIcons[0].exists():
            icon = customIcons
        # Next try the shortcut specified icon
        else:
            icon, idex = icon.split(u',')
            if icon == u'':
                if target.cext == u'.exe':
                    if win32gui and win32gui.ExtractIconEx(target.s, -1):
                        # -1 queries num of icons embedded in the exe
                        icon = target
                    else:  # generic exe icon, hardcoded and good to go
                        icon, idex = _os.path.expandvars(
                            u'%SystemRoot%\\System32\\shell32.dll'), u'2'
                else:
                    icon, idex = _get_default_app_icon(idex, target)
            icon = GPath(icon)
            if icon.exists():
                fileName = u';'.join((icon.s, idex))
                icon = iconList(fileName)
                # Last, use the 'x' icon
            else:
                icon = badIcons
        init_params.append((path, icon, description))
Ejemplo n.º 2
0
def _supportedGames(useCache=True):
    """Set games supported by Bash and return their paths from the registry."""
    if useCache and _allGames: return _registryGames.copy()
    # rebuilt cache
    _allGames.clear()
    _registryGames.clear()
    import pkgutil
    import game as _game
    # Detect the known games
    for importer,modname,ispkg in pkgutil.iter_modules(_game.__path__):
        if not ispkg: continue # game support modules are packages
        # Equivalent of "from game import <modname>"
        try:
            module = __import__('game',globals(),locals(),[modname],-1)
        except ImportError:
            deprint(u'Error in game support module:', modname, traceback=True)
            continue
        submod = getattr(module,modname)
        if not hasattr(submod,'fsName') or not hasattr(submod,'exe'): continue
        _allGames[submod.fsName.lower()] = submod
        #--Get this game's install path
        if not winreg:
            del module
            continue
        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
                    _registryGames[submod.fsName.lower()] = installPath
        del module
    # unload some modules, _supportedGames is meant to run once
    del pkgutil
    del _game
    deprint(u'Detected the following supported games via Windows Registry:')
    for foundName in _registryGames:
        deprint(u' %s:' % foundName, _registryGames[foundName])
    return _registryGames.copy()
Ejemplo n.º 3
0
def get_registry_path(subkey, entry, exe):
    """Check registry for a path to a program."""
    if not winreg: return None
    for hkey in (winreg.HKEY_LOCAL_MACHINE, winreg.HKEY_CURRENT_USER):
        for wow6432 in (u'', u'Wow6432Node\\'):
            try:
                key = winreg.OpenKey(hkey,
                                     u'Software\\%s%s' % (wow6432, subkey))
                value = winreg.QueryValueEx(key, entry)
            except OSError:
                continue
            if value[1] != winreg.REG_SZ: continue
            installPath = GPath(value[0])
            if not installPath.exists(): continue
            exePath = installPath.join(exe)
            if not exePath.exists(): continue
            return installPath
    return None
Ejemplo n.º 4
0
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
Ejemplo n.º 5
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
Ejemplo n.º 6
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
Ejemplo n.º 7
0
def test_permissions(path, permissions='rwcd'):
    """Test file permissions for a path:
        r = read permission
        w = write permission
        c = file creation permission
        d = file deletion permission"""
    return True  # Temporarily disabled, for testing purposes
    path = GPath(path)
    permissions = permissions.lower()

    def getTemp(path_):  # Get a temp file name
        if path_.isdir():
            tmp = path_.join(u'temp.temp')
        else:
            tmp = path_.temp
        while tmp.exists():
            tmp = tmp.temp
        return tmp

    def getSmallest():  # Get the smallest file in the directory
        if path.isfile(): return path
        smallsize = -1
        ret = None
        for node in path.list():
            node = path.join(node)
            if not node.isfile(): continue
            node_size = node.size
            if smallsize == -1 or node_size < smallsize:
                smallsize = node_size
                ret = node
        return ret

    #--Test read permissions
    try:
        smallestFile = None
        path_exists = path.exists()
        if 'r' in permissions and path_exists:
            smallestFile = getSmallest()
            if smallestFile:
                with smallestFile.open('rb'):
                    pass
        #--Test write permissions
        if 'w' in permissions and path_exists:
            smallestFile = smallestFile or getSmallest()
            if smallestFile:
                with smallestFile.open('ab'):
                    pass
        #--Test file creation permission (only for directories)
        if 'c' in permissions:
            if path.isdir() or not path_exists:
                if not path_exists:
                    path.makedirs()
                    removeAtEnd = True
                else:
                    removeAtEnd = False
                temp = getTemp(path)
                with temp.open('wb'):
                    pass
                temp.remove()
                if removeAtEnd:
                    path.removedirs()
        #--Test file deletion permission
        if 'd' in permissions and path_exists:
            smallestFile = smallestFile or getSmallest()
            if smallestFile:
                temp = getTemp(smallestFile)
                smallestFile.copyTo(temp)
                smallestFile.remove()
                temp.moveTo(smallestFile)
    except Exception as e:
        if getattr(e, 'errno', 0) == 13:
            return False  # Access denied
        elif getattr(e, 'winerror', 0) == 183:
            return False  # Cannot create file if already exists
        else:
            raise
    return True