Rockbox open source high quality audio player as a Music Player Daemon
mpris rockbox mpd libadwaita audio rust zig deno
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

rbutil: Add quessing of the Drive letter via Windows API, also restructuring for future Device detection via pid and vid.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@13655 a1c6a512-1295-4272-9138-f99709370657

+400 -69
+231
rbutil/autodetection.cpp
··· 1 + /*************************************************************************** 2 + * __________ __ ___. 3 + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ 4 + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / 5 + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < 6 + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 7 + * \/ \/ \/ \/ \/ 8 + * Module: rbutil 9 + * File: autodetection.cpp 10 + * 11 + * Copyright (C) 2008 Dominik Wenger 12 + * 13 + * All files in this archive are subject to the GNU General Public License. 14 + * See the file COPYING in the source tree root for full license agreement. 15 + * 16 + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 17 + * KIND, either express or implied. 18 + * 19 + ****************************************************************************/ 20 + 21 + #include "autodetection.h" 22 + #include "bootloaders.h" 23 + /*************************************************** 24 + * General autodetection code 25 + ****************************************************/ 26 + 27 + 28 + UsbDeviceInfo detectDevicesViaPatchers() 29 + { 30 + UsbDeviceInfo tempdevice; 31 + tempdevice.device_index= 0; 32 + tempdevice.path=wxT(""); 33 + tempdevice.status =0; 34 + 35 + /* scann for ipods */ 36 + 37 + struct ipod_t ipod; 38 + int n = ipod_scan(&ipod); 39 + if(n == 1) 40 + { 41 + wxString temp(ipod.targetname,wxConvUTF8); 42 + int index = gv->plat_bootloadername.Index(temp); // use the bootloader names.. 43 + tempdevice.device_index = index; 44 + /* find mount point if possible */ 45 + #if !(defined( __WXMSW__ ) || defined( __DARWIN__)) //linux code 46 + wxString tmp = resolve_mount_point(wxString(ipod.diskname,wxConvUTF8)+wxT("2")); 47 + if( tmp != wxT("") ) 48 + tempdevice.path = tmp; 49 + #endif 50 + #if defined( __WXMSW__ ) //Windows code 51 + wxString tmp = guess_mount_point(); 52 + if( tmp != wxT("") ) 53 + tempdevice.path = tmp; 54 + #endif 55 + return tempdevice; 56 + } 57 + else if (n > 1) 58 + { 59 + tempdevice.status = TOMANYDEVICES; 60 + return tempdevice; 61 + } 62 + 63 + /* scann for sansas */ 64 + struct sansa_t sansa; 65 + int n2 = sansa_scan(&sansa); 66 + if(n2==1) 67 + { 68 + tempdevice.device_index = gv->plat_id.Index(wxT("sansae200")); 69 + /* find mount point if possible */ 70 + #if !(defined( __WXMSW__ ) || defined( __DARWIN__)) //linux code 71 + wxString tmp = resolve_mount_point(wxString(ipod.diskname,wxConvUTF8)+wxT("1")); 72 + if( tmp != wxT("") ) 73 + tempdevice.path = tmp; 74 + #endif 75 + #if defined( __WXMSW__ ) // windows code 76 + wxString tmp = guess_mount_point(); 77 + if( tmp != wxT("") ) 78 + tempdevice.path = tmp; 79 + #endif 80 + return tempdevice; 81 + } 82 + else if (n > 1) 83 + { 84 + tempdevice.status = TOMANYDEVICES; 85 + return tempdevice; 86 + } 87 + 88 + 89 + tempdevice.status = NODEVICE; 90 + return tempdevice; 91 + 92 + } 93 + 94 + 95 + 96 + 97 + /*************************************************** 98 + * Windows code for autodetection 99 + ****************************************************/ 100 + #if defined( __WXMSW__ ) 101 + 102 + wxString guess_mount_point() 103 + { 104 + wxString mountpoint = wxT(""); 105 + TCHAR szDrvName[33]; 106 + DWORD maxDriveSet, curDriveSet; 107 + DWORD drive; 108 + TCHAR szBuf[300]; 109 + HANDLE hDevice; 110 + PSTORAGE_DEVICE_DESCRIPTOR pDevDesc; 111 + 112 + maxDriveSet = GetLogicalDrives(); 113 + curDriveSet = maxDriveSet; 114 + for ( drive = 0; drive < 32; ++drive ) 115 + { 116 + if ( maxDriveSet & (1 << drive) ) 117 + { 118 + DWORD temp = 1<<drive; 119 + _stprintf( szDrvName, _T("%c:\\"), 'A'+drive ); 120 + switch ( GetDriveType( szDrvName ) ) 121 + { 122 + case 0: // The drive type cannot be determined. 123 + case 1: // The root directory does not exist. 124 + case DRIVE_CDROM: // The drive is a CD-ROM drive. 125 + case DRIVE_REMOTE: // The drive is a remote (network) drive. 126 + case DRIVE_RAMDISK: // The drive is a RAM disk. 127 + case DRIVE_REMOVABLE: // The drive can be removed from the drive. 128 + break; 129 + case DRIVE_FIXED: // The disk cannot be removed from the drive. 130 + sprintf(szBuf, "\\\\?\\%c:", 'A'+drive); 131 + hDevice = CreateFile(szBuf, GENERIC_READ, 132 + FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, NULL, NULL); 133 + 134 + if (hDevice != INVALID_HANDLE_VALUE) 135 + { 136 + pDevDesc = (PSTORAGE_DEVICE_DESCRIPTOR)new BYTE[sizeof(STORAGE_DEVICE_DESCRIPTOR) + 512 - 1]; 137 + pDevDesc->Size = sizeof(STORAGE_DEVICE_DESCRIPTOR) + 512 - 1; 138 + 139 + if(GetDisksProperty(hDevice, pDevDesc)) 140 + { 141 + if(pDevDesc->BusType == BusTypeUsb) 142 + { 143 + mountpoint.Printf(wxT("%c:\\"), chFirstDriveFromMask(temp)); 144 + } 145 + } 146 + delete pDevDesc; 147 + CloseHandle(hDevice); 148 + } 149 + break; 150 + } 151 + } 152 + } 153 + return mountpoint; 154 + 155 + } 156 + 157 + 158 + 159 + /**************************************************************************** 160 + * FUNCTION: GetDisksProperty(HANDLE hDevice, PSTORAGE_DEVICE_DESCRIPTOR pDevDesc) 161 + * PURPOSE: get the info of specified device 162 + *****************************************************************************/ 163 + BOOL GetDisksProperty(HANDLE hDevice, PSTORAGE_DEVICE_DESCRIPTOR pDevDesc) 164 + { 165 + STORAGE_PROPERTY_QUERY Query; // input param for query 166 + DWORD dwOutBytes; // IOCTL output length 167 + BOOL bResult; // IOCTL return val 168 + 169 + // specify the query type 170 + Query.PropertyId = StorageDeviceProperty; 171 + Query.QueryType = PropertyStandardQuery; 172 + 173 + // Query using IOCTL_STORAGE_QUERY_PROPERTY 174 + bResult = ::DeviceIoControl(hDevice, // device handle 175 + IOCTL_STORAGE_QUERY_PROPERTY, // info of device property 176 + &Query, sizeof(STORAGE_PROPERTY_QUERY), // input data buffer 177 + pDevDesc, pDevDesc->Size, // output data buffer 178 + &dwOutBytes, // out's length 179 + (LPOVERLAPPED)NULL); 180 + 181 + return bResult; 182 + } 183 + 184 + /********************************************* 185 + * Converts the driveMask to a drive letter 186 + *******************************************/ 187 + char chFirstDriveFromMask (ULONG unitmask) 188 + { 189 + 190 + char i; 191 + for (i = 0; i < 26; ++i) 192 + { 193 + if (unitmask & 0x1) 194 + break; 195 + unitmask = unitmask >> 1; 196 + } 197 + return (i + 'A'); 198 + } 199 + #endif /* windows code */ 200 + 201 + /********************************************************** 202 + * Linux code for autodetection 203 + *******************************************************/ 204 + #if !(defined( __WXMSW__ ) || defined( __DARWIN__)) 205 + 206 + 207 + 208 + wxString resolve_mount_point( const wxString device ) 209 + { 210 + FILE *fp = fopen( "/proc/mounts", "r" ); 211 + if( !fp ) return wxT(""); 212 + char *dev, *dir; 213 + while( fscanf( fp, "%as %as %*s %*s %*s %*s", &dev, &dir ) != EOF ) 214 + { 215 + if( wxString( dev, wxConvUTF8 ) == device ) 216 + { 217 + wxString directory = wxString( dir, wxConvUTF8 ); 218 + free( dev ); 219 + free( dir ); 220 + return directory; 221 + } 222 + free( dev ); 223 + free( dir ); 224 + } 225 + fclose( fp ); 226 + return wxT(""); 227 + } 228 + 229 + 230 + 231 + #endif
+142
rbutil/autodetection.h
··· 1 + /*************************************************************************** 2 + * __________ __ ___. 3 + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ 4 + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / 5 + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < 6 + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 7 + * \/ \/ \/ \/ \/ 8 + * Module: rbutil 9 + * File: autodetection.h 10 + * 11 + * Copyright (C) 2008 Dominik Wenger 12 + * 13 + * All files in this archive are subject to the GNU General Public License. 14 + * See the file COPYING in the source tree root for full license agreement. 15 + * 16 + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 17 + * KIND, either express or implied. 18 + * 19 + ****************************************************************************/ 20 + 21 + #ifndef AUTODETECTION_H_INCLUDED 22 + #define AUTODETECTION_H_INCLUDED 23 + 24 + 25 + /************************************** 26 + * General code for USB Device detection 27 + ***************************************/ 28 + #include "rbutil.h" 29 + 30 + #define TOMANYDEVICES 2 31 + #define NODEVICE 1 32 + 33 + struct UsbDeviceInfo 34 + { 35 + int device_index; 36 + wxString path; 37 + int status; 38 + }; 39 + 40 + UsbDeviceInfo detectDevicesViaPatchers(); 41 + 42 + 43 + /******************************** 44 + * Windows code for USB Device detection and information 45 + **************************************/ 46 + 47 + #if defined( __WXMSW__ ) 48 + 49 + #include <dbt.h> // For DeviceChange. 50 + #include <winioctl.h> // For DeviceIOCtl. 51 + 52 + // IOCTL control code 53 + #define IOCTL_STORAGE_QUERY_PROPERTY CTL_CODE(IOCTL_STORAGE_BASE, 0x0500, METHOD_BUFFERED, FILE_ANY_ACCESS) 54 + 55 + //// The following structures all can find at MSDN. 56 + // enumeration type specifies the various types of storage buses 57 + typedef enum _STORAGE_BUS_TYPE { 58 + BusTypeUnknown = 0x00, 59 + BusTypeScsi, 60 + BusTypeAtapi, 61 + BusTypeAta, 62 + BusType1394, 63 + BusTypeSsa, 64 + BusTypeFibre, 65 + BusTypeUsb, 66 + BusTypeRAID, 67 + BusTypeMaxReserved = 0x7F 68 + } STORAGE_BUS_TYPE, *PSTORAGE_BUS_TYPE; 69 + // retrieve the storage device descriptor data for a device. 70 + typedef struct _STORAGE_DEVICE_DESCRIPTOR { 71 + ULONG Version; 72 + ULONG Size; 73 + UCHAR DeviceType; 74 + UCHAR DeviceTypeModifier; 75 + BOOLEAN RemovableMedia; 76 + BOOLEAN CommandQueueing; 77 + ULONG VendorIdOffset; 78 + ULONG ProductIdOffset; 79 + ULONG ProductRevisionOffset; 80 + ULONG SerialNumberOffset; 81 + STORAGE_BUS_TYPE BusType; 82 + ULONG RawPropertiesLength; 83 + UCHAR RawDeviceProperties[1]; 84 + 85 + } STORAGE_DEVICE_DESCRIPTOR, *PSTORAGE_DEVICE_DESCRIPTOR; 86 + // retrieve the properties of a storage device or adapter. 87 + typedef enum _STORAGE_QUERY_TYPE { 88 + PropertyStandardQuery = 0, 89 + PropertyExistsQuery, 90 + PropertyMaskQuery, 91 + PropertyQueryMaxDefined 92 + 93 + } STORAGE_QUERY_TYPE, *PSTORAGE_QUERY_TYPE; 94 + 95 + // retrieve the properties of a storage device or adapter. 96 + typedef enum _STORAGE_PROPERTY_ID { 97 + StorageDeviceProperty = 0, 98 + StorageAdapterProperty, 99 + StorageDeviceIdProperty 100 + 101 + } STORAGE_PROPERTY_ID, *PSTORAGE_PROPERTY_ID; 102 + // retrieve the properties of a storage device or adapter. 103 + typedef struct _STORAGE_PROPERTY_QUERY { 104 + STORAGE_PROPERTY_ID PropertyId; 105 + STORAGE_QUERY_TYPE QueryType; 106 + UCHAR AdditionalParameters[1]; 107 + 108 + } STORAGE_PROPERTY_QUERY, *PSTORAGE_PROPERTY_QUERY; 109 + 110 + 111 + wxString guess_mount_point(); 112 + 113 + BOOL GetDisksProperty(HANDLE hDevice, PSTORAGE_DEVICE_DESCRIPTOR pDevDesc); 114 + char chFirstDriveFromMask (ULONG unitmask); 115 + 116 + #endif /*__WXMSW__ */ 117 + 118 + 119 + /************************************************************************+ 120 + *Linux code for autodetection 121 + **************************************************************************/ 122 + 123 + 124 + #if !(defined( __WXMSW__ ) || defined( __DARWIN__)) 125 + 126 + wxString resolve_mount_point( const wxString device ); 127 + 128 + 129 + #endif /* Linux Code */ 130 + 131 + 132 + 133 + 134 + 135 + 136 + 137 + 138 + 139 + 140 + 141 + 142 + #endif
+20 -59
rbutil/rbutilCtrls.cpp
··· 1 1 2 2 #include "rbutilCtrls.h" 3 3 #include "bootloaders.h" 4 + #include "autodetection.h" 4 5 5 6 ///////////////////////////////////////////////////////////// 6 7 //// Controls ··· 435 436 AutoDetect(); 436 437 } 437 438 438 - #if !(defined( __WXMSW__ ) || defined( __DARWIN__)) 439 - wxString resolve_mount_point( const wxString device ) 440 - { 441 - FILE *fp = fopen( "/proc/mounts", "r" ); 442 - if( !fp ) return wxT(""); 443 - char *dev, *dir; 444 - while( fscanf( fp, "%as %as %*s %*s %*s %*s", &dev, &dir ) != EOF ) 445 - { 446 - if( wxString( dev, wxConvUTF8 ) == device ) 447 - { 448 - wxString directory = wxString( dir, wxConvUTF8 ); 449 - free( dev ); 450 - free( dir ); 451 - return directory; 452 - } 453 - free( dev ); 454 - free( dir ); 455 - } 456 - fclose( fp ); 457 - return wxT(""); 458 - } 459 - #endif 460 439 461 440 void DeviceSelectorCtrl::AutoDetect() 462 441 { 463 - struct ipod_t ipod; 464 - int n = ipod_scan(&ipod); 465 - if(n == 1) 466 - { 467 - wxString temp(ipod.targetname,wxConvUTF8); 468 - int index = gv->plat_bootloadername.Index(temp); // use the bootloader names.. 469 - m_deviceCbx->SetValue(gv->plat_name[index]); 470 - gv->curplat=gv->plat_id[index]; 442 + 471 443 472 - #if !(defined( __WXMSW__ ) || defined( __DARWIN__)) 473 - wxString tmp = resolve_mount_point(wxString(ipod.diskname,wxConvUTF8)+wxT("2")); 474 - if( tmp != wxT("") ) 475 - gv->curdestdir = tmp; 476 - #endif 477 - return; 478 - } 479 - else if (n > 1) 444 + UsbDeviceInfo device = detectDevicesViaPatchers(); 445 + 446 + if( device.status == NODEVICE) 480 447 { 481 - WARN_DIALOG(wxT("More then one Ipod device detected, please connect only One"), 448 + WARN_DIALOG(wxT("No Device detected. (This function currently only works for Ipods and Sansas)."), 482 449 wxT("Detecting a Device")); 483 450 return; 484 451 } 485 452 486 - struct sansa_t sansa; 487 - int n2 = sansa_scan(&sansa); 488 - if(n2==1) 453 + if( device.status == TOMANYDEVICES) 489 454 { 490 - int index = gv->plat_id.Index(wxT("sansae200")); 491 - m_deviceCbx->SetValue(gv->plat_name[index]); 492 - gv->curplat=gv->plat_id[index]; 455 + WARN_DIALOG(wxT("More then one device detected, please connect only One"), 456 + wxT("Detecting a Device")); 457 + return; 493 458 494 - #if !(defined( __WXMSW__ ) || defined( __DARWIN__)) 495 - wxString tmp = resolve_mount_point(wxString(sansa.diskname,wxConvUTF8)+wxT("1")); 496 - if( tmp != wxT("") ) 497 - gv->curdestdir = tmp; 498 - #endif 499 - return; 500 459 } 501 - else if (n2 > 1) 460 + 461 + if (device.status == 0 ) /* everything is ok */ 502 462 { 503 - WARN_DIALOG(wxT("More then one Sansa device detected, please connect only One"), 504 - wxT("Detecting a Device")); 505 - return; 463 + m_deviceCbx->SetValue(gv->plat_name[device.device_index]); 464 + gv->curplat=gv->plat_id[device.device_index]; 465 + 466 + if(device.path != wxT("")) 467 + { 468 + gv->curdestdir = device.path; 469 + } 470 + 506 471 } 507 - 508 - WARN_DIALOG(wxT("No Device detected. (This function currently only works for Ipods and Sansas)."), 509 - wxT("Detecting a Device")); 510 - return; 511 472 512 473 } 513 474
+7 -10
rbutil/rbutilFrm.cpp
··· 96 96 myDeviceSelector->setDefault(); 97 97 WxBoxSizer0->Add(myDeviceSelector,0,wxGROW|wxALL,5); 98 98 99 - 100 - 101 99 wxNotebook* tabwindow = new wxNotebook(mainPanel,wxID_ANY); 102 100 WxBoxSizer0->Add(tabwindow,1,wxGROW|wxALL,5); 103 101 ··· 130 128 wxBitmap BootloaderInstallButton (tools2_3d_xpm); 131 129 WxBitmapButton4 = new wxBitmapButton(installpage, ID_BOOTLOADER_BTN, 132 130 BootloaderInstallButton, wxPoint(0,0), wxSize(64,54), 133 - wxRAISED_BORDER | wxBU_AUTODRAW); 131 + wxRAISED_BORDER | wxBU_AUTODRAW, wxDefaultValidator,wxT("Bootloader Installation")); 134 132 WxBitmapButton4->SetToolTip(wxT("Click here to install the Rockbox bootloader")); 135 133 WxFlexGridSizer1->Add(WxBitmapButton4, 0, 136 134 wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL | wxALL,5); ··· 147 145 WxBitmapButton1 = new wxBitmapButton(installpage, ID_INSTALL_BTN, 148 146 WxBitmapButton1_BITMAP, wxPoint(0,0), wxSize(64,54), 149 147 wxRAISED_BORDER | wxBU_AUTODRAW, wxDefaultValidator, 150 - wxT("WxBitmapButton1")); 148 + wxT("Rockbox Installation")); 151 149 WxBitmapButton1->SetToolTip(wxT("Click here to install Rockbox")); 152 150 WxFlexGridSizer1->Add(WxBitmapButton1,0, 153 151 wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL | wxALL,5); ··· 177 175 wxBitmap FontInstallButton (fonts_3d_xpm); 178 176 WxBitmapButton3 = new wxBitmapButton(themepage, ID_FONT_BTN, 179 177 FontInstallButton, wxPoint(0,0), wxSize(64,54), 180 - wxRAISED_BORDER | wxBU_AUTODRAW); 178 + wxRAISED_BORDER | wxBU_AUTODRAW,wxDefaultValidator, wxT("Font installation")); 181 179 WxBitmapButton3->SetToolTip(wxT("Click here to install the most up to date " 182 180 "Rockbox fonts.")); 183 181 WxFlexGridSizer2->Add(WxBitmapButton3, 0, ··· 194 192 wxBitmap ThemesInstallButton (themes_3d_xpm); 195 193 WxBitmapButton5 = new wxBitmapButton(themepage, ID_THEMES_BTN, 196 194 ThemesInstallButton, wxPoint(0,0), wxSize(64,54), 197 - wxRAISED_BORDER | wxBU_AUTODRAW); 195 + wxRAISED_BORDER | wxBU_AUTODRAW,wxDefaultValidator, wxT("Theme installation")); 198 196 WxBitmapButton5->SetToolTip(wxT("Click here to install themes for Rockbox.")); 199 197 WxFlexGridSizer2->Add(WxBitmapButton5, 0, 200 198 wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL | wxALL,5); ··· 208 206 wxBitmap DoomInstallButton (doom_3d_xpm); 209 207 WxBitmapButton6 = new wxBitmapButton(themepage, ID_DOOM_BTN, 210 208 DoomInstallButton, wxPoint(0,0), wxSize(64,54), 211 - wxRAISED_BORDER | wxBU_AUTODRAW); 209 + wxRAISED_BORDER | wxBU_AUTODRAW,wxDefaultValidator, wxT("Freedoom installation")); 212 210 WxBitmapButton6->SetToolTip(wxT("Click here to install the freedoom wad files.")); 213 211 WxFlexGridSizer2->Add(WxBitmapButton6, 0, 214 212 wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL | wxALL,5); ··· 238 236 wxBitmap WxBitmapButton2_BITMAP (uninstall_3d_xpm); 239 237 WxBitmapButton2 = new wxBitmapButton(uninstallpage, ID_REMOVE_BTN, 240 238 WxBitmapButton2_BITMAP, wxPoint(0,0), wxSize(64,54), 241 - wxRAISED_BORDER | wxBU_AUTODRAW, wxDefaultValidator, 242 - wxT("WxBitmapButton2")); 239 + wxRAISED_BORDER | wxBU_AUTODRAW,wxDefaultValidator, wxT("Rockbox uninstallation")); 243 240 WxBitmapButton2->SetToolTip(wxT("Click here to uninstall Rockbox")); 244 241 WxFlexGridSizer3->Add(WxBitmapButton2,0, 245 242 wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL | wxALL,5); ··· 253 250 WxBitmapButton4 = new wxBitmapButton(uninstallpage, ID_BOOTLOADERREMOVE_BTN, 254 251 WxBitmapButton4_BITMAP, wxPoint(0,0), wxSize(64,54), 255 252 wxRAISED_BORDER | wxBU_AUTODRAW, wxDefaultValidator, 256 - wxT("WxBitmapButton4")); 253 + wxT("Bootloader uninstallation")); 257 254 WxBitmapButton4->SetToolTip(wxT("Click here to uninstall the Bootloader")); 258 255 WxFlexGridSizer3->Add(WxBitmapButton4,0, 259 256 wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL | wxALL,5);