Merge pull request #11474 from MayImilae/cleanup-remove-cdutils
Cleanup: Remove CDUtils
This commit is contained in:
commit
2eda76cffc
|
@ -1,230 +0,0 @@
|
||||||
// Copyright 2009 Dolphin Emulator Project
|
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
||||||
|
|
||||||
// Most of the code in this file was shamelessly ripped from libcdio With minor adjustments
|
|
||||||
|
|
||||||
#include "Common/CDUtils.h"
|
|
||||||
|
|
||||||
#include <algorithm>
|
|
||||||
#include <cstdlib>
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include <fmt/format.h>
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
#include <windows.h>
|
|
||||||
#elif __APPLE__
|
|
||||||
#include <CoreFoundation/CoreFoundation.h>
|
|
||||||
#include <IOKit/IOBSD.h>
|
|
||||||
#include <IOKit/IOKitLib.h>
|
|
||||||
#include <IOKit/storage/IOCDMedia.h>
|
|
||||||
#include <IOKit/storage/IOMedia.h>
|
|
||||||
#include <paths.h>
|
|
||||||
#else
|
|
||||||
#include <climits>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <sys/ioctl.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#endif // WIN32
|
|
||||||
|
|
||||||
#ifdef __linux__
|
|
||||||
#include <linux/cdrom.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "Common/Common.h"
|
|
||||||
#include "Common/CommonTypes.h"
|
|
||||||
#include "Common/StringUtil.h"
|
|
||||||
|
|
||||||
namespace Common
|
|
||||||
{
|
|
||||||
#ifdef _WIN32
|
|
||||||
// takes a root drive path, returns true if it is a cdrom drive
|
|
||||||
static bool IsCDROM(const TCHAR* drive)
|
|
||||||
{
|
|
||||||
return (DRIVE_CDROM == GetDriveType(drive));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns a vector with the device names
|
|
||||||
std::vector<std::string> GetCDDevices()
|
|
||||||
{
|
|
||||||
std::vector<std::string> drives;
|
|
||||||
|
|
||||||
const DWORD buffsize = GetLogicalDriveStrings(0, nullptr);
|
|
||||||
std::vector<TCHAR> buff(buffsize);
|
|
||||||
if (GetLogicalDriveStrings(buffsize, buff.data()) == buffsize - 1)
|
|
||||||
{
|
|
||||||
auto drive = buff.data();
|
|
||||||
while (*drive)
|
|
||||||
{
|
|
||||||
if (IsCDROM(drive))
|
|
||||||
{
|
|
||||||
std::string str(TStrToUTF8(drive));
|
|
||||||
str.pop_back(); // we don't want the final backslash
|
|
||||||
drives.push_back(std::move(str));
|
|
||||||
}
|
|
||||||
|
|
||||||
// advance to next drive
|
|
||||||
while (*drive++)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return drives;
|
|
||||||
}
|
|
||||||
#elif defined __APPLE__
|
|
||||||
// Returns a pointer to an array of strings with the device names
|
|
||||||
std::vector<std::string> GetCDDevices()
|
|
||||||
{
|
|
||||||
io_object_t next_media;
|
|
||||||
mach_port_t master_port;
|
|
||||||
kern_return_t kern_result;
|
|
||||||
io_iterator_t media_iterator;
|
|
||||||
CFMutableDictionaryRef classes_to_match;
|
|
||||||
std::vector<std::string> drives;
|
|
||||||
|
|
||||||
kern_result = IOMasterPort(MACH_PORT_NULL, &master_port);
|
|
||||||
if (kern_result != KERN_SUCCESS)
|
|
||||||
return drives;
|
|
||||||
|
|
||||||
classes_to_match = IOServiceMatching(kIOCDMediaClass);
|
|
||||||
if (classes_to_match == nullptr)
|
|
||||||
return drives;
|
|
||||||
|
|
||||||
CFDictionarySetValue(classes_to_match, CFSTR(kIOMediaEjectableKey), kCFBooleanTrue);
|
|
||||||
|
|
||||||
kern_result = IOServiceGetMatchingServices(master_port, classes_to_match, &media_iterator);
|
|
||||||
if (kern_result != KERN_SUCCESS)
|
|
||||||
return drives;
|
|
||||||
|
|
||||||
next_media = IOIteratorNext(media_iterator);
|
|
||||||
if (next_media != 0)
|
|
||||||
{
|
|
||||||
CFTypeRef str_bsd_path;
|
|
||||||
|
|
||||||
do
|
|
||||||
{
|
|
||||||
str_bsd_path =
|
|
||||||
IORegistryEntryCreateCFProperty(next_media, CFSTR(kIOBSDNameKey), kCFAllocatorDefault, 0);
|
|
||||||
if (str_bsd_path == nullptr)
|
|
||||||
{
|
|
||||||
IOObjectRelease(next_media);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (CFGetTypeID(str_bsd_path) == CFStringGetTypeID())
|
|
||||||
{
|
|
||||||
size_t buf_size = CFStringGetLength((CFStringRef)str_bsd_path) * 4 + 1;
|
|
||||||
char* buf = new char[buf_size];
|
|
||||||
|
|
||||||
if (CFStringGetCString((CFStringRef)str_bsd_path, buf, buf_size, kCFStringEncodingUTF8))
|
|
||||||
{
|
|
||||||
// Below, by appending 'r' to the BSD node name, we indicate
|
|
||||||
// a raw disk. Raw disks receive I/O requests directly and
|
|
||||||
// don't go through a buffer cache.
|
|
||||||
drives.push_back(std::string(_PATH_DEV "r") + buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
delete[] buf;
|
|
||||||
}
|
|
||||||
CFRelease(str_bsd_path);
|
|
||||||
IOObjectRelease(next_media);
|
|
||||||
} while ((next_media = IOIteratorNext(media_iterator)) != 0);
|
|
||||||
}
|
|
||||||
IOObjectRelease(media_iterator);
|
|
||||||
return drives;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
// checklist: /dev/cdrom, /dev/dvd /dev/hd?, /dev/scd? /dev/sr?
|
|
||||||
struct CheckListEntry
|
|
||||||
{
|
|
||||||
const char* format;
|
|
||||||
unsigned int num_min;
|
|
||||||
unsigned int num_max;
|
|
||||||
};
|
|
||||||
|
|
||||||
constexpr CheckListEntry checklist[] = {
|
|
||||||
#ifdef __linux__
|
|
||||||
{"/dev/cdrom", 0, 0}, {"/dev/dvd", 0, 0}, {"/dev/hd{}", 'a', 'z'},
|
|
||||||
{"/dev/scd{}", 0, 27}, {"/dev/sr{}", 0, 27},
|
|
||||||
#else
|
|
||||||
{"/dev/acd{}", 0, 27},
|
|
||||||
{"/dev/cd{}", 0, 27},
|
|
||||||
#endif
|
|
||||||
{nullptr, 0, 0},
|
|
||||||
};
|
|
||||||
|
|
||||||
// Returns true if a device is a block or char device and not a symbolic link
|
|
||||||
static bool IsDevice(const std::string& source_name)
|
|
||||||
{
|
|
||||||
struct stat buf;
|
|
||||||
if (0 != lstat(source_name.c_str(), &buf))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return ((S_ISBLK(buf.st_mode) || S_ISCHR(buf.st_mode)) && !S_ISLNK(buf.st_mode));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check a device to see if it is a DVD/CD-ROM drive
|
|
||||||
static bool IsCDROM(const std::string& drive)
|
|
||||||
{
|
|
||||||
// Check if the device exists
|
|
||||||
if (!IsDevice(drive))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
bool is_cd = false;
|
|
||||||
// If it does exist, verify that it is a cdrom/dvd drive
|
|
||||||
int cdfd = open(drive.c_str(), (O_RDONLY | O_NONBLOCK), 0);
|
|
||||||
if (cdfd >= 0)
|
|
||||||
{
|
|
||||||
#ifdef __linux__
|
|
||||||
if (ioctl(cdfd, CDROM_GET_CAPABILITY, 0) != -1)
|
|
||||||
#endif
|
|
||||||
is_cd = true;
|
|
||||||
close(cdfd);
|
|
||||||
}
|
|
||||||
return is_cd;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns a pointer to an array of strings with the device names
|
|
||||||
std::vector<std::string> GetCDDevices()
|
|
||||||
{
|
|
||||||
std::vector<std::string> drives;
|
|
||||||
// Scan the system for DVD/CD-ROM drives.
|
|
||||||
for (unsigned int i = 0; checklist[i].format; ++i)
|
|
||||||
{
|
|
||||||
for (unsigned int j = checklist[i].num_min; j <= checklist[i].num_max; ++j)
|
|
||||||
{
|
|
||||||
std::string drive = fmt::format(fmt::runtime(checklist[i].format), j);
|
|
||||||
if (IsCDROM(drive))
|
|
||||||
{
|
|
||||||
drives.push_back(std::move(drive));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return drives;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Returns true if device is a cdrom/dvd drive
|
|
||||||
bool IsCDROMDevice(std::string device)
|
|
||||||
{
|
|
||||||
#ifndef _WIN32
|
|
||||||
// Resolve symbolic links. This allows symbolic links to valid
|
|
||||||
// drives to be passed from the command line with the -e flag.
|
|
||||||
char resolved_path[PATH_MAX];
|
|
||||||
char* devname = realpath(device.c_str(), resolved_path);
|
|
||||||
if (!devname)
|
|
||||||
return false;
|
|
||||||
device = devname;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
std::vector<std::string> devices = GetCDDevices();
|
|
||||||
for (const std::string& d : devices)
|
|
||||||
{
|
|
||||||
if (d == device)
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} // namespace Common
|
|
|
@ -1,16 +0,0 @@
|
||||||
// Copyright 2009 Dolphin Emulator Project
|
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
namespace Common
|
|
||||||
{
|
|
||||||
// Returns a pointer to an array of strings with the device names
|
|
||||||
std::vector<std::string> GetCDDevices();
|
|
||||||
|
|
||||||
// Returns true if device is cdrom/dvd
|
|
||||||
bool IsCDROMDevice(std::string device);
|
|
||||||
} // namespace Common
|
|
|
@ -6,8 +6,6 @@ add_library(common
|
||||||
BitSet.h
|
BitSet.h
|
||||||
BitUtils.h
|
BitUtils.h
|
||||||
BlockingLoop.h
|
BlockingLoop.h
|
||||||
CDUtils.cpp
|
|
||||||
CDUtils.h
|
|
||||||
ChunkFile.h
|
ChunkFile.h
|
||||||
CodeBlock.h
|
CodeBlock.h
|
||||||
ColorUtil.cpp
|
ColorUtil.cpp
|
||||||
|
|
|
@ -15,7 +15,6 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "Common/Align.h"
|
#include "Common/Align.h"
|
||||||
#include "Common/CDUtils.h"
|
|
||||||
#include "Common/CommonPaths.h"
|
#include "Common/CommonPaths.h"
|
||||||
#include "Common/CommonTypes.h"
|
#include "Common/CommonTypes.h"
|
||||||
#include "Common/Config/Config.h"
|
#include "Common/Config/Config.h"
|
||||||
|
@ -193,10 +192,9 @@ std::unique_ptr<BootParameters> BootParameters::GenerateFromFile(std::vector<std
|
||||||
for (std::string& path : paths)
|
for (std::string& path : paths)
|
||||||
UnifyPathSeparators(path);
|
UnifyPathSeparators(path);
|
||||||
|
|
||||||
const bool is_drive = Common::IsCDROMDevice(paths.front());
|
|
||||||
// Check if the file exist, we may have gotten it from a --elf command line
|
// Check if the file exist, we may have gotten it from a --elf command line
|
||||||
// that gave an incorrect file name
|
// that gave an incorrect file name
|
||||||
if (!is_drive && !File::Exists(paths.front()))
|
if (!File::Exists(paths.front()))
|
||||||
{
|
{
|
||||||
PanicAlertFmtT("The specified file \"{0}\" does not exist", paths.front());
|
PanicAlertFmtT("The specified file \"{0}\" does not exist", paths.front());
|
||||||
return {};
|
return {};
|
||||||
|
@ -235,7 +233,7 @@ std::unique_ptr<BootParameters> BootParameters::GenerateFromFile(std::vector<std
|
||||||
|
|
||||||
static const std::unordered_set<std::string> disc_image_extensions = {
|
static const std::unordered_set<std::string> disc_image_extensions = {
|
||||||
{".gcm", ".iso", ".tgc", ".wbfs", ".ciso", ".gcz", ".wia", ".rvz", ".nfs", ".dol", ".elf"}};
|
{".gcm", ".iso", ".tgc", ".wbfs", ".ciso", ".gcz", ".wia", ".rvz", ".nfs", ".dol", ".elf"}};
|
||||||
if (disc_image_extensions.find(extension) != disc_image_extensions.end() || is_drive)
|
if (disc_image_extensions.find(extension) != disc_image_extensions.end())
|
||||||
{
|
{
|
||||||
std::unique_ptr<DiscIO::VolumeDisc> disc = DiscIO::CreateDisc(path);
|
std::unique_ptr<DiscIO::VolumeDisc> disc = DiscIO::CreateDisc(path);
|
||||||
if (disc)
|
if (disc)
|
||||||
|
@ -258,18 +256,7 @@ std::unique_ptr<BootParameters> BootParameters::GenerateFromFile(std::vector<std
|
||||||
std::move(boot_session_data_));
|
std::move(boot_session_data_));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_drive)
|
|
||||||
{
|
|
||||||
PanicAlertFmtT("Could not read \"{0}\". "
|
|
||||||
"There is no disc in the drive or it is not a GameCube/Wii backup. "
|
|
||||||
"Please note that Dolphin cannot play games directly from the original "
|
|
||||||
"GameCube and Wii discs.",
|
|
||||||
path);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
PanicAlertFmtT("\"{0}\" is an invalid GCM/ISO file, or is not a GC/Wii ISO.", path);
|
PanicAlertFmtT("\"{0}\" is an invalid GCM/ISO file, or is not a GC/Wii ISO.", path);
|
||||||
}
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,6 @@
|
||||||
#include "AudioCommon/AudioCommon.h"
|
#include "AudioCommon/AudioCommon.h"
|
||||||
|
|
||||||
#include "Common/Assert.h"
|
#include "Common/Assert.h"
|
||||||
#include "Common/CDUtils.h"
|
|
||||||
#include "Common/CommonPaths.h"
|
#include "Common/CommonPaths.h"
|
||||||
#include "Common/CommonTypes.h"
|
#include "Common/CommonTypes.h"
|
||||||
#include "Common/Config/Config.h"
|
#include "Common/Config/Config.h"
|
||||||
|
|
|
@ -10,7 +10,6 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#include "Common/CDUtils.h"
|
|
||||||
#include "Common/CommonTypes.h"
|
#include "Common/CommonTypes.h"
|
||||||
#include "Common/IOFile.h"
|
#include "Common/IOFile.h"
|
||||||
#include "Common/MsgHandler.h"
|
#include "Common/MsgHandler.h"
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
<ClInclude Include="Common\BitSet.h" />
|
<ClInclude Include="Common\BitSet.h" />
|
||||||
<ClInclude Include="Common\BitUtils.h" />
|
<ClInclude Include="Common\BitUtils.h" />
|
||||||
<ClInclude Include="Common\BlockingLoop.h" />
|
<ClInclude Include="Common\BlockingLoop.h" />
|
||||||
<ClInclude Include="Common\CDUtils.h" />
|
|
||||||
<ClInclude Include="Common\ChunkFile.h" />
|
<ClInclude Include="Common\ChunkFile.h" />
|
||||||
<ClInclude Include="Common\CodeBlock.h" />
|
<ClInclude Include="Common\CodeBlock.h" />
|
||||||
<ClInclude Include="Common\ColorUtil.h" />
|
<ClInclude Include="Common\ColorUtil.h" />
|
||||||
|
@ -724,7 +723,6 @@
|
||||||
<ClCompile Include="AudioCommon\WASAPIStream.cpp" />
|
<ClCompile Include="AudioCommon\WASAPIStream.cpp" />
|
||||||
<ClCompile Include="AudioCommon\WaveFile.cpp" />
|
<ClCompile Include="AudioCommon\WaveFile.cpp" />
|
||||||
<ClCompile Include="Common\Analytics.cpp" />
|
<ClCompile Include="Common\Analytics.cpp" />
|
||||||
<ClCompile Include="Common\CDUtils.cpp" />
|
|
||||||
<ClCompile Include="Common\ColorUtil.cpp" />
|
<ClCompile Include="Common\ColorUtil.cpp" />
|
||||||
<ClCompile Include="Common\CommonFuncs.cpp" />
|
<ClCompile Include="Common\CommonFuncs.cpp" />
|
||||||
<ClCompile Include="Common\CompatPatches.cpp" />
|
<ClCompile Include="Common\CompatPatches.cpp" />
|
||||||
|
|
|
@ -19,7 +19,6 @@
|
||||||
#include "Common/FileUtil.h"
|
#include "Common/FileUtil.h"
|
||||||
#include "Common/StringUtil.h"
|
#include "Common/StringUtil.h"
|
||||||
|
|
||||||
#include "Common/CDUtils.h"
|
|
||||||
#include "Core/Boot/Boot.h"
|
#include "Core/Boot/Boot.h"
|
||||||
#include "Core/CommonTitles.h"
|
#include "Core/CommonTitles.h"
|
||||||
#include "Core/Config/MainSettings.h"
|
#include "Core/Config/MainSettings.h"
|
||||||
|
|
Loading…
Reference in New Issue