Fix a couple AttractMode things

This commit is contained in:
Matt Nadareski
2020-09-07 12:58:55 -07:00
parent 1494e0693f
commit 9b6e54aeed
2 changed files with 49 additions and 49 deletions

View File

@@ -1,7 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq;
using System.Text; using System.Text;
using SabreTools.Library.Data; using SabreTools.Library.Data;
@@ -34,35 +33,37 @@ namespace SabreTools.Library.DatFiles
{ {
// Open a file reader // Open a file reader
Encoding enc = FileExtensions.GetEncoding(filename); Encoding enc = FileExtensions.GetEncoding(filename);
StreamReader sr = new StreamReader(FileExtensions.TryOpenRead(filename), enc); SeparatedValueReader svr = new SeparatedValueReader(FileExtensions.TryOpenRead(filename), enc)
sr.ReadLine(); // Skip the first line since it's the header
while (!sr.EndOfStream)
{ {
string line = sr.ReadLine(); Header = true,
Quotes = false,
Separator = ';',
VerifyFieldCount = true
};
/* // If we're somehow at the end of the stream already, we can't do anything
The gameinfo order is as follows if (svr.EndOfStream)
0 - game name return;
1 - game description
2 - emulator name (filename)
3 - cloneof
4 - year
5 - manufacturer
6 - category
7 - players
8 - rotation
9 - control
10 - status
11 - displaycount
12 - displaytype
13 - alt romname
14 - alt title
15 - extra
16 - buttons
*/
string[] gameinfo = line.Split(';'); // Read in the header
svr.ReadHeader();
// Header values should match
// #Name;Title;Emulator;CloneOf;Year;Manufacturer;Category;Players;Rotation;Control;Status;DisplayCount;DisplayType;AltRomname;AltTitle;Extra;Buttons
// Loop through all of the data lines
while (!svr.EndOfStream)
{
try
{
// Get the current line, split and parse
svr.ReadNextLine();
}
catch (InvalidDataException)
{
Globals.Logger.Warning($"Malformed line found in '{filename}' at line {svr.LineNumber}");
continue;
}
Rom rom = new Rom Rom rom = new Rom
{ {
@@ -70,32 +71,29 @@ namespace SabreTools.Library.DatFiles
Size = Constants.SizeZero, Size = Constants.SizeZero,
CRC = Constants.CRCZero, CRC = Constants.CRCZero,
MD5 = Constants.MD5Zero, MD5 = Constants.MD5Zero,
#if NET_FRAMEWORK
RIPEMD160 = Constants.RIPEMD160Zero,
#endif
SHA1 = Constants.SHA1Zero, SHA1 = Constants.SHA1Zero,
ItemStatus = ItemStatus.None, ItemStatus = ItemStatus.None,
Machine = new Machine Machine = new Machine
{ {
Name = gameinfo[0], Name = svr.Line[0], // #Name
Description = gameinfo[1], Description = svr.Line[1], // Title
CloneOf = gameinfo[3], CloneOf = svr.Line[3], // CloneOf
Year = gameinfo[4], Year = svr.Line[4], // Year
Manufacturer = gameinfo[5], Manufacturer = svr.Line[5], // Manufacturer
Category = gameinfo[6], Category = svr.Line[6], // Category
Players = gameinfo[7], Players = svr.Line[7], // Players
Rotation = gameinfo[8], Rotation = svr.Line[8], // Rotation
Control = gameinfo[9], Control = svr.Line[9], // Control
Status = gameinfo[10], Status = svr.Line[10], // Status
DisplayCount = gameinfo[11], DisplayCount = svr.Line[11], // DisplayCount
DisplayType = gameinfo[12], DisplayType = svr.Line[12], // DisplayType
Comment = gameinfo[15], Comment = svr.Line[15], // Extra
Buttons = gameinfo[16], Buttons = svr.Line[16], // Buttons
}, },
AltName = gameinfo[13], AltName = svr.Line[13], // AltRomname
AltTitle = gameinfo[14], AltTitle = svr.Line[14], // AltTitle
Source = new Source Source = new Source
{ {
@@ -108,7 +106,7 @@ namespace SabreTools.Library.DatFiles
ParseAddHelper(rom); ParseAddHelper(rom);
} }
sr.Dispose(); svr.Dispose();
} }
/// <summary> /// <summary>
@@ -186,8 +184,8 @@ namespace SabreTools.Library.DatFiles
{ {
string[] headers = new string[] string[] headers = new string[]
{ {
"#Title", "#Name",
"Name", "Title",
"Emulator", "Emulator",
"CloneOf", "CloneOf",
"Year", "Year",

View File

@@ -94,6 +94,8 @@ namespace SabreTools.Library.DatFiles
ParseAddHelper(datItem); ParseAddHelper(datItem);
} }
} }
svr.Dispose();
} }
/// <summary> /// <summary>