예제 #1
0
        private void EraseStart_Click(object sender, RoutedEventArgs e)
        {
            CancelButton.IsEnabled     = false;
            EraseStartButton.IsEnabled = false;
            eraseProgress.IsEnabled    = true;
            checkQuickErase.IsEnabled  = false;
            String driveId = (String)Application.Current.Properties["driveId"];

            eraseStatusText.Text = Properties.Resources.MediaErase_Erasing;

            ThreadStart start = delegate()
            {
                IDiscRecorder2 recorder = new MsftDiscRecorder2();
                recorder.InitializeDiscRecorder(driveId);
                recorder.AcquireExclusiveAccess(true, "imapi_erase_test");
                IDiscFormat2Erase discErase = new MsftDiscFormat2Erase();

                discErase.Recorder   = recorder;
                discErase.ClientName = "imapi_erase_test";

                try
                {
                    discErase.FullErase = (bool)checkQuickErase.IsChecked;
                }
                catch (System.InvalidOperationException)
                {
                    discErase.FullErase = false;
                }

                DiscFormat2Erase_Events eraseEvent = discErase as DiscFormat2Erase_Events; //DiscFormat2Data_Events burnProgress = dataWriterImage as DiscFormat2Data_Events;
                if (discErase.FullErase)
                {
                    eraseEvent.Update += new DiscFormat2Erase_EventsHandler(OnEraseProgress);
                }

                try{
                    discErase.EraseMedia();
                }
                catch
                {
                    //this.DialogResult = true;
                }

                if (discErase.FullErase)
                {
                    eraseEvent.Update -= new DiscFormat2Erase_EventsHandler(OnEraseProgress);
                }
                recorder.ReleaseExclusiveAccess();
                Dispatcher.Invoke(new System.EventHandler(OnEraseFinished), this, null);
            };

            Thread thread = new Thread(start);

            thread.IsBackground = true;
            thread.Start();
        }
예제 #2
0
        /// <summary>
        /// Worker thread that Formats the Disc
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void backgroundFormatWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            //
            // Create and initialize the IDiscRecorder2
            //
            MsftDiscRecorder2 discRecorder       = new MsftDiscRecorder2();
            string            activeDiscRecorder = (string)e.Argument;

            discRecorder.InitializeDiscRecorder(activeDiscRecorder);
            discRecorder.AcquireExclusiveAccess(true, m_clientName);

            //
            // Create the IDiscFormat2Erase and set properties
            //
            MsftDiscFormat2Erase discFormatErase = new MsftDiscFormat2Erase();

            discFormatErase.Recorder   = discRecorder;
            discFormatErase.ClientName = m_clientName;
            discFormatErase.FullErase  = !checkBoxQuickFormat.Checked;

            //
            // Setup the Update progress event handler
            //
            discFormatErase.Update += new DiscFormat2Erase_EventHandler(discFormatErase_Update);

            //
            // Erase the media here
            //
            try
            {
                discFormatErase.EraseMedia();
                e.Result = 0;
            }
            catch (COMException ex)
            {
                e.Result = ex.ErrorCode;
                MessageBox.Show(ex.Message, "IDiscFormat2.EraseMedia failed",
                                MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }

            //
            // Remove the Update progress event handler
            //
            discFormatErase.Update -= new DiscFormat2Erase_EventHandler(discFormatErase_Update);

            if (checkBoxEjectFormat.Checked)
            {
                discRecorder.EjectMedia();
            }

            discRecorder.ReleaseExclusiveAccess();
        }
예제 #3
0
        private int DoFormat(string activeDiscRecorder)
        {
            MsftDiscRecorder2 discRecorder = null;
            MsftDiscFormat2Erase discFormatErase = null;
            int result = 0;

            try
            {
                discRecorder = new MsftDiscRecorder2();
                discRecorder.InitializeDiscRecorder(activeDiscRecorder);

                discFormatErase = new MsftDiscFormat2Erase
                {
                    Recorder = discRecorder,
                    ClientName = "clientName",
                    FullErase = !quickFormat
                };

                discFormatErase.Update += discFormatErase_Update;

                try
                {
                    discFormatErase.EraseMedia();
                }
                catch (COMException ex)
                {
                    result = ex.ErrorCode;
                    MessageBox.Show(ex.Message, "IDiscFormat2.EraseMedia failed",
                        MessageBoxButton.OK, MessageBoxImage.Stop);
                }

                discFormatErase.Update -= discFormatErase_Update;

                if (ejectDisc)
                    discRecorder.EjectMedia();
            }
            catch (COMException exception)
            {
                MessageBox.Show(exception.Message);
            }
            finally
            {
                if (discRecorder != null)
                    Marshal.ReleaseComObject(discRecorder);

                if (discFormatErase != null)
                    Marshal.ReleaseComObject(discFormatErase);
            }

            return result;
        }
예제 #4
0
        public void FormatMedia(bool quick, bool eject)
        {
            if (!_mediaLoaded)
            {
                throw new InvalidOperationException("LoadMedia must be called first.");
            }

            MsftDiscRecorder2    recorder        = null;
            MsftDiscFormat2Erase discFormatErase = null;

            try
            {
                recorder = new MsftDiscRecorder2();
                recorder.InitializeDiscRecorder(_recorders.SelectedItem.InternalUniqueId);
                discFormatErase = new MsftDiscFormat2Erase
                {
                    Recorder   = recorder,
                    ClientName = ImageMaster.ClientName,
                    FullErase  = !quick
                };

                discFormatErase.Update += _discFormatErase_Update;
                discFormatErase.EraseMedia();

                if (eject)
                {
                    recorder.EjectMedia();
                }
            }
            finally
            {
                if (discFormatErase != null)
                {
                    Marshal.ReleaseComObject(discFormatErase);
                }
                if (recorder != null)
                {
                    Marshal.ReleaseComObject(recorder);
                }
            }
        }
예제 #5
0
        /// Worker thread that Formats the Disc
        private void BackgroundFormatWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            MsftDiscRecorder2    discRecorder    = null;
            MsftDiscFormat2Erase discFormatErase = null;

            try
            {
                //
                // Create and initialize the IDiscRecorder2
                //
                discRecorder = new MsftDiscRecorder2();
                var activeDiscRecorder = (string)e.Argument;
                discRecorder.InitializeDiscRecorder(activeDiscRecorder);

                //
                // Create the IDiscFormat2Erase and set properties
                //
                discFormatErase = new MsftDiscFormat2Erase
                {
                    Recorder   = discRecorder,
                    ClientName = ClientName,
                    FullErase  = !checkBoxQuickFormat.Checked
                };

                //
                // Setup the Update progress event handler
                //
                discFormatErase.Update += DiscFormatErase_Update;

                //
                // Erase the media here
                //
                try
                {
                    discFormatErase.EraseMedia();
                    e.Result = 0;
                }
                catch (COMException ex)
                {
                    e.Result = ex.ErrorCode;
                    MessageBox.Show(ex.Message, "IDiscFormat2.EraseMedia failed",
                                    MessageBoxButtons.OK, MessageBoxIcon.Stop);
                }

                //
                // Remove the Update progress event handler
                //
                discFormatErase.Update -= DiscFormatErase_Update;

                //
                // Eject the media
                //
                if (checkBoxEjectFormat.Checked)
                {
                    discRecorder.EjectMedia();
                }
            }
            catch (COMException exception)
            {
                //
                // If anything happens during the format, show the message
                //
                MessageBox.Show(exception.Message);
            }
            finally
            {
                if (discRecorder != null)
                {
                    Marshal.ReleaseComObject(discRecorder);
                }

                if (discFormatErase != null)
                {
                    Marshal.ReleaseComObject(discFormatErase);
                }
            }
        }
예제 #6
0
        /// <summary>
        /// 擦除光碟中数据
        /// </summary>
        private void DoEreaseDisc()
        {
            if (SelectedMediaWriter == null)
            {
                return;
            }

            MsftDiscFormat2Erase discFormatErase = null;

            try
            {
                //
                // Create the IDiscFormat2Erase and set properties
                //
                discFormatErase = new MsftDiscFormat2Erase
                {
                    Recorder   = SelectedMediaWriter,
                    ClientName = "ApplicationName",
                    FullErase  = true
                };

                if (discFormatErase.IsCurrentMediaSupported(SelectedMediaWriter))
                {
                    this.Host.ShowMessageBox("没有光碟", MessageBoxActions.Ok);
                    return;
                }

                //
                // Setup the Update progress event handler
                //
                discFormatErase.Update += discFormatErase_Update;
                //
                // Erase the media here
                //
                discFormatErase.EraseMedia();
                //
                // Remove the Update progress event handler
                //
                discFormatErase.Update -= discFormatErase_Update;
                //
                // Eject the media
                //
                if (EjectOnCompleted)
                {
                    SelectedMediaWriter.EjectMedia();
                }
            }
            catch (COMException exception)
            {
                //
                // If anything happens during the format, show the message
                //
                this.Host.ShowMessageBox(ImapiReturnValues.GetName(exception.ErrorCode), MessageBoxActions.Ok);
            }
            finally
            {
                if (discFormatErase != null)
                {
                    Marshal.ReleaseComObject(discFormatErase);
                }
            }
        }
예제 #7
0
        /// <summary>
        /// Worker thread that Formats the Disc
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void backgroundFormatWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            MsftDiscRecorder2    discRecorder    = null;
            MsftDiscFormat2Erase discFormatErase = null;
            BurnerMsg            burnerMsg       = new BurnerMsg(this);

            try
            {
                //
                // Create and initialize the IDiscRecorder2
                //
                discRecorder = new MsftDiscRecorder2();
                var activeDiscRecorder = (string)e.Argument;
                discRecorder.InitializeDiscRecorder(activeDiscRecorder);

                //
                // Create the IDiscFormat2Erase and set properties
                //
                discFormatErase = new MsftDiscFormat2Erase
                {
                    Recorder   = discRecorder,
                    ClientName = ClientName,
                    FullErase  = !quickFormat
                };

                //
                // Setup the Update progress event handler
                //
                discFormatErase.Update += discFormatErase_Update;

                //
                // Erase the media here
                //
                try
                {
                    discFormatErase.EraseMedia();
                    e.Result = 0;
                }
                catch (COMException ex)
                {
                    e.Result = ex.ErrorCode;
                    System.Diagnostics.Trace.WriteLine("IDiscFormat2.EraseMedia failed " + ex.Message);
                    burnerMsg.fase = Fase.FormattazioneFallita;
                    OnInviaStatoMasterizzazione(burnerMsg);
                }

                //
                // Remove the Update progress event handler
                //
                discFormatErase.Update -= discFormatErase_Update;

                //
                // Eject the media
                //
                if (ejectMedia)
                {
                    discRecorder.EjectMedia();
                }
                burnerMsg.fase = Fase.FormattazioneCompletata;
                OnInviaStatoMasterizzazione(burnerMsg);
            }
            catch (COMException exception)
            {
                //
                // If anything happens during the format, show the message
                //
                System.Diagnostics.Trace.WriteLine(exception.Message);
                burnerMsg.fase = Fase.FormattazioneFallita;
                OnInviaStatoMasterizzazione(burnerMsg);
            }
            finally
            {
                if (discRecorder != null)
                {
                    Marshal.ReleaseComObject(discRecorder);
                }

                if (discFormatErase != null)
                {
                    Marshal.ReleaseComObject(discFormatErase);
                }
            }
        }
예제 #8
0
        private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            MsftDiscRecorder2    Recorder   = null;
            MsftDiscFormat2Erase Format     = null;
            MsftFileSystemImage  fileSystem = null;

            try
            {
                Recorder = new MsftDiscRecorder2();
                string activeDiscRecorder = (string)e.Argument;
                Recorder.InitializeDiscRecorder(activeDiscRecorder);
                Recorder.AcquireExclusiveAccess(true, namaProgram);

                fileSystem            = new MsftFileSystemImage();
                fileSystem.VolumeName = "";

                Format            = new MsftDiscFormat2Erase();
                Format.Recorder   = Recorder;
                Format.ClientName = namaProgram;
                Format.FullErase  = checkBoxFormatCepat.Checked;

                Format.Update += new DiscFormat2Erase_EventHandler(eraseUpdate);

                try
                {
                    Format.EraseMedia();
                    e.Result = 0;
                }

                catch (COMException ex)
                {
                    e.Result = ex.ErrorCode;
                    MessageBox.Show("Sepertinya media ini tidak bisa dihapus...\nKemungkinan media terkunci, diproteksi atau sudah rusak.", pesan,
                                    MessageBoxButtons.OK, MessageBoxIcon.Stop);
                }

                Format.Update -= new DiscFormat2Erase_EventHandler(eraseUpdate);

                if (checkBoxKeluarkanTray.Checked)
                {
                    Recorder.EjectMedia();
                }
            }

            catch (COMException exception)
            {
                MessageBox.Show(exception.Message, pesan);
                if (checkBoxKeluarkanTray.Checked)
                {
                    Recorder.EjectMedia();
                }
            }

            finally
            {
                if (Recorder != null)
                {
                    Recorder.ReleaseExclusiveAccess();
                    Marshal.ReleaseComObject(Recorder);
                }

                if (Format != null)
                {
                    Marshal.ReleaseComObject(Format);
                }
            }
        }
