Esempio n. 1
0
        /// <summary>
        /// Fill a FILE from an array of lines
        /// </summary>
        /// <param name="fileName">File name to set</param>
        /// <param name="fileType">File type to set</param>
        /// <param name="cueLines">Lines array to pull from</param>
        /// <param name="i">Reference to index in array</param>
        public CueFile(string fileName, string fileType, string[] cueLines, ref int i)
        {
            if (cueLines == null || i < 0 || i > cueLines.Length)
            {
                return; // TODO: Make this throw an exception
            }
            // Set the current fields
            this.FileName = fileName.Trim('"');
            this.FileType = GetFileType(fileType);

            // Increment to start
            i++;

            for (; i < cueLines.Length; i++)
            {
                string   line      = cueLines[i].Trim();
                string[] splitLine = line.Split(' ');

                // If we have an empty line, we skip
                if (string.IsNullOrWhiteSpace(line))
                {
                    continue;
                }

                switch (splitLine[0])
                {
                // Read comments
                case "REM":
                    // We ignore all comments for now
                    break;

                // Read track information
                case "TRACK":
                    if (splitLine.Length < 3)
                    {
                        continue;     // TODO: Make this throw an exception
                    }
                    if (this.Tracks == null)
                    {
                        this.Tracks = new List <CueTrack>();
                    }

                    var track = new CueTrack(splitLine[1], splitLine[2], cueLines, ref i);
                    if (track == default)
                    {
                        continue;     // TODO: Make this throw an exception
                    }
                    this.Tracks.Add(track);
                    break;

                // Default means return
                default:
                    i--;
                    return;
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Fill a FILE from an array of lines
        /// </summary>
        /// <param name="fileName">File name to set</param>
        /// <param name="fileType">File type to set</param>
        /// <param name="cueLines">Lines array to pull from</param>
        /// <param name="i">Reference to index in array</param>
        /// <param name="throwOnError">True if errors throw an exception, false otherwise</param>
        public CueFile(string fileName, string fileType, string[] cueLines, ref int i, bool throwOnError = false)
        {
            if (cueLines == null)
            {
                if (throwOnError)
                {
                    throw new ArgumentNullException(nameof(cueLines));
                }

                return;
            }
            else if (i < 0 || i > cueLines.Length)
            {
                if (throwOnError)
                {
                    throw new IndexOutOfRangeException();
                }

                return;
            }

            // Set the current fields
            this.FileName = fileName.Trim('"');
            this.FileType = GetFileType(fileType);

            // Increment to start
            i++;

            for (; i < cueLines.Length; i++)
            {
                string   line      = cueLines[i].Trim();
                string[] splitLine = line.Split(' ');

                // If we have an empty line, we skip
                if (string.IsNullOrWhiteSpace(line))
                {
                    continue;
                }

                switch (splitLine[0])
                {
                // Read comments
                case "REM":
                    // We ignore all comments for now
                    break;

                // Read track information
                case "TRACK":
                    if (splitLine.Length < 3)
                    {
                        if (throwOnError)
                        {
                            throw new FormatException($"TRACK line malformed: {line}");
                        }

                        continue;
                    }

                    if (this.Tracks == null)
                    {
                        this.Tracks = new List <CueTrack>();
                    }

                    var track = new CueTrack(splitLine[1], splitLine[2], cueLines, ref i);
                    if (track == default)
                    {
                        if (throwOnError)
                        {
                            throw new FormatException($"TRACK line malformed: {line}");
                        }

                        continue;
                    }

                    this.Tracks.Add(track);
                    break;

                // Default means return
                default:
                    i--;
                    return;
                }
            }
        }