Skip to content

Conversation

4onen
Copy link
Contributor

@4onen 4onen commented Mar 21, 2025

As it says on the tin, implements unpacking of zip files that contain acceptably-formatted AwSW mods.

Purpose

To make non-Steam-Workshop mod installation easier.

Code process

After the mod folder list is compiled with reset_mods(), but before any mods are imported, this PR separates out and removes files whose lowercase path end in ".zip".

The implementation assumes the mod is implemented using an __init__.py at the root of the mod directory, as is the currently accepted mod format. It solves for zip files being nasty and nesting folders by finding the shallowest folder containing an __init__.py and extracting that + all siblings and siblings' descendants. If multiple folders have an __init__.py at the same depth, it errors out. If no __init__.py exists in the zip, it errors out.

The folder name for the extracted mod is the name of the zip without the ".zip" extension. If a folder already exists with that name, the m_time of the zip and folder are compared. If the zip is newer, the folder is recursively deleted and the zip file's contents are extracted into a fresh folder.

This process is performed for all zip files found in the mod directory. If any zip has been unpacked (after the m_time checks) then the game restarts entirely, exactly as if the user had clicked Remove mod and reload on an error screen.

Drawbacks

  • Fully reloads the game if any zips get unpacked. Not bad per-se but means it takes a few more seconds to boot on mod update on underpowered platforms. Only adds minimal overhead (stat n zip files, stat n folders up to twice) on subsequent boots.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant