| 
									
										
										
										
											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 04:46:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-10 13:54:46 -05:00
										 |  |  | #pragma once
 | 
					
						
							| 
									
										
										
										
											2008-12-08 04:46:09 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include <map>
 | 
					
						
							| 
									
										
										
										
											2014-08-25 23:40:05 -04:00
										 |  |  | #include <memory>
 | 
					
						
							| 
									
										
										
										
											2013-10-18 03:32:56 -04:00
										 |  |  | #include <string>
 | 
					
						
							| 
									
										
										
										
											2014-02-21 01:47:53 +01:00
										 |  |  | #include <vector>
 | 
					
						
							| 
									
										
										
										
											2013-10-18 03:32:56 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-21 01:47:53 +01:00
										 |  |  | #include "Common/CommonTypes.h"
 | 
					
						
							| 
									
										
										
										
											2014-02-17 05:18:15 -05:00
										 |  |  | #include "DiscIO/Volume.h"
 | 
					
						
							| 
									
										
										
										
											2008-12-08 04:46:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  | namespace File | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | struct FSTEntry; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2014-02-21 01:47:53 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-08 04:46:09 +00:00
										 |  |  | //
 | 
					
						
							| 
									
										
										
										
											2016-06-25 18:07:10 +02:00
										 |  |  | // --- this volume type is used for reading files directly from the hard drive ---
 | 
					
						
							| 
									
										
										
										
											2008-12-08 04:46:09 +00:00
										 |  |  | //
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace DiscIO | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-07-06 20:33:05 +02:00
										 |  |  | enum class BlobType; | 
					
						
							|  |  |  | enum class Country; | 
					
						
							|  |  |  | enum class Language; | 
					
						
							| 
									
										
										
										
											2016-12-23 18:41:21 +01:00
										 |  |  | enum class Region; | 
					
						
							| 
									
										
										
										
											2016-07-06 20:33:05 +02:00
										 |  |  | enum class Platform; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-31 22:42:10 +00:00
										 |  |  | class CVolumeDirectory : public IVolume | 
					
						
							| 
									
										
										
										
											2008-12-08 04:46:09 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-12-10 09:16:10 +00:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2016-12-26 11:45:22 +01:00
										 |  |  |   CVolumeDirectory(const std::string& directory, bool is_wii, const std::string& apploader = "", | 
					
						
							|  |  |  |                    const std::string& dol = ""); | 
					
						
							| 
									
										
										
										
											2008-12-08 04:46:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   ~CVolumeDirectory(); | 
					
						
							| 
									
										
										
										
											2008-12-08 04:46:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-26 11:45:22 +01:00
										 |  |  |   static bool IsValidDirectory(const std::string& directory); | 
					
						
							| 
									
										
										
										
											2008-12-08 04:46:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-26 11:45:22 +01:00
										 |  |  |   bool Read(u64 offset, u64 length, u8* buffer, bool decrypt) const override; | 
					
						
							| 
									
										
										
										
											2008-12-08 04:46:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-29 14:42:43 +02:00
										 |  |  |   std::string GetGameID() const override; | 
					
						
							| 
									
										
										
										
											2016-12-26 11:45:22 +01:00
										 |  |  |   void SetGameID(const std::string& id); | 
					
						
							| 
									
										
										
										
											2008-12-08 04:46:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   std::string GetMakerID() const override; | 
					
						
							| 
									
										
										
										
											2008-12-08 04:46:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   u16 GetRevision() const override { return 0; } | 
					
						
							|  |  |  |   std::string GetInternalName() const override; | 
					
						
							| 
									
										
										
										
											2016-07-06 20:33:05 +02:00
										 |  |  |   std::map<Language, std::string> GetLongNames() const override; | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   std::vector<u32> GetBanner(int* width, int* height) const override; | 
					
						
							|  |  |  |   void SetName(const std::string&); | 
					
						
							| 
									
										
										
										
											2008-12-08 04:46:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   u64 GetFSTSize() const override; | 
					
						
							| 
									
										
										
										
											2008-12-08 04:46:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   std::string GetApploaderDate() const override; | 
					
						
							| 
									
										
										
										
											2016-07-06 20:33:05 +02:00
										 |  |  |   Platform GetVolumeType() const override; | 
					
						
							| 
									
										
										
										
											2008-12-08 04:46:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-23 18:41:21 +01:00
										 |  |  |   Region GetRegion() const override; | 
					
						
							| 
									
										
										
										
											2016-07-06 20:33:05 +02:00
										 |  |  |   Country GetCountry() const override; | 
					
						
							| 
									
										
										
										
											2008-12-08 04:46:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   BlobType GetBlobType() const override; | 
					
						
							|  |  |  |   u64 GetSize() const override; | 
					
						
							|  |  |  |   u64 GetRawSize() const override; | 
					
						
							| 
									
										
										
										
											2008-12-08 04:46:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   void BuildFST(); | 
					
						
							| 
									
										
										
										
											2008-12-08 04:46:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-10 09:16:10 +00:00
										 |  |  | private: | 
					
						
							| 
									
										
										
										
											2016-12-26 11:45:22 +01:00
										 |  |  |   static std::string ExtractDirectoryName(const std::string& directory); | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   void SetDiskTypeWii(); | 
					
						
							|  |  |  |   void SetDiskTypeGC(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-26 11:45:22 +01:00
										 |  |  |   bool SetApploader(const std::string& apploader); | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-26 11:45:22 +01:00
										 |  |  |   void SetDOL(const std::string& dol); | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // writing to read buffer
 | 
					
						
							| 
									
										
										
										
											2016-12-26 11:45:22 +01:00
										 |  |  |   void WriteToBuffer(u64 source_start_address, u64 source_length, const u8* source, u64* address, | 
					
						
							|  |  |  |                      u64* length, u8** buffer) const; | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-26 11:45:22 +01:00
										 |  |  |   void PadToAddress(u64 start_address, u64* address, u64* length, u8** buffer) const; | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   void Write32(u32 data, u32 offset, std::vector<u8>* const buffer); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // FST creation
 | 
					
						
							| 
									
										
										
										
											2016-12-26 11:45:22 +01:00
										 |  |  |   void WriteEntryData(u32* entry_offset, u8 type, u32 name_offset, u64 data_offset, u64 length); | 
					
						
							|  |  |  |   void WriteEntryName(u32* name_offset, const std::string& name); | 
					
						
							|  |  |  |   void WriteDirectory(const File::FSTEntry& parent_entry, u32* fst_offset, u32* name_offset, | 
					
						
							|  |  |  |                       u64* data_offset, u32 parent_entry_index); | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-26 11:45:22 +01:00
										 |  |  |   std::string m_root_directory; | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-26 11:45:22 +01:00
										 |  |  |   std::map<u64, std::string> m_virtual_disk; | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   bool m_is_wii; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // GameCube has no shift, Wii has 2 bit shift
 | 
					
						
							| 
									
										
										
										
											2016-12-26 11:45:22 +01:00
										 |  |  |   u32 m_address_shift; | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // first address on disk containing file data
 | 
					
						
							| 
									
										
										
										
											2016-12-26 11:45:22 +01:00
										 |  |  |   u64 m_data_start_address; | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-26 11:45:22 +01:00
										 |  |  |   u64 m_fst_name_offset; | 
					
						
							|  |  |  |   std::vector<u8> m_fst_data; | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-26 11:45:22 +01:00
										 |  |  |   std::vector<u8> m_disk_header; | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | #pragma pack(push, 1)
 | 
					
						
							|  |  |  |   struct SDiskHeaderInfo | 
					
						
							|  |  |  |   { | 
					
						
							| 
									
										
										
										
											2016-12-26 11:45:22 +01:00
										 |  |  |     u32 debug_monitor_size; | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |     u32 simulated_mem_size; | 
					
						
							|  |  |  |     u32 arg_offset; | 
					
						
							|  |  |  |     u32 debug_flag; | 
					
						
							|  |  |  |     u32 track_location; | 
					
						
							|  |  |  |     u32 track_size; | 
					
						
							|  |  |  |     u32 country_code; | 
					
						
							|  |  |  |     u32 unknown; | 
					
						
							|  |  |  |     u32 unknown2; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // All the data is byteswapped
 | 
					
						
							|  |  |  |     SDiskHeaderInfo() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2016-12-26 11:45:22 +01:00
										 |  |  |       debug_monitor_size = 0; | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |       simulated_mem_size = 0; | 
					
						
							|  |  |  |       arg_offset = 0; | 
					
						
							|  |  |  |       debug_flag = 0; | 
					
						
							|  |  |  |       track_location = 0; | 
					
						
							|  |  |  |       track_size = 0; | 
					
						
							|  |  |  |       country_code = 0; | 
					
						
							|  |  |  |       unknown = 0; | 
					
						
							|  |  |  |       unknown2 = 0; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | #pragma pack(pop)
 | 
					
						
							| 
									
										
										
										
											2016-12-26 11:45:22 +01:00
										 |  |  |   std::unique_ptr<SDiskHeaderInfo> m_disk_header_info; | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   std::vector<u8> m_apploader; | 
					
						
							| 
									
										
										
										
											2016-12-26 11:45:22 +01:00
										 |  |  |   std::vector<u8> m_dol; | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   u64 m_fst_address; | 
					
						
							|  |  |  |   u64 m_dol_address; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   static constexpr u8 ENTRY_SIZE = 0x0c; | 
					
						
							|  |  |  |   static constexpr u8 FILE_ENTRY = 0; | 
					
						
							|  |  |  |   static constexpr u8 DIRECTORY_ENTRY = 1; | 
					
						
							|  |  |  |   static constexpr u64 DISKHEADER_ADDRESS = 0; | 
					
						
							|  |  |  |   static constexpr u64 DISKHEADERINFO_ADDRESS = 0x440; | 
					
						
							|  |  |  |   static constexpr u64 APPLOADER_ADDRESS = 0x2440; | 
					
						
							|  |  |  |   static const size_t MAX_NAME_LENGTH = 0x3df; | 
					
						
							|  |  |  |   static const size_t MAX_ID_LENGTH = 6; | 
					
						
							| 
									
										
										
										
											2008-12-08 04:46:09 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  | }  // namespace
 |