-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Supporting Directory Trees in MPQ Cross-Platform #36
base: master
Are you sure you want to change the base?
Conversation
…code reuse in extract_to_disk, add test with GatherMinerals.SC2Map and license. Should work on Python2.7, tested working on 3.7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR!
Aside some minor nitpicks, I don't think target_dir
should be a **kwargs
style dictionary here. I'd propose just making it a normal parameter with a default argument of os.getcwd()
.
(I'll take the liberty to fixup your later commits into the main one to clean up git history.)
"""Extract all the files inside the MPQ archive in memory.""" | ||
if self.files: | ||
return dict((f, self.read_file(f)) for f in self.files) | ||
files = filenames if len(filenames)>0 else self.files |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: missing spaces around comparison operator
for filename in filenames: | ||
data = self.read_file(filename) | ||
f = open(filename, 'wb') | ||
create_dir = os.path.join(target_dir, archive_name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
create_dir
could maybe be renamed to archive_dir
to better reflect which directory it represents.
@@ -252,29 +252,28 @@ def decompress(data): | |||
|
|||
return file_data | |||
|
|||
def extract(self): | |||
def extract(self, *filenames): | |||
"""Extract all the files inside the MPQ archive in memory.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This docstring is no longer necessarily true after the addition of *filenames
.
else: | ||
raise RuntimeError("Can't extract whole archive without listfile.") | ||
|
||
def extract_to_disk(self): | ||
def extract_to_disk(self, *filepaths, **target_dir): | ||
"""Extract all files and write them to disk.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This docstring is no longer necessarily true after the addition of *filenames
.
PR for #36.
This PR converts backslash separated filenames in MPQs into directory trees rather than concatenated long filenames (I believe as intended by the MPQ format). In doing so it makes the library and its extraction results compatible with Windows.
There is a small interface change to share the file writing code across extracting "all files" and "some files". This does not affect command line usage.
Added minigame and test for extraction to disk for CollectMineralShards from PySC2. License from PySC2 included.
Tests confirmed passing on: