Exemple #1
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);
                    }
                }
            }
        }
Exemple #2
0
 static extern int SHCreateStreamOnFile(string pszFile, uint grfMode, out IMAPI2.Interop.FsiStream ppstm);