Example #1
0
        private void ExportSingleTrack(BuiltStream isoStream, byte[] ipbinData, List <DiscTrack> tracks)
        {
            long currentBytes = 0;
            long totalBytes   = isoStream.Length;
            int  skip         = 0;

            DiscTrack track3 = new DiscTrack();

            track3.FileName = Path.GetFileName(Track03Path);
            track3.LBA      = GD_START_LBA;
            track3.Type     = 4;
            track3.FileSize = (GD_END_LBA - GD_START_LBA) * DATA_SECTOR_SIZE;
            tracks.Add(track3);
            UpdateIPBIN(ipbinData, tracks);
            using (FileStream destStream = new FileStream(Track03Path, FileMode.Create, FileAccess.Write))
            {
                destStream.Write(ipbinData, 0, ipbinData.Length);
                isoStream.Seek(ipbinData.Length, SeekOrigin.Begin);
                currentBytes += ipbinData.Length;

                byte[] buffer  = new byte[64 * 1024];
                int    numRead = isoStream.Read(buffer, 0, buffer.Length);
                while (numRead != 0)
                {
                    destStream.Write(buffer, 0, numRead);
                    numRead       = isoStream.Read(buffer, 0, buffer.Length);
                    currentBytes += numRead;
                    skip++;
                    if (skip >= 10)
                    {
                        skip = 0;
                        int percent = (int)((currentBytes * 100) / totalBytes);
                        if (percent > _lastProgress)
                        {
                            _lastProgress = percent;
                            if (ReportProgress != null)
                            {
                                ReportProgress(_lastProgress);
                            }
                        }
                    }
                }
            }
        }
Example #2
0
        private List <DiscTrack> ReadCDDA(List <string> paths)
        {
            List <DiscTrack> retval = new List <DiscTrack>();

            foreach (string path in paths)
            {
                FileInfo fi = new FileInfo(path);
                if (!fi.Exists)
                {
                    throw new FileNotFoundException("CDDA track " + fi.Name + " could not be accessed.");
                }
                DiscTrack track = new DiscTrack();
                track.FileName = fi.Name;
                track.Type     = 0;
                track.FileSize = fi.Length;
                retval.Add(track);
            }
            return(retval);
        }
Example #3
0
 private void UpdateIPBIN(byte[] ipbinData, List <DiscTrack> tracks)
 {
     //Tracks 03 to 99, 1 and 2 were in the low density area
     for (int t = 0; t < 97; t++)
     {
         uint dcLBA  = 0xFFFFFF;
         byte dcType = 0xFF;
         if (t < tracks.Count)
         {
             DiscTrack track = tracks[t];
             dcLBA  = track.LBA + 150;
             dcType = (byte)((track.Type << 4) | 0x1);
         }
         int offset = 0x104 + (t * 4);
         ipbinData[offset++] = (byte)(dcLBA & 0xFF);
         ipbinData[offset++] = (byte)((dcLBA >> 8) & 0xFF);
         ipbinData[offset++] = (byte)((dcLBA >> 16) & 0xFF);
         ipbinData[offset]   = dcType;
     }
 }
