Exemple #1
0
        /// <summary>
        /// Backup processing method.  Called from the worker thread.
        /// </summary>
        protected override void Backup()
        {
            if (String.IsNullOrEmpty(this.activeDriveId))
            {
                throw new InvalidOperationException("Drive not initialized.");
            }

            // Reset the time remaining from previous burns.
            this.StatusUpdateArgs.TimeRemaining = TimeSpan.Zero;
            this.UpdateStatus(DriveStatus.Burning);

            MsftDiscRecorder2 discRecorder2 = new MsftDiscRecorder2();

            discRecorder2.InitializeDiscRecorder(this.activeDriveId);
            discRecorder2.AcquireExclusiveAccess(true, ClientName);

            MsftDiscFormat2Data discFormatData = new MsftDiscFormat2Data();

            if (!discFormatData.IsCurrentMediaSupported(discRecorder2))
            {
                throw new IOException("Invalid media.");
            }

            discFormatData.Recorder             = discRecorder2;
            discFormatData.ClientName           = ClientName;
            discFormatData.ForceMediaToBeClosed = true;
            using (var stream = this.ImageReader.ImageFile.OpenRead())
            {
                discFormatData.Update += this.DiscFormatData_Update;

                try
                {
                    discFormatData.Write(ComStream.ToIStream(stream));
                }
                catch (COMException ex)
                {
                    // Ignore canceled hresult.  Other errors should be reported to the UI thread.
                    if (ex.ErrorCode != -1062600702)
                    {
                        throw;
                    }
                }
                finally
                {
                    discFormatData.Update -= this.DiscFormatData_Update;
                    discRecorder2.EjectMedia();
                }

                // Double check that the burn was completed.  Some cases with XP and 2003 do not
                // return an error, but the burn is not successful.  Using progress < 99 since
                // the last update isn't always returned.
                if (!this.WorkerThread.CancellationPending && this.progress < 99)
                {
                    throw new IOException("Burn not completed.");
                }
            }

            discRecorder2.ReleaseExclusiveAccess();
        }
Exemple #2
0
        public void BurnCD()
        {
            #region CD WRITING
            MsftDiscMaster2 discMaster = null;
            discMaster = new MsftDiscMaster2();
            String path = "D://hello2.txt";
            Console.WriteLine("Writing to the disc");
            if (!discMaster.IsSupportedEnvironment)
            {
                return;
            }
            foreach (string uniqueRecorderId in discMaster)
            {
                var discRecorder2 = new MsftDiscRecorder2();
                discRecorder2.InitializeDiscRecorder(uniqueRecorderId);
                MsftDiscFormat2Data datawriter = new MsftDiscFormat2Data();
                datawriter.Recorder   = discRecorder2;
                datawriter.ClientName = "IMAPIv2 TEST";
                MsftFileSystemImage FSI = new MsftFileSystemImage();
                try
                {
                    if (!datawriter.MediaHeuristicallyBlank)
                    {
                        FSI.MultisessionInterfaces = datawriter.MultisessionInterfaces;
                        FSI.ImportFileSystem();
                    }
                }
                catch (Exception)
                {
                    FSI.ChooseImageDefaults(discRecorder2);
                    Console.WriteLine("Multisession is not supported on this disk!");
                }
                try
                {
                    FSI.Root.AddTree(path, false);
                    IFileSystemImageResult Result = FSI.CreateResultImage();
                    var stream = Result.ImageStream;
                    Console.WriteLine("\nWriting to disc now!!");
                    datawriter.Write(stream);
                    Console.WriteLine("\nWrite Process completed!");
                }
                catch (Exception)
                {
                    Console.WriteLine("Unable to form image from given path!");
                    Console.WriteLine("\nAborted process!");
                }

                discRecorder2.EjectMedia();
            }
            #endregion
            OperationContext.Current.GetCallbackChannel <MyCallBackHandler>().CDBurnt();
        }
Exemple #3
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();
        }
        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;
        }
Exemple #5
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);
                }
            }
        }
