mirror of
https://github.com/leminlimez/Nugget.git
synced 2025-04-08 04:23:05 +08:00
read individual files rather than all at once
This commit is contained in:
@@ -2,7 +2,6 @@ from .tweak_classes import Tweak
|
||||
from Sparserestore.restore import FileToRestore
|
||||
import os
|
||||
import zipfile
|
||||
from tempfile import TemporaryDirectory
|
||||
|
||||
class PosterboardTweak(Tweak):
|
||||
def __init__(self):
|
||||
@@ -13,19 +12,18 @@ class PosterboardTweak(Tweak):
|
||||
|
||||
def recursive_add(self, files_to_restore: list[FileToRestore], curr_path: str, restore_path: str = "", isAdding: bool = False):
|
||||
for folder in sorted(os.listdir(curr_path)):
|
||||
if folder == ".DS_Store" or folder == "__MACOSX":
|
||||
if folder.startswith('.') or folder == "__MACOSX":
|
||||
continue
|
||||
if isAdding:
|
||||
# if file then add it, otherwise recursively call again
|
||||
if os.path.isfile(os.path.join(curr_path, folder)):
|
||||
try:
|
||||
with open(os.path.join(curr_path, folder), "rb") as in_file:
|
||||
contents = in_file.read()
|
||||
files_to_restore.append(FileToRestore(
|
||||
contents=contents,
|
||||
restore_path=f"{restore_path}/{folder}",
|
||||
domain=f"AppDomain-{self.bundle_id}"
|
||||
))
|
||||
files_to_restore.append(FileToRestore(
|
||||
contents=None,
|
||||
contents_path=os.path.join(curr_path, folder),
|
||||
restore_path=f"{restore_path}/{folder}",
|
||||
domain=f"AppDomain-{self.bundle_id}"
|
||||
))
|
||||
except IOError:
|
||||
print(f"Failed to open file: {folder}") # TODO: Add QDebug equivalent
|
||||
else:
|
||||
@@ -38,7 +36,7 @@ class PosterboardTweak(Tweak):
|
||||
else:
|
||||
self.recursive_add(files_to_restore, os.path.join(curr_path, folder), isAdding=False)
|
||||
|
||||
def apply_tweak(self, files_to_restore: list[FileToRestore]):
|
||||
def apply_tweak(self, files_to_restore: list[FileToRestore], output_dir: str):
|
||||
# unzip the file
|
||||
if not self.enabled:
|
||||
return
|
||||
@@ -52,8 +50,7 @@ class PosterboardTweak(Tweak):
|
||||
return
|
||||
elif self.zip_path == None:
|
||||
return
|
||||
with TemporaryDirectory() as output_dir:
|
||||
with zipfile.ZipFile(self.zip_path, 'r') as zip_ref:
|
||||
zip_ref.extractall(output_dir)
|
||||
# add the files
|
||||
self.recursive_add(files_to_restore, curr_path=output_dir)
|
||||
with zipfile.ZipFile(self.zip_path, 'r') as zip_ref:
|
||||
zip_ref.extractall(output_dir)
|
||||
# add the files
|
||||
self.recursive_add(files_to_restore, curr_path=output_dir)
|
||||
Reference in New Issue
Block a user