diff --git a/Source/Core/Common/Src/CDUtils.cpp b/Source/Core/Common/Src/CDUtils.cpp index 8339ea85e1..1ab2288f11 100644 --- a/Source/Core/Common/Src/CDUtils.cpp +++ b/Source/Core/Common/Src/CDUtils.cpp @@ -51,54 +51,6 @@ void cdio_follow_symlink(const char * src, char * dst) { strncpy(dst, src, PATH_MAX); #endif } - - - -// Add/allocate a drive to the end of drives. -// Use cdio_free_device_list() to free this device_list. -void cdio_add_device_list(char **device_list[], const char *drive, - unsigned int *num_drives) { - if (NULL != drive) { - unsigned int j; - char real_device_1[PATH_MAX]; - char real_device_2[PATH_MAX]; - cdio_follow_symlink(drive, real_device_1); - /* Check if drive is already in list. */ - for (j=0; j<*num_drives; j++) { - cdio_follow_symlink((*device_list)[j], real_device_2); - if (strcmp(real_device_1, real_device_2) == 0) break; - } - - if (j==*num_drives) { - /* Drive not in list. Add it. */ - (*num_drives)++; - *device_list = (char **)realloc(*device_list, (*num_drives) * sizeof(char *)); - (*device_list)[*num_drives-1] = __strdup(drive); - } - - } else { - (*num_drives)++; - if (*device_list) { - *device_list = (char **)realloc(*device_list, (*num_drives) * sizeof(char *)); - } else { - *device_list = (char **)malloc((*num_drives) * sizeof(char *)); - } - (*device_list)[*num_drives-1] = NULL; - } -} - -// Free device list returned by cdio_get_devices or -// cdio_get_devices_with_cap. -void cdio_free_device_list(char * ppsz_device_list[]) { - char **ppsz_device_list_save=ppsz_device_list; - if (!ppsz_device_list) return; - for ( ; NULL != *ppsz_device_list ; ppsz_device_list++ ) { - free(*ppsz_device_list); - *ppsz_device_list = NULL; - } - free(ppsz_device_list_save); -} - #ifdef _WIN32 // Returns a string that can be used in a CreateFile call if @@ -128,9 +80,8 @@ const char *is_cdrom_win32(const char c_drive_letter) { } // Returns a pointer to an array of strings with the device names -char ** cdio_get_devices_win32() { - char **drives = NULL; - unsigned int num_drives=0; +std::vector cdio_get_devices_win32() { + std::vector drives; char drive_letter; // Scan the system for CD-ROM drives. @@ -138,11 +89,10 @@ char ** cdio_get_devices_win32() { for (drive_letter='A'; drive_letter <= 'Z'; drive_letter++) { const char *drive_str=is_cdrom_win32(drive_letter); if (drive_str != NULL) { - cdio_add_device_list(&drives, drive_str, &num_drives); + drives.push_back(drive_str); delete drive_str; } } - cdio_add_device_list(&drives, NULL, &num_drives); return drives; } #endif // WIN32 @@ -153,23 +103,22 @@ char ** cdio_get_devices_win32() { /* Returns a pointer to an array of strings with the device names */ -char **cdio_get_devices_osx(void) { +std::vector cdio_get_devices_osx(void) { io_object_t next_media; mach_port_t master_port; kern_return_t kern_result; io_iterator_t media_iterator; CFMutableDictionaryRef classes_to_match; - char **drives = NULL; - unsigned int num_drives=0; + std::vector drives; kern_result = IOMasterPort( MACH_PORT_NULL, &master_port ); if( kern_result != KERN_SUCCESS ) { - return( NULL ); + return( drives ); } classes_to_match = IOServiceMatching( kIOCDMediaClass ); if( classes_to_match == NULL ) { - return( NULL ); + return( drives ); } CFDictionarySetValue( classes_to_match, CFSTR(kIOMediaEjectableKey), @@ -179,7 +128,7 @@ char **cdio_get_devices_osx(void) { classes_to_match, &media_iterator ); if( kern_result != KERN_SUCCESS) { - return( NULL ); + return( drives ); } next_media = IOIteratorNext( media_iterator ); @@ -209,7 +158,11 @@ char **cdio_get_devices_osx(void) { (char*)&psz_buf + dev_path_length, sizeof(psz_buf) - dev_path_length, kCFStringEncodingASCII)) { - cdio_add_device_list(&drives, strdup(psz_buf), &num_drives); + if(psz_buf != NULL) + { + std::string str = psz_buf; + drives.push_back(str); + } } CFRelease( str_bsd_path ); IOObjectRelease( next_media ); @@ -217,7 +170,6 @@ char **cdio_get_devices_osx(void) { } while( ( next_media = IOIteratorNext( media_iterator ) ) != 0 ); } IOObjectRelease( media_iterator ); - cdio_add_device_list(&drives, NULL, &num_drives); return drives; } #endif @@ -355,31 +307,33 @@ static char *check_mounts_linux(const char *mtab) } // Returns a pointer to an array of strings with the device names -char **cdio_get_devices_linux () { +std::vector cdio_get_devices_linux () { unsigned int i; char drive[40]; char *ret_drive; - char **drives = NULL; - unsigned int num_drives=0; + std::vector drives; // Scan the system for CD-ROM drives. for ( i=0; strlen(checklist1[i]) > 0; ++i ) { sprintf(drive, "/dev/%s", checklist1[i]); if ( is_cdrom_linux(drive, NULL) > 0 ) { - cdio_add_device_list(&drives, drive, &num_drives); + std::string str = drive; + drives.push_back(str); } } /* Now check the currently mounted CD drives */ if (NULL != (ret_drive = check_mounts_linux("/etc/mtab"))) { - cdio_add_device_list(&drives, ret_drive, &num_drives); + std::string str = ret_drive; + drives.push_back(str); free(ret_drive); } /* Finally check possible mountable drives in /etc/fstab */ if (NULL != (ret_drive = check_mounts_linux("/etc/fstab"))) { - cdio_add_device_list(&drives, ret_drive, &num_drives); + std::string str = ret_drive; + drives.push_back(str); free(ret_drive); } @@ -390,17 +344,17 @@ char **cdio_get_devices_linux () { for ( j=checklist2[i].num_min; j<=checklist2[i].num_max; ++j ) { sprintf(drive, checklist2[i].format, j); if ( (is_cdrom_linux(drive, NULL)) > 0 ) { - cdio_add_device_list(&drives, drive, &num_drives); + std::string str = drive; + drives.push_back(str); } } } - cdio_add_device_list(&drives, NULL, &num_drives); return drives; } #endif // Returns a pointer to an array of strings with the device names -char **cdio_get_devices() { +std::vector cdio_get_devices() { #ifdef _WIN32 return cdio_get_devices_win32(); #elif __APPLE__ @@ -416,17 +370,17 @@ char **cdio_get_devices() { // Returns true if device is cdrom/dvd -bool cdio_is_cdrom(const char *device) { - char **devices = cdio_get_devices(); +bool cdio_is_cdrom(std::string device) { + std::vector devices = cdio_get_devices(); bool res = false; - for (int i = 0; devices[i] != NULL; i++) { - if (strncmp(devices[i], device, PATH_MAX) == 0) { + for (int i = 0; i < devices.size(); i++) { + if (strncmp(devices[i].c_str(), device.c_str(), PATH_MAX) == 0) { res = true; break; } } - cdio_free_device_list(devices); + devices.clear(); return res; } diff --git a/Source/Core/Common/Src/CDUtils.h b/Source/Core/Common/Src/CDUtils.h index 58df5881f1..34b41a0d4f 100644 --- a/Source/Core/Common/Src/CDUtils.h +++ b/Source/Core/Common/Src/CDUtils.h @@ -2,17 +2,14 @@ #define _CDUTILS_H_ #include -#include +#include +#include #include // Returns a pointer to an array of strings with the device names -char **cdio_get_devices(); - -// Free device list returned by cdio_get_devices or -// cdio_get_devices_with_cap. -void cdio_free_device_list(char * ppsz_device_list[]); +std::vector cdio_get_devices(); // Returns true if device is cdrom/dvd -bool cdio_is_cdrom(const char *device); +bool cdio_is_cdrom(std::string device); #endif // _CDUTILS_H_ diff --git a/Source/Core/Common/Src/CommonFuncs.h b/Source/Core/Common/Src/CommonFuncs.h index 953da5bb61..5aa174ed98 100644 --- a/Source/Core/Common/Src/CommonFuncs.h +++ b/Source/Core/Common/Src/CommonFuncs.h @@ -120,6 +120,10 @@ inline u64 swap64(u64 _data) {return _byteswap_uint64(_data);} inline u16 swap16(u16 _data) {return bswap_16(_data);} inline u32 swap32(u32 _data) {return bswap_32(_data);} inline u64 swap64(u64 _data) {return bswap_64(_data);} +#elif __APPLE__ +inline u16 swap16(u16 _data) {return (_data >> 8) | (_data << 8);} +inline u32 swap32(u32 _data) {return __builtin_bswap32(_data);} +inline u64 swap64(u64 _data) {return __builtin_bswap64(_data);} #else // Slow generic implementation. inline u16 swap16(u16 data) {return (data >> 8) | (data << 8);} diff --git a/Source/Core/Core/Src/CoreParameter.cpp b/Source/Core/Core/Src/CoreParameter.cpp index 60dd6f68a8..a19781a23f 100644 --- a/Source/Core/Core/Src/CoreParameter.cpp +++ b/Source/Core/Core/Src/CoreParameter.cpp @@ -86,7 +86,7 @@ bool SCoreStartupParameter::AutoSetup(EBootBS2 _BootBS2) { case BOOT_DEFAULT: { - bool bootDrive = cdio_is_cdrom(m_strFilename.c_str()); + bool bootDrive = cdio_is_cdrom(m_strFilename); // 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 7f951dcf53..46e5d5e4ee 100644 --- a/Source/Core/DiscIO/Src/Blob.cpp +++ b/Source/Core/DiscIO/Src/Blob.cpp @@ -121,7 +121,7 @@ bool SectorReader::ReadMultipleAlignedBlocks(u64 block_num, u64 num_blocks, u8 * IBlobReader* CreateBlobReader(const char* filename) { - if (cdio_is_cdrom(filename)) + if (cdio_is_cdrom(std::string(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 68bd292ee5..71c3b055bb 100644 --- a/Source/Core/DolphinWX/Src/Frame.cpp +++ b/Source/Core/DolphinWX/Src/Frame.cpp @@ -510,7 +510,7 @@ CFrame::~CFrame() { m_bControlsCreated = false; - cdio_free_device_list(drives); + drives.clear(); /* 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 4564feb911..0384c9bc6a 100644 --- a/Source/Core/DolphinWX/Src/Frame.h +++ b/Source/Core/DolphinWX/Src/Frame.h @@ -29,6 +29,8 @@ #define id toolid #endif #include +#include +#include #include "CDUtils.h" #include "CodeWindow.h" @@ -202,7 +204,7 @@ class CFrame : public wxFrame char newDiscpath[2048]; wxMessageDialog *m_StopDlg; - char **drives; + std::vector drives; enum EToolbar { diff --git a/Source/Core/DolphinWX/Src/FrameTools.cpp b/Source/Core/DolphinWX/Src/FrameTools.cpp index 7058376ec2..cc4ea32085 100644 --- a/Source/Core/DolphinWX/Src/FrameTools.cpp +++ b/Source/Core/DolphinWX/Src/FrameTools.cpp @@ -115,8 +115,9 @@ void CFrame::CreateMenu() m_pSubMenuDrive = fileMenu->AppendSubMenu(externalDrive, _T("&Boot from DVD Drive...")); drives = cdio_get_devices(); - for (int i = 0; drives[i] != NULL && i < 24; i++) { - externalDrive->Append(IDM_DRIVE1 + i, wxString::FromAscii(drives[i])); + // Windows Limitation of 24 character drives + for (int i = 0; i < drives.size() && i < 24; i++) { + externalDrive->Append(IDM_DRIVE1 + i, wxString::FromAscii(drives[i].c_str())); } fileMenu->AppendSeparator(); @@ -666,7 +667,7 @@ void CFrame::StartGame(const std::string& filename) void CFrame::OnBootDrive(wxCommandEvent& event) { - BootManager::BootCore(drives[event.GetId()-IDM_DRIVE1]); + BootManager::BootCore(drives[event.GetId()-IDM_DRIVE1].c_str()); } diff --git a/Source/Core/DolphinWX/Src/GameListCtrl.cpp b/Source/Core/DolphinWX/Src/GameListCtrl.cpp index 9599418c33..d4f78d868d 100644 --- a/Source/Core/DolphinWX/Src/GameListCtrl.cpp +++ b/Source/Core/DolphinWX/Src/GameListCtrl.cpp @@ -559,11 +559,12 @@ void CGameListCtrl::ScanForISOs() if (SConfig::GetInstance().m_ListDrives) { - char **drives = cdio_get_devices(); + std::vector drives = cdio_get_devices(); GameListItem * Drive[24]; - for (int i = 0; drives[i] != NULL && i < 24; i++) + // Another silly Windows limitation of 24 drive letters + for (int i = 0; i < drives.size() != NULL && i < 24; i++) { - Drive[i] = new GameListItem(drives[i]); + Drive[i] = new GameListItem(drives[i].c_str()); if (Drive[i]->IsValid()) m_ISOFiles.push_back(*Drive[i]); } }