Exemple #6
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);
                }
            }
        }
        private int DoBurn(string activeDiscRecorder)
        {
            int result = 0;

            var discMaster = new MsftDiscMaster2();
            var discRecorder2 = new MsftDiscRecorder2();

            discRecorder2.InitializeDiscRecorder(activeDiscRecorder);

            var trackAtOnce = new MsftDiscFormat2TrackAtOnce();
            trackAtOnce.ClientName = "";
            trackAtOnce.Recorder = discRecorder2;
            burnData.totalTracks = mediaItems.Count;
            burnData.currentTrackNumber = 0;

            // Prepare the wave file streams
            foreach (MediaFile mediaFile in mediaItems)
            {
                if (cancellationToken.IsCancellationRequested)
                    break;

                // Report back to the UI that we're preparing stream
                burnData.task = BURN_MEDIA_TASK.BURN_MEDIA_TASK_PREPARING;
                burnData.filename = mediaFile.ToString();
                burnData.currentTrackNumber++;

                burnProgress.Report(burnData);
                mediaFile.PrepareStream();
            }

            trackAtOnce.Update += trackAtOnce_Update;

            trackAtOnce.PrepareMedia();

            foreach (MediaFile mediaFile in mediaItems)
            {
                if (cancellationToken.IsCancellationRequested)
                {
                    result = -1;
                    break;
                }

                burnData.filename = mediaFile.ToString();
                var stream = mediaFile.GetTrackIStream();
                trackAtOnce.AddAudioTrack(stream);
            }

            trackAtOnce.Update -= trackAtOnce_Update;

            trackAtOnce.ReleaseMedia();

            if (ejectMedia)
                discRecorder2.EjectMedia();

            return result;
        }
Exemple #8
0
 /// <summary>
 /// 弹出媒体
 /// </summary>
 void EjectMedia()
 {
     msRecorder.EjectMedia();
 }
Exemple #9
0
        public int WriteStream(System.Runtime.InteropServices.ComTypes.IStream stream, string initburner,
                               string clientName, bool forceMediaToBeClosed, int speed, bool eject)
        {
            MsftDiscRecorder2   discRecorder = null;
            MsftDiscFormat2Data discFormat   = null;
            var result = -1;

            try
            {
                discRecorder = new MsftDiscRecorder2();
                discRecorder.InitializeDiscRecorder(initburner);
                discFormat = new MsftDiscFormat2Data();
                //remove the comment for next 2 lines
                discFormat.Recorder = discRecorder;
                discRecorder.AcquireExclusiveAccess(true, clientName);
                //rec.DisableMcn();
                //
                // initialize the IDiscFormat2Data
                //

                discFormat.ClientName           = clientName;
                discFormat.ForceMediaToBeClosed = forceMediaToBeClosed;

                //
                // add the Update event handler
                //
                discFormat.Update += DiscFormatData_Update;
                //this is how it worked for my burner
                //speed = 0 => minimum speed descriptor in update
                // 0 < speed < minimum speed descriptor => half of minimum speed descriptor in update
                // minimum speed descriptor <= speed < next speed descriptor => minimum speed descriptor in update
                // next speed descriptor <= speed  => next speed descriptorin update
                //discFormat.SetWriteSpeed(2000, true);//?????????????
                discFormat.SetWriteSpeed(speed, true);

                //write the stream
                discFormat.Write(stream);

                if (_backgroundWorker.CancellationPending)
                {
                    return(1);
                }
                if (eject)
                {
                    //wait to flush all the content on the media
                    var state = IMAPI_FORMAT2_DATA_MEDIA_STATE.IMAPI_FORMAT2_DATA_MEDIA_STATE_UNKNOWN;
                    while (state == IMAPI_FORMAT2_DATA_MEDIA_STATE.IMAPI_FORMAT2_DATA_MEDIA_STATE_UNKNOWN &&
                           !_backgroundWorker.CancellationPending)
                    {
                        try
                        {
                            state = discFormat.CurrentMediaStatus;
                        }
                        catch (Exception)
                        {
                            state = IMAPI_FORMAT2_DATA_MEDIA_STATE.IMAPI_FORMAT2_DATA_MEDIA_STATE_UNKNOWN;
                            Thread.Sleep(3000);
                        }
                    }
                    if (!_backgroundWorker.CancellationPending)
                    {
                        discRecorder.EjectMedia();
                    }
                }
                result = 0;
            }
            finally
            {
                if (_backgroundWorker.CancellationPending)
                {
                    result = 1;
                }
                if (discFormat != null)
                {
                    // remove the Update event handler
                    //
                    discFormat.Update -= DiscFormatData_Update;
                    Marshal.FinalReleaseComObject(discFormat);
                }
                if (discRecorder != null)
                {
                    //discRecorder.EnableMcn();
                    discRecorder.ReleaseExclusiveAccess();
                    Marshal.FinalReleaseComObject(discRecorder);
                }
            }
            return(result);
        }
Exemple #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);
                }
            }
        }
