1 // Copyright 2017 Dolphin Emulator Project
2 // Licensed under GPLv2+
3 // Refer to the license.txt file included.
4 
5 #pragma once
6 
7 #include <functional>
8 #include <optional>
9 #include <string>
10 #include <string_view>
11 
12 #include "Common/CommonTypes.h"
13 
14 namespace DiscIO
15 {
16 class FileInfo;
17 struct Partition;
18 class Volume;
19 
20 constexpr u32 PARTITION_DATA = 0;
21 constexpr u32 PARTITION_UPDATE = 1;
22 constexpr u32 PARTITION_CHANNEL = 2;  // Mario Kart Wii, Wii Fit, Wii Fit Plus, Rabbids Go Home
23 constexpr u32 PARTITION_INSTALL = 3;  // Dragon Quest X only
24 
25 std::string NameForPartitionType(u32 partition_type, bool include_prefix);
26 
27 u64 ReadFile(const Volume& volume, const Partition& partition, const FileInfo* file_info,
28              u8* buffer, u64 max_buffer_size, u64 offset_in_file = 0);
29 u64 ReadFile(const Volume& volume, const Partition& partition, std::string_view path, u8* buffer,
30              u64 max_buffer_size, u64 offset_in_file = 0);
31 bool ExportData(const Volume& volume, const Partition& partition, u64 offset, u64 size,
32                 const std::string& export_filename);
33 bool ExportFile(const Volume& volume, const Partition& partition, const FileInfo* file_info,
34                 const std::string& export_filename);
35 bool ExportFile(const Volume& volume, const Partition& partition, std::string_view path,
36                 const std::string& export_filename);
37 
38 // update_progress is called once for each child (file or directory).
39 // If update_progress returns true, the extraction gets cancelled.
40 // filesystem_path is supposed to be the path corresponding to the directory argument.
41 void ExportDirectory(const Volume& volume, const Partition& partition, const FileInfo& directory,
42                      bool recursive, const std::string& filesystem_path,
43                      const std::string& export_folder,
44                      const std::function<bool(const std::string& path)>& update_progress);
45 
46 // To export everything listed below, you can use ExportSystemData
47 
48 bool ExportWiiUnencryptedHeader(const Volume& volume, const std::string& export_filename);
49 bool ExportWiiRegionData(const Volume& volume, const std::string& export_filename);
50 
51 bool ExportTicket(const Volume& volume, const Partition& partition,
52                   const std::string& export_filename);
53 bool ExportTMD(const Volume& volume, const Partition& partition,
54                const std::string& export_filename);
55 bool ExportCertificateChain(const Volume& volume, const Partition& partition,
56                             const std::string& export_filename);
57 bool ExportH3Hashes(const Volume& volume, const Partition& partition,
58                     const std::string& export_filename);
59 
60 bool ExportHeader(const Volume& volume, const Partition& partition,
61                   const std::string& export_filename);
62 bool ExportBI2Data(const Volume& volume, const Partition& partition,
63                    const std::string& export_filename);
64 std::optional<u64> GetApploaderSize(const Volume& volume, const Partition& partition);
65 bool ExportApploader(const Volume& volume, const Partition& partition,
66                      const std::string& export_filename);
67 std::optional<u64> GetBootDOLOffset(const Volume& volume, const Partition& partition);
68 std::optional<u32> GetBootDOLSize(const Volume& volume, const Partition& partition, u64 dol_offset);
69 bool ExportDOL(const Volume& volume, const Partition& partition,
70                const std::string& export_filename);
71 std::optional<u64> GetFSTOffset(const Volume& volume, const Partition& partition);
72 std::optional<u64> GetFSTSize(const Volume& volume, const Partition& partition);
73 bool ExportFST(const Volume& volume, const Partition& partition,
74                const std::string& export_filename);
75 
76 bool ExportSystemData(const Volume& volume, const Partition& partition,
77                       const std::string& export_folder);
78 
79 }  // namespace DiscIO
80