예제 #1
0
def _find_devenv_path(vs_version):
    devenv_path = None

    # First try the registry, because the environment variable is unreliable
    # (case of Visual Studio installed on a different drive; it still sets
    # the envvar to point to C:\Program Files even if devenv.com is on D:\)
    #pylint: disable=import-error
    from winreg import OpenKey, QueryValue, HKEY_LOCAL_MACHINE
    key_path = 'SOFTWARE\\Classes\\VisualStudio.accessor.' + vs_version + '.0\\shell\\Open'
    try:
        with OpenKey(HKEY_LOCAL_MACHINE, key_path) as key:
            cmdline = QueryValue(key, 'Command')
            if cmdline[:1] == '"':
                cmdline = cmdline.split('"')[1]
            elif ' ' in cmdline:
                cmdline = cmdline.split(' ')[0]
            devenv_path = cmdline.replace('devenv.exe', 'devenv.com')
    #pylint: disable=broad-except
    except Exception:
        pass

    # If the registry key is unhelpful, try the environment variable
    if not devenv_path:
        vstools_path = os.getenv('VS' + vs_version + '0COMNTOOLS')
        if vstools_path is not None:
            # Sanitize this because os.path.join sometimes gets confused
            if vstools_path[-1] in [ '/', '\\' ]:
                vstools_path = vstools_path[:-1]
            devenv_path = os.path.join(vstools_path, '../../Common7/IDE/devenv.com')

    if not devenv_path or not os.path.exists(devenv_path):
        return None

    logging.info("Found Visual Studio at %s", devenv_path)
    return devenv_path
예제 #2
0
def _find_devenv_path(vs_version):
    devenv_path = None

    # Sanitize vs_version
    if vs_version == '2015':
        vs_version = '14'
    if vs_version == '2017':
        vs_version = '15'
    if vs_version == '2019':
        vs_version = '16'

    # First try the registry, because the environment variable is unreliable
    # (case of Visual Studio installed on a different drive; it still sets
    # the envvar to point to C:\Program Files even if devenv.com is on D:\)
    #pylint: disable=import-error
    from winreg import OpenKey, QueryValue, HKEY_LOCAL_MACHINE
    key_path = 'SOFTWARE\\Classes\\VisualStudio.accessor.' + vs_version + '.0\\shell\\Open'
    try:
        with OpenKey(HKEY_LOCAL_MACHINE, key_path) as key:
            cmdline = QueryValue(key, 'Command')
            if cmdline[:1] == '"':
                cmdline = cmdline.split('"')[1]
            elif ' ' in cmdline:
                cmdline = cmdline.split(' ')[0]
            devenv_path = cmdline.replace('devenv.exe', 'devenv.com')
    #pylint: disable=broad-except
    except Exception:
        pass

    # For VS2017 and later, there is vswhere
    if not devenv_path:
        vswhere_path = os.path.join(os.environ['ProgramFiles(x86)'], 'Microsoft Visual Studio/Installer/vswhere.exe')
        result, output, _ = nimp.sys.process.call([vswhere_path], capture_output=True, hide_output=True)
        if result == 0:
            for line in output.split('\n'):
                line = line.strip()
                if 'installationPath: ' in line:
                    candidate = line.split(' ', 1)[1]
                elif 'installationVersion: ' + vs_version in line:
                    devenv_path = os.path.join(candidate, 'Common7/IDE/devenv.com')
                    break

    # If the registry key is unhelpful, try the environment variable
    if not devenv_path:
        vstools_path = os.getenv('VS' + vs_version + '0COMNTOOLS')
        if vstools_path is not None:
            # Sanitize this because os.path.join sometimes gets confused
            if vstools_path[-1] in [ '/', '\\' ]:
                vstools_path = vstools_path[:-1]
            devenv_path = os.path.join(vstools_path, '../../Common7/IDE/devenv.com')

    if not devenv_path or not os.path.exists(devenv_path):
        return None

    devenv_path = os.path.normpath(devenv_path)
    logging.info("Found Visual Studio at %s", devenv_path)
    return devenv_path
