Fix CMP/DC parsing, strip DC down

This commit is contained in:
Matt Nadareski
2020-06-12 15:42:47 -07:00
parent daa63a5e8a
commit aa4f669bb9
3 changed files with 17 additions and 17 deletions

View File

@@ -64,7 +64,7 @@ namespace SabreTools.Library.DatFiles
if (normalizedValue == "doscenter")
ReadHeader(sr, keep);
// If we have a known set type
// If we have a game
else if (normalizedValue == "game" )
ReadGame(sr, filename, sysid, srcid, clean, remUnicode);
}
@@ -80,8 +80,6 @@ namespace SabreTools.Library.DatFiles
/// <param name="keep">True if full pathnames are to be kept, false otherwise (default)</param>
private void ReadHeader(StreamReader reader, bool keep)
{
bool superdat = false;
// If there's no subtree to the header, skip it
if (reader == null || reader.EndOfStream)
return;
@@ -97,12 +95,7 @@ namespace SabreTools.Library.DatFiles
// Some dats don't have the space between "Name:" and the dat name
if (line.Trim().StartsWith("Name:"))
{
Name = (string.IsNullOrWhiteSpace(Name) ? line.Substring(6) : Name);
superdat = superdat || itemval.Contains(" - SuperDAT");
if (keep && superdat)
Type = (string.IsNullOrWhiteSpace(Type) ? "SuperDAT" : Type);
Name = (string.IsNullOrWhiteSpace(Name) ? line.Substring(6).Trim() : Name);
line = reader.ReadLine();
continue;
}
@@ -111,11 +104,6 @@ namespace SabreTools.Library.DatFiles
{
case "Name:":
Name = (string.IsNullOrWhiteSpace(Name) ? itemval : Name);
superdat = superdat || itemval.Contains(" - SuperDAT");
if (keep && superdat)
Type = (string.IsNullOrWhiteSpace(Type) ? "SuperDAT" : Type);
break;
case "Description:":
Description = (string.IsNullOrWhiteSpace(Description) ? itemval : Description);
@@ -246,6 +234,18 @@ namespace SabreTools.Library.DatFiles
continue;
}
// Game-specific lines have a known pattern
GroupCollection setgc = Regex.Match(line, Constants.ItemPatternCMP).Groups;
string itemval = setgc[2].Value.Replace("\"", string.Empty);
switch (setgc[1].Value)
{
case "name":
machine.Name = (itemval.ToLowerInvariant().EndsWith(".zip") ? itemval.Remove(itemval.Length - 4) : itemval);
machine.Description = (itemval.ToLowerInvariant().EndsWith(".zip") ? itemval.Remove(itemval.Length - 4) : itemval);
break;
}
line = reader.ReadLine();
}

View File

@@ -2843,8 +2843,8 @@ namespace SabreTools.Library.Tools
// Now we get each string, divided up as cleanly as possible
string[] matches = Regex
//.Matches(s, @"([^\s]*string.Empty[^string.Empty]+string.Empty[^\s]*)|[^string.Empty]?\w+[^string.Empty]?")
.Matches(s, @"[^\sstring.Empty]+|string.Empty[^string.Empty]*string.Empty")
//.Matches(s, @"([^\s]*""[^""]+""[^\s]*)|[^""]?\w+[^""]?")
.Matches(s, @"[^\s""]+|""[^""]*""")
.Cast<Match>()
.Select(m => m.Groups[0].Value)
.ToArray();

View File

@@ -2,7 +2,7 @@
"profiles": {
"SabreTools": {
"commandName": "Project",
"commandLineArgs": "--help update"
"commandLineArgs": "--update --output-dir=B:\\_TEMP --output-type=xml \"C:\\Users\\Matt\\Downloads\\DC_DAT.DAT\""
}
}
}