discsystem - successfully parse cues that are bigger garbage

This commit is contained in:
zeromus 2015-09-16 14:37:42 -05:00
parent 8f5059d53e
commit bafe41fa54
2 changed files with 31 additions and 2 deletions

View File

@ -236,6 +236,7 @@ namespace BizHawk.Emulation.DiscSystem.CUE
}
var cfi = new CompiledCueFile();
curr_file = cfi;
OUT_CompiledCueFiles.Add(cfi);
cfi.FullPath = choice;

View File

@ -3,6 +3,7 @@
using System;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.IO;
using System.Collections.Generic;
@ -27,6 +28,11 @@ namespace BizHawk.Emulation.DiscSystem.CUE
/// </summary>
public CUE_File OUT_CueFile;
/// <summary>
/// Indicates whether parsing will be strict or lenient
/// </summary>
public bool IN_Strict = false;
class CueLineParser
{
@ -141,7 +147,22 @@ namespace BizHawk.Emulation.DiscSystem.CUE
var clp = new CueLineParser(line);
string key = clp.ReadToken().ToUpperInvariant();
if (key.StartsWith(";"))
//remove nonsense at beginning
if (!IN_Strict)
{
while (key.Length > 0)
{
char c = key[0];
if(c == ';') break;
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) break;
key = key.Substring(1);
}
}
bool startsWithSemicolon = key.StartsWith(";");
if (startsWithSemicolon)
{
clp.EOF = true;
OUT_CueFile.Commands.Add(new CUE_File.Command.COMMENT() { Value = line });
@ -237,9 +258,16 @@ namespace BizHawk.Emulation.DiscSystem.CUE
}
string str_timestamp = clp.ReadToken();
var ts = new Timestamp(str_timestamp);
if (!ts.Valid && !IN_Strict)
{
//try cleaning it up
str_timestamp = Regex.Replace(str_timestamp, "[^0-9:]", "");
ts = new Timestamp(str_timestamp);
}
if (!ts.Valid)
{
job.Error("Invalid INDEX timestamp: " + str_timestamp);
if (IN_Strict)
job.Error("Invalid INDEX timestamp: " + str_timestamp);
break;
}
OUT_CueFile.Commands.Add(new CUE_File.Command.INDEX() { Number = indexnum, Timestamp = ts });