DiscExtractor: Make P prefix for partition names optional

Also added constants for common partition types.
This commit is contained in:
JosJuice 2019-03-21 22:23:12 +01:00
parent 3014dadfa8
commit cf9ab6ddcc
3 changed files with 12 additions and 9 deletions

View File

@ -19,15 +19,15 @@
namespace DiscIO namespace DiscIO
{ {
std::string DirectoryNameForPartitionType(u32 partition_type) std::string NameForPartitionType(u32 partition_type, bool include_prefix)
{ {
switch (partition_type) switch (partition_type)
{ {
case 0: case PARTITION_DATA:
return "DATA"; return "DATA";
case 1: case PARTITION_UPDATE:
return "UPDATE"; return "UPDATE";
case 2: case PARTITION_CHANNEL:
return "CHANNEL"; return "CHANNEL";
default: default:
const std::string type_as_game_id{static_cast<char>((partition_type >> 24) & 0xFF), const std::string type_as_game_id{static_cast<char>((partition_type >> 24) & 0xFF),
@ -37,10 +37,10 @@ std::string DirectoryNameForPartitionType(u32 partition_type)
if (std::all_of(type_as_game_id.cbegin(), type_as_game_id.cend(), if (std::all_of(type_as_game_id.cbegin(), type_as_game_id.cend(),
[](char c) { return std::isalnum(c, std::locale::classic()); })) [](char c) { return std::isalnum(c, std::locale::classic()); }))
{ {
return "P-" + type_as_game_id; return include_prefix ? "P-" + type_as_game_id : type_as_game_id;
} }
return StringFromFormat("P%u", partition_type); return StringFromFormat(include_prefix ? "P%u" : "%u", partition_type);
} }
} }

View File

@ -15,7 +15,11 @@ class FileInfo;
struct Partition; struct Partition;
class Volume; class Volume;
std::string DirectoryNameForPartitionType(u32 partition_type); constexpr u32 PARTITION_DATA = 0;
constexpr u32 PARTITION_UPDATE = 1;
constexpr u32 PARTITION_CHANNEL = 2;
std::string NameForPartitionType(u32 partition_type, bool include_prefix);
u64 ReadFile(const Volume& volume, const Partition& partition, const FileInfo* file_info, u64 ReadFile(const Volume& volume, const Partition& partition, const FileInfo* file_info,
u8* buffer, u64 max_buffer_size, u64 offset_in_file = 0); u8* buffer, u64 max_buffer_size, u64 offset_in_file = 0);

View File

@ -225,8 +225,7 @@ void FilesystemWidget::ShowContextMenu(const QPoint&)
{ {
if (const std::optional<u32> partition_type = m_volume->GetPartitionType(p)) if (const std::optional<u32> partition_type = m_volume->GetPartitionType(p))
{ {
const std::string partition_name = const std::string partition_name = DiscIO::NameForPartitionType(*partition_type, true);
DiscIO::DirectoryNameForPartitionType(*partition_type);
ExtractPartition(p, folder + QChar(u'/') + QString::fromStdString(partition_name)); ExtractPartition(p, folder + QChar(u'/') + QString::fromStdString(partition_name));
} }
} }