/// <inheritdoc/> public override void ParseFile(string filename, int indexId, bool keep, bool statsOnly = false, bool throwOnError = false) { // Open a file reader Encoding enc = filename.GetEncoding(); SeparatedValueReader svr = new SeparatedValueReader(File.OpenRead(filename), enc) { Header = true, Quotes = true, Separator = _delim, VerifyFieldCount = true, }; // If we're somehow at the end of the stream already, we can't do anything if (svr.EndOfStream) { return; } // Read in the header svr.ReadHeader(); // Loop through all of the data lines while (!svr.EndOfStream) { try { // Get the current line, split and parse svr.ReadNextLine(); // Create mapping dictionaries Setter setter = new Setter(); setter.PopulateSettersFromList(svr.HeaderValues, svr.Line); // Set DatHeader fields DatHeader datHeader = new DatHeader(); setter.SetFields(datHeader); Header.ConditionalCopy(datHeader); // Set Machine and DatItem fields if (setter.DatItemMappings.ContainsKey(DatItemField.Type)) { DatItem datItem = DatItem.Create(setter.DatItemMappings[DatItemField.Type].AsItemType()); setter.SetFields(datItem); datItem.Machine = new Machine(); setter.SetFields(datItem.Machine); datItem.Source = new Source(indexId, filename); ParseAddHelper(datItem, statsOnly); } } catch (Exception ex) when(!throwOnError) { string message = $"'{filename}' - There was an error parsing line {svr.LineNumber} '{svr.CurrentLine}'"; logger.Error(ex, message); } } svr.Dispose(); }
/// <summary> /// Parse a character-separated value DAT and return all found games and roms within /// </summary> /// <param name="filename">Name of the file to be parsed</param> /// <param name="indexId">Index ID for the DAT</param> /// <param name="keep">True if full pathnames are to be kept, false otherwise (default)</param> /// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param> protected override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false) { // Open a file reader Encoding enc = FileExtensions.GetEncoding(filename); SeparatedValueReader svr = new SeparatedValueReader(FileExtensions.TryOpenRead(filename), enc) { Header = true, Quotes = true, Separator = _delim, VerifyFieldCount = true, }; // If we're somehow at the end of the stream already, we can't do anything if (svr.EndOfStream) { return; } // Read in the header svr.ReadHeader(); // Loop through all of the data lines while (!svr.EndOfStream) { try { // Get the current line, split and parse svr.ReadNextLine(); // Create mapping dictionary var mappings = new Dictionary <Field, string>(); // Now we loop through and get values for everything for (int i = 0; i < svr.HeaderValues.Count; i++) { Field key = svr.HeaderValues[i].AsField(); string value = svr.Line[i]; mappings[key] = value; } // Set DatHeader fields DatHeader header = new DatHeader(); header.SetFields(mappings); Header.ConditionalCopy(header); // Set Machine and DatItem fields if (mappings.ContainsKey(Field.DatItem_Type)) { DatItem datItem = DatItem.Create(mappings[Field.DatItem_Type].AsItemType()); datItem.SetFields(mappings); datItem.Source = new Source(indexId, filename); ParseAddHelper(datItem); } } catch (Exception ex) { string message = $"'{filename}' - There was an error parsing line {svr.LineNumber} '{svr.CurrentLine}'"; logger.Error(ex, message); if (throwOnError) { svr.Dispose(); throw new Exception(message, ex); } } } svr.Dispose(); }
/// <summary> /// Parse an Everdrive SMDB file and return all found games within /// </summary> /// <param name="filename">Name of the file to be parsed</param> /// <param name="indexId">Index ID for the DAT</param> /// <param name="keep">True if full pathnames are to be kept, false otherwise (default)</param> /// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param> protected override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false) { // Open a file reader Encoding enc = FileExtensions.GetEncoding(filename); SeparatedValueReader svr = new SeparatedValueReader(FileExtensions.TryOpenRead(filename), enc) { Header = false, Quotes = false, Separator = '\t', VerifyFieldCount = false, }; while (!svr.EndOfStream) { try { // If we can't read the next line, break if (!svr.ReadNextLine()) { break; } // If the line returns null somehow, skip if (svr.Line == null) { continue; } /* * The gameinfo order is as follows * 0 - SHA-256 * 1 - Machine Name/Filename * 2 - SHA-1 * 3 - MD5 * 4 - CRC32 */ string[] fullname = svr.Line[1].Split('/'); Rom rom = new Rom { Name = svr.Line[1].Substring(fullname[0].Length + 1), Size = null, // No size provided, but we don't want the size being 0 CRC = svr.Line[4], MD5 = svr.Line[3], SHA1 = svr.Line[2], SHA256 = svr.Line[0], ItemStatus = ItemStatus.None, Machine = new Machine { Name = fullname[0], Description = fullname[0], }, Source = new Source { Index = indexId, Name = filename, }, }; // Now process and add the rom ParseAddHelper(rom); } catch (Exception ex) { string message = $"'{filename}' - There was an error parsing line {svr.LineNumber} '{svr.CurrentLine}'"; logger.Error(ex, message); if (throwOnError) { svr.Dispose(); throw new Exception(message, ex); } } } svr.Dispose(); }
/// <summary> /// Parse an AttractMode DAT and return all found games within /// </summary> /// <param name="filename">Name of the file to be parsed</param> /// <param name="indexId">Index ID for the DAT</param> /// <param name="keep">True if full pathnames are to be kept, false otherwise (default)</param> /// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param> protected override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false) { // Open a file reader Encoding enc = FileExtensions.GetEncoding(filename); SeparatedValueReader svr = new SeparatedValueReader(FileExtensions.TryOpenRead(filename), enc) { Header = true, Quotes = false, Separator = ';', VerifyFieldCount = true }; // If we're somehow at the end of the stream already, we can't do anything if (svr.EndOfStream) { return; } // 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(); Rom rom = new Rom { Name = "-", Size = Constants.SizeZero, CRC = Constants.CRCZero, MD5 = Constants.MD5Zero, SHA1 = Constants.SHA1Zero, ItemStatus = ItemStatus.None, Machine = new Machine { Name = svr.Line[0], // #Name Description = svr.Line[1], // Title CloneOf = svr.Line[3], // CloneOf Year = svr.Line[4], // Year Manufacturer = svr.Line[5], // Manufacturer Category = svr.Line[6], // Category Players = svr.Line[7], // Players Rotation = svr.Line[8], // Rotation Control = svr.Line[9], // Control Status = svr.Line[10], // Status DisplayCount = svr.Line[11], // DisplayCount DisplayType = svr.Line[12], // DisplayType Comment = svr.Line[15], // Extra Buttons = svr.Line[16], // Buttons }, AltName = svr.Line[13], // AltRomname AltTitle = svr.Line[14], // AltTitle Source = new Source { Index = indexId, Name = filename, }, }; // Now process and add the rom ParseAddHelper(rom); } catch (Exception ex) { string message = $"'{filename}' - There was an error parsing line {svr.LineNumber} '{svr.CurrentLine}'"; logger.Error(ex, message); if (throwOnError) { svr.Dispose(); throw new Exception(message, ex); } } } svr.Dispose(); }