public DownloadingDriverModel(string operation, DeviceInfo device) { Operation = operation; Device = device; }
void ShowDriverInfo(DeviceInfo device) { Window mainWnd = Application.Current.MainWindow; DriverDetailInfoPopup driverInfoDetailPopup = new DriverDetailInfoPopup { Owner = mainWnd }; driverInfoDetailPopup.DriverName.Text = device.DeviceName; if (!string.IsNullOrEmpty(device.InstalledDriverDate)) driverInfoDetailPopup.DetailCurrentDriverDate.Text = device.InstalledDriverDate.ToString(); if (!string.IsNullOrEmpty(device.NewDriverDate)) driverInfoDetailPopup.DetailNewDriverDate.Text = device.NewDriverDate.ToString(); driverInfoDetailPopup.Left = mainWnd.Left + (mainWnd.Width / 2 - driverInfoDetailPopup.Width / 2); int regToolsHeight = (int)driverInfoDetailPopup.Height; driverInfoDetailPopup.Height = 0; int topStart = (int)(mainWnd.Top + mainWnd.Height) + 30; driverInfoDetailPopup.Top = topStart; int topFinal = (int)(mainWnd.Top + (mainWnd.Height / 2 - regToolsHeight / 2)); const int fullAnimationDuration = 50; int heightAnimationDuration = (fullAnimationDuration * regToolsHeight / (topStart - topFinal)); DoubleAnimation slideUp = new DoubleAnimation { From = topStart, To = topFinal, Duration = new Duration(TimeSpan.FromMilliseconds(fullAnimationDuration)) }; driverInfoDetailPopup.BeginAnimation(Window.TopProperty, slideUp); DoubleAnimation scaleUp = new DoubleAnimation { From = 0, To = regToolsHeight, Duration = new Duration(TimeSpan.FromMilliseconds(heightAnimationDuration)) }; driverInfoDetailPopup.BeginAnimation(Window.HeightProperty, scaleUp); driverInfoDetailPopup.AnimateInnerBox(); driverInfoDetailPopup.ShowDialog(); }
/// <summary>- /// receives the progress of driver scan /// </summary> /// <param name="progressType"></param> /// <param name="data"></param> /// <param name="currentItemPos"></param> /// <param name="nTotalDriversToScan"></param> /// <param name="progress"></param> /// <returns></returns> public bool progressCallback(DUSDKHandler.PROGRESS_TYPE progressType, IntPtr data, int currentItemPos, int nTotalDriversToScan, int progress) { // here we will get the progress of driver scan. DriverData? dd = null; string category = string.Empty; string VersionInstalled = string.Empty; string VersionUpdated = string.Empty; DateTime dtInstalled; if (data != IntPtr.Zero) { dd = (DriverData)Marshal.PtrToStructure( (IntPtr)(data.ToInt64() + currentItemPos * Marshal.SizeOf(typeof(DriverData))), typeof(DriverData) ); } switch (progressType) { case DUSDKHandler.PROGRESS_TYPE.PROGRESS_SIZE_SCAN_DATA: nTotalDrivers = nTotalDriversToScan; driverData = new DriverData[nTotalDriversToScan]; UserUpdates = new Dictionary<int, DriverData>(); break; case DUSDKHandler.PROGRESS_TYPE.PROGRESS_SCANNING: if (data != IntPtr.Zero && !bIsStopped) { driverData[currentItemPos] = (DriverData)dd; string infName = string.Empty; try { infName = new FileInfo(driverData[currentItemPos].location).Name; } catch { } DeviceInfo item = new DeviceInfo( null, driverData[currentItemPos].category, driverData[currentItemPos].driverName, infName, string.IsNullOrEmpty(driverData[currentItemPos].version) || driverData[currentItemPos].version == "null" ? string.Empty : driverData[currentItemPos].version, currentItemPos.ToString(), driverData[currentItemPos].hardwareId, driverData[currentItemPos].CompatibleIdIndex.ToString() ); dtInstalled = DateTime.FromFileTime(driverData[currentItemPos].ulDateTimeQuadPart); item.InstalledDriverDate = dtInstalled.ToShortDateString(); string driverName = driverData[currentItemPos].driverName; if (driverName.Length > 46) driverName = driverName.Substring(0, 43) + "..."; if (CurrentDispatcher.Thread != null) { CurrentDispatcher.Invoke((MethodInvoker)delegate { ScanStatusText = driverName; var excludedDevice = ExcludedDevices.FirstOrDefault(d => d.Id == item.Id); if (excludedDevice != null) { item.IsExcluded = excludedDevice.IsExcluded; } if (!item.IsExcluded) { DevicesForScanning.Add(item); } AllDevices.Add(item); } , null); } } break; case DUSDKHandler.PROGRESS_TYPE.PROGRESS_RETRIEVING_UPDATES_DATA: if (CurrentDispatcher.Thread != null) { CurrentDispatcher.Invoke((MethodInvoker)delegate { ScanStatusText = string.Empty; ScanStatusTitle = WPFLocalizeExtensionHelpers.GetUIString("ContactingServer"); }, null); } break; //case DUSDKHandler.PROGRESS_TYPE.PROGRESS_RETRIEVING_UPDATES_FAILED_INET: // break; case DUSDKHandler.PROGRESS_TYPE.PROGRESS_FILTERING_UPDATES: if (data != IntPtr.Zero && !bIsStopped) { // get driver update information DriverData DriverUpdate = (DriverData)Marshal.PtrToStructure( (IntPtr)(data.ToInt64() + currentItemPos * Marshal.SizeOf(typeof(DriverData))), typeof(DriverData) ); if (CurrentDispatcher.Thread != null) { CurrentDispatcher.Invoke((MethodInvoker)delegate { DeviceInfo deviceInfo = DevicesForScanning.Where(wh => wh.Id == currentItemPos.ToString()).FirstOrDefault(); if (deviceInfo != null) { deviceInfo.NeedsUpdate = true; deviceInfo.SelectedForUpdate = true; deviceInfo.NewDriverDate = DateTime.FromFileTime(DriverUpdate.ulDateTimeQuadPart).ToShortDateString(); deviceInfo.DownloadLink = DriverUpdate.libURL; deviceInfo.InstallCommand = DriverUpdate.SetupLaunchParam; } UserUpdates.Add(currentItemPos, DriverUpdate); } , null); } } break; case DUSDKHandler.PROGRESS_TYPE.PROGRESS_SCANNED: //if (CurrentDispatcher.Thread != null) //{ // CurrentDispatcher.BeginInvoke((Action)(() => // { // ScanStatusTitle = WPFLocalizeExtensionHelpers.GetUIString("ScanCompleted"); // ScanStatusText = ""; // })); //} break; case DUSDKHandler.PROGRESS_TYPE.PROGRESS_UPDATE_STARTED_FOR_SINGLE: { if (data != IntPtr.Zero && dd.HasValue) { if (CurrentDispatcher.Thread != null) { CurrentDispatcher.BeginInvoke((Action)(() => { DownloadedDrivers.Add(new DownloadingDriverModel(WPFLocalizeExtensionHelpers.GetUIString("InstallingDriver"), devicesForUpdate[currentItemPos])); ScanStatusTitle = WPFLocalizeExtensionHelpers.GetUIString("InstallingDriver"); ScanStatusText = devicesForUpdate[currentItemPos].DeviceName; //Progress = 0; })); } } } break; case DUSDKHandler.PROGRESS_TYPE.PROGRESS_UPDATE_END_FOR_SINGLE: { if (data != IntPtr.Zero && dd.HasValue) { if (CurrentDispatcher.Thread != null) { CurrentDispatcher.BeginInvoke((Action)(() => { //ScanStatusTitle = ScanStatusText = WPFLocalizeExtensionHelpers.GetUIString("UpdateCompleted") + " " + ((DriverData)dd).driverName; })); } } } break; case DUSDKHandler.PROGRESS_TYPE.PROGRESS_UPDATE_SUCCESSFUL: { } break; case DUSDKHandler.PROGRESS_TYPE.PROGRESS_UPDATE_FAILED: { if (data != IntPtr.Zero && dd.HasValue) { string driverName = ((DriverData)dd).driverName; if (driverName.Length > 37) driverName = driverName.Substring(0, 34) + "..."; if (CurrentDispatcher.Thread != null) { CurrentDispatcher.BeginInvoke((Action)(() => { ScanStatusTitle = WPFLocalizeExtensionHelpers.GetUIString("UpdateFailed") + " " + driverName; ScanStatusText = string.Empty; })); } } } break; case DUSDKHandler.PROGRESS_TYPE.PROGRESS_DOWNLOAD_STARTED_FOR_SINGLE: { if (data != IntPtr.Zero && dd.HasValue) { string driverName = ((DriverData)dd).driverName; if (driverName.Length > 23) driverName = driverName.Substring(0, 20) + "..."; if (CurrentDispatcher.Thread != null) { CurrentDispatcher.BeginInvoke((Action)(() => { DownloadedDrivers.Add(new DownloadingDriverModel(WPFLocalizeExtensionHelpers.GetUIString("DownloadingDriver"), devicesForUpdate[currentItemPos])); ScanStatusTitle = WPFLocalizeExtensionHelpers.GetUIString("DownloadingDriver"); ScanStatusText = driverName;// ((DriverData)dd).driverName; })); } } } break; case DUSDKHandler.PROGRESS_TYPE.PROGRESS_DOWNLOAD_END_FOR_SINGLE: { if (data != IntPtr.Zero && dd.HasValue) { if (CurrentDispatcher.Thread != null) { CurrentDispatcher.BeginInvoke((Action)(() => { ScanStatusTitle = WPFLocalizeExtensionHelpers.GetUIString("DownloadComplete") + " " + ((DriverData)dd).driverName; ScanStatusText = string.Empty; })); } } } break; case DUSDKHandler.PROGRESS_TYPE.PROGRESS_DOWNLOAD_END_FOR_SINGLE_UNREG: { // download failed as user is unregistered } break; case DUSDKHandler.PROGRESS_TYPE.PROGRESS_DOWNLOAD_END_FOR_SINGLE_INET_ERROR: { // download failed because of Internet Error } break; default: break; } if (progress > 0) { if (CurrentDispatcher.Thread != null) { CurrentDispatcher.BeginInvoke((Action)(() => { Progress = progress; })); } } return true; }
void RunInitialScan() { var devices = driverUtils.ScanDevices(); AllDevices = new ObservableCollection<DeviceInfo>(); object ClassGuid; foreach (ManagementObject device in devices) { if (DriverUtils.RestrictedClasses.Contains(device.GetPropertyValue("DeviceClass"))) continue; //Uses device friendly name instead of device name when it's possible string deviceName = ""; if (device.GetPropertyValue("FriendlyName") != null) { deviceName = (string)device.GetPropertyValue("FriendlyName"); } else { deviceName = (string)(device.GetPropertyValue("DeviceName")); } //Uses device friendly name instead of class name when it's possible string deviceClassName = ""; if (device.GetPropertyValue("ClassGuid") != null) { var openSubKey = deviceClasses.OpenSubKey((string)device.GetPropertyValue("ClassGuid")); if (openSubKey != null) { ClassGuid = openSubKey.GetValue(null); if (ClassGuid != null) { deviceClassName = ClassGuid.ToString(); } } } else { deviceClassName = (string)(device.GetPropertyValue("DeviceClass")); } var item = new DeviceInfo( (string)(device.GetPropertyValue("DeviceClass")), deviceClassName, deviceName, (string)(device.GetPropertyValue("InfName")), (string)(device.GetPropertyValue("DriverVersion")), (string)(device.GetPropertyValue("DeviceId")), (string)(device.GetPropertyValue("HardwareID")), (string)(device.GetPropertyValue("CompatID")) ); AllDevices.Add(item); } }