mirror of
				https://github.com/NinjaCheetah/WiiPy.git
				synced 2025-10-30 15:16:19 -04:00 
			
		
		
		
	Allow extracting WAD/U8 files to an existing empty directory
This commit is contained in:
		
							parent
							
								
									c7e78476c0
								
							
						
					
					
						commit
						dcafda4b71
					
				| @ -30,12 +30,8 @@ def handle_u8(args): | |||||||
| 
 | 
 | ||||||
|         u8_data = open(input_path, "rb").read() |         u8_data = open(input_path, "rb").read() | ||||||
| 
 | 
 | ||||||
|         # Ensure the output directory doesn't already exist, because libWiiPy wants to create a new one to ensure that |         # Output path is deliberately not checked in any way because libWiiPy already has those checks, and it's easier | ||||||
|         # the contents of the U8 archive are extracted correctly. |         # and cleaner to only have one component doing all the checks. | ||||||
|         if output_path.exists(): |  | ||||||
|             print("Error: Specified output directory already exists!") |  | ||||||
|             return |  | ||||||
| 
 |  | ||||||
|         libWiiPy.archive.extract_u8(u8_data, str(output_path)) |         libWiiPy.archive.extract_u8(u8_data, str(output_path)) | ||||||
| 
 | 
 | ||||||
|         print("U8 archive unpacked!") |         print("U8 archive unpacked!") | ||||||
|  | |||||||
| @ -1,6 +1,7 @@ | |||||||
| # "wad.py" from WiiPy by NinjaCheetah | # "wad.py" from WiiPy by NinjaCheetah | ||||||
| # https://github.com/NinjaCheetah/WiiPy | # https://github.com/NinjaCheetah/WiiPy | ||||||
| 
 | 
 | ||||||
|  | import os | ||||||
| import pathlib | import pathlib | ||||||
| import binascii | import binascii | ||||||
| import libWiiPy | import libWiiPy | ||||||
| @ -89,8 +90,14 @@ def handle_wad(args): | |||||||
|     elif args.unpack: |     elif args.unpack: | ||||||
|         if not input_path.exists(): |         if not input_path.exists(): | ||||||
|             raise FileNotFoundError(input_path) |             raise FileNotFoundError(input_path) | ||||||
|         if not output_path.is_dir(): |         # Check if the output path already exists, and if it does, ensure that it is both a directory and empty. | ||||||
|             output_path.mkdir() |         if output_path.exists(): | ||||||
|  |             if output_path.is_dir() and next(os.scandir(output_path), None): | ||||||
|  |                 raise ValueError("Output folder is not empty!") | ||||||
|  |             elif output_path.is_file(): | ||||||
|  |                 raise ValueError("A file already exists with the provided name!") | ||||||
|  |         else: | ||||||
|  |             os.mkdir(output_path) | ||||||
| 
 | 
 | ||||||
|         # Step through each component of a WAD and dump it to a file. |         # Step through each component of a WAD and dump it to a file. | ||||||
|         with open(args.input, "rb") as wad_file: |         with open(args.input, "rb") as wad_file: | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user