Skip to content
Permalink
Browse files

DiscExtractor: Make P prefix for partition names optional

Also added constants for common partition types.
  • Loading branch information...
JosJuice committed Mar 21, 2019
1 parent 3014dad commit cf9ab6ddcc93cd279aaf62897095ac5b8929bab9
@@ -19,15 +19,15 @@

namespace DiscIO
{
std::string DirectoryNameForPartitionType(u32 partition_type)
std::string NameForPartitionType(u32 partition_type, bool include_prefix)
{
switch (partition_type)
{
case 0:
case PARTITION_DATA:
return "DATA";
case 1:
case PARTITION_UPDATE:
return "UPDATE";
case 2:
case PARTITION_CHANNEL:
return "CHANNEL";
default:
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(),
[](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);
}
}

@@ -15,7 +15,11 @@ class FileInfo;
struct Partition;
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,
u8* buffer, u64 max_buffer_size, u64 offset_in_file = 0);
@@ -225,8 +225,7 @@ void FilesystemWidget::ShowContextMenu(const QPoint&)
{
if (const std::optional<u32> partition_type = m_volume->GetPartitionType(p))
{
const std::string partition_name =
DiscIO::DirectoryNameForPartitionType(*partition_type);
const std::string partition_name = DiscIO::NameForPartitionType(*partition_type, true);
ExtractPartition(p, folder + QChar(u'/') + QString::fromStdString(partition_name));
}
}

0 comments on commit cf9ab6d

Please sign in to comment.
You can’t perform that action at this time.