Exemple #11
0
        private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            if (radioButtonData.Checked)
            {
                MsftDiscRecorder2   Recorder = null;
                MsftDiscFormat2Data Data     = null;

                try
                {
                    Recorder = new MsftDiscRecorder2();
                    BURN_INTERFACE burnMedia = (BURN_INTERFACE)e.Argument;
                    Recorder.InitializeDiscRecorder(burnMedia.uniqueRecorderId);
                    Recorder.AcquireExclusiveAccess(true, namaProgram);

                    Data                      = new MsftDiscFormat2Data();
                    Data.Recorder             = Recorder;
                    Data.ClientName           = namaProgram;
                    Data.ForceMediaToBeClosed = checkBoxSekaliPakai.Checked;

                    IBurnVerification burnVerification = (IBurnVerification)Data;
                    burnVerification.BurnVerificationLevel = (IMAPI_BURN_VERIFICATION_LEVEL)verificationLevel;

                    object[] multisessionInterfaces = null;
                    if (!Data.MediaHeuristicallyBlank)
                    {
                        multisessionInterfaces = Data.MultisessionInterfaces;
                    }

                    IStream fileSystem = null;
                    if (!membuatFileSystem(Recorder, multisessionInterfaces, out fileSystem))
                    {
                        e.Result = -1;
                        return;
                    }

                    Data.Update += new DiscFormat2Data_EventHandler(burningUpdate);

                    try
                    {
                        Data.Write(fileSystem);
                        e.Result = 0;
                    }

                    catch (COMException ex)
                    {
                        e.Result = ex.ErrorCode;
                        MessageBox.Show("Sepertinya terjadi masalah dalam I/O stream. \nTidak perlu panik, coba cek parameter...", pesan,
                                        MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    }

                    finally
                    {
                        if (fileSystem != null)
                        {
                            Marshal.FinalReleaseComObject(fileSystem);
                        }
                    }

                    Data.Update -= new DiscFormat2Data_EventHandler(burningUpdate);

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

                catch (COMException exception)
                {
                    MessageBox.Show("Okay, ini mungkin masalah...\nCoba cek semua parameter dan lakukan ulang semua langkah dari awal.", pesan);
                    e.Result = exception.ErrorCode;
                    if (this.checkBoxKeluarkanTray.Checked)
                    {
                        Recorder.EjectMedia();
                    }
                }

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

                    if (Data != null)
                    {
                        Marshal.ReleaseComObject(Data);
                    }
                }
            }

            else if (radioButtonImage.Checked)
            {
                MsftDiscRecorder2   Recorder = null;
                MsftDiscFormat2Data Data     = null;

                IMAPI2.Interop.FsiStream streamData = null;
                int imageStream = SHCreateStreamOnFile(textBoxImage.Text, 0x20, out streamData);

                if (imageStream < 0)
                {
                    return;
                }

                try
                {
                    Recorder = new MsftDiscRecorder2();
                    BURN_INTERFACE burnMedia = (BURN_INTERFACE)e.Argument;
                    Recorder.InitializeDiscRecorder(burnMedia.uniqueRecorderId);
                    Recorder.AcquireExclusiveAccess(true, namaProgram);

                    Data            = new MsftDiscFormat2Data();
                    Data.Recorder   = Recorder;
                    Data.ClientName = namaProgram;

                    IBurnVerification burnVerification = (IBurnVerification)Data;
                    burnVerification.BurnVerificationLevel = (IMAPI_BURN_VERIFICATION_LEVEL)verificationLevel;

                    Data.Update += new DiscFormat2Data_EventHandler(burningUpdate);

                    try
                    {
                        Data.Write(streamData);
                        e.Result = 0;
                    }
                    catch (COMException ex)
                    {
                        e.Result = ex.ErrorCode;
                        MessageBox.Show("Ups, terjadi kesalahan...\nHal ini karena ukuran *ISO yang tidak sesuai dengan ukuran media.", pesan,
                                        MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    }
                    finally
                    {
                        if (streamData != null)
                        {
                            Marshal.FinalReleaseComObject(streamData);
                        }
                    }

                    Data.Update -= new DiscFormat2Data_EventHandler(burningUpdate);

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

                catch (COMException exception)
                {
                    MessageBox.Show("Okay, ini mungkin masalah...\nCoba cek semua parameter dan lakukan ulang semua langkah dari awal.", pesan);
                    e.Result = exception.ErrorCode;
                    if (this.checkBoxKeluarkanTray.Checked)
                    {
                        Recorder.EjectMedia();
                    }
                }

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

                    if (Data != null)
                    {
                        Marshal.ReleaseComObject(Data);
                    }
                }
            }
        }
        private int DoBurn(string activeDiscRecorder, IMAPI_BURN_VERIFICATION_LEVEL verificationLevel)
        {
            MsftDiscRecorder2 discRecorder = null;
            MsftDiscFormat2Data discFormatData = null;
            int result = 0;

            try
            {
                discRecorder = new MsftDiscRecorder2();
                discRecorder.InitializeDiscRecorder(burnData.uniqueRecorderId);

                discFormatData = new MsftDiscFormat2Data
                {
                    Recorder = discRecorder,
                    ClientName = "ClientName",
                    ForceMediaToBeClosed = closeMedia
                };

                var burnVerification = (IBurnVerification)discFormatData;
                burnVerification.BurnVerificationLevel = verificationLevel;

                object[] multisessionInterfaces = null;
                if (!discFormatData.MediaHeuristicallyBlank)
                    multisessionInterfaces = discFormatData.MultisessionInterfaces;

                IStream fileSystem;
                if (!CreateMediaFileSystem(discRecorder, multisessionInterfaces, out fileSystem))
                    return -1;

                discFormatData.Update += discFormatData_Update;

                try
                {
                    discFormatData.Write(fileSystem);
                    result = 0;
                }
                catch (COMException ex)
                {
                    result = ex.ErrorCode;
                    MessageBox.Show(ex.Message, "IDiscFormat2Data.Write failed",
                        MessageBoxButton.OK, MessageBoxImage.Stop);
                }
                finally
                {
                    if (fileSystem != null)
                        Marshal.FinalReleaseComObject(fileSystem);
                }

                discFormatData.Update -= discFormatData_Update;

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

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

            return result;
        }
Exemple #13
0
        public void WriteImage(BurnVerificationLevel verification, bool finalize, bool eject)
        {
            if (!_recorderLoaded)
                throw new InvalidOperationException("LoadMedia must be called first.");

            MsftDiscRecorder2 recorder = null;
            MsftDiscFormat2Data discFormatData = null;

            try
            {
                recorder = new MsftDiscRecorder2();
                recorder.InitializeDiscRecorder(_recorders.SelectedItem.InternalUniqueId);

                discFormatData = new MsftDiscFormat2Data
                    {
                        Recorder = recorder,
                        ClientName = ClientName,
                        ForceMediaToBeClosed = finalize
                    };

                //
                // Set the verification level
                //
                var burnVerification = (IBurnVerification)discFormatData;
                burnVerification.BurnVerificationLevel = IMAPI_BURN_VERIFICATION_LEVEL.IMAPI_BURN_VERIFICATION_NONE;

                //
                // Check if media is blank, (for RW media)
                //
                object[] multisessionInterfaces = null;
                if (!discFormatData.MediaHeuristicallyBlank)
                    multisessionInterfaces = discFormatData.MultisessionInterfaces;

                //
                // Create the file system
                //
                IStream fileSystem;
                _CreateImage(recorder, multisessionInterfaces, out fileSystem);

                discFormatData.Update += _discFormatWrite_Update;

                //
                // Write the data
                //
                try
                {
                    discFormatData.Write(fileSystem);
                }
                finally
                {
                    if (fileSystem != null) Marshal.FinalReleaseComObject(fileSystem);
                }

                discFormatData.Update -= _discFormatWrite_Update;

                if (eject) recorder.EjectMedia();
            }
            finally
            {
                _isWriting = false;
                if (discFormatData != null) Marshal.ReleaseComObject(discFormatData);
                if (recorder != null) Marshal.ReleaseComObject(recorder);
            }
        }
Exemple #14
0
        private void BackgroundBurnWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            MsftDiscRecorder2   discRecorder   = null;
            MsftDiscFormat2Data discFormatData = null;

            try
            {
                discRecorder = new MsftDiscRecorder2();
                var burnData = (BurnData)e.Argument;
                discRecorder.InitializeDiscRecorder(burnData.UniqueRecorderId);
                discFormatData = new MsftDiscFormat2Data
                {
                    Recorder             = discRecorder,
                    ClientName           = ClientName,
                    ForceMediaToBeClosed = _closeMedia
                };
                var burnVerification = (IBurnVerification)discFormatData;
                burnVerification.BurnVerificationLevel = _verificationLevel;

                object[] multisessionInterfaces = null;
                if (!discFormatData.MediaHeuristicallyBlank)
                {
                    multisessionInterfaces = discFormatData.MultisessionInterfaces;
                }

                if (!CreateMediaFileSystem(discRecorder, multisessionInterfaces, out IStream fileSystem))
                {
                    e.Result = -1;
                    return;
                }

                discFormatData.Update += DiscFormatData_Update;

                try
                {
                    discFormatData.Write(fileSystem);
                    e.Result = 0;
                }
                catch (COMException ex)
                {
                    e.Result = ex.ErrorCode;
                    MessageBox.Show(ex.Message, "IDiscFormat2Data.Write failed",
                                    MessageBoxButtons.OK, MessageBoxIcon.Stop);
                }
                finally
                {
                    if (fileSystem != null)
                    {
                        Marshal.FinalReleaseComObject(fileSystem);
                    }
                }

                discFormatData.Update -= DiscFormatData_Update;

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

                if (discFormatData != null)
                {
                    Marshal.ReleaseComObject(discFormatData);
                }
            }
        }
Exemple #15
0
        public void WriteImage(BurnVerificationLevel verification, bool finalize, bool eject)
        {
            if (!_recorderLoaded)
            {
                throw new InvalidOperationException("LoadMedia must be called first.");
            }

            MsftDiscRecorder2   recorder       = null;
            MsftDiscFormat2Data discFormatData = null;

            try
            {
                recorder = new MsftDiscRecorder2();
                recorder.InitializeDiscRecorder(_recorders.SelectedItem.InternalUniqueId);

                discFormatData = new MsftDiscFormat2Data
                {
                    Recorder             = recorder,
                    ClientName           = ClientName,
                    ForceMediaToBeClosed = finalize
                };

                //
                // Set the verification level
                //
                var burnVerification = (IBurnVerification)discFormatData;
                burnVerification.BurnVerificationLevel = IMAPI_BURN_VERIFICATION_LEVEL.IMAPI_BURN_VERIFICATION_NONE;

                //
                // Check if media is blank, (for RW media)
                //
                object[] multisessionInterfaces = null;
                if (!discFormatData.MediaHeuristicallyBlank)
                {
                    multisessionInterfaces = discFormatData.MultisessionInterfaces;
                }

                //
                // Create the file system
                //
                IStream fileSystem;
                _CreateImage(recorder, multisessionInterfaces, out fileSystem);

                discFormatData.Update += _discFormatWrite_Update;

                //
                // Write the data
                //
                try
                {
                    discFormatData.Write(fileSystem);
                }
                finally
                {
                    if (fileSystem != null)
                    {
                        Marshal.FinalReleaseComObject(fileSystem);
                    }
                }

                discFormatData.Update -= _discFormatWrite_Update;

                if (eject)
                {
                    recorder.EjectMedia();
                }
            }
            finally
            {
                _isWriting = false;
                if (discFormatData != null)
                {
                    Marshal.ReleaseComObject(discFormatData);
                }
                if (recorder != null)
                {
                    Marshal.ReleaseComObject(recorder);
                }
            }
        }
Exemple #16
0
        /// <summary>
        /// The thread that does the burning of the media
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void backgroundBurnWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            MsftDiscRecorder2   discRecorder   = null;
            MsftDiscFormat2Data discFormatData = null;

            try
            {
                //
                // Create and initialize the IDiscRecorder2 object
                //
                discRecorder = new MsftDiscRecorder2();
                var burnData = (BurnData)e.Argument;
                discRecorder.InitializeDiscRecorder(burnData.uniqueRecorderId);

                //
                // Create and initialize the IDiscFormat2Data
                //
                discFormatData = new MsftDiscFormat2Data
                {
                    Recorder   = discRecorder,
                    ClientName = ClientName
                };

                //
                // Set the verification level
                //
                var burnVerification = (IBurnVerification)discFormatData;
                burnVerification.BurnVerificationLevel = _verificationLevel;

                //
                // Check if media is blank, (for RW media)
                //
                object[] multisessionInterfaces = null;
                if (!discFormatData.MediaHeuristicallyBlank)
                {
                    multisessionInterfaces = discFormatData.MultisessionInterfaces;
                }

                //
                // Create the file system
                //
                IStream fileSystem;
                if (!CreateMediaFileSystem(discRecorder, multisessionInterfaces, out fileSystem))
                {
                    e.Result = -1;
                    return;
                }

                //
                // add the Update event handler
                //
                discFormatData.Update += discFormatData_Update;

                //
                // Write the data here
                //
                try
                {
                    discFormatData.Write(fileSystem);
                    e.Result = 0;
                }
                catch (COMException ex)
                {
                    e.Result = ex.ErrorCode;
                    MessageBox.Show(ex.Message, "IDiscFormat2Data.Write failed",
                                    MessageBoxButtons.OK, MessageBoxIcon.Stop);
                }
                finally
                {
                    if (fileSystem != null)
                    {
                        Marshal.FinalReleaseComObject(fileSystem);
                    }
                }

                //
                // remove the Update event handler
                //
                discFormatData.Update -= discFormatData_Update;

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

                if (discFormatData != null)
                {
                    Marshal.ReleaseComObject(discFormatData);
                }
            }
        }