예제 #9
0
파일: MainForm.cs 프로젝트: developer88/umk
        /// <summary>
        /// Worker thread that Formats the Disc
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void backgroundFormatWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            MsftDiscRecorder2 discRecorder = null;
            MsftDiscFormat2Erase discFormatErase = null;

            try
            {
                //
                // Create and initialize the IDiscRecorder2
                //
                discRecorder = new MsftDiscRecorder2();
                string activeDiscRecorder = (string)e.Argument;
                discRecorder.InitializeDiscRecorder(activeDiscRecorder);
                discRecorder.AcquireExclusiveAccess(true, m_clientName);

                //
                // Create the IDiscFormat2Erase and set properties
                //
                discFormatErase = new MsftDiscFormat2Erase();
                discFormatErase.Recorder = discRecorder;
                discFormatErase.ClientName = m_clientName;
                discFormatErase.FullErase = !checkBoxQuickFormat.Checked;

                //
                // Setup the Update progress event handler
                //
                discFormatErase.Update += new DiscFormat2Erase_EventHandler(discFormatErase_Update);

                //
                // Erase the media here
                //
                try
                {
                    discFormatErase.EraseMedia();
                    e.Result = 0;
                }
                catch (COMException ex)
                {
                    e.Result = ex.ErrorCode;
                    MessageBox.Show(ex.Message, "Ошибка при форматировании!",
                        MessageBoxButtons.OK, MessageBoxIcon.Stop);
                }

                //
                // Remove the Update progress event handler
                //
                discFormatErase.Update -= new DiscFormat2Erase_EventHandler(discFormatErase_Update);

                //
                // Eject the media
                //
                if (checkBoxEjectFormat.Checked)
                {
                    discRecorder.EjectMedia();
                }

                discRecorder.ReleaseExclusiveAccess();
            }
            catch (COMException exception)
            {
                //
                // If anything happens during the format, show the message
                //
               // MessageBox.Show(exception.Message);
            }
            finally
            {
                if (discRecorder != null)
                {
                    Marshal.ReleaseComObject(discRecorder);
                }

                if (discFormatErase != null)
                {
                    Marshal.ReleaseComObject(discFormatErase);
                }
            }
        }
예제 #10
0
        public void FormatMedia(string activeDiscRecorder, string clientName, bool QuickFormat, bool eject)
        {
            MsftDiscFormat2Erase discFormatErase = null;
            MsftDiscRecorder2    discRecorder    = null;

            try
            {
                // Create and initialize the IDiscRecorder2
                //
                discRecorder = new MsftDiscRecorder2();

                discRecorder.InitializeDiscRecorder(activeDiscRecorder);
                discRecorder.AcquireExclusiveAccess(true, clientName);
                // discRecorder.DisableMcn();


                //
                // Create the IDiscFormat2Erase and set properties
                ////
                discFormatErase            = new MsftDiscFormat2Erase();
                discFormatErase.Recorder   = discRecorder;
                discFormatErase.ClientName = clientName;
                discFormatErase.FullErase  = !QuickFormat;

                //
                // Setup the Update progress event handler
                //
                discFormatErase.Update += DiscFormaEraseData_Update;

                //
                // Erase the media here
                //

                discFormatErase.EraseMedia();
                if (eject)
                {
                    Thread.Sleep(2000);
                    if (!_backgroundWorker.CancellationPending)
                    {
                        discRecorder.EjectMedia();
                    }
                }
            }
            finally
            {
                //
                // remove the Update event handler
                //
                if (discFormatErase != null)
                {
                    discFormatErase.Update -= DiscFormaEraseData_Update;
                }
                if (discFormatErase != null)
                {
                    Marshal.FinalReleaseComObject(discFormatErase);
                }
                if (discRecorder != null)
                {
                    //discRecorder.EnableMcn();
                    discRecorder.ReleaseExclusiveAccess();
                    Marshal.FinalReleaseComObject(discRecorder);
                }
            }
        }
예제 #11
0
        public void FormatMedia(bool quick, bool eject)
        {
            if (!_mediaLoaded)
                throw new InvalidOperationException("LoadMedia must be called first.");

            MsftDiscRecorder2 recorder = null;
            MsftDiscFormat2Erase discFormatErase = null;

            try
            {
                recorder = new MsftDiscRecorder2();
                recorder.InitializeDiscRecorder(_recorders.SelectedItem.InternalUniqueId);
                discFormatErase = new MsftDiscFormat2Erase
                {
                    Recorder = recorder,
                    ClientName = ImageMaster.ClientName,
                    FullErase = !quick
                };

                discFormatErase.Update += _discFormatErase_Update;
                discFormatErase.EraseMedia();

                if (eject) recorder.EjectMedia();
            }
            finally
            {
                if (discFormatErase != null) Marshal.ReleaseComObject(discFormatErase);
                if (recorder != null) Marshal.ReleaseComObject(recorder);
            }
        }