Skip to content
Open
Show file tree
Hide file tree
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
31 changes: 26 additions & 5 deletions acquisition/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from meta import AUTHOR, VERSION
from shared.utils import command_to_properties, lines_to_properties


@dataclass
class Parameters:
case: str = ""
Expand Down Expand Up @@ -264,11 +263,11 @@ def _create_temporary_image(self, report: Report) -> bool:
success = result == 0 and len(volume_lines) > 0
if success:
container_line = container_lines[0]
parts = re.split("\s+", container_line, maxsplit=2)
parts = re.split(r"\s+", container_line, maxsplit=2)
self.temporary_container = parts[0]

mount_line = volume_lines[0]
parts = re.split("\s+", mount_line, maxsplit=2)
parts = re.split(r"\s+", mount_line, maxsplit=2)
self.temporary_volume = parts[0]
self.temporary_mount = parts[2]

Expand All @@ -278,6 +277,20 @@ def _create_temporary_image(self, report: Report) -> bool:

return success

def _delete_temporary_image(self, report: Report) -> bool:
params = report.parameters
output_directory = params.tmp / params.image_name
self.temporary_path = output_directory / f"{params.image_name}.sparseimage"
if os.path.exists(self.temporary_path):
if params.state_temporary_image:
try:
os.remove(self.temporary_path)
print(f"Temporary image file {self.temporary_path} deleted.")
return True
except Exception as e:
print(f"Error while delete temporary image file {self.temporary_path}: {e}")
print(f"{self.temporary_path}")

def _detach_temporary_image(self, delay=10, interval=5, attempts=20) -> bool:
print("\nWaiting to detach temporary image...")
time.sleep(delay)
Expand Down Expand Up @@ -306,8 +319,12 @@ def _generate_dmg(self, report: Report) -> bool:
print("\nConverting", self.temporary_path, "->", self.output_path)
sparseimage = f"{self.temporary_path}"
dmg = f"{self.output_path}"
if params.compressed:
dmgformat = "UDRW"
else:
dmgformat = "UDZO"
result = self._run_status(
["hdiutil", "convert", sparseimage, "-format", "UDZO", "-o", dmg]
["hdiutil", "convert", sparseimage, "-format", dmgformat, "-o", dmg]
)

success = result == 0
Expand Down Expand Up @@ -402,6 +419,8 @@ def _write_report(self, report: Report) -> None:
f"End time: {report.end_time}",
f"Source: {report.parameters.source}",
f"Acquisition method: {report.method.name}",
f"Imagefile type: {'uncompressed (UDRW)' if report.parameters.compressed else 'compressed (UDZO)'}",
f"temporary image file: {'delete' if report.parameters.state_temporary_image else 'keep'} after acquisition",
separator,
report.hardware_info,
separator,
Expand All @@ -428,8 +447,10 @@ def _dmg_and_hash(self, report: Report) -> Report:
report.success = True
report.end_time = datetime.now()

self._write_report(report)
_ = self._delete_temporary_image(report)

self._write_report(report)

print("\nAcquisition completed!")
return report

Expand Down
20 changes: 19 additions & 1 deletion fuji.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def __init__(self, parent):
if not line.startswith("/dev/disk"):
continue
identifier, size, used, free, _, _, _, _, mount_point = re.split(
"\s+", line, maxsplit=8
r"\s+", line, maxsplit=8
)
short_identifier = identifier[5:]
mount_info[short_identifier] = DiskSpaceInfo(
Expand Down Expand Up @@ -349,6 +349,18 @@ def __init__(self):
description_text.SetLabelMarkup(description_label)
self.description_texts.append(description_text)

# compressed dmg file checkbox
self.compressed_checkbox = wx.CheckBox(
panel, label="Create an un-compressed (UDRW) acquisition .dmg-file"
)
self.compressed_checkbox.SetValue(False)

# keep/delete temporary sparseimage file after acquisition
self.state_temporary_image_checkbox = wx.CheckBox(
panel, label="Delete temporary image file after acquisition"
)
self.state_temporary_image_checkbox.SetValue(False)

# Sound checkbox
self.sound_checkbox = wx.CheckBox(
panel, label="Play loud sound when acquisition is completed"
Expand Down Expand Up @@ -402,6 +414,8 @@ def __init__(self):
vbox.Add(description_text, 0, wx.LEFT | wx.RIGHT | wx.BOTTOM, 10)

vbox.Add((0, 20))
vbox.Add(self.compressed_checkbox, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.BOTTOM, 10)
vbox.Add(self.state_temporary_image_checkbox, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.BOTTOM, 10)
vbox.Add(self.sound_checkbox, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.BOTTOM, 10)
vbox.Add(continue_btn, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.BOTTOM, 20)
panel.SetSizer(vbox)
Expand Down Expand Up @@ -449,6 +463,8 @@ def on_continue(self, event):
PARAMS.tmp = Path(self.tmp_picker.GetPath().strip())
PARAMS.destination = Path(self.destination_picker.GetPath().strip())
PARAMS.sound = self.sound_checkbox.GetValue()
PARAMS.compressed = self.compressed_checkbox.GetValue()
PARAMS.state_temporary_image = self.state_temporary_image_checkbox.GetValue()
self.method = METHODS[self.method_choice.GetSelection()]

self.Hide()
Expand Down Expand Up @@ -517,6 +533,8 @@ def update_overview(self):
"Temp image location": PARAMS.tmp,
"DMG destination": PARAMS.destination,
"Acquisition method": INPUT_WINDOW.method.name,
"Imagefile type": "uncompressed (UDRW)" if PARAMS.compressed else "compressed (UDZO)",
"Temporary image file": f"{'delete' if PARAMS.state_temporary_image else 'keep'} after acquisition",
"Play sound": "Yes" if PARAMS.sound else "No",
}

Expand Down