Exemple #17
0
        private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            IStream           stream;
            MsftDiscRecorder2 msftDiscRecorder2Class = null;
            GInterface6       gInterface6            = null;

            try
            {
                try
                {
                    msftDiscRecorder2Class = (MsftDiscRecorder2)(new MsftDiscRecorder2Class());
                    msftDiscRecorder2Class.InitializeDiscRecorder(((BurnData)e.Argument).uniqueRecorderId);
                    GInterface6 msftDiscFormat2DataClass = (GInterface6)(new MsftDiscFormat2DataClass());
                    msftDiscFormat2DataClass.Recorder             = msftDiscRecorder2Class;
                    msftDiscFormat2DataClass.ClientName           = "C3BurnMedia";
                    msftDiscFormat2DataClass.ForceMediaToBeClosed = this._closeMedia;
                    gInterface6 = msftDiscFormat2DataClass;
                    ((IBurnVerification)gInterface6).BurnVerificationLevel = this._verificationLevel;
                    object[] multisessionInterfaces = null;
                    if (!gInterface6.MediaHeuristicallyBlank)
                    {
                        multisessionInterfaces = gInterface6.MultisessionInterfaces;
                    }
                    if (this.CreateMediaFileSystem(msftDiscRecorder2Class, multisessionInterfaces, out stream))
                    {
                        gInterface6.Update += new DiscFormat2Data_EventHandler(this.discFormatData_Update);
                        this.backgroundWorker.ReportProgress(0, this._burnData);
                        try
                        {
                            try
                            {
                                gInterface6.Write(stream);
                                e.Result = 0;
                            }
                            catch (COMException cOMException1)
                            {
                                COMException cOMException = cOMException1;
                                e.Result = cOMException.ErrorCode;
                                MessageBox.Show(this, cOMException.Message, "Write failed", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                            }
                        }
                        finally
                        {
                            if (stream != null)
                            {
                                Marshal.FinalReleaseComObject(stream);
                            }
                        }
                        gInterface6.Update -= new DiscFormat2Data_EventHandler(this.discFormatData_Update);
                        this.backgroundWorker.ReportProgress(0, this._burnData);
                        if (this._ejectMedia)
                        {
                            msftDiscRecorder2Class.EjectMedia();
                        }
                    }
                    else
                    {
                        e.Result = -1;
                        return;
                    }
                }
                catch (COMException cOMException3)
                {
                    COMException cOMException2 = cOMException3;
                    MessageBox.Show(cOMException2.Message);
                    e.Result = cOMException2.ErrorCode;
                }
            }
            finally
            {
                if (msftDiscRecorder2Class != null)
                {
                    Marshal.ReleaseComObject(msftDiscRecorder2Class);
                }
                if (gInterface6 != null)
                {
                    Marshal.ReleaseComObject(gInterface6);
                }
            }
        }
