Deleted some comments

This commit is contained in:
2024-02-20 23:02:10 -05:00
parent a219f22614
commit 5b002940f4

14
main.py
View File

@@ -131,7 +131,7 @@ def save_modpack_manifest(modpack_dir, mod_filenames):
def is_modpack_installed(modpack_dir): def is_modpack_installed(modpack_dir):
manifest_path = os.path.join(modpack_dir, 'modpack_manifest.txt') manifest_path = os.path.join(modpack_dir, 'modpack_manifest.txt')
if not os.path.exists(manifest_path): if not os.path.exists(manifest_path):
return False # Manifest does not exist, modpack likely not installed. return False
with open(manifest_path, 'r') as manifest_file: with open(manifest_path, 'r') as manifest_file:
manifest_files = {line.strip() for line in manifest_file} manifest_files = {line.strip() for line in manifest_file}
existing_files = {file for file in os.listdir(modpack_dir) if os.path.isfile(os.path.join(modpack_dir, file))} existing_files = {file for file in os.listdir(modpack_dir) if os.path.isfile(os.path.join(modpack_dir, file))}
@@ -153,14 +153,12 @@ def install_modpack(modpack_url, modpack_dir, mods_backup_dir):
modpack_files = set() modpack_files = set()
with zipfile.ZipFile(zip_path) as modpack_zip: with zipfile.ZipFile(zip_path) as modpack_zip:
for member in modpack_zip.namelist(): for member in modpack_zip.namelist():
if not member.endswith("/"): # Ignore directories if not member.endswith("/"):
filename = os.path.basename(member) # Get base name to avoid directory structure filename = os.path.basename(member)
if filename: # Ignore any empty names if filename:
# Compute target path for extraction
target_path = os.path.join(modpack_dir, filename) target_path = os.path.join(modpack_dir, filename)
modpack_files.add(filename) modpack_files.add(filename)
# Extract each file to its correct location
source = modpack_zip.open(member) source = modpack_zip.open(member)
target = open(target_path, "wb") target = open(target_path, "wb")
@@ -168,8 +166,8 @@ def install_modpack(modpack_url, modpack_dir, mods_backup_dir):
shutil.copyfileobj(source, target) shutil.copyfileobj(source, target)
print("Modpack installed successfully.") print("Modpack installed successfully.")
os.remove(zip_path) # Clean up the downloaded ZIP file os.remove(zip_path)
save_modpack_manifest(modpack_dir, modpack_files) # Update the manifest save_modpack_manifest(modpack_dir, modpack_files)
except Exception as e: except Exception as e:
print(f"An error occurred during modpack installation: {e}") print(f"An error occurred during modpack installation: {e}")