Example #4
0
        private void ExportMultiTrackRaw(BuiltStream isoStream, byte[] ipbinData, List <DiscTrack> tracks)
        {
            //There is a 150 sector gap before and after the CDDA
            long lastHeaderEnd  = 0;
            long firstFileStart = 0;

            foreach (BuilderExtent extent in isoStream.BuilderExtents)
            {
                if (extent is FileExtent)
                {
                    firstFileStart = extent.Start;
                    break;
                }
                else
                {
                    lastHeaderEnd = extent.Start + RoundUp(extent.Length, DATA_SECTOR_SIZE);
                }
            }
            lastHeaderEnd  = lastHeaderEnd / DATA_SECTOR_SIZE;
            firstFileStart = firstFileStart / DATA_SECTOR_SIZE;
            int trackEnd = (int)(firstFileStart - 150);

            for (int i = tracks.Count - 1; i >= 0; i--)
            {
                trackEnd = trackEnd - (int)(RoundUp(tracks[i].FileSize, RAW_SECTOR_SIZE) / RAW_SECTOR_SIZE);
                //Track end is now the beginning of this track and the end of the previous
                tracks[i].LBA = (uint)(trackEnd + GD_START_LBA);
            }
            trackEnd = trackEnd - 150;
            if (trackEnd < lastHeaderEnd)
            {
                throw new Exception("Not enough room to fit all of the CDDA after we added the data.");
            }
            if (TruncateData)
            {
                trackEnd = (int)lastHeaderEnd;
            }
            DiscTrack track3 = new DiscTrack();

            track3.FileName = Path.GetFileName(Track03Path);
            track3.LBA      = GD_START_LBA;
            track3.Type     = 4;
            track3.FileSize = trackEnd * DATA_SECTOR_SIZE;
            tracks.Insert(0, track3);
            DiscTrack lastTrack = new DiscTrack();

            lastTrack.FileName = GetLastTrackName(tracks.Count - 1);
            lastTrack.FileSize = (GD_END_LBA - GD_START_LBA - firstFileStart) * DATA_SECTOR_SIZE;
            lastTrack.LBA      = (uint)(GD_START_LBA + firstFileStart);
            lastTrack.Type     = 4;
            tracks.Add(lastTrack);
            UpdateIPBIN(ipbinData, tracks);

            long currentBytes = 0;
            long totalBytes   = isoStream.Length;
            int  skip         = 0;
            int  currentLBA   = GD_START_LBA;

            using (FileStream destStream = new FileStream(Track03Path, FileMode.Create, FileAccess.Write))
            {
                byte[] buffer = new byte[DATA_SECTOR_SIZE];
                byte[] resultSector;
                for (int i = 0; i < ipbinData.Length; i += buffer.Length)
                {
                    Array.Copy(ipbinData, i, buffer, 0, buffer.Length);
                    resultSector = SectorConversion.ConvertSectorToRawMode1(buffer, currentLBA++);
                    destStream.Write(resultSector, 0, resultSector.Length);
                    currentBytes += 2048;
                }
                isoStream.Seek(ipbinData.Length, SeekOrigin.Begin);
                long bytesWritten = (long)ipbinData.Length;

                int numRead = isoStream.Read(buffer, 0, buffer.Length);
                while (numRead != 0 && bytesWritten < track3.FileSize)
                {
                    while (numRead != 0 && numRead < buffer.Length)
                    {
                        //We need all 2048 bytes for a complete sector!
                        int localRead = isoStream.Read(buffer, numRead, buffer.Length - numRead);
                        numRead += localRead;
                        if (localRead == 0)
                        {
                            for (int i = numRead; i < buffer.Length; i++)
                            {
                                buffer[i] = 0;
                            }
                            break; //Prevent infinite loop
                        }
                    }
                    resultSector = SectorConversion.ConvertSectorToRawMode1(buffer, currentLBA++);
                    destStream.Write(resultSector, 0, resultSector.Length);
                    numRead       = isoStream.Read(buffer, 0, buffer.Length);
                    bytesWritten += numRead;
                    currentBytes += numRead;
                    skip++;
                    if (skip >= 50)
                    {
                        skip = 0;
                        int percent = (int)((currentBytes * 100) / totalBytes);
                        if (percent > _lastProgress)
                        {
                            _lastProgress = percent;
                            if (ReportProgress != null)
                            {
                                ReportProgress(_lastProgress);
                            }
                        }
                    }
                }
            }
            currentLBA = (int)lastTrack.LBA;
            using (FileStream destStream = new FileStream(LastTrackPath, FileMode.Create, FileAccess.Write))
            {
                byte[] buffer = new byte[DATA_SECTOR_SIZE];
                byte[] resultSector;
                currentBytes = firstFileStart * DATA_SECTOR_SIZE;
                isoStream.Seek(currentBytes, SeekOrigin.Begin);
                int numRead = isoStream.Read(buffer, 0, buffer.Length);
                while (numRead != 0)
                {
                    while (numRead != 0 && numRead < buffer.Length)
                    {
                        //We need all 2048 bytes for a complete sector!
                        int localRead = isoStream.Read(buffer, numRead, buffer.Length - numRead);
                        numRead += localRead;
                        if (localRead == 0)
                        {
                            for (int i = numRead; i < buffer.Length; i++)
                            {
                                buffer[i] = 0;
                            }
                            break; //Prevent infinite loop
                        }
                    }
                    resultSector = SectorConversion.ConvertSectorToRawMode1(buffer, currentLBA++);
                    destStream.Write(resultSector, 0, resultSector.Length);
                    numRead = isoStream.Read(buffer, 0, buffer.Length);

                    currentBytes += numRead;
                    skip++;
                    if (skip >= 10)
                    {
                        skip = 0;
                        int percent = (int)((currentBytes * 100) / totalBytes);
                        if (percent > _lastProgress)
                        {
                            _lastProgress = percent;
                            if (ReportProgress != null)
                            {
                                ReportProgress(_lastProgress);
                            }
                        }
                    }
                }
            }
        }
