CDImage: Tidy up Open() method
This commit is contained in:
parent
7905793ae0
commit
21b167d382
|
@ -50,83 +50,79 @@ void CDImage::DeinterleaveSubcode(const u8* subcode_in, u8* subcode_out)
|
|||
}
|
||||
}
|
||||
|
||||
std::unique_ptr<CDImage> CDImage::Open(const char* filename, bool allow_patches, Error* error)
|
||||
std::unique_ptr<CDImage> CDImage::Open(const char* path, bool allow_patches, Error* error)
|
||||
{
|
||||
const char* extension;
|
||||
|
||||
// Annoying handling because of storage access framework.
|
||||
#ifdef __ANDROID__
|
||||
std::string filename_display_name(FileSystem::GetDisplayNameFromPath(filename));
|
||||
if (filename_display_name.empty())
|
||||
filename_display_name = filename;
|
||||
|
||||
extension = std::strrchr(filename_display_name.c_str(), '.');
|
||||
const std::string path_display_name = FileSystem::GetDisplayNameFromPath(path);
|
||||
const std::string_view extension = Path::GetExtension(path_display_name);
|
||||
#else
|
||||
extension = std::strrchr(filename, '.');
|
||||
const std::string_view extension = Path::GetExtension(path);
|
||||
#endif
|
||||
|
||||
std::unique_ptr<CDImage> image;
|
||||
if (!extension)
|
||||
if (extension.empty())
|
||||
{
|
||||
// Device filenames on Linux don't have extensions.
|
||||
if (IsDeviceName(filename))
|
||||
if (IsDeviceName(path))
|
||||
{
|
||||
image = OpenDeviceImage(filename, error);
|
||||
image = OpenDeviceImage(path, error);
|
||||
}
|
||||
else
|
||||
{
|
||||
Error::SetStringFmt(error, "Invalid filename: '{}'", Path::GetFileName(filename));
|
||||
Error::SetStringFmt(error, "Invalid filename: '{}'", Path::GetFileName(path));
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
else if (StringUtil::Strcasecmp(extension, ".cue") == 0)
|
||||
else if (StringUtil::EqualNoCase(extension, "cue"))
|
||||
{
|
||||
image = OpenCueSheetImage(filename, error);
|
||||
image = OpenCueSheetImage(path, error);
|
||||
}
|
||||
else if (StringUtil::Strcasecmp(extension, ".bin") == 0 || StringUtil::Strcasecmp(extension, ".img") == 0 ||
|
||||
StringUtil::Strcasecmp(extension, ".iso") == 0 || StringUtil::Strcasecmp(extension, ".ecm") == 0)
|
||||
else if (StringUtil::EqualNoCase(extension, "bin") || StringUtil::EqualNoCase(extension, "img") ||
|
||||
StringUtil::EqualNoCase(extension, "iso") || StringUtil::EqualNoCase(extension, "ecm"))
|
||||
{
|
||||
image = OpenBinImage(filename, error);
|
||||
image = OpenBinImage(path, error);
|
||||
}
|
||||
else if (StringUtil::Strcasecmp(extension, ".chd") == 0)
|
||||
else if (StringUtil::EqualNoCase(extension, "chd"))
|
||||
{
|
||||
image = OpenCHDImage(filename, error);
|
||||
image = OpenCHDImage(path, error);
|
||||
}
|
||||
else if (StringUtil::Strcasecmp(extension, ".mds") == 0)
|
||||
else if (StringUtil::EqualNoCase(extension, "mds"))
|
||||
{
|
||||
image = OpenMdsImage(filename, error);
|
||||
image = OpenMdsImage(path, error);
|
||||
}
|
||||
else if (StringUtil::Strcasecmp(extension, ".pbp") == 0)
|
||||
else if (StringUtil::EqualNoCase(extension, "pbp"))
|
||||
{
|
||||
image = OpenPBPImage(filename, error);
|
||||
image = OpenPBPImage(path, error);
|
||||
}
|
||||
else if (StringUtil::Strcasecmp(extension, ".m3u") == 0)
|
||||
else if (StringUtil::EqualNoCase(extension, "m3u"))
|
||||
{
|
||||
image = OpenM3uImage(filename, allow_patches, error);
|
||||
// skip applying patches to the main path, which isn't a real disc
|
||||
image = OpenM3uImage(path, allow_patches, error);
|
||||
allow_patches = false;
|
||||
}
|
||||
else if (IsDeviceName(filename))
|
||||
else if (IsDeviceName(path))
|
||||
{
|
||||
image = OpenDeviceImage(filename, error);
|
||||
image = OpenDeviceImage(path, error);
|
||||
}
|
||||
else
|
||||
{
|
||||
Error::SetStringFmt(error, "Unknown extension '{}' from filename '{}'", extension, Path::GetFileName(filename));
|
||||
Error::SetStringFmt(error, "Unknown extension '{}' from filename '{}'", extension, Path::GetFileName(path));
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (allow_patches)
|
||||
{
|
||||
#ifdef __ANDROID__
|
||||
const std::string ppf_filename(
|
||||
Path::BuildRelativePath(filename, Path::ReplaceExtension(filename_display_name, "ppf")));
|
||||
const std::string ppf_path = Path::BuildRelativePath(path, Path::ReplaceExtension(path_display_name, "ppf"));
|
||||
#else
|
||||
const std::string ppf_filename(
|
||||
Path::BuildRelativePath(filename, Path::ReplaceExtension(Path::GetFileName(filename), "ppf")));
|
||||
const std::string ppf_path = Path::BuildRelativePath(path, Path::ReplaceExtension(Path::GetFileName(path), "ppf"));
|
||||
#endif
|
||||
if (FileSystem::FileExists(ppf_filename.c_str()))
|
||||
if (FileSystem::FileExists(ppf_path.c_str()))
|
||||
{
|
||||
image = CDImage::OverlayPPFPatch(ppf_filename.c_str(), std::move(image));
|
||||
image = CDImage::OverlayPPFPatch(ppf_path.c_str(), std::move(image));
|
||||
if (!image)
|
||||
Error::SetStringFmt(error, "Failed to apply ppf patch from '{}'.", ppf_filename);
|
||||
Error::SetStringFmt(error, "Failed to apply ppf patch from '{}'.", ppf_path);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ public:
|
|||
MODE1_HEADER_SIZE = 4,
|
||||
MODE2_HEADER_SIZE = 12,
|
||||
MODE2_DATA_SECTOR_SIZE = 2336, // header + edc
|
||||
FRAMES_PER_SECOND = 75, // "sectors", or "timecode frames" (not "channel frames")
|
||||
FRAMES_PER_SECOND = 75, // "sectors", or "timecode frames" (not "channel frames")
|
||||
SECONDS_PER_MINUTE = 60,
|
||||
FRAMES_PER_MINUTE = FRAMES_PER_SECOND * SECONDS_PER_MINUTE,
|
||||
SUBCHANNEL_BYTES_PER_FRAME = 12,
|
||||
|
@ -240,17 +240,17 @@ public:
|
|||
static bool IsDeviceName(const char* filename);
|
||||
|
||||
// Opening disc image.
|
||||
static std::unique_ptr<CDImage> Open(const char* filename, bool allow_patches, Error* error);
|
||||
static std::unique_ptr<CDImage> Open(const char* path, bool allow_patches, Error* error);
|
||||
static std::unique_ptr<CDImage> OpenBinImage(const char* path, Error* error);
|
||||
static std::unique_ptr<CDImage> OpenCueSheetImage(const char* path, Error* error);
|
||||
static std::unique_ptr<CDImage> OpenCHDImage(const char* filename, Error* error);
|
||||
static std::unique_ptr<CDImage> OpenMdsImage(const char* filename, Error* error);
|
||||
static std::unique_ptr<CDImage> OpenPBPImage(const char* filename, Error* error);
|
||||
static std::unique_ptr<CDImage> OpenM3uImage(const char* filename, bool apply_patches, Error* error);
|
||||
static std::unique_ptr<CDImage> OpenDeviceImage(const char* filename, Error* error);
|
||||
static std::unique_ptr<CDImage> OpenCHDImage(const char* path, Error* error);
|
||||
static std::unique_ptr<CDImage> OpenMdsImage(const char* path, Error* error);
|
||||
static std::unique_ptr<CDImage> OpenPBPImage(const char* path, Error* error);
|
||||
static std::unique_ptr<CDImage> OpenM3uImage(const char* path, bool apply_patches, Error* error);
|
||||
static std::unique_ptr<CDImage> OpenDeviceImage(const char* path, Error* error);
|
||||
static std::unique_ptr<CDImage>
|
||||
CreateMemoryImage(CDImage* image, ProgressCallback* progress = ProgressCallback::NullProgressCallback);
|
||||
static std::unique_ptr<CDImage> OverlayPPFPatch(const char* filename, std::unique_ptr<CDImage> parent_image,
|
||||
static std::unique_ptr<CDImage> OverlayPPFPatch(const char* path, std::unique_ptr<CDImage> parent_image,
|
||||
ProgressCallback* progress = ProgressCallback::NullProgressCallback);
|
||||
|
||||
// Accessors.
|
||||
|
|
|
@ -533,10 +533,10 @@ s64 CDImageCHD::GetSizeOnDisk() const
|
|||
return static_cast<s64>(chd_get_compressed_size(m_chd));
|
||||
}
|
||||
|
||||
std::unique_ptr<CDImage> CDImage::OpenCHDImage(const char* filename, Error* error)
|
||||
std::unique_ptr<CDImage> CDImage::OpenCHDImage(const char* path, Error* error)
|
||||
{
|
||||
std::unique_ptr<CDImageCHD> image = std::make_unique<CDImageCHD>();
|
||||
if (!image->Open(filename, error))
|
||||
if (!image->Open(path, error))
|
||||
return {};
|
||||
|
||||
return image;
|
||||
|
|
|
@ -634,10 +634,10 @@ bool CDImageDeviceWin32::DetermineReadMode(bool try_sptd)
|
|||
return false;
|
||||
}
|
||||
|
||||
std::unique_ptr<CDImage> CDImage::OpenDeviceImage(const char* filename, Error* error)
|
||||
std::unique_ptr<CDImage> CDImage::OpenDeviceImage(const char* path, Error* error)
|
||||
{
|
||||
std::unique_ptr<CDImageDeviceWin32> image = std::make_unique<CDImageDeviceWin32>();
|
||||
if (!image->Open(filename, error))
|
||||
if (!image->Open(path, error))
|
||||
return {};
|
||||
|
||||
return image;
|
||||
|
@ -679,9 +679,9 @@ std::vector<std::pair<std::string, std::string>> CDImage::GetDeviceList()
|
|||
return ret;
|
||||
}
|
||||
|
||||
bool CDImage::IsDeviceName(const char* filename)
|
||||
bool CDImage::IsDeviceName(const char* path)
|
||||
{
|
||||
return std::string_view(filename).starts_with("\\\\.\\");
|
||||
return std::string_view(path).starts_with("\\\\.\\");
|
||||
}
|
||||
|
||||
#elif defined(__linux__) && !defined(__ANDROID__)
|
||||
|
@ -1083,10 +1083,10 @@ bool CDImageDeviceLinux::DetermineReadMode(Error* error)
|
|||
return false;
|
||||
}
|
||||
|
||||
std::unique_ptr<CDImage> CDImage::OpenDeviceImage(const char* filename, Error* error)
|
||||
std::unique_ptr<CDImage> CDImage::OpenDeviceImage(const char* path, Error* error)
|
||||
{
|
||||
std::unique_ptr<CDImageDeviceLinux> image = std::make_unique<CDImageDeviceLinux>();
|
||||
if (!image->Open(filename, error))
|
||||
if (!image->Open(path, error))
|
||||
return {};
|
||||
|
||||
return image;
|
||||
|
@ -1550,10 +1550,10 @@ bool CDImageDeviceMacOS::DetermineReadMode(Error* error)
|
|||
return false;
|
||||
}
|
||||
|
||||
std::unique_ptr<CDImage> CDImage::OpenDeviceImage(const char* filename, Error* error)
|
||||
std::unique_ptr<CDImage> CDImage::OpenDeviceImage(const char* path, Error* error)
|
||||
{
|
||||
std::unique_ptr<CDImageDeviceMacOS> image = std::make_unique<CDImageDeviceMacOS>();
|
||||
if (!image->Open(filename, error))
|
||||
if (!image->Open(path, error))
|
||||
return {};
|
||||
|
||||
return image;
|
||||
|
@ -1605,12 +1605,12 @@ std::vector<std::pair<std::string, std::string>> CDImage::GetDeviceList()
|
|||
return ret;
|
||||
}
|
||||
|
||||
bool CDImage::IsDeviceName(const char* filename)
|
||||
bool CDImage::IsDeviceName(const char* path)
|
||||
{
|
||||
if (!std::string_view(filename).starts_with("/dev"))
|
||||
if (!std::string_view(path).starts_with("/dev"))
|
||||
return false;
|
||||
|
||||
io_service_t service = GetDeviceMediaService(filename);
|
||||
io_service_t service = GetDeviceMediaService(path);
|
||||
const bool valid = (service != 0);
|
||||
if (valid)
|
||||
IOObjectRelease(service);
|
||||
|
@ -1620,7 +1620,7 @@ bool CDImage::IsDeviceName(const char* filename)
|
|||
|
||||
#else
|
||||
|
||||
std::unique_ptr<CDImage> CDImage::OpenDeviceImage(const char* filename, Error* error)
|
||||
std::unique_ptr<CDImage> CDImage::OpenDeviceImage(const char* path, Error* error)
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
@ -1630,7 +1630,7 @@ std::vector<std::pair<std::string, std::string>> CDImage::GetDeviceList()
|
|||
return {};
|
||||
}
|
||||
|
||||
bool CDImage::IsDeviceName(const char* filename)
|
||||
bool CDImage::IsDeviceName(const char* path)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -181,10 +181,10 @@ bool CDImageM3u::ReadSubChannelQ(SubChannelQ* subq, const Index& index, LBA lba_
|
|||
return m_current_image->ReadSubChannelQ(subq, index, lba_in_index);
|
||||
}
|
||||
|
||||
std::unique_ptr<CDImage> CDImage::OpenM3uImage(const char* filename, bool apply_patches, Error* error)
|
||||
std::unique_ptr<CDImage> CDImage::OpenM3uImage(const char* path, bool apply_patches, Error* error)
|
||||
{
|
||||
std::unique_ptr<CDImageM3u> image = std::make_unique<CDImageM3u>();
|
||||
if (!image->Open(filename, apply_patches, error))
|
||||
if (!image->Open(path, apply_patches, error))
|
||||
return {};
|
||||
|
||||
return image;
|
||||
|
|
|
@ -270,10 +270,10 @@ s64 CDImageMds::GetSizeOnDisk() const
|
|||
return FileSystem::FSize64(m_mdf_file);
|
||||
}
|
||||
|
||||
std::unique_ptr<CDImage> CDImage::OpenMdsImage(const char* filename, Error* error)
|
||||
std::unique_ptr<CDImage> CDImage::OpenMdsImage(const char* path, Error* error)
|
||||
{
|
||||
std::unique_ptr<CDImageMds> image = std::make_unique<CDImageMds>();
|
||||
if (!image->OpenAndParse(filename, error))
|
||||
if (!image->OpenAndParse(path, error))
|
||||
return {};
|
||||
|
||||
return image;
|
||||
|
|
|
@ -935,10 +935,10 @@ s64 CDImagePBP::GetSizeOnDisk() const
|
|||
return FileSystem::FSize64(m_file);
|
||||
}
|
||||
|
||||
std::unique_ptr<CDImage> CDImage::OpenPBPImage(const char* filename, Error* error)
|
||||
std::unique_ptr<CDImage> CDImage::OpenPBPImage(const char* path, Error* error)
|
||||
{
|
||||
std::unique_ptr<CDImagePBP> image = std::make_unique<CDImagePBP>();
|
||||
if (!image->Open(filename, error))
|
||||
if (!image->Open(path, error))
|
||||
return {};
|
||||
|
||||
return image;
|
||||
|
|
|
@ -458,12 +458,11 @@ s64 CDImagePPF::GetSizeOnDisk() const
|
|||
return m_patch_size + m_parent_image->GetSizeOnDisk();
|
||||
}
|
||||
|
||||
std::unique_ptr<CDImage>
|
||||
CDImage::OverlayPPFPatch(const char* filename, std::unique_ptr<CDImage> parent_image,
|
||||
ProgressCallback* progress /* = ProgressCallback::NullProgressCallback */)
|
||||
std::unique_ptr<CDImage> CDImage::OverlayPPFPatch(const char* path, std::unique_ptr<CDImage> parent_image,
|
||||
ProgressCallback* progress)
|
||||
{
|
||||
std::unique_ptr<CDImagePPF> ppf_image = std::make_unique<CDImagePPF>();
|
||||
if (!ppf_image->Open(filename, std::move(parent_image)))
|
||||
if (!ppf_image->Open(path, std::move(parent_image)))
|
||||
return {};
|
||||
|
||||
return ppf_image;
|
||||
|
|
Loading…
Reference in New Issue