コード例 #1
0
        private void BtnCreateISO_OnClick(object sender, RoutedEventArgs e)
        {
            if (btnCreateISO.Label == Localization.GetString("FrmISOMaker", 6))
            {
                if (lblDirectory.Content.ToString().Equals(Localization.GetString("FrmISOMaker", 10)))
                {
                    MessageBox.Show(Localization.GetString("FrmISOMaker", 10), "");
                    return;
                }

                if (lblISO.Content.ToString().Equals(Localization.GetString("FrmISOMaker", 9)))
                {
                    MessageBox.Show(Localization.GetString("FrmISOMaker", 9), "");
                    return;
                }

                var directory = new DirectoryInfo(lblDirectory.Content.ToString());
                var files     = directory.GetFiles("*", SearchOption.AllDirectories);

                var filtered = files.Select(f => f)
                               .Where(f => (f.Attributes & FileAttributes.Directory) != FileAttributes.Directory);

                if (!filtered.Any())
                {
                    MessageBox.Show(Localization.GetString("FrmISOMaker", 21), Localization.GetString("Global", 68));
                    return;
                }

                var timer = new ElapsedTimer(ref txtTime);

                timer.Start();
                Enable(false);
                cancel         = false;
                lblStatus.Text = Localization.GetString("FrmISOMaker", 18) + "...";

                btnCreateISO.Label = Localization.GetString("Global", 66);
                var folder  = lblDirectory.Content.ToString();
                var isoPath = lblISO.Content.ToString();
                iso = new ISO(folder, isoPath, txtLabel.Text);
                iso.ProgressChanged += iso_ProgressChanged;
                try
                {
                    iso.CreateISO();

                    if (cancel)
                    {
                        pbProgress.Foreground = Brushes.Gold;
                        DeleteISO();
                        lblStatus.Text = Localization.GetString("FrmISOMaker", 20);
                    }
                    else
                    {
                        lblStatus.Text = Localization.GetString("FrmISOMaker", 19);
                    }
                }
                catch (Exception Ex)
                {
                    DeleteISO();
                    lblStatus.Text        = Localization.GetString("Global", 67) + ": " + Ex.Message;
                    pbProgress.Foreground = Brushes.Red;
                }
                timer.Stop();

                Enable(true);
                btnCreateISO.Label     = Localization.GetString("FrmISOMaker", 6);
                btnCreateISO.IsEnabled = true;
            }
            else
            {
                cancel = true;
                pbProgress.Foreground  = Brushes.Gold;
                btnCreateISO.IsEnabled = false;
                iso.Cancel();
            }
        }