Exemple #18
0
        /// <summary>
        /// The thread that does the burning of the media
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void backgroundBurnWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            MsftDiscRecorder2 discRecorder = null;
            MsftDiscFormat2Data discFormatData = null;

            try
            {
                //
                // Create and initialize the IDiscRecorder2 object
                //
                discRecorder = new MsftDiscRecorder2();
                var burnData = (BurnData)e.Argument;
                discRecorder.InitializeDiscRecorder(burnData.uniqueRecorderId);

                //
                // Create and initialize the IDiscFormat2Data
                //
                discFormatData = new MsftDiscFormat2Data
                    {
                        Recorder = discRecorder,
                        ClientName = ClientName
                        
                    };

                //
                // Set the verification level
                //
                var burnVerification = (IBurnVerification)discFormatData;
                burnVerification.BurnVerificationLevel = _verificationLevel;

                //
                // Check if media is blank, (for RW media)
                //
                object[] multisessionInterfaces = null;
                if (!discFormatData.MediaHeuristicallyBlank)
                {
                    multisessionInterfaces = discFormatData.MultisessionInterfaces;
                }

                //
                // Create the file system
                //
                IStream fileSystem;
                if (!CreateMediaFileSystem(discRecorder, multisessionInterfaces, out fileSystem))
                {
                    e.Result = -1;
                    return;
                }

                //
                // add the Update event handler
                //
                discFormatData.Update += discFormatData_Update;

                //
                // Write the data here
                //
                try
                {
                    discFormatData.Write(fileSystem);
                    e.Result = 0;
                }
                catch (COMException ex)
                {
                    e.Result = ex.ErrorCode;
                    MessageBox.Show(ex.Message, "IDiscFormat2Data.Write failed",
                        MessageBoxButtons.OK, MessageBoxIcon.Stop);
                }
                finally
                {
                    if (fileSystem != null)
                    {
                        Marshal.FinalReleaseComObject(fileSystem);
                    }
                }

                //
                // remove the Update event handler
                //
                discFormatData.Update -= discFormatData_Update;

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

                if (discFormatData != null)
                {
                    Marshal.ReleaseComObject(discFormatData);
                }
            }
        }
