Skip to content

Commit

Permalink
Fix zip slashes error
Browse files Browse the repository at this point in the history
  • Loading branch information
SunsetMkt committed Jun 14, 2024
1 parent 7935860 commit eb45364
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions MSD-Manual-Portable.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,25 @@ def msd_manual_parser(target_dir, dest_dir):
return dest_dir


def extract_zip_file(origFilename, unzippedDirName):
with zipfile.ZipFile(origFilename, "r") as zip_ref:
for member in zip_ref.infolist():
# Replace backslashes with forward slashes
member_path = member.filename.replace("\\", "/")
target_path = os.path.join(unzippedDirName, member_path)

print(f"Extracting {target_path}")

# Create target directories if they don't exist
if not os.path.exists(os.path.dirname(target_path)):
os.makedirs(os.path.dirname(target_path))

# Extract the file
if not member.is_dir():
with zip_ref.open(member) as source, open(target_path, "wb") as target:
shutil.copyfileobj(source, target)


# argparse
parser = argparse.ArgumentParser(
# prog='MSD-Manual-Portable',
Expand Down Expand Up @@ -250,8 +269,9 @@ def msd_manual_parser(target_dir, dest_dir):

if not os.path.exists(os.path.join(unzippedDirName, "index.html")):
print("Unpacking MSD Manual...")
with zipfile.ZipFile(origFilename, "r") as zip_ref:
zip_ref.extractall(unzippedDirName)
# with zipfile.ZipFile(origFilename, "r") as zip_ref:
# zip_ref.extractall(unzippedDirName)
extract_zip_file(origFilename, unzippedDirName)
print("Unpacking complete.")

# Try getting favicon.ico
Expand Down

0 comments on commit eb45364

Please sign in to comment.