private bool format_device(string drive_letter, string model_id, string file_system = "FAT", bool quick_format = false, int cluster_size = 2048) { bool bReturn = false; string err_message = ""; Application.Current.Dispatcher.Invoke(() => { prgbFormat.Visibility = Visibility.Visible; prgbUpgradeText.Text = string.Format("Formatting... "); prgbUpgrade.Maximum = 100; prgbUpgrade.Value = 0; }); try { DriveManager dm = new DriveManager(); dm.FormatUSBProgress += Dm_FormatUSBProgress; dm.FormatUSBCompleted += Dm_FormatUSBCompleted; bReturn = dm.FormatUSB(drive_letter, file_system, quick_format, cluster_size, model_id); /* * dm.FormatDriveCompleted += Dm_FormatUSBCompleted; * bReturn = dm.FormatDrive_CommandLine(drive_letter, model_id, file_system, quick_format, false, cluster_size); */ } catch (FormatException e) { err_message = e.Message; } catch (IOException e) { err_message = e.Message; } catch (Exception e) { err_message = e.Message; } if (err_message != "") { Application.Current.Dispatcher.Invoke(() => { prgbFormat.Visibility = Visibility.Hidden; prgbUpgradeText.Text = err_message; prgbUpgrade.Maximum = 100; prgbUpgrade.Value = 0; }); } return(bReturn); }
private bool format_device(string drive_letter) { bool bReturn = false; Application.Current.Dispatcher.Invoke(() => { prgbFormat.Visibility = Visibility.Visible; prgbUpgradeText.Text = string.Format("Formatting... "); prgbUpgrade.Maximum = 100; prgbUpgrade.Value = 0; }); try { DriveManager dm = new DriveManager(); // bReturn = dm.FormatDrive(char.Parse(drive_letter.Replace(":",""))); dm.FormatUSBProgress += Dm_FormatUSBProgress; dm.FormatUSBCompleted += Dm_FormatUSBCompleted; bReturn = dm.FormatUSB(drive_letter); } catch (FormatException e) { Application.Current.Dispatcher.Invoke(() => { prgbUpgradeText.Text = e.Message; prgbUpgrade.Maximum = 100; prgbUpgrade.Value = 0; }); } catch (IOException e) { Application.Current.Dispatcher.Invoke(() => { prgbUpgradeText.Text = e.Message; prgbUpgrade.Maximum = 100; prgbUpgrade.Value = 0; }); } catch (Exception e) { Application.Current.Dispatcher.Invoke(() => { prgbUpgradeText.Text = e.Message; prgbUpgrade.Maximum = 100; prgbUpgrade.Value = 0; }); } return(bReturn); }