Example #5
0
        /// <summary>
        /// Separate raw logic to maintain performance of the 2048 version
        /// </summary>
        private void ExportSingleTrackRaw(BuiltStream isoStream, byte[] ipbinData, List <DiscTrack> tracks)
        {
            long currentBytes = 0;
            long totalBytes   = isoStream.Length;
            int  skip         = 0;

            DiscTrack track3 = new DiscTrack();

            track3.FileName = Path.GetFileName(Track03Path);
            track3.LBA      = GD_START_LBA;
            track3.Type     = 4;
            track3.FileSize = (GD_END_LBA - GD_START_LBA) * DATA_SECTOR_SIZE;
            tracks.Add(track3);
            UpdateIPBIN(ipbinData, tracks);
            using (FileStream destStream = new FileStream(Track03Path, FileMode.Create, FileAccess.Write))
            {
                int    currentLBA = GD_START_LBA;
                byte[] buffer     = new byte[DATA_SECTOR_SIZE];
                byte[] resultSector;
                for (int i = 0; i < ipbinData.Length; i += buffer.Length)
                {
                    Array.Copy(ipbinData, i, buffer, 0, buffer.Length);
                    resultSector = SectorConversion.ConvertSectorToRawMode1(buffer, currentLBA++);
                    destStream.Write(resultSector, 0, resultSector.Length);
                    currentBytes += 2048;
                }
                isoStream.Seek(ipbinData.Length, SeekOrigin.Begin);

                int numRead = isoStream.Read(buffer, 0, buffer.Length);
                while (numRead != 0)
                {
                    while (numRead != 0 && numRead < buffer.Length)
                    {
                        //We need all 2048 bytes for a complete sector!
                        int localRead = isoStream.Read(buffer, numRead, buffer.Length - numRead);
                        numRead += localRead;
                        if (localRead == 0)
                        {
                            for (int i = numRead; i < buffer.Length; i++)
                            {
                                buffer[i] = 0;
                            }
                            break; //Prevent infinite loop
                        }
                    }
                    resultSector = SectorConversion.ConvertSectorToRawMode1(buffer, currentLBA++);
                    destStream.Write(resultSector, 0, resultSector.Length);
                    numRead       = isoStream.Read(buffer, 0, buffer.Length);
                    currentBytes += numRead;
                    skip++;
                    if (skip >= 10)
                    {
                        skip = 0;
                        int percent = (int)((currentBytes * 100) / totalBytes);
                        if (percent > _lastProgress)
                        {
                            _lastProgress = percent;
                            if (ReportProgress != null)
                            {
                                ReportProgress(_lastProgress);
                            }
                        }
                    }
                }
            }
        }
Example #6
0
 private List<DiscTrack> ReadCDDA(List<string> paths)
 {
     List<DiscTrack> retval = new List<DiscTrack>();
     foreach (string path in paths)
     {
         FileInfo fi = new FileInfo(path);
         if (!fi.Exists)
         {
             throw new FileNotFoundException("CDDA track " + fi.Name + " could not be accessed.");
         }
         DiscTrack track = new DiscTrack();
         track.FileName = fi.Name;
         track.Type = 0;
         track.FileSize = fi.Length;
         retval.Add(track);
     }
     return retval;
 }
