def clear_vpk_files(game) -> str: """Remove existing VPKs files from a game. We want to leave other files - otherwise users will end up regenerating the sound cache every time they export. This returns the path to the game folder. """ dest_folder = game.abs_path( VPK_FOLDER.get( game.steamID, 'portal2_dlc3', )) os.makedirs(dest_folder, exist_ok=True) try: for file in os.listdir(dest_folder): if file[:6] == 'pak01_': os.remove(os.path.join(dest_folder, file)) except PermissionError: # The player might have Portal 2 open. Abort changing the VPK. LOGGER.warning("Couldn't replace VPK files. Is Portal 2 " "or Hammer open?") raise return dest_folder
def post_parse(cls) -> None: """Verify no quote packs have duplicate IDs.""" def iter_lines(conf: Property) -> Iterator[Property]: """Iterate over the varios line blocks.""" yield from conf.find_all("Quotes", "Group", "Quote", "Line") yield from conf.find_all("Quotes", "Midchamber", "Quote", "Line") for group in conf.find_children("Quotes", "CoopResponses"): if group.has_children(): yield from group for voice in cls.all(): used: Set[str] = set() for quote in iter_lines(voice.config): try: quote_id = quote['id'] except LookupError: quote_id = quote['name', ''] LOGGER.warning( 'Quote Pack "{}" has no specific ID for "{}"!', voice.id, quote_id, ) if quote_id in used: LOGGER.warning( 'Quote Pack "{}" has duplicate ' 'voice ID "{}"!', voice.id, quote_id, ) used.add(quote_id)
def parse(cls, data: ParseData) -> 'PackList': """Read pack lists from packages.""" filesystem = data.fsys conf = data.info.find_key('Config', '') if 'AddIfMat' in data.info: LOGGER.warning( '{}:{}: AddIfMat is no ' 'longer used.', data.pak_id, data.id, ) files = [] if conf.has_children(): # Allow having a child block to define packlists inline files = [prop.value for prop in conf] elif conf.value: path = 'pack/' + conf.value + '.cfg' with filesystem, filesystem.open_str(path) as f: # Each line is a file to pack. # Skip blank lines, strip whitespace, and # allow // comments. for line in f: line = srctools.clean_line(line) if line: files.append(line) # Deprecated old option. for prop in data.info.find_all('AddIfMat'): files.append('materials/' + prop.value + '.vmt') if not files: raise ValueError('"{}" has no files to pack!'.format(data.id)) if CHECK_PACKFILE_CORRECTNESS: # Use normpath so sep differences are ignored, plus case. resources = { os.path.normpath(file.path).casefold() for file in filesystem.walk_folder('resources/') } for file in files: if file.startswith(('-#', 'precache_sound:')): # Used to disable stock soundscripts, and precache sounds # Not to pack - ignore. continue file = file.lstrip( '#') # This means to put in soundscript too... # Check to make sure the files exist... file = os.path.join('resources', os.path.normpath(file)).casefold() if file not in resources: LOGGER.warning( 'Warning: "{file}" not in zip! ({pak_id})', file=file, pak_id=data.pak_id, ) return cls(data.id, files)