示例#1
0
        public bool Close()
        {
            if (!IsWriting)
            {
                ErrorMessage = "Image is not opened for writing";
                return(false);
            }

            if (separateTracksWriting)
            {
                foreach (FileStream writingStream in writingStreams.Values)
                {
                    writingStream.Flush();
                    writingStream.Close();
                }
            }
            else
            {
                writingStreams.First().Value.Flush();
                writingStreams.First().Value.Close();
            }

            bool data  = writingTracks.Count(t => t.TrackType != TrackType.Audio) > 0;
            bool mode2 = writingTracks.Count(t => t.TrackType == TrackType.CdMode2Form1 ||
                                             t.TrackType == TrackType.CdMode2Form2 ||
                                             t.TrackType == TrackType.CdMode2Formless) > 0;

            if (mode2)
            {
                descriptorStream.WriteLine("CD_ROM_XA");
            }
            else if (data)
            {
                descriptorStream.WriteLine("CD_ROM");
            }
            else
            {
                descriptorStream.WriteLine("CD_DA");
            }

            if (!string.IsNullOrWhiteSpace(discimage.Comment))
            {
                string[] commentLines = discimage.Comment.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
                foreach (string line in commentLines)
                {
                    descriptorStream.WriteLine("// {0}", line);
                }
            }

            descriptorStream.WriteLine();

            if (!string.IsNullOrEmpty(discimage.Mcn))
            {
                descriptorStream.WriteLine("CATALOG {0}", discimage.Mcn);
            }

            foreach (Track track in writingTracks)
            {
                descriptorStream.WriteLine();
                descriptorStream.WriteLine("// Track {0}", track.TrackSequence);

                string subchannelType;

                switch (track.TrackSubchannelType)
                {
                case TrackSubchannelType.Packed:
                case TrackSubchannelType.PackedInterleaved:
                    subchannelType = " RW";
                    break;

                case TrackSubchannelType.Raw:
                case TrackSubchannelType.RawInterleaved:
                    subchannelType = " RW_RAW";
                    break;

                default:
                    subchannelType = "";
                    break;
                }

                descriptorStream.WriteLine("TRACK {0}{1}", GetTrackMode(track), subchannelType);

                trackFlags.TryGetValue((byte)track.TrackSequence, out byte flagsByte);

                CdFlags flags = (CdFlags)flagsByte;

                descriptorStream.WriteLine("{0}COPY", flags.HasFlag(CdFlags.CopyPermitted) ? "" : "NO ");

                if (track.TrackType == TrackType.Audio)
                {
                    descriptorStream.WriteLine("{0}PRE_EMPHASIS", flags.HasFlag(CdFlags.PreEmphasis) ? "" : "NO ");
                    descriptorStream.WriteLine("{0}_CHANNEL_AUDIO",
                                               flags.HasFlag(CdFlags.FourChannel) ? "FOUR" : "TWO");
                }

                if (trackIsrcs.TryGetValue((byte)track.TrackSequence, out string isrc))
                {
                    descriptorStream.WriteLine("ISRC {0}", isrc);
                }

                (byte minute, byte second, byte frame)
                msf = LbaToMsf(track.TrackEndSector - track.TrackStartSector + 1);

                descriptorStream.WriteLine("DATAFILE \"{0}\" #{1} {2:D2}:{3:D2}:{4:D2} // length in bytes: {5}",
                                           Path.GetFileName(track.TrackFile), track.TrackFileOffset, msf.minute,
                                           msf.second, msf.frame,
                                           (track.TrackEndSector - track.TrackStartSector + 1) *
                                           (ulong)(track.TrackRawBytesPerSector +
                                                   (track.TrackSubchannelType != TrackSubchannelType.None ? 96 : 0)));

                descriptorStream.WriteLine();
            }

            descriptorStream.Flush();
            descriptorStream.Close();

            IsWriting    = false;
            ErrorMessage = "";
            return(true);
        }
示例#2
0
        public bool Close()
        {
            if (!IsWriting)
            {
                ErrorMessage = "Image is not opened for writing";
                return(false);
            }

            if (separateTracksWriting)
            {
                foreach (FileStream writingStream in writingStreams.Values)
                {
                    writingStream.Flush();
                    writingStream.Close();
                }
            }
            else
            {
                writingStreams.First().Value.Flush();
                writingStreams.First().Value.Close();
            }

            int currentSession = 0;

            if (!string.IsNullOrWhiteSpace(discimage.Comment))
            {
                string[] commentLines = discimage.Comment.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
                foreach (string line in commentLines)
                {
                    descriptorStream.WriteLine("REM {0}", line);
                }
            }

            descriptorStream.WriteLine("REM ORIGINAL MEDIA-TYPE {0}", MediaTypeToCdrwinType(imageInfo.MediaType));

            if (!string.IsNullOrEmpty(discimage.Cdtextfile))
            {
                descriptorStream.WriteLine("CDTEXTFILE \"{0}\"", Path.GetFileName(discimage.Cdtextfile));
            }

            if (!string.IsNullOrEmpty(discimage.Title))
            {
                descriptorStream.WriteLine("TITLE {0}", discimage.Title);
            }

            if (!string.IsNullOrEmpty(discimage.Mcn))
            {
                descriptorStream.WriteLine("CATALOG {0}", discimage.Mcn);
            }

            if (!string.IsNullOrEmpty(discimage.Barcode))
            {
                descriptorStream.WriteLine("UPC_EAN {0}", discimage.Barcode);
            }

            if (!separateTracksWriting)
            {
                descriptorStream.WriteLine("FILE \"{0}\" BINARY", Path.GetFileName(writingStreams.First().Value.Name));
            }

            foreach (Track track in writingTracks)
            {
                if (track.TrackSession > currentSession)
                {
                    descriptorStream.WriteLine("REM SESSION {0}", ++currentSession);
                }

                if (separateTracksWriting)
                {
                    descriptorStream.WriteLine("FILE \"{0}\" BINARY", Path.GetFileName(track.TrackFile));
                }

                (byte minute, byte second, byte frame)msf = LbaToMsf(track.TrackStartSector);
                descriptorStream.WriteLine("  TRACK {0:D2} {1}", track.TrackSequence, GetTrackMode(track));

                if (trackFlags.TryGetValue((byte)track.TrackSequence, out byte flagsByte))
                {
                    if (flagsByte != 0 && flagsByte != (byte)CdFlags.DataTrack)
                    {
                        CdFlags flags = (CdFlags)flagsByte;
                        descriptorStream.WriteLine("    FLAGS{0}{1}{2}",
                                                   flags.HasFlag(CdFlags.CopyPermitted) ? " DCP" : "",
                                                   flags.HasFlag(CdFlags.FourChannel) ? " 4CH" : "",
                                                   flags.HasFlag(CdFlags.PreEmphasis) ? " PRE" : "");
                    }
                }

                if (trackIsrcs.TryGetValue((byte)track.TrackSequence, out string isrc))
                {
                    descriptorStream.WriteLine("    ISRC {0}", isrc);
                }

                descriptorStream.WriteLine("    INDEX {0:D2} {1:D2}:{2:D2}:{3:D2}", 1, msf.minute, msf.second,
                                           msf.frame);
            }

            descriptorStream.Flush();
            descriptorStream.Close();

            IsWriting    = false;
            ErrorMessage = "";
            return(true);
        }