Minecraft client: skip deleting and recopying an apmc file that is already in APData

This commit is contained in:
espeon65536 2021-08-15 08:16:30 -05:00 committed by Fabian Dill
parent ce6cdcaf92
commit 81da0d2ba4
1 changed files with 10 additions and 5 deletions

View File

@ -61,15 +61,20 @@ def replace_apmc_files(forge_dir, apmc_file):
if apmc_file is None: if apmc_file is None:
return return
apdata_dir = os.path.join(forge_dir, 'APData') apdata_dir = os.path.join(forge_dir, 'APData')
copy_apmc = True
if not os.path.isdir(apdata_dir): if not os.path.isdir(apdata_dir):
os.mkdir(apdata_dir) os.mkdir(apdata_dir)
print(f"Created APData folder in {forge_dir}") print(f"Created APData folder in {forge_dir}")
for entry in os.scandir(apdata_dir): for entry in os.scandir(apdata_dir):
if ".apmc" in entry.name and entry.is_file(): if entry.name.endswith(".apmc") and entry.is_file():
os.remove(entry.path) if not os.path.samefile(apmc_file, entry.path):
print(f"Removed {entry.name} in {apdata_dir}") os.remove(entry.path)
copyfile(apmc_file, os.path.join(apdata_dir, os.path.basename(apmc_file))) print(f"Removed {entry.name} in {apdata_dir}")
print(f"Copied {os.path.basename(apmc_file)} to {apdata_dir}") else: # apmc already in apdata
copy_apmc = False
if copy_apmc:
copyfile(apmc_file, os.path.join(apdata_dir, os.path.basename(apmc_file)))
print(f"Copied {os.path.basename(apmc_file)} to {apdata_dir}")
# Check mod version, download new mod from GitHub releases page if needed. # Check mod version, download new mod from GitHub releases page if needed.