예제 #1
0
def extractArchive(modPath: str) -> str:
    extractedDir = normalizePath(data.config.extracted)
    modPath = normalizePath(modPath)
    if (path.exists(extractedDir)):
        removeDirectory(extractedDir)
        while path.isdir(extractedDir):
            pass
    mkdir(extractedDir)
    if platform == "win32" or platform == "cygwin":
        si = subprocess.STARTUPINFO()
        CREATE_NO_WINDOW = 0x08000000
        si.dwFlags |= subprocess.STARTF_USESHOWWINDOW
        exe = getProgramRootFolder() + "/tools/7zip/7z.exe"
        result = subprocess.run([exe, "x", modPath, "-o" + extractedDir, "-y"],
                                creationflags=CREATE_NO_WINDOW,
                                startupinfo=si,
                                stdin=subprocess.DEVNULL,
                                capture_output=True)
        if result.returncode != 0:
            raise IOError(
                result.stderr.decode('utf-8') if result.
                stderr else 'Could not extract archive')
    else:
        from pyunpack import Archive
        Archive(modPath).extractall(extractedDir)
    return extractedDir
예제 #2
0
def fetchModFromDirectory(modPath: str) -> Tuple[Mod, List[str], List[str]]:
    mod = Mod(path.split(modPath)[1])
    mod_dirs: List[str] = []
    mod_xmls: List[str] = []
    for current_dir, _, _ in walk(modPath):
        if fetchDataIfRelevantFolder(current_dir, mod):
            mod_dirs.append(normalizePath(current_dir))
        mod_xmls += fetchDataFromRelevantFiles(current_dir, mod)
    return mod, mod_dirs, mod_xmls
예제 #3
0
 def getCorrectGamePath(gamePath: Union[str, None]) -> str:
     '''Checks and corrects game path'''
     if not gamePath:
         return ''
     _, ext = path.splitext(gamePath)
     if ext == '.exe':
         for _ in range(3):
             gamePath, _ = path.split(gamePath)
     return normalizePath(gamePath) if path.exists(gamePath) \
         and path.exists(gamePath + '/content') \
         and path.isfile(gamePath + '/bin/x64/witcher3.exe') else ''
예제 #4
0
def fetchDataFromRelevantFiles(current_dir: str, mod: Mod) -> List[str]:
    mod_xmls: List[str] = []
    for file in getAllFilesFromDirectory(current_dir):
        if isMenuXmlFile(file):
            mod.menus.append(file)
            mod_xmls.append(normalizePath(current_dir + "/" + file))
        elif isTxtOrInputXmlFile(file):
            with open(current_dir + "/" + file, 'rb') as file_:
                file_contents = file_.read()
                try:
                    text = file_contents.decode("utf-8")
                except UnicodeError:
                    text = file_contents.decode("utf-16")
                if file == "input.xml":
                    text = fetchRelevantDataFromInputXml(text, mod)
                fetchAllXmlKeys(file, text, mod)
                inpt = fetchInputSettings(text)
                if inpt:
                    mod.inputsettings += inpt
                usrs = fetchUserSettings(text)
                if usrs:
                    mod.usersettings += usrs
    return mod_xmls