diff --git a/Source/Core/Common/Src/DriveUtil.cpp b/Source/Core/Common/Src/DriveUtil.cpp deleted file mode 100644 index e76b646c31..0000000000 --- a/Source/Core/Common/Src/DriveUtil.cpp +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright (C) 2003-2008 Dolphin Project. - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, version 2.0. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License 2.0 for more details. - -// A copy of the GPL 2.0 should have been included with the program. -// If not, see http://www.gnu.org/licenses/ - -// Official SVN repository and contact information can be found at -// http://code.google.com/p/dolphin-emu/ - -#include -#include "DriveUtil.h" - -#ifdef _WIN32 -#include -#include -#elif defined(__GNUC__) // TODO: replace these with real linux / os x functinos -#define GetLogicalDriveStrings(x, y) (int)memcpy(y,"/dev/cdrom\0/dev/cdrom1\0/dev/cdrom2\0/dev/cdrom3\0/dev/cdrom4\0/dev/cdrom5\0/dev/cdrom6\0/dev/cdrom7\0/dev/cdrom8\0/dev/cdrom9\0\0\0", 121); -#else -#define GetLogicalDriveStrings(x, y) (int)memcpy(y,"/dev/disk2\0/dev/disk3\0/dev/disk4\0/dev/disk5\0/dev/disk6\0/dev/disk7\0/dev/disk8\0/dev/disk9\0/dev/disk10\0/dev/disk11\0\0\0",114); -#endif - -void GetAllRemovableDrives(std::vector *drives) { - drives->clear(); - char drives_string[1024]; - int max_drive_pos = GetLogicalDriveStrings(1024, drives_string); - - char *p = drives_string; - // GetLogicalDriveStrings returns the drives as a a series of null-terminated strings - // laid out right after each other in RAM, with a double null at the end. - while (*p) - { - if (File::IsDisk(p)) - { - drives->push_back(std::string(p)); - } - p += strlen(p) + 1; - } -} diff --git a/Source/Core/Common/Src/DriveUtil.h b/Source/Core/Common/Src/DriveUtil.h deleted file mode 100644 index 54d946355d..0000000000 --- a/Source/Core/Common/Src/DriveUtil.h +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (C) 2003-2008 Dolphin Project. - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, version 2.0. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License 2.0 for more details. - -// A copy of the GPL 2.0 should have been included with the program. -// If not, see http://www.gnu.org/licenses/ - -// Official SVN repository and contact information can be found at -// http://code.google.com/p/dolphin-emu/ - -#ifndef _DRIVEUTIL_H -#define _DRIVEUTIL_H - -#include -#include -#include "Common.h" -#include "FileUtil.h" - -// Tools to enumerate drives (HDD, DVD, CD) in a platform-independent manner. - -void GetAllRemovableDrives(std::vector *drives); - -#endif diff --git a/Source/Core/Common/Src/FileUtil.cpp b/Source/Core/Common/Src/FileUtil.cpp index 07ffc9d1f3..0d79954fa2 100644 --- a/Source/Core/Common/Src/FileUtil.cpp +++ b/Source/Core/Common/Src/FileUtil.cpp @@ -72,40 +72,6 @@ bool Exists(const char *filename) return (result == 0); } -bool IsDisk(const char *filename) -{ -#ifdef _WIN32 - if (GetDriveType(filename) == DRIVE_CDROM) // CD_ROM also applies to DVD. Noone has a plain CDROM without DVD anymore so we should be fine. - return true; -#else - struct stat statInfo; - if((stat(filename, &statInfo) > -1) && (S_ISCHR(statInfo.st_mode) || S_ISBLK(statInfo.st_mode))) - { - int fileHandle; - // try to open the device - fileHandle = open(filename, O_RDONLY | O_NONBLOCK, 0); - if (fileHandle >= 0) - { - cdrom_subchnl cdChannelInfo; - cdChannelInfo.cdsc_format = CDROM_MSF; - - if ((ioctl(fileHandle, CDROMSUBCHNL, &cdChannelInfo) == 0) || - (errno == EIO) || (errno == ENOENT) || - (errno == EINVAL) - #ifdef __GNUC__ - || (errno == ENOMEDIUM) - #endif - ) - { - return true; - } - close(fileHandle); - } - } -#endif - return false; -} - bool IsDirectory(const char *filename) { struct stat file_info; diff --git a/Source/Core/Common/Src/SConscript b/Source/Core/Common/Src/SConscript index 491b47943d..6cb18ad748 100644 --- a/Source/Core/Common/Src/SConscript +++ b/Source/Core/Common/Src/SConscript @@ -5,11 +5,11 @@ Import('env') files = [ "ABI.cpp", "MsgHandler.cpp", + "CDUtils.cpp", "ChunkFile.cpp", "ConsoleWindow.cpp", "ColorUtil.cpp", "CPUDetect.cpp", - "DriveUtil.cpp", "DynamicLibrary.cpp", "Hash.cpp", "IniFile.cpp", diff --git a/Source/Core/Core/Src/CoreParameter.cpp b/Source/Core/Core/Src/CoreParameter.cpp index 2a0d45c909..2339c03ec4 100644 --- a/Source/Core/Core/Src/CoreParameter.cpp +++ b/Source/Core/Core/Src/CoreParameter.cpp @@ -18,6 +18,7 @@ #include "Common.h" // Common #include "FileUtil.h" #include "StringUtil.h" +#include "CDUtils.h" #include "VolumeCreator.h" // DiscIO @@ -62,7 +63,7 @@ bool SCoreStartupParameter::AutoSetup(EBootBios _BootBios) { case BOOT_DEFAULT: { - bool bootDrive = File::IsDisk(m_strFilename.c_str()); + bool bootDrive = cdio_is_cdrom(m_strFilename.c_str()); // Check if the file exist, we may have gotten it from a --elf command line // that gave an incorrect file name if (!bootDrive && !File::Exists(m_strFilename.c_str())) diff --git a/Source/Core/DiscIO/Src/Blob.cpp b/Source/Core/DiscIO/Src/Blob.cpp index 9ca96a87ad..a2c04feec8 100644 --- a/Source/Core/DiscIO/Src/Blob.cpp +++ b/Source/Core/DiscIO/Src/Blob.cpp @@ -17,6 +17,7 @@ #include "Common.h" #include "FileUtil.h" +#include "CDUtils.h" #include "Blob.h" #include "CompressedBlob.h" #include "FileBlob.h" @@ -121,7 +122,7 @@ bool SectorReader::ReadMultipleAlignedBlocks(u64 block_num, u64 num_blocks, u8 * IBlobReader* CreateBlobReader(const char* filename) { - if (File::IsDisk(filename)) + if (cdio_is_cdrom(filename)) return DriveReader::Create(filename); if (!File::Exists(filename)) diff --git a/Source/Core/DolphinWX/Src/Frame.cpp b/Source/Core/DolphinWX/Src/Frame.cpp index f171d0d0f3..74087a9037 100644 --- a/Source/Core/DolphinWX/Src/Frame.cpp +++ b/Source/Core/DolphinWX/Src/Frame.cpp @@ -389,6 +389,7 @@ CFrame::CFrame(wxFrame* parent, // Destructor CFrame::~CFrame() { + cdio_free_device_list(drives); /* The statbar sample has this so I add this to, but I guess timer will be deleted after this anyway */ #if wxUSE_TIMER diff --git a/Source/Core/DolphinWX/Src/Frame.h b/Source/Core/DolphinWX/Src/Frame.h index 588ea699be..14cb29c41f 100644 --- a/Source/Core/DolphinWX/Src/Frame.h +++ b/Source/Core/DolphinWX/Src/Frame.h @@ -26,7 +26,7 @@ #include #include //////////////////////////////// -#include "DriveUtil.h" +#include "CDUtils.h" ////////////////////////////////////////////////////////////////////////// // A shortcut to access the bitmaps @@ -98,7 +98,7 @@ class CFrame : public wxFrame wxToolBar* TheToolBar; wxToolBarToolBase* m_ToolPlay; - std::vector drives; + char **drives; ////////////////////////////////////////////////////////////////////////////////////// // Music mod diff --git a/Source/Core/DolphinWX/Src/FrameTools.cpp b/Source/Core/DolphinWX/Src/FrameTools.cpp index 0e0e9985c3..44e9b2b39e 100644 --- a/Source/Core/DolphinWX/Src/FrameTools.cpp +++ b/Source/Core/DolphinWX/Src/FrameTools.cpp @@ -100,15 +100,14 @@ void CFrame::CreateMenu() wxMenu* fileMenu = new wxMenu; m_pMenuItemOpen = fileMenu->Append(wxID_OPEN, _T("&Open...\tCtrl+O")); -#if defined(_WIN32) || defined(__GNUC__) // not tested on os x wxMenu *externalDrive = new wxMenu; fileMenu->AppendSubMenu(externalDrive, _T("&Boot from DVD Drive...")); - GetAllRemovableDrives(&drives); - for (int i = 0; i < drives.size() && i < 24; i++) - { - externalDrive->Append(IDM_DRIVE1 + i, wxString::FromAscii(drives.at(i).c_str())); + + drives = cdio_get_devices(); + for (int i = 0; drives[i] != NULL && i < 24; i++) { + externalDrive->Append(IDM_DRIVE1 + i, wxString::FromAscii(drives[i])); } -#endif + fileMenu->AppendSeparator(); fileMenu->Append(wxID_REFRESH, _T("&Refresh List")); fileMenu->AppendSeparator(); @@ -489,7 +488,7 @@ void CFrame::OnPlay(wxCommandEvent& WXUNUSED (event)) void CFrame::OnBootDrive(wxCommandEvent& event) { - BootManager::BootCore(drives.at(event.GetId()-IDM_DRIVE1).c_str()); + BootManager::BootCore(drives[event.GetId()-IDM_DRIVE1]); } ////////////////////////////////////////////////////