def saveDirFunc(parent): saveDir = QFileDialog.getExistingDirectory(parent, "选取保存文件夹", "./") # print(saveDir, type(saveDir)) if saveDir != "": parent.mainWin.savePath = saveDir.replace("/", "\\") # print(parent.mainWin.savePath) iep(parent.mainWin.savePath)
def outPutExtractFile(utPort: str, fileList: list, errorLog: list, saveMainDir: str, imgNpkDict=None): imgList = [] for filePath in fileList: if isinstance(filePath, bool): continue content = fromPvfGetContent(utPort, filePath.lower()) if content is False: errorLog.append(filePath + "\t可能不存在") continue try: contentList = fileText2List(content) except: errorLog.append(filePath + "\t解析错误,请确认文件是否正确") continue savePath = saveMainDir + "\\".join(filePath.split('/')) iep(path.split(savePath)[0]) with open(savePath, 'w', encoding='utf-8') as file: for line in contentList: file.write(line + '\n') # except: # errorLog.append(savePath + "\t保存失败") if imgNpkDict: imgList = getImgList(contentList, imgList, imgNpkDict) return list(set(imgList)), errorLog
def outPutFileAndNPK(saveMainDir, lstD, imgDir, npkFlag, allFile, errorLog, utPort, exImg=None, exLstT=None): iep(saveMainDir) lstSavePath = checkLstFile(saveMainDir) # -----------导出文件+整合IMG outPutLstFile(lstD, lstSavePath, exLstT) if npkFlag == "1": imgNpkDict = getImgDict(imgDir) imgList, errorLog = outPutExtractFile(utPort, allFile, errorLog, saveMainDir, imgNpkDict) if exImg: exImgList = getTrueVarImg(list(set(exImg[0])), imgNpkDict) + exImg[1] imgList += exImgList imgList = list(set([img.lower() for img in imgList])) imgList.sort() npkSavePath = saveMainDir + "\\sprite_a(extract).NPK" with open(saveMainDir + "\\IMG列表.txt", 'w', encoding="utf-8") as imgLst: for img in imgList: imgLst.write(img + '\n') errorLog = reComImg2Npk(imgList, imgNpkDict, npkSavePath, imgDir, errorLog) else: imgList, errorLog = outPutExtractFile(utPort, allFile, errorLog, saveMainDir) return imgList, errorLog
def saveFile(stkID, content, stkList, apcSaveDir): iep(apcSaveDir + '\\stackable\\apcPackage') savePath = apcSaveDir + '\\stackable\\apcPackage\\{stk}.stk'.format( stk=str(stkID)) with open(savePath, 'w', encoding='utf-8') as f: f.write(content) stkList.append( str(stkID) + '\n' + '`' + savePath.replace(apcSaveDir + '\\stackable\\', '').replace('\\', '/') + '`\n') return stkID + 1, stkList
def reCheckSetting(settingList, settingFilePath, settingDict): [imgDir, puPort, saveMainDir, extractMode, npkMode] = settingList imgDir = checkDir(imgDir) # 测试port puPort = checkPuPort(puPort) # 创建保存路径 iep(saveMainDir) # 测试全提取模式 extractMode = checkFlag(extractMode, "请输入提取模式,全部提取为1,分别提取为0\n") # 测试NPK提取模式 npkMode = checkFlag(npkMode, "请输入NPK导出模式,导出整合NPK为1,不导出为0\n" "注意,导出整合NPK需要正确的IMG2目录支持,创建NPK词典可能会花费一些时间\n") result = [imgDir, puPort, saveMainDir, extractMode, npkMode] for i in range(len(settingDict.keys())): settingDict[list(settingDict.keys())[i]] = result[i] with open(settingFilePath, 'w') as setting: for key, value in settingDict.items(): setting.write("{}=[{}]".format(key, value) + '\n') return settingDict
def dropImg(self, index=-1, savePath=GetDesktopPath() + "\\dropImg", dropAllMode=False): """ 提取NPK内IMG保存为文件 :param dropAllMode: 全提取标识符, 全提取时,会在桌面目录下创建一个dropImg文件夹,并在其之中创建已被提取NPK的名字命名的文件夹 :param index: 提取编号或列表 :param savePath: 保存路径 :return: """ header, imgCount, dictA, dictB, imgContentSplits = self.getSplitData() def saveImg(index_, path_, dict_, contents_): for element in index_: imgName = dict_[element][-1] imgContent = contents_[element] with open(path_ + "\\{name}".format(name=imgName), 'wb') as dropImg: dropImg.write(imgContent) return True if dropAllMode: savePath = GetDesktopPath() + "\\dropImg" + "\\{npkName}".format( npkName=self.path.split('\\')[-1]) # 判断创建保存目录 iep(savePath) saveImg(range(imgCount), savePath, self.dictAna, imgContentSplits) return True if isinstance(index, int): index = [index] if isinstance(index, list): # 判断创建保存目录 iep(savePath) saveImg(index, savePath, self.dictAna, imgContentSplits) return True return True
def writeSetting(settingFilePath, settingDict): print("未找到配置文件,请设置\n") imgDir = checkDir(dirType="IMG2") puPort = checkPuPort() saveMainDir = input("请输入默认保存路径, 例如\tD:\\提取保存文件夹\n").replace('\\', '\\\\').strip() iep(saveMainDir) extractMode = checkFlag(text="请输入提取模式,全部提取为1,分别提取为0\n") npkMode = checkFlag(text="请输入NPK导出模式,导出整合NPK为1,不导出为0\n注意," "导出整合NPK需要正确的IMG2目录支持," "创建NPK词典可能会花费一些时间\n") result = [imgDir, puPort, saveMainDir, extractMode, npkMode] for i in range(len(settingDict.keys())): settingDict[list(settingDict.keys())[i]] = result[i] with open(settingFilePath, 'w') as setting: for key, value in settingDict.items(): setting.write("{}=[{}]".format(key, value) + '\n') return settingDict
def ani2GifSingle(ani, img2Dir, imgDict, saveDir=GetDesktopPath() + '\\ani2Gif', port="27000", mainWin=None): aniResult = anaAni(ani, port) if isinstance(aniResult, str): print(ani + '\tError') return False else: nameFrameList, delays = aniResult aniName = ani.split('\\')[-1] allFrameDicts = {} imgNameList = [] for nameFrame in nameFrameList: imgName, frameIndex = nameFrame if imgName in list(allFrameDicts.keys()): allFrameDicts[imgName].append(frameIndex) else: allFrameDicts[imgName] = [frameIndex] imgNameList.append(imgName) imgNameConDict = {} # 从主程序加载的IMG资源中读取IMG if mainWin: notInList = [] for imgName in imgNameList: if imgName in mainWin.npkSource.keys(): imgNameConDict[imgName] = mainWin.npkSource[imgName] else: notInList.append(imgName) loadIMGSource(mainWin, notInList) for imgName in notInList: if imgName in mainWin.npkSource.keys(): imgNameConDict[imgName] = mainWin.npkSource[imgName] else: print(imgName + "没被加载") else: imgNameConDict = getImgContent(img2Dir, imgNameList, imgDict) imgNameKeys = list(imgNameConDict.keys()) imgNameFrameImageDict = {} for imgName, frameIndex in allFrameDicts.items(): if imgName not in imgNameKeys: print(imgName + '\tError') continue imgContent = imgNameConDict[imgName] imgNameFrameImageDict[imgName] = getImage(imgName, imgContent, frameIndex) gifSaveFilePath = saveDir + '\\{}.gif'.format( aniName.split('/')[-1].split('.')[0]) allFrameImage = [] for element in nameFrameList: allFrameImage.append(imgNameFrameImageDict[element[0]][element[1]]) # for index, Image_ in enumerate(allFrameImage): # Image_.show() iep(saveDir) return saveGif(allFrameImage, gifSaveFilePath, delays, showMode=False)
def ani2Gif(aniList, img2Dir, imgDict, saveDir=GetDesktopPath() + '\\ani2Gif', mode=False, port=""): # aniFrameDict = {aniName: [nameFrameList, delays] } # nameFrameList = {imgName: aniFrameIndexList} aniFrameDict = {} # ~ imgFrames = [] # ~ for ani in aniList: if ani.split('.')[-1].lower() != 'ani': continue aniResult = anaAni(ani, port) if isinstance(aniResult, str): print(ani + '\tError') continue else: nameFrameList, delays = aniResult aniName = ani.split('\\')[-1] imgFrames.append(nameFrameList) aniFrameDict[aniName] = [nameFrameList, delays] # allFrameDicts = {imgName: allFrameIndex } allFrameDicts, imgNameList = getAllImgFrame(imgFrames) # imgNameConDict = {imgName: imgContent } imgNameConDict = getImgContent(img2Dir, imgNameList, imgDict) # imgNameFrameImageDict = {imgName: # {frameIndex: ImageObject } # } imgNameKeys = list(imgNameConDict.keys()) imgNameFrameImageDict = {} for imgName, frameIndex in allFrameDicts.items(): if imgName not in imgNameKeys: print(imgName + '\tError') continue imgContent = imgNameConDict[imgName] imgNameFrameImageDict[imgName] = getImage(imgName, imgContent, frameIndex) ########################### # 拼合 if mode: iep(saveDir) gifName = '-'.join( [aniName.split('.')[0] for aniName in aniFrameDict.keys()]) gifSavePath = saveDir + '\\{}.gif'.format(gifName) allDelay = [] allFrameImage = [] for frameIndex in aniFrameDict.values(): nameFrameList, delays = frameIndex allDelay += delays for element in nameFrameList: allFrameImage.append( imgNameFrameImageDict[element[0]][element[1]]) return saveGif(allFrameImage, gifSavePath, allDelay, showMode=False) else: iep(saveDir) gifPathList = [] for aniName, VALUE in aniFrameDict.items(): gifSavePath = saveDir + '\\{}.gif'.format(aniName.split('.')[0]) if port != "": gifSavePath = saveDir + '\\{}.gif'.format( aniName.split('/')[-1].split('.')[0]) allFrameImage = [] nameFrame, delays = VALUE for element in nameFrame: allFrameImage.append( imgNameFrameImageDict[element[0]][element[1]]) # for index, Image_ in enumerate(allFrameImage): # Image_.show() gifPathList.append( saveGif(allFrameImage, gifSavePath, delays, showMode=False)) return gifPathList
errorLog = result break npcID, errorLog = result directExtractFiles, allItemID, npcWritID, itemshopWriteID, npcItemDIct, errorLog = extractNpc( npcLst, itemShopLst, npcID, port, errorLog) name = "\\NPC\\{}".format("_".join(npcID)) lstDict = { "npc": [npcWritID, npcLst], "itemshop": [itemshopWriteID, itemShopLst] } itemIDFilePath = saveMainDir + name + "\\商店物品列表.txt" iep(saveMainDir + name) with open(itemIDFilePath, 'w', encoding='utf-8') as f: f.write('**所有商店物品代码**\n') items = ','.join(allItemID) f.write('-' * (len(items) + 4) + '\n') f.write('+ ' + items + ' +\n') f.write('-' * (len(items) + 4) + '\n\n') f.write('\n\n**对应NPC/ItemShop商店物品代码**\n') for npc, item in npcItemDIct.items(): f.write('npcName:' + item[2] + '\n' + 'npcID:\t' + npc + '\n' + 'itemShopID:\t' + item[0] + '\n') items = ','.join(item[1]) f.write('-' * (len(items) + 4) + '\n') f.write('+ ' + items + ' +\n') f.write('-' * (len(items) + 4) + '\n\n')
def save(self, path): iep("\\".join(path.split('\\')[:-1])) self.img.save(path)
cList[index + 1] = "`[priest]`" nameList[name].append('\n'.join(cList[index:i + 1])) if name in nameList.keys(): equL = '`' + '/'.join( equF.split('\\')[2:-1]) + '/soulWeapon{}.equ`'.format( str(start_id)) savePath = '\\'.join( equF.replace('H:', GetDesktopPath() + '\\new').split('\\') [:-1]) + '\\soulWeapon{}.equ'.format(str(start_id)) nameList[name] += [savePath, str(start_id), equL] start_id += 1 iep('\\'.join(nameList[list(nameList.keys())[0]][-3].split('\\')[:-1])) with open(GetDesktopPath() + '\\new\\equipment.lst', 'w', encoding='utf-8') as ls: for key, value in nameList.items(): newW = weaponModel newW = newW + key + '\n' for v in value[:-3]: newW += v + '\n' with open(value[-3], 'w', encoding='utf-8') as f: f.write(newW.format(job=' `[priest]`')) ls.write(value[-2] + '\n' + value[-1] + '\n') # with open()
def extractAva(pvfDecodeDir, job): avatarDict = {} extractList = [] with open(pvfDecodeDir + "\\equipment.lst", 'r', encoding='utf-8') as f: trueContent = f.read().replace('\t', '\r\n') equLst = [ line.strip() for line in trueContent.split('\n') if line != '' ] for index, line in enumerate(equLst): splitC = line.replace('\\', '/').lower().split('/') if len(splitC) > 2 and job in line and splitC[3] not in errorList: avatarDict[equLst[index - 1]] = [ pvfDecodeDir + "\\" + line.replace('`', '').replace('/', '\\'), line ] for code, path in avatarDict.items(): try: with open(path[0], 'r', encoding='utf-8') as equ: content = equ.read() except: print(path[0] + "\t不存在或者文件错误") continue # 替换职业 if content: contentList = fileText2List(content) if "[name]" not in contentList: continue else: name = contentList[contentList.index("[name]") + 1] if "name_" in name or name == "``" or 'awaken' in name or '[' in name or '((' in name or '??' in name: continue content = re.sub(jobP, "`[at fighter]`", content) # 删除[avatar type select] content = re.sub(typeSelectP, "", content, flags=re.S) # 删除套装 content = re.sub(partSetP, '', content, flags=re.S) # 修复属性 content = re.sub(abilityP, ability, content, flags=re.S) content = re.sub(coatAbilityP, ability, content, flags=re.S) content = re.sub(skillLevelP, '', content, flags=re.S) content = re.sub(clearP, '''[clear avatar] 1''', content, flags=re.S) content = re.sub(p1, '', content, flags=re.S) filePath = GetDesktopPath( ) + '\\extractAvatar\\equipment\\' + path[1].replace( '/', '\\').replace('`', '') dirPath = '\\'.join(filePath.split('\\')[:-1]) iep(dirPath) with open(filePath, 'w', encoding='utf-8') as f: f.write(content) extractList.append(code) extractList.append(path[-1]) with open(GetDesktopPath() + '\\extractAvatar\\{}.lst'.format(job.split("/")[0]), 'w', encoding='utf-8') as f: for line in extractList: f.write(line + '\n')
if len(_partSetContent) > 0: setPartContent += _partSetContent + '\n' # ------------重复获取可重复文件 directExtractFiles, allObjID, allMobID, errorLog = repeatGet(allObjID, objLst, allMobID, mobLst, repeatFileList, directExtractFiles, allApcID, port, errorLog) notInLstApc = checkInList(allApcID, apcLst) errorLog += [apcID + "\tAPC不在列表中" for apcID in notInLstApc] apdFilePathList, allApdID = getApdFilePathList(allApdID, apdLst, port, errorLog) directExtractFiles += apdFilePathList # ------------写出文件 newSaveMainDir = saveMainDir + '\\消耗品_装备\\{name}\\'.format(name=allItemID[0]) iep(newSaveMainDir[:-1]) # 写出列表 lstSavePath = newSaveMainDir + "\\提取列表.txt" lstDict = {"stackable": [allStkID, stkLst], "equipment": [allEquID, equLst], "aicharacter": [allApcID, apcLst], "appendage": [allApdID, apdLst], "creature": [allCreID, creLst], "passiveObject": [allObjID, objLst], "monster": [allMobID, mobLst]} # ------------导出整合IMG imgList, errorLog = outPutFileAndNPK(newSaveMainDir, lstDict, imgDir, npk, directExtractFiles, errorLog, port, [trueVars, icons])
errorLog = result break allApcID, errorLog = result # -----------获取提取DGN路径 # print(allApcID) if len(allApcID) == 0: with open(saveMainDir + '\\error.log', 'w', encoding='utf-8') as f: for line in errorLog: f.write(line + '\n') break if extractMode: apcSaveDir = saveMainDir + '\\APC\\ALL-APC\\' else: apcSaveDir = saveMainDir + '\\APC\\' + '-'.join(allApcID) + '\\' iep(apcSaveDir) allDirectFile, allRepeatFile, allItems, newAllApc, allObjID, allMobID, stkList, newCashShopList = getEmptyList( 8) apcNameList = getApcNameDict(allApcID, apcLst, equLst, port, errorLog) for apcC in apcNameList: [apcID, apcName, equItem, apcJob, directFile, repeatFile] = apcC allItems += equItem allDirectFile += directFile allRepeatFile += repeatFile newAllApc.append(apcID) newSummon = summonStk.format(name=apcName, ID=apcID)
directExtractFiles += creDirectFile repeatFileList += creRepeatFile allObjID += creObj # ------------重复获取可重复文件 directExtractFiles, allObjID, allMobID, errorLog = repeatGet( allObjID, objLst, allMobID, mobLst, repeatFileList, directExtractFiles, allApcID, port, errorLog) apdFilePathList, allApdID = getApdFilePathList(allApdID, apdLst, port, errorLog) directExtractFiles += apdFilePathList # ------------写出文件 newSaveMainDir = saveMainDir + '\\装备\\{name}\\'.format(name=allEquID[0]) iep(newSaveMainDir) lstSavePath = newSaveMainDir + "\\提取列表.txt" lstDict = { "appendage": [allApdID, apdLst], "equipment": [allEquID, equLst], "creature": [allCreID, creLst], "passiveObject": [allObjID, objLst], "monster": [allMobID, mobLst] } # ------------导出整合IMG imgList, errorLog = outPutFileAndNPK(newSaveMainDir, lstDict, imgDir, npk, directExtractFiles, errorLog, port, [trueVars, iconImgFiles])
ability, buy, "[attach type]", "`[free]`" ] if clearFlag: needClist += ["[enable dye]", "1 0"] try: flag = '\\' + file.split('\\')[9] + '\\' except: print(file) continue newPath = '\\'.join(file.replace('\\wwww\\', '\\new\\').split('\\')[:-1]) + '\\' + str( partType[flag]) + '.equ' iep('\\'.join(newPath.split('\\')[:-1])) newEquLst += [ str(partType[flag]), '`' + newPath.replace(GetDesktopPath() + '\\new\\equipment\\', '').replace('\\', '/') + '`' ] # print(startIndex, newPath, newEquLst) partType[flag] += 1 # break with open(newPath, 'w', encoding='utf-8') as f2: for line in needClist: f2.write(line + '\n') with open(GetDesktopPath() + '\\equ.lst', 'w', encoding='utf-8') as f: for line in newEquLst: f.write(line + '\n')
from extractFuncs.toolFunc import GetDesktopPath, laf, iep with open(GetDesktopPath() + '\\weaponAni.txt', 'r', encoding='utf-8') as f: weaponAniList = [line.strip() for line in f.readlines() if line != ''] for line in weaponAniList: a, b = line.split('\t') weaponType = 'at_' + a.split('_')[0] dirPath = GetDesktopPath() + '\\type\\' + weaponType newDir = GetDesktopPath() + '\\weaponNew\\' + 'at_' + a.replace('_', '') iep(newDir) for file in laf(dirPath): with open(file, 'r', encoding='utf-8') as aniF: newC = aniF.read().replace('%s', b.replace('sprite/', '')) with open(newDir + '\\' + file.split('\\')[-1], 'w', encoding='utf-8') as newF: newF.write(newC) with open(GetDesktopPath() + '\\layerT.txt', 'r', encoding='utf-8') as f: avatarAniList = [line.strip() for line in f.readlines() if line != ''] for line in avatarAniList: a, b = line.split('\t') avatarType = a.split('_')[0] newDir = GetDesktopPath() + '\\avatarAniNew\\' + avatarType + '\\' + a iep(newDir) for file in laf(GetDesktopPath() + '\\atanimation'): with open(file, 'r', encoding='utf-8') as aniF: newC = aniF.read().replace('%s', b.replace('sprite/', '')) with open(newDir + '\\' + file.split('\\')[-1], 'w', encoding='utf-8') as newF: