1616# Code is formatted with `black`
1717
1818from __future__ import annotations
19+ from enum import Enum
1920
2021import argparse
2122import copy
8687# fmt: on
8788
8889
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+
89103def decode_macjapanese (text : bytes ) -> str :
90104 """
91105 Decode MacJapanese
@@ -291,9 +305,9 @@ def encode_string(args: argparse.Namespace) -> int:
291305 return 0
292306
293307
294- def probe_iso (args ):
308+ def probe_iso (args : argparse . Namespace ):
295309 fs = check_fs (args .src )
296- print ('Detected file system:' , fs )
310+ print ('Detected file system:' , fs . value )
297311 args .fs = fs
298312 args .dryrun = True
299313 args .dir = Path ('testing' )
@@ -303,17 +317,17 @@ def probe_iso(args):
303317 args .log = 'INFO'
304318 args .nopunycode = False
305319 args .japanese = False
306- if fs == ' hybrid' or fs == ' iso9660' :
320+ if fs in [ FileSystem . hybrid , FileSystem . iso9660 ] :
307321 args .extension = check_extension (args )
308- print ('Detected extension:' , args .extension )
322+ print ('Detected extension:' , args .extension . value )
309323 print ('Japanese detected:' , check_japanese (args ))
310324
311325
312- def check_japanese (args ):
326+ def check_japanese (args : argparse . Namespace ):
313327 args .japanese = False
314- if args .fs == ' hybrid' :
328+ if args .fs == FileSystem . hybrid :
315329 fn = extract_volume_hybrid
316- elif args .fs == ' iso9660' :
330+ elif args .fs == FileSystem . iso9660 :
317331 fn = extract_volume_iso
318332 else :
319333 fn = extract_volume_hfs
@@ -331,21 +345,21 @@ def check_japanese(args):
331345 return False
332346
333347
334- def check_extension (args ):
348+ def check_extension (args : argparse . Namespace ):
335349 args_copy = copy .copy (args )
336350 args_copy .dryrun = True
337- extensions = ['joliet' , 'rr' , 'udf' ]
338351 args_copy .dir = args .dir .joinpath ('test' )
339- args_copy .fs = ' iso9660'
352+ args_copy .fs = FileSystem . iso9660
340353 args_copy .silent = True
341- for extension in extensions :
354+ for extension in Extension :
342355 args_copy .extension = extension
343356 try :
344357 extract_volume_iso (args_copy )
345358 except Exception as e :
346359 pass
347360 else :
348361 return extension
362+ return Extension .none
349363
350364
351365def check_fs (iso ):
@@ -359,7 +373,7 @@ def check_fs(iso):
359373 f .seek (64 * SECTOR_SIZE )
360374 if f .read (6 ) == b"\x01 CD001" :
361375 # print('Found ISO PVD')
362- disk_formats .append (" iso9660" )
376+ disk_formats .append (FileSystem . iso9660 )
363377
364378 f .seek (0 )
365379 mac_1 = f .read (4 )
@@ -374,7 +388,7 @@ def check_fs(iso):
374388 f .seek (32 , 1 )
375389 partition_type = f .read (32 ).decode ("mac-roman" ).split ("\x00 " )[0 ]
376390 if partition_type == "Apple_HFS" :
377- disk_formats .append (" hfs" )
391+ disk_formats .append (FileSystem . hfs )
378392 break
379393 # Check if there are more partitions
380394 if partition_num <= num_partitions :
@@ -383,25 +397,28 @@ def check_fs(iso):
383397 f .seek (partition_num * SECTOR_SIZE + 4 )
384398 # Bootable Mac-only disc
385399 elif mac_1 == b"LK\x60 \x00 " and mac_3 == b"BD" :
386- disk_formats .append (" hfs" )
400+ disk_formats .append (FileSystem . hfs )
387401
388402 if len (disk_formats ) > 1 :
389- return 'hybrid'
390- else :
391- return disk_formats [0 ]
403+ return FileSystem .hybrid
404+ return disk_formats [0 ]
392405
393406
394407def extract_iso (args : argparse .Namespace ):
395408 if not args .fs :
396409 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 :
399414 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 )
401418
402- if args .fs == ' iso9660' :
419+ if args .fs == FileSystem . iso9660 :
403420 extract_volume_iso (args )
404- elif args .fs == ' hfs' :
421+ elif args .fs == FileSystem . hfs :
405422 extract_volume_hfs (args )
406423 else :
407424 extract_volume_hybrid (args )
@@ -482,11 +499,11 @@ def extract_volume_iso(args: argparse.Namespace):
482499
483500 output_dir = str (args .dir )
484501
485- if not args .extension :
502+ if not args .extension or args . extension == Extension . none :
486503 path_type = 'iso_path'
487- elif args .extension == ' joliet' :
504+ elif args .extension == Extension . joliet :
488505 path_type = 'joliet_path'
489- elif args .extension == 'rr' :
506+ elif args .extension == Extension . rr :
490507 path_type = 'rr_path'
491508 else :
492509 path_type = 'udf_path'
@@ -596,7 +613,9 @@ def extract_partition(args: argparse.Namespace, vol) -> int:
596613 folders .append ((upath , obj .mddate - 2082844800 ))
597614 continue
598615
599- # print(upath)
616+ if not silent :
617+ print (upath )
618+
600619 if obj .data and not obj .rsrc and not force_macbinary :
601620 upath .write_bytes (obj .data )
602621
0 commit comments