public static String getVolumeGUID(ManagementObject obj) { String result = String.Empty; String mountPoint = String.Empty; // Try to ask WMI about Volume GUID first if (obj != null) { var deviceID = obj["DeviceID"].ToString(); if (!String.IsNullOrEmpty(deviceID)) { var match = PatternGUID.Match(deviceID); if (match.Success) { var guid = match.Groups[1].Value; result = String.Format("\\\\?\\Volume{{{0}}}", guid); } } mountPoint = obj["DriveLetter"].ToString(); } // If WMI has no information about volume GUID - use WinAPI method if (String.IsNullOrEmpty(result) && !String.IsNullOrEmpty(mountPoint)) { result = DiskManagement.getVolumeNameForVolumeMountPointWin32(mountPoint); } return(result); }
/// <summary> /// Check if currently selected disk is compatible with partial update /// </summary> /// <returns></returns> bool CheckPartialUpdateCompatible(String physicalDiskName, uint bytesPerSector) { bool result = false; //TODO: Remove Debug Logger.Info("CheckPartialUpdateCompatible()..."); try { result = DiskManagement.CheckDiskCompatible(physicalDiskName, bytesPerSector); } catch (Exception e) { Logger.Error("Unable to check card for MiSTer compatibility"); Logger.Error(e.Message); } isDiskUpdatable = result; // Update UI status if (isDiskUpdatable && isUpdatePackageValid) { buttonLinux.Enabled = true; } else { buttonLinux.Enabled = false; } //TODO: Remove Debug Logger.Info("done"); return(result); }
private void driveSelectionChanged(object sender, EventArgs e) { var idx = comboBoxDrives.SelectedIndex; var item = (ComboBoxItem)comboBoxDrives.SelectedItem; if (item != null && item.value.Length > 0) { var diskDescriptor = DiskManagement.getDiskDescriptor(item.value); // Remember current selection this.currentPhysicalDisk = diskDescriptor.physicalName; textDiskSize.Text = diskDescriptor.description; // Check if card eligible for update without disk layout changes CheckPartialUpdateCompatible(diskDescriptor.physicalName, diskDescriptor.bytesPerSector); if (isLayoutV1) { labelStatus.Text = @"Old disk layout. Full install is recommended"; } } else { textDiskSize.Text = String.Empty; } }
/// <summary> /// Load in the drives /// </summary> private void PopulateDrives() { if (InvokeRequired) { Invoke(new MethodInvoker(PopulateDrives)); return; } comboBoxDrives.SelectedIndex = -1; comboBoxDrives.Items.Clear(); ComboBoxItem selectedItem = null; try { var removableDisks = DiskManagement.getRemovableDisks(); foreach (var disk in removableDisks) { var item = new ComboBoxItem(disk.displayName, disk.physicalName); // If disk name matches previously used one - remember the item if (disk.physicalName.Equals(this.currentPhysicalDisk)) { selectedItem = item; } comboBoxDrives.Items.Add(item); } } catch { Logger.Error("Unable to get list of removable disks"); } // Restore item selection if (comboBoxDrives.Items.Count > 0) { if (selectedItem != null) { comboBoxDrives.SelectedItem = selectedItem; } else { comboBoxDrives.SelectedIndex = 0; } } else { textDiskSize.Text = String.Empty; } }
private void buttonFull_Click(object sender, EventArgs e) { var item = (ComboBoxItem)this.comboBoxDrives.SelectedItem; if (item != null && item.value.Length > 0) { var disk = DiskManagement.getDiskDescriptor(item.value); var message = string.Format("All data on '{0} - {1}' will be lost.\r\n Do you want to continue?", disk.displayName, disk.description); var confirmResult = MessageBox.Show(message, "Warning!", MessageBoxButtons.YesNo); if (confirmResult == DialogResult.Yes) { DiskOperationStarted(); // Run operation in a background worker thread BackgroundWorker worker = new BackgroundWorker(); worker.DoWork += delegate { bool result = DiskManagement.fullInstall(disk.physicalName); DiskOperationFinished(); if (IsCancelTriggered()) { message = string.Format("Full install for disk {0} was cancelled", disk.displayName); ShowMessageBoxTopmost(message, "Operation cancelled"); } else if (result) { message = string.Format("Full install for disk {0} finished successfully", disk.displayName); ShowMessageBoxTopmost(message, "Operation finished"); } else { message = string.Format("Unable to install on {0}", disk.displayName); ShowMessageBoxTopmost(message, "Operation failed"); } }; worker.RunWorkerCompleted += delegate { CheckPartialUpdateCompatible(disk.physicalName, disk.bytesPerSector); }; worker.RunWorkerAsync(); } } }
private void buttonUpdateAll_Click(object sender, EventArgs e) { var item = (ComboBoxItem)this.comboBoxDrives.SelectedItem; if (item != null && item.value.Length > 0) { var disk = DiskManagement.getDiskDescriptor(item.value); var message = string.Format("MiSTer bootloader, Linux and system files will be updated.\r\nUser data will remain untouched and safe\r\n Do you want to continue?", disk.displayName, disk.description); var confirmResult = MessageBox.Show(message, "Warning!", MessageBoxButtons.YesNo); if (confirmResult == DialogResult.Yes) { DiskOperationStarted(); BackgroundWorker worker = new BackgroundWorker(); worker.DoWork += delegate { bool result = DiskManagement.updateAll(disk.physicalName); DiskOperationFinished(); if (IsCancelTriggered()) { message = string.Format("System update on disk {0} was cancelled", disk.displayName); ShowMessageBoxTopmost(message, "Operation cancelled"); } else if (result) { message = string.Format("System update on disk {0} finished successfully", disk.displayName); ShowMessageBoxTopmost(message, "Operation finished"); } else { message = string.Format("Unable to update on {0}", disk.displayName); ShowMessageBoxTopmost(message, "Operation failed"); } }; worker.RunWorkerCompleted += delegate { CheckPartialUpdateCompatible(disk.physicalName, disk.bytesPerSector); }; worker.RunWorkerAsync(); } } }
private void buttonWipe_Click(object sender, EventArgs e) { var item = (ComboBoxItem)this.comboBoxDrives.SelectedItem; if (item != null && item.value.Length > 0) { var disk = DiskManagement.getDiskDescriptor(item.value); var message = string.Format("All data on '{0} - {1}' will be lost.\r\n Do you want to continue?", disk.displayName, disk.description); var confirmResult = MessageBox.Show(message, "Warning!", MessageBoxButtons.YesNo); if (confirmResult == DialogResult.Yes) { DiskOperationStarted(); BackgroundWorker worker = new BackgroundWorker(); worker.DoWork += delegate { if (DiskManagement.wipeDisk(disk.physicalName)) { SetProgress(100); message = string.Format("{0} wiped successfully", disk.displayName); ShowMessageBoxTopmost(message, "Operation finished"); } else { SetProgress(100); message = string.Format("Unable to wipe {0}", disk.displayName); ShowMessageBoxTopmost(message, "Operation failed"); } }; worker.RunWorkerCompleted += delegate { DiskOperationFinished(); CheckPartialUpdateCompatible(disk.physicalName, disk.bytesPerSector); }; worker.RunWorkerAsync(); } else { // If 'No', do something here. } } }
/// <summary> /// Check if currently selected disk is compatible with partial update /// </summary> /// <returns></returns> bool CheckPartialUpdateCompatible(String physicalDiskName, uint bytesPerSector) { bool result = false; isDiskUpdatable = false; isLayoutV1 = false; //TODO: Remove Debug Logger.Info("CheckPartialUpdateCompatible()..."); try { DiskLayoutType type = DiskManagement.GetDiskLayoutScheme(physicalDiskName, bytesPerSector); isDiskUpdatable = (type != DiskLayoutType.Unknown); isLayoutV1 = (type == DiskLayoutType.LayoutV1); result = isDiskUpdatable; } catch (Exception e) { Logger.Error("Unable to check card for MiSTer compatibility"); Logger.Error(e.Message); } // Update UI status if (isDiskUpdatable && isUpdatePackageValid) { buttonUpdateBoot.Enabled = true; } else { buttonUpdateBoot.Enabled = false; } //TODO: Remove Debug Logger.Info("done"); return(result); }
private void driveSelectionChanged(object sender, EventArgs e) { var idx = comboBoxDrives.SelectedIndex; var item = (ComboBoxItem)comboBoxDrives.SelectedItem; if (item != null && item.value.Length > 0) { var diskDescriptor = DiskManagement.getDiskDescriptor(item.value); // Remember current selection this.currentPhysicalDisk = diskDescriptor.physicalName; textDiskSize.Text = diskDescriptor.description; // Check drive CheckPartialUpdateCompatible(diskDescriptor.physicalName, diskDescriptor.bytesPerSector); } else { textDiskSize.Text = String.Empty; } }