mirror of
				https://github.com/chev2/botw-toolset.git
				synced 2025-10-30 08:12:17 +00:00 
			
		
		
		
	Change Yaz0 method ReadFile to FromBytes
This commit is contained in:
		
							parent
							
								
									f19f94f459
								
							
						
					
					
						commit
						7aa85c437b
					
				
					 1 changed files with 16 additions and 23 deletions
				
			
		|  | @ -32,35 +32,28 @@ namespace BOTWToolset.IO.Yaz0 | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         /// <param name="file">The file (full path) to read.</param> |         /// <param name="file">The file (full path) to read.</param> | ||||||
|         /// <returns><see cref="Yaz0"/> containing the file's data.</returns> |         /// <returns><see cref="Yaz0"/> containing the file's data.</returns> | ||||||
|         public static Yaz0 ReadFile(string file) |         public static Yaz0 FromBytes(byte[] bytes) | ||||||
|         { |         { | ||||||
|             if (File.Exists(file)) |             Yaz0 y = new Yaz0(); | ||||||
|  | 
 | ||||||
|  |             // Use big-endian | ||||||
|  |             using (var r = new BinaryReaderBig(new MemoryStream(bytes))) | ||||||
|             { |             { | ||||||
|                 Yaz0 y = new Yaz0(); |                 y.Magic = new string(r.ReadChars(4)); | ||||||
|  |                 if (y.Magic != "Yaz0") | ||||||
|  |                     throw new InvalidMagicException("This file is not Yaz0-encoded."); | ||||||
| 
 | 
 | ||||||
|                 // Use big-endian |                 y.UncompressedDataSize = r.ReadUInt32(); | ||||||
|                 using (var r = new BinaryReaderBig(File.Open(file, FileMode.Open))) |                 y.DataAlignment = r.ReadUInt32(); | ||||||
|                 { |  | ||||||
|                     y.Magic = new string(r.ReadChars(4)); |  | ||||||
|                     if (y.Magic != "Yaz0") |  | ||||||
|                         throw new InvalidMagicException("This file is not Yaz0-encoded."); |  | ||||||
| 
 | 
 | ||||||
|                     y.UncompressedDataSize = r.ReadUInt32(); |                 // Seek back to beginning of file to capture all bytes | ||||||
|                     y.DataAlignment = r.ReadUInt32(); |                 r.BaseStream.Seek(0, SeekOrigin.Begin); | ||||||
| 
 | 
 | ||||||
|                     // Seek back to beginning of file to capture all bytes |                 // Capture all bytes | ||||||
|                     r.BaseStream.Seek(0, SeekOrigin.Begin); |                 y.Bytes = r.ReadBytes((int)r.BaseStream.Length); | ||||||
| 
 |  | ||||||
|                     // Capture all bytes |  | ||||||
|                     y.Bytes = r.ReadBytes((int)r.BaseStream.Length); |  | ||||||
|                 } |  | ||||||
| 
 |  | ||||||
|                 return y; |  | ||||||
|             } |  | ||||||
|             else |  | ||||||
|             { |  | ||||||
|                 throw new FileNotFoundException("Cannot find Yaz0 file to read."); |  | ||||||
|             } |             } | ||||||
|  | 
 | ||||||
|  |             return y; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         /// <summary> |         /// <summary> | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 Chev
						Chev