예제 #1
0
        private void BrowseForImage_Click(object sender, RoutedEventArgs e)
        {
            var formats = DiskImageFactory.GetAllSupportedFormats();

            var filter = new StringBuilder();

            filter.Append("All Supported Images Types|");
            filter.Append(string.Join(";", formats.Select(f => "*" + f.Extension)));
            foreach (var format in formats)
            {
                filter.Append('|');
                filter.Append(format.Name);
                filter.Append('|');
                filter.Append("*" + format.Extension);
            }

            var dlg = new OpenFileDialog();

            dlg.Title  = "Open Disk Image";
            dlg.Filter = filter.ToString();
            if (dlg.ShowDialog() == true)
            {
                txtImagePath.Text = dlg.FileName;
            }
        }
예제 #2
0
        private async void WriteImage_Click(object sender, RoutedEventArgs e)
        {
            string imagePath = txtImagePath.Text;
            Disk   disk      = (Disk)cmbDisk.SelectedItem;

            if (!File.Exists(imagePath))
            {
                MessageBox.Show(this, "Disk image file does not exist.");
                return;
            }

            if (disk == null)
            {
                MessageBox.Show(this, "No disk was selected.");
                return;
            }

            var confirmMessage = new StringBuilder();

            confirmMessage.AppendLine("Are you sure you want to OVERWRITE and DESTROY all data on:");
            confirmMessage.AppendLine(disk.Name);
            confirmMessage.AppendLine("With the contents of:");
            confirmMessage.AppendLine(imagePath);

            if (MessageBoxResult.Yes != MessageBox.Show(this, confirmMessage.ToString(), "Confirm", MessageBoxButton.YesNo, MessageBoxImage.Warning, defaultResult: MessageBoxResult.No))
            {
                return;
            }

            prog.Value = 0;

            mWritingImage  = true;
            this.IsEnabled = false;

            try
            {
                mTaskbarManager?.SetProgressState(TaskbarProgressBarState.Normal);
                using (var diskImage = DiskImageFactory.Create(imagePath))
                {
                    await DiskImageWriter.WriteImageToDisk(disk, diskImage, new Progress <int>(onProgress));
                }
                MessageBox.Show(this, "Image writing complete!");
            }
            catch (PartitionInformationMissingException)
            {
                var sb = new StringBuilder();
                sb.AppendLine("No partitioning information was found in in this disk image.");
                sb.AppendLine("If this is an ISO image, such as a Windows install disc image,");
                sb.AppendLine("please try using Rufus instead.");
                sb.AppendLine();
                sb.Append("Would you like to navigate to the Rufus web site?");
                var result = MessageBox.Show(this, sb.ToString(), this.Title, MessageBoxButton.YesNo, MessageBoxImage.Question);
                if (result == MessageBoxResult.Yes)
                {
                    Process.Start("https://rufus.ie/");
                }
            }
            catch (Exception ex)
            {
                mTaskbarManager?.SetProgressState(TaskbarProgressBarState.Error);
                MessageBox.Show(this, "Failed to write image: " + ex.Message);
            }
            finally
            {
                mWritingImage           = false;
                mShouldWiggleOnDiskLoad = false;
                mTaskbarManager?.SetProgressState(TaskbarProgressBarState.NoProgress);
                this.IsEnabled = true;
                QueueDiskLoading();
            }
        }