Exemple #19
0
        /// <summary>
        /// Backup processing method.  Called from the worker thread.
        /// </summary>
        protected override void Backup()
        {
            if (String.IsNullOrEmpty(this.activeDriveId))
            {
                throw new InvalidOperationException("Drive not initialized.");
            }

            // Reset the time remaining from previous burns.
            this.StatusUpdateArgs.TimeRemaining = TimeSpan.Zero;
            this.UpdateStatus(DriveStatus.Burning);

            MsftDiscRecorder2 discRecorder2 = new MsftDiscRecorder2();
            discRecorder2.InitializeDiscRecorder(this.activeDriveId);
            discRecorder2.AcquireExclusiveAccess(true, ClientName);

            MsftDiscFormat2Data discFormatData = new MsftDiscFormat2Data();
            if (!discFormatData.IsCurrentMediaSupported(discRecorder2))
            {
                throw new IOException("Invalid media.");
            }

            discFormatData.Recorder = discRecorder2;
            discFormatData.ClientName = ClientName;
            discFormatData.ForceMediaToBeClosed = true;
            using (var stream = this.ImageReader.ImageFile.OpenRead())
            {
                discFormatData.Update += this.DiscFormatData_Update;

                try
                {
                    discFormatData.Write(ComStream.ToIStream(stream));
                }
                catch (COMException ex)
                {
                    // Ignore canceled hresult.  Other errors should be reported to the UI thread.
                    if (ex.ErrorCode != -1062600702)
                    {
                        throw;
                    }
                }
                finally
                {
                    discFormatData.Update -= this.DiscFormatData_Update;
                    discRecorder2.EjectMedia();
                }

                // Double check that the burn was completed.  Some cases with XP and 2003 do not
                // return an error, but the burn is not successful.  Using progress < 99 since
                // the last update isn't always returned.
                if (!this.WorkerThread.CancellationPending && this.progress < 99)
                {
                    throw new IOException("Burn not completed.");
                }
            }

            discRecorder2.ReleaseExclusiveAccess();
        }
