Example #1
0
        void burningUpdate([In, MarshalAs(UnmanagedType.IDispatch)] object sender, [In, MarshalAs(UnmanagedType.IDispatch)] object progress)
        {
            if (backgroundWorker.CancellationPending)
            {
                IDiscFormat2Data Data = (IDiscFormat2Data)sender;
                Data.CancelWrite();
                return;
            }

            IDiscFormat2DataEventArgs kejadian = (IDiscFormat2DataEventArgs)progress;

            burnMedia.task = BURN_MEDIA_TASK.BURN_MEDIA_TASK_WRITING;

            burnMedia.elapsedTime   = kejadian.ElapsedTime;
            burnMedia.remainingTime = kejadian.RemainingTime;
            burnMedia.totalTime     = kejadian.TotalTime;

            burnMedia.currentAction     = kejadian.CurrentAction;
            burnMedia.startLba          = kejadian.StartLba;
            burnMedia.sectorCount       = kejadian.SectorCount;
            burnMedia.lastReadLba       = kejadian.LastReadLba;
            burnMedia.lastWrittenLba    = kejadian.LastWrittenLba;
            burnMedia.totalSystemBuffer = kejadian.TotalSystemBuffer;
            burnMedia.usedSystemBuffer  = kejadian.UsedSystemBuffer;
            burnMedia.freeSystemBuffer  = kejadian.FreeSystemBuffer;

            backgroundWorker.ReportProgress(0, burnMedia);
        }
