def checkLstFile(saveMainDir): lstSavePath = saveMainDir + "\\提取列表.txt" if ife(lstSavePath): remove(lstSavePath) with open(lstSavePath, 'w', encoding="utf-8") as lst: lst.write("") return lstSavePath
def delOldErrorLog(desktop): if ife(desktop + '\\error.txt'): try: remove(desktop + '\\error.txt') except: return False return True
def getImgDict(imgDir=None): while True: if not ife(imgDir + '\\img2NpkDict.pkl'): print("\n--未查找到到IMG词典文件,将自动生成--\n") print("-----创建IMG/NPK词典中,请等待-----") newDictStartTime = time() img2NpkDict = newImgNpkDict(imgDir) newDictEndTime = time() print("创建词典用时", int(newDictEndTime - newDictStartTime), '秒\n') with open(imgDir + "\\img2NpkDict.pkl", 'wb') as imgDict: dump(img2NpkDict, imgDict) if ife(imgDir + '\\img2NpkDict.pkl'): break with open(imgDir + '\\img2NpkDict.pkl', 'rb') as imgNpkD: imgNpkDict = load(imgNpkD) return imgNpkDict
def getPartSetIndexDict(imgDir, equLst, utPort): def createDictFromPC(): while True: equDir = input("输入equipment文件夹, 例如\tD:\\自己的DNF\\Script\n").replace('\\', '\\\\').strip() if path.exists(equDir): partSetDict = newPartSetDict(equLst, utPort, imgDir, equDir) break else: print("输入有误,无此文件夹,请重新输入!") return partSetDict # ------------创建套装词典 if ife(imgDir + "\\partSetDict.pkl"): with open(imgDir + "\\partSetDict.pkl", 'rb') as f: partSetIndexDict = load(f) else: while True: flag = input("从本地创建词典,请输入1, 从PVF工具创建输入0\n") if flag == "1": return createDictFromPC() elif flag == "0": partSetIndexDict = newPartSetDict(equLst, utPort, imgDir) return partSetIndexDict else: print("输入有误,请重新输入") return partSetIndexDict
def getMapDict(utPort, mapLst, imgDir): while True: if not ife(imgDir + '\\map2DgnDict.pkl'): print("\n--未查找到到map词典文件,将自动生成--\n") print("-----创建MAP/DGN词典中,请等待-----") newDictStartTime = time() map2DgnDict = createMapDict(utPort, mapLst, imgDir) newDictEndTime = time() print("创建词典用时", int(newDictEndTime - newDictStartTime), '秒\n') with open(imgDir + "\\map2DgnDict.pkl", 'wb') as map2DgnD: dump(map2DgnDict, map2DgnD) if ife(imgDir + '\\map2DgnDict.pkl'): break with open(imgDir + '\\map2DgnDict.pkl', 'rb') as map2DgnD: map2DgnDict = load(map2DgnD) return map2DgnDict
def checkLogin(codeFlag): pwPath = getcwd() + "\\{}.pwd".format(get_disk_ID()) if ife(pwPath): with open(pwPath, 'rb') as pwd: passDict = load(pwd) if codeFlag not in passDict.keys() or not login( passDict[codeFlag], codeFlag): print("未授权") return False else: return True else: print("未找到授权文件,即将退出") return False
def img2DirFunc(parent): img2Dir = QFileDialog.getExistingDirectory(parent, "选取ImagePacks2文件夹", "./") # print(saveDir, type(saveDir)) if img2Dir != "": parent.mainWin.img2Dir = img2Dir if len(lafOneDir(img2Dir, 'npk')) == 0: return False else: if ife(img2Dir + "\\img2NpkDict.pkl"): with open(img2Dir + "\\img2NpkDict.pkl", 'rb') as f: parent.mainWin.npkDict = pickle.load(f) QMessageBox.information(parent, "读取成功", "读取NPK字典成功", QMessageBox.Yes, QMessageBox.Yes) return img2Dir else: return False
def newPartSetDict(equLst, utPort, imgDir, equipmentDir=None): partSetDict = {} equCList = equLst[2:][::2] if equipmentDir: equPList = [ equipmentDir + ('\\equipment\\' + fileP.replace("`", '').lower()).replace( '/', '\\') for fileP in equLst[2:][::-1][::2] ][::-1] for filePath in tqdm(equPList): # print(filePath) if ife(filePath): with open(filePath, 'r', encoding="utf-8") as f: Clist = [line.strip() for line in f.readlines()] # print(Clist) if "[part set index]" in Clist: equIndex = equCList[equPList.index(filePath)] setIndex = Clist[Clist.index("[part set index]") + 1] try: partSetDict[setIndex].append(equIndex) except: partSetDict[setIndex] = [equIndex] else: equPList = [ 'equipment/' + fileP.replace("`", '').lower() for fileP in equLst[2:][::-1][::2] ][::-1] for filePath in tqdm(equPList): content = fromPvfGetContent(utPort, filePath) if isinstance(content, str): Clist = fileText2List(content) if "[part set index]" in Clist: equIndex = equCList[equPList.index(filePath)] setIndex = Clist[Clist.index("[part set index]") + 1] try: partSetDict[setIndex].append(equIndex) except: partSetDict[setIndex] = [equIndex] if partSetDict: savePath = imgDir + "\\partSetDict.pkl" with open(savePath, "wb") as f: dump(partSetDict, f) return partSetDict else: return False
def getImg2DirPort(): workPath = getcwd() settingFilePath = workPath + '\\setting.ini' reWriteFlag = False settingDict = { "IMG2目录": workPath, "PVF端口": "27000", "保存路径": workPath, "全提取模式": "0", "NPK导出模式": "0" } def getInfo(c): return c.split("[")[1].strip()[:-1] def checkSetting(setLines): if len(setLines) < len(list(settingDict.keys())): return False for line in setLines: if "[" not in line and "]" not in line: return False return True if ife(settingFilePath): with open(settingFilePath, 'r') as setting: settingLines = setting.readlines() if checkSetting(settingLines): settingList = [getInfo(line) for line in settingLines] settingDict = reCheckSetting(settingList, settingFilePath, settingDict) else: reWriteFlag = True else: reWriteFlag = True if reWriteFlag: settingDict = writeSetting(settingFilePath, settingDict) for key, value in settingDict.items(): if key == "密码": continue print(key + ':\t' + value) print("\n如果错误,请退出在同级目录下setting.ini文件进行修改\n读取需要的列表中····") return settingDict.values()
def imgMerge(imgList, imgDict, npkSavePath, img2Path): npk = NPK() npk.new() notExistNpk = [] keys = imgDict.keys() notInDictImg = [] waitOpenNpk = {} # 创建进度条······ for img in imgList: if img not in keys: notInDictImg.append(img) continue npkName, imgIndex = imgDict[img] try: waitOpenNpk[npkName].append(imgIndex) waitOpenNpk[npkName] = list(set(waitOpenNpk[npkName])) except: waitOpenNpk[npkName] = [imgIndex] pBar = tqdm(waitOpenNpk.items()) for key, value in pBar: pBar.set_description("拼合NPK中>>>\r") extractedNpk = NPK() npkPath = img2Path + "\\" + key if ife(npkPath): extractedNpk.open(npkPath) else: notExistNpk.append(npkPath) continue extractImg_, errorIndex = extractedNpk.extractImg(value) npk.addDictImg(extractImg_) for key in errorIndex: notExistNpk.append(key + "\t第{index}号IMG不存在".format(index=key)) npk.save(npkSavePath, mode=False) return notInDictImg, notExistNpk
from extractFuncs.mainFunc import reComImg2Npk, getImg2DirPort, confirmExit from extractFuncs.toolFunc import ife from os import getcwd, system from pickle import load txtPath = getcwd() + '\\imgText.txt' errorLog = [] # img2Dir = input("输入IMG2目\n例:D:\\\\1128\\\\ImagePacks2\n") imgDir, port, saveMainDir, extractMode, npk = getImg2DirPort() while True: if ife(txtPath) and ife(imgDir + '\\img2NpkDict.pkl'): newNpkName = input("输入新生成的NPK名称,不用加后缀。例如:newNPK\n") with open(txtPath, 'r', encoding='utf-8') as img: imgList = ['sprite/' + line.replace('`', '').lower().strip() for line in img.readlines()] if len(imgList) > 0: with open(imgDir + '\\img2NpkDict.pkl', 'rb') as npkD: img2NpkDict = load(npkD) reComImg2Npk(imgList, img2NpkDict, getcwd() + '\\{}.npk'.format(newNpkName), imgDir, errorLog) with open(getcwd() + '\\errorLog.txt', 'w', encoding='utf-8')as f: for line in errorLog: f.write(line) else: pass flag = confirmExit()
equLst = toList(fromPvfGetContent(port, "equipment/equipment.lst")) cnP = re.compile( r'\[animation job\]\n`\[at swordman\].*equipment/character/atswordman\.lay`', flags=re.S) twP = re.compile("\[animation job\].*\.lay`", flags=re.S) twCharP = re.compile(r'\[usable job\].*\[/usable job\]', flags=re.S) # priestWeaponPath = [] for line in equLst: if 'character/swordman/weapon' in line: pvfPath = 'equipment/' + line.replace('`', '').lower().replace( '\\', '/') weaponC = fromPvfGetContent(port, pvfPath) filePath = "G:\\" + pvfPath.replace('/', '\\') if weaponC and ife(filePath): with open(filePath, 'r', encoding='utf-8') as cnF: cnWeaponC = cnF.read() twS = re.search(twP, weaponC) cnS = re.search(cnP, cnWeaponC) twCS = re.search(twCharP, weaponC) if twS and cnS and twCS: weaponC = re.sub(twCharP, replaceChar, weaponC) newC = weaponC.replace(twS.group(), twS.group() + '\n' + cnS.group()).replace( '`[at swordman]`', '`[at fighter]`') # print(newC) # break newPath = filePath.replace('G:', GetDesktopPath())
[allMobID, allObjID, allApcID, allCreID, allApdID, icons, directExtractFiles, repeatFileList, repeatStk] = getEmptyList(9) getContentList = directExtractFiles, repeatStk, allEquID, allMobID, \ allObjID, allApcID, repeatFileList, icons, allApdID getContentList, errorLog = stkIDFunc(allStkID, stkLst, equLst, getContentList, port, errorLog) repeatStk = list(set(list(set(repeatStk))) - set(allStkID)) # ------------新获取的STK重复 allStkID, getContentList = stkRepeat(repeatStk, allStkID, getContentList, stkLst, equLst, port, errorLog) directExtractFiles, repeatStk, allEquID, allMobID, allObjID, allApcID, repeatFileList, icons, allApdID = getContentList if ife(imgDir + '\\partSetDict.pkl'): with open(imgDir + '\\partSetDict.pkl', 'rb') as f: partSetIndexDict = load(f) else: partSetIndexDict = getPartSetIndexDict(imgDir, equLst, port) # ------------提取装备 trueVars = [] result = equExtract(allEquID, equLst, port, errorLog, imgDir) if result: _directExtractFiles, _repeatFileList, \ allEquID, _MobID, _ObjID, _ApdID, _CreID, _ApcID, \ _iconImgs, _trueVars, _partSetContent = result directExtractFiles += _directExtractFiles