| 
									
										
										
										
											2015-05-24 06:55:12 +02:00
										 |  |  | // Copyright 2008 Dolphin Emulator Project
 | 
					
						
							| 
									
										
										
										
											2015-05-18 01:08:10 +02:00
										 |  |  | // Licensed under GPLv2+
 | 
					
						
							| 
									
										
										
										
											2013-04-17 23:09:55 -04:00
										 |  |  | // Refer to the license.txt file included.
 | 
					
						
							| 
									
										
										
										
											2008-12-08 05:30:24 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-06 23:15:51 -05:00
										 |  |  | #include <memory>
 | 
					
						
							| 
									
										
										
										
											2014-03-12 15:33:41 -04:00
										 |  |  | #include <string>
 | 
					
						
							| 
									
										
										
										
											2014-02-17 05:18:15 -05:00
										 |  |  | #include "DiscIO/FileBlob.h"
 | 
					
						
							| 
									
										
										
										
											2008-12-08 05:30:24 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace DiscIO | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-11 10:21:46 +00:00
										 |  |  | PlainFileReader::PlainFileReader(std::FILE* file) | 
					
						
							|  |  |  | 	: m_file(file) | 
					
						
							| 
									
										
										
										
											2008-12-08 05:30:24 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-11 10:21:46 +00:00
										 |  |  | 	m_size = m_file.GetSize(); | 
					
						
							| 
									
										
										
										
											2008-12-08 05:30:24 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-06 23:15:51 -05:00
										 |  |  | std::unique_ptr<PlainFileReader> PlainFileReader::Create(const std::string& filename) | 
					
						
							| 
									
										
										
										
											2008-12-08 05:30:24 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-11 10:21:46 +00:00
										 |  |  | 	File::IOFile f(filename, "rb"); | 
					
						
							| 
									
										
										
										
											2011-01-27 05:01:00 +00:00
										 |  |  | 	if (f) | 
					
						
							| 
									
										
										
										
											2015-12-06 23:15:51 -05:00
										 |  |  | 		return std::unique_ptr<PlainFileReader>(new PlainFileReader(f.ReleaseHandle())); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return nullptr; | 
					
						
							| 
									
										
										
										
											2008-12-08 05:30:24 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool PlainFileReader::Read(u64 offset, u64 nbytes, u8* out_ptr) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-12-14 13:16:21 +01:00
										 |  |  | 	if (m_file.Seek(offset, SEEK_SET) && m_file.ReadBytes(out_ptr, nbytes)) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		return true; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		m_file.Clear(); | 
					
						
							|  |  |  | 		return false; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-12-08 05:30:24 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | }  // namespace
 |