Example #2
0
        public void cekDrive()
        {
            IDiscRecorder2   Recorder   = (IDiscRecorder2)comboBoxDrive.Items[comboBoxDrive.SelectedIndex];
            IDiscFormat2Data FormatData = null;

            try
            {
                FormatData = new MsftDiscFormat2Data();
                if (!FormatData.IsRecorderSupported(Recorder))
                {
                    aktifkanUIData(false);
                    aktifkanUIImage(false);
                }
            }

            catch
            {
                suaraGalat(true);

                MessageBox.Show(this, "Drive ini tidak mendukung Burning. \nSilakan pilih drive lainnya atau hubungi manufaktur komputer ini.",
                                pesan, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }

            finally
            {
                if (FormatData != null)
                {
                    Marshal.ReleaseComObject(FormatData);
                }
            }
        }
Example #3
0
        /// <summary>
        /// Selected a new device
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void devicesComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (devicesComboBox.SelectedIndex == -1)
            {
                return;
            }

            var discRecorder =
                (IDiscRecorder2)devicesComboBox.Items[devicesComboBox.SelectedIndex];

            supportedMediaLabel.Text = string.Empty;

            //
            // Verify recorder is supported
            //
            IDiscFormat2Data discFormatData = null;

            try
            {
                discFormatData = new MsftDiscFormat2Data();
                if (!discFormatData.IsRecorderSupported(discRecorder))
                {
                    MessageBox.Show("Recorder not supported", ClientName,
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                StringBuilder supportedMediaTypes = new StringBuilder();
                foreach (IMAPI_PROFILE_TYPE profileType in discRecorder.SupportedProfiles)
                {
                    string profileName = GetProfileTypeString(profileType);

                    if (string.IsNullOrEmpty(profileName))
                    {
                        continue;
                    }

                    if (supportedMediaTypes.Length > 0)
                    {
                        supportedMediaTypes.Append(", ");
                    }
                    supportedMediaTypes.Append(profileName);
                }

                supportedMediaLabel.Text = supportedMediaTypes.ToString();
            }
            catch (COMException)
            {
                supportedMediaLabel.Text = "Error getting supported types";
            }
            finally
            {
                if (discFormatData != null)
                {
                    Marshal.ReleaseComObject(discFormatData);
                }
            }
        }
        /// <summary>Burns data files to disc in a single session using files from a single directory tree.</summary>
        /// <param name="recorder">Burning Device. Must be initialized.</param>
        /// <param name="path">Directory of files to burn.</param>
        public static void BurnDirectory(this IDiscRecorder2 recorder, string path, string imageName = "IMAPI Sample")
        {
            // Define the new disc format and set the recorder
            var dataWriterImage = new IDiscFormat2Data
            {
                Recorder = recorder
            };

            if (!dataWriterImage.IsRecorderSupported(recorder))
            {
                Console.WriteLine("The recorder is not supported");
                return;
            }

            if (!dataWriterImage.IsCurrentMediaSupported(recorder))
            {
                Console.WriteLine("The current media is not supported");
                return;
            }

            dataWriterImage.ClientName = imageName;

            // Create an image stream for a specified directory.

            // Create a new file system image and retrieve the root directory
            var fsi = new IFileSystemImage
            {
                // Set the media size
                FreeMediaBlocks = dataWriterImage.FreeSectorsOnMedia,

                // Use legacy ISO 9660 Format
                FileSystemsToCreate = FsiFileSystems.FsiFileSystemUDF
            };

            // Add the directory to the disc file system
            IFsiDirectoryItem dir = fsi.Root;

            Console.WriteLine();
            Console.Write("Adding files to image:".PadRight(80));
            using (var eventDisp = new ComConnectionPoint(fsi, new DFileSystemImageEventsSink(AddTreeUpdate)))
                dir.AddTree(path, false);
            Console.WriteLine();

            // Create an image from the file system
            Console.WriteLine("\nWriting content to disc...");
            IFileSystemImageResult result = fsi.CreateResultImage();

            // Data stream sent to the burning device
            IStream stream = result.ImageStream;

            // Write the image stream to disc using the specified recorder.
            using (var eventDisp = new ComConnectionPoint(dataWriterImage, new DDiscFormat2DataEventsSink(WriteUpdate)))
                dataWriterImage.Write(stream);                   // Burn the stream to disc

            Console.WriteLine("----- Finished writing content -----");
Example #5
0
        private void DevicesComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (devicesComboBox.SelectedIndex == -1)
            {
                return;
            }

            var discRecorder = (IDiscRecorder2)devicesComboBox.Items[devicesComboBox.SelectedIndex];
            IDiscFormat2Data discFormatData = null;

            try
            {
                discFormatData = new MsftDiscFormat2Data();
                if (!discFormatData.IsRecorderSupported(discRecorder))
                {
                    MessageBox.Show("Recorder not supported",
                                    ClientName,
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                    return;
                }

                totalSpaceOnDisk = (2048 * discFormatData.TotalSectorsOnMedia) / 1048576;
                TotalSpace.Text  = "Total Space: " + Convert.ToInt32(totalSpaceOnDisk).ToString() + " MB";
                freeSpaceOnDisk  = freeSpaceOnDisk == null ?
                                   (2048 * discFormatData.FreeSectorsOnMedia) / 1048576
                    : freeSpaceOnDisk + (2048 * discFormatData.FreeSectorsOnMedia) / 1048576;
                FreeSpace.Text = "Free Space: " + Convert.ToInt32(freeSpaceOnDisk) + " MB";

                var supportedMediaTypes = new StringBuilder();
                foreach (IMAPI_PROFILE_TYPE profileType in discRecorder.SupportedProfiles)
                {
                    var profileName = _dictionares.ProfileTypeDictionary[profileType];
                    if (string.IsNullOrEmpty(profileName))
                    {
                        continue;
                    }
                    if (supportedMediaTypes.Length > 0)
                    {
                        supportedMediaTypes.Append(", ");
                    }
                    supportedMediaTypes.Append(profileName);
                }
            }
            catch (COMException)
            { }
            finally
            {
                if (discFormatData != null)
                {
                    Marshal.ReleaseComObject(discFormatData);
                }
            }
        }
Example #6
0
        /// <summary>
        /// The update event handler for the IMAPI service.  Reports the progress of the DVD burn.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="args">Event arguments.</param>
        private void DiscFormatData_Update(
            [In, MarshalAs(UnmanagedType.IDispatch)] object sender,
            [In, MarshalAs(UnmanagedType.IDispatch)] object args)
        {
            if (this.WorkerThread.CancellationPending)
            {
                IDiscFormat2Data format2Data = (IDiscFormat2Data)sender;
                format2Data.CancelWrite();
                return;
            }

            IDiscFormat2DataEventArgs ea = (IDiscFormat2DataEventArgs)args;
            double currentProgress       = 100 * ((ea.LastWrittenLba - ea.StartLba) / (double)ea.SectorCount);

            this.progress = (int)Math.Floor(currentProgress);
            this.StatusUpdateArgs.TimeRemaining = new TimeSpan(0, 0, ea.RemainingTime);
            this.WorkerThread.ReportProgress(this.progress);
        }
Example #7
0
        private void OnBurnProgress(object o1, object o2)
        {
            IDiscFormat2Data          dd = o1 as IDiscFormat2Data;
            IDiscFormat2DataEventArgs ea = o2 as IDiscFormat2DataEventArgs;

            if (ea != null && dd != null)
            {
                Dispatcher.Invoke(
                    DispatcherPriority.Normal,
                    (Action) delegate() { OnUpdateProgress(ea); }
                    );

                if (isCancelRequested)
                {
                    dd.CancelWrite();
                }
            }
        }
        /// <summary>
        /// 获得光碟容量
        /// </summary>
        private void GetDiskSize()
        {
            IDiscFormat2Data format2Data = null;

            try
            {
                format2Data = new MsftDiscFormat2Data();

                if (format2Data.IsRecorderSupported(SelectedMediaWriter) == false)
                {
                    this.Host.ShowMessageBox("没有光碟", MessageBoxActions.Ok);
                    return;
                }

                if (!format2Data.IsCurrentMediaSupported(SelectedMediaWriter))
                {
                    this.Host.ShowMessageBox("没有光碟", MessageBoxActions.Ok);
                    _diskSize        = -1;
                    _diskUseAbleSize = -1;
                    return;
                }
                format2Data.Recorder = SelectedMediaWriter;
                IMAPI_MEDIA_PHYSICAL_TYPE mediaType = format2Data.CurrentPhysicalMediaType;
                CurrentMediaDescription = EnumeratorMediaPhysicalLType.GetMediaTypeString(mediaType);
                Int64 totalSectors = format2Data.TotalSectorsOnMedia;
                Int64 freeSectors  = format2Data.FreeSectorsOnMedia;
                _diskSize        = totalSectors * 2048;
                _diskUseAbleSize = freeSectors * 2048;
            }
            catch (COMException e)
            {
                this.Host.ShowMessageBox(ImapiReturnValues.GetName(e.ErrorCode), MessageBoxActions.Ok);
                _diskSize        = 0;
                _diskUseAbleSize = 0;
            }
            finally
            {
                if (format2Data != null)
                {
                    Marshal.ReleaseComObject(format2Data);
                }
            }
        }
Example #9
0
        /// <summary>
        /// Sets the write speed for the current media.
        /// </summary>
        /// <param name="discFormatData">The format data to set the write speed for.</param>
        private static void SetWriteSpeed(IDiscFormat2Data discFormatData)
        {
            object[] descriptors      = discFormatData.SupportedWriteSpeedDescriptors;
            IWriteSpeedDescriptor max = null;

            foreach (IWriteSpeedDescriptor descriptor in descriptors)
            {
                if (descriptor.WriteSpeed <= MaxWriteSpeed && (max == null || max.WriteSpeed < descriptor.WriteSpeed))
                {
                    max = descriptor;
                }
            }

            if (max != null)
            {
                // Set the speed if we found one that will work.  Otherwise use the default.
                discFormatData.SetWriteSpeed(max.WriteSpeed, max.RotationTypeIsPureCAV);
            }
        }
Example #10
0
        public bool RecorderIsSupported(MsftDiscRecorder2 discRecorder)
        {
            IDiscFormat2Data discFormatData = null;
            bool             answer         = false;

            try
            {
                discFormatData = new MsftDiscFormat2Data();
                answer         = discFormatData.IsRecorderSupported(discRecorder);
            }
            finally
            {
                if (discFormatData != null)
                {
                    Marshal.ReleaseComObject(discFormatData);
                }
            }
            return(answer);
        }
            static void WriteUpdate(IDiscFormat2Data @object, IDiscFormat2DataEventArgs progress)
            {
                switch (progress.CurrentAction)
                {
                case IMAPI_FORMAT2_DATA_WRITE_ACTION.IMAPI_FORMAT2_DATA_WRITE_ACTION_VALIDATING_MEDIA:
                    Console.Write("Validating media. ");
                    break;

                case IMAPI_FORMAT2_DATA_WRITE_ACTION.IMAPI_FORMAT2_DATA_WRITE_ACTION_FORMATTING_MEDIA:
                    Console.Write("Formatting media. ");
                    break;

                case IMAPI_FORMAT2_DATA_WRITE_ACTION.IMAPI_FORMAT2_DATA_WRITE_ACTION_INITIALIZING_HARDWARE:
                    Console.Write("Initializing Hardware. ");
                    break;

                case IMAPI_FORMAT2_DATA_WRITE_ACTION.IMAPI_FORMAT2_DATA_WRITE_ACTION_CALIBRATING_POWER:
                    Console.Write("Calibrating Power (OPC). ");
                    break;

                case IMAPI_FORMAT2_DATA_WRITE_ACTION.IMAPI_FORMAT2_DATA_WRITE_ACTION_WRITING_DATA:
                    var totalSectors   = progress.SectorCount;
                    var writtenSectors = progress.LastWrittenLba - progress.StartLba;
                    var percentDone    = writtenSectors / totalSectors;
                    Console.Write("Progress: {0} - ", percentDone);
                    break;

                case IMAPI_FORMAT2_DATA_WRITE_ACTION.IMAPI_FORMAT2_DATA_WRITE_ACTION_FINALIZATION:
                    Console.Write("Finishing the writing. ");
                    break;

                case IMAPI_FORMAT2_DATA_WRITE_ACTION.IMAPI_FORMAT2_DATA_WRITE_ACTION_COMPLETED:
                    Console.Write("Completed the burn. ");
                    break;

                default:
                    Console.Write("Error!!!! Unknown Action: 0x{0:X} ", progress.CurrentAction);
                    break;
                }
                Console.WriteLine($"Time: {progress.ElapsedTime} / {progress.TotalTime} ({progress.ElapsedTime * 100 / progress.TotalTime}%)");
            }
Example #12
0
        public void cekDrive()
        {
            IDiscRecorder2   Recorder   = (IDiscRecorder2)comboBoxDrive.Items[comboBoxDrive.SelectedIndex];
            IDiscFormat2Data FormatData = null;

            richTextBox.Text = string.Empty;

            try
            {
                StringBuilder tipeMedia = new StringBuilder();
                foreach (IMAPI_PROFILE_TYPE profileType in Recorder.SupportedProfiles)
                {
                    string profileName = jenisDrive(profileType);

                    if (string.IsNullOrEmpty(profileName))
                    {
                        continue;
                    }

                    if (tipeMedia.Length > 0)
                    {
                        tipeMedia.Append("\n");
                    }
                    tipeMedia.Append(profileName);
                }
                richTextBox.Text = tipeMedia.ToString();
            }

            catch
            {
                richTextBox.Text = "KESALAHAN MENDETEKSI DRIVE !@#$%";
            }

            finally
            {
                if (FormatData != null)
                {
                    Marshal.ReleaseComObject(FormatData);
                }
            }
        }
Example #13
0
        public void LoadRecorder()
        {
            if (_recorders.SelectedIndex == -1)
            {
                throw new InvalidOperationException("No DiscRecorder selected from the DiscRecorders list.");
            }

            MsftDiscRecorder2 recorder       = null;
            IDiscFormat2Data  discFormatData = null;

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

                discFormatData = new MsftDiscFormat2Data();
                switch (discFormatData.IsRecorderSupported(recorder))
                {
                case 0x80004003:
                    throw new RecorderNotSupportedException("Pointer is not valid.");

                case 0xC0AA0202:
                    throw new RecorderNotSupportedException("The selected recorder is not supported on this system.");
                }
                _recorderLoaded = true;
                _mediaLoaded    = false;
            }
            finally
            {
                if (discFormatData != null)
                {
                    Marshal.ReleaseComObject(discFormatData);
                }
                if (recorder != null)
                {
                    Marshal.ReleaseComObject(recorder);
                }
            }
        }
Example #14
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="progress"></param>
        void discFormatData_Update([In, MarshalAs(UnmanagedType.IDispatch)] object sender, [In, MarshalAs(UnmanagedType.IDispatch)] object progress)
        {
            //
            // Check if we've cancelled
            //
            if (backgroundBurnWorker.CancellationPending)
            {
                IDiscFormat2Data format2Data = (IDiscFormat2Data)sender;
                format2Data.CancelWrite();
                return;
            }

            IDiscFormat2DataEventArgs eventArgs = (IDiscFormat2DataEventArgs)progress;

            m_burnData.task = BURN_MEDIA_TASK.BURN_MEDIA_TASK_WRITING;

            // IDiscFormat2DataEventArgs Interface
            m_burnData.elapsedTime   = eventArgs.ElapsedTime;
            m_burnData.remainingTime = eventArgs.RemainingTime;
            m_burnData.totalTime     = eventArgs.TotalTime;

            // IWriteEngine2EventArgs Interface
            m_burnData.currentAction     = eventArgs.CurrentAction;
            m_burnData.startLba          = eventArgs.StartLba;
            m_burnData.sectorCount       = eventArgs.SectorCount;
            m_burnData.lastReadLba       = eventArgs.LastReadLba;
            m_burnData.lastWrittenLba    = eventArgs.LastWrittenLba;
            m_burnData.totalSystemBuffer = eventArgs.TotalSystemBuffer;
            m_burnData.usedSystemBuffer  = eventArgs.UsedSystemBuffer;
            m_burnData.freeSystemBuffer  = eventArgs.FreeSystemBuffer;

            //
            // Report back to the UI
            //
            backgroundBurnWorker.ReportProgress(0, m_burnData);
        }
Example #15
0
        public void CreateISO()
        {
            Extraction.WriteResource(Resources.BIOS, Directories.TempPath + "Files\\BIOS.com");
            _repository.BootableImageFile = Directories.TempPath + "Files\\BIOS.com";
            Application.DoEvents();
            OnPropertyChanged("0|Enumerating files...");
            var directory = new DirectoryInfo(_path);
            var files     = directory.GetFiles("*", SearchOption.AllDirectories);

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

            foreach (var file in filtered)
            {
                _repository.AddNewFile(file.FullName);
            }

            IFileSystemImageResult imageResult = null;

            COMTypes.IStream imagestream = null;
            try
            {
                var ifsi = InitRepository();
                Application.DoEvents();
                ifsi.CaptureDirectory = _path;
                imageResult           = ifsi.CreateResultImage();

                if (imageResult == null)
                {
                }

                formatter = new ISOFormatter(_output);


                DiscFormat2Data_Events ev = formatter;
                // if (_ckUseUIReport.Checked)
                ev.Update += FormattingEvent;

                imagestream = formatter.CreateImageStream(imageResult);
                IDiscFormat2Data idf = formatter;

                try
                {
                    idf.Write(imagestream);
                }
                catch (ApplicationException)
                {
                    throw;
                }
                catch (IOException)
                {
                    //WaitForSelection(_output);
                    //if (_backgroundISOWorker.CancellationPending)
                    //    throw;
                    idf.Write(imagestream);
                }
                catch (COMException ex)
                {
                    if (ex.ErrorCode == -2147024864)
                    {
                        //WaitForSelection(_output);
                        //if (_backgroundISOWorker.CancellationPending)
                        //    throw;
                        idf.Write(imagestream);
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            catch (COMException ex)
            {
                //Console.Beep();
                //if (ex.ErrorCode == -1062555360)
                //{
                //    _lblUpdate.Text = "On UI Thread: Media size could be too small for the amount of data";
                //}
                //else
                //    _lblUpdate.Text = "On UI Thread: " + ex.Message;
                if (ex.ErrorCode != -2147024864 && File.Exists(_output))
                {
                    File.Delete(_output);
                }
            }
            catch (Exception ex)
            {
                //if (!this.IsDisposed)
                //{
                //    if (_repository.Cancel)
                //        _lblUpdate.Text = "Canceled on UI thread";
                //    else
                //    {
                //        Console.Beep();
                //        _lblUpdate.Text = "Failed on UI thread: " + ex.Message;
                //    }
                //}
                if (!(ex is IOException) && File.Exists(_output))
                {
                    File.Delete(_output);
                }
            }
            finally
            {
                if (imagestream != null)
                {
                    Marshal.FinalReleaseComObject(imagestream);
                    imagestream = null;
                }
                if (_repository.Cancel && !string.IsNullOrEmpty(_output))
                {
                    File.Delete(_output);
                }
                //else if (!_ckWorker.Checked)
                //    _lblFileImage.Text = _output;
                //if (!_ckWorker.Checked)
                //    RestoreUI(formatter);
                FileHandling.DeleteFile(Directories.TempPath + "Files\\BIOS.com");
            }
        }
 static void fmtHelper_Update(IDiscFormat2Data @object, IDiscFormat2DataEventArgs args)
 {
     Console.WriteLine("{0}: Elapsed: {1}, Estimated: {2}", args.CurrentAction, args.ElapsedTime, args.TotalTime);
 }
Example #17
0
        /// <summary>
        /// Sets the write speed for the current media.
        /// </summary>
        /// <param name="discFormatData">The format data to set the write speed for.</param>
        private static void SetWriteSpeed(IDiscFormat2Data discFormatData)
        {
            object[] descriptors = discFormatData.SupportedWriteSpeedDescriptors;
            IWriteSpeedDescriptor max = null;
            foreach (IWriteSpeedDescriptor descriptor in descriptors)
            {
                if (descriptor.WriteSpeed <= MaxWriteSpeed && (max == null || max.WriteSpeed < descriptor.WriteSpeed))
                {
                    max = descriptor;
                }
            }

            if (max != null)
            {
                // Set the speed if we found one that will work.  Otherwise use the default.
                discFormatData.SetWriteSpeed(max.WriteSpeed, max.RotationTypeIsPureCAV);
            }
        }