[DatFile, FileTools] Move GetXmlTextReader to a better location

This commit is contained in:
Matt Nadareski
2016-09-22 17:14:23 -07:00
parent 27cd7e89da
commit ae9bfb9cd3
4 changed files with 28 additions and 27 deletions

View File

@@ -33,7 +33,7 @@ namespace SabreTools
Dictionary<string, Tuple<long, bool>> depots = new Dictionary<string, Tuple<long, bool>>(); Dictionary<string, Tuple<long, bool>> depots = new Dictionary<string, Tuple<long, bool>>();
// Get the XML text reader for the configuration file, if possible // Get the XML text reader for the configuration file, if possible
XmlTextReader xtr = DatFile.GetXmlTextReader(_config, _logger); XmlTextReader xtr = FileTools.GetXmlTextReader(_config, _logger);
// Now parse the XML file for settings // Now parse the XML file for settings
if (xtr != null) if (xtr != null)

View File

@@ -519,30 +519,6 @@ namespace SabreTools.Helper
} }
} }
/// <summary>
/// Get the XmlTextReader associated with a file, if possible
/// </summary>
/// <param name="filename">Name of the file to be parsed</param>
/// <param name="logger">Logger object for console and file output</param>
/// <returns>The XmlTextReader representing the (possibly converted) file, null otherwise</returns>
public static XmlTextReader GetXmlTextReader(string filename, Logger logger)
{
logger.Log("Attempting to read file: \"" + filename + "\"");
// Check if file exists
if (!File.Exists(filename))
{
logger.Warning("File '" + filename + "' could not read from!");
return null;
}
XmlTextReader xtr;
xtr = new XmlTextReader(filename);
xtr.WhitespaceHandling = WhitespaceHandling.None;
xtr.DtdProcessing = DtdProcessing.Ignore;
return xtr;
}
/// <summary> /// <summary>
/// Parse a DAT and return all found games and roms within /// Parse a DAT and return all found games and roms within
/// </summary> /// </summary>
@@ -1509,7 +1485,7 @@ namespace SabreTools.Helper
ItemStatus its = ItemStatus.None; ItemStatus its = ItemStatus.None;
List<string> parent = new List<string>(); List<string> parent = new List<string>();
XmlTextReader xtr = GetXmlTextReader(filename, logger); XmlTextReader xtr = FileTools.GetXmlTextReader(filename, logger);
if (xtr != null) if (xtr != null)
{ {
xtr.MoveToContent(); xtr.MoveToContent();

View File

@@ -80,7 +80,7 @@ namespace SabreTools.Helper
} }
Logger logger = new Logger(false, ""); Logger logger = new Logger(false, "");
XmlTextReader xtr = DatFile.GetXmlTextReader(filename, logger); XmlTextReader xtr = FileTools.GetXmlTextReader(filename, logger);
if (xtr == null) if (xtr == null)
{ {

View File

@@ -11,6 +11,7 @@ using System.Linq;
using System.Security.Cryptography; using System.Security.Cryptography;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Xml;
namespace SabreTools.Helper namespace SabreTools.Helper
{ {
@@ -1080,6 +1081,30 @@ namespace SabreTools.Helper
#region File Manipulation #region File Manipulation
/// <summary>
/// Get the XmlTextReader associated with a file, if possible
/// </summary>
/// <param name="filename">Name of the file to be parsed</param>
/// <param name="logger">Logger object for console and file output</param>
/// <returns>The XmlTextReader representing the (possibly converted) file, null otherwise</returns>
public static XmlTextReader GetXmlTextReader(string filename, Logger logger)
{
logger.Log("Attempting to read file: \"" + filename + "\"");
// Check if file exists
if (!File.Exists(filename))
{
logger.Warning("File '" + filename + "' could not read from!");
return null;
}
XmlTextReader xtr;
xtr = new XmlTextReader(filename);
xtr.WhitespaceHandling = WhitespaceHandling.None;
xtr.DtdProcessing = DtdProcessing.Ignore;
return xtr;
}
/// <summary> /// <summary>
/// Remove an arbitrary number of bytes from the inputted file /// Remove an arbitrary number of bytes from the inputted file
/// </summary> /// </summary>