Пример #1
0
        /// <summary>
        /// Copies a CD to an ISO image file.
        /// </summary>
        /// <param name="sourceVolume">Volume to copy from.</param>
        /// <param name="imageFileName">Path to image file to create.</param>
        /// <param name="reportProgress">Optional delegate which is periodically invoked with the percent completion.</param>
        public static void CreateIsoImage(string sourceVolume, string imageFileName, Action <int> reportProgress)
        {
            if (sourceVolume == null)
            {
                throw new ArgumentNullException(nameof(sourceVolume));
            }
            if (imageFileName == null)
            {
                throw new ArgumentNullException(nameof(imageFileName));
            }

            using (var reader = new RawCDReader(sourceVolume))
                using (var writer = File.Create(imageFileName))
                {
                    var  buffer         = new byte[2048];
                    uint count          = (uint)(reader.Length / 2048);
                    int  currentPercent = 0;

                    for (uint i = 0; i < count; i++)
                    {
                        reader.Read(buffer, 0, 2048);
                        writer.Write(buffer, 0, 2048);

                        if (reportProgress != null && currentPercent != (int)((double)i / (double)count))
                        {
                            currentPercent = (int)((double)i / (double)count);
                            reportProgress(currentPercent);
                        }
                    }
                }
        }
Пример #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="HostCDDrive"/> class.
        /// </summary>
        /// <param name="volume">The physical volume to access.</param>
        public HostCDDrive(string volume)
        {
            if (volume == null)
            {
                throw new ArgumentNullException(nameof(volume));
            }

            this.hostDrive   = new RawCDReader(volume);
            this.currentDisc = new Iso9660Disc(this.hostDrive);
        }