Extract out IO namespace, Part 3

This commit is contained in:
Matt Nadareski
2020-12-08 00:13:22 -08:00
parent 53f5d07ae4
commit 96f0a94b10
60 changed files with 950 additions and 1319 deletions

View File

@@ -35,7 +35,7 @@ namespace SabreTools.Library.DatFiles
{
// Open a file reader
Encoding enc = FileExtensions.GetEncoding(filename);
SeparatedValueReader svr = new SeparatedValueReader(FileExtensions.TryOpenRead(filename), enc)
SeparatedValueReader svr = new SeparatedValueReader(File.OpenRead(filename), enc)
{
Header = true,
Quotes = false,
@@ -134,7 +134,7 @@ namespace SabreTools.Library.DatFiles
try
{
logger.User($"Opening file for writing: {outfile}");
FileStream fs = FileExtensions.TryCreate(outfile);
FileStream fs = File.Create(outfile);
// If we get back null for some reason, just log and return
if (fs == null)

View File

@@ -46,7 +46,7 @@ namespace SabreTools.Library.DatFiles
{
// Open a file reader
Encoding enc = FileExtensions.GetEncoding(filename);
ClrMameProReader cmpr = new ClrMameProReader(FileExtensions.TryOpenRead(filename), enc)
ClrMameProReader cmpr = new ClrMameProReader(File.OpenRead(filename), enc)
{
DosCenter = false,
Quotes = Quotes,
@@ -459,7 +459,7 @@ namespace SabreTools.Library.DatFiles
try
{
logger.User($"Opening file for writing: {outfile}");
FileStream fs = FileExtensions.TryCreate(outfile);
FileStream fs = File.Create(outfile);
// If we get back null for some reason, just log and return
if (fs == null)

View File

@@ -17,8 +17,8 @@ using SabreTools.Library.FileTypes;
using SabreTools.Library.Filtering;
using SabreTools.Library.IO;
using SabreTools.Library.Reports;
using SabreTools.Library.Skippers;
using SabreTools.Library.Tools;
using SabreTools.Skippers;
using NaturalSort;
using Newtonsoft.Json;
@@ -1870,13 +1870,14 @@ namespace SabreTools.Library.DatFiles
Header.FileName = (string.IsNullOrWhiteSpace(Header.FileName) ? (keepext ? Path.GetFileName(currentPath) : Path.GetFileNameWithoutExtension(currentPath)) : Header.FileName);
// If the output type isn't set already, get the internal output type
Header.DatFormat = (Header.DatFormat == 0 ? currentPath.GetDatFormat() : Header.DatFormat);
DatFormat currentPathFormat = GetDatFormat(currentPath);
Header.DatFormat = (Header.DatFormat == 0 ? currentPathFormat : Header.DatFormat);
Items.SetBucketedBy(Field.DatItem_CRC); // Setting this because it can reduce issues later
// Now parse the correct type of DAT
try
{
Create(currentPath.GetDatFormat(), this, quotes)?.ParseFile(currentPath, indexId, keep, throwOnError);
Create(currentPathFormat, this, quotes)?.ParseFile(currentPath, indexId, keep, throwOnError);
}
catch (Exception ex)
{
@@ -1885,6 +1886,142 @@ namespace SabreTools.Library.DatFiles
}
}
/// <summary>
/// Get what type of DAT the input file is
/// </summary>
/// <param name="filename">Name of the file to be parsed</param>
/// <returns>The DatFormat corresponding to the DAT</returns>
protected DatFormat GetDatFormat(string filename)
{
// Limit the output formats based on extension
if (!PathExtensions.HasValidDatExtension(filename))
return 0;
// Get the extension from the filename
string ext = PathExtensions.GetNormalizedExtension(filename);
// Check if file exists
if (!File.Exists(filename))
return 0;
// Some formats should only require the extension to know
switch (ext)
{
case "csv":
return DatFormat.CSV;
case "json":
return DatFormat.SabreJSON;
case "md5":
return DatFormat.RedumpMD5;
#if NET_FRAMEWORK
case "ripemd160":
return DatFormat.RedumpRIPEMD160;
#endif
case "sfv":
return DatFormat.RedumpSFV;
case "sha1":
return DatFormat.RedumpSHA1;
case "sha256":
return DatFormat.RedumpSHA256;
case "sha384":
return DatFormat.RedumpSHA384;
case "sha512":
return DatFormat.RedumpSHA512;
case "spamsum":
return DatFormat.RedumpSpamSum;
case "ssv":
return DatFormat.SSV;
case "tsv":
return DatFormat.TSV;
}
// For everything else, we need to read it
// Get the first two non-whitespace, non-comment lines to check, if possible
string first = string.Empty, second = string.Empty;
try
{
using (StreamReader sr = File.OpenText(filename))
{
first = sr.ReadLine().ToLowerInvariant();
while ((string.IsNullOrWhiteSpace(first) || first.StartsWith("<!--"))
&& !sr.EndOfStream)
{
first = sr.ReadLine().ToLowerInvariant();
}
if (!sr.EndOfStream)
{
second = sr.ReadLine().ToLowerInvariant();
while (string.IsNullOrWhiteSpace(second) || second.StartsWith("<!--")
&& !sr.EndOfStream)
{
second = sr.ReadLine().ToLowerInvariant();
}
}
}
}
catch { }
// If we have an XML-based DAT
if (first.Contains("<?xml") && first.Contains("?>"))
{
if (second.StartsWith("<!doctype datafile"))
return DatFormat.Logiqx;
else if (second.StartsWith("<!doctype mame")
|| second.StartsWith("<!doctype m1")
|| second.StartsWith("<mame")
|| second.StartsWith("<m1"))
return DatFormat.Listxml;
else if (second.StartsWith("<!doctype softwaredb"))
return DatFormat.OpenMSX;
else if (second.StartsWith("<!doctype softwarelist"))
return DatFormat.SoftwareList;
else if (second.StartsWith("<!doctype sabredat"))
return DatFormat.SabreXML;
else if ((second.StartsWith("<dat") && !second.StartsWith("<datafile"))
|| second.StartsWith("<?xml-stylesheet"))
return DatFormat.OfflineList;
// Older and non-compliant DATs
else
return DatFormat.Logiqx;
}
// If we have an SMDB (SHA-256, Filename, SHA-1, MD5, CRC32)
else if (Regex.IsMatch(first, @"[0-9a-f]{64}\t.*?\t[0-9a-f]{40}\t[0-9a-f]{32}\t[0-9a-f]{8}"))
return DatFormat.EverdriveSMDB;
// If we have an INI-based DAT
else if (first.Contains("[") && first.Contains("]"))
return DatFormat.RomCenter;
// If we have a listroms DAT
else if (first.StartsWith("roms required for driver"))
return DatFormat.Listrom;
// If we have a CMP-based DAT
else if (first.Contains("clrmamepro"))
return DatFormat.ClrMamePro;
else if (first.Contains("romvault"))
return DatFormat.ClrMamePro;
else if (first.Contains("doscenter"))
return DatFormat.DOSCenter;
else if (first.Contains("#Name;Title;Emulator;CloneOf;Year;Manufacturer;Category;Players;Rotation;Control;Status;DisplayCount;DisplayType;AltRomname;AltTitle;Extra"))
return DatFormat.AttractMode;
else
return DatFormat.ClrMamePro;
}
/// <summary>
/// Add a rom to the Dat after checking
/// </summary>
@@ -2043,7 +2180,10 @@ namespace SabreTools.Library.DatFiles
// Now that we're done, delete the temp folder (if it's not the default)
logger.User("Cleaning temp folder");
if (Globals.TempDir != Path.GetTempPath())
DirectoryExtensions.TryDelete(Globals.TempDir);
{
if (Directory.Exists(Globals.TempDir))
Directory.Delete(Globals.TempDir, true);
}
return true;
}
@@ -2247,7 +2387,7 @@ namespace SabreTools.Library.DatFiles
private void ProcessFile(string item, string basePath, Hash hashes, TreatAsFile asFiles)
{
logger.Verbose($"'{Path.GetFileName(item)}' treated like a file");
BaseFile baseFile = FileExtensions.GetInfo(item, header: Header.HeaderSkipper, hashes: hashes, asFiles: asFiles);
BaseFile baseFile = BaseFile.GetInfo(item, header: Header.HeaderSkipper, hashes: hashes, asFiles: asFiles);
DatItem datItem = DatItem.Create(baseFile);
ProcessFileHelper(item, datItem, basePath, string.Empty);
}
@@ -2504,7 +2644,7 @@ namespace SabreTools.Library.DatFiles
// If we are supposed to delete the depot file, do so
if (delete && usedInternally)
FileExtensions.TryDelete(foundpath);
File.Delete(foundpath);
}
watch.Stop();
@@ -2579,7 +2719,7 @@ namespace SabreTools.Library.DatFiles
// If we are supposed to delete the file, do so
if (delete && rebuilt)
FileExtensions.TryDelete(input);
File.Delete(input);
}
// If the input is a directory
@@ -2593,7 +2733,7 @@ namespace SabreTools.Library.DatFiles
// If we are supposed to delete the file, do so
if (delete && rebuilt)
FileExtensions.TryDelete(input);
File.Delete(input);
}
}
}
@@ -2653,7 +2793,7 @@ namespace SabreTools.Library.DatFiles
// If the entries list is null, we encountered an error or have a file and should scan externally
if (entries == null && File.Exists(file))
{
BaseFile internalFileInfo = FileExtensions.GetInfo(file, asFiles: asFiles);
BaseFile internalFileInfo = BaseFile.GetInfo(file, asFiles: asFiles);
// Create the correct DatItem
DatItem internalDatItem;
@@ -2982,7 +3122,7 @@ namespace SabreTools.Library.DatFiles
// Otherwise, just open the filestream
else
{
stream = FileExtensions.TryOpenRead(file);
stream = File.OpenRead(file);
}
// If the stream is null, then continue

View File

@@ -4,8 +4,9 @@ using System.IO;
using System.Linq;
using System.Xml.Serialization;
using SabreTools.Data;
using SabreTools.IO;
using SabreTools.Library.DatItems;
using SabreTools.Library.IO;
using SabreTools.Library.Tools;
using Newtonsoft.Json;

View File

@@ -36,7 +36,7 @@ namespace SabreTools.Library.DatFiles
{
// Open a file reader
Encoding enc = FileExtensions.GetEncoding(filename);
ClrMameProReader cmpr = new ClrMameProReader(FileExtensions.TryOpenRead(filename), enc)
ClrMameProReader cmpr = new ClrMameProReader(File.OpenRead(filename), enc)
{
DosCenter = true
};
@@ -278,7 +278,7 @@ namespace SabreTools.Library.DatFiles
try
{
logger.User($"Opening file for writing: {outfile}");
FileStream fs = FileExtensions.TryCreate(outfile);
FileStream fs = File.Create(outfile);
// If we get back null for some reason, just log and return
if (fs == null)

View File

@@ -2,164 +2,6 @@
namespace SabreTools.Library.DatFiles
{
/// <summary>
/// DAT output formats
/// </summary>
[Flags]
public enum DatFormat
{
#region XML Formats
/// <summary>
/// Logiqx XML (using machine)
/// </summary>
Logiqx = 1 << 0,
/// <summary>
/// Logiqx XML (using game)
/// </summary>
LogiqxDeprecated = 1 << 1,
/// <summary>
/// MAME Softare List XML
/// </summary>
SoftwareList = 1 << 2,
/// <summary>
/// MAME Listxml output
/// </summary>
Listxml = 1 << 3,
/// <summary>
/// OfflineList XML
/// </summary>
OfflineList = 1 << 4,
/// <summary>
/// SabreDAT XML
/// </summary>
SabreXML = 1 << 5,
/// <summary>
/// openMSX Software List XML
/// </summary>
OpenMSX = 1 << 6,
#endregion
#region Propietary Formats
/// <summary>
/// ClrMamePro custom
/// </summary>
ClrMamePro = 1 << 7,
/// <summary>
/// RomCenter INI-based
/// </summary>
RomCenter = 1 << 8,
/// <summary>
/// DOSCenter custom
/// </summary>
DOSCenter = 1 << 9,
/// <summary>
/// AttractMode custom
/// </summary>
AttractMode = 1 << 10,
#endregion
#region Standardized Text Formats
/// <summary>
/// ClrMamePro missfile
/// </summary>
MissFile = 1 << 11,
/// <summary>
/// Comma-Separated Values (standardized)
/// </summary>
CSV = 1 << 12,
/// <summary>
/// Semicolon-Separated Values (standardized)
/// </summary>
SSV = 1 << 13,
/// <summary>
/// Tab-Separated Values (standardized)
/// </summary>
TSV = 1 << 14,
/// <summary>
/// MAME Listrom output
/// </summary>
Listrom = 1 << 15,
/// <summary>
/// Everdrive Packs SMDB
/// </summary>
EverdriveSMDB = 1 << 16,
/// <summary>
/// SabreJSON
/// </summary>
SabreJSON = 1 << 17,
#endregion
#region SFV-similar Formats
/// <summary>
/// CRC32 hash list
/// </summary>
RedumpSFV = 1 << 18,
/// <summary>
/// MD5 hash list
/// </summary>
RedumpMD5 = 1 << 19,
#if NET_FRAMEWORK
/// <summary>
/// RIPEMD160 hash list
/// </summary>
RedumpRIPEMD160 = 1 << 20,
#endif
/// <summary>
/// SHA-1 hash list
/// </summary>
RedumpSHA1 = 1 << 21,
/// <summary>
/// SHA-256 hash list
/// </summary>
RedumpSHA256 = 1 << 22,
/// <summary>
/// SHA-384 hash list
/// </summary>
RedumpSHA384 = 1 << 23,
/// <summary>
/// SHA-512 hash list
/// </summary>
RedumpSHA512 = 1 << 24,
/// <summary>
/// SpamSum hash list
/// </summary>
RedumpSpamSum = 1 << 25,
#endregion
// Specialty combinations
ALL = Int32.MaxValue,
}
/// <summary>
/// Determines the DAT deduplication type
/// </summary>
@@ -244,19 +86,4 @@ namespace SabreTools.Library.DatFiles
Archive,
File,
}
/// <summary>
/// Determines what sort of files get externally hashed
/// </summary>
/// TODO: Can FileType be used instead?
[Flags]
public enum TreatAsFile
{
CHD = 1 << 0,
Archive = 1 << 1,
AaruFormat = 1 << 2,
NonArchive = CHD | AaruFormat,
All = CHD | Archive | AaruFormat,
}
}

View File

@@ -34,7 +34,7 @@ namespace SabreTools.Library.DatFiles
{
// Open a file reader
Encoding enc = FileExtensions.GetEncoding(filename);
SeparatedValueReader svr = new SeparatedValueReader(FileExtensions.TryOpenRead(filename), enc)
SeparatedValueReader svr = new SeparatedValueReader(File.OpenRead(filename), enc)
{
Header = false,
Quotes = false,
@@ -124,7 +124,7 @@ namespace SabreTools.Library.DatFiles
try
{
logger.User($"Opening file for writing: {outfile}");
FileStream fs = FileExtensions.TryCreate(outfile);
FileStream fs = File.Create(outfile);
// If we get back null for some reason, just log and return
if (fs == null)

View File

@@ -40,7 +40,7 @@ namespace SabreTools.Library.DatFiles
{
// Open a file reader
Encoding enc = FileExtensions.GetEncoding(filename);
StreamReader sr = new StreamReader(FileExtensions.TryOpenRead(filename), enc);
StreamReader sr = new StreamReader(File.OpenRead(filename), enc);
while (!sr.EndOfStream)
{
@@ -130,7 +130,7 @@ namespace SabreTools.Library.DatFiles
try
{
logger.User($"Opening file for writing: {outfile}");
FileStream fs = FileExtensions.TryCreate(outfile);
FileStream fs = File.Create(outfile);
// If we get back null for some reason, just log and return
if (fs == null)

View File

@@ -4,8 +4,8 @@ using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using SabreTools.IO;
using SabreTools.Library.DatItems;
using SabreTools.Library.IO;
using SabreTools.Library.Tools;
namespace SabreTools.Library.DatFiles
@@ -44,7 +44,7 @@ namespace SabreTools.Library.DatFiles
{
// Open a file reader
Encoding enc = FileExtensions.GetEncoding(filename);
StreamReader sr = new StreamReader(FileExtensions.TryOpenRead(filename), enc);
StreamReader sr = new StreamReader(File.OpenRead(filename), enc);
string gamename = string.Empty;
while (!sr.EndOfStream)
@@ -280,7 +280,7 @@ namespace SabreTools.Library.DatFiles
try
{
logger.User($"Opening file for writing: {outfile}");
FileStream fs = FileExtensions.TryCreate(outfile);
FileStream fs = File.Create(outfile);
// If we get back null for some reason, just log and return
if (fs == null)

View File

@@ -4,10 +4,10 @@ using System.IO;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Schema;
using SabreTools.IO;
using SabreTools.Library.DatItems;
using SabreTools.Library.IO;
using SabreTools.Library.Tools;
namespace SabreTools.Library.DatFiles
@@ -36,7 +36,15 @@ namespace SabreTools.Library.DatFiles
protected override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false)
{
// Prepare all internal variables
XmlReader xtr = filename.GetXmlTextReader();
XmlReader xtr = XmlReader.Create(filename, new XmlReaderSettings
{
CheckCharacters = false,
DtdProcessing = DtdProcessing.Ignore,
IgnoreComments = true,
IgnoreWhitespace = true,
ValidationFlags = XmlSchemaValidationFlags.None,
ValidationType = ValidationType.None,
});
// If we got a null reader, just return
if (xtr == null)
@@ -1192,7 +1200,7 @@ namespace SabreTools.Library.DatFiles
try
{
logger.User($"Opening file for writing: {outfile}");
FileStream fs = FileExtensions.TryCreate(outfile);
FileStream fs = File.Create(outfile);
// If we get back null for some reason, just log and return
if (fs == null)

View File

@@ -5,10 +5,10 @@ using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Xml;
using System.Xml.Schema;
using SabreTools.IO;
using SabreTools.Library.DatItems;
using SabreTools.Library.IO;
using SabreTools.Library.Tools;
namespace SabreTools.Library.DatFiles
@@ -42,7 +42,16 @@ namespace SabreTools.Library.DatFiles
protected override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false)
{
// Prepare all internal variables
XmlReader xtr = filename.GetXmlTextReader();
XmlReader xtr = XmlReader.Create(filename, new XmlReaderSettings
{
CheckCharacters = false,
DtdProcessing = DtdProcessing.Ignore,
IgnoreComments = true,
IgnoreWhitespace = true,
ValidationFlags = XmlSchemaValidationFlags.None,
ValidationType = ValidationType.None,
});
List<string> dirs = new List<string>();
// If we got a null reader, just return
@@ -689,7 +698,7 @@ namespace SabreTools.Library.DatFiles
try
{
logger.User($"Opening file for writing: {outfile}");
FileStream fs = FileExtensions.TryCreate(outfile);
FileStream fs = File.Create(outfile);
// If we get back null for some reason, just log and return
if (fs == null)

View File

@@ -4,7 +4,6 @@ using System.IO;
using System.Text;
using SabreTools.Library.DatItems;
using SabreTools.Library.IO;
namespace SabreTools.Library.DatFiles
{
@@ -47,7 +46,7 @@ namespace SabreTools.Library.DatFiles
try
{
logger.User($"Opening file for writing: {outfile}");
FileStream fs = FileExtensions.TryCreate(outfile);
FileStream fs = File.Create(outfile);
// If we get back null for some reason, just log and return
if (fs == null)

View File

@@ -3,10 +3,10 @@ using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Xml;
using System.Xml.Schema;
using SabreTools.IO;
using SabreTools.Library.DatItems;
using SabreTools.Library.IO;
using SabreTools.Library.Tools;
namespace SabreTools.Library.DatFiles
@@ -34,7 +34,15 @@ namespace SabreTools.Library.DatFiles
/// <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)
{
XmlReader xtr = filename.GetXmlTextReader();
XmlReader xtr = XmlReader.Create(filename, new XmlReaderSettings
{
CheckCharacters = false,
DtdProcessing = DtdProcessing.Ignore,
IgnoreComments = true,
IgnoreWhitespace = true,
ValidationFlags = XmlSchemaValidationFlags.None,
ValidationType = ValidationType.None,
});
// If we got a null reader, just return
if (xtr == null)
@@ -677,7 +685,7 @@ namespace SabreTools.Library.DatFiles
try
{
logger.User($"Opening file for writing: {outfile}");
FileStream fs = FileExtensions.TryCreate(outfile);
FileStream fs = File.Create(outfile);
// If we get back null for some reason, just log and return
if (fs == null)

View File

@@ -3,10 +3,10 @@ using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Xml;
using System.Xml.Schema;
using SabreTools.IO;
using SabreTools.Library.DatItems;
using SabreTools.Library.IO;
using SabreTools.Library.Tools;
namespace SabreTools.Library.DatFiles
@@ -35,7 +35,15 @@ namespace SabreTools.Library.DatFiles
protected override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false)
{
// Prepare all internal variables
XmlReader xtr = filename.GetXmlTextReader();
XmlReader xtr = XmlReader.Create(filename, new XmlReaderSettings
{
CheckCharacters = false,
DtdProcessing = DtdProcessing.Ignore,
IgnoreComments = true,
IgnoreWhitespace = true,
ValidationFlags = XmlSchemaValidationFlags.None,
ValidationType = ValidationType.None,
});
// If we got a null reader, just return
if (xtr == null)
@@ -531,7 +539,7 @@ namespace SabreTools.Library.DatFiles
try
{
logger.User($"Opening file for writing: {outfile}");
FileStream fs = FileExtensions.TryCreate(outfile);
FileStream fs = File.Create(outfile);
// If we get back null for some reason, just log and return
if (fs == null)

View File

@@ -34,7 +34,7 @@ namespace SabreTools.Library.DatFiles
protected override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false)
{
// Prepare all intenral variables
IniReader ir = filename.GetIniReader(false);
IniReader ir = new IniReader(filename) { ValidateRows = false };
// If we got a null reader, just return
if (ir == null)
@@ -384,7 +384,7 @@ namespace SabreTools.Library.DatFiles
try
{
logger.User($"Opening file for writing: {outfile}");
FileStream fs = FileExtensions.TryCreate(outfile);
FileStream fs = File.Create(outfile);
// If we get back null for some reason, just log and return
if (fs == null)

View File

@@ -3,8 +3,8 @@ using System.Collections.Generic;
using System.IO;
using System.Text;
using SabreTools.IO;
using SabreTools.Library.DatItems;
using SabreTools.Library.IO;
using SabreTools.Library.Tools;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
@@ -35,7 +35,7 @@ namespace SabreTools.Library.DatFiles
protected override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false)
{
// Prepare all internal variables
StreamReader sr = new StreamReader(FileExtensions.TryOpenRead(filename), new UTF8Encoding(false));
StreamReader sr = new StreamReader(File.OpenRead(filename), new UTF8Encoding(false));
JsonTextReader jtr = new JsonTextReader(sr);
// If we got a null reader, just return
@@ -342,7 +342,7 @@ namespace SabreTools.Library.DatFiles
try
{
logger.User($"Opening file for writing: {outfile}");
FileStream fs = FileExtensions.TryCreate(outfile);
FileStream fs = File.Create(outfile);
// If we get back null for some reason, just log and return
if (fs == null)

View File

@@ -3,10 +3,10 @@ using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;
using SabreTools.Library.DatItems;
using SabreTools.Library.IO;
namespace SabreTools.Library.DatFiles
{
@@ -34,7 +34,15 @@ namespace SabreTools.Library.DatFiles
protected override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false)
{
// Prepare all internal variables
XmlReader xtr = filename.GetXmlTextReader();
XmlReader xtr = XmlReader.Create(filename, new XmlReaderSettings
{
CheckCharacters = false,
DtdProcessing = DtdProcessing.Ignore,
IgnoreComments = true,
IgnoreWhitespace = true,
ValidationFlags = XmlSchemaValidationFlags.None,
ValidationType = ValidationType.None,
});
// If we got a null reader, just return
if (xtr == null)
@@ -190,7 +198,7 @@ namespace SabreTools.Library.DatFiles
try
{
logger.User($"Opening file for writing: {outfile}");
FileStream fs = FileExtensions.TryCreate(outfile);
FileStream fs = File.Create(outfile);
// If we get back null for some reason, just log and return
if (fs == null)

View File

@@ -40,7 +40,7 @@ namespace SabreTools.Library.DatFiles
{
// Open a file reader
Encoding enc = FileExtensions.GetEncoding(filename);
SeparatedValueReader svr = new SeparatedValueReader(FileExtensions.TryOpenRead(filename), enc)
SeparatedValueReader svr = new SeparatedValueReader(File.OpenRead(filename), enc)
{
Header = true,
Quotes = true,
@@ -121,7 +121,7 @@ namespace SabreTools.Library.DatFiles
try
{
logger.User($"Opening file for writing: {outfile}");
FileStream fs = FileExtensions.TryCreate(outfile);
FileStream fs = File.Create(outfile);
// If we get back null for some reason, just log and return
if (fs == null)

View File

@@ -4,10 +4,10 @@ using System.IO;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Schema;
using SabreTools.IO;
using SabreTools.Library.DatItems;
using SabreTools.Library.IO;
using SabreTools.Library.Tools;
// TODO: Use softwarelist.dtd and *try* to make this write more correctly
@@ -37,7 +37,15 @@ namespace SabreTools.Library.DatFiles
protected override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false)
{
// Prepare all internal variables
XmlReader xtr = filename.GetXmlTextReader();
XmlReader xtr = XmlReader.Create(filename, new XmlReaderSettings
{
CheckCharacters = false,
DtdProcessing = DtdProcessing.Ignore,
IgnoreComments = true,
IgnoreWhitespace = true,
ValidationFlags = XmlSchemaValidationFlags.None,
ValidationType = ValidationType.None,
});
// If we got a null reader, just return
if (xtr == null)
@@ -531,7 +539,7 @@ namespace SabreTools.Library.DatFiles
try
{
logger.User($"Opening file for writing: {outfile}");
FileStream fs = FileExtensions.TryCreate(outfile);
FileStream fs = File.Create(outfile);
// If we get back null for some reason, just log and return
if (fs == null)