Implement mod zip unpacking #121
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 clickedRemove mod and reload
on an error screen.Drawbacks