// This does the same as GetVolumePathNamesForVolumeNameW() on Windows XP and // later. It is built into 32 bit versions of this library to make sure that // the DLL can load correctly on Windows 2000 as well. BOOL WINAPI ImScsiLegacyGetVolumePathNamesForVolumeName( __in LPCWSTR lpszVolumeName, __out LPWSTR lpszVolumePathNames, __in DWORD cchBufferLength, __out PDWORD lpcchReturnLength) { *lpcchReturnLength = 0; DWORD dw; dw; LPWSTR cur_ptr = lpszVolumePathNames; LPWSTR end_ptr = lpszVolumePathNames + cchBufferLength; WCHAR vol_target[MAX_PATH]; wcsncpy(vol_target, lpszVolumeName + 4, 44); vol_target[44] = 0; if (!QueryDosDevice(vol_target, vol_target, _countof(vol_target))) { return FALSE; } WHeapMem<WCHAR> dosdevs(UNICODE_STRING_MAX_BYTES, HEAP_GENERATE_EXCEPTIONS); if (!QueryDosDevice(NULL, dosdevs, (DWORD)dosdevs.Count())) { return FALSE; } DWORD good = cchBufferLength >= 2; *lpcchReturnLength = 2; WCHAR dev_target[MAX_PATH]; SIZE_T length; for (LPCWSTR ptr = dosdevs; (length = wcslen(ptr)) != 0; ptr += length + 1) { if (good) { *cur_ptr = 0; } if ((length != 2) || (ptr[1] != L':') || (!QueryDosDevice(ptr, dev_target, _countof(dev_target))) || (_wcsicmp(dev_target, vol_target) != 0)) { continue; } *lpcchReturnLength += 4; if ((cur_ptr + 4) >= end_ptr) { good = FALSE; } if (good) { swprintf(cur_ptr, L"%ws\\", ptr); cur_ptr += 4; } } WCHAR vol_name[50]; HANDLE volume = FindFirstVolume(vol_name, _countof(vol_name)); if (volume == INVALID_HANDLE_VALUE) { return FALSE; } DWORD error_mode = SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX); do { HANDLE vol_mnt = FindFirstVolumeMountPoint(vol_name, dosdevs, (DWORD)dosdevs.Count()); if (vol_mnt == INVALID_HANDLE_VALUE) { continue; } do { WMem<WCHAR> mnt_path; mnt_path = ImDiskAllocPrintF(L"%1!ws!%2!ws!", vol_name, dosdevs); if (!mnt_path) { continue; } WCHAR mnt_vol_name[50]; if (!GetVolumeNameForVolumeMountPoint(mnt_path, mnt_vol_name, _countof(mnt_vol_name))) { continue; } if (_wcsicmp(mnt_vol_name, lpszVolumeName) == 0) { if (ImScsiLegacyGetVolumePathNamesForVolumeName(vol_name, vol_target, _countof(vol_target), &dw)) { mnt_path = ImDiskAllocPrintF(L"%1!ws!%2!ws!", vol_target, dosdevs); } size_t len = wcslen(mnt_path) + 1; *lpcchReturnLength += (DWORD)len; if ((cur_ptr + len) >= end_ptr) { good = FALSE; } if (good) { wcscpy(cur_ptr, mnt_path); cur_ptr += len; } } } while (FindNextVolumeMountPoint(vol_mnt, dosdevs, (DWORD)dosdevs.Count())); FindVolumeMountPointClose(vol_mnt); } while (FindNextVolume(volume, vol_name, _countof(vol_name))); FindVolumeClose(volume); SetErrorMode(error_mode); if (cur_ptr >= end_ptr) { good = FALSE; } if (good) { *cur_ptr = 0; ++*lpcchReturnLength; } else { SetLastError(ERROR_MORE_DATA); } return good; }
void g_scan_drives (DWORD mask) { //pfc::hires_timer timer; //timer.start(); //profiler(scandrives); #if 0 { TCHAR volume[128], mount[512]; memset(volume, 0, sizeof(volume)); HANDLE vol = FindFirstVolume(volume, tabsize(volume)-1); if (vol != INVALID_HANDLE_VALUE) { do { console::formatter() << "Volume: " << pfc::stringcvt::string_utf8_from_wide(volume, 128); memset(mount, 0, sizeof(mount)); HANDLE hmount = FindFirstVolumeMountPoint(volume, mount, tabsize(mount)-1); if (hmount != INVALID_HANDLE_VALUE) { do { console::formatter() << "mountpoint: " << pfc::stringcvt::string_utf8_from_wide(mount, tabsize(mount)); memset(mount, 0, sizeof(mount)); } while (FindNextVolumeMountPoint(hmount, mount, tabsize(mount)-1) || GetLastError() != ERROR_NO_MORE_FILES); FindVolumeMountPointClose(hmount); } memset(volume, 0, sizeof(volume)); } while (FindNextVolume(vol, volume, tabsize(volume)-1) || GetLastError() != ERROR_NO_MORE_FILES); FindVolumeClose(vol); } } #endif if (mask) { t_volumes volumes; build_volumes_v2(volumes); t_size i =0; for (i=0; i<32; i++) { if (mask & 1<<i) { pfc::string8 drive; drive.add_byte('A'+i); pfc::array_t<WCHAR> path, itunesdb_path; path.append_single('A'+i); path.append_fromptr(L":\\", 3); { WCHAR volumename[129]; memset(volumename, 0, sizeof(volumename)); if (GetDriveType(path.get_ptr()) == DRIVE_REMOVABLE && GetVolumeNameForVolumeMountPoint(path.get_ptr(), volumename, 128)) { t_size indexvol; //if (volumes.find(volumename, 128, indexvol)) { //FIXME WTF if (volumes.find(volumename, 128, indexvol) /*&& g_check_devid_is_ipod(volumes[indexvol].disk_device_id)*/) { ipod_device_ptr_t temp = new ipod_device_t('A' + i, volumes[indexvol].model, volumes[indexvol].shuffle, volumes[indexvol].disk_device_id.get_ptr(), volumes[indexvol].volume_name.get_ptr(), volumes[indexvol].driver_symbolic_path.get_ptr(), volumes[indexvol].instance, device_properties_t()); pfc::string8 pl; try { g_get_device_xml(temp, pl); #if 0//_DEBUG { file::ptr f; abort_callback_dummy noabort; filesystem::g_open_read(f, "i:\\nano6g.plist", noabort); pfc::array_staticsize_t<char> d(pfc::downcast_guarded<t_uint32>(f->get_size_ex(noabort))); f->read(d.get_ptr(), d.get_size(), noabort); pl.set_string(d.get_ptr(), d.get_size()); } #endif g_get_artwork_info(pl, temp->m_device_properties); } catch (const pfc::exception & ex) { console::formatter() << "iPod manager: Failed to get iPod checkpoint data - " << ex.what() << ". Artwork functionality will be unavailable."; temp->m_device_properties.m_artwork_formats.remove_all(); }; //console::formatter() << "New iPod detected. Drive: " << drive << " Device Instance ID: " << pfc::stringcvt::string_utf8_from_wide(volumes[indexvol].disk_device_id); if (m_abort) g_drive_manager.add_drive(temp, *m_abort); else g_drive_manager.add_drive(temp, abort_callback_dummy()); } //else // console::formatter() << "New drive detected. Drive: " << drive << " Device Instance ID: " << pfc::stringcvt::string_utf8_from_wide(volumes[indexvol].disk_device_id);// << " Volume ID: " << pfc::stringcvt::string_utf8_from_wide(volumes[indexvol].volume_name); } } //else // console::formatter() << "Drive is not expected type or GetVolumeNameForVolumeMountPoint failed. Drive: " << drive; } } } } //console::formatter() << "old:" << timer.query(); }