Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions UnityPy/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,24 @@ def load(self, files: List[str]):
{ntpath.basename(f): self.load_file(self.fs.open(f, "rb"), self, f) for f in files if self.fs.exists(f)}
)

def _load_split_file(self, basename: str) -> bytes:
def _load_split_file(self, basename: str, open_f: Callable[[str], BinaryIO] = None) -> bytes:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type annotation of open_f should be wrapped with Optional[...].

file: List[bytes] = []
for i in range(0, 999):
item = f"{basename}.split{i}"
if self.fs.exists(item):
with self.fs.open(item, "rb") as f:
file.append(f.read()) # type: ignore
elif i:
Comment thread
GoJean marked this conversation as resolved.
Resolved
break
if open_f:
try:
file.append(open_f(item).read())
except:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will cause E722 Do not use bare except ruff error.

if i:
break
else:
if self.fs.exists(item):
with self.fs.open(item, "rb") as f:
file.append(f.read()) # type: ignore
else:
if i:
break

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line has trailing spaces

return b"".join(file)

def load_file(
Expand Down Expand Up @@ -311,7 +320,7 @@ def load_assets(self, assets: List[str], open_f: Callable[[str], BinaryIO]):
continue

split_files.append(basepath)
data = self._load_split_file(basepath)
data = self._load_split_file(basepath, open_f)
path = basepath
else:
data = open_f(path)
Expand Down