16
16
# Code is formatted with `black`
17
17
18
18
from __future__ import annotations
19
+ from enum import Enum
19
20
20
21
import argparse
21
22
import copy
86
87
# fmt: on
87
88
88
89
90
+ class FileSystem (Enum ):
91
+ hybrid = 'hybrid'
92
+ hfs = 'hfs'
93
+ iso9660 = 'iso9660'
94
+
95
+
96
+ class Extension (Enum ):
97
+ none = None
98
+ joliet = 'joliet'
99
+ rr = 'rr'
100
+ udf = 'udf'
101
+
102
+
89
103
def decode_macjapanese (text : bytes ) -> str :
90
104
"""
91
105
Decode MacJapanese
@@ -291,9 +305,9 @@ def encode_string(args: argparse.Namespace) -> int:
291
305
return 0
292
306
293
307
294
- def probe_iso (args ):
308
+ def probe_iso (args : argparse . Namespace ):
295
309
fs = check_fs (args .src )
296
- print ('Detected file system:' , fs )
310
+ print ('Detected file system:' , fs . value )
297
311
args .fs = fs
298
312
args .dryrun = True
299
313
args .dir = Path ('testing' )
@@ -303,17 +317,17 @@ def probe_iso(args):
303
317
args .log = 'INFO'
304
318
args .nopunycode = False
305
319
args .japanese = False
306
- if fs == ' hybrid' or fs == ' iso9660' :
320
+ if fs in [ FileSystem . hybrid , FileSystem . iso9660 ] :
307
321
args .extension = check_extension (args )
308
- print ('Detected extension:' , args .extension )
322
+ print ('Detected extension:' , args .extension . value )
309
323
print ('Japanese detected:' , check_japanese (args ))
310
324
311
325
312
- def check_japanese (args ):
326
+ def check_japanese (args : argparse . Namespace ):
313
327
args .japanese = False
314
- if args .fs == ' hybrid' :
328
+ if args .fs == FileSystem . hybrid :
315
329
fn = extract_volume_hybrid
316
- elif args .fs == ' iso9660' :
330
+ elif args .fs == FileSystem . iso9660 :
317
331
fn = extract_volume_iso
318
332
else :
319
333
fn = extract_volume_hfs
@@ -331,21 +345,21 @@ def check_japanese(args):
331
345
return False
332
346
333
347
334
- def check_extension (args ):
348
+ def check_extension (args : argparse . Namespace ):
335
349
args_copy = copy .copy (args )
336
350
args_copy .dryrun = True
337
- extensions = ['joliet' , 'rr' , 'udf' ]
338
351
args_copy .dir = args .dir .joinpath ('test' )
339
- args_copy .fs = ' iso9660'
352
+ args_copy .fs = FileSystem . iso9660
340
353
args_copy .silent = True
341
- for extension in extensions :
354
+ for extension in Extension :
342
355
args_copy .extension = extension
343
356
try :
344
357
extract_volume_iso (args_copy )
345
358
except Exception as e :
346
359
pass
347
360
else :
348
361
return extension
362
+ return Extension .none
349
363
350
364
351
365
def check_fs (iso ):
@@ -359,7 +373,7 @@ def check_fs(iso):
359
373
f .seek (64 * SECTOR_SIZE )
360
374
if f .read (6 ) == b"\x01 CD001" :
361
375
# print('Found ISO PVD')
362
- disk_formats .append (" iso9660" )
376
+ disk_formats .append (FileSystem . iso9660 )
363
377
364
378
f .seek (0 )
365
379
mac_1 = f .read (4 )
@@ -374,7 +388,7 @@ def check_fs(iso):
374
388
f .seek (32 , 1 )
375
389
partition_type = f .read (32 ).decode ("mac-roman" ).split ("\x00 " )[0 ]
376
390
if partition_type == "Apple_HFS" :
377
- disk_formats .append (" hfs" )
391
+ disk_formats .append (FileSystem . hfs )
378
392
break
379
393
# Check if there are more partitions
380
394
if partition_num <= num_partitions :
@@ -383,25 +397,28 @@ def check_fs(iso):
383
397
f .seek (partition_num * SECTOR_SIZE + 4 )
384
398
# Bootable Mac-only disc
385
399
elif mac_1 == b"LK\x60 \x00 " and mac_3 == b"BD" :
386
- disk_formats .append (" hfs" )
400
+ disk_formats .append (FileSystem . hfs )
387
401
388
402
if len (disk_formats ) > 1 :
389
- return 'hybrid'
390
- else :
391
- return disk_formats [0 ]
403
+ return FileSystem .hybrid
404
+ return disk_formats [0 ]
392
405
393
406
394
407
def extract_iso (args : argparse .Namespace ):
395
408
if not args .fs :
396
409
args .fs = check_fs (args .src )
397
- print ('Detected filesystem:' , args .fs )
398
- if (args .fs == 'hybrid' or args .fs == 'iso9660' ) and not args .extension :
410
+ print ('Detected filesystem:' , args .fs .value )
411
+ else :
412
+ args .fs = FileSystem (args .fs )
413
+ if args .fs in [FileSystem .hybrid , FileSystem .iso9660 ] and not args .extension :
399
414
args .extension = check_extension (args )
400
- print ('Detected extension:' , args .extension )
415
+ print ('Detected extension:' , args .extension .value )
416
+ elif args .extension :
417
+ args .extension = Extension (args .extension )
401
418
402
- if args .fs == ' iso9660' :
419
+ if args .fs == FileSystem . iso9660 :
403
420
extract_volume_iso (args )
404
- elif args .fs == ' hfs' :
421
+ elif args .fs == FileSystem . hfs :
405
422
extract_volume_hfs (args )
406
423
else :
407
424
extract_volume_hybrid (args )
@@ -482,11 +499,11 @@ def extract_volume_iso(args: argparse.Namespace):
482
499
483
500
output_dir = str (args .dir )
484
501
485
- if not args .extension :
502
+ if not args .extension or args . extension == Extension . none :
486
503
path_type = 'iso_path'
487
- elif args .extension == ' joliet' :
504
+ elif args .extension == Extension . joliet :
488
505
path_type = 'joliet_path'
489
- elif args .extension == 'rr' :
506
+ elif args .extension == Extension . rr :
490
507
path_type = 'rr_path'
491
508
else :
492
509
path_type = 'udf_path'
@@ -596,7 +613,9 @@ def extract_partition(args: argparse.Namespace, vol) -> int:
596
613
folders .append ((upath , obj .mddate - 2082844800 ))
597
614
continue
598
615
599
- # print(upath)
616
+ if not silent :
617
+ print (upath )
618
+
600
619
if obj .data and not obj .rsrc and not force_macbinary :
601
620
upath .write_bytes (obj .data )
602
621
0 commit comments