Last active
January 13, 2024 01:32
-
-
Save tarosbubbletea/2a6e741578fd7b5b4ef00bfb288bb0ac to your computer and use it in GitHub Desktop.
python script to symlink ONLY CAMPAIGNS from a local l4d2 install to a l4d2 dedicated server. do py -m pip install vpk beforehand
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import vpk, glob, os, re | |
original_workshop_path = os.path.abspath('D:\\SteamLibrary\\steamapps\\common\\Left 4 Dead 2\\left4dead2\\addons\\workshop') | |
destination_addons_folder = os.getcwd() #intended to be ran in the addons folder of the dedicated server | |
allvpks = glob.glob(original_workshop_path+'\\*.vpk') | |
nicevpks = [] | |
preparedregex = r'addonContent_Campaign[\s\t]+?1' | |
counter = 0 | |
counter2 = 0 | |
for i in allvpks: | |
counter += 1 | |
pak1 = vpk.open(i) | |
try: | |
pakfile = pak1.get_file("addoninfo.txt") #mods with no addoninfos will not be copied for good measure. | |
addoninfo = pakfile.read().decode('latin1') | |
counter2 += 1 | |
if re.search(preparedregex,addoninfo,re.I): #exists: None, otherwise: <re.Match object; ...> | |
nicevpks.append(i) | |
except: | |
print(f'Exception for file {os.path.basename(i)}') | |
continue | |
print(f'Went through {counter} vpks, {counter2} addoninfos processed, {len(nicevpks)} campaigns.') | |
for i in nicevpks: | |
os.symlink(i, os.path.join(destination_addons_folder,os.path.basename(i))) #remember to delete symlinks if they already exist in the dest first. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment