[Style, DatFile] Add better encoding finding

This commit is contained in:
Matt Nadareski
2016-09-21 12:47:11 -07:00
parent 08437314df
commit 7212949f56
2 changed files with 30 additions and 30 deletions

View File

@@ -707,7 +707,8 @@ namespace SabreTools.Helper
bool clean)
{
// Open a file reader
StreamReader sr = new StreamReader(File.OpenRead(filename));
Encoding enc = Style.GetEncoding(filename);
StreamReader sr = new StreamReader(File.OpenRead(filename), enc);
bool block = false, superdat = false;
string blockname = "", tempgamename = "", gamedesc = "", cloneof = "",
@@ -1202,7 +1203,8 @@ namespace SabreTools.Helper
bool clean)
{
// Open a file reader
StreamReader sr = new StreamReader(File.OpenRead(filename));
Encoding enc = Style.GetEncoding(filename);
StreamReader sr = new StreamReader(File.OpenRead(filename), enc);
string blocktype = "";
while (!sr.EndOfStream)
@@ -2249,22 +2251,8 @@ namespace SabreTools.Helper
List<string> keys = dict.Keys.ToList();
foreach (string key in keys)
{
// If the dictionary somehow doesn't have the key in question, continue
if (!dict.ContainsKey(key))
{
logger.Warning("Input Dictionary does not contain key: " + key);
continue;
}
List<DatItem> roms = dict[key];
// If we somehow have a null list, just skip it
if (roms == null)
{
logger.Warning("Blank list found for key: " + key);
continue;
}
// If we're merging the roms, do so
if (mergeroms)
{
@@ -2282,6 +2270,7 @@ namespace SabreTools.Helper
+ (String.IsNullOrEmpty(rom.MachineName)
? "Default"
: rom.MachineName.ToLowerInvariant());
newkey = HttpUtility.HtmlEncode(newkey);
if (sortable.ContainsKey(newkey))
{
sortable[newkey].Add(rom);
@@ -2306,13 +2295,6 @@ namespace SabreTools.Helper
continue;
}
// If we somehow have a null list, just skip it
if (sortable[key] == null)
{
logger.Warning("Blank list found for key: " + key);
continue;
}
List<DatItem> sortedlist = sortable[key];
DatItem.Sort(ref sortedlist, norename);
sortable[key] = sortedlist;
@@ -3012,13 +2994,6 @@ namespace SabreTools.Helper
continue;
}
// If we somehow have a null list, just skip it
if (sortable[key] == null)
{
logger.Warning("Blank list found for key: " + key);
continue;
}
List<DatItem> roms = sortable[key];
for (int index = 0; index < roms.Count; index++)