예제 #3
0
    def getMODirectory(gameName):
        #This custom function is used to detect the location of Mod Organizer

        ModOrganizerINILocationFromConfig = ModifyINI("Bethini.ini").get_value("Directories", "s" + gameName + "ModOrganizerINIPath", default="Not Detected")

        pathValue = "Not Detected"
        gameReg = Info.nxmhandler_game_reference(gameName)

        #Look up the nxm link (download with mod manager links on the
        #NexusMods.com sites) handler to find Mod Organizer location
        try:
            nxm = QueryValue(OpenKey(ConnectRegistry(None, HKEY_CLASSES_ROOT), r'nxm\shell\open\command'),"")
            sm(f'NXM links point to {nxm}')
            if 'nxmhandler' in nxm:
                nxmhandler = nxm.split('\"')[1]
                nxmhandlers = nxmhandler.replace("nxmhandler.exe","nxmhandlers.ini")
                if os.path.isfile(nxmhandlers):
                    nxmhandlersINI = ModifyINI(nxmhandlers)
                    sm(f'nxmhandlers.ini found here: {nxmhandlers}')
        except:
            sm('NXM links are probably not set up.', exception=1)
        
        try:
            nxmhandlersINI
        except:
            #nxmhandlers.ini not found.  Check for the AppData location.
            sm('nxmhandlers.ini not found. Checking AppData location.', exception=1)
            AppDataLocation = str(pathlib.Path.home()) + r"\AppData\Local\ModOrganizer\nxmhandler.ini"
            if os.path.isfile(AppDataLocation):
                nxmhandlers = AppDataLocation
                nxmhandlersINI = ModifyINI(nxmhandlers)
                sm(f'nxmhandler.ini found in {nxmhandlers}')
        try:
            size = int(nxmhandlersINI.get_value('handlers', 'size')) + 1
            for n in range(size):
                key = str(n) + '\\games'
                value = nxmhandlersINI.get_value('handlers', key)
                if gameReg != "skyrimse":
                    value = value.replace('skyrimse','')
                if gameReg in value:
                    pathKey = str(n) + '\\executable'
                    pathValue = os.path.split(nxmhandlersINI.get_value('handlers', pathKey).replace('\\\\','\\'))[0]
                    pathValue += '\\'
                    sm(f'Mod Organizer appears to be located at {pathValue}')
        except:
            sm('There is probably no nxmhandler.ini.', exception=1)

        ModOrganizerINILocation = 'Not Detected'
        if os.path.isfile(f'{pathValue}ModOrganizer.ini'):
            ModOrganizerINILocation = f'{pathValue}ModOrganizer.ini'
            sm(f'Found {ModOrganizerINILocation}')
        elif os.path.isfile(str(pathlib.Path.home()) + f"\\AppData\\Local\\ModOrganizer\\{gameReg}\\ModOrganizer.ini"):
            ModOrganizerINILocation = str(pathlib.Path.home()) + f"\\AppData\\Local\\ModOrganizer\\{gameReg}\\ModOrganizer.ini"
            sm(f'Found {ModOrganizerINILocation}')
        if ModOrganizerINILocation != 'Not Detected':
            ModOrganizerINILocation = os.path.split(ModOrganizerINILocation)[0]
            ModOrganizerINILocation += '\\'
        else:
            sm('Failed to locate ModOrganizer.ini')
            ModOrganizerINILocation = ModOrganizerINILocationFromConfig
            
        if ModOrganizerINILocation != ModOrganizerINILocationFromConfig and ModOrganizerINILocationFromConfig != "Not Detected":
            return [ModOrganizerINILocationFromConfig,ModOrganizerINILocation,"Browse..."]

        return [ModOrganizerINILocation,"Browse...","Manual..."]