def _getFileType(dirPath, baseName): tokens = baseName.split(".") if len(tokens) < 2: return FileNodeType.Invalid lastToken = tokens[-1] if lastToken == "png": return FileNodeType.Image elif lastToken == "ogg": return FileNodeType.Sound elif lastToken == "json": return FileNodeType.Entity elif lastToken == "frag": return FileNodeType.FragShader elif lastToken == "vert": return FileNodeType.VertShader elif lastToken == "ttf": return FileNodeType.TTFFont else: Log.warning( "[AssetsModel:_getFileType] Can't determine file type: '{0}/{1}'". format(dirPath, baseName)) return FileNodeType.Invalid
def _onPaste(self): copyFile = GetCopyPasteManager().getCopyFile() if not os.path.exists(copyFile): GetCopyPasteManager().setCopyFile(None, doCut=True) Log.warning( "[FileTreeMenu:_onPaste] Can't find file to copy: '{0}'". format(copyFile)) return doCut = GetCopyPasteManager().getCutFlag() dstDir = self._getCopyDirDestination() if doCut: try: shutil.move(copyFile, dstDir) except Exception as e: Log.warning( "[FileTreeMenu:_onPaste] Can't move file '{0}' to another '{1}' (Error: {2})" .format(copyFile, dstDir, e.__str__())) return else: path = pathlib.Path(copyFile) stemName = path.stem extName = path.suffix i = 1 while True: newFilePath = "{0}/{1} ({2}){3}".format( dstDir, stemName, i, extName) if not os.path.exists(newFilePath): break try: if not os.path.isdir(copyFile): shutil.copy2(copyFile, newFilePath) else: shutil.copytree(copyFile, newFilePath) except Exception as e: Log.warning( "[FileTreeMenu:_onPaste] Can't copy file '{0}' to another '{1}' (Error: {2})" .format(copyFile, newFilePath, e.__str__())) return GetEventManager().rebuildAssetsModel()