Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Utilities/File.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1127,6 +1127,13 @@ bool fs::is_optical_raw_device(const std::string& path)

bool fs::get_optical_raw_device(const std::string& path, std::string* raw_device)
{
// Skip a useless check to detect an optical raw device if navigating on subfolders (e.g. C:/subfolder_1/subfolder_2/), it means we are on a hdd/ssd.
// A path for an optical drive should include only the drive letter (e.g. E:/)
if (path.find_first_of(":") != path.find_last_not_of(delim))
{
return false;
}

if (fs::is_optical_raw_device(path))
{
if (raw_device)
Expand Down Expand Up @@ -1745,6 +1752,17 @@ fs::file::file(const std::string& path, bs_t<open_mode> mode)
// (the following GetFileInformationByHandle() would always fail on a raw device).
if (is_optical_raw_device(path))
{
DISK_GEOMETRY_EX geometry;

// Try to retrieve information on content. If it fails, no disc is probably mounted so abort the file opening
if (!DeviceIoControl(handle, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX, nullptr, 0, &geometry, sizeof(geometry), nullptr, nullptr))
{
const DWORD last_error = GetLastError();
Comment thread
elad335 marked this conversation as resolved.
CloseHandle(handle);
g_tls_error = to_error(last_error);
return;
}

m_file = std::make_unique<windows_file>(handle, true);
return;
}
Expand Down