Example #7
0
        /// <summary>
        /// Separate raw logic to maintain performance of the 2048 version
        /// </summary>
        private void ExportSingleTrackRaw(BuiltStream isoStream, byte[] ipbinData, List<DiscTrack> tracks)
        {
            long currentBytes = 0;
            long totalBytes = isoStream.Length;
            int skip = 0;

            DiscTrack track3 = new DiscTrack();
            track3.FileName = Path.GetFileName(Track03Path);
            track3.LBA = GD_START_LBA;
            track3.Type = 4;
            track3.FileSize = (GD_END_LBA - GD_START_LBA) * DATA_SECTOR_SIZE;
            tracks.Add(track3);
            UpdateIPBIN(ipbinData, tracks);
            using (FileStream destStream = new FileStream(Track03Path, FileMode.Create, FileAccess.Write))
            {
                int currentLBA = GD_START_LBA;
                byte[] buffer = new byte[DATA_SECTOR_SIZE];
                byte[] resultSector;
                for (int i = 0; i < ipbinData.Length; i += buffer.Length)
                {
                    Array.Copy(ipbinData, i, buffer, 0, buffer.Length);
                    resultSector = SectorConversion.ConvertSectorToRawMode1(buffer, currentLBA++);
                    destStream.Write(resultSector, 0, resultSector.Length);
                    currentBytes += 2048;
                }
                isoStream.Seek(ipbinData.Length, SeekOrigin.Begin);

                int numRead = isoStream.Read(buffer, 0, buffer.Length);
                while (numRead != 0)
                {
                    while (numRead != 0 && numRead < buffer.Length)
                    {
                        //We need all 2048 bytes for a complete sector!
                        int localRead = isoStream.Read(buffer, numRead, buffer.Length - numRead);
                        numRead += localRead;
                        if (localRead == 0)
                        {
                            for (int i = numRead; i < buffer.Length; i++)
                            {
                                buffer[i] = 0;
                            }
                            break; //Prevent infinite loop
                        }
                    }
                    resultSector = SectorConversion.ConvertSectorToRawMode1(buffer, currentLBA++);
                    destStream.Write(resultSector, 0, resultSector.Length);
                    numRead = isoStream.Read(buffer, 0, buffer.Length);
                    currentBytes += numRead;
                    skip++;
                    if (skip >= 10)
                    {
                        skip = 0;
                        int percent = (int)((currentBytes * 100) / totalBytes);
                        if (percent > _lastProgress)
                        {
                            _lastProgress = percent;
                            if (ReportProgress != null)
                            {
                                ReportProgress(_lastProgress);
                            }
                        }
                    }
                }
            }
        }
Example #8
0
        private void ExportSingleTrack(BuiltStream isoStream, byte[] ipbinData, List<DiscTrack> tracks)
        {
            long currentBytes = 0;
            long totalBytes = isoStream.Length;
            int skip = 0;

            DiscTrack track3 = new DiscTrack();
            track3.FileName = Path.GetFileName(Track03Path);
            track3.LBA = GD_START_LBA;
            track3.Type = 4;
            track3.FileSize = (GD_END_LBA - GD_START_LBA) * DATA_SECTOR_SIZE;
            tracks.Add(track3);
            UpdateIPBIN(ipbinData, tracks);
            using (FileStream destStream = new FileStream(Track03Path, FileMode.Create, FileAccess.Write))
            {
                destStream.Write(ipbinData, 0, ipbinData.Length);
                isoStream.Seek(ipbinData.Length, SeekOrigin.Begin);
                currentBytes += ipbinData.Length;

                byte[] buffer = new byte[64 * 1024];
                int numRead = isoStream.Read(buffer, 0, buffer.Length);
                while (numRead != 0)
                {
                    destStream.Write(buffer, 0, numRead);
                    numRead = isoStream.Read(buffer, 0, buffer.Length);
                    currentBytes += numRead;
                    skip++;
                    if (skip >= 10)
                    {
                        skip = 0;
                        int percent = (int)((currentBytes*100) / totalBytes);
                        if (percent > _lastProgress)
                        {
                            _lastProgress = percent;
                            if(ReportProgress != null){
                                ReportProgress(_lastProgress);
                            }
                        }
                    }
                }
            }
        }
Example #9
0
        private void ExportMultiTrackRaw(BuiltStream isoStream, byte[] ipbinData, List<DiscTrack> tracks)
        {
            //There is a 150 sector gap before and after the CDDA
            long lastHeaderEnd = 0;
            long firstFileStart = 0;
            foreach (BuilderExtent extent in isoStream.BuilderExtents)
            {
                if (extent is FileExtent)
                {
                    firstFileStart = extent.Start;
                    break;
                }
                else
                {
                    lastHeaderEnd = extent.Start + RoundUp(extent.Length, DATA_SECTOR_SIZE);
                }
            }
            lastHeaderEnd = lastHeaderEnd / DATA_SECTOR_SIZE;
            firstFileStart = firstFileStart / DATA_SECTOR_SIZE;
            int trackEnd = (int)(firstFileStart - 150);
            for (int i = tracks.Count - 1; i >= 0; i--)
            {
                trackEnd = trackEnd - (int)(RoundUp(tracks[i].FileSize, RAW_SECTOR_SIZE) / RAW_SECTOR_SIZE);
                //Track end is now the beginning of this track and the end of the previous
                tracks[i].LBA = (uint)(trackEnd + GD_START_LBA);
            }
            trackEnd = trackEnd - 150;
            if (trackEnd < lastHeaderEnd)
            {
                throw new Exception("Not enough room to fit all of the CDDA after we added the data.");
            }
            if (TruncateData)
            {
                trackEnd = (int)lastHeaderEnd;
            }
            DiscTrack track3 = new DiscTrack();
            track3.FileName = Path.GetFileName(Track03Path);
            track3.LBA = GD_START_LBA;
            track3.Type = 4;
            track3.FileSize = trackEnd * DATA_SECTOR_SIZE;
            tracks.Insert(0, track3);
            DiscTrack lastTrack = new DiscTrack();
            lastTrack.FileName = GetLastTrackName(tracks.Count - 1);
            lastTrack.FileSize = (GD_END_LBA - GD_START_LBA - firstFileStart) * DATA_SECTOR_SIZE;
            lastTrack.LBA = (uint)(GD_START_LBA + firstFileStart);
            lastTrack.Type = 4;
            tracks.Add(lastTrack);
            UpdateIPBIN(ipbinData, tracks);

            long currentBytes = 0;
            long totalBytes = isoStream.Length;
            int skip = 0;
            int currentLBA = GD_START_LBA;

            using (FileStream destStream = new FileStream(Track03Path, FileMode.Create, FileAccess.Write))
            {
                byte[] buffer = new byte[DATA_SECTOR_SIZE];
                byte[] resultSector;
                for (int i = 0; i < ipbinData.Length; i += buffer.Length)
                {
                    Array.Copy(ipbinData, i, buffer, 0, buffer.Length);
                    resultSector = SectorConversion.ConvertSectorToRawMode1(buffer, currentLBA++);
                    destStream.Write(resultSector, 0, resultSector.Length);
                    currentBytes += 2048;
                }
                isoStream.Seek(ipbinData.Length, SeekOrigin.Begin);
                long bytesWritten = (long)ipbinData.Length;

                int numRead = isoStream.Read(buffer, 0, buffer.Length);
                while (numRead != 0 && bytesWritten < track3.FileSize)
                {
                    while (numRead != 0 && numRead < buffer.Length)
                    {
                        //We need all 2048 bytes for a complete sector!
                        int localRead = isoStream.Read(buffer, numRead, buffer.Length - numRead);
                        numRead += localRead;
                        if (localRead == 0)
                        {
                            for (int i = numRead; i < buffer.Length; i++)
                            {
                                buffer[i] = 0;
                            }
                            break; //Prevent infinite loop
                        }
                    }
                    resultSector = SectorConversion.ConvertSectorToRawMode1(buffer, currentLBA++);
                    destStream.Write(resultSector, 0, resultSector.Length);
                    numRead = isoStream.Read(buffer, 0, buffer.Length);
                    bytesWritten += numRead;
                    currentBytes += numRead;
                    skip++;
                    if (skip >= 50)
                    {
                        skip = 0;
                        int percent = (int)((currentBytes * 100) / totalBytes);
                        if (percent > _lastProgress)
                        {
                            _lastProgress = percent;
                            if (ReportProgress != null)
                            {
                                ReportProgress(_lastProgress);
                            }
                        }
                    }
                }
            }
            currentLBA = (int)lastTrack.LBA;
            using (FileStream destStream = new FileStream(LastTrackPath, FileMode.Create, FileAccess.Write))
            {
                byte[] buffer = new byte[DATA_SECTOR_SIZE];
                byte[] resultSector;
                currentBytes = firstFileStart * DATA_SECTOR_SIZE;
                isoStream.Seek(currentBytes, SeekOrigin.Begin);
                int numRead = isoStream.Read(buffer, 0, buffer.Length);
                while (numRead != 0)
                {
                    while (numRead != 0 && numRead < buffer.Length)
                    {
                        //We need all 2048 bytes for a complete sector!
                        int localRead = isoStream.Read(buffer, numRead, buffer.Length - numRead);
                        numRead += localRead;
                        if (localRead == 0)
                        {
                            for (int i = numRead; i < buffer.Length; i++)
                            {
                                buffer[i] = 0;
                            }
                            break; //Prevent infinite loop
                        }
                    }
                    resultSector = SectorConversion.ConvertSectorToRawMode1(buffer, currentLBA++);
                    destStream.Write(resultSector, 0, resultSector.Length);
                    numRead = isoStream.Read(buffer, 0, buffer.Length);

                    currentBytes += numRead;
                    skip++;
                    if (skip >= 10)
                    {
                        skip = 0;
                        int percent = (int)((currentBytes * 100) / totalBytes);
                        if (percent > _lastProgress)
                        {
                            _lastProgress = percent;
                            if (ReportProgress != null)
                            {
                                ReportProgress(_lastProgress);
                            }
                        }
                    }
                }
            }
        }