/// <summary> /// Write to removable media from file /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ButtonWriteClick(object sender, EventArgs e) { if (comboBoxDrives.SelectedIndex < 0) { return; } var drive = (string)comboBoxDrives.SelectedItem; if (string.IsNullOrEmpty(textBoxFileName.Text)) { ChooseFile(); } if (((string)comboBoxDrives.SelectedItem).ToUpper().StartsWith("C:")) { var dr = MessageBox.Show( "C: is almost certainly your main hard drive. Writing to this will likely destroy your data, and brick your PC. Are you absolutely sure you want to do this?", "*** WARNING ***", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (dr != DialogResult.Yes) { return; } } DisableButtons(true); if (!File.Exists(textBoxFileName.Text)) { MessageBoxEx.Show("File does not exist!", "I/O Error", MessageBoxButtons.OK, MessageBoxIcon.Error); EnableButtons(); return; } var success = false; try { success = _disk.WriteDrive(drive, textBoxFileName.Text, _eCompType); } catch (Exception ex) { success = false; toolStripStatusLabel1.Text = ex.Message; } if (!success && !_disk.IsCancelling) { MessageBoxEx.Show("Problem writing to disk. Is it write-protected?", "Write Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } EnableButtons(); }
/// <summary> /// Write to removable media from file /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ButtonWriteClick(object sender, EventArgs e) { if (checkedListBoxDrives.CheckedItems.Count == 0) return; var drives = checkedListBoxDrives.CheckedItems.Cast<Object>().Select(d => d.ToString()).ToArray(); if (drives.Any(d => d.ToUpper().StartsWith("C:"))) { var dr = MessageBox.Show( Resources.MainForm_ButtonWriteClick_C__is_almost_certainly_your_main_HDD, Resources.MainForm_ButtonReadClick_____WARNING____, MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (dr != DialogResult.Yes) return; } ClearLayoutPanels(); if (ChooseFileToWrite() == false) return; var filePath = lastDirectoryUsed + "//" + lastFileUsed; if (!File.Exists(filePath)) { MessageBox.Show(Resources.MainForm_ButtonWriteClick_File_does_not_exist_, Resources.MainForm_ButtonWriteClick_I_O_Error, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } DisableButtons(true); Task.Factory.StartNew(() => { DiskAccesses.Clear(); _disks.Clear(); var tasks = drives.Select(drive => Task.Factory.StartNew(() => { var diskAccess = NewDiskAccess(); var disk = new Disk(diskAccess); Thread.CurrentThread.CurrentUICulture = CurrentLocale; SendProgressToUI(disk); DiskAccesses.Add(diskAccess); _disks.Add(disk); var res = false; try { res = disk.WriteDrive(drive, filePath, _eCompType, unmountDrivesToolStripMenuItem.Checked); } catch (Exception ex) { Invoke(new Action( () => MessageBox.Show(ex.Message, @"Exception at WriteDrive", MessageBoxButtons.OK, MessageBoxIcon.Error))); } if (!res && !disk.IsCancelling) { Invoke(new Action ( () => MessageBox.Show(Resources.MainForm_ButtonWriteClick_Problem_writing_to_disk__Is_it_write_protected_, Resources.MainForm_ButtonWriteClick_Write_Error, MessageBoxButtons.OK, MessageBoxIcon.Error))); } })).ToArray(); Task.WaitAll(tasks); Invoke((MethodInvoker)EndInfo); Invoke((MethodInvoker)EnableButtons); }); }
/// <summary> /// Write to removable media from file /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ButtonWriteClick(object sender, EventArgs e) { if (checkedListBoxDrives.CheckedItems.Count == 0) { return; } var drives = checkedListBoxDrives.CheckedItems.Cast <Object>().Select(d => d.ToString()).ToArray(); if (drives.Any(d => d.ToUpper().StartsWith("C:"))) { var dr = MessageBox.Show( Resources.MainForm_ButtonWriteClick_C__is_almost_certainly_your_main_HDD, Resources.MainForm_ButtonReadClick_____WARNING____, MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (dr != DialogResult.Yes) { return; } } ClearLayoutPanels(); if (ChooseFileToWrite() == false) { return; } var filePath = lastDirectoryUsed + "//" + lastFileUsed; if (!File.Exists(filePath)) { MessageBox.Show(Resources.MainForm_ButtonWriteClick_File_does_not_exist_, Resources.MainForm_ButtonWriteClick_I_O_Error, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } DisableButtons(true); Task.Factory.StartNew(() => { DiskAccesses.Clear(); _disks.Clear(); var tasks = drives.Select(drive => Task.Factory.StartNew(() => { var diskAccess = NewDiskAccess(); var disk = new Disk(diskAccess); Thread.CurrentThread.CurrentUICulture = CurrentLocale; SendProgressToUI(disk); DiskAccesses.Add(diskAccess); _disks.Add(disk); var res = false; try { res = disk.WriteDrive(drive, filePath, _eCompType, unmountDrivesToolStripMenuItem.Checked); } catch (Exception ex) { Invoke(new Action(() => MessageBox.Show(ex.Message, @"Exception at WriteDrive", MessageBoxButtons.OK, MessageBoxIcon.Error))); } if (!res && !disk.IsCancelling) { Invoke(new Action(() => MessageBox.Show(Resources.MainForm_ButtonWriteClick_Problem_writing_to_disk__Is_it_write_protected_, Resources.MainForm_ButtonWriteClick_Write_Error, MessageBoxButtons.OK, MessageBoxIcon.Error))); } })).ToArray(); Task.WaitAll(tasks); Invoke((MethodInvoker)EndInfo); Invoke((MethodInvoker)EnableButtons); }); }