Exemple #20
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;

            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);
                }
            }
        }
Exemple #21
0
        /// <summary>
        /// The thread that does the burning of the media
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void backgroundBurnWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            MsftDiscRecorder2 discRecorder = null;
            MsftDiscFormat2Data discFormatData = null;

            try
            {
                //
                // Create and initialize the IDiscRecorder2 object
                //
                discRecorder = new MsftDiscRecorder2();
                BurnData burnData = (BurnData)e.Argument;
                discRecorder.InitializeDiscRecorder(burnData.uniqueRecorderId);
                discRecorder.AcquireExclusiveAccess(true, m_clientName);

                //
                // Create and initialize the IDiscFormat2Data
                //
                discFormatData = new MsftDiscFormat2Data();
                discFormatData.Recorder = discRecorder;
                discFormatData.ClientName = m_clientName;
                discFormatData.ForceMediaToBeClosed = checkBoxCloseMedia.Checked;

                //
                // Set the verification level
                //
                IBurnVerification burnVerification = (IBurnVerification)discFormatData;
                burnVerification.BurnVerificationLevel = (IMAPI_BURN_VERIFICATION_LEVEL)m_verificationLevel;

                //
                // Check if media is blank, (for RW media)
                //
                object[] multisessionInterfaces = null;
                if (!discFormatData.MediaHeuristicallyBlank)
                {
                    multisessionInterfaces = discFormatData.MultisessionInterfaces;
                }

                //
                // Create the file system
                //
                IStream fileSystem = null;
                if (!CreateMediaFileSystem(discRecorder, multisessionInterfaces, out fileSystem))
                {
                    e.Result = -1;
                    return;
                }

                //
                // add the Update event handler
                //
                discFormatData.Update += new DiscFormat2Data_EventHandler(discFormatData_Update);

                //
                // Write the data here
                //
                try
                {
                    discFormatData.Write(fileSystem);
                    e.Result = 0;
                }
                catch (COMException ex)
                {
                    e.Result = ex.ErrorCode;
                    MessageBox.Show(ex.Message, "Ошибка в процессе записи диска!",
                        MessageBoxButtons.OK, MessageBoxIcon.Stop);
                }
                finally
                {
                    if (fileSystem != null)
                    {
                        Marshal.FinalReleaseComObject(fileSystem);
                    }
                }

                //
                // remove the Update event handler
                //
                discFormatData.Update -= new DiscFormat2Data_EventHandler(discFormatData_Update);

                if (this.checkBoxEject.Checked)
                {
                    discRecorder.EjectMedia();
                }

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

                if (discFormatData != null)
                {
                    Marshal.ReleaseComObject(discFormatData);
                }
            }
        }
Exemple #22
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);
                }
            }
        }
Exemple #23
0
        /// <summary>
        /// The thread that does the burning of the media
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void backgroundBurnWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            //
            // Create and initialize the IDiscRecorder2 object
            //
            MsftDiscRecorder2 discRecorder = new MsftDiscRecorder2();
            BurnData          burnData     = (BurnData)e.Argument;

            discRecorder.InitializeDiscRecorder(burnData.uniqueRecorderId);
            discRecorder.AcquireExclusiveAccess(true, m_clientName);

            //
            // Create and initialize the IDiscFormat2Data
            //
            MsftDiscFormat2Data discFormatData = new MsftDiscFormat2Data();

            discFormatData.Recorder             = discRecorder;
            discFormatData.ClientName           = m_clientName;
            discFormatData.ForceMediaToBeClosed = checkBoxCloseMedia.Checked;

            //
            // Check if media is blank, (for RW media)
            //
            object[] multisessionInterfaces = null;
            if (!discFormatData.MediaHeuristicallyBlank)
            {
                multisessionInterfaces = discFormatData.MultisessionInterfaces;
            }

            //
            // Create the file system
            //
            IStream fileSystem = null;

            if (!CreateMediaFileSystem(discRecorder, multisessionInterfaces, out fileSystem))
            {
                e.Result = -1;
                return;
            }

            //
            // add the Update event handler
            //
            discFormatData.Update += new DiscFormat2Data_EventHandler(discFormatData_Update);

            //
            // Write the data here
            //
            try
            {
                discFormatData.Write(fileSystem);
                e.Result = 0;
            }
            catch (COMException ex)
            {
                e.Result = ex.ErrorCode;
                MessageBox.Show(ex.Message, "IDiscFormat2Data.Write failed",
                                MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }

            //
            // remove the Update event handler
            //
            discFormatData.Update -= new DiscFormat2Data_EventHandler(discFormatData_Update);

            if (this.checkBoxEject.Checked)
            {
                discRecorder.EjectMedia();
            }

            discRecorder.ReleaseExclusiveAccess();
        }
Exemple #24
0
        private void backgroundBurnWorker2_DoWork(object sender, DoWorkEventArgs e)
        {
            MsftDiscRecorder2   discRecorder   = null;
            MsftDiscFormat2Data discFormatData = null;

            try
            {
                // Create and initialize the IDiscRecorder2 object
                discRecorder = new MsftDiscRecorder2();
                var burnData = (BurnData)e.Argument;
                try
                {
                    Log.WriteLine("DISK 2 uniqueRecorderId = " + burnData.uniqueRecorderId);
                    discRecorder.InitializeDiscRecorder(burnData.uniqueRecorderId);
                }
                catch (Exception ex)
                {
                    e.Result = -1;
                    Log.WriteLine(ex.ToString());
                    return;
                }

                // Create and initialize the IDiscFormat2Data
                discFormatData = new MsftDiscFormat2Data
                {
                    Recorder             = discRecorder,
                    ClientName           = "VACamera",
                    ForceMediaToBeClosed = _closeMedia
                };

                // Set the verification level
                var burnVerification = (IBurnVerification)discFormatData;
                burnVerification.BurnVerificationLevel = _verificationLevel;

                // Check if media is blank, (for RW media)
                object[] multisessionInterfaces = null;
                if (!discFormatData.MediaHeuristicallyBlank)
                {
                    multisessionInterfaces = discFormatData.MultisessionInterfaces;
                }

                // Create the file system
                IStream fileSystem;
                if (!createMediaFileSystem(discRecorder, multisessionInterfaces, out fileSystem))
                {
                    e.Result = -1;
                    Log.WriteLine("Cannot create filesystem on disk!");
                    return;
                }

                // add the Update event handler
                discFormatData.Update += discFormatData2_Update;

                // Write the data here
                try
                {
                    discFormatData.Write(fileSystem);
                    e.Result = 0;
                }
                catch (Exception ex)
                {
                    e.Result = -1;
                    Log.WriteLine(ex.ToString());
                }
                finally
                {
                    if (fileSystem != null)
                    {
                        Marshal.FinalReleaseComObject(fileSystem);
                    }
                }

                // remove the Update event handler
                discFormatData.Update -= discFormatData2_Update;

                if (_ejectMedia)
                {
                    discRecorder.EjectMedia();
                }
            }
            catch (Exception ex)
            {
                e.Result = -1;
                Log.WriteLine(ex.ToString());
            }
            finally
            {
                if (discRecorder != null)
                {
                    Marshal.ReleaseComObject(discRecorder);
                }

                if (discFormatData != null)
                {
                    Marshal.ReleaseComObject(discFormatData);
                }
            }
        }
Exemple #25
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);
            }
        }